* config/m68k/netbsd-elf.h (LONG_DOUBLE_TYPE_SIZE): Compute
[official-gcc.git] / gcc / dwarf2out.c
blob07295229a11756f4eacbcbca8bf4fa6a774d29bf
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 number of the current function definition for which debugging
107 information is being generated. These numbers range from 1 up to the
108 maximum number of function definitions contained within the current
109 compilation unit. These numbers are used to create unique label id's
110 unique to each function definition. */
111 unsigned current_funcdef_number = 0;
113 /* The size of the target's pointer type. */
114 #ifndef PTR_SIZE
115 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
116 #endif
118 /* Default version of targetm.eh_frame_section. Note this must appear
119 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
120 guards. */
122 void
123 default_eh_frame_section ()
125 #ifdef EH_FRAME_SECTION_NAME
126 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
127 #else
128 tree label = get_file_function_name ('F');
130 data_section ();
131 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
132 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
133 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
134 #endif
137 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
139 /* How to start an assembler comment. */
140 #ifndef ASM_COMMENT_START
141 #define ASM_COMMENT_START ";#"
142 #endif
144 typedef struct dw_cfi_struct *dw_cfi_ref;
145 typedef struct dw_fde_struct *dw_fde_ref;
146 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
148 /* Call frames are described using a sequence of Call Frame
149 Information instructions. The register number, offset
150 and address fields are provided as possible operands;
151 their use is selected by the opcode field. */
153 typedef union dw_cfi_oprnd_struct
155 unsigned long dw_cfi_reg_num;
156 long int dw_cfi_offset;
157 const char *dw_cfi_addr;
158 struct dw_loc_descr_struct *dw_cfi_loc;
160 dw_cfi_oprnd;
162 typedef struct dw_cfi_struct
164 dw_cfi_ref dw_cfi_next;
165 enum dwarf_call_frame_info dw_cfi_opc;
166 dw_cfi_oprnd dw_cfi_oprnd1;
167 dw_cfi_oprnd dw_cfi_oprnd2;
169 dw_cfi_node;
171 /* This is how we define the location of the CFA. We use to handle it
172 as REG + OFFSET all the time, but now it can be more complex.
173 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
174 Instead of passing around REG and OFFSET, we pass a copy
175 of this structure. */
176 typedef struct cfa_loc
178 unsigned long reg;
179 long offset;
180 long base_offset;
181 int indirect; /* 1 if CFA is accessed via a dereference. */
182 } dw_cfa_location;
184 /* All call frame descriptions (FDE's) in the GCC generated DWARF
185 refer to a single Common Information Entry (CIE), defined at
186 the beginning of the .debug_frame section. This use of a single
187 CIE obviates the need to keep track of multiple CIE's
188 in the DWARF generation routines below. */
190 typedef struct dw_fde_struct
192 const char *dw_fde_begin;
193 const char *dw_fde_current_label;
194 const char *dw_fde_end;
195 dw_cfi_ref dw_fde_cfi;
196 unsigned funcdef_number;
197 unsigned nothrow : 1;
198 unsigned uses_eh_lsda : 1;
200 dw_fde_node;
202 /* Maximum size (in bytes) of an artificially generated label. */
203 #define MAX_ARTIFICIAL_LABEL_BYTES 30
205 /* The size of addresses as they appear in the Dwarf 2 data.
206 Some architectures use word addresses to refer to code locations,
207 but Dwarf 2 info always uses byte addresses. On such machines,
208 Dwarf 2 addresses need to be larger than the architecture's
209 pointers. */
210 #ifndef DWARF2_ADDR_SIZE
211 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
212 #endif
214 /* The size in bytes of a DWARF field indicating an offset or length
215 relative to a debug info section, specified to be 4 bytes in the
216 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
217 as PTR_SIZE. */
219 #ifndef DWARF_OFFSET_SIZE
220 #define DWARF_OFFSET_SIZE 4
221 #endif
223 #define DWARF_VERSION 2
225 /* Round SIZE up to the nearest BOUNDARY. */
226 #define DWARF_ROUND(SIZE,BOUNDARY) \
227 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
229 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
230 #ifndef DWARF_CIE_DATA_ALIGNMENT
231 #ifdef STACK_GROWS_DOWNWARD
232 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
233 #else
234 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
235 #endif
236 #endif
238 /* A pointer to the base of a table that contains frame description
239 information for each routine. */
240 static dw_fde_ref fde_table;
242 /* Number of elements currently allocated for fde_table. */
243 static unsigned fde_table_allocated;
245 /* Number of elements in fde_table currently in use. */
246 static unsigned fde_table_in_use;
248 /* Size (in elements) of increments by which we may expand the
249 fde_table. */
250 #define FDE_TABLE_INCREMENT 256
252 /* A list of call frame insns for the CIE. */
253 static dw_cfi_ref cie_cfi_head;
255 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
256 attribute that accelerates the lookup of the FDE associated
257 with the subprogram. This variable holds the table index of the FDE
258 associated with the current function (body) definition. */
259 static unsigned current_funcdef_fde;
261 struct ht *debug_str_hash;
263 struct indirect_string_node
265 struct ht_identifier id;
266 unsigned int refcount;
267 unsigned int form;
268 char *label;
271 /* Forward declarations for functions defined in this file. */
273 static char *stripattributes PARAMS ((const char *));
274 static const char *dwarf_cfi_name PARAMS ((unsigned));
275 static dw_cfi_ref new_cfi PARAMS ((void));
276 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
277 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
278 static void lookup_cfa_1 PARAMS ((dw_cfi_ref,
279 dw_cfa_location *));
280 static void lookup_cfa PARAMS ((dw_cfa_location *));
281 static void reg_save PARAMS ((const char *, unsigned,
282 unsigned, long));
283 static void initial_return_save PARAMS ((rtx));
284 static long stack_adjust_offset PARAMS ((rtx));
285 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
286 static void output_call_frame_info PARAMS ((int));
287 static void dwarf2out_stack_adjust PARAMS ((rtx));
288 static void queue_reg_save PARAMS ((const char *, rtx, long));
289 static void flush_queued_reg_saves PARAMS ((void));
290 static bool clobbers_queued_reg_save PARAMS ((rtx));
291 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
293 /* Support for complex CFA locations. */
294 static void output_cfa_loc PARAMS ((dw_cfi_ref));
295 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
296 struct dw_loc_descr_struct *));
297 static struct dw_loc_descr_struct *build_cfa_loc
298 PARAMS ((dw_cfa_location *));
299 static void def_cfa_1 PARAMS ((const char *,
300 dw_cfa_location *));
302 /* How to start an assembler comment. */
303 #ifndef ASM_COMMENT_START
304 #define ASM_COMMENT_START ";#"
305 #endif
307 /* Data and reference forms for relocatable data. */
308 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
309 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
311 /* Pseudo-op for defining a new section. */
312 #ifndef SECTION_ASM_OP
313 #define SECTION_ASM_OP "\t.section\t"
314 #endif
316 #ifndef DEBUG_FRAME_SECTION
317 #define DEBUG_FRAME_SECTION ".debug_frame"
318 #endif
320 #ifndef FUNC_BEGIN_LABEL
321 #define FUNC_BEGIN_LABEL "LFB"
322 #endif
324 #ifndef FUNC_END_LABEL
325 #define FUNC_END_LABEL "LFE"
326 #endif
328 #define FRAME_BEGIN_LABEL "Lframe"
329 #define CIE_AFTER_SIZE_LABEL "LSCIE"
330 #define CIE_END_LABEL "LECIE"
331 #define CIE_LENGTH_LABEL "LLCIE"
332 #define FDE_LABEL "LSFDE"
333 #define FDE_AFTER_SIZE_LABEL "LASFDE"
334 #define FDE_END_LABEL "LEFDE"
335 #define FDE_LENGTH_LABEL "LLFDE"
336 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
337 #define LINE_NUMBER_END_LABEL "LELT"
338 #define LN_PROLOG_AS_LABEL "LASLTP"
339 #define LN_PROLOG_END_LABEL "LELTP"
340 #define DIE_LABEL_PREFIX "DW"
342 /* Definitions of defaults for various types of primitive assembly language
343 output operations. These may be overridden from within the tm.h file,
344 but typically, that is unnecessary. */
346 #ifdef SET_ASM_OP
347 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
348 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
349 do \
351 fprintf (FILE, "%s", SET_ASM_OP); \
352 assemble_name (FILE, SY); \
353 fputc (',', FILE); \
354 assemble_name (FILE, HI); \
355 fputc ('-', FILE); \
356 assemble_name (FILE, LO); \
358 while (0)
359 #endif
360 #endif
362 /* The DWARF 2 CFA column which tracks the return address. Normally this
363 is the column for PC, or the first column after all of the hard
364 registers. */
365 #ifndef DWARF_FRAME_RETURN_COLUMN
366 #ifdef PC_REGNUM
367 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
368 #else
369 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
370 #endif
371 #endif
373 /* The mapping from gcc register number to DWARF 2 CFA column number. By
374 default, we just provide columns for all registers. */
375 #ifndef DWARF_FRAME_REGNUM
376 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
377 #endif
379 /* The offset from the incoming value of %sp to the top of the stack frame
380 for the current function. */
381 #ifndef INCOMING_FRAME_SP_OFFSET
382 #define INCOMING_FRAME_SP_OFFSET 0
383 #endif
385 /* Hook used by __throw. */
388 expand_builtin_dwarf_fp_regnum ()
390 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
393 /* Return a pointer to a copy of the section string name S with all
394 attributes stripped off, and an asterisk prepended (for assemble_name). */
396 static inline char *
397 stripattributes (s)
398 const char *s;
400 char *stripped = xmalloc (strlen (s) + 2);
401 char *p = stripped;
403 *p++ = '*';
405 while (*s && *s != ',')
406 *p++ = *s++;
408 *p = '\0';
409 return stripped;
412 /* Generate code to initialize the register size table. */
414 void
415 expand_builtin_init_dwarf_reg_sizes (address)
416 tree address;
418 int i;
419 enum machine_mode mode = TYPE_MODE (char_type_node);
420 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
421 rtx mem = gen_rtx_MEM (BLKmode, addr);
423 for (i = 0; i < DWARF_FRAME_REGISTERS; i++)
425 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
426 HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]);
428 if (offset < 0)
429 continue;
431 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
435 /* Convert a DWARF call frame info. operation to its string name */
437 static const char *
438 dwarf_cfi_name (cfi_opc)
439 unsigned cfi_opc;
441 switch (cfi_opc)
443 case DW_CFA_advance_loc:
444 return "DW_CFA_advance_loc";
445 case DW_CFA_offset:
446 return "DW_CFA_offset";
447 case DW_CFA_restore:
448 return "DW_CFA_restore";
449 case DW_CFA_nop:
450 return "DW_CFA_nop";
451 case DW_CFA_set_loc:
452 return "DW_CFA_set_loc";
453 case DW_CFA_advance_loc1:
454 return "DW_CFA_advance_loc1";
455 case DW_CFA_advance_loc2:
456 return "DW_CFA_advance_loc2";
457 case DW_CFA_advance_loc4:
458 return "DW_CFA_advance_loc4";
459 case DW_CFA_offset_extended:
460 return "DW_CFA_offset_extended";
461 case DW_CFA_restore_extended:
462 return "DW_CFA_restore_extended";
463 case DW_CFA_undefined:
464 return "DW_CFA_undefined";
465 case DW_CFA_same_value:
466 return "DW_CFA_same_value";
467 case DW_CFA_register:
468 return "DW_CFA_register";
469 case DW_CFA_remember_state:
470 return "DW_CFA_remember_state";
471 case DW_CFA_restore_state:
472 return "DW_CFA_restore_state";
473 case DW_CFA_def_cfa:
474 return "DW_CFA_def_cfa";
475 case DW_CFA_def_cfa_register:
476 return "DW_CFA_def_cfa_register";
477 case DW_CFA_def_cfa_offset:
478 return "DW_CFA_def_cfa_offset";
480 /* DWARF 3 */
481 case DW_CFA_def_cfa_expression:
482 return "DW_CFA_def_cfa_expression";
483 case DW_CFA_expression:
484 return "DW_CFA_expression";
485 case DW_CFA_offset_extended_sf:
486 return "DW_CFA_offset_extended_sf";
487 case DW_CFA_def_cfa_sf:
488 return "DW_CFA_def_cfa_sf";
489 case DW_CFA_def_cfa_offset_sf:
490 return "DW_CFA_def_cfa_offset_sf";
492 /* SGI/MIPS specific */
493 case DW_CFA_MIPS_advance_loc8:
494 return "DW_CFA_MIPS_advance_loc8";
496 /* GNU extensions */
497 case DW_CFA_GNU_window_save:
498 return "DW_CFA_GNU_window_save";
499 case DW_CFA_GNU_args_size:
500 return "DW_CFA_GNU_args_size";
501 case DW_CFA_GNU_negative_offset_extended:
502 return "DW_CFA_GNU_negative_offset_extended";
504 default:
505 return "DW_CFA_<unknown>";
509 /* Return a pointer to a newly allocated Call Frame Instruction. */
511 static inline dw_cfi_ref
512 new_cfi ()
514 dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
516 cfi->dw_cfi_next = NULL;
517 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
518 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
520 return cfi;
523 /* Add a Call Frame Instruction to list of instructions. */
525 static inline void
526 add_cfi (list_head, cfi)
527 dw_cfi_ref *list_head;
528 dw_cfi_ref cfi;
530 dw_cfi_ref *p;
532 /* Find the end of the chain. */
533 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
536 *p = cfi;
539 /* Generate a new label for the CFI info to refer to. */
541 char *
542 dwarf2out_cfi_label ()
544 static char label[20];
545 static unsigned long label_num = 0;
547 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
548 ASM_OUTPUT_LABEL (asm_out_file, label);
549 return label;
552 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
553 or to the CIE if LABEL is NULL. */
555 static void
556 add_fde_cfi (label, cfi)
557 const char *label;
558 dw_cfi_ref cfi;
560 if (label)
562 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
564 if (*label == 0)
565 label = dwarf2out_cfi_label ();
567 if (fde->dw_fde_current_label == NULL
568 || strcmp (label, fde->dw_fde_current_label) != 0)
570 dw_cfi_ref xcfi;
572 fde->dw_fde_current_label = label = xstrdup (label);
574 /* Set the location counter to the new label. */
575 xcfi = new_cfi ();
576 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
577 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
578 add_cfi (&fde->dw_fde_cfi, xcfi);
581 add_cfi (&fde->dw_fde_cfi, cfi);
584 else
585 add_cfi (&cie_cfi_head, cfi);
588 /* Subroutine of lookup_cfa. */
590 static inline void
591 lookup_cfa_1 (cfi, loc)
592 dw_cfi_ref cfi;
593 dw_cfa_location *loc;
595 switch (cfi->dw_cfi_opc)
597 case DW_CFA_def_cfa_offset:
598 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
599 break;
600 case DW_CFA_def_cfa_register:
601 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
602 break;
603 case DW_CFA_def_cfa:
604 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
605 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
606 break;
607 case DW_CFA_def_cfa_expression:
608 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
609 break;
610 default:
611 break;
615 /* Find the previous value for the CFA. */
617 static void
618 lookup_cfa (loc)
619 dw_cfa_location *loc;
621 dw_cfi_ref cfi;
623 loc->reg = (unsigned long) -1;
624 loc->offset = 0;
625 loc->indirect = 0;
626 loc->base_offset = 0;
628 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
629 lookup_cfa_1 (cfi, loc);
631 if (fde_table_in_use)
633 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
634 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
635 lookup_cfa_1 (cfi, loc);
639 /* The current rule for calculating the DWARF2 canonical frame address. */
640 static dw_cfa_location cfa;
642 /* The register used for saving registers to the stack, and its offset
643 from the CFA. */
644 static dw_cfa_location cfa_store;
646 /* The running total of the size of arguments pushed onto the stack. */
647 static long args_size;
649 /* The last args_size we actually output. */
650 static long old_args_size;
652 /* Entry point to update the canonical frame address (CFA).
653 LABEL is passed to add_fde_cfi. The value of CFA is now to be
654 calculated from REG+OFFSET. */
656 void
657 dwarf2out_def_cfa (label, reg, offset)
658 const char *label;
659 unsigned reg;
660 long offset;
662 dw_cfa_location loc;
663 loc.indirect = 0;
664 loc.base_offset = 0;
665 loc.reg = reg;
666 loc.offset = offset;
667 def_cfa_1 (label, &loc);
670 /* This routine does the actual work. The CFA is now calculated from
671 the dw_cfa_location structure. */
673 static void
674 def_cfa_1 (label, loc_p)
675 const char *label;
676 dw_cfa_location *loc_p;
678 dw_cfi_ref cfi;
679 dw_cfa_location old_cfa, loc;
681 cfa = *loc_p;
682 loc = *loc_p;
684 if (cfa_store.reg == loc.reg && loc.indirect == 0)
685 cfa_store.offset = loc.offset;
687 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
688 lookup_cfa (&old_cfa);
690 /* If nothing changed, no need to issue any call frame instructions. */
691 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
692 && loc.indirect == old_cfa.indirect
693 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
694 return;
696 cfi = new_cfi ();
698 if (loc.reg == old_cfa.reg && !loc.indirect)
700 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
701 indicating the CFA register did not change but the offset
702 did. */
703 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
704 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
707 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
708 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
709 && !loc.indirect)
711 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
712 indicating the CFA register has changed to <register> but the
713 offset has not changed. */
714 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
715 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
717 #endif
719 else if (loc.indirect == 0)
721 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
722 indicating the CFA register has changed to <register> with
723 the specified offset. */
724 cfi->dw_cfi_opc = DW_CFA_def_cfa;
725 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
726 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
728 else
730 /* Construct a DW_CFA_def_cfa_expression instruction to
731 calculate the CFA using a full location expression since no
732 register-offset pair is available. */
733 struct dw_loc_descr_struct *loc_list;
735 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
736 loc_list = build_cfa_loc (&loc);
737 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
740 add_fde_cfi (label, cfi);
743 /* Add the CFI for saving a register. REG is the CFA column number.
744 LABEL is passed to add_fde_cfi.
745 If SREG is -1, the register is saved at OFFSET from the CFA;
746 otherwise it is saved in SREG. */
748 static void
749 reg_save (label, reg, sreg, offset)
750 const char *label;
751 unsigned reg;
752 unsigned sreg;
753 long offset;
755 dw_cfi_ref cfi = new_cfi ();
757 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
759 /* The following comparison is correct. -1 is used to indicate that
760 the value isn't a register number. */
761 if (sreg == (unsigned int) -1)
763 if (reg & ~0x3f)
764 /* The register number won't fit in 6 bits, so we have to use
765 the long form. */
766 cfi->dw_cfi_opc = DW_CFA_offset_extended;
767 else
768 cfi->dw_cfi_opc = DW_CFA_offset;
770 #ifdef ENABLE_CHECKING
772 /* If we get an offset that is not a multiple of
773 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
774 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
775 description. */
776 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
778 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
779 abort ();
781 #endif
782 offset /= DWARF_CIE_DATA_ALIGNMENT;
783 if (offset < 0)
784 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
786 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
788 else if (sreg == reg)
789 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
790 return;
791 else
793 cfi->dw_cfi_opc = DW_CFA_register;
794 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
797 add_fde_cfi (label, cfi);
800 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
801 This CFI tells the unwinder that it needs to restore the window registers
802 from the previous frame's window save area.
804 ??? Perhaps we should note in the CIE where windows are saved (instead of
805 assuming 0(cfa)) and what registers are in the window. */
807 void
808 dwarf2out_window_save (label)
809 const char *label;
811 dw_cfi_ref cfi = new_cfi ();
813 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
814 add_fde_cfi (label, cfi);
817 /* Add a CFI to update the running total of the size of arguments
818 pushed onto the stack. */
820 void
821 dwarf2out_args_size (label, size)
822 const char *label;
823 long size;
825 dw_cfi_ref cfi;
827 if (size == old_args_size)
828 return;
830 old_args_size = size;
832 cfi = new_cfi ();
833 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
834 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
835 add_fde_cfi (label, cfi);
838 /* Entry point for saving a register to the stack. REG is the GCC register
839 number. LABEL and OFFSET are passed to reg_save. */
841 void
842 dwarf2out_reg_save (label, reg, offset)
843 const char *label;
844 unsigned reg;
845 long offset;
847 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
850 /* Entry point for saving the return address in the stack.
851 LABEL and OFFSET are passed to reg_save. */
853 void
854 dwarf2out_return_save (label, offset)
855 const char *label;
856 long offset;
858 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
861 /* Entry point for saving the return address in a register.
862 LABEL and SREG are passed to reg_save. */
864 void
865 dwarf2out_return_reg (label, sreg)
866 const char *label;
867 unsigned sreg;
869 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
872 /* Record the initial position of the return address. RTL is
873 INCOMING_RETURN_ADDR_RTX. */
875 static void
876 initial_return_save (rtl)
877 rtx rtl;
879 unsigned int reg = (unsigned int) -1;
880 HOST_WIDE_INT offset = 0;
882 switch (GET_CODE (rtl))
884 case REG:
885 /* RA is in a register. */
886 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
887 break;
889 case MEM:
890 /* RA is on the stack. */
891 rtl = XEXP (rtl, 0);
892 switch (GET_CODE (rtl))
894 case REG:
895 if (REGNO (rtl) != STACK_POINTER_REGNUM)
896 abort ();
897 offset = 0;
898 break;
900 case PLUS:
901 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
902 abort ();
903 offset = INTVAL (XEXP (rtl, 1));
904 break;
906 case MINUS:
907 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
908 abort ();
909 offset = -INTVAL (XEXP (rtl, 1));
910 break;
912 default:
913 abort ();
916 break;
918 case PLUS:
919 /* The return address is at some offset from any value we can
920 actually load. For instance, on the SPARC it is in %i7+8. Just
921 ignore the offset for now; it doesn't matter for unwinding frames. */
922 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
923 abort ();
924 initial_return_save (XEXP (rtl, 0));
925 return;
927 default:
928 abort ();
931 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
934 /* Given a SET, calculate the amount of stack adjustment it
935 contains. */
937 static long
938 stack_adjust_offset (pattern)
939 rtx pattern;
941 rtx src = SET_SRC (pattern);
942 rtx dest = SET_DEST (pattern);
943 HOST_WIDE_INT offset = 0;
944 enum rtx_code code;
946 if (dest == stack_pointer_rtx)
948 /* (set (reg sp) (plus (reg sp) (const_int))) */
949 code = GET_CODE (src);
950 if (! (code == PLUS || code == MINUS)
951 || XEXP (src, 0) != stack_pointer_rtx
952 || GET_CODE (XEXP (src, 1)) != CONST_INT)
953 return 0;
955 offset = INTVAL (XEXP (src, 1));
956 if (code == PLUS)
957 offset = -offset;
959 else if (GET_CODE (dest) == MEM)
961 /* (set (mem (pre_dec (reg sp))) (foo)) */
962 src = XEXP (dest, 0);
963 code = GET_CODE (src);
965 switch (code)
967 case PRE_MODIFY:
968 case POST_MODIFY:
969 if (XEXP (src, 0) == stack_pointer_rtx)
971 rtx val = XEXP (XEXP (src, 1), 1);
972 /* We handle only adjustments by constant amount. */
973 if (GET_CODE (XEXP (src, 1)) != PLUS ||
974 GET_CODE (val) != CONST_INT)
975 abort ();
976 offset = -INTVAL (val);
977 break;
979 return 0;
981 case PRE_DEC:
982 case POST_DEC:
983 if (XEXP (src, 0) == stack_pointer_rtx)
985 offset = GET_MODE_SIZE (GET_MODE (dest));
986 break;
988 return 0;
990 case PRE_INC:
991 case POST_INC:
992 if (XEXP (src, 0) == stack_pointer_rtx)
994 offset = -GET_MODE_SIZE (GET_MODE (dest));
995 break;
997 return 0;
999 default:
1000 return 0;
1003 else
1004 return 0;
1006 return offset;
1009 /* Check INSN to see if it looks like a push or a stack adjustment, and
1010 make a note of it if it does. EH uses this information to find out how
1011 much extra space it needs to pop off the stack. */
1013 static void
1014 dwarf2out_stack_adjust (insn)
1015 rtx insn;
1017 HOST_WIDE_INT offset;
1018 const char *label;
1019 int i;
1021 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1023 /* Extract the size of the args from the CALL rtx itself. */
1024 insn = PATTERN (insn);
1025 if (GET_CODE (insn) == PARALLEL)
1026 insn = XVECEXP (insn, 0, 0);
1027 if (GET_CODE (insn) == SET)
1028 insn = SET_SRC (insn);
1029 if (GET_CODE (insn) != CALL)
1030 abort ();
1032 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1033 return;
1036 /* If only calls can throw, and we have a frame pointer,
1037 save up adjustments until we see the CALL_INSN. */
1038 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1039 return;
1041 if (GET_CODE (insn) == BARRIER)
1043 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1044 the compiler will have already emitted a stack adjustment, but
1045 doesn't bother for calls to noreturn functions. */
1046 #ifdef STACK_GROWS_DOWNWARD
1047 offset = -args_size;
1048 #else
1049 offset = args_size;
1050 #endif
1052 else if (GET_CODE (PATTERN (insn)) == SET)
1053 offset = stack_adjust_offset (PATTERN (insn));
1054 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1055 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1057 /* There may be stack adjustments inside compound insns. Search
1058 for them. */
1059 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1060 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1061 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1063 else
1064 return;
1066 if (offset == 0)
1067 return;
1069 if (cfa.reg == STACK_POINTER_REGNUM)
1070 cfa.offset += offset;
1072 #ifndef STACK_GROWS_DOWNWARD
1073 offset = -offset;
1074 #endif
1076 args_size += offset;
1077 if (args_size < 0)
1078 args_size = 0;
1080 label = dwarf2out_cfi_label ();
1081 def_cfa_1 (label, &cfa);
1082 dwarf2out_args_size (label, args_size);
1085 /* We delay emitting a register save until either (a) we reach the end
1086 of the prologue or (b) the register is clobbered. This clusters
1087 register saves so that there are fewer pc advances. */
1089 struct queued_reg_save
1091 struct queued_reg_save *next;
1092 rtx reg;
1093 long cfa_offset;
1096 static struct queued_reg_save *queued_reg_saves;
1097 static const char *last_reg_save_label;
1099 static void
1100 queue_reg_save (label, reg, offset)
1101 const char *label;
1102 rtx reg;
1103 long offset;
1105 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1107 q->next = queued_reg_saves;
1108 q->reg = reg;
1109 q->cfa_offset = offset;
1110 queued_reg_saves = q;
1112 last_reg_save_label = label;
1115 static void
1116 flush_queued_reg_saves ()
1118 struct queued_reg_save *q, *next;
1120 for (q = queued_reg_saves; q; q = next)
1122 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1123 next = q->next;
1124 free (q);
1127 queued_reg_saves = NULL;
1128 last_reg_save_label = NULL;
1131 static bool
1132 clobbers_queued_reg_save (insn)
1133 rtx insn;
1135 struct queued_reg_save *q;
1137 for (q = queued_reg_saves; q; q = q->next)
1138 if (modified_in_p (q->reg, insn))
1139 return true;
1141 return false;
1145 /* A temporary register holding an integral value used in adjusting SP
1146 or setting up the store_reg. The "offset" field holds the integer
1147 value, not an offset. */
1148 static dw_cfa_location cfa_temp;
1150 /* Record call frame debugging information for an expression EXPR,
1151 which either sets SP or FP (adjusting how we calculate the frame
1152 address) or saves a register to the stack. LABEL indicates the
1153 address of EXPR.
1155 This function encodes a state machine mapping rtxes to actions on
1156 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1157 users need not read the source code.
1159 The High-Level Picture
1161 Changes in the register we use to calculate the CFA: Currently we
1162 assume that if you copy the CFA register into another register, we
1163 should take the other one as the new CFA register; this seems to
1164 work pretty well. If it's wrong for some target, it's simple
1165 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1167 Changes in the register we use for saving registers to the stack:
1168 This is usually SP, but not always. Again, we deduce that if you
1169 copy SP into another register (and SP is not the CFA register),
1170 then the new register is the one we will be using for register
1171 saves. This also seems to work.
1173 Register saves: There's not much guesswork about this one; if
1174 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1175 register save, and the register used to calculate the destination
1176 had better be the one we think we're using for this purpose.
1178 Except: If the register being saved is the CFA register, and the
1179 offset is non-zero, we are saving the CFA, so we assume we have to
1180 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1181 the intent is to save the value of SP from the previous frame.
1183 Invariants / Summaries of Rules
1185 cfa current rule for calculating the CFA. It usually
1186 consists of a register and an offset.
1187 cfa_store register used by prologue code to save things to the stack
1188 cfa_store.offset is the offset from the value of
1189 cfa_store.reg to the actual CFA
1190 cfa_temp register holding an integral value. cfa_temp.offset
1191 stores the value, which will be used to adjust the
1192 stack pointer. cfa_temp is also used like cfa_store,
1193 to track stores to the stack via fp or a temp reg.
1195 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1196 with cfa.reg as the first operand changes the cfa.reg and its
1197 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1198 cfa_temp.offset.
1200 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1201 expression yielding a constant. This sets cfa_temp.reg
1202 and cfa_temp.offset.
1204 Rule 5: Create a new register cfa_store used to save items to the
1205 stack.
1207 Rules 10-14: Save a register to the stack. Define offset as the
1208 difference of the original location and cfa_store's
1209 location (or cfa_temp's location if cfa_temp is used).
1211 The Rules
1213 "{a,b}" indicates a choice of a xor b.
1214 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1216 Rule 1:
1217 (set <reg1> <reg2>:cfa.reg)
1218 effects: cfa.reg = <reg1>
1219 cfa.offset unchanged
1220 cfa_temp.reg = <reg1>
1221 cfa_temp.offset = cfa.offset
1223 Rule 2:
1224 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1225 {<const_int>,<reg>:cfa_temp.reg}))
1226 effects: cfa.reg = sp if fp used
1227 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1228 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1229 if cfa_store.reg==sp
1231 Rule 3:
1232 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1233 effects: cfa.reg = fp
1234 cfa_offset += +/- <const_int>
1236 Rule 4:
1237 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1238 constraints: <reg1> != fp
1239 <reg1> != sp
1240 effects: cfa.reg = <reg1>
1241 cfa_temp.reg = <reg1>
1242 cfa_temp.offset = cfa.offset
1244 Rule 5:
1245 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1246 constraints: <reg1> != fp
1247 <reg1> != sp
1248 effects: cfa_store.reg = <reg1>
1249 cfa_store.offset = cfa.offset - cfa_temp.offset
1251 Rule 6:
1252 (set <reg> <const_int>)
1253 effects: cfa_temp.reg = <reg>
1254 cfa_temp.offset = <const_int>
1256 Rule 7:
1257 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1258 effects: cfa_temp.reg = <reg1>
1259 cfa_temp.offset |= <const_int>
1261 Rule 8:
1262 (set <reg> (high <exp>))
1263 effects: none
1265 Rule 9:
1266 (set <reg> (lo_sum <exp> <const_int>))
1267 effects: cfa_temp.reg = <reg>
1268 cfa_temp.offset = <const_int>
1270 Rule 10:
1271 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1272 effects: cfa_store.offset -= <const_int>
1273 cfa.offset = cfa_store.offset if cfa.reg == sp
1274 cfa.reg = sp
1275 cfa.base_offset = -cfa_store.offset
1277 Rule 11:
1278 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1279 effects: cfa_store.offset += -/+ mode_size(mem)
1280 cfa.offset = cfa_store.offset if cfa.reg == sp
1281 cfa.reg = sp
1282 cfa.base_offset = -cfa_store.offset
1284 Rule 12:
1285 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1287 <reg2>)
1288 effects: cfa.reg = <reg1>
1289 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1291 Rule 13:
1292 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1293 effects: cfa.reg = <reg1>
1294 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1296 Rule 14:
1297 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1298 effects: cfa.reg = <reg1>
1299 cfa.base_offset = -cfa_temp.offset
1300 cfa_temp.offset -= mode_size(mem) */
1302 static void
1303 dwarf2out_frame_debug_expr (expr, label)
1304 rtx expr;
1305 const char *label;
1307 rtx src, dest;
1308 HOST_WIDE_INT offset;
1310 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1311 the PARALLEL independently. The first element is always processed if
1312 it is a SET. This is for backward compatibility. Other elements
1313 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1314 flag is set in them. */
1315 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1317 int par_index;
1318 int limit = XVECLEN (expr, 0);
1320 for (par_index = 0; par_index < limit; par_index++)
1321 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1322 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1323 || par_index == 0))
1324 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1326 return;
1329 if (GET_CODE (expr) != SET)
1330 abort ();
1332 src = SET_SRC (expr);
1333 dest = SET_DEST (expr);
1335 switch (GET_CODE (dest))
1337 case REG:
1338 /* Rule 1 */
1339 /* Update the CFA rule wrt SP or FP. Make sure src is
1340 relative to the current CFA register. */
1341 switch (GET_CODE (src))
1343 /* Setting FP from SP. */
1344 case REG:
1345 if (cfa.reg == (unsigned) REGNO (src))
1346 /* OK. */
1348 else
1349 abort ();
1351 /* We used to require that dest be either SP or FP, but the
1352 ARM copies SP to a temporary register, and from there to
1353 FP. So we just rely on the backends to only set
1354 RTX_FRAME_RELATED_P on appropriate insns. */
1355 cfa.reg = REGNO (dest);
1356 cfa_temp.reg = cfa.reg;
1357 cfa_temp.offset = cfa.offset;
1358 break;
1360 case PLUS:
1361 case MINUS:
1362 case LO_SUM:
1363 if (dest == stack_pointer_rtx)
1365 /* Rule 2 */
1366 /* Adjusting SP. */
1367 switch (GET_CODE (XEXP (src, 1)))
1369 case CONST_INT:
1370 offset = INTVAL (XEXP (src, 1));
1371 break;
1372 case REG:
1373 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1374 abort ();
1375 offset = cfa_temp.offset;
1376 break;
1377 default:
1378 abort ();
1381 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1383 /* Restoring SP from FP in the epilogue. */
1384 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1385 abort ();
1386 cfa.reg = STACK_POINTER_REGNUM;
1388 else if (GET_CODE (src) == LO_SUM)
1389 /* Assume we've set the source reg of the LO_SUM from sp. */
1391 else if (XEXP (src, 0) != stack_pointer_rtx)
1392 abort ();
1394 if (GET_CODE (src) != MINUS)
1395 offset = -offset;
1396 if (cfa.reg == STACK_POINTER_REGNUM)
1397 cfa.offset += offset;
1398 if (cfa_store.reg == STACK_POINTER_REGNUM)
1399 cfa_store.offset += offset;
1401 else if (dest == hard_frame_pointer_rtx)
1403 /* Rule 3 */
1404 /* Either setting the FP from an offset of the SP,
1405 or adjusting the FP */
1406 if (! frame_pointer_needed)
1407 abort ();
1409 if (GET_CODE (XEXP (src, 0)) == REG
1410 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1411 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1413 offset = INTVAL (XEXP (src, 1));
1414 if (GET_CODE (src) != MINUS)
1415 offset = -offset;
1416 cfa.offset += offset;
1417 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1419 else
1420 abort ();
1422 else
1424 if (GET_CODE (src) == MINUS)
1425 abort ();
1427 /* Rule 4 */
1428 if (GET_CODE (XEXP (src, 0)) == REG
1429 && REGNO (XEXP (src, 0)) == cfa.reg
1430 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1432 /* Setting a temporary CFA register that will be copied
1433 into the FP later on. */
1434 offset = - INTVAL (XEXP (src, 1));
1435 cfa.offset += offset;
1436 cfa.reg = REGNO (dest);
1437 /* Or used to save regs to the stack. */
1438 cfa_temp.reg = cfa.reg;
1439 cfa_temp.offset = cfa.offset;
1442 /* Rule 5 */
1443 else if (GET_CODE (XEXP (src, 0)) == REG
1444 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1445 && XEXP (src, 1) == stack_pointer_rtx)
1447 /* Setting a scratch register that we will use instead
1448 of SP for saving registers to the stack. */
1449 if (cfa.reg != STACK_POINTER_REGNUM)
1450 abort ();
1451 cfa_store.reg = REGNO (dest);
1452 cfa_store.offset = cfa.offset - cfa_temp.offset;
1455 /* Rule 9 */
1456 else if (GET_CODE (src) == LO_SUM
1457 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1459 cfa_temp.reg = REGNO (dest);
1460 cfa_temp.offset = INTVAL (XEXP (src, 1));
1462 else
1463 abort ();
1465 break;
1467 /* Rule 6 */
1468 case CONST_INT:
1469 cfa_temp.reg = REGNO (dest);
1470 cfa_temp.offset = INTVAL (src);
1471 break;
1473 /* Rule 7 */
1474 case IOR:
1475 if (GET_CODE (XEXP (src, 0)) != REG
1476 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1477 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1478 abort ();
1480 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1481 cfa_temp.reg = REGNO (dest);
1482 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1483 break;
1485 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1486 which will fill in all of the bits. */
1487 /* Rule 8 */
1488 case HIGH:
1489 break;
1491 default:
1492 abort ();
1495 def_cfa_1 (label, &cfa);
1496 break;
1498 case MEM:
1499 if (GET_CODE (src) != REG)
1500 abort ();
1502 /* Saving a register to the stack. Make sure dest is relative to the
1503 CFA register. */
1504 switch (GET_CODE (XEXP (dest, 0)))
1506 /* Rule 10 */
1507 /* With a push. */
1508 case PRE_MODIFY:
1509 /* We can't handle variable size modifications. */
1510 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1511 abort ();
1512 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1514 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1515 || cfa_store.reg != STACK_POINTER_REGNUM)
1516 abort ();
1518 cfa_store.offset += offset;
1519 if (cfa.reg == STACK_POINTER_REGNUM)
1520 cfa.offset = cfa_store.offset;
1522 offset = -cfa_store.offset;
1523 break;
1525 /* Rule 11 */
1526 case PRE_INC:
1527 case PRE_DEC:
1528 offset = GET_MODE_SIZE (GET_MODE (dest));
1529 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1530 offset = -offset;
1532 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1533 || cfa_store.reg != STACK_POINTER_REGNUM)
1534 abort ();
1536 cfa_store.offset += offset;
1537 if (cfa.reg == STACK_POINTER_REGNUM)
1538 cfa.offset = cfa_store.offset;
1540 offset = -cfa_store.offset;
1541 break;
1543 /* Rule 12 */
1544 /* With an offset. */
1545 case PLUS:
1546 case MINUS:
1547 case LO_SUM:
1548 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1549 abort ();
1550 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1551 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1552 offset = -offset;
1554 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1555 offset -= cfa_store.offset;
1556 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1557 offset -= cfa_temp.offset;
1558 else
1559 abort ();
1560 break;
1562 /* Rule 13 */
1563 /* Without an offset. */
1564 case REG:
1565 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1566 offset = -cfa_store.offset;
1567 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1568 offset = -cfa_temp.offset;
1569 else
1570 abort ();
1571 break;
1573 /* Rule 14 */
1574 case POST_INC:
1575 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1576 abort ();
1577 offset = -cfa_temp.offset;
1578 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1579 break;
1581 default:
1582 abort ();
1585 if (REGNO (src) != STACK_POINTER_REGNUM
1586 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1587 && (unsigned) REGNO (src) == cfa.reg)
1589 /* We're storing the current CFA reg into the stack. */
1591 if (cfa.offset == 0)
1593 /* If the source register is exactly the CFA, assume
1594 we're saving SP like any other register; this happens
1595 on the ARM. */
1596 def_cfa_1 (label, &cfa);
1597 queue_reg_save (label, stack_pointer_rtx, offset);
1598 break;
1600 else
1602 /* Otherwise, we'll need to look in the stack to
1603 calculate the CFA. */
1604 rtx x = XEXP (dest, 0);
1606 if (GET_CODE (x) != REG)
1607 x = XEXP (x, 0);
1608 if (GET_CODE (x) != REG)
1609 abort ();
1611 cfa.reg = REGNO (x);
1612 cfa.base_offset = offset;
1613 cfa.indirect = 1;
1614 def_cfa_1 (label, &cfa);
1615 break;
1619 def_cfa_1 (label, &cfa);
1620 queue_reg_save (label, src, offset);
1621 break;
1623 default:
1624 abort ();
1628 /* Record call frame debugging information for INSN, which either
1629 sets SP or FP (adjusting how we calculate the frame address) or saves a
1630 register to the stack. If INSN is NULL_RTX, initialize our state. */
1632 void
1633 dwarf2out_frame_debug (insn)
1634 rtx insn;
1636 const char *label;
1637 rtx src;
1639 if (insn == NULL_RTX)
1641 /* Flush any queued register saves. */
1642 flush_queued_reg_saves ();
1644 /* Set up state for generating call frame debug info. */
1645 lookup_cfa (&cfa);
1646 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1647 abort ();
1649 cfa.reg = STACK_POINTER_REGNUM;
1650 cfa_store = cfa;
1651 cfa_temp.reg = -1;
1652 cfa_temp.offset = 0;
1653 return;
1656 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1657 flush_queued_reg_saves ();
1659 if (! RTX_FRAME_RELATED_P (insn))
1661 if (!ACCUMULATE_OUTGOING_ARGS)
1662 dwarf2out_stack_adjust (insn);
1664 return;
1667 label = dwarf2out_cfi_label ();
1668 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1669 if (src)
1670 insn = XEXP (src, 0);
1671 else
1672 insn = PATTERN (insn);
1674 dwarf2out_frame_debug_expr (insn, label);
1677 /* Output a Call Frame Information opcode and its operand(s). */
1679 static void
1680 output_cfi (cfi, fde, for_eh)
1681 dw_cfi_ref cfi;
1682 dw_fde_ref fde;
1683 int for_eh;
1685 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1686 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1687 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1688 "DW_CFA_advance_loc 0x%lx",
1689 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1690 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1692 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1693 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1694 "DW_CFA_offset, column 0x%lx",
1695 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1696 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1698 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1699 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1700 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1701 "DW_CFA_restore, column 0x%lx",
1702 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1703 else
1705 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1706 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1708 switch (cfi->dw_cfi_opc)
1710 case DW_CFA_set_loc:
1711 if (for_eh)
1712 dw2_asm_output_encoded_addr_rtx (
1713 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1714 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1715 NULL);
1716 else
1717 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1718 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1719 break;
1721 case DW_CFA_advance_loc1:
1722 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1723 fde->dw_fde_current_label, NULL);
1724 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1725 break;
1727 case DW_CFA_advance_loc2:
1728 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1729 fde->dw_fde_current_label, NULL);
1730 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1731 break;
1733 case DW_CFA_advance_loc4:
1734 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1735 fde->dw_fde_current_label, NULL);
1736 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1737 break;
1739 case DW_CFA_MIPS_advance_loc8:
1740 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1741 fde->dw_fde_current_label, NULL);
1742 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1743 break;
1745 case DW_CFA_offset_extended:
1746 case DW_CFA_def_cfa:
1747 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1748 NULL);
1749 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1750 break;
1752 case DW_CFA_offset_extended_sf:
1753 case DW_CFA_def_cfa_sf:
1754 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1755 NULL);
1756 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1757 break;
1759 case DW_CFA_restore_extended:
1760 case DW_CFA_undefined:
1761 case DW_CFA_same_value:
1762 case DW_CFA_def_cfa_register:
1763 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1764 NULL);
1765 break;
1767 case DW_CFA_register:
1768 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1769 NULL);
1770 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1771 NULL);
1772 break;
1774 case DW_CFA_def_cfa_offset:
1775 case DW_CFA_GNU_args_size:
1776 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1777 break;
1779 case DW_CFA_def_cfa_offset_sf:
1780 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1781 break;
1783 case DW_CFA_GNU_window_save:
1784 break;
1786 case DW_CFA_def_cfa_expression:
1787 case DW_CFA_expression:
1788 output_cfa_loc (cfi);
1789 break;
1791 case DW_CFA_GNU_negative_offset_extended:
1792 /* Obsoleted by DW_CFA_offset_extended_sf. */
1793 abort ();
1795 default:
1796 break;
1801 /* Output the call frame information used to used to record information
1802 that relates to calculating the frame pointer, and records the
1803 location of saved registers. */
1805 static void
1806 output_call_frame_info (for_eh)
1807 int for_eh;
1809 unsigned int i;
1810 dw_fde_ref fde;
1811 dw_cfi_ref cfi;
1812 char l1[20], l2[20], section_start_label[20];
1813 int any_lsda_needed = 0;
1814 char augmentation[6];
1815 int augmentation_size;
1816 int fde_encoding = DW_EH_PE_absptr;
1817 int per_encoding = DW_EH_PE_absptr;
1818 int lsda_encoding = DW_EH_PE_absptr;
1820 /* Don't emit a CIE if there won't be any FDEs. */
1821 if (fde_table_in_use == 0)
1822 return;
1824 /* If we don't have any functions we'll want to unwind out of, don't emit any
1825 EH unwind information. */
1826 if (for_eh)
1828 int any_eh_needed = flag_asynchronous_unwind_tables;
1830 for (i = 0; i < fde_table_in_use; i++)
1831 if (fde_table[i].uses_eh_lsda)
1832 any_eh_needed = any_lsda_needed = 1;
1833 else if (! fde_table[i].nothrow)
1834 any_eh_needed = 1;
1836 if (! any_eh_needed)
1837 return;
1840 /* We're going to be generating comments, so turn on app. */
1841 if (flag_debug_asm)
1842 app_enable ();
1844 if (for_eh)
1845 (*targetm.asm_out.eh_frame_section) ();
1846 else
1847 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1849 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1850 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1852 /* Output the CIE. */
1853 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1854 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1855 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1856 "Length of Common Information Entry");
1857 ASM_OUTPUT_LABEL (asm_out_file, l1);
1859 /* Now that the CIE pointer is PC-relative for EH,
1860 use 0 to identify the CIE. */
1861 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1862 (for_eh ? 0 : DW_CIE_ID),
1863 "CIE Identifier Tag");
1865 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1867 augmentation[0] = 0;
1868 augmentation_size = 0;
1869 if (for_eh)
1871 char *p;
1873 /* Augmentation:
1874 z Indicates that a uleb128 is present to size the
1875 augmentation section.
1876 L Indicates the encoding (and thus presence) of
1877 an LSDA pointer in the FDE augmentation.
1878 R Indicates a non-default pointer encoding for
1879 FDE code pointers.
1880 P Indicates the presence of an encoding + language
1881 personality routine in the CIE augmentation. */
1883 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1884 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1885 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1887 p = augmentation + 1;
1888 if (eh_personality_libfunc)
1890 *p++ = 'P';
1891 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1893 if (any_lsda_needed)
1895 *p++ = 'L';
1896 augmentation_size += 1;
1898 if (fde_encoding != DW_EH_PE_absptr)
1900 *p++ = 'R';
1901 augmentation_size += 1;
1903 if (p > augmentation + 1)
1905 augmentation[0] = 'z';
1906 *p = '\0';
1909 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1910 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1912 int offset = ( 4 /* Length */
1913 + 4 /* CIE Id */
1914 + 1 /* CIE version */
1915 + strlen (augmentation) + 1 /* Augmentation */
1916 + size_of_uleb128 (1) /* Code alignment */
1917 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1918 + 1 /* RA column */
1919 + 1 /* Augmentation size */
1920 + 1 /* Personality encoding */ );
1921 int pad = -offset & (PTR_SIZE - 1);
1923 augmentation_size += pad;
1925 /* Augmentations should be small, so there's scarce need to
1926 iterate for a solution. Die if we exceed one uleb128 byte. */
1927 if (size_of_uleb128 (augmentation_size) != 1)
1928 abort ();
1932 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1933 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1934 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1935 "CIE Data Alignment Factor");
1936 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1938 if (augmentation[0])
1940 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1941 if (eh_personality_libfunc)
1943 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1944 eh_data_format_name (per_encoding));
1945 dw2_asm_output_encoded_addr_rtx (per_encoding,
1946 eh_personality_libfunc, NULL);
1949 if (any_lsda_needed)
1950 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1951 eh_data_format_name (lsda_encoding));
1953 if (fde_encoding != DW_EH_PE_absptr)
1954 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1955 eh_data_format_name (fde_encoding));
1958 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1959 output_cfi (cfi, NULL, for_eh);
1961 /* Pad the CIE out to an address sized boundary. */
1962 ASM_OUTPUT_ALIGN (asm_out_file,
1963 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1964 ASM_OUTPUT_LABEL (asm_out_file, l2);
1966 /* Loop through all of the FDE's. */
1967 for (i = 0; i < fde_table_in_use; i++)
1969 fde = &fde_table[i];
1971 /* Don't emit EH unwind info for leaf functions that don't need it. */
1972 if (!flag_asynchronous_unwind_tables && for_eh && fde->nothrow
1973 && ! fde->uses_eh_lsda)
1974 continue;
1976 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1977 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1978 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1979 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1980 "FDE Length");
1981 ASM_OUTPUT_LABEL (asm_out_file, l1);
1983 if (for_eh)
1984 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
1985 else
1986 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
1987 "FDE CIE offset");
1989 if (for_eh)
1991 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1992 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1993 "FDE initial location");
1994 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1995 fde->dw_fde_end, fde->dw_fde_begin,
1996 "FDE address range");
1998 else
2000 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2001 "FDE initial location");
2002 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2003 fde->dw_fde_end, fde->dw_fde_begin,
2004 "FDE address range");
2007 if (augmentation[0])
2009 if (any_lsda_needed)
2011 int size = size_of_encoded_value (lsda_encoding);
2013 if (lsda_encoding == DW_EH_PE_aligned)
2015 int offset = ( 4 /* Length */
2016 + 4 /* CIE offset */
2017 + 2 * size_of_encoded_value (fde_encoding)
2018 + 1 /* Augmentation size */ );
2019 int pad = -offset & (PTR_SIZE - 1);
2021 size += pad;
2022 if (size_of_uleb128 (size) != 1)
2023 abort ();
2026 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2028 if (fde->uses_eh_lsda)
2030 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2031 fde->funcdef_number);
2032 dw2_asm_output_encoded_addr_rtx (
2033 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2034 "Language Specific Data Area");
2036 else
2038 if (lsda_encoding == DW_EH_PE_aligned)
2039 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2040 dw2_asm_output_data
2041 (size_of_encoded_value (lsda_encoding), 0,
2042 "Language Specific Data Area (none)");
2045 else
2046 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2049 /* Loop through the Call Frame Instructions associated with
2050 this FDE. */
2051 fde->dw_fde_current_label = fde->dw_fde_begin;
2052 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2053 output_cfi (cfi, fde, for_eh);
2055 /* Pad the FDE out to an address sized boundary. */
2056 ASM_OUTPUT_ALIGN (asm_out_file,
2057 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2058 ASM_OUTPUT_LABEL (asm_out_file, l2);
2061 #ifndef EH_FRAME_SECTION_NAME
2062 if (for_eh)
2063 dw2_asm_output_data (4, 0, "End of Table");
2064 #endif
2065 #ifdef MIPS_DEBUGGING_INFO
2066 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2067 get a value of 0. Putting .align 0 after the label fixes it. */
2068 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2069 #endif
2071 /* Turn off app to make assembly quicker. */
2072 if (flag_debug_asm)
2073 app_disable ();
2076 /* Output a marker (i.e. a label) for the beginning of a function, before
2077 the prologue. */
2079 void
2080 dwarf2out_begin_prologue (line, file)
2081 unsigned int line ATTRIBUTE_UNUSED;
2082 const char *file ATTRIBUTE_UNUSED;
2084 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2085 dw_fde_ref fde;
2087 current_function_func_begin_label = 0;
2089 #ifdef IA64_UNWIND_INFO
2090 /* ??? current_function_func_begin_label is also used by except.c
2091 for call-site information. We must emit this label if it might
2092 be used. */
2093 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2094 && ! dwarf2out_do_frame ())
2095 return;
2096 #else
2097 if (! dwarf2out_do_frame ())
2098 return;
2099 #endif
2101 current_funcdef_number++;
2102 function_section (current_function_decl);
2103 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2104 current_funcdef_number);
2105 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2106 current_funcdef_number);
2107 current_function_func_begin_label = get_identifier (label);
2109 #ifdef IA64_UNWIND_INFO
2110 /* We can elide the fde allocation if we're not emitting debug info. */
2111 if (! dwarf2out_do_frame ())
2112 return;
2113 #endif
2115 /* Expand the fde table if necessary. */
2116 if (fde_table_in_use == fde_table_allocated)
2118 fde_table_allocated += FDE_TABLE_INCREMENT;
2119 fde_table
2120 = (dw_fde_ref) xrealloc (fde_table,
2121 fde_table_allocated * sizeof (dw_fde_node));
2124 /* Record the FDE associated with this function. */
2125 current_funcdef_fde = fde_table_in_use;
2127 /* Add the new FDE at the end of the fde_table. */
2128 fde = &fde_table[fde_table_in_use++];
2129 fde->dw_fde_begin = xstrdup (label);
2130 fde->dw_fde_current_label = NULL;
2131 fde->dw_fde_end = NULL;
2132 fde->dw_fde_cfi = NULL;
2133 fde->funcdef_number = current_funcdef_number;
2134 fde->nothrow = current_function_nothrow;
2135 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2137 args_size = old_args_size = 0;
2139 /* We only want to output line number information for the genuine dwarf2
2140 prologue case, not the eh frame case. */
2141 #ifdef DWARF2_DEBUGGING_INFO
2142 if (file)
2143 dwarf2out_source_line (line, file);
2144 #endif
2147 /* Output a marker (i.e. a label) for the absolute end of the generated code
2148 for a function definition. This gets called *after* the epilogue code has
2149 been generated. */
2151 void
2152 dwarf2out_end_epilogue ()
2154 dw_fde_ref fde;
2155 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2157 /* Output a label to mark the endpoint of the code generated for this
2158 function. */
2159 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2160 ASM_OUTPUT_LABEL (asm_out_file, label);
2161 fde = &fde_table[fde_table_in_use - 1];
2162 fde->dw_fde_end = xstrdup (label);
2165 void
2166 dwarf2out_frame_init ()
2168 /* Allocate the initial hunk of the fde_table. */
2169 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2170 fde_table_allocated = FDE_TABLE_INCREMENT;
2171 fde_table_in_use = 0;
2173 /* Generate the CFA instructions common to all FDE's. Do it now for the
2174 sake of lookup_cfa. */
2176 #ifdef DWARF2_UNWIND_INFO
2177 /* On entry, the Canonical Frame Address is at SP. */
2178 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2179 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2180 #endif
2183 void
2184 dwarf2out_frame_finish ()
2186 /* Output call frame information. */
2187 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2188 output_call_frame_info (0);
2190 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2191 output_call_frame_info (1);
2194 /* And now, the subset of the debugging information support code necessary
2195 for emitting location expressions. */
2197 typedef struct dw_val_struct *dw_val_ref;
2198 typedef struct die_struct *dw_die_ref;
2199 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2200 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2202 /* Each DIE may have a series of attribute/value pairs. Values
2203 can take on several forms. The forms that are used in this
2204 implementation are listed below. */
2206 typedef enum
2208 dw_val_class_addr,
2209 dw_val_class_offset,
2210 dw_val_class_loc,
2211 dw_val_class_loc_list,
2212 dw_val_class_range_list,
2213 dw_val_class_const,
2214 dw_val_class_unsigned_const,
2215 dw_val_class_long_long,
2216 dw_val_class_float,
2217 dw_val_class_flag,
2218 dw_val_class_die_ref,
2219 dw_val_class_fde_ref,
2220 dw_val_class_lbl_id,
2221 dw_val_class_lbl_offset,
2222 dw_val_class_str
2224 dw_val_class;
2226 /* Describe a double word constant value. */
2227 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2229 typedef struct dw_long_long_struct
2231 unsigned long hi;
2232 unsigned long low;
2234 dw_long_long_const;
2236 /* Describe a floating point constant value. */
2238 typedef struct dw_fp_struct
2240 long *array;
2241 unsigned length;
2243 dw_float_const;
2245 /* The dw_val_node describes an attribute's value, as it is
2246 represented internally. */
2248 typedef struct dw_val_struct
2250 dw_val_class val_class;
2251 union
2253 rtx val_addr;
2254 long unsigned val_offset;
2255 dw_loc_list_ref val_loc_list;
2256 dw_loc_descr_ref val_loc;
2257 long int val_int;
2258 long unsigned val_unsigned;
2259 dw_long_long_const val_long_long;
2260 dw_float_const val_float;
2261 struct
2263 dw_die_ref die;
2264 int external;
2265 } val_die_ref;
2266 unsigned val_fde_index;
2267 struct indirect_string_node *val_str;
2268 char *val_lbl_id;
2269 unsigned char val_flag;
2273 dw_val_node;
2275 /* Locations in memory are described using a sequence of stack machine
2276 operations. */
2278 typedef struct dw_loc_descr_struct
2280 dw_loc_descr_ref dw_loc_next;
2281 enum dwarf_location_atom dw_loc_opc;
2282 dw_val_node dw_loc_oprnd1;
2283 dw_val_node dw_loc_oprnd2;
2284 int dw_loc_addr;
2286 dw_loc_descr_node;
2288 /* Location lists are ranges + location descriptions for that range,
2289 so you can track variables that are in different places over
2290 their entire life. */
2291 typedef struct dw_loc_list_struct
2293 dw_loc_list_ref dw_loc_next;
2294 const char *begin; /* Label for begin address of range */
2295 const char *end; /* Label for end address of range */
2296 char *ll_symbol; /* Label for beginning of location list.
2297 Only on head of list */
2298 const char *section; /* Section this loclist is relative to */
2299 dw_loc_descr_ref expr;
2300 } dw_loc_list_node;
2302 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2303 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2304 unsigned long,
2305 unsigned long));
2306 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2307 dw_loc_descr_ref));
2308 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2309 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2310 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2311 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2313 /* Convert a DWARF stack opcode into its string name. */
2315 static const char *
2316 dwarf_stack_op_name (op)
2317 unsigned op;
2319 switch (op)
2321 case DW_OP_addr:
2322 return "DW_OP_addr";
2323 case DW_OP_deref:
2324 return "DW_OP_deref";
2325 case DW_OP_const1u:
2326 return "DW_OP_const1u";
2327 case DW_OP_const1s:
2328 return "DW_OP_const1s";
2329 case DW_OP_const2u:
2330 return "DW_OP_const2u";
2331 case DW_OP_const2s:
2332 return "DW_OP_const2s";
2333 case DW_OP_const4u:
2334 return "DW_OP_const4u";
2335 case DW_OP_const4s:
2336 return "DW_OP_const4s";
2337 case DW_OP_const8u:
2338 return "DW_OP_const8u";
2339 case DW_OP_const8s:
2340 return "DW_OP_const8s";
2341 case DW_OP_constu:
2342 return "DW_OP_constu";
2343 case DW_OP_consts:
2344 return "DW_OP_consts";
2345 case DW_OP_dup:
2346 return "DW_OP_dup";
2347 case DW_OP_drop:
2348 return "DW_OP_drop";
2349 case DW_OP_over:
2350 return "DW_OP_over";
2351 case DW_OP_pick:
2352 return "DW_OP_pick";
2353 case DW_OP_swap:
2354 return "DW_OP_swap";
2355 case DW_OP_rot:
2356 return "DW_OP_rot";
2357 case DW_OP_xderef:
2358 return "DW_OP_xderef";
2359 case DW_OP_abs:
2360 return "DW_OP_abs";
2361 case DW_OP_and:
2362 return "DW_OP_and";
2363 case DW_OP_div:
2364 return "DW_OP_div";
2365 case DW_OP_minus:
2366 return "DW_OP_minus";
2367 case DW_OP_mod:
2368 return "DW_OP_mod";
2369 case DW_OP_mul:
2370 return "DW_OP_mul";
2371 case DW_OP_neg:
2372 return "DW_OP_neg";
2373 case DW_OP_not:
2374 return "DW_OP_not";
2375 case DW_OP_or:
2376 return "DW_OP_or";
2377 case DW_OP_plus:
2378 return "DW_OP_plus";
2379 case DW_OP_plus_uconst:
2380 return "DW_OP_plus_uconst";
2381 case DW_OP_shl:
2382 return "DW_OP_shl";
2383 case DW_OP_shr:
2384 return "DW_OP_shr";
2385 case DW_OP_shra:
2386 return "DW_OP_shra";
2387 case DW_OP_xor:
2388 return "DW_OP_xor";
2389 case DW_OP_bra:
2390 return "DW_OP_bra";
2391 case DW_OP_eq:
2392 return "DW_OP_eq";
2393 case DW_OP_ge:
2394 return "DW_OP_ge";
2395 case DW_OP_gt:
2396 return "DW_OP_gt";
2397 case DW_OP_le:
2398 return "DW_OP_le";
2399 case DW_OP_lt:
2400 return "DW_OP_lt";
2401 case DW_OP_ne:
2402 return "DW_OP_ne";
2403 case DW_OP_skip:
2404 return "DW_OP_skip";
2405 case DW_OP_lit0:
2406 return "DW_OP_lit0";
2407 case DW_OP_lit1:
2408 return "DW_OP_lit1";
2409 case DW_OP_lit2:
2410 return "DW_OP_lit2";
2411 case DW_OP_lit3:
2412 return "DW_OP_lit3";
2413 case DW_OP_lit4:
2414 return "DW_OP_lit4";
2415 case DW_OP_lit5:
2416 return "DW_OP_lit5";
2417 case DW_OP_lit6:
2418 return "DW_OP_lit6";
2419 case DW_OP_lit7:
2420 return "DW_OP_lit7";
2421 case DW_OP_lit8:
2422 return "DW_OP_lit8";
2423 case DW_OP_lit9:
2424 return "DW_OP_lit9";
2425 case DW_OP_lit10:
2426 return "DW_OP_lit10";
2427 case DW_OP_lit11:
2428 return "DW_OP_lit11";
2429 case DW_OP_lit12:
2430 return "DW_OP_lit12";
2431 case DW_OP_lit13:
2432 return "DW_OP_lit13";
2433 case DW_OP_lit14:
2434 return "DW_OP_lit14";
2435 case DW_OP_lit15:
2436 return "DW_OP_lit15";
2437 case DW_OP_lit16:
2438 return "DW_OP_lit16";
2439 case DW_OP_lit17:
2440 return "DW_OP_lit17";
2441 case DW_OP_lit18:
2442 return "DW_OP_lit18";
2443 case DW_OP_lit19:
2444 return "DW_OP_lit19";
2445 case DW_OP_lit20:
2446 return "DW_OP_lit20";
2447 case DW_OP_lit21:
2448 return "DW_OP_lit21";
2449 case DW_OP_lit22:
2450 return "DW_OP_lit22";
2451 case DW_OP_lit23:
2452 return "DW_OP_lit23";
2453 case DW_OP_lit24:
2454 return "DW_OP_lit24";
2455 case DW_OP_lit25:
2456 return "DW_OP_lit25";
2457 case DW_OP_lit26:
2458 return "DW_OP_lit26";
2459 case DW_OP_lit27:
2460 return "DW_OP_lit27";
2461 case DW_OP_lit28:
2462 return "DW_OP_lit28";
2463 case DW_OP_lit29:
2464 return "DW_OP_lit29";
2465 case DW_OP_lit30:
2466 return "DW_OP_lit30";
2467 case DW_OP_lit31:
2468 return "DW_OP_lit31";
2469 case DW_OP_reg0:
2470 return "DW_OP_reg0";
2471 case DW_OP_reg1:
2472 return "DW_OP_reg1";
2473 case DW_OP_reg2:
2474 return "DW_OP_reg2";
2475 case DW_OP_reg3:
2476 return "DW_OP_reg3";
2477 case DW_OP_reg4:
2478 return "DW_OP_reg4";
2479 case DW_OP_reg5:
2480 return "DW_OP_reg5";
2481 case DW_OP_reg6:
2482 return "DW_OP_reg6";
2483 case DW_OP_reg7:
2484 return "DW_OP_reg7";
2485 case DW_OP_reg8:
2486 return "DW_OP_reg8";
2487 case DW_OP_reg9:
2488 return "DW_OP_reg9";
2489 case DW_OP_reg10:
2490 return "DW_OP_reg10";
2491 case DW_OP_reg11:
2492 return "DW_OP_reg11";
2493 case DW_OP_reg12:
2494 return "DW_OP_reg12";
2495 case DW_OP_reg13:
2496 return "DW_OP_reg13";
2497 case DW_OP_reg14:
2498 return "DW_OP_reg14";
2499 case DW_OP_reg15:
2500 return "DW_OP_reg15";
2501 case DW_OP_reg16:
2502 return "DW_OP_reg16";
2503 case DW_OP_reg17:
2504 return "DW_OP_reg17";
2505 case DW_OP_reg18:
2506 return "DW_OP_reg18";
2507 case DW_OP_reg19:
2508 return "DW_OP_reg19";
2509 case DW_OP_reg20:
2510 return "DW_OP_reg20";
2511 case DW_OP_reg21:
2512 return "DW_OP_reg21";
2513 case DW_OP_reg22:
2514 return "DW_OP_reg22";
2515 case DW_OP_reg23:
2516 return "DW_OP_reg23";
2517 case DW_OP_reg24:
2518 return "DW_OP_reg24";
2519 case DW_OP_reg25:
2520 return "DW_OP_reg25";
2521 case DW_OP_reg26:
2522 return "DW_OP_reg26";
2523 case DW_OP_reg27:
2524 return "DW_OP_reg27";
2525 case DW_OP_reg28:
2526 return "DW_OP_reg28";
2527 case DW_OP_reg29:
2528 return "DW_OP_reg29";
2529 case DW_OP_reg30:
2530 return "DW_OP_reg30";
2531 case DW_OP_reg31:
2532 return "DW_OP_reg31";
2533 case DW_OP_breg0:
2534 return "DW_OP_breg0";
2535 case DW_OP_breg1:
2536 return "DW_OP_breg1";
2537 case DW_OP_breg2:
2538 return "DW_OP_breg2";
2539 case DW_OP_breg3:
2540 return "DW_OP_breg3";
2541 case DW_OP_breg4:
2542 return "DW_OP_breg4";
2543 case DW_OP_breg5:
2544 return "DW_OP_breg5";
2545 case DW_OP_breg6:
2546 return "DW_OP_breg6";
2547 case DW_OP_breg7:
2548 return "DW_OP_breg7";
2549 case DW_OP_breg8:
2550 return "DW_OP_breg8";
2551 case DW_OP_breg9:
2552 return "DW_OP_breg9";
2553 case DW_OP_breg10:
2554 return "DW_OP_breg10";
2555 case DW_OP_breg11:
2556 return "DW_OP_breg11";
2557 case DW_OP_breg12:
2558 return "DW_OP_breg12";
2559 case DW_OP_breg13:
2560 return "DW_OP_breg13";
2561 case DW_OP_breg14:
2562 return "DW_OP_breg14";
2563 case DW_OP_breg15:
2564 return "DW_OP_breg15";
2565 case DW_OP_breg16:
2566 return "DW_OP_breg16";
2567 case DW_OP_breg17:
2568 return "DW_OP_breg17";
2569 case DW_OP_breg18:
2570 return "DW_OP_breg18";
2571 case DW_OP_breg19:
2572 return "DW_OP_breg19";
2573 case DW_OP_breg20:
2574 return "DW_OP_breg20";
2575 case DW_OP_breg21:
2576 return "DW_OP_breg21";
2577 case DW_OP_breg22:
2578 return "DW_OP_breg22";
2579 case DW_OP_breg23:
2580 return "DW_OP_breg23";
2581 case DW_OP_breg24:
2582 return "DW_OP_breg24";
2583 case DW_OP_breg25:
2584 return "DW_OP_breg25";
2585 case DW_OP_breg26:
2586 return "DW_OP_breg26";
2587 case DW_OP_breg27:
2588 return "DW_OP_breg27";
2589 case DW_OP_breg28:
2590 return "DW_OP_breg28";
2591 case DW_OP_breg29:
2592 return "DW_OP_breg29";
2593 case DW_OP_breg30:
2594 return "DW_OP_breg30";
2595 case DW_OP_breg31:
2596 return "DW_OP_breg31";
2597 case DW_OP_regx:
2598 return "DW_OP_regx";
2599 case DW_OP_fbreg:
2600 return "DW_OP_fbreg";
2601 case DW_OP_bregx:
2602 return "DW_OP_bregx";
2603 case DW_OP_piece:
2604 return "DW_OP_piece";
2605 case DW_OP_deref_size:
2606 return "DW_OP_deref_size";
2607 case DW_OP_xderef_size:
2608 return "DW_OP_xderef_size";
2609 case DW_OP_nop:
2610 return "DW_OP_nop";
2611 default:
2612 return "OP_<unknown>";
2616 /* Return a pointer to a newly allocated location description. Location
2617 descriptions are simple expression terms that can be strung
2618 together to form more complicated location (address) descriptions. */
2620 static inline dw_loc_descr_ref
2621 new_loc_descr (op, oprnd1, oprnd2)
2622 enum dwarf_location_atom op;
2623 unsigned long oprnd1;
2624 unsigned long oprnd2;
2626 /* Use xcalloc here so we clear out all of the long_long constant in
2627 the union. */
2628 dw_loc_descr_ref descr
2629 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2631 descr->dw_loc_opc = op;
2632 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2633 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2634 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2635 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2637 return descr;
2641 /* Add a location description term to a location description expression. */
2643 static inline void
2644 add_loc_descr (list_head, descr)
2645 dw_loc_descr_ref *list_head;
2646 dw_loc_descr_ref descr;
2648 dw_loc_descr_ref *d;
2650 /* Find the end of the chain. */
2651 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2654 *d = descr;
2657 /* Return the size of a location descriptor. */
2659 static unsigned long
2660 size_of_loc_descr (loc)
2661 dw_loc_descr_ref loc;
2663 unsigned long size = 1;
2665 switch (loc->dw_loc_opc)
2667 case DW_OP_addr:
2668 size += DWARF2_ADDR_SIZE;
2669 break;
2670 case DW_OP_const1u:
2671 case DW_OP_const1s:
2672 size += 1;
2673 break;
2674 case DW_OP_const2u:
2675 case DW_OP_const2s:
2676 size += 2;
2677 break;
2678 case DW_OP_const4u:
2679 case DW_OP_const4s:
2680 size += 4;
2681 break;
2682 case DW_OP_const8u:
2683 case DW_OP_const8s:
2684 size += 8;
2685 break;
2686 case DW_OP_constu:
2687 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2688 break;
2689 case DW_OP_consts:
2690 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2691 break;
2692 case DW_OP_pick:
2693 size += 1;
2694 break;
2695 case DW_OP_plus_uconst:
2696 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2697 break;
2698 case DW_OP_skip:
2699 case DW_OP_bra:
2700 size += 2;
2701 break;
2702 case DW_OP_breg0:
2703 case DW_OP_breg1:
2704 case DW_OP_breg2:
2705 case DW_OP_breg3:
2706 case DW_OP_breg4:
2707 case DW_OP_breg5:
2708 case DW_OP_breg6:
2709 case DW_OP_breg7:
2710 case DW_OP_breg8:
2711 case DW_OP_breg9:
2712 case DW_OP_breg10:
2713 case DW_OP_breg11:
2714 case DW_OP_breg12:
2715 case DW_OP_breg13:
2716 case DW_OP_breg14:
2717 case DW_OP_breg15:
2718 case DW_OP_breg16:
2719 case DW_OP_breg17:
2720 case DW_OP_breg18:
2721 case DW_OP_breg19:
2722 case DW_OP_breg20:
2723 case DW_OP_breg21:
2724 case DW_OP_breg22:
2725 case DW_OP_breg23:
2726 case DW_OP_breg24:
2727 case DW_OP_breg25:
2728 case DW_OP_breg26:
2729 case DW_OP_breg27:
2730 case DW_OP_breg28:
2731 case DW_OP_breg29:
2732 case DW_OP_breg30:
2733 case DW_OP_breg31:
2734 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2735 break;
2736 case DW_OP_regx:
2737 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2738 break;
2739 case DW_OP_fbreg:
2740 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2741 break;
2742 case DW_OP_bregx:
2743 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2744 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2745 break;
2746 case DW_OP_piece:
2747 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2748 break;
2749 case DW_OP_deref_size:
2750 case DW_OP_xderef_size:
2751 size += 1;
2752 break;
2753 default:
2754 break;
2757 return size;
2760 /* Return the size of a series of location descriptors. */
2762 static unsigned long
2763 size_of_locs (loc)
2764 dw_loc_descr_ref loc;
2766 unsigned long size;
2768 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2770 loc->dw_loc_addr = size;
2771 size += size_of_loc_descr (loc);
2774 return size;
2777 /* Output location description stack opcode's operands (if any). */
2779 static void
2780 output_loc_operands (loc)
2781 dw_loc_descr_ref loc;
2783 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2784 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2786 switch (loc->dw_loc_opc)
2788 #ifdef DWARF2_DEBUGGING_INFO
2789 case DW_OP_addr:
2790 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2791 break;
2792 case DW_OP_const2u:
2793 case DW_OP_const2s:
2794 dw2_asm_output_data (2, val1->v.val_int, NULL);
2795 break;
2796 case DW_OP_const4u:
2797 case DW_OP_const4s:
2798 dw2_asm_output_data (4, val1->v.val_int, NULL);
2799 break;
2800 case DW_OP_const8u:
2801 case DW_OP_const8s:
2802 if (HOST_BITS_PER_LONG < 64)
2803 abort ();
2804 dw2_asm_output_data (8, val1->v.val_int, NULL);
2805 break;
2806 case DW_OP_skip:
2807 case DW_OP_bra:
2809 int offset;
2811 if (val1->val_class == dw_val_class_loc)
2812 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2813 else
2814 abort ();
2816 dw2_asm_output_data (2, offset, NULL);
2818 break;
2819 #else
2820 case DW_OP_addr:
2821 case DW_OP_const2u:
2822 case DW_OP_const2s:
2823 case DW_OP_const4u:
2824 case DW_OP_const4s:
2825 case DW_OP_const8u:
2826 case DW_OP_const8s:
2827 case DW_OP_skip:
2828 case DW_OP_bra:
2829 /* We currently don't make any attempt to make sure these are
2830 aligned properly like we do for the main unwind info, so
2831 don't support emitting things larger than a byte if we're
2832 only doing unwinding. */
2833 abort ();
2834 #endif
2835 case DW_OP_const1u:
2836 case DW_OP_const1s:
2837 dw2_asm_output_data (1, val1->v.val_int, NULL);
2838 break;
2839 case DW_OP_constu:
2840 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2841 break;
2842 case DW_OP_consts:
2843 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2844 break;
2845 case DW_OP_pick:
2846 dw2_asm_output_data (1, val1->v.val_int, NULL);
2847 break;
2848 case DW_OP_plus_uconst:
2849 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2850 break;
2851 case DW_OP_breg0:
2852 case DW_OP_breg1:
2853 case DW_OP_breg2:
2854 case DW_OP_breg3:
2855 case DW_OP_breg4:
2856 case DW_OP_breg5:
2857 case DW_OP_breg6:
2858 case DW_OP_breg7:
2859 case DW_OP_breg8:
2860 case DW_OP_breg9:
2861 case DW_OP_breg10:
2862 case DW_OP_breg11:
2863 case DW_OP_breg12:
2864 case DW_OP_breg13:
2865 case DW_OP_breg14:
2866 case DW_OP_breg15:
2867 case DW_OP_breg16:
2868 case DW_OP_breg17:
2869 case DW_OP_breg18:
2870 case DW_OP_breg19:
2871 case DW_OP_breg20:
2872 case DW_OP_breg21:
2873 case DW_OP_breg22:
2874 case DW_OP_breg23:
2875 case DW_OP_breg24:
2876 case DW_OP_breg25:
2877 case DW_OP_breg26:
2878 case DW_OP_breg27:
2879 case DW_OP_breg28:
2880 case DW_OP_breg29:
2881 case DW_OP_breg30:
2882 case DW_OP_breg31:
2883 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2884 break;
2885 case DW_OP_regx:
2886 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2887 break;
2888 case DW_OP_fbreg:
2889 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2890 break;
2891 case DW_OP_bregx:
2892 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2893 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2894 break;
2895 case DW_OP_piece:
2896 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2897 break;
2898 case DW_OP_deref_size:
2899 case DW_OP_xderef_size:
2900 dw2_asm_output_data (1, val1->v.val_int, NULL);
2901 break;
2902 default:
2903 /* Other codes have no operands. */
2904 break;
2908 /* Output a sequence of location operations. */
2910 static void
2911 output_loc_sequence (loc)
2912 dw_loc_descr_ref loc;
2914 for (; loc != NULL; loc = loc->dw_loc_next)
2916 /* Output the opcode. */
2917 dw2_asm_output_data (1, loc->dw_loc_opc,
2918 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2920 /* Output the operand(s) (if any). */
2921 output_loc_operands (loc);
2925 /* This routine will generate the correct assembly data for a location
2926 description based on a cfi entry with a complex address. */
2928 static void
2929 output_cfa_loc (cfi)
2930 dw_cfi_ref cfi;
2932 dw_loc_descr_ref loc;
2933 unsigned long size;
2935 /* Output the size of the block. */
2936 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2937 size = size_of_locs (loc);
2938 dw2_asm_output_data_uleb128 (size, NULL);
2940 /* Now output the operations themselves. */
2941 output_loc_sequence (loc);
2944 /* This function builds a dwarf location descriptor sequence from
2945 a dw_cfa_location. */
2947 static struct dw_loc_descr_struct *
2948 build_cfa_loc (cfa)
2949 dw_cfa_location *cfa;
2951 struct dw_loc_descr_struct *head, *tmp;
2953 if (cfa->indirect == 0)
2954 abort ();
2956 if (cfa->base_offset)
2958 if (cfa->reg <= 31)
2959 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2960 else
2961 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2963 else if (cfa->reg <= 31)
2964 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2965 else
2966 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2968 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2969 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2970 add_loc_descr (&head, tmp);
2971 if (cfa->offset != 0)
2973 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2974 add_loc_descr (&head, tmp);
2977 return head;
2980 /* This function fills in aa dw_cfa_location structure from a dwarf location
2981 descriptor sequence. */
2983 static void
2984 get_cfa_from_loc_descr (cfa, loc)
2985 dw_cfa_location *cfa;
2986 struct dw_loc_descr_struct *loc;
2988 struct dw_loc_descr_struct *ptr;
2989 cfa->offset = 0;
2990 cfa->base_offset = 0;
2991 cfa->indirect = 0;
2992 cfa->reg = -1;
2994 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2996 enum dwarf_location_atom op = ptr->dw_loc_opc;
2998 switch (op)
3000 case DW_OP_reg0:
3001 case DW_OP_reg1:
3002 case DW_OP_reg2:
3003 case DW_OP_reg3:
3004 case DW_OP_reg4:
3005 case DW_OP_reg5:
3006 case DW_OP_reg6:
3007 case DW_OP_reg7:
3008 case DW_OP_reg8:
3009 case DW_OP_reg9:
3010 case DW_OP_reg10:
3011 case DW_OP_reg11:
3012 case DW_OP_reg12:
3013 case DW_OP_reg13:
3014 case DW_OP_reg14:
3015 case DW_OP_reg15:
3016 case DW_OP_reg16:
3017 case DW_OP_reg17:
3018 case DW_OP_reg18:
3019 case DW_OP_reg19:
3020 case DW_OP_reg20:
3021 case DW_OP_reg21:
3022 case DW_OP_reg22:
3023 case DW_OP_reg23:
3024 case DW_OP_reg24:
3025 case DW_OP_reg25:
3026 case DW_OP_reg26:
3027 case DW_OP_reg27:
3028 case DW_OP_reg28:
3029 case DW_OP_reg29:
3030 case DW_OP_reg30:
3031 case DW_OP_reg31:
3032 cfa->reg = op - DW_OP_reg0;
3033 break;
3034 case DW_OP_regx:
3035 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3036 break;
3037 case DW_OP_breg0:
3038 case DW_OP_breg1:
3039 case DW_OP_breg2:
3040 case DW_OP_breg3:
3041 case DW_OP_breg4:
3042 case DW_OP_breg5:
3043 case DW_OP_breg6:
3044 case DW_OP_breg7:
3045 case DW_OP_breg8:
3046 case DW_OP_breg9:
3047 case DW_OP_breg10:
3048 case DW_OP_breg11:
3049 case DW_OP_breg12:
3050 case DW_OP_breg13:
3051 case DW_OP_breg14:
3052 case DW_OP_breg15:
3053 case DW_OP_breg16:
3054 case DW_OP_breg17:
3055 case DW_OP_breg18:
3056 case DW_OP_breg19:
3057 case DW_OP_breg20:
3058 case DW_OP_breg21:
3059 case DW_OP_breg22:
3060 case DW_OP_breg23:
3061 case DW_OP_breg24:
3062 case DW_OP_breg25:
3063 case DW_OP_breg26:
3064 case DW_OP_breg27:
3065 case DW_OP_breg28:
3066 case DW_OP_breg29:
3067 case DW_OP_breg30:
3068 case DW_OP_breg31:
3069 cfa->reg = op - DW_OP_breg0;
3070 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3071 break;
3072 case DW_OP_bregx:
3073 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3074 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3075 break;
3076 case DW_OP_deref:
3077 cfa->indirect = 1;
3078 break;
3079 case DW_OP_plus_uconst:
3080 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3081 break;
3082 default:
3083 internal_error ("DW_LOC_OP %s not implemented\n",
3084 dwarf_stack_op_name (ptr->dw_loc_opc));
3088 #endif /* .debug_frame support */
3090 /* And now, the support for symbolic debugging information. */
3091 #ifdef DWARF2_DEBUGGING_INFO
3093 /* .debug_str support. */
3094 static hashnode indirect_string_alloc PARAMS ((hash_table *));
3095 static int output_indirect_string PARAMS ((struct cpp_reader *,
3096 hashnode, const PTR));
3099 static void dwarf2out_init PARAMS ((const char *));
3100 static void dwarf2out_finish PARAMS ((const char *));
3101 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3102 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3103 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3104 static void dwarf2out_end_source_file PARAMS ((unsigned));
3105 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3106 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3107 static bool dwarf2out_ignore_block PARAMS ((tree));
3108 static void dwarf2out_global_decl PARAMS ((tree));
3109 static void dwarf2out_abstract_function PARAMS ((tree));
3111 /* The debug hooks structure. */
3113 const struct gcc_debug_hooks dwarf2_debug_hooks =
3115 dwarf2out_init,
3116 dwarf2out_finish,
3117 dwarf2out_define,
3118 dwarf2out_undef,
3119 dwarf2out_start_source_file,
3120 dwarf2out_end_source_file,
3121 dwarf2out_begin_block,
3122 dwarf2out_end_block,
3123 dwarf2out_ignore_block,
3124 dwarf2out_source_line,
3125 dwarf2out_begin_prologue,
3126 debug_nothing_int, /* end_prologue */
3127 dwarf2out_end_epilogue,
3128 debug_nothing_tree, /* begin_function */
3129 debug_nothing_int, /* end_function */
3130 dwarf2out_decl, /* function_decl */
3131 dwarf2out_global_decl,
3132 debug_nothing_tree, /* deferred_inline_function */
3133 /* The DWARF 2 backend tries to reduce debugging bloat by not
3134 emitting the abstract description of inline functions until
3135 something tries to reference them. */
3136 dwarf2out_abstract_function, /* outlining_inline_function */
3137 debug_nothing_rtx /* label */
3140 /* NOTE: In the comments in this file, many references are made to
3141 "Debugging Information Entries". This term is abbreviated as `DIE'
3142 throughout the remainder of this file. */
3144 /* An internal representation of the DWARF output is built, and then
3145 walked to generate the DWARF debugging info. The walk of the internal
3146 representation is done after the entire program has been compiled.
3147 The types below are used to describe the internal representation. */
3149 /* Various DIE's use offsets relative to the beginning of the
3150 .debug_info section to refer to each other. */
3152 typedef long int dw_offset;
3154 /* Define typedefs here to avoid circular dependencies. */
3156 typedef struct dw_attr_struct *dw_attr_ref;
3157 typedef struct dw_line_info_struct *dw_line_info_ref;
3158 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3159 typedef struct pubname_struct *pubname_ref;
3160 typedef struct dw_ranges_struct *dw_ranges_ref;
3162 /* Each entry in the line_info_table maintains the file and
3163 line number associated with the label generated for that
3164 entry. The label gives the PC value associated with
3165 the line number entry. */
3167 typedef struct dw_line_info_struct
3169 unsigned long dw_file_num;
3170 unsigned long dw_line_num;
3172 dw_line_info_entry;
3174 /* Line information for functions in separate sections; each one gets its
3175 own sequence. */
3176 typedef struct dw_separate_line_info_struct
3178 unsigned long dw_file_num;
3179 unsigned long dw_line_num;
3180 unsigned long function;
3182 dw_separate_line_info_entry;
3184 /* Each DIE attribute has a field specifying the attribute kind,
3185 a link to the next attribute in the chain, and an attribute value.
3186 Attributes are typically linked below the DIE they modify. */
3188 typedef struct dw_attr_struct
3190 enum dwarf_attribute dw_attr;
3191 dw_attr_ref dw_attr_next;
3192 dw_val_node dw_attr_val;
3194 dw_attr_node;
3196 /* The Debugging Information Entry (DIE) structure */
3198 typedef struct die_struct
3200 enum dwarf_tag die_tag;
3201 char *die_symbol;
3202 dw_attr_ref die_attr;
3203 dw_die_ref die_parent;
3204 dw_die_ref die_child;
3205 dw_die_ref die_sib;
3206 dw_offset die_offset;
3207 unsigned long die_abbrev;
3208 int die_mark;
3210 die_node;
3212 /* The pubname structure */
3214 typedef struct pubname_struct
3216 dw_die_ref die;
3217 char *name;
3219 pubname_entry;
3221 struct dw_ranges_struct
3223 int block_num;
3226 /* The limbo die list structure. */
3227 typedef struct limbo_die_struct
3229 dw_die_ref die;
3230 tree created_for;
3231 struct limbo_die_struct *next;
3233 limbo_die_node;
3235 /* How to start an assembler comment. */
3236 #ifndef ASM_COMMENT_START
3237 #define ASM_COMMENT_START ";#"
3238 #endif
3240 /* Define a macro which returns non-zero for a TYPE_DECL which was
3241 implicitly generated for a tagged type.
3243 Note that unlike the gcc front end (which generates a NULL named
3244 TYPE_DECL node for each complete tagged type, each array type, and
3245 each function type node created) the g++ front end generates a
3246 _named_ TYPE_DECL node for each tagged type node created.
3247 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3248 generate a DW_TAG_typedef DIE for them. */
3250 #define TYPE_DECL_IS_STUB(decl) \
3251 (DECL_NAME (decl) == NULL_TREE \
3252 || (DECL_ARTIFICIAL (decl) \
3253 && is_tagged_type (TREE_TYPE (decl)) \
3254 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3255 /* This is necessary for stub decls that \
3256 appear in nested inline functions. */ \
3257 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3258 && (decl_ultimate_origin (decl) \
3259 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3261 /* Information concerning the compilation unit's programming
3262 language, and compiler version. */
3264 /* Fixed size portion of the DWARF compilation unit header. */
3265 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3267 /* Fixed size portion of debugging line information prolog. */
3268 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3270 /* Fixed size portion of public names info. */
3271 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3273 /* Fixed size portion of the address range info. */
3274 #define DWARF_ARANGES_HEADER_SIZE \
3275 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3276 - DWARF_OFFSET_SIZE)
3278 /* Size of padding portion in the address range info. It must be
3279 aligned to twice the pointer size. */
3280 #define DWARF_ARANGES_PAD_SIZE \
3281 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3282 - (2 * DWARF_OFFSET_SIZE + 4))
3284 /* Use assembler line directives if available. */
3285 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3286 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3287 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3288 #else
3289 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3290 #endif
3291 #endif
3293 /* Minimum line offset in a special line info. opcode.
3294 This value was chosen to give a reasonable range of values. */
3295 #define DWARF_LINE_BASE -10
3297 /* First special line opcode - leave room for the standard opcodes. */
3298 #define DWARF_LINE_OPCODE_BASE 10
3300 /* Range of line offsets in a special line info. opcode. */
3301 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3303 /* Flag that indicates the initial value of the is_stmt_start flag.
3304 In the present implementation, we do not mark any lines as
3305 the beginning of a source statement, because that information
3306 is not made available by the GCC front-end. */
3307 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3309 /* This location is used by calc_die_sizes() to keep track
3310 the offset of each DIE within the .debug_info section. */
3311 static unsigned long next_die_offset;
3313 /* Record the root of the DIE's built for the current compilation unit. */
3314 static dw_die_ref comp_unit_die;
3316 /* A list of DIEs with a NULL parent waiting to be relocated. */
3317 static limbo_die_node *limbo_die_list = 0;
3319 /* Structure used by lookup_filename to manage sets of filenames. */
3320 struct file_table
3322 char **table;
3323 unsigned allocated;
3324 unsigned in_use;
3325 unsigned last_lookup_index;
3328 /* Size (in elements) of increments by which we may expand the filename
3329 table. */
3330 #define FILE_TABLE_INCREMENT 64
3332 /* Filenames referenced by this compilation unit. */
3333 static struct file_table file_table;
3335 /* Local pointer to the name of the main input file. Initialized in
3336 dwarf2out_init. */
3337 static const char *primary_filename;
3339 /* A pointer to the base of a table of references to DIE's that describe
3340 declarations. The table is indexed by DECL_UID() which is a unique
3341 number identifying each decl. */
3342 static dw_die_ref *decl_die_table;
3344 /* Number of elements currently allocated for the decl_die_table. */
3345 static unsigned decl_die_table_allocated;
3347 /* Number of elements in decl_die_table currently in use. */
3348 static unsigned decl_die_table_in_use;
3350 /* Size (in elements) of increments by which we may expand the
3351 decl_die_table. */
3352 #define DECL_DIE_TABLE_INCREMENT 256
3354 /* A pointer to the base of a table of references to declaration
3355 scopes. This table is a display which tracks the nesting
3356 of declaration scopes at the current scope and containing
3357 scopes. This table is used to find the proper place to
3358 define type declaration DIE's. */
3359 varray_type decl_scope_table;
3361 /* A pointer to the base of a list of references to DIE's that
3362 are uniquely identified by their tag, presence/absence of
3363 children DIE's, and list of attribute/value pairs. */
3364 static dw_die_ref *abbrev_die_table;
3366 /* Number of elements currently allocated for abbrev_die_table. */
3367 static unsigned abbrev_die_table_allocated;
3369 /* Number of elements in type_die_table currently in use. */
3370 static unsigned abbrev_die_table_in_use;
3372 /* Size (in elements) of increments by which we may expand the
3373 abbrev_die_table. */
3374 #define ABBREV_DIE_TABLE_INCREMENT 256
3376 /* A pointer to the base of a table that contains line information
3377 for each source code line in .text in the compilation unit. */
3378 static dw_line_info_ref line_info_table;
3380 /* Number of elements currently allocated for line_info_table. */
3381 static unsigned line_info_table_allocated;
3383 /* Number of elements in separate_line_info_table currently in use. */
3384 static unsigned separate_line_info_table_in_use;
3386 /* A pointer to the base of a table that contains line information
3387 for each source code line outside of .text in the compilation unit. */
3388 static dw_separate_line_info_ref separate_line_info_table;
3390 /* Number of elements currently allocated for separate_line_info_table. */
3391 static unsigned separate_line_info_table_allocated;
3393 /* Number of elements in line_info_table currently in use. */
3394 static unsigned line_info_table_in_use;
3396 /* Size (in elements) of increments by which we may expand the
3397 line_info_table. */
3398 #define LINE_INFO_TABLE_INCREMENT 1024
3400 /* A pointer to the base of a table that contains a list of publicly
3401 accessible names. */
3402 static pubname_ref pubname_table;
3404 /* Number of elements currently allocated for pubname_table. */
3405 static unsigned pubname_table_allocated;
3407 /* Number of elements in pubname_table currently in use. */
3408 static unsigned pubname_table_in_use;
3410 /* Size (in elements) of increments by which we may expand the
3411 pubname_table. */
3412 #define PUBNAME_TABLE_INCREMENT 64
3414 /* Array of dies for which we should generate .debug_arange info. */
3415 static dw_die_ref *arange_table;
3417 /* Number of elements currently allocated for arange_table. */
3418 static unsigned arange_table_allocated;
3420 /* Number of elements in arange_table currently in use. */
3421 static unsigned arange_table_in_use;
3423 /* Size (in elements) of increments by which we may expand the
3424 arange_table. */
3425 #define ARANGE_TABLE_INCREMENT 64
3427 /* Array of dies for which we should generate .debug_ranges info. */
3428 static dw_ranges_ref ranges_table;
3430 /* Number of elements currently allocated for ranges_table. */
3431 static unsigned ranges_table_allocated;
3433 /* Number of elements in ranges_table currently in use. */
3434 static unsigned ranges_table_in_use;
3436 /* Size (in elements) of increments by which we may expand the
3437 ranges_table. */
3438 #define RANGES_TABLE_INCREMENT 64
3440 /* Whether we have location lists that need outputting */
3441 static unsigned have_location_lists;
3443 /* A pointer to the base of a list of incomplete types which might be
3444 completed at some later time. incomplete_types_list needs to be a VARRAY
3445 because we want to tell the garbage collector about it. */
3446 varray_type incomplete_types;
3448 /* Record whether the function being analyzed contains inlined functions. */
3449 static int current_function_has_inlines;
3450 #if 0 && defined (MIPS_DEBUGGING_INFO)
3451 static int comp_unit_has_inlines;
3452 #endif
3454 /* Array of RTXes referenced by the debugging information, which therefore
3455 must be kept around forever. This is a GC root. */
3456 static varray_type used_rtx_varray;
3458 /* Forward declarations for functions defined in this file. */
3460 static int is_pseudo_reg PARAMS ((rtx));
3461 static tree type_main_variant PARAMS ((tree));
3462 static int is_tagged_type PARAMS ((tree));
3463 static const char *dwarf_tag_name PARAMS ((unsigned));
3464 static const char *dwarf_attr_name PARAMS ((unsigned));
3465 static const char *dwarf_form_name PARAMS ((unsigned));
3466 #if 0
3467 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3468 #endif
3469 static tree decl_ultimate_origin PARAMS ((tree));
3470 static tree block_ultimate_origin PARAMS ((tree));
3471 static tree decl_class_context PARAMS ((tree));
3472 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3473 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
3474 static void add_AT_flag PARAMS ((dw_die_ref,
3475 enum dwarf_attribute,
3476 unsigned));
3477 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3478 static void add_AT_int PARAMS ((dw_die_ref,
3479 enum dwarf_attribute, long));
3480 static inline long int AT_int PARAMS ((dw_attr_ref));
3481 static void add_AT_unsigned PARAMS ((dw_die_ref,
3482 enum dwarf_attribute,
3483 unsigned long));
3484 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
3485 static void add_AT_long_long PARAMS ((dw_die_ref,
3486 enum dwarf_attribute,
3487 unsigned long,
3488 unsigned long));
3489 static void add_AT_float PARAMS ((dw_die_ref,
3490 enum dwarf_attribute,
3491 unsigned, long *));
3492 static void add_AT_string PARAMS ((dw_die_ref,
3493 enum dwarf_attribute,
3494 const char *));
3495 static inline const char *AT_string PARAMS ((dw_attr_ref));
3496 static int AT_string_form PARAMS ((dw_attr_ref));
3497 static void add_AT_die_ref PARAMS ((dw_die_ref,
3498 enum dwarf_attribute,
3499 dw_die_ref));
3500 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
3501 static inline int AT_ref_external PARAMS ((dw_attr_ref));
3502 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
3503 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3504 enum dwarf_attribute,
3505 unsigned));
3506 static void add_AT_loc PARAMS ((dw_die_ref,
3507 enum dwarf_attribute,
3508 dw_loc_descr_ref));
3509 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
3510 static void add_AT_loc_list PARAMS ((dw_die_ref,
3511 enum dwarf_attribute,
3512 dw_loc_list_ref));
3513 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
3514 static void add_AT_addr PARAMS ((dw_die_ref,
3515 enum dwarf_attribute,
3516 rtx));
3517 static inline rtx AT_addr PARAMS ((dw_attr_ref));
3518 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3519 enum dwarf_attribute,
3520 const char *));
3521 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3522 enum dwarf_attribute,
3523 const char *));
3524 static void add_AT_offset PARAMS ((dw_die_ref,
3525 enum dwarf_attribute,
3526 unsigned long));
3527 static void add_AT_range_list PARAMS ((dw_die_ref,
3528 enum dwarf_attribute,
3529 unsigned long));
3530 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
3531 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3532 enum dwarf_attribute));
3533 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3534 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3535 static const char *get_AT_string PARAMS ((dw_die_ref,
3536 enum dwarf_attribute));
3537 static int get_AT_flag PARAMS ((dw_die_ref,
3538 enum dwarf_attribute));
3539 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3540 enum dwarf_attribute));
3541 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3542 enum dwarf_attribute));
3543 static int is_c_family PARAMS ((void));
3544 static int is_cxx PARAMS ((void));
3545 static int is_java PARAMS ((void));
3546 static int is_fortran PARAMS ((void));
3547 static void remove_AT PARAMS ((dw_die_ref,
3548 enum dwarf_attribute));
3549 static inline void free_die PARAMS ((dw_die_ref));
3550 static void remove_children PARAMS ((dw_die_ref));
3551 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3552 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref,
3553 tree));
3554 static dw_die_ref lookup_type_die PARAMS ((tree));
3555 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3556 static dw_die_ref lookup_decl_die PARAMS ((tree));
3557 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3558 static void print_spaces PARAMS ((FILE *));
3559 static void print_die PARAMS ((dw_die_ref, FILE *));
3560 static void print_dwarf_line_table PARAMS ((FILE *));
3561 static void reverse_die_lists PARAMS ((dw_die_ref));
3562 static void reverse_all_dies PARAMS ((dw_die_ref));
3563 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3564 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3565 static void loc_checksum PARAMS ((dw_loc_descr_ref,
3566 struct md5_ctx *));
3567 static void attr_checksum PARAMS ((dw_attr_ref,
3568 struct md5_ctx *));
3569 static void die_checksum PARAMS ((dw_die_ref,
3570 struct md5_ctx *));
3571 static void compute_section_prefix PARAMS ((dw_die_ref));
3572 static int is_type_die PARAMS ((dw_die_ref));
3573 static int is_comdat_die PARAMS ((dw_die_ref));
3574 static int is_symbol_die PARAMS ((dw_die_ref));
3575 static void assign_symbol_names PARAMS ((dw_die_ref));
3576 static void break_out_includes PARAMS ((dw_die_ref));
3577 static void add_sibling_attributes PARAMS ((dw_die_ref));
3578 static void build_abbrev_table PARAMS ((dw_die_ref));
3579 static void output_location_lists PARAMS ((dw_die_ref));
3580 static int constant_size PARAMS ((long unsigned));
3581 static unsigned long size_of_die PARAMS ((dw_die_ref));
3582 static void calc_die_sizes PARAMS ((dw_die_ref));
3583 static void mark_dies PARAMS ((dw_die_ref));
3584 static void unmark_dies PARAMS ((dw_die_ref));
3585 static unsigned long size_of_pubnames PARAMS ((void));
3586 static unsigned long size_of_aranges PARAMS ((void));
3587 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3588 static void output_value_format PARAMS ((dw_attr_ref));
3589 static void output_abbrev_section PARAMS ((void));
3590 static void output_die_symbol PARAMS ((dw_die_ref));
3591 static void output_die PARAMS ((dw_die_ref));
3592 static void output_compilation_unit_header PARAMS ((void));
3593 static void output_comp_unit PARAMS ((dw_die_ref));
3594 static const char *dwarf2_name PARAMS ((tree, int));
3595 static void add_pubname PARAMS ((tree, dw_die_ref));
3596 static void output_pubnames PARAMS ((void));
3597 static void add_arange PARAMS ((tree, dw_die_ref));
3598 static void output_aranges PARAMS ((void));
3599 static unsigned int add_ranges PARAMS ((tree));
3600 static void output_ranges PARAMS ((void));
3601 static void output_line_info PARAMS ((void));
3602 static void output_file_names PARAMS ((void));
3603 static dw_die_ref base_type_die PARAMS ((tree));
3604 static tree root_type PARAMS ((tree));
3605 static int is_base_type PARAMS ((tree));
3606 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3607 static int type_is_enum PARAMS ((tree));
3608 static unsigned int reg_number PARAMS ((rtx));
3609 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3610 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3611 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3612 static int is_based_loc PARAMS ((rtx));
3613 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3614 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3615 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3616 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3617 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3618 static tree field_type PARAMS ((tree));
3619 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3620 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3621 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3622 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3623 static void add_AT_location_description PARAMS ((dw_die_ref,
3624 enum dwarf_attribute, rtx));
3625 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3626 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3627 static rtx rtl_for_decl_location PARAMS ((tree));
3628 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3629 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3630 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3631 static void add_bound_info PARAMS ((dw_die_ref,
3632 enum dwarf_attribute, tree));
3633 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3634 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3635 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3636 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3637 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3638 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3639 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3640 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3641 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3642 static void push_decl_scope PARAMS ((tree));
3643 static void pop_decl_scope PARAMS ((void));
3644 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3645 static inline int local_scope_p PARAMS ((dw_die_ref));
3646 static inline int class_scope_p PARAMS ((dw_die_ref));
3647 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3648 dw_die_ref));
3649 static const char *type_tag PARAMS ((tree));
3650 static tree member_declared_type PARAMS ((tree));
3651 #if 0
3652 static const char *decl_start_label PARAMS ((tree));
3653 #endif
3654 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3655 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3656 #if 0
3657 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3658 #endif
3659 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3660 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3661 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3662 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3663 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3664 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3665 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3666 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3667 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3668 static void gen_label_die PARAMS ((tree, dw_die_ref));
3669 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3670 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3671 static void gen_field_die PARAMS ((tree, dw_die_ref));
3672 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3673 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3674 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3675 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3676 static void gen_member_die PARAMS ((tree, dw_die_ref));
3677 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3678 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3679 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3680 static void gen_type_die PARAMS ((tree, dw_die_ref));
3681 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3682 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3683 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3684 static int is_redundant_typedef PARAMS ((tree));
3685 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3686 static unsigned lookup_filename PARAMS ((const char *));
3687 static void init_file_table PARAMS ((void));
3688 static void retry_incomplete_types PARAMS ((void));
3689 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3690 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3691 static int file_info_cmp PARAMS ((const void *, const void *));
3692 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3693 const char *, const char *,
3694 const char *, unsigned));
3695 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3696 dw_loc_descr_ref,
3697 const char *, const char *, const char *));
3698 static void output_loc_list PARAMS ((dw_loc_list_ref));
3699 static char *gen_internal_sym PARAMS ((const char *));
3700 static void mark_limbo_die_list PARAMS ((void *));
3702 /* Section names used to hold DWARF debugging information. */
3703 #ifndef DEBUG_INFO_SECTION
3704 #define DEBUG_INFO_SECTION ".debug_info"
3705 #endif
3706 #ifndef DEBUG_ABBREV_SECTION
3707 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3708 #endif
3709 #ifndef DEBUG_ARANGES_SECTION
3710 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3711 #endif
3712 #ifndef DEBUG_MACINFO_SECTION
3713 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3714 #endif
3715 #ifndef DEBUG_LINE_SECTION
3716 #define DEBUG_LINE_SECTION ".debug_line"
3717 #endif
3718 #ifndef DEBUG_LOC_SECTION
3719 #define DEBUG_LOC_SECTION ".debug_loc"
3720 #endif
3721 #ifndef DEBUG_PUBNAMES_SECTION
3722 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3723 #endif
3724 #ifndef DEBUG_STR_SECTION
3725 #define DEBUG_STR_SECTION ".debug_str"
3726 #endif
3727 #ifndef DEBUG_RANGES_SECTION
3728 #define DEBUG_RANGES_SECTION ".debug_ranges"
3729 #endif
3731 /* Standard ELF section names for compiled code and data. */
3732 #ifndef TEXT_SECTION_NAME
3733 #define TEXT_SECTION_NAME ".text"
3734 #endif
3736 /* Section flags for .debug_str section. */
3737 #ifdef HAVE_GAS_SHF_MERGE
3738 #define DEBUG_STR_SECTION_FLAGS \
3739 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3740 #else
3741 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3742 #endif
3744 /* Labels we insert at beginning sections we can reference instead of
3745 the section names themselves. */
3747 #ifndef TEXT_SECTION_LABEL
3748 #define TEXT_SECTION_LABEL "Ltext"
3749 #endif
3750 #ifndef DEBUG_LINE_SECTION_LABEL
3751 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3752 #endif
3753 #ifndef DEBUG_INFO_SECTION_LABEL
3754 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3755 #endif
3756 #ifndef DEBUG_ABBREV_SECTION_LABEL
3757 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3758 #endif
3759 #ifndef DEBUG_LOC_SECTION_LABEL
3760 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3761 #endif
3762 #ifndef DEBUG_RANGES_SECTION_LABEL
3763 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3764 #endif
3765 #ifndef DEBUG_MACINFO_SECTION_LABEL
3766 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3767 #endif
3769 /* Definitions of defaults for formats and names of various special
3770 (artificial) labels which may be generated within this file (when the -g
3771 options is used and DWARF_DEBUGGING_INFO is in effect.
3772 If necessary, these may be overridden from within the tm.h file, but
3773 typically, overriding these defaults is unnecessary. */
3775 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3776 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3777 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3778 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3779 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3780 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3781 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3782 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3784 #ifndef TEXT_END_LABEL
3785 #define TEXT_END_LABEL "Letext"
3786 #endif
3787 #ifndef DATA_END_LABEL
3788 #define DATA_END_LABEL "Ledata"
3789 #endif
3790 #ifndef BSS_END_LABEL
3791 #define BSS_END_LABEL "Lebss"
3792 #endif
3793 #ifndef BLOCK_BEGIN_LABEL
3794 #define BLOCK_BEGIN_LABEL "LBB"
3795 #endif
3796 #ifndef BLOCK_END_LABEL
3797 #define BLOCK_END_LABEL "LBE"
3798 #endif
3799 #ifndef BODY_BEGIN_LABEL
3800 #define BODY_BEGIN_LABEL "Lbb"
3801 #endif
3802 #ifndef BODY_END_LABEL
3803 #define BODY_END_LABEL "Lbe"
3804 #endif
3805 #ifndef LINE_CODE_LABEL
3806 #define LINE_CODE_LABEL "LM"
3807 #endif
3808 #ifndef SEPARATE_LINE_CODE_LABEL
3809 #define SEPARATE_LINE_CODE_LABEL "LSM"
3810 #endif
3812 /* We allow a language front-end to designate a function that is to be
3813 called to "demangle" any name before it it put into a DIE. */
3815 static const char *(*demangle_name_func) PARAMS ((const char *));
3817 void
3818 dwarf2out_set_demangle_name_func (func)
3819 const char *(*func) PARAMS ((const char *));
3821 demangle_name_func = func;
3824 /* Test if rtl node points to a pseudo register. */
3826 static inline int
3827 is_pseudo_reg (rtl)
3828 rtx rtl;
3830 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3831 || (GET_CODE (rtl) == SUBREG
3832 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3835 /* Return a reference to a type, with its const and volatile qualifiers
3836 removed. */
3838 static inline tree
3839 type_main_variant (type)
3840 tree type;
3842 type = TYPE_MAIN_VARIANT (type);
3844 /* ??? There really should be only one main variant among any group of
3845 variants of a given type (and all of the MAIN_VARIANT values for all
3846 members of the group should point to that one type) but sometimes the C
3847 front-end messes this up for array types, so we work around that bug
3848 here. */
3849 if (TREE_CODE (type) == ARRAY_TYPE)
3850 while (type != TYPE_MAIN_VARIANT (type))
3851 type = TYPE_MAIN_VARIANT (type);
3853 return type;
3856 /* Return non-zero if the given type node represents a tagged type. */
3858 static inline int
3859 is_tagged_type (type)
3860 tree type;
3862 enum tree_code code = TREE_CODE (type);
3864 return (code == RECORD_TYPE || code == UNION_TYPE
3865 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3868 /* Convert a DIE tag into its string name. */
3870 static const char *
3871 dwarf_tag_name (tag)
3872 unsigned tag;
3874 switch (tag)
3876 case DW_TAG_padding:
3877 return "DW_TAG_padding";
3878 case DW_TAG_array_type:
3879 return "DW_TAG_array_type";
3880 case DW_TAG_class_type:
3881 return "DW_TAG_class_type";
3882 case DW_TAG_entry_point:
3883 return "DW_TAG_entry_point";
3884 case DW_TAG_enumeration_type:
3885 return "DW_TAG_enumeration_type";
3886 case DW_TAG_formal_parameter:
3887 return "DW_TAG_formal_parameter";
3888 case DW_TAG_imported_declaration:
3889 return "DW_TAG_imported_declaration";
3890 case DW_TAG_label:
3891 return "DW_TAG_label";
3892 case DW_TAG_lexical_block:
3893 return "DW_TAG_lexical_block";
3894 case DW_TAG_member:
3895 return "DW_TAG_member";
3896 case DW_TAG_pointer_type:
3897 return "DW_TAG_pointer_type";
3898 case DW_TAG_reference_type:
3899 return "DW_TAG_reference_type";
3900 case DW_TAG_compile_unit:
3901 return "DW_TAG_compile_unit";
3902 case DW_TAG_string_type:
3903 return "DW_TAG_string_type";
3904 case DW_TAG_structure_type:
3905 return "DW_TAG_structure_type";
3906 case DW_TAG_subroutine_type:
3907 return "DW_TAG_subroutine_type";
3908 case DW_TAG_typedef:
3909 return "DW_TAG_typedef";
3910 case DW_TAG_union_type:
3911 return "DW_TAG_union_type";
3912 case DW_TAG_unspecified_parameters:
3913 return "DW_TAG_unspecified_parameters";
3914 case DW_TAG_variant:
3915 return "DW_TAG_variant";
3916 case DW_TAG_common_block:
3917 return "DW_TAG_common_block";
3918 case DW_TAG_common_inclusion:
3919 return "DW_TAG_common_inclusion";
3920 case DW_TAG_inheritance:
3921 return "DW_TAG_inheritance";
3922 case DW_TAG_inlined_subroutine:
3923 return "DW_TAG_inlined_subroutine";
3924 case DW_TAG_module:
3925 return "DW_TAG_module";
3926 case DW_TAG_ptr_to_member_type:
3927 return "DW_TAG_ptr_to_member_type";
3928 case DW_TAG_set_type:
3929 return "DW_TAG_set_type";
3930 case DW_TAG_subrange_type:
3931 return "DW_TAG_subrange_type";
3932 case DW_TAG_with_stmt:
3933 return "DW_TAG_with_stmt";
3934 case DW_TAG_access_declaration:
3935 return "DW_TAG_access_declaration";
3936 case DW_TAG_base_type:
3937 return "DW_TAG_base_type";
3938 case DW_TAG_catch_block:
3939 return "DW_TAG_catch_block";
3940 case DW_TAG_const_type:
3941 return "DW_TAG_const_type";
3942 case DW_TAG_constant:
3943 return "DW_TAG_constant";
3944 case DW_TAG_enumerator:
3945 return "DW_TAG_enumerator";
3946 case DW_TAG_file_type:
3947 return "DW_TAG_file_type";
3948 case DW_TAG_friend:
3949 return "DW_TAG_friend";
3950 case DW_TAG_namelist:
3951 return "DW_TAG_namelist";
3952 case DW_TAG_namelist_item:
3953 return "DW_TAG_namelist_item";
3954 case DW_TAG_packed_type:
3955 return "DW_TAG_packed_type";
3956 case DW_TAG_subprogram:
3957 return "DW_TAG_subprogram";
3958 case DW_TAG_template_type_param:
3959 return "DW_TAG_template_type_param";
3960 case DW_TAG_template_value_param:
3961 return "DW_TAG_template_value_param";
3962 case DW_TAG_thrown_type:
3963 return "DW_TAG_thrown_type";
3964 case DW_TAG_try_block:
3965 return "DW_TAG_try_block";
3966 case DW_TAG_variant_part:
3967 return "DW_TAG_variant_part";
3968 case DW_TAG_variable:
3969 return "DW_TAG_variable";
3970 case DW_TAG_volatile_type:
3971 return "DW_TAG_volatile_type";
3972 case DW_TAG_MIPS_loop:
3973 return "DW_TAG_MIPS_loop";
3974 case DW_TAG_format_label:
3975 return "DW_TAG_format_label";
3976 case DW_TAG_function_template:
3977 return "DW_TAG_function_template";
3978 case DW_TAG_class_template:
3979 return "DW_TAG_class_template";
3980 case DW_TAG_GNU_BINCL:
3981 return "DW_TAG_GNU_BINCL";
3982 case DW_TAG_GNU_EINCL:
3983 return "DW_TAG_GNU_EINCL";
3984 default:
3985 return "DW_TAG_<unknown>";
3989 /* Convert a DWARF attribute code into its string name. */
3991 static const char *
3992 dwarf_attr_name (attr)
3993 unsigned attr;
3995 switch (attr)
3997 case DW_AT_sibling:
3998 return "DW_AT_sibling";
3999 case DW_AT_location:
4000 return "DW_AT_location";
4001 case DW_AT_name:
4002 return "DW_AT_name";
4003 case DW_AT_ordering:
4004 return "DW_AT_ordering";
4005 case DW_AT_subscr_data:
4006 return "DW_AT_subscr_data";
4007 case DW_AT_byte_size:
4008 return "DW_AT_byte_size";
4009 case DW_AT_bit_offset:
4010 return "DW_AT_bit_offset";
4011 case DW_AT_bit_size:
4012 return "DW_AT_bit_size";
4013 case DW_AT_element_list:
4014 return "DW_AT_element_list";
4015 case DW_AT_stmt_list:
4016 return "DW_AT_stmt_list";
4017 case DW_AT_low_pc:
4018 return "DW_AT_low_pc";
4019 case DW_AT_high_pc:
4020 return "DW_AT_high_pc";
4021 case DW_AT_language:
4022 return "DW_AT_language";
4023 case DW_AT_member:
4024 return "DW_AT_member";
4025 case DW_AT_discr:
4026 return "DW_AT_discr";
4027 case DW_AT_discr_value:
4028 return "DW_AT_discr_value";
4029 case DW_AT_visibility:
4030 return "DW_AT_visibility";
4031 case DW_AT_import:
4032 return "DW_AT_import";
4033 case DW_AT_string_length:
4034 return "DW_AT_string_length";
4035 case DW_AT_common_reference:
4036 return "DW_AT_common_reference";
4037 case DW_AT_comp_dir:
4038 return "DW_AT_comp_dir";
4039 case DW_AT_const_value:
4040 return "DW_AT_const_value";
4041 case DW_AT_containing_type:
4042 return "DW_AT_containing_type";
4043 case DW_AT_default_value:
4044 return "DW_AT_default_value";
4045 case DW_AT_inline:
4046 return "DW_AT_inline";
4047 case DW_AT_is_optional:
4048 return "DW_AT_is_optional";
4049 case DW_AT_lower_bound:
4050 return "DW_AT_lower_bound";
4051 case DW_AT_producer:
4052 return "DW_AT_producer";
4053 case DW_AT_prototyped:
4054 return "DW_AT_prototyped";
4055 case DW_AT_return_addr:
4056 return "DW_AT_return_addr";
4057 case DW_AT_start_scope:
4058 return "DW_AT_start_scope";
4059 case DW_AT_stride_size:
4060 return "DW_AT_stride_size";
4061 case DW_AT_upper_bound:
4062 return "DW_AT_upper_bound";
4063 case DW_AT_abstract_origin:
4064 return "DW_AT_abstract_origin";
4065 case DW_AT_accessibility:
4066 return "DW_AT_accessibility";
4067 case DW_AT_address_class:
4068 return "DW_AT_address_class";
4069 case DW_AT_artificial:
4070 return "DW_AT_artificial";
4071 case DW_AT_base_types:
4072 return "DW_AT_base_types";
4073 case DW_AT_calling_convention:
4074 return "DW_AT_calling_convention";
4075 case DW_AT_count:
4076 return "DW_AT_count";
4077 case DW_AT_data_member_location:
4078 return "DW_AT_data_member_location";
4079 case DW_AT_decl_column:
4080 return "DW_AT_decl_column";
4081 case DW_AT_decl_file:
4082 return "DW_AT_decl_file";
4083 case DW_AT_decl_line:
4084 return "DW_AT_decl_line";
4085 case DW_AT_declaration:
4086 return "DW_AT_declaration";
4087 case DW_AT_discr_list:
4088 return "DW_AT_discr_list";
4089 case DW_AT_encoding:
4090 return "DW_AT_encoding";
4091 case DW_AT_external:
4092 return "DW_AT_external";
4093 case DW_AT_frame_base:
4094 return "DW_AT_frame_base";
4095 case DW_AT_friend:
4096 return "DW_AT_friend";
4097 case DW_AT_identifier_case:
4098 return "DW_AT_identifier_case";
4099 case DW_AT_macro_info:
4100 return "DW_AT_macro_info";
4101 case DW_AT_namelist_items:
4102 return "DW_AT_namelist_items";
4103 case DW_AT_priority:
4104 return "DW_AT_priority";
4105 case DW_AT_segment:
4106 return "DW_AT_segment";
4107 case DW_AT_specification:
4108 return "DW_AT_specification";
4109 case DW_AT_static_link:
4110 return "DW_AT_static_link";
4111 case DW_AT_type:
4112 return "DW_AT_type";
4113 case DW_AT_use_location:
4114 return "DW_AT_use_location";
4115 case DW_AT_variable_parameter:
4116 return "DW_AT_variable_parameter";
4117 case DW_AT_virtuality:
4118 return "DW_AT_virtuality";
4119 case DW_AT_vtable_elem_location:
4120 return "DW_AT_vtable_elem_location";
4122 case DW_AT_allocated:
4123 return "DW_AT_allocated";
4124 case DW_AT_associated:
4125 return "DW_AT_associated";
4126 case DW_AT_data_location:
4127 return "DW_AT_data_location";
4128 case DW_AT_stride:
4129 return "DW_AT_stride";
4130 case DW_AT_entry_pc:
4131 return "DW_AT_entry_pc";
4132 case DW_AT_use_UTF8:
4133 return "DW_AT_use_UTF8";
4134 case DW_AT_extension:
4135 return "DW_AT_extension";
4136 case DW_AT_ranges:
4137 return "DW_AT_ranges";
4138 case DW_AT_trampoline:
4139 return "DW_AT_trampoline";
4140 case DW_AT_call_column:
4141 return "DW_AT_call_column";
4142 case DW_AT_call_file:
4143 return "DW_AT_call_file";
4144 case DW_AT_call_line:
4145 return "DW_AT_call_line";
4147 case DW_AT_MIPS_fde:
4148 return "DW_AT_MIPS_fde";
4149 case DW_AT_MIPS_loop_begin:
4150 return "DW_AT_MIPS_loop_begin";
4151 case DW_AT_MIPS_tail_loop_begin:
4152 return "DW_AT_MIPS_tail_loop_begin";
4153 case DW_AT_MIPS_epilog_begin:
4154 return "DW_AT_MIPS_epilog_begin";
4155 case DW_AT_MIPS_loop_unroll_factor:
4156 return "DW_AT_MIPS_loop_unroll_factor";
4157 case DW_AT_MIPS_software_pipeline_depth:
4158 return "DW_AT_MIPS_software_pipeline_depth";
4159 case DW_AT_MIPS_linkage_name:
4160 return "DW_AT_MIPS_linkage_name";
4161 case DW_AT_MIPS_stride:
4162 return "DW_AT_MIPS_stride";
4163 case DW_AT_MIPS_abstract_name:
4164 return "DW_AT_MIPS_abstract_name";
4165 case DW_AT_MIPS_clone_origin:
4166 return "DW_AT_MIPS_clone_origin";
4167 case DW_AT_MIPS_has_inlines:
4168 return "DW_AT_MIPS_has_inlines";
4170 case DW_AT_sf_names:
4171 return "DW_AT_sf_names";
4172 case DW_AT_src_info:
4173 return "DW_AT_src_info";
4174 case DW_AT_mac_info:
4175 return "DW_AT_mac_info";
4176 case DW_AT_src_coords:
4177 return "DW_AT_src_coords";
4178 case DW_AT_body_begin:
4179 return "DW_AT_body_begin";
4180 case DW_AT_body_end:
4181 return "DW_AT_body_end";
4182 case DW_AT_GNU_vector:
4183 return "DW_AT_GNU_vector";
4185 case DW_AT_VMS_rtnbeg_pd_address:
4186 return "DW_AT_VMS_rtnbeg_pd_address";
4188 default:
4189 return "DW_AT_<unknown>";
4193 /* Convert a DWARF value form code into its string name. */
4195 static const char *
4196 dwarf_form_name (form)
4197 unsigned form;
4199 switch (form)
4201 case DW_FORM_addr:
4202 return "DW_FORM_addr";
4203 case DW_FORM_block2:
4204 return "DW_FORM_block2";
4205 case DW_FORM_block4:
4206 return "DW_FORM_block4";
4207 case DW_FORM_data2:
4208 return "DW_FORM_data2";
4209 case DW_FORM_data4:
4210 return "DW_FORM_data4";
4211 case DW_FORM_data8:
4212 return "DW_FORM_data8";
4213 case DW_FORM_string:
4214 return "DW_FORM_string";
4215 case DW_FORM_block:
4216 return "DW_FORM_block";
4217 case DW_FORM_block1:
4218 return "DW_FORM_block1";
4219 case DW_FORM_data1:
4220 return "DW_FORM_data1";
4221 case DW_FORM_flag:
4222 return "DW_FORM_flag";
4223 case DW_FORM_sdata:
4224 return "DW_FORM_sdata";
4225 case DW_FORM_strp:
4226 return "DW_FORM_strp";
4227 case DW_FORM_udata:
4228 return "DW_FORM_udata";
4229 case DW_FORM_ref_addr:
4230 return "DW_FORM_ref_addr";
4231 case DW_FORM_ref1:
4232 return "DW_FORM_ref1";
4233 case DW_FORM_ref2:
4234 return "DW_FORM_ref2";
4235 case DW_FORM_ref4:
4236 return "DW_FORM_ref4";
4237 case DW_FORM_ref8:
4238 return "DW_FORM_ref8";
4239 case DW_FORM_ref_udata:
4240 return "DW_FORM_ref_udata";
4241 case DW_FORM_indirect:
4242 return "DW_FORM_indirect";
4243 default:
4244 return "DW_FORM_<unknown>";
4248 /* Convert a DWARF type code into its string name. */
4250 #if 0
4251 static const char *
4252 dwarf_type_encoding_name (enc)
4253 unsigned enc;
4255 switch (enc)
4257 case DW_ATE_address:
4258 return "DW_ATE_address";
4259 case DW_ATE_boolean:
4260 return "DW_ATE_boolean";
4261 case DW_ATE_complex_float:
4262 return "DW_ATE_complex_float";
4263 case DW_ATE_float:
4264 return "DW_ATE_float";
4265 case DW_ATE_signed:
4266 return "DW_ATE_signed";
4267 case DW_ATE_signed_char:
4268 return "DW_ATE_signed_char";
4269 case DW_ATE_unsigned:
4270 return "DW_ATE_unsigned";
4271 case DW_ATE_unsigned_char:
4272 return "DW_ATE_unsigned_char";
4273 default:
4274 return "DW_ATE_<unknown>";
4277 #endif
4279 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4280 instance of an inlined instance of a decl which is local to an inline
4281 function, so we have to trace all of the way back through the origin chain
4282 to find out what sort of node actually served as the original seed for the
4283 given block. */
4285 static tree
4286 decl_ultimate_origin (decl)
4287 tree decl;
4289 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4290 nodes in the function to point to themselves; ignore that if
4291 we're trying to output the abstract instance of this function. */
4292 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4293 return NULL_TREE;
4295 #ifdef ENABLE_CHECKING
4296 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4297 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4298 most distant ancestor, this should never happen. */
4299 abort ();
4300 #endif
4302 return DECL_ABSTRACT_ORIGIN (decl);
4305 /* Determine the "ultimate origin" of a block. The block may be an inlined
4306 instance of an inlined instance of a block which is local to an inline
4307 function, so we have to trace all of the way back through the origin chain
4308 to find out what sort of node actually served as the original seed for the
4309 given block. */
4311 static tree
4312 block_ultimate_origin (block)
4313 tree block;
4315 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4317 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4318 nodes in the function to point to themselves; ignore that if
4319 we're trying to output the abstract instance of this function. */
4320 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4321 return NULL_TREE;
4323 if (immediate_origin == NULL_TREE)
4324 return NULL_TREE;
4325 else
4327 tree ret_val;
4328 tree lookahead = immediate_origin;
4332 ret_val = lookahead;
4333 lookahead = (TREE_CODE (ret_val) == BLOCK
4334 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4336 while (lookahead != NULL && lookahead != ret_val);
4338 return ret_val;
4342 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4343 of a virtual function may refer to a base class, so we check the 'this'
4344 parameter. */
4346 static tree
4347 decl_class_context (decl)
4348 tree decl;
4350 tree context = NULL_TREE;
4352 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4353 context = DECL_CONTEXT (decl);
4354 else
4355 context = TYPE_MAIN_VARIANT
4356 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4358 if (context && !TYPE_P (context))
4359 context = NULL_TREE;
4361 return context;
4364 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4365 addition order, and correct that in reverse_all_dies. */
4367 static inline void
4368 add_dwarf_attr (die, attr)
4369 dw_die_ref die;
4370 dw_attr_ref attr;
4372 if (die != NULL && attr != NULL)
4374 attr->dw_attr_next = die->die_attr;
4375 die->die_attr = attr;
4379 static inline dw_val_class
4380 AT_class (a)
4381 dw_attr_ref a;
4383 return a->dw_attr_val.val_class;
4386 /* Add a flag value attribute to a DIE. */
4388 static inline void
4389 add_AT_flag (die, attr_kind, flag)
4390 dw_die_ref die;
4391 enum dwarf_attribute attr_kind;
4392 unsigned flag;
4394 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4396 attr->dw_attr_next = NULL;
4397 attr->dw_attr = attr_kind;
4398 attr->dw_attr_val.val_class = dw_val_class_flag;
4399 attr->dw_attr_val.v.val_flag = flag;
4400 add_dwarf_attr (die, attr);
4403 static inline unsigned
4404 AT_flag (a)
4405 dw_attr_ref a;
4407 if (a && AT_class (a) == dw_val_class_flag)
4408 return a->dw_attr_val.v.val_flag;
4410 abort ();
4413 /* Add a signed integer attribute value to a DIE. */
4415 static inline void
4416 add_AT_int (die, attr_kind, int_val)
4417 dw_die_ref die;
4418 enum dwarf_attribute attr_kind;
4419 long int int_val;
4421 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4423 attr->dw_attr_next = NULL;
4424 attr->dw_attr = attr_kind;
4425 attr->dw_attr_val.val_class = dw_val_class_const;
4426 attr->dw_attr_val.v.val_int = int_val;
4427 add_dwarf_attr (die, attr);
4430 static inline long int
4431 AT_int (a)
4432 dw_attr_ref a;
4434 if (a && AT_class (a) == dw_val_class_const)
4435 return a->dw_attr_val.v.val_int;
4437 abort ();
4440 /* Add an unsigned integer attribute value to a DIE. */
4442 static inline void
4443 add_AT_unsigned (die, attr_kind, unsigned_val)
4444 dw_die_ref die;
4445 enum dwarf_attribute attr_kind;
4446 unsigned long unsigned_val;
4448 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4450 attr->dw_attr_next = NULL;
4451 attr->dw_attr = attr_kind;
4452 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4453 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4454 add_dwarf_attr (die, attr);
4457 static inline unsigned long
4458 AT_unsigned (a)
4459 dw_attr_ref a;
4461 if (a && AT_class (a) == dw_val_class_unsigned_const)
4462 return a->dw_attr_val.v.val_unsigned;
4464 abort ();
4467 /* Add an unsigned double integer attribute value to a DIE. */
4469 static inline void
4470 add_AT_long_long (die, attr_kind, val_hi, val_low)
4471 dw_die_ref die;
4472 enum dwarf_attribute attr_kind;
4473 unsigned long val_hi;
4474 unsigned long val_low;
4476 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4478 attr->dw_attr_next = NULL;
4479 attr->dw_attr = attr_kind;
4480 attr->dw_attr_val.val_class = dw_val_class_long_long;
4481 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4482 attr->dw_attr_val.v.val_long_long.low = val_low;
4483 add_dwarf_attr (die, attr);
4486 /* Add a floating point attribute value to a DIE and return it. */
4488 static inline void
4489 add_AT_float (die, attr_kind, length, array)
4490 dw_die_ref die;
4491 enum dwarf_attribute attr_kind;
4492 unsigned length;
4493 long *array;
4495 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4497 attr->dw_attr_next = NULL;
4498 attr->dw_attr = attr_kind;
4499 attr->dw_attr_val.val_class = dw_val_class_float;
4500 attr->dw_attr_val.v.val_float.length = length;
4501 attr->dw_attr_val.v.val_float.array = array;
4502 add_dwarf_attr (die, attr);
4505 /* Add a string attribute value to a DIE. */
4507 static inline void
4508 add_AT_string (die, attr_kind, str)
4509 dw_die_ref die;
4510 enum dwarf_attribute attr_kind;
4511 const char *str;
4513 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4514 struct indirect_string_node *node;
4516 if (! debug_str_hash)
4518 debug_str_hash = ht_create (10);
4519 debug_str_hash->alloc_node = indirect_string_alloc;
4522 node = (struct indirect_string_node *)
4523 ht_lookup (debug_str_hash, (const unsigned char *) str,
4524 strlen (str), HT_ALLOC);
4525 node->refcount++;
4527 attr->dw_attr_next = NULL;
4528 attr->dw_attr = attr_kind;
4529 attr->dw_attr_val.val_class = dw_val_class_str;
4530 attr->dw_attr_val.v.val_str = node;
4531 add_dwarf_attr (die, attr);
4534 static inline const char *
4535 AT_string (a)
4536 dw_attr_ref a;
4538 if (a && AT_class (a) == dw_val_class_str)
4539 return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id);
4541 abort ();
4544 /* Find out whether a string should be output inline in DIE
4545 or out-of-line in .debug_str section. */
4547 static int
4548 AT_string_form (a)
4549 dw_attr_ref a;
4551 if (a && AT_class (a) == dw_val_class_str)
4553 struct indirect_string_node *node;
4554 unsigned int len;
4555 extern int const_labelno;
4556 char label[32];
4558 node = a->dw_attr_val.v.val_str;
4559 if (node->form)
4560 return node->form;
4562 len = HT_LEN (&node->id) + 1;
4564 /* If the string is shorter or equal to the size of the reference, it is
4565 always better to put it inline. */
4566 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4567 return node->form = DW_FORM_string;
4569 /* If we cannot expect the linker to merge strings in .debug_str
4570 section, only put it into .debug_str if it is worth even in this
4571 single module. */
4572 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4573 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4574 return node->form = DW_FORM_string;
4576 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4577 ++const_labelno;
4578 node->label = xstrdup (label);
4580 return node->form = DW_FORM_strp;
4583 abort ();
4586 /* Add a DIE reference attribute value to a DIE. */
4588 static inline void
4589 add_AT_die_ref (die, attr_kind, targ_die)
4590 dw_die_ref die;
4591 enum dwarf_attribute attr_kind;
4592 dw_die_ref targ_die;
4594 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4596 attr->dw_attr_next = NULL;
4597 attr->dw_attr = attr_kind;
4598 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4599 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4600 attr->dw_attr_val.v.val_die_ref.external = 0;
4601 add_dwarf_attr (die, attr);
4604 static inline dw_die_ref
4605 AT_ref (a)
4606 dw_attr_ref a;
4608 if (a && AT_class (a) == dw_val_class_die_ref)
4609 return a->dw_attr_val.v.val_die_ref.die;
4611 abort ();
4614 static inline int
4615 AT_ref_external (a)
4616 dw_attr_ref a;
4618 if (a && AT_class (a) == dw_val_class_die_ref)
4619 return a->dw_attr_val.v.val_die_ref.external;
4621 return 0;
4624 static inline void
4625 set_AT_ref_external (a, i)
4626 dw_attr_ref a;
4627 int i;
4629 if (a && AT_class (a) == dw_val_class_die_ref)
4630 a->dw_attr_val.v.val_die_ref.external = i;
4631 else
4632 abort ();
4635 /* Add an FDE reference attribute value to a DIE. */
4637 static inline void
4638 add_AT_fde_ref (die, attr_kind, targ_fde)
4639 dw_die_ref die;
4640 enum dwarf_attribute attr_kind;
4641 unsigned targ_fde;
4643 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4645 attr->dw_attr_next = NULL;
4646 attr->dw_attr = attr_kind;
4647 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4648 attr->dw_attr_val.v.val_fde_index = targ_fde;
4649 add_dwarf_attr (die, attr);
4652 /* Add a location description attribute value to a DIE. */
4654 static inline void
4655 add_AT_loc (die, attr_kind, loc)
4656 dw_die_ref die;
4657 enum dwarf_attribute attr_kind;
4658 dw_loc_descr_ref loc;
4660 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4662 attr->dw_attr_next = NULL;
4663 attr->dw_attr = attr_kind;
4664 attr->dw_attr_val.val_class = dw_val_class_loc;
4665 attr->dw_attr_val.v.val_loc = loc;
4666 add_dwarf_attr (die, attr);
4669 static inline dw_loc_descr_ref
4670 AT_loc (a)
4671 dw_attr_ref a;
4673 if (a && AT_class (a) == dw_val_class_loc)
4674 return a->dw_attr_val.v.val_loc;
4676 abort ();
4679 static inline void
4680 add_AT_loc_list (die, attr_kind, loc_list)
4681 dw_die_ref die;
4682 enum dwarf_attribute attr_kind;
4683 dw_loc_list_ref loc_list;
4685 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4687 attr->dw_attr_next = NULL;
4688 attr->dw_attr = attr_kind;
4689 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4690 attr->dw_attr_val.v.val_loc_list = loc_list;
4691 add_dwarf_attr (die, attr);
4692 have_location_lists = 1;
4695 static inline dw_loc_list_ref
4696 AT_loc_list (a)
4697 dw_attr_ref a;
4699 if (a && AT_class (a) == dw_val_class_loc_list)
4700 return a->dw_attr_val.v.val_loc_list;
4702 abort ();
4705 /* Add an address constant attribute value to a DIE. */
4707 static inline void
4708 add_AT_addr (die, attr_kind, addr)
4709 dw_die_ref die;
4710 enum dwarf_attribute attr_kind;
4711 rtx addr;
4713 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4715 attr->dw_attr_next = NULL;
4716 attr->dw_attr = attr_kind;
4717 attr->dw_attr_val.val_class = dw_val_class_addr;
4718 attr->dw_attr_val.v.val_addr = addr;
4719 add_dwarf_attr (die, attr);
4722 static inline rtx
4723 AT_addr (a)
4724 dw_attr_ref a;
4726 if (a && AT_class (a) == dw_val_class_addr)
4727 return a->dw_attr_val.v.val_addr;
4729 abort ();
4732 /* Add a label identifier attribute value to a DIE. */
4734 static inline void
4735 add_AT_lbl_id (die, attr_kind, lbl_id)
4736 dw_die_ref die;
4737 enum dwarf_attribute attr_kind;
4738 const char *lbl_id;
4740 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4742 attr->dw_attr_next = NULL;
4743 attr->dw_attr = attr_kind;
4744 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4745 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4746 add_dwarf_attr (die, attr);
4749 /* Add a section offset attribute value to a DIE. */
4751 static inline void
4752 add_AT_lbl_offset (die, attr_kind, label)
4753 dw_die_ref die;
4754 enum dwarf_attribute attr_kind;
4755 const char *label;
4757 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4759 attr->dw_attr_next = NULL;
4760 attr->dw_attr = attr_kind;
4761 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4762 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4763 add_dwarf_attr (die, attr);
4766 /* Add an offset attribute value to a DIE. */
4768 static inline void
4769 add_AT_offset (die, attr_kind, offset)
4770 dw_die_ref die;
4771 enum dwarf_attribute attr_kind;
4772 unsigned long offset;
4774 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4776 attr->dw_attr_next = NULL;
4777 attr->dw_attr = attr_kind;
4778 attr->dw_attr_val.val_class = dw_val_class_offset;
4779 attr->dw_attr_val.v.val_offset = offset;
4780 add_dwarf_attr (die, attr);
4783 /* Add an range_list attribute value to a DIE. */
4785 static void
4786 add_AT_range_list (die, attr_kind, offset)
4787 dw_die_ref die;
4788 enum dwarf_attribute attr_kind;
4789 unsigned long offset;
4791 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4793 attr->dw_attr_next = NULL;
4794 attr->dw_attr = attr_kind;
4795 attr->dw_attr_val.val_class = dw_val_class_range_list;
4796 attr->dw_attr_val.v.val_offset = offset;
4797 add_dwarf_attr (die, attr);
4800 static inline const char *
4801 AT_lbl (a)
4802 dw_attr_ref a;
4804 if (a && (AT_class (a) == dw_val_class_lbl_id
4805 || AT_class (a) == dw_val_class_lbl_offset))
4806 return a->dw_attr_val.v.val_lbl_id;
4808 abort ();
4811 /* Get the attribute of type attr_kind. */
4813 static inline dw_attr_ref
4814 get_AT (die, attr_kind)
4815 dw_die_ref die;
4816 enum dwarf_attribute attr_kind;
4818 dw_attr_ref a;
4819 dw_die_ref spec = NULL;
4821 if (die != NULL)
4823 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4824 if (a->dw_attr == attr_kind)
4825 return a;
4826 else if (a->dw_attr == DW_AT_specification
4827 || a->dw_attr == DW_AT_abstract_origin)
4828 spec = AT_ref (a);
4830 if (spec)
4831 return get_AT (spec, attr_kind);
4834 return NULL;
4837 /* Return the "low pc" attribute value, typically associated with a subprogram
4838 DIE. Return null if the "low pc" attribute is either not present, or if it
4839 cannot be represented as an assembler label identifier. */
4841 static inline const char *
4842 get_AT_low_pc (die)
4843 dw_die_ref die;
4845 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4847 return a ? AT_lbl (a) : NULL;
4850 /* Return the "high pc" attribute value, typically associated with a subprogram
4851 DIE. Return null if the "high pc" attribute is either not present, or if it
4852 cannot be represented as an assembler label identifier. */
4854 static inline const char *
4855 get_AT_hi_pc (die)
4856 dw_die_ref die;
4858 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4860 return a ? AT_lbl (a) : NULL;
4863 /* Return the value of the string attribute designated by ATTR_KIND, or
4864 NULL if it is not present. */
4866 static inline const char *
4867 get_AT_string (die, attr_kind)
4868 dw_die_ref die;
4869 enum dwarf_attribute attr_kind;
4871 dw_attr_ref a = get_AT (die, attr_kind);
4873 return a ? AT_string (a) : NULL;
4876 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4877 if it is not present. */
4879 static inline int
4880 get_AT_flag (die, attr_kind)
4881 dw_die_ref die;
4882 enum dwarf_attribute attr_kind;
4884 dw_attr_ref a = get_AT (die, attr_kind);
4886 return a ? AT_flag (a) : 0;
4889 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4890 if it is not present. */
4892 static inline unsigned
4893 get_AT_unsigned (die, attr_kind)
4894 dw_die_ref die;
4895 enum dwarf_attribute attr_kind;
4897 dw_attr_ref a = get_AT (die, attr_kind);
4899 return a ? AT_unsigned (a) : 0;
4902 static inline dw_die_ref
4903 get_AT_ref (die, attr_kind)
4904 dw_die_ref die;
4905 enum dwarf_attribute attr_kind;
4907 dw_attr_ref a = get_AT (die, attr_kind);
4909 return a ? AT_ref (a) : NULL;
4912 static inline int
4913 is_c_family ()
4915 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4917 return (lang == DW_LANG_C || lang == DW_LANG_C89
4918 || lang == DW_LANG_C_plus_plus);
4921 static inline int
4922 is_cxx ()
4924 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4925 == DW_LANG_C_plus_plus);
4928 static inline int
4929 is_fortran ()
4931 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4933 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4936 static inline int
4937 is_java ()
4939 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4941 return (lang == DW_LANG_Java);
4944 /* Free up the memory used by A. */
4946 static inline void free_AT PARAMS ((dw_attr_ref));
4947 static inline void
4948 free_AT (a)
4949 dw_attr_ref a;
4951 switch (AT_class (a))
4953 case dw_val_class_str:
4954 if (a->dw_attr_val.v.val_str->refcount)
4955 a->dw_attr_val.v.val_str->refcount--;
4956 break;
4958 case dw_val_class_lbl_id:
4959 case dw_val_class_lbl_offset:
4960 free (a->dw_attr_val.v.val_lbl_id);
4961 break;
4963 case dw_val_class_float:
4964 free (a->dw_attr_val.v.val_float.array);
4965 break;
4967 default:
4968 break;
4971 free (a);
4974 /* Remove the specified attribute if present. */
4976 static void
4977 remove_AT (die, attr_kind)
4978 dw_die_ref die;
4979 enum dwarf_attribute attr_kind;
4981 dw_attr_ref *p;
4982 dw_attr_ref removed = NULL;
4984 if (die != NULL)
4986 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4987 if ((*p)->dw_attr == attr_kind)
4989 removed = *p;
4990 *p = (*p)->dw_attr_next;
4991 break;
4994 if (removed != 0)
4995 free_AT (removed);
4999 /* Free up the memory used by DIE. */
5001 static inline void
5002 free_die (die)
5003 dw_die_ref die;
5005 remove_children (die);
5006 free (die);
5009 /* Discard the children of this DIE. */
5011 static void
5012 remove_children (die)
5013 dw_die_ref die;
5015 dw_die_ref child_die = die->die_child;
5017 die->die_child = NULL;
5019 while (child_die != NULL)
5021 dw_die_ref tmp_die = child_die;
5022 dw_attr_ref a;
5024 child_die = child_die->die_sib;
5026 for (a = tmp_die->die_attr; a != NULL;)
5028 dw_attr_ref tmp_a = a;
5030 a = a->dw_attr_next;
5031 free_AT (tmp_a);
5034 free_die (tmp_die);
5038 /* Add a child DIE below its parent. We build the lists up in reverse
5039 addition order, and correct that in reverse_all_dies. */
5041 static inline void
5042 add_child_die (die, child_die)
5043 dw_die_ref die;
5044 dw_die_ref child_die;
5046 if (die != NULL && child_die != NULL)
5048 if (die == child_die)
5049 abort ();
5051 child_die->die_parent = die;
5052 child_die->die_sib = die->die_child;
5053 die->die_child = child_die;
5057 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5058 is the specification, to the front of PARENT's list of children. */
5060 static void
5061 splice_child_die (parent, child)
5062 dw_die_ref parent, child;
5064 dw_die_ref *p;
5066 /* We want the declaration DIE from inside the class, not the
5067 specification DIE at toplevel. */
5068 if (child->die_parent != parent)
5070 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5072 if (tmp)
5073 child = tmp;
5076 if (child->die_parent != parent
5077 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
5078 abort ();
5080 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5081 if (*p == child)
5083 *p = child->die_sib;
5084 break;
5087 child->die_sib = parent->die_child;
5088 parent->die_child = child;
5091 /* Return a pointer to a newly created DIE node. */
5093 static inline dw_die_ref
5094 new_die (tag_value, parent_die, t)
5095 enum dwarf_tag tag_value;
5096 dw_die_ref parent_die;
5097 tree t;
5099 dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5101 die->die_tag = tag_value;
5103 if (parent_die != NULL)
5104 add_child_die (parent_die, die);
5105 else
5107 limbo_die_node *limbo_node;
5109 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5110 limbo_node->die = die;
5111 limbo_node->created_for = t;
5112 limbo_node->next = limbo_die_list;
5113 limbo_die_list = limbo_node;
5116 return die;
5119 /* Return the DIE associated with the given type specifier. */
5121 static inline dw_die_ref
5122 lookup_type_die (type)
5123 tree type;
5125 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
5128 /* Equate a DIE to a given type specifier. */
5130 static inline void
5131 equate_type_number_to_die (type, type_die)
5132 tree type;
5133 dw_die_ref type_die;
5135 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
5138 /* Return the DIE associated with a given declaration. */
5140 static inline dw_die_ref
5141 lookup_decl_die (decl)
5142 tree decl;
5144 unsigned decl_id = DECL_UID (decl);
5146 return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
5149 /* Equate a DIE to a particular declaration. */
5151 static void
5152 equate_decl_number_to_die (decl, decl_die)
5153 tree decl;
5154 dw_die_ref decl_die;
5156 unsigned int decl_id = DECL_UID (decl);
5157 unsigned int num_allocated;
5159 if (decl_id >= decl_die_table_allocated)
5161 num_allocated
5162 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5163 / DECL_DIE_TABLE_INCREMENT)
5164 * DECL_DIE_TABLE_INCREMENT;
5166 decl_die_table
5167 = (dw_die_ref *) xrealloc (decl_die_table,
5168 sizeof (dw_die_ref) * num_allocated);
5170 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5171 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5172 decl_die_table_allocated = num_allocated;
5175 if (decl_id >= decl_die_table_in_use)
5176 decl_die_table_in_use = (decl_id + 1);
5178 decl_die_table[decl_id] = decl_die;
5181 /* Keep track of the number of spaces used to indent the
5182 output of the debugging routines that print the structure of
5183 the DIE internal representation. */
5184 static int print_indent;
5186 /* Indent the line the number of spaces given by print_indent. */
5188 static inline void
5189 print_spaces (outfile)
5190 FILE *outfile;
5192 fprintf (outfile, "%*s", print_indent, "");
5195 /* Print the information associated with a given DIE, and its children.
5196 This routine is a debugging aid only. */
5198 static void
5199 print_die (die, outfile)
5200 dw_die_ref die;
5201 FILE *outfile;
5203 dw_attr_ref a;
5204 dw_die_ref c;
5206 print_spaces (outfile);
5207 fprintf (outfile, "DIE %4lu: %s\n",
5208 die->die_offset, dwarf_tag_name (die->die_tag));
5209 print_spaces (outfile);
5210 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5211 fprintf (outfile, " offset: %lu\n", die->die_offset);
5213 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5215 print_spaces (outfile);
5216 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5218 switch (AT_class (a))
5220 case dw_val_class_addr:
5221 fprintf (outfile, "address");
5222 break;
5223 case dw_val_class_offset:
5224 fprintf (outfile, "offset");
5225 break;
5226 case dw_val_class_loc:
5227 fprintf (outfile, "location descriptor");
5228 break;
5229 case dw_val_class_loc_list:
5230 fprintf (outfile, "location list -> label:%s",
5231 AT_loc_list (a)->ll_symbol);
5232 break;
5233 case dw_val_class_range_list:
5234 fprintf (outfile, "range list");
5235 break;
5236 case dw_val_class_const:
5237 fprintf (outfile, "%ld", AT_int (a));
5238 break;
5239 case dw_val_class_unsigned_const:
5240 fprintf (outfile, "%lu", AT_unsigned (a));
5241 break;
5242 case dw_val_class_long_long:
5243 fprintf (outfile, "constant (%lu,%lu)",
5244 a->dw_attr_val.v.val_long_long.hi,
5245 a->dw_attr_val.v.val_long_long.low);
5246 break;
5247 case dw_val_class_float:
5248 fprintf (outfile, "floating-point constant");
5249 break;
5250 case dw_val_class_flag:
5251 fprintf (outfile, "%u", AT_flag (a));
5252 break;
5253 case dw_val_class_die_ref:
5254 if (AT_ref (a) != NULL)
5256 if (AT_ref (a)->die_symbol)
5257 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5258 else
5259 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5261 else
5262 fprintf (outfile, "die -> <null>");
5263 break;
5264 case dw_val_class_lbl_id:
5265 case dw_val_class_lbl_offset:
5266 fprintf (outfile, "label: %s", AT_lbl (a));
5267 break;
5268 case dw_val_class_str:
5269 if (AT_string (a) != NULL)
5270 fprintf (outfile, "\"%s\"", AT_string (a));
5271 else
5272 fprintf (outfile, "<null>");
5273 break;
5274 default:
5275 break;
5278 fprintf (outfile, "\n");
5281 if (die->die_child != NULL)
5283 print_indent += 4;
5284 for (c = die->die_child; c != NULL; c = c->die_sib)
5285 print_die (c, outfile);
5287 print_indent -= 4;
5289 if (print_indent == 0)
5290 fprintf (outfile, "\n");
5293 /* Print the contents of the source code line number correspondence table.
5294 This routine is a debugging aid only. */
5296 static void
5297 print_dwarf_line_table (outfile)
5298 FILE *outfile;
5300 unsigned i;
5301 dw_line_info_ref line_info;
5303 fprintf (outfile, "\n\nDWARF source line information\n");
5304 for (i = 1; i < line_info_table_in_use; i++)
5306 line_info = &line_info_table[i];
5307 fprintf (outfile, "%5d: ", i);
5308 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5309 fprintf (outfile, "%6ld", line_info->dw_line_num);
5310 fprintf (outfile, "\n");
5313 fprintf (outfile, "\n\n");
5316 /* Print the information collected for a given DIE. */
5318 void
5319 debug_dwarf_die (die)
5320 dw_die_ref die;
5322 print_die (die, stderr);
5325 /* Print all DWARF information collected for the compilation unit.
5326 This routine is a debugging aid only. */
5328 void
5329 debug_dwarf ()
5331 print_indent = 0;
5332 print_die (comp_unit_die, stderr);
5333 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5334 print_dwarf_line_table (stderr);
5337 /* We build up the lists of children and attributes by pushing new ones
5338 onto the beginning of the list. Reverse the lists for DIE so that
5339 they are in order of addition. */
5341 static void
5342 reverse_die_lists (die)
5343 dw_die_ref die;
5345 dw_die_ref c, cp, cn;
5346 dw_attr_ref a, ap, an;
5348 for (a = die->die_attr, ap = 0; a; a = an)
5350 an = a->dw_attr_next;
5351 a->dw_attr_next = ap;
5352 ap = a;
5355 die->die_attr = ap;
5357 for (c = die->die_child, cp = 0; c; c = cn)
5359 cn = c->die_sib;
5360 c->die_sib = cp;
5361 cp = c;
5364 die->die_child = cp;
5367 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5368 reverse all dies in add_sibling_attributes, which runs through all the dies,
5369 it would reverse all the dies. Now, however, since we don't call
5370 reverse_die_lists in add_sibling_attributes, we need a routine to
5371 recursively reverse all the dies. This is that routine. */
5373 static void
5374 reverse_all_dies (die)
5375 dw_die_ref die;
5377 dw_die_ref c;
5379 reverse_die_lists (die);
5381 for (c = die->die_child; c; c = c->die_sib)
5382 reverse_all_dies (c);
5385 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5386 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5387 DIE that marks the start of the DIEs for this include file. */
5389 static dw_die_ref
5390 push_new_compile_unit (old_unit, bincl_die)
5391 dw_die_ref old_unit, bincl_die;
5393 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5394 dw_die_ref new_unit = gen_compile_unit_die (filename);
5396 new_unit->die_sib = old_unit;
5397 return new_unit;
5400 /* Close an include-file CU and reopen the enclosing one. */
5402 static dw_die_ref
5403 pop_compile_unit (old_unit)
5404 dw_die_ref old_unit;
5406 dw_die_ref new_unit = old_unit->die_sib;
5408 old_unit->die_sib = NULL;
5409 return new_unit;
5412 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5413 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5415 /* Calculate the checksum of a location expression. */
5417 static inline void
5418 loc_checksum (loc, ctx)
5419 dw_loc_descr_ref loc;
5420 struct md5_ctx *ctx;
5422 CHECKSUM (loc->dw_loc_opc);
5423 CHECKSUM (loc->dw_loc_oprnd1);
5424 CHECKSUM (loc->dw_loc_oprnd2);
5427 /* Calculate the checksum of an attribute. */
5429 static void
5430 attr_checksum (at, ctx)
5431 dw_attr_ref at;
5432 struct md5_ctx *ctx;
5434 dw_loc_descr_ref loc;
5435 rtx r;
5437 CHECKSUM (at->dw_attr);
5439 /* We don't care about differences in file numbering. */
5440 if (at->dw_attr == DW_AT_decl_file
5441 /* Or that this was compiled with a different compiler snapshot; if
5442 the output is the same, that's what matters. */
5443 || at->dw_attr == DW_AT_producer)
5444 return;
5446 switch (AT_class (at))
5448 case dw_val_class_const:
5449 CHECKSUM (at->dw_attr_val.v.val_int);
5450 break;
5451 case dw_val_class_unsigned_const:
5452 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5453 break;
5454 case dw_val_class_long_long:
5455 CHECKSUM (at->dw_attr_val.v.val_long_long);
5456 break;
5457 case dw_val_class_float:
5458 CHECKSUM (at->dw_attr_val.v.val_float);
5459 break;
5460 case dw_val_class_flag:
5461 CHECKSUM (at->dw_attr_val.v.val_flag);
5462 break;
5463 case dw_val_class_str:
5464 CHECKSUM_STRING (AT_string (at));
5465 break;
5467 case dw_val_class_addr:
5468 r = AT_addr (at);
5469 switch (GET_CODE (r))
5471 case SYMBOL_REF:
5472 CHECKSUM_STRING (XSTR (r, 0));
5473 break;
5475 default:
5476 abort ();
5478 break;
5480 case dw_val_class_offset:
5481 CHECKSUM (at->dw_attr_val.v.val_offset);
5482 break;
5484 case dw_val_class_loc:
5485 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5486 loc_checksum (loc, ctx);
5487 break;
5489 case dw_val_class_die_ref:
5490 if (AT_ref (at)->die_offset)
5491 CHECKSUM (AT_ref (at)->die_offset);
5492 /* FIXME else use target die name or something. */
5494 case dw_val_class_fde_ref:
5495 case dw_val_class_lbl_id:
5496 case dw_val_class_lbl_offset:
5497 break;
5499 default:
5500 break;
5504 /* Calculate the checksum of a DIE. */
5506 static void
5507 die_checksum (die, ctx)
5508 dw_die_ref die;
5509 struct md5_ctx *ctx;
5511 dw_die_ref c;
5512 dw_attr_ref a;
5514 CHECKSUM (die->die_tag);
5516 for (a = die->die_attr; a; a = a->dw_attr_next)
5517 attr_checksum (a, ctx);
5519 for (c = die->die_child; c; c = c->die_sib)
5520 die_checksum (c, ctx);
5523 #undef CHECKSUM
5524 #undef CHECKSUM_STRING
5526 /* The prefix to attach to symbols on DIEs in the current comdat debug
5527 info section. */
5528 static char *comdat_symbol_id;
5530 /* The index of the current symbol within the current comdat CU. */
5531 static unsigned int comdat_symbol_number;
5533 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5534 children, and set comdat_symbol_id accordingly. */
5536 static void
5537 compute_section_prefix (unit_die)
5538 dw_die_ref unit_die;
5540 const char *base = lbasename (get_AT_string (unit_die, DW_AT_name));
5541 char *name = (char *) alloca (strlen (base) + 64);
5542 char *p;
5543 int i;
5544 unsigned char checksum[16];
5545 struct md5_ctx ctx;
5547 /* Compute the checksum of the DIE, then append part of it as hex digits to
5548 the name filename of the unit. */
5550 md5_init_ctx (&ctx);
5551 die_checksum (unit_die, &ctx);
5552 md5_finish_ctx (&ctx, checksum);
5554 sprintf (name, "%s.", base);
5555 clean_symbol_name (name);
5557 p = name + strlen (name);
5558 for (i = 0; i < 4; i++)
5560 sprintf (p, "%.2x", checksum[i]);
5561 p += 2;
5564 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5565 comdat_symbol_number = 0;
5568 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5570 static int
5571 is_type_die (die)
5572 dw_die_ref die;
5574 switch (die->die_tag)
5576 case DW_TAG_array_type:
5577 case DW_TAG_class_type:
5578 case DW_TAG_enumeration_type:
5579 case DW_TAG_pointer_type:
5580 case DW_TAG_reference_type:
5581 case DW_TAG_string_type:
5582 case DW_TAG_structure_type:
5583 case DW_TAG_subroutine_type:
5584 case DW_TAG_union_type:
5585 case DW_TAG_ptr_to_member_type:
5586 case DW_TAG_set_type:
5587 case DW_TAG_subrange_type:
5588 case DW_TAG_base_type:
5589 case DW_TAG_const_type:
5590 case DW_TAG_file_type:
5591 case DW_TAG_packed_type:
5592 case DW_TAG_volatile_type:
5593 return 1;
5594 default:
5595 return 0;
5599 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5600 Basically, we want to choose the bits that are likely to be shared between
5601 compilations (types) and leave out the bits that are specific to individual
5602 compilations (functions). */
5604 static int
5605 is_comdat_die (c)
5606 dw_die_ref c;
5608 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5609 we do for stabs. The advantage is a greater likelihood of sharing between
5610 objects that don't include headers in the same order (and therefore would
5611 put the base types in a different comdat). jason 8/28/00 */
5613 if (c->die_tag == DW_TAG_base_type)
5614 return 0;
5616 if (c->die_tag == DW_TAG_pointer_type
5617 || c->die_tag == DW_TAG_reference_type
5618 || c->die_tag == DW_TAG_const_type
5619 || c->die_tag == DW_TAG_volatile_type)
5621 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5623 return t ? is_comdat_die (t) : 0;
5626 return is_type_die (c);
5629 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5630 compilation unit. */
5632 static int
5633 is_symbol_die (c)
5634 dw_die_ref c;
5636 return (is_type_die (c)
5637 || (get_AT (c, DW_AT_declaration)
5638 && !get_AT (c, DW_AT_specification)));
5641 static char *
5642 gen_internal_sym (prefix)
5643 const char *prefix;
5645 char buf[256];
5646 static int label_num;
5648 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5649 return xstrdup (buf);
5652 /* Assign symbols to all worthy DIEs under DIE. */
5654 static void
5655 assign_symbol_names (die)
5656 dw_die_ref die;
5658 dw_die_ref c;
5660 if (is_symbol_die (die))
5662 if (comdat_symbol_id)
5664 char *p = alloca (strlen (comdat_symbol_id) + 64);
5666 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5667 comdat_symbol_id, comdat_symbol_number++);
5668 die->die_symbol = xstrdup (p);
5670 else
5671 die->die_symbol = gen_internal_sym ("LDIE");
5674 for (c = die->die_child; c != NULL; c = c->die_sib)
5675 assign_symbol_names (c);
5678 /* Traverse the DIE (which is always comp_unit_die), and set up
5679 additional compilation units for each of the include files we see
5680 bracketed by BINCL/EINCL. */
5682 static void
5683 break_out_includes (die)
5684 dw_die_ref die;
5686 dw_die_ref *ptr;
5687 dw_die_ref unit = NULL;
5688 limbo_die_node *node;
5690 for (ptr = &(die->die_child); *ptr;)
5692 dw_die_ref c = *ptr;
5694 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
5695 || (unit && is_comdat_die (c)))
5697 /* This DIE is for a secondary CU; remove it from the main one. */
5698 *ptr = c->die_sib;
5700 if (c->die_tag == DW_TAG_GNU_BINCL)
5702 unit = push_new_compile_unit (unit, c);
5703 free_die (c);
5705 else if (c->die_tag == DW_TAG_GNU_EINCL)
5707 unit = pop_compile_unit (unit);
5708 free_die (c);
5710 else
5711 add_child_die (unit, c);
5713 else
5715 /* Leave this DIE in the main CU. */
5716 ptr = &(c->die_sib);
5717 continue;
5721 #if 0
5722 /* We can only use this in debugging, since the frontend doesn't check
5723 to make sure that we leave every include file we enter. */
5724 if (unit != NULL)
5725 abort ();
5726 #endif
5728 assign_symbol_names (die);
5729 for (node = limbo_die_list; node; node = node->next)
5731 compute_section_prefix (node->die);
5732 assign_symbol_names (node->die);
5736 /* Traverse the DIE and add a sibling attribute if it may have the
5737 effect of speeding up access to siblings. To save some space,
5738 avoid generating sibling attributes for DIE's without children. */
5740 static void
5741 add_sibling_attributes (die)
5742 dw_die_ref die;
5744 dw_die_ref c;
5746 if (die->die_tag != DW_TAG_compile_unit
5747 && die->die_sib && die->die_child != NULL)
5748 /* Add the sibling link to the front of the attribute list. */
5749 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5751 for (c = die->die_child; c != NULL; c = c->die_sib)
5752 add_sibling_attributes (c);
5755 /* Output all location lists for the DIE and its children. */
5757 static void
5758 output_location_lists (die)
5759 dw_die_ref die;
5761 dw_die_ref c;
5762 dw_attr_ref d_attr;
5764 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5765 if (AT_class (d_attr) == dw_val_class_loc_list)
5766 output_loc_list (AT_loc_list (d_attr));
5768 for (c = die->die_child; c != NULL; c = c->die_sib)
5769 output_location_lists (c);
5773 /* The format of each DIE (and its attribute value pairs) is encoded in an
5774 abbreviation table. This routine builds the abbreviation table and assigns
5775 a unique abbreviation id for each abbreviation entry. The children of each
5776 die are visited recursively. */
5778 static void
5779 build_abbrev_table (die)
5780 dw_die_ref die;
5782 unsigned long abbrev_id;
5783 unsigned int n_alloc;
5784 dw_die_ref c;
5785 dw_attr_ref d_attr, a_attr;
5787 /* Scan the DIE references, and mark as external any that refer to
5788 DIEs from other CUs (i.e. those which are not marked). */
5789 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5790 if (AT_class (d_attr) == dw_val_class_die_ref
5791 && AT_ref (d_attr)->die_mark == 0)
5793 if (AT_ref (d_attr)->die_symbol == 0)
5794 abort ();
5796 set_AT_ref_external (d_attr, 1);
5799 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5801 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5803 if (abbrev->die_tag == die->die_tag)
5805 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5807 a_attr = abbrev->die_attr;
5808 d_attr = die->die_attr;
5810 while (a_attr != NULL && d_attr != NULL)
5812 if ((a_attr->dw_attr != d_attr->dw_attr)
5813 || (value_format (a_attr) != value_format (d_attr)))
5814 break;
5816 a_attr = a_attr->dw_attr_next;
5817 d_attr = d_attr->dw_attr_next;
5820 if (a_attr == NULL && d_attr == NULL)
5821 break;
5826 if (abbrev_id >= abbrev_die_table_in_use)
5828 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5830 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5831 abbrev_die_table
5832 = (dw_die_ref *) xrealloc (abbrev_die_table,
5833 sizeof (dw_die_ref) * n_alloc);
5835 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5836 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5837 abbrev_die_table_allocated = n_alloc;
5840 ++abbrev_die_table_in_use;
5841 abbrev_die_table[abbrev_id] = die;
5844 die->die_abbrev = abbrev_id;
5845 for (c = die->die_child; c != NULL; c = c->die_sib)
5846 build_abbrev_table (c);
5849 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5851 static int
5852 constant_size (value)
5853 long unsigned value;
5855 int log;
5857 if (value == 0)
5858 log = 0;
5859 else
5860 log = floor_log2 (value);
5862 log = log / 8;
5863 log = 1 << (floor_log2 (log) + 1);
5865 return log;
5868 /* Return the size of a DIE as it is represented in the
5869 .debug_info section. */
5871 static unsigned long
5872 size_of_die (die)
5873 dw_die_ref die;
5875 unsigned long size = 0;
5876 dw_attr_ref a;
5878 size += size_of_uleb128 (die->die_abbrev);
5879 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5881 switch (AT_class (a))
5883 case dw_val_class_addr:
5884 size += DWARF2_ADDR_SIZE;
5885 break;
5886 case dw_val_class_offset:
5887 size += DWARF_OFFSET_SIZE;
5888 break;
5889 case dw_val_class_loc:
5891 unsigned long lsize = size_of_locs (AT_loc (a));
5893 /* Block length. */
5894 size += constant_size (lsize);
5895 size += lsize;
5897 break;
5898 case dw_val_class_loc_list:
5899 size += DWARF_OFFSET_SIZE;
5900 break;
5901 case dw_val_class_range_list:
5902 size += DWARF_OFFSET_SIZE;
5903 break;
5904 case dw_val_class_const:
5905 size += size_of_sleb128 (AT_int (a));
5906 break;
5907 case dw_val_class_unsigned_const:
5908 size += constant_size (AT_unsigned (a));
5909 break;
5910 case dw_val_class_long_long:
5911 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5912 break;
5913 case dw_val_class_float:
5914 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5915 break;
5916 case dw_val_class_flag:
5917 size += 1;
5918 break;
5919 case dw_val_class_die_ref:
5920 size += DWARF_OFFSET_SIZE;
5921 break;
5922 case dw_val_class_fde_ref:
5923 size += DWARF_OFFSET_SIZE;
5924 break;
5925 case dw_val_class_lbl_id:
5926 size += DWARF2_ADDR_SIZE;
5927 break;
5928 case dw_val_class_lbl_offset:
5929 size += DWARF_OFFSET_SIZE;
5930 break;
5931 case dw_val_class_str:
5932 if (AT_string_form (a) == DW_FORM_strp)
5933 size += DWARF_OFFSET_SIZE;
5934 else
5935 size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1;
5936 break;
5937 default:
5938 abort ();
5942 return size;
5945 /* Size the debugging information associated with a given DIE. Visits the
5946 DIE's children recursively. Updates the global variable next_die_offset, on
5947 each time through. Uses the current value of next_die_offset to update the
5948 die_offset field in each DIE. */
5950 static void
5951 calc_die_sizes (die)
5952 dw_die_ref die;
5954 dw_die_ref c;
5956 die->die_offset = next_die_offset;
5957 next_die_offset += size_of_die (die);
5959 for (c = die->die_child; c != NULL; c = c->die_sib)
5960 calc_die_sizes (c);
5962 if (die->die_child != NULL)
5963 /* Count the null byte used to terminate sibling lists. */
5964 next_die_offset += 1;
5967 /* Set the marks for a die and its children. We do this so
5968 that we know whether or not a reference needs to use FORM_ref_addr; only
5969 DIEs in the same CU will be marked. We used to clear out the offset
5970 and use that as the flag, but ran into ordering problems. */
5972 static void
5973 mark_dies (die)
5974 dw_die_ref die;
5976 dw_die_ref c;
5978 die->die_mark = 1;
5979 for (c = die->die_child; c; c = c->die_sib)
5980 mark_dies (c);
5983 /* Clear the marks for a die and its children. */
5985 static void
5986 unmark_dies (die)
5987 dw_die_ref die;
5989 dw_die_ref c;
5991 die->die_mark = 0;
5992 for (c = die->die_child; c; c = c->die_sib)
5993 unmark_dies (c);
5996 /* Return the size of the .debug_pubnames table generated for the
5997 compilation unit. */
5999 static unsigned long
6000 size_of_pubnames ()
6002 unsigned long size;
6003 unsigned i;
6005 size = DWARF_PUBNAMES_HEADER_SIZE;
6006 for (i = 0; i < pubname_table_in_use; i++)
6008 pubname_ref p = &pubname_table[i];
6009 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
6012 size += DWARF_OFFSET_SIZE;
6013 return size;
6016 /* Return the size of the information in the .debug_aranges section. */
6018 static unsigned long
6019 size_of_aranges ()
6021 unsigned long size;
6023 size = DWARF_ARANGES_HEADER_SIZE;
6025 /* Count the address/length pair for this compilation unit. */
6026 size += 2 * DWARF2_ADDR_SIZE;
6027 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6029 /* Count the two zero words used to terminated the address range table. */
6030 size += 2 * DWARF2_ADDR_SIZE;
6031 return size;
6034 /* Select the encoding of an attribute value. */
6036 static enum dwarf_form
6037 value_format (a)
6038 dw_attr_ref a;
6040 switch (a->dw_attr_val.val_class)
6042 case dw_val_class_addr:
6043 return DW_FORM_addr;
6044 case dw_val_class_range_list:
6045 case dw_val_class_offset:
6046 if (DWARF_OFFSET_SIZE == 4)
6047 return DW_FORM_data4;
6048 if (DWARF_OFFSET_SIZE == 8)
6049 return DW_FORM_data8;
6050 abort ();
6051 case dw_val_class_loc_list:
6052 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6053 .debug_loc section */
6054 return DW_FORM_data4;
6055 case dw_val_class_loc:
6056 switch (constant_size (size_of_locs (AT_loc (a))))
6058 case 1:
6059 return DW_FORM_block1;
6060 case 2:
6061 return DW_FORM_block2;
6062 default:
6063 abort ();
6065 case dw_val_class_const:
6066 return DW_FORM_sdata;
6067 case dw_val_class_unsigned_const:
6068 switch (constant_size (AT_unsigned (a)))
6070 case 1:
6071 return DW_FORM_data1;
6072 case 2:
6073 return DW_FORM_data2;
6074 case 4:
6075 return DW_FORM_data4;
6076 case 8:
6077 return DW_FORM_data8;
6078 default:
6079 abort ();
6081 case dw_val_class_long_long:
6082 return DW_FORM_block1;
6083 case dw_val_class_float:
6084 return DW_FORM_block1;
6085 case dw_val_class_flag:
6086 return DW_FORM_flag;
6087 case dw_val_class_die_ref:
6088 if (AT_ref_external (a))
6089 return DW_FORM_ref_addr;
6090 else
6091 return DW_FORM_ref;
6092 case dw_val_class_fde_ref:
6093 return DW_FORM_data;
6094 case dw_val_class_lbl_id:
6095 return DW_FORM_addr;
6096 case dw_val_class_lbl_offset:
6097 return DW_FORM_data;
6098 case dw_val_class_str:
6099 return AT_string_form (a);
6101 default:
6102 abort ();
6106 /* Output the encoding of an attribute value. */
6108 static void
6109 output_value_format (a)
6110 dw_attr_ref a;
6112 enum dwarf_form form = value_format (a);
6114 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6117 /* Output the .debug_abbrev section which defines the DIE abbreviation
6118 table. */
6120 static void
6121 output_abbrev_section ()
6123 unsigned long abbrev_id;
6125 dw_attr_ref a_attr;
6127 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6129 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6131 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6132 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6133 dwarf_tag_name (abbrev->die_tag));
6135 if (abbrev->die_child != NULL)
6136 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6137 else
6138 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6140 for (a_attr = abbrev->die_attr; a_attr != NULL;
6141 a_attr = a_attr->dw_attr_next)
6143 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6144 dwarf_attr_name (a_attr->dw_attr));
6145 output_value_format (a_attr);
6148 dw2_asm_output_data (1, 0, NULL);
6149 dw2_asm_output_data (1, 0, NULL);
6152 /* Terminate the table. */
6153 dw2_asm_output_data (1, 0, NULL);
6156 /* Output a symbol we can use to refer to this DIE from another CU. */
6158 static inline void
6159 output_die_symbol (die)
6160 dw_die_ref die;
6162 char *sym = die->die_symbol;
6164 if (sym == 0)
6165 return;
6167 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6168 /* We make these global, not weak; if the target doesn't support
6169 .linkonce, it doesn't support combining the sections, so debugging
6170 will break. */
6171 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6173 ASM_OUTPUT_LABEL (asm_out_file, sym);
6176 /* Return a new location list, given the begin and end range, and the
6177 expression. gensym tells us whether to generate a new internal symbol for
6178 this location list node, which is done for the head of the list only. */
6180 static inline dw_loc_list_ref
6181 new_loc_list (expr, begin, end, section, gensym)
6182 dw_loc_descr_ref expr;
6183 const char *begin;
6184 const char *end;
6185 const char *section;
6186 unsigned gensym;
6188 dw_loc_list_ref retlist
6189 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6191 retlist->begin = begin;
6192 retlist->end = end;
6193 retlist->expr = expr;
6194 retlist->section = section;
6195 if (gensym)
6196 retlist->ll_symbol = gen_internal_sym ("LLST");
6198 return retlist;
6201 /* Add a location description expression to a location list */
6203 static inline void
6204 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6205 dw_loc_list_ref *list_head;
6206 dw_loc_descr_ref descr;
6207 const char *begin;
6208 const char *end;
6209 const char *section;
6211 dw_loc_list_ref *d;
6213 /* Find the end of the chain. */
6214 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6217 /* Add a new location list node to the list */
6218 *d = new_loc_list (descr, begin, end, section, 0);
6221 /* Output the location list given to us */
6223 static void
6224 output_loc_list (list_head)
6225 dw_loc_list_ref list_head;
6227 dw_loc_list_ref curr = list_head;
6229 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6231 /* ??? This shouldn't be needed now that we've forced the
6232 compilation unit base address to zero when there is code
6233 in more than one section. */
6234 if (strcmp (curr->section, ".text") == 0)
6236 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6237 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
6238 "Location list base address specifier fake entry");
6239 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6240 "Location list base address specifier base");
6243 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
6245 unsigned long size;
6247 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6248 "Location list begin address (%s)",
6249 list_head->ll_symbol);
6250 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6251 "Location list end address (%s)",
6252 list_head->ll_symbol);
6253 size = size_of_locs (curr->expr);
6255 /* Output the block length for this list of location operations. */
6256 if (size > 0xffff)
6257 abort ();
6258 dw2_asm_output_data (2, size, "%s", "Location expression size");
6260 output_loc_sequence (curr->expr);
6263 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6264 "Location list terminator begin (%s)",
6265 list_head->ll_symbol);
6266 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6267 "Location list terminator end (%s)",
6268 list_head->ll_symbol);
6271 /* Output the DIE and its attributes. Called recursively to generate
6272 the definitions of each child DIE. */
6274 static void
6275 output_die (die)
6276 dw_die_ref die;
6278 dw_attr_ref a;
6279 dw_die_ref c;
6280 unsigned long size;
6282 /* If someone in another CU might refer to us, set up a symbol for
6283 them to point to. */
6284 if (die->die_symbol)
6285 output_die_symbol (die);
6287 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6288 die->die_offset, dwarf_tag_name (die->die_tag));
6290 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6292 const char *name = dwarf_attr_name (a->dw_attr);
6294 switch (AT_class (a))
6296 case dw_val_class_addr:
6297 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6298 break;
6300 case dw_val_class_offset:
6301 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6302 "%s", name);
6303 break;
6305 case dw_val_class_range_list:
6307 char *p = strchr (ranges_section_label, '\0');
6309 sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset);
6310 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6311 "%s", name);
6312 *p = '\0';
6314 break;
6316 case dw_val_class_loc:
6317 size = size_of_locs (AT_loc (a));
6319 /* Output the block length for this list of location operations. */
6320 dw2_asm_output_data (constant_size (size), size, "%s", name);
6322 output_loc_sequence (AT_loc (a));
6323 break;
6325 case dw_val_class_const:
6326 /* ??? It would be slightly more efficient to use a scheme like is
6327 used for unsigned constants below, but gdb 4.x does not sign
6328 extend. Gdb 5.x does sign extend. */
6329 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6330 break;
6332 case dw_val_class_unsigned_const:
6333 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6334 AT_unsigned (a), "%s", name);
6335 break;
6337 case dw_val_class_long_long:
6339 unsigned HOST_WIDE_INT first, second;
6341 dw2_asm_output_data (1,
6342 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6343 "%s", name);
6345 if (WORDS_BIG_ENDIAN)
6347 first = a->dw_attr_val.v.val_long_long.hi;
6348 second = a->dw_attr_val.v.val_long_long.low;
6350 else
6352 first = a->dw_attr_val.v.val_long_long.low;
6353 second = a->dw_attr_val.v.val_long_long.hi;
6356 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6357 first, "long long constant");
6358 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6359 second, NULL);
6361 break;
6363 case dw_val_class_float:
6365 unsigned int i;
6367 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6368 "%s", name);
6370 for (i = 0; i < a->dw_attr_val.v.val_float.length; i++)
6371 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6372 "fp constant word %u", i);
6373 break;
6376 case dw_val_class_flag:
6377 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6378 break;
6380 case dw_val_class_loc_list:
6382 char *sym = AT_loc_list (a)->ll_symbol;
6384 if (sym == 0)
6385 abort ();
6386 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6387 loc_section_label, "%s", name);
6389 break;
6391 case dw_val_class_die_ref:
6392 if (AT_ref_external (a))
6394 char *sym = AT_ref (a)->die_symbol;
6396 if (sym == 0)
6397 abort ();
6398 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6400 else if (AT_ref (a)->die_offset == 0)
6401 abort ();
6402 else
6403 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6404 "%s", name);
6405 break;
6407 case dw_val_class_fde_ref:
6409 char l1[20];
6411 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6412 a->dw_attr_val.v.val_fde_index * 2);
6413 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6415 break;
6417 case dw_val_class_lbl_id:
6418 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6419 break;
6421 case dw_val_class_lbl_offset:
6422 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6423 break;
6425 case dw_val_class_str:
6426 if (AT_string_form (a) == DW_FORM_strp)
6427 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6428 a->dw_attr_val.v.val_str->label,
6429 "%s: \"%s\"", name, AT_string (a));
6430 else
6431 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6432 break;
6434 default:
6435 abort ();
6439 for (c = die->die_child; c != NULL; c = c->die_sib)
6440 output_die (c);
6442 /* Add null byte to terminate sibling list. */
6443 if (die->die_child != NULL)
6444 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6445 die->die_offset);
6448 /* Output the compilation unit that appears at the beginning of the
6449 .debug_info section, and precedes the DIE descriptions. */
6451 static void
6452 output_compilation_unit_header ()
6454 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6455 "Length of Compilation Unit Info");
6456 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6457 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6458 "Offset Into Abbrev. Section");
6459 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6462 /* Output the compilation unit DIE and its children. */
6464 static void
6465 output_comp_unit (die)
6466 dw_die_ref die;
6468 const char *secname;
6470 /* Even if there are no children of this DIE, we must output the information
6471 about the compilation unit. Otherwise, on an empty translation unit, we
6472 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6473 will then complain when examining the file. First mark all the DIEs in
6474 this CU so we know which get local refs. */
6475 mark_dies (die);
6477 build_abbrev_table (die);
6479 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6480 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6481 calc_die_sizes (die);
6483 if (die->die_symbol)
6485 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6487 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6488 secname = tmp;
6489 die->die_symbol = NULL;
6491 else
6492 secname = (const char *) DEBUG_INFO_SECTION;
6494 /* Output debugging information. */
6495 named_section_flags (secname, SECTION_DEBUG);
6496 output_compilation_unit_header ();
6497 output_die (die);
6499 /* Leave the marks on the main CU, so we can check them in
6500 output_pubnames. */
6501 if (die->die_symbol)
6502 unmark_dies (die);
6505 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6506 output of lang_hooks.decl_printable_name for C++ looks like
6507 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6509 static const char *
6510 dwarf2_name (decl, scope)
6511 tree decl;
6512 int scope;
6514 return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0);
6517 /* Add a new entry to .debug_pubnames if appropriate. */
6519 static void
6520 add_pubname (decl, die)
6521 tree decl;
6522 dw_die_ref die;
6524 pubname_ref p;
6526 if (! TREE_PUBLIC (decl))
6527 return;
6529 if (pubname_table_in_use == pubname_table_allocated)
6531 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6532 pubname_table
6533 = (pubname_ref) xrealloc (pubname_table,
6534 (pubname_table_allocated
6535 * sizeof (pubname_entry)));
6538 p = &pubname_table[pubname_table_in_use++];
6539 p->die = die;
6540 p->name = xstrdup (dwarf2_name (decl, 1));
6543 /* Output the public names table used to speed up access to externally
6544 visible names. For now, only generate entries for externally
6545 visible procedures. */
6547 static void
6548 output_pubnames ()
6550 unsigned i;
6551 unsigned long pubnames_length = size_of_pubnames ();
6553 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6554 "Length of Public Names Info");
6555 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6556 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6557 "Offset of Compilation Unit Info");
6558 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6559 "Compilation Unit Length");
6561 for (i = 0; i < pubname_table_in_use; i++)
6563 pubname_ref pub = &pubname_table[i];
6565 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6566 if (pub->die->die_mark == 0)
6567 abort ();
6569 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6570 "DIE offset");
6572 dw2_asm_output_nstring (pub->name, -1, "external name");
6575 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6578 /* Add a new entry to .debug_aranges if appropriate. */
6580 static void
6581 add_arange (decl, die)
6582 tree decl;
6583 dw_die_ref die;
6585 if (! DECL_SECTION_NAME (decl))
6586 return;
6588 if (arange_table_in_use == arange_table_allocated)
6590 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6591 arange_table = (dw_die_ref *)
6592 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6595 arange_table[arange_table_in_use++] = die;
6598 /* Output the information that goes into the .debug_aranges table.
6599 Namely, define the beginning and ending address range of the
6600 text section generated for this compilation unit. */
6602 static void
6603 output_aranges ()
6605 unsigned i;
6606 unsigned long aranges_length = size_of_aranges ();
6608 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6609 "Length of Address Ranges Info");
6610 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6611 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6612 "Offset of Compilation Unit Info");
6613 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6614 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6616 /* We need to align to twice the pointer size here. */
6617 if (DWARF_ARANGES_PAD_SIZE)
6619 /* Pad using a 2 byte words so that padding is correct for any
6620 pointer size. */
6621 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6622 2 * DWARF2_ADDR_SIZE);
6623 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6624 dw2_asm_output_data (2, 0, NULL);
6627 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6628 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6629 text_section_label, "Length");
6631 for (i = 0; i < arange_table_in_use; i++)
6633 dw_die_ref die = arange_table[i];
6635 /* We shouldn't see aranges for DIEs outside of the main CU. */
6636 if (die->die_mark == 0)
6637 abort ();
6639 if (die->die_tag == DW_TAG_subprogram)
6641 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6642 "Address");
6643 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6644 get_AT_low_pc (die), "Length");
6646 else
6648 /* A static variable; extract the symbol from DW_AT_location.
6649 Note that this code isn't currently hit, as we only emit
6650 aranges for functions (jason 9/23/99). */
6651 dw_attr_ref a = get_AT (die, DW_AT_location);
6652 dw_loc_descr_ref loc;
6654 if (! a || AT_class (a) != dw_val_class_loc)
6655 abort ();
6657 loc = AT_loc (a);
6658 if (loc->dw_loc_opc != DW_OP_addr)
6659 abort ();
6661 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6662 loc->dw_loc_oprnd1.v.val_addr, "Address");
6663 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6664 get_AT_unsigned (die, DW_AT_byte_size),
6665 "Length");
6669 /* Output the terminator words. */
6670 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6671 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6674 /* Add a new entry to .debug_ranges. Return the offset at which it
6675 was placed. */
6677 static unsigned int
6678 add_ranges (block)
6679 tree block;
6681 unsigned int in_use = ranges_table_in_use;
6683 if (in_use == ranges_table_allocated)
6685 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6686 ranges_table = (dw_ranges_ref)
6687 xrealloc (ranges_table, (ranges_table_allocated
6688 * sizeof (struct dw_ranges_struct)));
6691 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6692 ranges_table_in_use = in_use + 1;
6694 return in_use * 2 * DWARF2_ADDR_SIZE;
6697 static void
6698 output_ranges ()
6700 unsigned i;
6701 static const char *const start_fmt = "Offset 0x%x";
6702 const char *fmt = start_fmt;
6704 for (i = 0; i < ranges_table_in_use; i++)
6706 int block_num = ranges_table[i].block_num;
6708 if (block_num)
6710 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6711 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6713 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6714 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6716 /* If all code is in the text section, then the compilation
6717 unit base address defaults to DW_AT_low_pc, which is the
6718 base of the text section. */
6719 if (separate_line_info_table_in_use == 0)
6721 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6722 text_section_label,
6723 fmt, i * 2 * DWARF2_ADDR_SIZE);
6724 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6725 text_section_label, NULL);
6728 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6729 compilation unit base address to zero, which allows us to
6730 use absolute addresses, and not worry about whether the
6731 target supports cross-section arithmetic. */
6732 else
6734 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6735 fmt, i * 2 * DWARF2_ADDR_SIZE);
6736 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6739 fmt = NULL;
6741 else
6743 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6744 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6745 fmt = start_fmt;
6750 /* Data structure containing information about input files. */
6751 struct file_info
6753 char *path; /* Complete file name. */
6754 char *fname; /* File name part. */
6755 int length; /* Length of entire string. */
6756 int file_idx; /* Index in input file table. */
6757 int dir_idx; /* Index in directory table. */
6760 /* Data structure containing information about directories with source
6761 files. */
6762 struct dir_info
6764 char *path; /* Path including directory name. */
6765 int length; /* Path length. */
6766 int prefix; /* Index of directory entry which is a prefix. */
6767 int count; /* Number of files in this directory. */
6768 int dir_idx; /* Index of directory used as base. */
6769 int used; /* Used in the end? */
6772 /* Callback function for file_info comparison. We sort by looking at
6773 the directories in the path. */
6775 static int
6776 file_info_cmp (p1, p2)
6777 const void *p1;
6778 const void *p2;
6780 const struct file_info *s1 = p1;
6781 const struct file_info *s2 = p2;
6782 unsigned char *cp1;
6783 unsigned char *cp2;
6785 /* Take care of file names without directories. We need to make sure that
6786 we return consistent values to qsort since some will get confused if
6787 we return the same value when identical operands are passed in opposite
6788 orders. So if neither has a directory, return 0 and otherwise return
6789 1 or -1 depending on which one has the directory. */
6790 if ((s1->path == s1->fname || s2->path == s2->fname))
6791 return (s2->path == s2->fname) - (s1->path == s1->fname);
6793 cp1 = (unsigned char *) s1->path;
6794 cp2 = (unsigned char *) s2->path;
6796 while (1)
6798 ++cp1;
6799 ++cp2;
6800 /* Reached the end of the first path? If so, handle like above. */
6801 if ((cp1 == (unsigned char *) s1->fname)
6802 || (cp2 == (unsigned char *) s2->fname))
6803 return ((cp2 == (unsigned char *) s2->fname)
6804 - (cp1 == (unsigned char *) s1->fname));
6806 /* Character of current path component the same? */
6807 else if (*cp1 != *cp2)
6808 return *cp1 - *cp2;
6812 /* Output the directory table and the file name table. We try to minimize
6813 the total amount of memory needed. A heuristic is used to avoid large
6814 slowdowns with many input files. */
6816 static void
6817 output_file_names ()
6819 struct file_info *files;
6820 struct dir_info *dirs;
6821 int *saved;
6822 int *savehere;
6823 int *backmap;
6824 int ndirs;
6825 int idx_offset;
6826 int i;
6827 int idx;
6829 /* Allocate the various arrays we need. */
6830 files = (struct file_info *) alloca (file_table.in_use
6831 * sizeof (struct file_info));
6832 dirs = (struct dir_info *) alloca (file_table.in_use
6833 * sizeof (struct dir_info));
6835 /* Sort the file names. */
6836 for (i = 1; i < (int) file_table.in_use; i++)
6838 char *f;
6840 /* Skip all leading "./". */
6841 f = file_table.table[i];
6842 while (f[0] == '.' && f[1] == '/')
6843 f += 2;
6845 /* Create a new array entry. */
6846 files[i].path = f;
6847 files[i].length = strlen (f);
6848 files[i].file_idx = i;
6850 /* Search for the file name part. */
6851 f = strrchr (f, '/');
6852 files[i].fname = f == NULL ? files[i].path : f + 1;
6855 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6857 /* Find all the different directories used. */
6858 dirs[0].path = files[1].path;
6859 dirs[0].length = files[1].fname - files[1].path;
6860 dirs[0].prefix = -1;
6861 dirs[0].count = 1;
6862 dirs[0].dir_idx = 0;
6863 dirs[0].used = 0;
6864 files[1].dir_idx = 0;
6865 ndirs = 1;
6867 for (i = 2; i < (int) file_table.in_use; i++)
6868 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6869 && memcmp (dirs[ndirs - 1].path, files[i].path,
6870 dirs[ndirs - 1].length) == 0)
6872 /* Same directory as last entry. */
6873 files[i].dir_idx = ndirs - 1;
6874 ++dirs[ndirs - 1].count;
6876 else
6878 int j;
6880 /* This is a new directory. */
6881 dirs[ndirs].path = files[i].path;
6882 dirs[ndirs].length = files[i].fname - files[i].path;
6883 dirs[ndirs].count = 1;
6884 dirs[ndirs].dir_idx = ndirs;
6885 dirs[ndirs].used = 0;
6886 files[i].dir_idx = ndirs;
6888 /* Search for a prefix. */
6889 dirs[ndirs].prefix = -1;
6890 for (j = 0; j < ndirs; j++)
6891 if (dirs[j].length < dirs[ndirs].length
6892 && dirs[j].length > 1
6893 && (dirs[ndirs].prefix == -1
6894 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6895 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6896 dirs[ndirs].prefix = j;
6898 ++ndirs;
6901 /* Now to the actual work. We have to find a subset of the directories which
6902 allow expressing the file name using references to the directory table
6903 with the least amount of characters. We do not do an exhaustive search
6904 where we would have to check out every combination of every single
6905 possible prefix. Instead we use a heuristic which provides nearly optimal
6906 results in most cases and never is much off. */
6907 saved = (int *) alloca (ndirs * sizeof (int));
6908 savehere = (int *) alloca (ndirs * sizeof (int));
6910 memset (saved, '\0', ndirs * sizeof (saved[0]));
6911 for (i = 0; i < ndirs; i++)
6913 int j;
6914 int total;
6916 /* We can always save some space for the current directory. But this
6917 does not mean it will be enough to justify adding the directory. */
6918 savehere[i] = dirs[i].length;
6919 total = (savehere[i] - saved[i]) * dirs[i].count;
6921 for (j = i + 1; j < ndirs; j++)
6923 savehere[j] = 0;
6924 if (saved[j] < dirs[i].length)
6926 /* Determine whether the dirs[i] path is a prefix of the
6927 dirs[j] path. */
6928 int k;
6930 k = dirs[j].prefix;
6931 while (k != -1 && k != i)
6932 k = dirs[k].prefix;
6934 if (k == i)
6936 /* Yes it is. We can possibly safe some memory but
6937 writing the filenames in dirs[j] relative to
6938 dirs[i]. */
6939 savehere[j] = dirs[i].length;
6940 total += (savehere[j] - saved[j]) * dirs[j].count;
6945 /* Check whether we can safe enough to justify adding the dirs[i]
6946 directory. */
6947 if (total > dirs[i].length + 1)
6949 /* It's worthwhile adding. */
6950 for (j = i; j < ndirs; j++)
6951 if (savehere[j] > 0)
6953 /* Remember how much we saved for this directory so far. */
6954 saved[j] = savehere[j];
6956 /* Remember the prefix directory. */
6957 dirs[j].dir_idx = i;
6962 /* We have to emit them in the order they appear in the file_table array
6963 since the index is used in the debug info generation. To do this
6964 efficiently we generate a back-mapping of the indices first. */
6965 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6966 for (i = 1; i < (int) file_table.in_use; i++)
6968 backmap[files[i].file_idx] = i;
6970 /* Mark this directory as used. */
6971 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6974 /* That was it. We are ready to emit the information. First emit the
6975 directory name table. We have to make sure the first actually emitted
6976 directory name has index one; zero is reserved for the current working
6977 directory. Make sure we do not confuse these indices with the one for the
6978 constructed table (even though most of the time they are identical). */
6979 idx = 1;
6980 idx_offset = dirs[0].length > 0 ? 1 : 0;
6981 for (i = 1 - idx_offset; i < ndirs; i++)
6982 if (dirs[i].used != 0)
6984 dirs[i].used = idx++;
6985 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6986 "Directory Entry: 0x%x", dirs[i].used);
6989 dw2_asm_output_data (1, 0, "End directory table");
6991 /* Correct the index for the current working directory entry if it
6992 exists. */
6993 if (idx_offset == 0)
6994 dirs[0].used = 0;
6996 /* Now write all the file names. */
6997 for (i = 1; i < (int) file_table.in_use; i++)
6999 int file_idx = backmap[i];
7000 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
7002 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
7003 "File Entry: 0x%x", i);
7005 /* Include directory index. */
7006 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
7008 /* Modification time. */
7009 dw2_asm_output_data_uleb128 (0, NULL);
7011 /* File length in bytes. */
7012 dw2_asm_output_data_uleb128 (0, NULL);
7015 dw2_asm_output_data (1, 0, "End file name table");
7019 /* Output the source line number correspondence information. This
7020 information goes into the .debug_line section. */
7022 static void
7023 output_line_info ()
7025 char l1[20], l2[20], p1[20], p2[20];
7026 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7027 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7028 unsigned opc;
7029 unsigned n_op_args;
7030 unsigned long lt_index;
7031 unsigned long current_line;
7032 long line_offset;
7033 long line_delta;
7034 unsigned long current_file;
7035 unsigned long function;
7037 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7038 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7039 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7040 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7042 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7043 "Length of Source Line Info");
7044 ASM_OUTPUT_LABEL (asm_out_file, l1);
7046 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7047 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7048 ASM_OUTPUT_LABEL (asm_out_file, p1);
7050 /* Define the architecture-dependent minimum instruction length (in
7051 bytes). In this implementation of DWARF, this field is used for
7052 information purposes only. Since GCC generates assembly language,
7053 we have no a priori knowledge of how many instruction bytes are
7054 generated for each source line, and therefore can use only the
7055 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7056 commands. Accordingly, we fix this as `1', which is "correct
7057 enough" for all architectures, and don't let the target override. */
7058 dw2_asm_output_data (1, 1,
7059 "Minimum Instruction Length");
7061 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7062 "Default is_stmt_start flag");
7063 dw2_asm_output_data (1, DWARF_LINE_BASE,
7064 "Line Base Value (Special Opcodes)");
7065 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7066 "Line Range Value (Special Opcodes)");
7067 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7068 "Special Opcode Base");
7070 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7072 switch (opc)
7074 case DW_LNS_advance_pc:
7075 case DW_LNS_advance_line:
7076 case DW_LNS_set_file:
7077 case DW_LNS_set_column:
7078 case DW_LNS_fixed_advance_pc:
7079 n_op_args = 1;
7080 break;
7081 default:
7082 n_op_args = 0;
7083 break;
7086 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7087 opc, n_op_args);
7090 /* Write out the information about the files we use. */
7091 output_file_names ();
7092 ASM_OUTPUT_LABEL (asm_out_file, p2);
7094 /* We used to set the address register to the first location in the text
7095 section here, but that didn't accomplish anything since we already
7096 have a line note for the opening brace of the first function. */
7098 /* Generate the line number to PC correspondence table, encoded as
7099 a series of state machine operations. */
7100 current_file = 1;
7101 current_line = 1;
7102 strcpy (prev_line_label, text_section_label);
7103 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7105 dw_line_info_ref line_info = &line_info_table[lt_index];
7107 #if 0
7108 /* Disable this optimization for now; GDB wants to see two line notes
7109 at the beginning of a function so it can find the end of the
7110 prologue. */
7112 /* Don't emit anything for redundant notes. Just updating the
7113 address doesn't accomplish anything, because we already assume
7114 that anything after the last address is this line. */
7115 if (line_info->dw_line_num == current_line
7116 && line_info->dw_file_num == current_file)
7117 continue;
7118 #endif
7120 /* Emit debug info for the address of the current line.
7122 Unfortunately, we have little choice here currently, and must always
7123 use the most general form. GCC does not know the address delta
7124 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7125 attributes which will give an upper bound on the address range. We
7126 could perhaps use length attributes to determine when it is safe to
7127 use DW_LNS_fixed_advance_pc. */
7129 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7130 if (0)
7132 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7133 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7134 "DW_LNS_fixed_advance_pc");
7135 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7137 else
7139 /* This can handle any delta. This takes
7140 4+DWARF2_ADDR_SIZE bytes. */
7141 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7142 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7143 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7144 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7147 strcpy (prev_line_label, line_label);
7149 /* Emit debug info for the source file of the current line, if
7150 different from the previous line. */
7151 if (line_info->dw_file_num != current_file)
7153 current_file = line_info->dw_file_num;
7154 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7155 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7156 file_table.table[current_file]);
7159 /* Emit debug info for the current line number, choosing the encoding
7160 that uses the least amount of space. */
7161 if (line_info->dw_line_num != current_line)
7163 line_offset = line_info->dw_line_num - current_line;
7164 line_delta = line_offset - DWARF_LINE_BASE;
7165 current_line = line_info->dw_line_num;
7166 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7167 /* This can handle deltas from -10 to 234, using the current
7168 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7169 takes 1 byte. */
7170 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7171 "line %lu", current_line);
7172 else
7174 /* This can handle any delta. This takes at least 4 bytes,
7175 depending on the value being encoded. */
7176 dw2_asm_output_data (1, DW_LNS_advance_line,
7177 "advance to line %lu", current_line);
7178 dw2_asm_output_data_sleb128 (line_offset, NULL);
7179 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7182 else
7183 /* We still need to start a new row, so output a copy insn. */
7184 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7187 /* Emit debug info for the address of the end of the function. */
7188 if (0)
7190 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7191 "DW_LNS_fixed_advance_pc");
7192 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7194 else
7196 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7197 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7198 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7199 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7202 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7203 dw2_asm_output_data_uleb128 (1, NULL);
7204 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7206 function = 0;
7207 current_file = 1;
7208 current_line = 1;
7209 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7211 dw_separate_line_info_ref line_info
7212 = &separate_line_info_table[lt_index];
7214 #if 0
7215 /* Don't emit anything for redundant notes. */
7216 if (line_info->dw_line_num == current_line
7217 && line_info->dw_file_num == current_file
7218 && line_info->function == function)
7219 goto cont;
7220 #endif
7222 /* Emit debug info for the address of the current line. If this is
7223 a new function, or the first line of a function, then we need
7224 to handle it differently. */
7225 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7226 lt_index);
7227 if (function != line_info->function)
7229 function = line_info->function;
7231 /* Set the address register to the first line in the function */
7232 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7233 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7234 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7235 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7237 else
7239 /* ??? See the DW_LNS_advance_pc comment above. */
7240 if (0)
7242 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7243 "DW_LNS_fixed_advance_pc");
7244 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7246 else
7248 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7249 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7250 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7251 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7255 strcpy (prev_line_label, line_label);
7257 /* Emit debug info for the source file of the current line, if
7258 different from the previous line. */
7259 if (line_info->dw_file_num != current_file)
7261 current_file = line_info->dw_file_num;
7262 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7263 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7264 file_table.table[current_file]);
7267 /* Emit debug info for the current line number, choosing the encoding
7268 that uses the least amount of space. */
7269 if (line_info->dw_line_num != current_line)
7271 line_offset = line_info->dw_line_num - current_line;
7272 line_delta = line_offset - DWARF_LINE_BASE;
7273 current_line = line_info->dw_line_num;
7274 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7275 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7276 "line %lu", current_line);
7277 else
7279 dw2_asm_output_data (1, DW_LNS_advance_line,
7280 "advance to line %lu", current_line);
7281 dw2_asm_output_data_sleb128 (line_offset, NULL);
7282 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7285 else
7286 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7288 #if 0
7289 cont:
7290 #endif
7292 lt_index++;
7294 /* If we're done with a function, end its sequence. */
7295 if (lt_index == separate_line_info_table_in_use
7296 || separate_line_info_table[lt_index].function != function)
7298 current_file = 1;
7299 current_line = 1;
7301 /* Emit debug info for the address of the end of the function. */
7302 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7303 if (0)
7305 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7306 "DW_LNS_fixed_advance_pc");
7307 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7309 else
7311 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7312 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7313 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7314 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7317 /* Output the marker for the end of this sequence. */
7318 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7319 dw2_asm_output_data_uleb128 (1, NULL);
7320 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7324 /* Output the marker for the end of the line number info. */
7325 ASM_OUTPUT_LABEL (asm_out_file, l2);
7328 /* Given a pointer to a tree node for some base type, return a pointer to
7329 a DIE that describes the given type.
7331 This routine must only be called for GCC type nodes that correspond to
7332 Dwarf base (fundamental) types. */
7334 static dw_die_ref
7335 base_type_die (type)
7336 tree type;
7338 dw_die_ref base_type_result;
7339 const char *type_name;
7340 enum dwarf_type encoding;
7341 tree name = TYPE_NAME (type);
7343 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7344 return 0;
7346 if (name)
7348 if (TREE_CODE (name) == TYPE_DECL)
7349 name = DECL_NAME (name);
7351 type_name = IDENTIFIER_POINTER (name);
7353 else
7354 type_name = "__unknown__";
7356 switch (TREE_CODE (type))
7358 case INTEGER_TYPE:
7359 /* Carefully distinguish the C character types, without messing
7360 up if the language is not C. Note that we check only for the names
7361 that contain spaces; other names might occur by coincidence in other
7362 languages. */
7363 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7364 && (type == char_type_node
7365 || ! strcmp (type_name, "signed char")
7366 || ! strcmp (type_name, "unsigned char"))))
7368 if (TREE_UNSIGNED (type))
7369 encoding = DW_ATE_unsigned;
7370 else
7371 encoding = DW_ATE_signed;
7372 break;
7374 /* else fall through. */
7376 case CHAR_TYPE:
7377 /* GNU Pascal/Ada CHAR type. Not used in C. */
7378 if (TREE_UNSIGNED (type))
7379 encoding = DW_ATE_unsigned_char;
7380 else
7381 encoding = DW_ATE_signed_char;
7382 break;
7384 case REAL_TYPE:
7385 encoding = DW_ATE_float;
7386 break;
7388 /* Dwarf2 doesn't know anything about complex ints, so use
7389 a user defined type for it. */
7390 case COMPLEX_TYPE:
7391 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7392 encoding = DW_ATE_complex_float;
7393 else
7394 encoding = DW_ATE_lo_user;
7395 break;
7397 case BOOLEAN_TYPE:
7398 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7399 encoding = DW_ATE_boolean;
7400 break;
7402 default:
7403 /* No other TREE_CODEs are Dwarf fundamental types. */
7404 abort ();
7407 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
7408 if (demangle_name_func)
7409 type_name = (*demangle_name_func) (type_name);
7411 add_AT_string (base_type_result, DW_AT_name, type_name);
7412 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7413 int_size_in_bytes (type));
7414 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7416 return base_type_result;
7419 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7420 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7421 a given type is generally the same as the given type, except that if the
7422 given type is a pointer or reference type, then the root type of the given
7423 type is the root type of the "basis" type for the pointer or reference
7424 type. (This definition of the "root" type is recursive.) Also, the root
7425 type of a `const' qualified type or a `volatile' qualified type is the
7426 root type of the given type without the qualifiers. */
7428 static tree
7429 root_type (type)
7430 tree type;
7432 if (TREE_CODE (type) == ERROR_MARK)
7433 return error_mark_node;
7435 switch (TREE_CODE (type))
7437 case ERROR_MARK:
7438 return error_mark_node;
7440 case POINTER_TYPE:
7441 case REFERENCE_TYPE:
7442 return type_main_variant (root_type (TREE_TYPE (type)));
7444 default:
7445 return type_main_variant (type);
7449 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7450 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7452 static inline int
7453 is_base_type (type)
7454 tree type;
7456 switch (TREE_CODE (type))
7458 case ERROR_MARK:
7459 case VOID_TYPE:
7460 case INTEGER_TYPE:
7461 case REAL_TYPE:
7462 case COMPLEX_TYPE:
7463 case BOOLEAN_TYPE:
7464 case CHAR_TYPE:
7465 return 1;
7467 case SET_TYPE:
7468 case ARRAY_TYPE:
7469 case RECORD_TYPE:
7470 case UNION_TYPE:
7471 case QUAL_UNION_TYPE:
7472 case ENUMERAL_TYPE:
7473 case FUNCTION_TYPE:
7474 case METHOD_TYPE:
7475 case POINTER_TYPE:
7476 case REFERENCE_TYPE:
7477 case FILE_TYPE:
7478 case OFFSET_TYPE:
7479 case LANG_TYPE:
7480 case VECTOR_TYPE:
7481 return 0;
7483 default:
7484 abort ();
7487 return 0;
7490 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7491 entry that chains various modifiers in front of the given type. */
7493 static dw_die_ref
7494 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7495 tree type;
7496 int is_const_type;
7497 int is_volatile_type;
7498 dw_die_ref context_die;
7500 enum tree_code code = TREE_CODE (type);
7501 dw_die_ref mod_type_die = NULL;
7502 dw_die_ref sub_die = NULL;
7503 tree item_type = NULL;
7505 if (code != ERROR_MARK)
7507 tree qualified_type;
7509 /* See if we already have the appropriately qualified variant of
7510 this type. */
7511 qualified_type
7512 = get_qualified_type (type,
7513 ((is_const_type ? TYPE_QUAL_CONST : 0)
7514 | (is_volatile_type
7515 ? TYPE_QUAL_VOLATILE : 0)));
7517 /* If we do, then we can just use its DIE, if it exists. */
7518 if (qualified_type)
7520 mod_type_die = lookup_type_die (qualified_type);
7521 if (mod_type_die)
7522 return mod_type_die;
7525 /* Handle C typedef types. */
7526 if (qualified_type && TYPE_NAME (qualified_type)
7527 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7528 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7530 tree type_name = TYPE_NAME (qualified_type);
7531 tree dtype = TREE_TYPE (type_name);
7533 if (qualified_type == dtype)
7535 /* For a named type, use the typedef. */
7536 gen_type_die (qualified_type, context_die);
7537 mod_type_die = lookup_type_die (qualified_type);
7539 else if (is_const_type < TYPE_READONLY (dtype)
7540 || is_volatile_type < TYPE_VOLATILE (dtype))
7541 /* cv-unqualified version of named type. Just use the unnamed
7542 type to which it refers. */
7543 mod_type_die
7544 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7545 is_const_type, is_volatile_type,
7546 context_die);
7548 /* Else cv-qualified version of named type; fall through. */
7551 if (mod_type_die)
7552 /* OK. */
7554 else if (is_const_type)
7556 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
7557 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7559 else if (is_volatile_type)
7561 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
7562 sub_die = modified_type_die (type, 0, 0, context_die);
7564 else if (code == POINTER_TYPE)
7566 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
7567 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7568 #if 0
7569 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7570 #endif
7571 item_type = TREE_TYPE (type);
7573 else if (code == REFERENCE_TYPE)
7575 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
7576 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7577 #if 0
7578 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7579 #endif
7580 item_type = TREE_TYPE (type);
7582 else if (is_base_type (type))
7583 mod_type_die = base_type_die (type);
7584 else
7586 gen_type_die (type, context_die);
7588 /* We have to get the type_main_variant here (and pass that to the
7589 `lookup_type_die' routine) because the ..._TYPE node we have
7590 might simply be a *copy* of some original type node (where the
7591 copy was created to help us keep track of typedef names) and
7592 that copy might have a different TYPE_UID from the original
7593 ..._TYPE node. */
7594 if (TREE_CODE (type) != VECTOR_TYPE)
7595 mod_type_die = lookup_type_die (type_main_variant (type));
7596 else
7597 /* Vectors have the debugging information in the type,
7598 not the main variant. */
7599 mod_type_die = lookup_type_die (type);
7600 if (mod_type_die == NULL)
7601 abort ();
7604 /* We want to equate the qualified type to the die below. */
7605 if (qualified_type)
7606 type = qualified_type;
7609 equate_type_number_to_die (type, mod_type_die);
7610 if (item_type)
7611 /* We must do this after the equate_type_number_to_die call, in case
7612 this is a recursive type. This ensures that the modified_type_die
7613 recursion will terminate even if the type is recursive. Recursive
7614 types are possible in Ada. */
7615 sub_die = modified_type_die (item_type,
7616 TYPE_READONLY (item_type),
7617 TYPE_VOLATILE (item_type),
7618 context_die);
7620 if (sub_die != NULL)
7621 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7623 return mod_type_die;
7626 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7627 an enumerated type. */
7629 static inline int
7630 type_is_enum (type)
7631 tree type;
7633 return TREE_CODE (type) == ENUMERAL_TYPE;
7636 /* Return the register number described by a given RTL node. */
7638 static unsigned int
7639 reg_number (rtl)
7640 rtx rtl;
7642 unsigned regno = REGNO (rtl);
7644 if (regno >= FIRST_PSEUDO_REGISTER)
7645 abort ();
7647 return DBX_REGISTER_NUMBER (regno);
7650 /* Return a location descriptor that designates a machine register or
7651 zero if there is no such. */
7653 static dw_loc_descr_ref
7654 reg_loc_descriptor (rtl)
7655 rtx rtl;
7657 dw_loc_descr_ref loc_result = NULL;
7658 unsigned reg;
7660 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7661 return 0;
7663 reg = reg_number (rtl);
7664 if (reg <= 31)
7665 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7666 else
7667 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7669 return loc_result;
7672 /* Return a location descriptor that designates a constant. */
7674 static dw_loc_descr_ref
7675 int_loc_descriptor (i)
7676 HOST_WIDE_INT i;
7678 enum dwarf_location_atom op;
7680 /* Pick the smallest representation of a constant, rather than just
7681 defaulting to the LEB encoding. */
7682 if (i >= 0)
7684 if (i <= 31)
7685 op = DW_OP_lit0 + i;
7686 else if (i <= 0xff)
7687 op = DW_OP_const1u;
7688 else if (i <= 0xffff)
7689 op = DW_OP_const2u;
7690 else if (HOST_BITS_PER_WIDE_INT == 32
7691 || i <= 0xffffffff)
7692 op = DW_OP_const4u;
7693 else
7694 op = DW_OP_constu;
7696 else
7698 if (i >= -0x80)
7699 op = DW_OP_const1s;
7700 else if (i >= -0x8000)
7701 op = DW_OP_const2s;
7702 else if (HOST_BITS_PER_WIDE_INT == 32
7703 || i >= -0x80000000)
7704 op = DW_OP_const4s;
7705 else
7706 op = DW_OP_consts;
7709 return new_loc_descr (op, i, 0);
7712 /* Return a location descriptor that designates a base+offset location. */
7714 static dw_loc_descr_ref
7715 based_loc_descr (reg, offset)
7716 unsigned reg;
7717 long int offset;
7719 dw_loc_descr_ref loc_result;
7720 /* For the "frame base", we use the frame pointer or stack pointer
7721 registers, since the RTL for local variables is relative to one of
7722 them. */
7723 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7724 ? HARD_FRAME_POINTER_REGNUM
7725 : STACK_POINTER_REGNUM);
7727 if (reg == fp_reg)
7728 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7729 else if (reg <= 31)
7730 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7731 else
7732 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7734 return loc_result;
7737 /* Return true if this RTL expression describes a base+offset calculation. */
7739 static inline int
7740 is_based_loc (rtl)
7741 rtx rtl;
7743 return (GET_CODE (rtl) == PLUS
7744 && ((GET_CODE (XEXP (rtl, 0)) == REG
7745 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
7746 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7749 /* The following routine converts the RTL for a variable or parameter
7750 (resident in memory) into an equivalent Dwarf representation of a
7751 mechanism for getting the address of that same variable onto the top of a
7752 hypothetical "address evaluation" stack.
7754 When creating memory location descriptors, we are effectively transforming
7755 the RTL for a memory-resident object into its Dwarf postfix expression
7756 equivalent. This routine recursively descends an RTL tree, turning
7757 it into Dwarf postfix code as it goes.
7759 MODE is the mode of the memory reference, needed to handle some
7760 autoincrement addressing modes.
7762 Return 0 if we can't represent the location. */
7764 static dw_loc_descr_ref
7765 mem_loc_descriptor (rtl, mode)
7766 rtx rtl;
7767 enum machine_mode mode;
7769 dw_loc_descr_ref mem_loc_result = NULL;
7771 /* Note that for a dynamically sized array, the location we will generate a
7772 description of here will be the lowest numbered location which is
7773 actually within the array. That's *not* necessarily the same as the
7774 zeroth element of the array. */
7776 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7777 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7778 #endif
7780 switch (GET_CODE (rtl))
7782 case POST_INC:
7783 case POST_DEC:
7784 case POST_MODIFY:
7785 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7786 just fall into the SUBREG code. */
7788 /* ... fall through ... */
7790 case SUBREG:
7791 /* The case of a subreg may arise when we have a local (register)
7792 variable or a formal (register) parameter which doesn't quite fill
7793 up an entire register. For now, just assume that it is
7794 legitimate to make the Dwarf info refer to the whole register which
7795 contains the given subreg. */
7796 rtl = SUBREG_REG (rtl);
7798 /* ... fall through ... */
7800 case REG:
7801 /* Whenever a register number forms a part of the description of the
7802 method for calculating the (dynamic) address of a memory resident
7803 object, DWARF rules require the register number be referred to as
7804 a "base register". This distinction is not based in any way upon
7805 what category of register the hardware believes the given register
7806 belongs to. This is strictly DWARF terminology we're dealing with
7807 here. Note that in cases where the location of a memory-resident
7808 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7809 OP_CONST (0)) the actual DWARF location descriptor that we generate
7810 may just be OP_BASEREG (basereg). This may look deceptively like
7811 the object in question was allocated to a register (rather than in
7812 memory) so DWARF consumers need to be aware of the subtle
7813 distinction between OP_REG and OP_BASEREG. */
7814 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
7815 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7816 break;
7818 case MEM:
7819 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7820 if (mem_loc_result != 0)
7821 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7822 break;
7824 case LABEL_REF:
7825 /* Some ports can transform a symbol ref into a label ref, because
7826 the symbol ref is too far away and has to be dumped into a constant
7827 pool. */
7828 case CONST:
7829 case SYMBOL_REF:
7830 /* Alternatively, the symbol in the constant pool might be referenced
7831 by a different symbol. */
7832 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
7834 bool marked;
7835 rtx tmp = get_pool_constant_mark (rtl, &marked);
7837 if (GET_CODE (tmp) == SYMBOL_REF)
7839 rtl = tmp;
7840 if (CONSTANT_POOL_ADDRESS_P (tmp))
7841 get_pool_constant_mark (tmp, &marked);
7842 else
7843 marked = true;
7846 /* If all references to this pool constant were optimized away,
7847 it was not output and thus we can't represent it.
7848 FIXME: might try to use DW_OP_const_value here, though
7849 DW_OP_piece complicates it. */
7850 if (!marked)
7851 return 0;
7854 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7855 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7856 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
7857 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
7858 break;
7860 case PRE_MODIFY:
7861 /* Extract the PLUS expression nested inside and fall into
7862 PLUS code below. */
7863 rtl = XEXP (rtl, 1);
7864 goto plus;
7866 case PRE_INC:
7867 case PRE_DEC:
7868 /* Turn these into a PLUS expression and fall into the PLUS code
7869 below. */
7870 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7871 GEN_INT (GET_CODE (rtl) == PRE_INC
7872 ? GET_MODE_UNIT_SIZE (mode)
7873 : -GET_MODE_UNIT_SIZE (mode)));
7875 /* ... fall through ... */
7877 case PLUS:
7878 plus:
7879 if (is_based_loc (rtl))
7880 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7881 INTVAL (XEXP (rtl, 1)));
7882 else
7884 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7885 if (mem_loc_result == 0)
7886 break;
7888 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7889 && INTVAL (XEXP (rtl, 1)) >= 0)
7890 add_loc_descr (&mem_loc_result,
7891 new_loc_descr (DW_OP_plus_uconst,
7892 INTVAL (XEXP (rtl, 1)), 0));
7893 else
7895 add_loc_descr (&mem_loc_result,
7896 mem_loc_descriptor (XEXP (rtl, 1), mode));
7897 add_loc_descr (&mem_loc_result,
7898 new_loc_descr (DW_OP_plus, 0, 0));
7901 break;
7903 case MULT:
7905 /* If a pseudo-reg is optimized away, it is possible for it to
7906 be replaced with a MEM containing a multiply. */
7907 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
7908 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
7910 if (op0 == 0 || op1 == 0)
7911 break;
7913 mem_loc_result = op0;
7914 add_loc_descr (&mem_loc_result, op1);
7915 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7916 break;
7919 case CONST_INT:
7920 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7921 break;
7923 case ADDRESSOF:
7924 /* If this is a MEM, return its address. Otherwise, we can't
7925 represent this. */
7926 if (GET_CODE (XEXP (rtl, 0)) == MEM)
7927 return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode);
7928 else
7929 return 0;
7931 default:
7932 abort ();
7935 return mem_loc_result;
7938 /* Return a descriptor that describes the concatenation of two locations.
7939 This is typically a complex variable. */
7941 static dw_loc_descr_ref
7942 concat_loc_descriptor (x0, x1)
7943 rtx x0, x1;
7945 dw_loc_descr_ref cc_loc_result = NULL;
7946 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
7947 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
7949 if (x0_ref == 0 || x1_ref == 0)
7950 return 0;
7952 cc_loc_result = x0_ref;
7953 add_loc_descr (&cc_loc_result,
7954 new_loc_descr (DW_OP_piece,
7955 GET_MODE_SIZE (GET_MODE (x0)), 0));
7957 add_loc_descr (&cc_loc_result, x1_ref);
7958 add_loc_descr (&cc_loc_result,
7959 new_loc_descr (DW_OP_piece,
7960 GET_MODE_SIZE (GET_MODE (x1)), 0));
7962 return cc_loc_result;
7965 /* Output a proper Dwarf location descriptor for a variable or parameter
7966 which is either allocated in a register or in a memory location. For a
7967 register, we just generate an OP_REG and the register number. For a
7968 memory location we provide a Dwarf postfix expression describing how to
7969 generate the (dynamic) address of the object onto the address stack.
7971 If we don't know how to describe it, return 0. */
7973 static dw_loc_descr_ref
7974 loc_descriptor (rtl)
7975 rtx rtl;
7977 dw_loc_descr_ref loc_result = NULL;
7979 switch (GET_CODE (rtl))
7981 case SUBREG:
7982 /* The case of a subreg may arise when we have a local (register)
7983 variable or a formal (register) parameter which doesn't quite fill
7984 up an entire register. For now, just assume that it is
7985 legitimate to make the Dwarf info refer to the whole register which
7986 contains the given subreg. */
7987 rtl = SUBREG_REG (rtl);
7989 /* ... fall through ... */
7991 case REG:
7992 loc_result = reg_loc_descriptor (rtl);
7993 break;
7995 case MEM:
7996 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7997 break;
7999 case CONCAT:
8000 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8001 break;
8003 default:
8004 abort ();
8007 return loc_result;
8010 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8011 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8012 looking for an address. Otherwise, we return a value. If we can't make a
8013 descriptor, return 0. */
8015 static dw_loc_descr_ref
8016 loc_descriptor_from_tree (loc, addressp)
8017 tree loc;
8018 int addressp;
8020 dw_loc_descr_ref ret, ret1;
8021 int indirect_p = 0;
8022 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
8023 enum dwarf_location_atom op;
8025 /* ??? Most of the time we do not take proper care for sign/zero
8026 extending the values properly. Hopefully this won't be a real
8027 problem... */
8029 switch (TREE_CODE (loc))
8031 case ERROR_MARK:
8032 return 0;
8034 case WITH_RECORD_EXPR:
8035 case PLACEHOLDER_EXPR:
8036 /* This case involves extracting fields from an object to determine the
8037 position of other fields. We don't try to encode this here. The
8038 only user of this is Ada, which encodes the needed information using
8039 the names of types. */
8040 return 0;
8042 case CALL_EXPR:
8043 return 0;
8045 case ADDR_EXPR:
8046 /* We can support this only if we can look through conversions and
8047 find an INDIRECT_EXPR. */
8048 for (loc = TREE_OPERAND (loc, 0);
8049 TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR
8050 || TREE_CODE (loc) == NON_LVALUE_EXPR
8051 || TREE_CODE (loc) == VIEW_CONVERT_EXPR
8052 || TREE_CODE (loc) == SAVE_EXPR;
8053 loc = TREE_OPERAND (loc, 0))
8056 return (TREE_CODE (loc) == INDIRECT_REF
8057 ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp)
8058 : 0);
8060 case VAR_DECL:
8061 case PARM_DECL:
8063 rtx rtl = rtl_for_decl_location (loc);
8065 if (rtl == NULL_RTX)
8066 return 0;
8067 else if (CONSTANT_P (rtl))
8069 ret = new_loc_descr (DW_OP_addr, 0, 0);
8070 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8071 ret->dw_loc_oprnd1.v.val_addr = rtl;
8072 indirect_p = 1;
8074 else
8076 enum machine_mode mode = GET_MODE (rtl);
8078 if (GET_CODE (rtl) == MEM)
8080 indirect_p = 1;
8081 rtl = XEXP (rtl, 0);
8084 ret = mem_loc_descriptor (rtl, mode);
8087 break;
8089 case INDIRECT_REF:
8090 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8091 indirect_p = 1;
8092 break;
8094 case COMPOUND_EXPR:
8095 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
8097 case NOP_EXPR:
8098 case CONVERT_EXPR:
8099 case NON_LVALUE_EXPR:
8100 case VIEW_CONVERT_EXPR:
8101 case SAVE_EXPR:
8102 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8104 case COMPONENT_REF:
8105 case BIT_FIELD_REF:
8106 case ARRAY_REF:
8107 case ARRAY_RANGE_REF:
8109 tree obj, offset;
8110 HOST_WIDE_INT bitsize, bitpos, bytepos;
8111 enum machine_mode mode;
8112 int volatilep;
8114 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8115 &unsignedp, &volatilep);
8117 if (obj == loc)
8118 return 0;
8120 ret = loc_descriptor_from_tree (obj, 1);
8121 if (ret == 0
8122 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
8123 return 0;
8125 if (offset != NULL_TREE)
8127 /* Variable offset. */
8128 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8129 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8132 if (!addressp)
8133 indirect_p = 1;
8135 bytepos = bitpos / BITS_PER_UNIT;
8136 if (bytepos > 0)
8137 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8138 else if (bytepos < 0)
8140 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8141 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8143 break;
8146 case INTEGER_CST:
8147 if (host_integerp (loc, 0))
8148 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8149 else
8150 return 0;
8151 break;
8153 case TRUTH_AND_EXPR:
8154 case TRUTH_ANDIF_EXPR:
8155 case BIT_AND_EXPR:
8156 op = DW_OP_and;
8157 goto do_binop;
8159 case TRUTH_XOR_EXPR:
8160 case BIT_XOR_EXPR:
8161 op = DW_OP_xor;
8162 goto do_binop;
8164 case TRUTH_OR_EXPR:
8165 case TRUTH_ORIF_EXPR:
8166 case BIT_IOR_EXPR:
8167 op = DW_OP_or;
8168 goto do_binop;
8170 case TRUNC_DIV_EXPR:
8171 op = DW_OP_div;
8172 goto do_binop;
8174 case MINUS_EXPR:
8175 op = DW_OP_minus;
8176 goto do_binop;
8178 case TRUNC_MOD_EXPR:
8179 op = DW_OP_mod;
8180 goto do_binop;
8182 case MULT_EXPR:
8183 op = DW_OP_mul;
8184 goto do_binop;
8186 case LSHIFT_EXPR:
8187 op = DW_OP_shl;
8188 goto do_binop;
8190 case RSHIFT_EXPR:
8191 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8192 goto do_binop;
8194 case PLUS_EXPR:
8195 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8196 && host_integerp (TREE_OPERAND (loc, 1), 0))
8198 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8199 if (ret == 0)
8200 return 0;
8202 add_loc_descr (&ret,
8203 new_loc_descr (DW_OP_plus_uconst,
8204 tree_low_cst (TREE_OPERAND (loc, 1),
8206 0));
8207 break;
8210 op = DW_OP_plus;
8211 goto do_binop;
8213 case LE_EXPR:
8214 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8215 return 0;
8217 op = DW_OP_le;
8218 goto do_binop;
8220 case GE_EXPR:
8221 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8222 return 0;
8224 op = DW_OP_ge;
8225 goto do_binop;
8227 case LT_EXPR:
8228 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8229 return 0;
8231 op = DW_OP_lt;
8232 goto do_binop;
8234 case GT_EXPR:
8235 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8236 return 0;
8238 op = DW_OP_gt;
8239 goto do_binop;
8241 case EQ_EXPR:
8242 op = DW_OP_eq;
8243 goto do_binop;
8245 case NE_EXPR:
8246 op = DW_OP_ne;
8247 goto do_binop;
8249 do_binop:
8250 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8251 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8252 if (ret == 0 || ret1 == 0)
8253 return 0;
8255 add_loc_descr (&ret, ret1);
8256 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8257 break;
8259 case TRUTH_NOT_EXPR:
8260 case BIT_NOT_EXPR:
8261 op = DW_OP_not;
8262 goto do_unop;
8264 case ABS_EXPR:
8265 op = DW_OP_abs;
8266 goto do_unop;
8268 case NEGATE_EXPR:
8269 op = DW_OP_neg;
8270 goto do_unop;
8272 do_unop:
8273 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8274 if (ret == 0)
8275 return 0;
8277 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8278 break;
8280 case MAX_EXPR:
8281 loc = build (COND_EXPR, TREE_TYPE (loc),
8282 build (LT_EXPR, integer_type_node,
8283 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8284 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8286 /* ... fall through ... */
8288 case COND_EXPR:
8290 dw_loc_descr_ref lhs
8291 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8292 dw_loc_descr_ref rhs
8293 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8294 dw_loc_descr_ref bra_node, jump_node, tmp;
8296 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8297 if (ret == 0 || lhs == 0 || rhs == 0)
8298 return 0;
8300 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8301 add_loc_descr (&ret, bra_node);
8303 add_loc_descr (&ret, rhs);
8304 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8305 add_loc_descr (&ret, jump_node);
8307 add_loc_descr (&ret, lhs);
8308 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8309 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
8311 /* ??? Need a node to point the skip at. Use a nop. */
8312 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8313 add_loc_descr (&ret, tmp);
8314 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8315 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8317 break;
8319 default:
8320 abort ();
8323 /* Show if we can't fill the request for an address. */
8324 if (addressp && indirect_p == 0)
8325 return 0;
8327 /* If we've got an address and don't want one, dereference. */
8328 if (!addressp && indirect_p > 0)
8330 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8332 if (size > DWARF2_ADDR_SIZE || size == -1)
8333 return 0;
8334 else if (size == DWARF2_ADDR_SIZE)
8335 op = DW_OP_deref;
8336 else
8337 op = DW_OP_deref_size;
8339 add_loc_descr (&ret, new_loc_descr (op, size, 0));
8342 return ret;
8345 /* Given a value, round it up to the lowest multiple of `boundary'
8346 which is not less than the value itself. */
8348 static inline HOST_WIDE_INT
8349 ceiling (value, boundary)
8350 HOST_WIDE_INT value;
8351 unsigned int boundary;
8353 return (((value + boundary - 1) / boundary) * boundary);
8356 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8357 pointer to the declared type for the relevant field variable, or return
8358 `integer_type_node' if the given node turns out to be an
8359 ERROR_MARK node. */
8361 static inline tree
8362 field_type (decl)
8363 tree decl;
8365 tree type;
8367 if (TREE_CODE (decl) == ERROR_MARK)
8368 return integer_type_node;
8370 type = DECL_BIT_FIELD_TYPE (decl);
8371 if (type == NULL_TREE)
8372 type = TREE_TYPE (decl);
8374 return type;
8377 /* Given a pointer to a tree node, return the alignment in bits for
8378 it, or else return BITS_PER_WORD if the node actually turns out to
8379 be an ERROR_MARK node. */
8381 static inline unsigned
8382 simple_type_align_in_bits (type)
8383 tree type;
8385 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8388 static inline unsigned
8389 simple_decl_align_in_bits (decl)
8390 tree decl;
8392 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8395 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8396 node, return the size in bits for the type if it is a constant, or else
8397 return the alignment for the type if the type's size is not constant, or
8398 else return BITS_PER_WORD if the type actually turns out to be an
8399 ERROR_MARK node. */
8401 static inline unsigned HOST_WIDE_INT
8402 simple_type_size_in_bits (type)
8403 tree type;
8406 if (TREE_CODE (type) == ERROR_MARK)
8407 return BITS_PER_WORD;
8408 else if (TYPE_SIZE (type) == NULL_TREE)
8409 return 0;
8410 else if (host_integerp (TYPE_SIZE (type), 1))
8411 return tree_low_cst (TYPE_SIZE (type), 1);
8412 else
8413 return TYPE_ALIGN (type);
8416 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8417 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8418 or return 0 if we are unable to determine what that offset is, either
8419 because the argument turns out to be a pointer to an ERROR_MARK node, or
8420 because the offset is actually variable. (We can't handle the latter case
8421 just yet). */
8423 static HOST_WIDE_INT
8424 field_byte_offset (decl)
8425 tree decl;
8427 unsigned int type_align_in_bits;
8428 unsigned int decl_align_in_bits;
8429 unsigned HOST_WIDE_INT type_size_in_bits;
8430 HOST_WIDE_INT object_offset_in_bits;
8431 tree type;
8432 tree field_size_tree;
8433 HOST_WIDE_INT bitpos_int;
8434 HOST_WIDE_INT deepest_bitpos;
8435 unsigned HOST_WIDE_INT field_size_in_bits;
8437 if (TREE_CODE (decl) == ERROR_MARK)
8438 return 0;
8439 else if (TREE_CODE (decl) != FIELD_DECL)
8440 abort ();
8442 type = field_type (decl);
8443 field_size_tree = DECL_SIZE (decl);
8445 /* The size could be unspecified if there was an error, or for
8446 a flexible array member. */
8447 if (! field_size_tree)
8448 field_size_tree = bitsize_zero_node;
8450 /* We cannot yet cope with fields whose positions are variable, so
8451 for now, when we see such things, we simply return 0. Someday, we may
8452 be able to handle such cases, but it will be damn difficult. */
8453 if (! host_integerp (bit_position (decl), 0))
8454 return 0;
8456 bitpos_int = int_bit_position (decl);
8458 /* If we don't know the size of the field, pretend it's a full word. */
8459 if (host_integerp (field_size_tree, 1))
8460 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8461 else
8462 field_size_in_bits = BITS_PER_WORD;
8464 type_size_in_bits = simple_type_size_in_bits (type);
8465 type_align_in_bits = simple_type_align_in_bits (type);
8466 decl_align_in_bits = simple_decl_align_in_bits (decl);
8468 /* The GCC front-end doesn't make any attempt to keep track of the starting
8469 bit offset (relative to the start of the containing structure type) of the
8470 hypothetical "containing object" for a bit-field. Thus, when computing
8471 the byte offset value for the start of the "containing object" of a
8472 bit-field, we must deduce this information on our own. This can be rather
8473 tricky to do in some cases. For example, handling the following structure
8474 type definition when compiling for an i386/i486 target (which only aligns
8475 long long's to 32-bit boundaries) can be very tricky:
8477 struct S { int field1; long long field2:31; };
8479 Fortunately, there is a simple rule-of-thumb which can be used in such
8480 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8481 structure shown above. It decides to do this based upon one simple rule
8482 for bit-field allocation. GCC allocates each "containing object" for each
8483 bit-field at the first (i.e. lowest addressed) legitimate alignment
8484 boundary (based upon the required minimum alignment for the declared type
8485 of the field) which it can possibly use, subject to the condition that
8486 there is still enough available space remaining in the containing object
8487 (when allocated at the selected point) to fully accommodate all of the
8488 bits of the bit-field itself.
8490 This simple rule makes it obvious why GCC allocates 8 bytes for each
8491 object of the structure type shown above. When looking for a place to
8492 allocate the "containing object" for `field2', the compiler simply tries
8493 to allocate a 64-bit "containing object" at each successive 32-bit
8494 boundary (starting at zero) until it finds a place to allocate that 64-
8495 bit field such that at least 31 contiguous (and previously unallocated)
8496 bits remain within that selected 64 bit field. (As it turns out, for the
8497 example above, the compiler finds it is OK to allocate the "containing
8498 object" 64-bit field at bit-offset zero within the structure type.)
8500 Here we attempt to work backwards from the limited set of facts we're
8501 given, and we try to deduce from those facts, where GCC must have believed
8502 that the containing object started (within the structure type). The value
8503 we deduce is then used (by the callers of this routine) to generate
8504 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8505 and, in the case of DW_AT_location, regular fields as well). */
8507 /* Figure out the bit-distance from the start of the structure to the
8508 "deepest" bit of the bit-field. */
8509 deepest_bitpos = bitpos_int + field_size_in_bits;
8511 /* This is the tricky part. Use some fancy footwork to deduce where the
8512 lowest addressed bit of the containing object must be. */
8513 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8515 /* Round up to type_align by default. This works best for bitfields. */
8516 object_offset_in_bits += type_align_in_bits - 1;
8517 object_offset_in_bits /= type_align_in_bits;
8518 object_offset_in_bits *= type_align_in_bits;
8520 if (object_offset_in_bits > bitpos_int)
8522 /* Sigh, the decl must be packed. */
8523 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8525 /* Round up to decl_align instead. */
8526 object_offset_in_bits += decl_align_in_bits - 1;
8527 object_offset_in_bits /= decl_align_in_bits;
8528 object_offset_in_bits *= decl_align_in_bits;
8531 return object_offset_in_bits / BITS_PER_UNIT;
8534 /* The following routines define various Dwarf attributes and any data
8535 associated with them. */
8537 /* Add a location description attribute value to a DIE.
8539 This emits location attributes suitable for whole variables and
8540 whole parameters. Note that the location attributes for struct fields are
8541 generated by the routine `data_member_location_attribute' below. */
8543 static void
8544 add_AT_location_description (die, attr_kind, rtl)
8545 dw_die_ref die;
8546 enum dwarf_attribute attr_kind;
8547 rtx rtl;
8549 dw_loc_descr_ref descr = loc_descriptor (rtl);
8551 if (descr != 0)
8552 add_AT_loc (die, attr_kind, descr);
8555 /* Attach the specialized form of location attribute used for data members of
8556 struct and union types. In the special case of a FIELD_DECL node which
8557 represents a bit-field, the "offset" part of this special location
8558 descriptor must indicate the distance in bytes from the lowest-addressed
8559 byte of the containing struct or union type to the lowest-addressed byte of
8560 the "containing object" for the bit-field. (See the `field_byte_offset'
8561 function above).
8563 For any given bit-field, the "containing object" is a hypothetical object
8564 (of some integral or enum type) within which the given bit-field lives. The
8565 type of this hypothetical "containing object" is always the same as the
8566 declared type of the individual bit-field itself (for GCC anyway... the
8567 DWARF spec doesn't actually mandate this). Note that it is the size (in
8568 bytes) of the hypothetical "containing object" which will be given in the
8569 DW_AT_byte_size attribute for this bit-field. (See the
8570 `byte_size_attribute' function below.) It is also used when calculating the
8571 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8572 function below.) */
8574 static void
8575 add_data_member_location_attribute (die, decl)
8576 dw_die_ref die;
8577 tree decl;
8579 long offset;
8580 dw_loc_descr_ref loc_descr = 0;
8582 if (TREE_CODE (decl) == TREE_VEC)
8584 /* We're working on the TAG_inheritance for a base class. */
8585 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
8587 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8588 aren't at a fixed offset from all (sub)objects of the same
8589 type. We need to extract the appropriate offset from our
8590 vtable. The following dwarf expression means
8592 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8594 This is specific to the V3 ABI, of course. */
8596 dw_loc_descr_ref tmp;
8598 /* Make a copy of the object address. */
8599 tmp = new_loc_descr (DW_OP_dup, 0, 0);
8600 add_loc_descr (&loc_descr, tmp);
8602 /* Extract the vtable address. */
8603 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8604 add_loc_descr (&loc_descr, tmp);
8606 /* Calculate the address of the offset. */
8607 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
8608 if (offset >= 0)
8609 abort ();
8611 tmp = int_loc_descriptor (-offset);
8612 add_loc_descr (&loc_descr, tmp);
8613 tmp = new_loc_descr (DW_OP_minus, 0, 0);
8614 add_loc_descr (&loc_descr, tmp);
8616 /* Extract the offset. */
8617 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8618 add_loc_descr (&loc_descr, tmp);
8620 /* Add it to the object address. */
8621 tmp = new_loc_descr (DW_OP_plus, 0, 0);
8622 add_loc_descr (&loc_descr, tmp);
8624 else
8625 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8627 else
8628 offset = field_byte_offset (decl);
8630 if (! loc_descr)
8632 enum dwarf_location_atom op;
8634 /* The DWARF2 standard says that we should assume that the structure
8635 address is already on the stack, so we can specify a structure field
8636 address by using DW_OP_plus_uconst. */
8638 #ifdef MIPS_DEBUGGING_INFO
8639 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8640 operator correctly. It works only if we leave the offset on the
8641 stack. */
8642 op = DW_OP_constu;
8643 #else
8644 op = DW_OP_plus_uconst;
8645 #endif
8647 loc_descr = new_loc_descr (op, offset, 0);
8650 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8653 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8654 does not have a "location" either in memory or in a register. These
8655 things can arise in GNU C when a constant is passed as an actual parameter
8656 to an inlined function. They can also arise in C++ where declared
8657 constants do not necessarily get memory "homes". */
8659 static void
8660 add_const_value_attribute (die, rtl)
8661 dw_die_ref die;
8662 rtx rtl;
8664 switch (GET_CODE (rtl))
8666 case CONST_INT:
8667 /* Note that a CONST_INT rtx could represent either an integer
8668 or a floating-point constant. A CONST_INT is used whenever
8669 the constant will fit into a single word. In all such
8670 cases, the original mode of the constant value is wiped
8671 out, and the CONST_INT rtx is assigned VOIDmode. */
8673 HOST_WIDE_INT val = INTVAL (rtl);
8675 /* ??? We really should be using HOST_WIDE_INT throughout. */
8676 if (val < 0 && (long) val == val)
8677 add_AT_int (die, DW_AT_const_value, (long) val);
8678 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
8679 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8680 else
8682 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8683 add_AT_long_long (die, DW_AT_const_value,
8684 val >> HOST_BITS_PER_LONG, val);
8685 #else
8686 abort ();
8687 #endif
8690 break;
8692 case CONST_DOUBLE:
8693 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8694 floating-point constant. A CONST_DOUBLE is used whenever the
8695 constant requires more than one word in order to be adequately
8696 represented. We output CONST_DOUBLEs as blocks. */
8698 enum machine_mode mode = GET_MODE (rtl);
8700 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8702 unsigned length = GET_MODE_SIZE (mode) / 4;
8703 long *array = (long *) xmalloc (sizeof (long) * length);
8704 REAL_VALUE_TYPE rv;
8706 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8707 switch (mode)
8709 case SFmode:
8710 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8711 break;
8713 case DFmode:
8714 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8715 break;
8717 case XFmode:
8718 case TFmode:
8719 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8720 break;
8722 default:
8723 abort ();
8726 add_AT_float (die, DW_AT_const_value, length, array);
8728 else
8730 /* ??? We really should be using HOST_WIDE_INT throughout. */
8731 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8732 abort ();
8734 add_AT_long_long (die, DW_AT_const_value,
8735 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8738 break;
8740 case CONST_STRING:
8741 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8742 break;
8744 case SYMBOL_REF:
8745 case LABEL_REF:
8746 case CONST:
8747 add_AT_addr (die, DW_AT_const_value, rtl);
8748 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
8749 break;
8751 case PLUS:
8752 /* In cases where an inlined instance of an inline function is passed
8753 the address of an `auto' variable (which is local to the caller) we
8754 can get a situation where the DECL_RTL of the artificial local
8755 variable (for the inlining) which acts as a stand-in for the
8756 corresponding formal parameter (of the inline function) will look
8757 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8758 exactly a compile-time constant expression, but it isn't the address
8759 of the (artificial) local variable either. Rather, it represents the
8760 *value* which the artificial local variable always has during its
8761 lifetime. We currently have no way to represent such quasi-constant
8762 values in Dwarf, so for now we just punt and generate nothing. */
8763 break;
8765 default:
8766 /* No other kinds of rtx should be possible here. */
8767 abort ();
8772 static rtx
8773 rtl_for_decl_location (decl)
8774 tree decl;
8776 rtx rtl;
8778 /* Here we have to decide where we are going to say the parameter "lives"
8779 (as far as the debugger is concerned). We only have a couple of
8780 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8782 DECL_RTL normally indicates where the parameter lives during most of the
8783 activation of the function. If optimization is enabled however, this
8784 could be either NULL or else a pseudo-reg. Both of those cases indicate
8785 that the parameter doesn't really live anywhere (as far as the code
8786 generation parts of GCC are concerned) during most of the function's
8787 activation. That will happen (for example) if the parameter is never
8788 referenced within the function.
8790 We could just generate a location descriptor here for all non-NULL
8791 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8792 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8793 where DECL_RTL is NULL or is a pseudo-reg.
8795 Note however that we can only get away with using DECL_INCOMING_RTL as
8796 a backup substitute for DECL_RTL in certain limited cases. In cases
8797 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8798 we can be sure that the parameter was passed using the same type as it is
8799 declared to have within the function, and that its DECL_INCOMING_RTL
8800 points us to a place where a value of that type is passed.
8802 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8803 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8804 because in these cases DECL_INCOMING_RTL points us to a value of some
8805 type which is *different* from the type of the parameter itself. Thus,
8806 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8807 such cases, the debugger would end up (for example) trying to fetch a
8808 `float' from a place which actually contains the first part of a
8809 `double'. That would lead to really incorrect and confusing
8810 output at debug-time.
8812 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8813 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8814 are a couple of exceptions however. On little-endian machines we can
8815 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8816 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8817 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8818 when (on a little-endian machine) a non-prototyped function has a
8819 parameter declared to be of type `short' or `char'. In such cases,
8820 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8821 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8822 passed `int' value. If the debugger then uses that address to fetch
8823 a `short' or a `char' (on a little-endian machine) the result will be
8824 the correct data, so we allow for such exceptional cases below.
8826 Note that our goal here is to describe the place where the given formal
8827 parameter lives during most of the function's activation (i.e. between the
8828 end of the prologue and the start of the epilogue). We'll do that as best
8829 as we can. Note however that if the given formal parameter is modified
8830 sometime during the execution of the function, then a stack backtrace (at
8831 debug-time) will show the function as having been called with the *new*
8832 value rather than the value which was originally passed in. This happens
8833 rarely enough that it is not a major problem, but it *is* a problem, and
8834 I'd like to fix it.
8836 A future version of dwarf2out.c may generate two additional attributes for
8837 any given DW_TAG_formal_parameter DIE which will describe the "passed
8838 type" and the "passed location" for the given formal parameter in addition
8839 to the attributes we now generate to indicate the "declared type" and the
8840 "active location" for each parameter. This additional set of attributes
8841 could be used by debuggers for stack backtraces. Separately, note that
8842 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8843 This happens (for example) for inlined-instances of inline function formal
8844 parameters which are never referenced. This really shouldn't be
8845 happening. All PARM_DECL nodes should get valid non-NULL
8846 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8847 values for inlined instances of inline function parameters, so when we see
8848 such cases, we are just out-of-luck for the time being (until integrate.c
8849 gets fixed). */
8851 /* Use DECL_RTL as the "location" unless we find something better. */
8852 rtl = DECL_RTL_IF_SET (decl);
8854 /* When generating abstract instances, ignore everything except
8855 constants and symbols living in memory. */
8856 if (! reload_completed)
8858 if (rtl
8859 && (CONSTANT_P (rtl)
8860 || (GET_CODE (rtl) == MEM
8861 && CONSTANT_P (XEXP (rtl, 0)))))
8863 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8864 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
8865 #endif
8866 return rtl;
8868 rtl = NULL_RTX;
8870 else if (TREE_CODE (decl) == PARM_DECL)
8872 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8874 tree declared_type = type_main_variant (TREE_TYPE (decl));
8875 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8877 /* This decl represents a formal parameter which was optimized out.
8878 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8879 all cases where (rtl == NULL_RTX) just below. */
8880 if (declared_type == passed_type)
8881 rtl = DECL_INCOMING_RTL (decl);
8882 else if (! BYTES_BIG_ENDIAN
8883 && TREE_CODE (declared_type) == INTEGER_TYPE
8884 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8885 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8886 rtl = DECL_INCOMING_RTL (decl);
8889 /* If the parm was passed in registers, but lives on the stack, then
8890 make a big endian correction if the mode of the type of the
8891 parameter is not the same as the mode of the rtl. */
8892 /* ??? This is the same series of checks that are made in dbxout.c before
8893 we reach the big endian correction code there. It isn't clear if all
8894 of these checks are necessary here, but keeping them all is the safe
8895 thing to do. */
8896 else if (GET_CODE (rtl) == MEM
8897 && XEXP (rtl, 0) != const0_rtx
8898 && ! CONSTANT_P (XEXP (rtl, 0))
8899 /* Not passed in memory. */
8900 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8901 /* Not passed by invisible reference. */
8902 && (GET_CODE (XEXP (rtl, 0)) != REG
8903 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8904 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8905 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8906 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8907 #endif
8909 /* Big endian correction check. */
8910 && BYTES_BIG_ENDIAN
8911 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8912 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8913 < UNITS_PER_WORD))
8915 int offset = (UNITS_PER_WORD
8916 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8918 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8919 plus_constant (XEXP (rtl, 0), offset));
8923 if (rtl != NULL_RTX)
8925 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8926 #ifdef LEAF_REG_REMAP
8927 if (current_function_uses_only_leaf_regs)
8928 leaf_renumber_regs_insn (rtl);
8929 #endif
8932 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8933 and will have been substituted directly into all expressions that use it.
8934 C does not have such a concept, but C++ and other languages do. */
8935 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
8937 /* If a variable is initialized with a string constant without embedded
8938 zeros, build CONST_STRING. */
8939 if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8940 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
8942 tree arrtype = TREE_TYPE (decl);
8943 tree enttype = TREE_TYPE (arrtype);
8944 tree domain = TYPE_DOMAIN (arrtype);
8945 tree init = DECL_INITIAL (decl);
8946 enum machine_mode mode = TYPE_MODE (enttype);
8948 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
8949 && domain
8950 && integer_zerop (TYPE_MIN_VALUE (domain))
8951 && compare_tree_int (TYPE_MAX_VALUE (domain),
8952 TREE_STRING_LENGTH (init) - 1) == 0
8953 && ((size_t) TREE_STRING_LENGTH (init)
8954 == strlen (TREE_STRING_POINTER (init)) + 1))
8955 rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init));
8957 /* If the initializer is something that we know will expand into an
8958 immediate RTL constant, expand it now. Expanding anything else
8959 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
8960 else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST
8961 || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST)
8963 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
8964 EXPAND_INITIALIZER);
8965 /* If expand_expr returns a MEM, it wasn't immediate. */
8966 if (rtl && GET_CODE (rtl) == MEM)
8967 abort ();
8971 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8972 if (rtl)
8973 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
8974 #endif
8975 return rtl;
8978 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8979 data attribute for a variable or a parameter. We generate the
8980 DW_AT_const_value attribute only in those cases where the given variable
8981 or parameter does not have a true "location" either in memory or in a
8982 register. This can happen (for example) when a constant is passed as an
8983 actual argument in a call to an inline function. (It's possible that
8984 these things can crop up in other ways also.) Note that one type of
8985 constant value which can be passed into an inlined function is a constant
8986 pointer. This can happen for example if an actual argument in an inlined
8987 function call evaluates to a compile-time constant address. */
8989 static void
8990 add_location_or_const_value_attribute (die, decl)
8991 dw_die_ref die;
8992 tree decl;
8994 rtx rtl;
8996 if (TREE_CODE (decl) == ERROR_MARK)
8997 return;
8998 else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8999 abort ();
9001 rtl = rtl_for_decl_location (decl);
9002 if (rtl == NULL_RTX)
9003 return;
9005 /* If we don't look past the constant pool, we risk emitting a
9006 reference to a constant pool entry that isn't referenced from
9007 code, and thus is not emitted. */
9008 rtl = avoid_constant_pool_reference (rtl);
9010 switch (GET_CODE (rtl))
9012 case ADDRESSOF:
9013 /* The address of a variable that was optimized away; don't emit
9014 anything. */
9015 break;
9017 case CONST_INT:
9018 case CONST_DOUBLE:
9019 case CONST_STRING:
9020 case SYMBOL_REF:
9021 case LABEL_REF:
9022 case CONST:
9023 case PLUS:
9024 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9025 add_const_value_attribute (die, rtl);
9026 break;
9028 case MEM:
9029 case REG:
9030 case SUBREG:
9031 case CONCAT:
9032 add_AT_location_description (die, DW_AT_location, rtl);
9033 break;
9035 default:
9036 abort ();
9040 /* If we don't have a copy of this variable in memory for some reason (such
9041 as a C++ member constant that doesn't have an out-of-line definition),
9042 we should tell the debugger about the constant value. */
9044 static void
9045 tree_add_const_value_attribute (var_die, decl)
9046 dw_die_ref var_die;
9047 tree decl;
9049 tree init = DECL_INITIAL (decl);
9050 tree type = TREE_TYPE (decl);
9052 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
9053 && initializer_constant_valid_p (init, type) == null_pointer_node)
9054 /* OK */;
9055 else
9056 return;
9058 switch (TREE_CODE (type))
9060 case INTEGER_TYPE:
9061 if (host_integerp (init, 0))
9062 add_AT_unsigned (var_die, DW_AT_const_value,
9063 tree_low_cst (init, 0));
9064 else
9065 add_AT_long_long (var_die, DW_AT_const_value,
9066 TREE_INT_CST_HIGH (init),
9067 TREE_INT_CST_LOW (init));
9068 break;
9070 default:;
9074 /* Generate an DW_AT_name attribute given some string value to be included as
9075 the value of the attribute. */
9077 static inline void
9078 add_name_attribute (die, name_string)
9079 dw_die_ref die;
9080 const char *name_string;
9082 if (name_string != NULL && *name_string != 0)
9084 if (demangle_name_func)
9085 name_string = (*demangle_name_func) (name_string);
9087 add_AT_string (die, DW_AT_name, name_string);
9091 /* Given a tree node describing an array bound (either lower or upper) output
9092 a representation for that bound. */
9094 static void
9095 add_bound_info (subrange_die, bound_attr, bound)
9096 dw_die_ref subrange_die;
9097 enum dwarf_attribute bound_attr;
9098 tree bound;
9100 switch (TREE_CODE (bound))
9102 case ERROR_MARK:
9103 return;
9105 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9106 case INTEGER_CST:
9107 if (! host_integerp (bound, 0)
9108 || (bound_attr == DW_AT_lower_bound
9109 && (((is_c_family () || is_java ()) && integer_zerop (bound))
9110 || (is_fortran () && integer_onep (bound)))))
9111 /* use the default */
9113 else
9114 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
9115 break;
9117 case CONVERT_EXPR:
9118 case NOP_EXPR:
9119 case NON_LVALUE_EXPR:
9120 case VIEW_CONVERT_EXPR:
9121 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
9122 break;
9124 case SAVE_EXPR:
9125 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9126 access the upper bound values may be bogus. If they refer to a
9127 register, they may only describe how to get at these values at the
9128 points in the generated code right after they have just been
9129 computed. Worse yet, in the typical case, the upper bound values
9130 will not even *be* computed in the optimized code (though the
9131 number of elements will), so these SAVE_EXPRs are entirely
9132 bogus. In order to compensate for this fact, we check here to see
9133 if optimization is enabled, and if so, we don't add an attribute
9134 for the (unknown and unknowable) upper bound. This should not
9135 cause too much trouble for existing (stupid?) debuggers because
9136 they have to deal with empty upper bounds location descriptions
9137 anyway in order to be able to deal with incomplete array types.
9138 Of course an intelligent debugger (GDB?) should be able to
9139 comprehend that a missing upper bound specification in an array
9140 type used for a storage class `auto' local array variable
9141 indicates that the upper bound is both unknown (at compile- time)
9142 and unknowable (at run-time) due to optimization.
9144 We assume that a MEM rtx is safe because gcc wouldn't put the
9145 value there unless it was going to be used repeatedly in the
9146 function, i.e. for cleanups. */
9147 if (SAVE_EXPR_RTL (bound)
9148 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9150 dw_die_ref ctx = lookup_decl_die (current_function_decl);
9151 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound);
9152 rtx loc = SAVE_EXPR_RTL (bound);
9154 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9155 it references an outer function's frame. */
9156 if (GET_CODE (loc) == MEM)
9158 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9160 if (XEXP (loc, 0) != new_addr)
9161 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9164 add_AT_flag (decl_die, DW_AT_artificial, 1);
9165 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9166 add_AT_location_description (decl_die, DW_AT_location, loc);
9167 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9170 /* Else leave out the attribute. */
9171 break;
9173 case VAR_DECL:
9174 case PARM_DECL:
9176 dw_die_ref decl_die = lookup_decl_die (bound);
9178 /* ??? Can this happen, or should the variable have been bound
9179 first? Probably it can, since I imagine that we try to create
9180 the types of parameters in the order in which they exist in
9181 the list, and won't have created a forward reference to a
9182 later parameter. */
9183 if (decl_die != NULL)
9184 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9185 break;
9188 default:
9190 /* Otherwise try to create a stack operation procedure to
9191 evaluate the value of the array bound. */
9193 dw_die_ref ctx, decl_die;
9194 dw_loc_descr_ref loc;
9196 loc = loc_descriptor_from_tree (bound, 0);
9197 if (loc == NULL)
9198 break;
9200 if (current_function_decl == 0)
9201 ctx = comp_unit_die;
9202 else
9203 ctx = lookup_decl_die (current_function_decl);
9205 /* If we weren't able to find a context, it's most likely the case
9206 that we are processing the return type of the function. So
9207 make a SAVE_EXPR to point to it and have the limbo DIE code
9208 find the proper die. The save_expr function doesn't always
9209 make a SAVE_EXPR, so do it ourselves. */
9210 if (ctx == 0)
9211 bound = build (SAVE_EXPR, TREE_TYPE (bound), bound,
9212 current_function_decl, NULL_TREE);
9214 decl_die = new_die (DW_TAG_variable, ctx, bound);
9215 add_AT_flag (decl_die, DW_AT_artificial, 1);
9216 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9217 add_AT_loc (decl_die, DW_AT_location, loc);
9219 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9220 break;
9225 /* Note that the block of subscript information for an array type also
9226 includes information about the element type of type given array type. */
9228 static void
9229 add_subscript_info (type_die, type)
9230 dw_die_ref type_die;
9231 tree type;
9233 #ifndef MIPS_DEBUGGING_INFO
9234 unsigned dimension_number;
9235 #endif
9236 tree lower, upper;
9237 dw_die_ref subrange_die;
9239 /* The GNU compilers represent multidimensional array types as sequences of
9240 one dimensional array types whose element types are themselves array
9241 types. Here we squish that down, so that each multidimensional array
9242 type gets only one array_type DIE in the Dwarf debugging info. The draft
9243 Dwarf specification say that we are allowed to do this kind of
9244 compression in C (because there is no difference between an array or
9245 arrays and a multidimensional array in C) but for other source languages
9246 (e.g. Ada) we probably shouldn't do this. */
9248 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9249 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9250 We work around this by disabling this feature. See also
9251 gen_array_type_die. */
9252 #ifndef MIPS_DEBUGGING_INFO
9253 for (dimension_number = 0;
9254 TREE_CODE (type) == ARRAY_TYPE;
9255 type = TREE_TYPE (type), dimension_number++)
9256 #endif
9258 tree domain = TYPE_DOMAIN (type);
9260 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9261 and (in GNU C only) variable bounds. Handle all three forms
9262 here. */
9263 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
9264 if (domain)
9266 /* We have an array type with specified bounds. */
9267 lower = TYPE_MIN_VALUE (domain);
9268 upper = TYPE_MAX_VALUE (domain);
9270 /* define the index type. */
9271 if (TREE_TYPE (domain))
9273 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9274 TREE_TYPE field. We can't emit debug info for this
9275 because it is an unnamed integral type. */
9276 if (TREE_CODE (domain) == INTEGER_TYPE
9277 && TYPE_NAME (domain) == NULL_TREE
9278 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9279 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9281 else
9282 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9283 type_die);
9286 /* ??? If upper is NULL, the array has unspecified length,
9287 but it does have a lower bound. This happens with Fortran
9288 dimension arr(N:*)
9289 Since the debugger is definitely going to need to know N
9290 to produce useful results, go ahead and output the lower
9291 bound solo, and hope the debugger can cope. */
9293 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9294 if (upper)
9295 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9298 /* Otherwise we have an array type with an unspecified length. The
9299 DWARF-2 spec does not say how to handle this; let's just leave out the
9300 bounds. */
9304 static void
9305 add_byte_size_attribute (die, tree_node)
9306 dw_die_ref die;
9307 tree tree_node;
9309 unsigned size;
9311 switch (TREE_CODE (tree_node))
9313 case ERROR_MARK:
9314 size = 0;
9315 break;
9316 case ENUMERAL_TYPE:
9317 case RECORD_TYPE:
9318 case UNION_TYPE:
9319 case QUAL_UNION_TYPE:
9320 size = int_size_in_bytes (tree_node);
9321 break;
9322 case FIELD_DECL:
9323 /* For a data member of a struct or union, the DW_AT_byte_size is
9324 generally given as the number of bytes normally allocated for an
9325 object of the *declared* type of the member itself. This is true
9326 even for bit-fields. */
9327 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9328 break;
9329 default:
9330 abort ();
9333 /* Note that `size' might be -1 when we get to this point. If it is, that
9334 indicates that the byte size of the entity in question is variable. We
9335 have no good way of expressing this fact in Dwarf at the present time,
9336 so just let the -1 pass on through. */
9337 add_AT_unsigned (die, DW_AT_byte_size, size);
9340 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9341 which specifies the distance in bits from the highest order bit of the
9342 "containing object" for the bit-field to the highest order bit of the
9343 bit-field itself.
9345 For any given bit-field, the "containing object" is a hypothetical object
9346 (of some integral or enum type) within which the given bit-field lives. The
9347 type of this hypothetical "containing object" is always the same as the
9348 declared type of the individual bit-field itself. The determination of the
9349 exact location of the "containing object" for a bit-field is rather
9350 complicated. It's handled by the `field_byte_offset' function (above).
9352 Note that it is the size (in bytes) of the hypothetical "containing object"
9353 which will be given in the DW_AT_byte_size attribute for this bit-field.
9354 (See `byte_size_attribute' above). */
9356 static inline void
9357 add_bit_offset_attribute (die, decl)
9358 dw_die_ref die;
9359 tree decl;
9361 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9362 tree type = DECL_BIT_FIELD_TYPE (decl);
9363 HOST_WIDE_INT bitpos_int;
9364 HOST_WIDE_INT highest_order_object_bit_offset;
9365 HOST_WIDE_INT highest_order_field_bit_offset;
9366 HOST_WIDE_INT unsigned bit_offset;
9368 /* Must be a field and a bit field. */
9369 if (!type
9370 || TREE_CODE (decl) != FIELD_DECL)
9371 abort ();
9373 /* We can't yet handle bit-fields whose offsets are variable, so if we
9374 encounter such things, just return without generating any attribute
9375 whatsoever. Likewise for variable or too large size. */
9376 if (! host_integerp (bit_position (decl), 0)
9377 || ! host_integerp (DECL_SIZE (decl), 1))
9378 return;
9380 bitpos_int = int_bit_position (decl);
9382 /* Note that the bit offset is always the distance (in bits) from the
9383 highest-order bit of the "containing object" to the highest-order bit of
9384 the bit-field itself. Since the "high-order end" of any object or field
9385 is different on big-endian and little-endian machines, the computation
9386 below must take account of these differences. */
9387 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9388 highest_order_field_bit_offset = bitpos_int;
9390 if (! BYTES_BIG_ENDIAN)
9392 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9393 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9396 bit_offset
9397 = (! BYTES_BIG_ENDIAN
9398 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9399 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9401 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9404 /* For a FIELD_DECL node which represents a bit field, output an attribute
9405 which specifies the length in bits of the given field. */
9407 static inline void
9408 add_bit_size_attribute (die, decl)
9409 dw_die_ref die;
9410 tree decl;
9412 /* Must be a field and a bit field. */
9413 if (TREE_CODE (decl) != FIELD_DECL
9414 || ! DECL_BIT_FIELD_TYPE (decl))
9415 abort ();
9417 if (host_integerp (DECL_SIZE (decl), 1))
9418 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9421 /* If the compiled language is ANSI C, then add a 'prototyped'
9422 attribute, if arg types are given for the parameters of a function. */
9424 static inline void
9425 add_prototyped_attribute (die, func_type)
9426 dw_die_ref die;
9427 tree func_type;
9429 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9430 && TYPE_ARG_TYPES (func_type) != NULL)
9431 add_AT_flag (die, DW_AT_prototyped, 1);
9434 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9435 by looking in either the type declaration or object declaration
9436 equate table. */
9438 static inline void
9439 add_abstract_origin_attribute (die, origin)
9440 dw_die_ref die;
9441 tree origin;
9443 dw_die_ref origin_die = NULL;
9445 if (TREE_CODE (origin) != FUNCTION_DECL)
9447 /* We may have gotten separated from the block for the inlined
9448 function, if we're in an exception handler or some such; make
9449 sure that the abstract function has been written out.
9451 Doing this for nested functions is wrong, however; functions are
9452 distinct units, and our context might not even be inline. */
9453 tree fn = origin;
9455 if (TYPE_P (fn))
9456 fn = TYPE_STUB_DECL (fn);
9458 fn = decl_function_context (fn);
9459 if (fn)
9460 dwarf2out_abstract_function (fn);
9463 if (DECL_P (origin))
9464 origin_die = lookup_decl_die (origin);
9465 else if (TYPE_P (origin))
9466 origin_die = lookup_type_die (origin);
9468 if (origin_die == NULL)
9469 abort ();
9471 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9474 /* We do not currently support the pure_virtual attribute. */
9476 static inline void
9477 add_pure_or_virtual_attribute (die, func_decl)
9478 dw_die_ref die;
9479 tree func_decl;
9481 if (DECL_VINDEX (func_decl))
9483 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9485 if (host_integerp (DECL_VINDEX (func_decl), 0))
9486 add_AT_loc (die, DW_AT_vtable_elem_location,
9487 new_loc_descr (DW_OP_constu,
9488 tree_low_cst (DECL_VINDEX (func_decl), 0),
9489 0));
9491 /* GNU extension: Record what type this method came from originally. */
9492 if (debug_info_level > DINFO_LEVEL_TERSE)
9493 add_AT_die_ref (die, DW_AT_containing_type,
9494 lookup_type_die (DECL_CONTEXT (func_decl)));
9498 /* Add source coordinate attributes for the given decl. */
9500 static void
9501 add_src_coords_attributes (die, decl)
9502 dw_die_ref die;
9503 tree decl;
9505 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9507 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9508 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9511 /* Add an DW_AT_name attribute and source coordinate attribute for the
9512 given decl, but only if it actually has a name. */
9514 static void
9515 add_name_and_src_coords_attributes (die, decl)
9516 dw_die_ref die;
9517 tree decl;
9519 tree decl_name;
9521 decl_name = DECL_NAME (decl);
9522 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9524 add_name_attribute (die, dwarf2_name (decl, 0));
9525 if (! DECL_ARTIFICIAL (decl))
9526 add_src_coords_attributes (die, decl);
9528 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9529 && TREE_PUBLIC (decl)
9530 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9531 && !DECL_ABSTRACT (decl))
9532 add_AT_string (die, DW_AT_MIPS_linkage_name,
9533 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9536 #ifdef VMS_DEBUGGING_INFO
9537 /* Get the function's name, as described by its RTL. This may be different
9538 from the DECL_NAME name used in the source file. */
9539 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
9541 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
9542 XEXP (DECL_RTL (decl), 0));
9543 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
9545 #endif
9548 /* Push a new declaration scope. */
9550 static void
9551 push_decl_scope (scope)
9552 tree scope;
9554 VARRAY_PUSH_TREE (decl_scope_table, scope);
9557 /* Pop a declaration scope. */
9559 static inline void
9560 pop_decl_scope ()
9562 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9563 abort ();
9565 VARRAY_POP (decl_scope_table);
9568 /* Return the DIE for the scope that immediately contains this type.
9569 Non-named types get global scope. Named types nested in other
9570 types get their containing scope if it's open, or global scope
9571 otherwise. All other types (i.e. function-local named types) get
9572 the current active scope. */
9574 static dw_die_ref
9575 scope_die_for (t, context_die)
9576 tree t;
9577 dw_die_ref context_die;
9579 dw_die_ref scope_die = NULL;
9580 tree containing_scope;
9581 int i;
9583 /* Non-types always go in the current scope. */
9584 if (! TYPE_P (t))
9585 abort ();
9587 containing_scope = TYPE_CONTEXT (t);
9589 /* Ignore namespaces for the moment. */
9590 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9591 containing_scope = NULL_TREE;
9593 /* Ignore function type "scopes" from the C frontend. They mean that
9594 a tagged type is local to a parmlist of a function declarator, but
9595 that isn't useful to DWARF. */
9596 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9597 containing_scope = NULL_TREE;
9599 if (containing_scope == NULL_TREE)
9600 scope_die = comp_unit_die;
9601 else if (TYPE_P (containing_scope))
9603 /* For types, we can just look up the appropriate DIE. But
9604 first we check to see if we're in the middle of emitting it
9605 so we know where the new DIE should go. */
9606 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9607 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
9608 break;
9610 if (i < 0)
9612 if (debug_info_level > DINFO_LEVEL_TERSE
9613 && !TREE_ASM_WRITTEN (containing_scope))
9614 abort ();
9616 /* If none of the current dies are suitable, we get file scope. */
9617 scope_die = comp_unit_die;
9619 else
9620 scope_die = lookup_type_die (containing_scope);
9622 else
9623 scope_die = context_die;
9625 return scope_die;
9628 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9630 static inline int
9631 local_scope_p (context_die)
9632 dw_die_ref context_die;
9634 for (; context_die; context_die = context_die->die_parent)
9635 if (context_die->die_tag == DW_TAG_inlined_subroutine
9636 || context_die->die_tag == DW_TAG_subprogram)
9637 return 1;
9639 return 0;
9642 /* Returns nonzero if CONTEXT_DIE is a class. */
9644 static inline int
9645 class_scope_p (context_die)
9646 dw_die_ref context_die;
9648 return (context_die
9649 && (context_die->die_tag == DW_TAG_structure_type
9650 || context_die->die_tag == DW_TAG_union_type));
9653 /* Many forms of DIEs require a "type description" attribute. This
9654 routine locates the proper "type descriptor" die for the type given
9655 by 'type', and adds an DW_AT_type attribute below the given die. */
9657 static void
9658 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9659 dw_die_ref object_die;
9660 tree type;
9661 int decl_const;
9662 int decl_volatile;
9663 dw_die_ref context_die;
9665 enum tree_code code = TREE_CODE (type);
9666 dw_die_ref type_die = NULL;
9668 /* ??? If this type is an unnamed subrange type of an integral or
9669 floating-point type, use the inner type. This is because we have no
9670 support for unnamed types in base_type_die. This can happen if this is
9671 an Ada subrange type. Correct solution is emit a subrange type die. */
9672 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9673 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9674 type = TREE_TYPE (type), code = TREE_CODE (type);
9676 if (code == ERROR_MARK
9677 /* Handle a special case. For functions whose return type is void, we
9678 generate *no* type attribute. (Note that no object may have type
9679 `void', so this only applies to function return types). */
9680 || code == VOID_TYPE)
9681 return;
9683 type_die = modified_type_die (type,
9684 decl_const || TYPE_READONLY (type),
9685 decl_volatile || TYPE_VOLATILE (type),
9686 context_die);
9688 if (type_die != NULL)
9689 add_AT_die_ref (object_die, DW_AT_type, type_die);
9692 /* Given a tree pointer to a struct, class, union, or enum type node, return
9693 a pointer to the (string) tag name for the given type, or zero if the type
9694 was declared without a tag. */
9696 static const char *
9697 type_tag (type)
9698 tree type;
9700 const char *name = 0;
9702 if (TYPE_NAME (type) != 0)
9704 tree t = 0;
9706 /* Find the IDENTIFIER_NODE for the type name. */
9707 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9708 t = TYPE_NAME (type);
9710 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9711 a TYPE_DECL node, regardless of whether or not a `typedef' was
9712 involved. */
9713 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9714 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9715 t = DECL_NAME (TYPE_NAME (type));
9717 /* Now get the name as a string, or invent one. */
9718 if (t != 0)
9719 name = IDENTIFIER_POINTER (t);
9722 return (name == 0 || *name == '\0') ? 0 : name;
9725 /* Return the type associated with a data member, make a special check
9726 for bit field types. */
9728 static inline tree
9729 member_declared_type (member)
9730 tree member;
9732 return (DECL_BIT_FIELD_TYPE (member)
9733 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
9736 /* Get the decl's label, as described by its RTL. This may be different
9737 from the DECL_NAME name used in the source file. */
9739 #if 0
9740 static const char *
9741 decl_start_label (decl)
9742 tree decl;
9744 rtx x;
9745 const char *fnname;
9747 x = DECL_RTL (decl);
9748 if (GET_CODE (x) != MEM)
9749 abort ();
9751 x = XEXP (x, 0);
9752 if (GET_CODE (x) != SYMBOL_REF)
9753 abort ();
9755 fnname = XSTR (x, 0);
9756 return fnname;
9758 #endif
9760 /* These routines generate the internal representation of the DIE's for
9761 the compilation unit. Debugging information is collected by walking
9762 the declaration trees passed in from dwarf2out_decl(). */
9764 static void
9765 gen_array_type_die (type, context_die)
9766 tree type;
9767 dw_die_ref context_die;
9769 dw_die_ref scope_die = scope_die_for (type, context_die);
9770 dw_die_ref array_die;
9771 tree element_type;
9773 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9774 the inner array type comes before the outer array type. Thus we must
9775 call gen_type_die before we call new_die. See below also. */
9776 #ifdef MIPS_DEBUGGING_INFO
9777 gen_type_die (TREE_TYPE (type), context_die);
9778 #endif
9780 array_die = new_die (DW_TAG_array_type, scope_die, type);
9781 add_name_attribute (array_die, type_tag (type));
9782 equate_type_number_to_die (type, array_die);
9784 if (TREE_CODE (type) == VECTOR_TYPE)
9786 /* The frontend feeds us a representation for the vector as a struct
9787 containing an array. Pull out the array type. */
9788 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
9789 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
9792 #if 0
9793 /* We default the array ordering. SDB will probably do
9794 the right things even if DW_AT_ordering is not present. It's not even
9795 an issue until we start to get into multidimensional arrays anyway. If
9796 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9797 then we'll have to put the DW_AT_ordering attribute back in. (But if
9798 and when we find out that we need to put these in, we will only do so
9799 for multidimensional arrays. */
9800 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9801 #endif
9803 #ifdef MIPS_DEBUGGING_INFO
9804 /* The SGI compilers handle arrays of unknown bound by setting
9805 AT_declaration and not emitting any subrange DIEs. */
9806 if (! TYPE_DOMAIN (type))
9807 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9808 else
9809 #endif
9810 add_subscript_info (array_die, type);
9812 /* Add representation of the type of the elements of this array type. */
9813 element_type = TREE_TYPE (type);
9815 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9816 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9817 We work around this by disabling this feature. See also
9818 add_subscript_info. */
9819 #ifndef MIPS_DEBUGGING_INFO
9820 while (TREE_CODE (element_type) == ARRAY_TYPE)
9821 element_type = TREE_TYPE (element_type);
9823 gen_type_die (element_type, context_die);
9824 #endif
9826 add_type_attribute (array_die, element_type, 0, 0, context_die);
9829 static void
9830 gen_set_type_die (type, context_die)
9831 tree type;
9832 dw_die_ref context_die;
9834 dw_die_ref type_die
9835 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
9837 equate_type_number_to_die (type, type_die);
9838 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9841 #if 0
9842 static void
9843 gen_entry_point_die (decl, context_die)
9844 tree decl;
9845 dw_die_ref context_die;
9847 tree origin = decl_ultimate_origin (decl);
9848 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
9850 if (origin != NULL)
9851 add_abstract_origin_attribute (decl_die, origin);
9852 else
9854 add_name_and_src_coords_attributes (decl_die, decl);
9855 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9856 0, 0, context_die);
9859 if (DECL_ABSTRACT (decl))
9860 equate_decl_number_to_die (decl, decl_die);
9861 else
9862 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9864 #endif
9866 /* Walk through the list of incomplete types again, trying once more to
9867 emit full debugging info for them. */
9869 static void
9870 retry_incomplete_types ()
9872 int i;
9874 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
9875 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
9878 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9880 static void
9881 gen_inlined_enumeration_type_die (type, context_die)
9882 tree type;
9883 dw_die_ref context_die;
9885 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
9887 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9888 be incomplete and such types are not marked. */
9889 add_abstract_origin_attribute (type_die, type);
9892 /* Generate a DIE to represent an inlined instance of a structure type. */
9894 static void
9895 gen_inlined_structure_type_die (type, context_die)
9896 tree type;
9897 dw_die_ref context_die;
9899 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
9901 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9902 be incomplete and such types are not marked. */
9903 add_abstract_origin_attribute (type_die, type);
9906 /* Generate a DIE to represent an inlined instance of a union type. */
9908 static void
9909 gen_inlined_union_type_die (type, context_die)
9910 tree type;
9911 dw_die_ref context_die;
9913 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
9915 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9916 be incomplete and such types are not marked. */
9917 add_abstract_origin_attribute (type_die, type);
9920 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9921 include all of the information about the enumeration values also. Each
9922 enumerated type name/value is listed as a child of the enumerated type
9923 DIE. */
9925 static void
9926 gen_enumeration_type_die (type, context_die)
9927 tree type;
9928 dw_die_ref context_die;
9930 dw_die_ref type_die = lookup_type_die (type);
9932 if (type_die == NULL)
9934 type_die = new_die (DW_TAG_enumeration_type,
9935 scope_die_for (type, context_die), type);
9936 equate_type_number_to_die (type, type_die);
9937 add_name_attribute (type_die, type_tag (type));
9939 else if (! TYPE_SIZE (type))
9940 return;
9941 else
9942 remove_AT (type_die, DW_AT_declaration);
9944 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9945 given enum type is incomplete, do not generate the DW_AT_byte_size
9946 attribute or the DW_AT_element_list attribute. */
9947 if (TYPE_SIZE (type))
9949 tree link;
9951 TREE_ASM_WRITTEN (type) = 1;
9952 add_byte_size_attribute (type_die, type);
9953 if (TYPE_STUB_DECL (type) != NULL_TREE)
9954 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9956 /* If the first reference to this type was as the return type of an
9957 inline function, then it may not have a parent. Fix this now. */
9958 if (type_die->die_parent == NULL)
9959 add_child_die (scope_die_for (type, context_die), type_die);
9961 for (link = TYPE_FIELDS (type);
9962 link != NULL; link = TREE_CHAIN (link))
9964 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
9966 add_name_attribute (enum_die,
9967 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9969 if (host_integerp (TREE_VALUE (link), 0))
9971 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9972 add_AT_int (enum_die, DW_AT_const_value,
9973 tree_low_cst (TREE_VALUE (link), 0));
9974 else
9975 add_AT_unsigned (enum_die, DW_AT_const_value,
9976 tree_low_cst (TREE_VALUE (link), 0));
9980 else
9981 add_AT_flag (type_die, DW_AT_declaration, 1);
9984 /* Generate a DIE to represent either a real live formal parameter decl or to
9985 represent just the type of some formal parameter position in some function
9986 type.
9988 Note that this routine is a bit unusual because its argument may be a
9989 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9990 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9991 node. If it's the former then this function is being called to output a
9992 DIE to represent a formal parameter object (or some inlining thereof). If
9993 it's the latter, then this function is only being called to output a
9994 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9995 argument type of some subprogram type. */
9997 static dw_die_ref
9998 gen_formal_parameter_die (node, context_die)
9999 tree node;
10000 dw_die_ref context_die;
10002 dw_die_ref parm_die
10003 = new_die (DW_TAG_formal_parameter, context_die, node);
10004 tree origin;
10006 switch (TREE_CODE_CLASS (TREE_CODE (node)))
10008 case 'd':
10009 origin = decl_ultimate_origin (node);
10010 if (origin != NULL)
10011 add_abstract_origin_attribute (parm_die, origin);
10012 else
10014 add_name_and_src_coords_attributes (parm_die, node);
10015 add_type_attribute (parm_die, TREE_TYPE (node),
10016 TREE_READONLY (node),
10017 TREE_THIS_VOLATILE (node),
10018 context_die);
10019 if (DECL_ARTIFICIAL (node))
10020 add_AT_flag (parm_die, DW_AT_artificial, 1);
10023 equate_decl_number_to_die (node, parm_die);
10024 if (! DECL_ABSTRACT (node))
10025 add_location_or_const_value_attribute (parm_die, node);
10027 break;
10029 case 't':
10030 /* We were called with some kind of a ..._TYPE node. */
10031 add_type_attribute (parm_die, node, 0, 0, context_die);
10032 break;
10034 default:
10035 abort ();
10038 return parm_die;
10041 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10042 at the end of an (ANSI prototyped) formal parameters list. */
10044 static void
10045 gen_unspecified_parameters_die (decl_or_type, context_die)
10046 tree decl_or_type;
10047 dw_die_ref context_die;
10049 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
10052 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10053 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10054 parameters as specified in some function type specification (except for
10055 those which appear as part of a function *definition*). */
10057 static void
10058 gen_formal_types_die (function_or_method_type, context_die)
10059 tree function_or_method_type;
10060 dw_die_ref context_die;
10062 tree link;
10063 tree formal_type = NULL;
10064 tree first_parm_type;
10065 tree arg;
10067 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
10069 arg = DECL_ARGUMENTS (function_or_method_type);
10070 function_or_method_type = TREE_TYPE (function_or_method_type);
10072 else
10073 arg = NULL_TREE;
10075 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
10077 /* Make our first pass over the list of formal parameter types and output a
10078 DW_TAG_formal_parameter DIE for each one. */
10079 for (link = first_parm_type; link; )
10081 dw_die_ref parm_die;
10083 formal_type = TREE_VALUE (link);
10084 if (formal_type == void_type_node)
10085 break;
10087 /* Output a (nameless) DIE to represent the formal parameter itself. */
10088 parm_die = gen_formal_parameter_die (formal_type, context_die);
10089 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
10090 && link == first_parm_type)
10091 || (arg && DECL_ARTIFICIAL (arg)))
10092 add_AT_flag (parm_die, DW_AT_artificial, 1);
10094 link = TREE_CHAIN (link);
10095 if (arg)
10096 arg = TREE_CHAIN (arg);
10099 /* If this function type has an ellipsis, add a
10100 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10101 if (formal_type != void_type_node)
10102 gen_unspecified_parameters_die (function_or_method_type, context_die);
10104 /* Make our second (and final) pass over the list of formal parameter types
10105 and output DIEs to represent those types (as necessary). */
10106 for (link = TYPE_ARG_TYPES (function_or_method_type);
10107 link && TREE_VALUE (link);
10108 link = TREE_CHAIN (link))
10109 gen_type_die (TREE_VALUE (link), context_die);
10112 /* We want to generate the DIE for TYPE so that we can generate the
10113 die for MEMBER, which has been defined; we will need to refer back
10114 to the member declaration nested within TYPE. If we're trying to
10115 generate minimal debug info for TYPE, processing TYPE won't do the
10116 trick; we need to attach the member declaration by hand. */
10118 static void
10119 gen_type_die_for_member (type, member, context_die)
10120 tree type, member;
10121 dw_die_ref context_die;
10123 gen_type_die (type, context_die);
10125 /* If we're trying to avoid duplicate debug info, we may not have
10126 emitted the member decl for this function. Emit it now. */
10127 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10128 && ! lookup_decl_die (member))
10130 if (decl_ultimate_origin (member))
10131 abort ();
10133 push_decl_scope (type);
10134 if (TREE_CODE (member) == FUNCTION_DECL)
10135 gen_subprogram_die (member, lookup_type_die (type));
10136 else
10137 gen_variable_die (member, lookup_type_die (type));
10139 pop_decl_scope ();
10143 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10144 may later generate inlined and/or out-of-line instances of. */
10146 static void
10147 dwarf2out_abstract_function (decl)
10148 tree decl;
10150 dw_die_ref old_die;
10151 tree save_fn;
10152 tree context;
10153 int was_abstract = DECL_ABSTRACT (decl);
10155 /* Make sure we have the actual abstract inline, not a clone. */
10156 decl = DECL_ORIGIN (decl);
10158 old_die = lookup_decl_die (decl);
10159 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10160 /* We've already generated the abstract instance. */
10161 return;
10163 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10164 we don't get confused by DECL_ABSTRACT. */
10165 if (debug_info_level > DINFO_LEVEL_TERSE)
10167 context = decl_class_context (decl);
10168 if (context)
10169 gen_type_die_for_member
10170 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
10173 /* Pretend we've just finished compiling this function. */
10174 save_fn = current_function_decl;
10175 current_function_decl = decl;
10177 set_decl_abstract_flags (decl, 1);
10178 dwarf2out_decl (decl);
10179 if (! was_abstract)
10180 set_decl_abstract_flags (decl, 0);
10182 current_function_decl = save_fn;
10185 /* Generate a DIE to represent a declared function (either file-scope or
10186 block-local). */
10188 static void
10189 gen_subprogram_die (decl, context_die)
10190 tree decl;
10191 dw_die_ref context_die;
10193 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10194 tree origin = decl_ultimate_origin (decl);
10195 dw_die_ref subr_die;
10196 rtx fp_reg;
10197 tree fn_arg_types;
10198 tree outer_scope;
10199 dw_die_ref old_die = lookup_decl_die (decl);
10200 int declaration = (current_function_decl != decl
10201 || class_scope_p (context_die));
10203 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10204 started to generate the abstract instance of an inline, decided to output
10205 its containing class, and proceeded to emit the declaration of the inline
10206 from the member list for the class. If so, DECLARATION takes priority;
10207 we'll get back to the abstract instance when done with the class. */
10209 /* The class-scope declaration DIE must be the primary DIE. */
10210 if (origin && declaration && class_scope_p (context_die))
10212 origin = NULL;
10213 if (old_die)
10214 abort ();
10217 if (origin != NULL)
10219 if (declaration && ! local_scope_p (context_die))
10220 abort ();
10222 /* Fixup die_parent for the abstract instance of a nested
10223 inline function. */
10224 if (old_die && old_die->die_parent == NULL)
10225 add_child_die (context_die, old_die);
10227 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10228 add_abstract_origin_attribute (subr_die, origin);
10230 else if (old_die)
10232 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10234 if (!get_AT_flag (old_die, DW_AT_declaration)
10235 /* We can have a normal definition following an inline one in the
10236 case of redefinition of GNU C extern inlines.
10237 It seems reasonable to use AT_specification in this case. */
10238 && !get_AT_unsigned (old_die, DW_AT_inline))
10240 /* ??? This can happen if there is a bug in the program, for
10241 instance, if it has duplicate function definitions. Ideally,
10242 we should detect this case and ignore it. For now, if we have
10243 already reported an error, any error at all, then assume that
10244 we got here because of an input error, not a dwarf2 bug. */
10245 if (errorcount)
10246 return;
10247 abort ();
10250 /* If the definition comes from the same place as the declaration,
10251 maybe use the old DIE. We always want the DIE for this function
10252 that has the *_pc attributes to be under comp_unit_die so the
10253 debugger can find it. We also need to do this for abstract
10254 instances of inlines, since the spec requires the out-of-line copy
10255 to have the same parent. For local class methods, this doesn't
10256 apply; we just use the old DIE. */
10257 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10258 && (DECL_ARTIFICIAL (decl)
10259 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10260 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10261 == (unsigned) DECL_SOURCE_LINE (decl)))))
10263 subr_die = old_die;
10265 /* Clear out the declaration attribute and the parm types. */
10266 remove_AT (subr_die, DW_AT_declaration);
10267 remove_children (subr_die);
10269 else
10271 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10272 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10273 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10274 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10275 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10276 != (unsigned) DECL_SOURCE_LINE (decl))
10277 add_AT_unsigned
10278 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10281 else
10283 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10285 if (TREE_PUBLIC (decl))
10286 add_AT_flag (subr_die, DW_AT_external, 1);
10288 add_name_and_src_coords_attributes (subr_die, decl);
10289 if (debug_info_level > DINFO_LEVEL_TERSE)
10291 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
10292 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
10293 0, 0, context_die);
10296 add_pure_or_virtual_attribute (subr_die, decl);
10297 if (DECL_ARTIFICIAL (decl))
10298 add_AT_flag (subr_die, DW_AT_artificial, 1);
10300 if (TREE_PROTECTED (decl))
10301 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10302 else if (TREE_PRIVATE (decl))
10303 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10306 if (declaration)
10308 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10310 add_AT_flag (subr_die, DW_AT_declaration, 1);
10312 /* The first time we see a member function, it is in the context of
10313 the class to which it belongs. We make sure of this by emitting
10314 the class first. The next time is the definition, which is
10315 handled above. The two may come from the same source text. */
10316 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10317 equate_decl_number_to_die (decl, subr_die);
10320 else if (DECL_ABSTRACT (decl))
10322 if (DECL_INLINE (decl) && !flag_no_inline)
10324 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10325 inline functions, but not for extern inline functions.
10326 We can't get this completely correct because information
10327 about whether the function was declared inline is not
10328 saved anywhere. */
10329 if (DECL_DEFER_OUTPUT (decl))
10330 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10331 else
10332 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10334 else
10335 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10337 equate_decl_number_to_die (decl, subr_die);
10339 else if (!DECL_EXTERNAL (decl))
10341 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10342 equate_decl_number_to_die (decl, subr_die);
10344 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10345 current_funcdef_number);
10346 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10347 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10348 current_funcdef_number);
10349 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10351 add_pubname (decl, subr_die);
10352 add_arange (decl, subr_die);
10354 #ifdef MIPS_DEBUGGING_INFO
10355 /* Add a reference to the FDE for this routine. */
10356 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10357 #endif
10359 /* Define the "frame base" location for this routine. We use the
10360 frame pointer or stack pointer registers, since the RTL for local
10361 variables is relative to one of them. */
10362 fp_reg
10363 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10364 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10366 #if 0
10367 /* ??? This fails for nested inline functions, because context_display
10368 is not part of the state saved/restored for inline functions. */
10369 if (current_function_needs_context)
10370 add_AT_location_description (subr_die, DW_AT_static_link,
10371 lookup_static_chain (decl));
10372 #endif
10375 /* Now output descriptions of the arguments for this function. This gets
10376 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10377 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10378 `...' at the end of the formal parameter list. In order to find out if
10379 there was a trailing ellipsis or not, we must instead look at the type
10380 associated with the FUNCTION_DECL. This will be a node of type
10381 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10382 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10383 an ellipsis at the end. */
10385 /* In the case where we are describing a mere function declaration, all we
10386 need to do here (and all we *can* do here) is to describe the *types* of
10387 its formal parameters. */
10388 if (debug_info_level <= DINFO_LEVEL_TERSE)
10390 else if (declaration)
10391 gen_formal_types_die (decl, subr_die);
10392 else
10394 /* Generate DIEs to represent all known formal parameters */
10395 tree arg_decls = DECL_ARGUMENTS (decl);
10396 tree parm;
10398 /* When generating DIEs, generate the unspecified_parameters DIE
10399 instead if we come across the arg "__builtin_va_alist" */
10400 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10401 if (TREE_CODE (parm) == PARM_DECL)
10403 if (DECL_NAME (parm)
10404 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10405 "__builtin_va_alist"))
10406 gen_unspecified_parameters_die (parm, subr_die);
10407 else
10408 gen_decl_die (parm, subr_die);
10411 /* Decide whether we need an unspecified_parameters DIE at the end.
10412 There are 2 more cases to do this for: 1) the ansi ... declaration -
10413 this is detectable when the end of the arg list is not a
10414 void_type_node 2) an unprototyped function declaration (not a
10415 definition). This just means that we have no info about the
10416 parameters at all. */
10417 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10418 if (fn_arg_types != NULL)
10420 /* this is the prototyped case, check for ... */
10421 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10422 gen_unspecified_parameters_die (decl, subr_die);
10424 else if (DECL_INITIAL (decl) == NULL_TREE)
10425 gen_unspecified_parameters_die (decl, subr_die);
10428 /* Output Dwarf info for all of the stuff within the body of the function
10429 (if it has one - it may be just a declaration). */
10430 outer_scope = DECL_INITIAL (decl);
10432 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10433 a function. This BLOCK actually represents the outermost binding contour
10434 for the function, i.e. the contour in which the function's formal
10435 parameters and labels get declared. Curiously, it appears that the front
10436 end doesn't actually put the PARM_DECL nodes for the current function onto
10437 the BLOCK_VARS list for this outer scope, but are strung off of the
10438 DECL_ARGUMENTS list for the function instead.
10440 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10441 the LABEL_DECL nodes for the function however, and we output DWARF info
10442 for those in decls_for_scope. Just within the `outer_scope' there will be
10443 a BLOCK node representing the function's outermost pair of curly braces,
10444 and any blocks used for the base and member initializers of a C++
10445 constructor function. */
10446 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10448 current_function_has_inlines = 0;
10449 decls_for_scope (outer_scope, subr_die, 0);
10451 #if 0 && defined (MIPS_DEBUGGING_INFO)
10452 if (current_function_has_inlines)
10454 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10455 if (! comp_unit_has_inlines)
10457 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10458 comp_unit_has_inlines = 1;
10461 #endif
10465 /* Generate a DIE to represent a declared data object. */
10467 static void
10468 gen_variable_die (decl, context_die)
10469 tree decl;
10470 dw_die_ref context_die;
10472 tree origin = decl_ultimate_origin (decl);
10473 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
10475 dw_die_ref old_die = lookup_decl_die (decl);
10476 int declaration = (DECL_EXTERNAL (decl)
10477 || class_scope_p (context_die));
10479 if (origin != NULL)
10480 add_abstract_origin_attribute (var_die, origin);
10482 /* Loop unrolling can create multiple blocks that refer to the same
10483 static variable, so we must test for the DW_AT_declaration flag.
10485 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10486 copy decls and set the DECL_ABSTRACT flag on them instead of
10487 sharing them.
10489 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10490 else if (old_die && TREE_STATIC (decl)
10491 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10493 /* This is a definition of a C++ class level static. */
10494 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10495 if (DECL_NAME (decl))
10497 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10499 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10500 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10502 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10503 != (unsigned) DECL_SOURCE_LINE (decl))
10505 add_AT_unsigned (var_die, DW_AT_decl_line,
10506 DECL_SOURCE_LINE (decl));
10509 else
10511 add_name_and_src_coords_attributes (var_die, decl);
10512 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
10513 TREE_THIS_VOLATILE (decl), context_die);
10515 if (TREE_PUBLIC (decl))
10516 add_AT_flag (var_die, DW_AT_external, 1);
10518 if (DECL_ARTIFICIAL (decl))
10519 add_AT_flag (var_die, DW_AT_artificial, 1);
10521 if (TREE_PROTECTED (decl))
10522 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10523 else if (TREE_PRIVATE (decl))
10524 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10527 if (declaration)
10528 add_AT_flag (var_die, DW_AT_declaration, 1);
10530 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10531 equate_decl_number_to_die (decl, var_die);
10533 if (! declaration && ! DECL_ABSTRACT (decl))
10535 add_location_or_const_value_attribute (var_die, decl);
10536 add_pubname (decl, var_die);
10538 else
10539 tree_add_const_value_attribute (var_die, decl);
10542 /* Generate a DIE to represent a label identifier. */
10544 static void
10545 gen_label_die (decl, context_die)
10546 tree decl;
10547 dw_die_ref context_die;
10549 tree origin = decl_ultimate_origin (decl);
10550 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
10551 rtx insn;
10552 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10554 if (origin != NULL)
10555 add_abstract_origin_attribute (lbl_die, origin);
10556 else
10557 add_name_and_src_coords_attributes (lbl_die, decl);
10559 if (DECL_ABSTRACT (decl))
10560 equate_decl_number_to_die (decl, lbl_die);
10561 else
10563 insn = DECL_RTL (decl);
10565 /* Deleted labels are programmer specified labels which have been
10566 eliminated because of various optimisations. We still emit them
10567 here so that it is possible to put breakpoints on them. */
10568 if (GET_CODE (insn) == CODE_LABEL
10569 || ((GET_CODE (insn) == NOTE
10570 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10572 /* When optimization is enabled (via -O) some parts of the compiler
10573 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10574 represent source-level labels which were explicitly declared by
10575 the user. This really shouldn't be happening though, so catch
10576 it if it ever does happen. */
10577 if (INSN_DELETED_P (insn))
10578 abort ();
10580 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10581 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10586 /* Generate a DIE for a lexical block. */
10588 static void
10589 gen_lexical_block_die (stmt, context_die, depth)
10590 tree stmt;
10591 dw_die_ref context_die;
10592 int depth;
10594 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
10595 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10597 if (! BLOCK_ABSTRACT (stmt))
10599 if (BLOCK_FRAGMENT_CHAIN (stmt))
10601 tree chain;
10603 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
10605 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10608 add_ranges (chain);
10609 chain = BLOCK_FRAGMENT_CHAIN (chain);
10611 while (chain);
10612 add_ranges (NULL);
10614 else
10616 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10617 BLOCK_NUMBER (stmt));
10618 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10619 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10620 BLOCK_NUMBER (stmt));
10621 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10625 decls_for_scope (stmt, stmt_die, depth);
10628 /* Generate a DIE for an inlined subprogram. */
10630 static void
10631 gen_inlined_subroutine_die (stmt, context_die, depth)
10632 tree stmt;
10633 dw_die_ref context_die;
10634 int depth;
10636 if (! BLOCK_ABSTRACT (stmt))
10638 dw_die_ref subr_die
10639 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
10640 tree decl = block_ultimate_origin (stmt);
10641 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10643 /* Emit info for the abstract instance first, if we haven't yet. */
10644 dwarf2out_abstract_function (decl);
10646 add_abstract_origin_attribute (subr_die, decl);
10647 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10648 BLOCK_NUMBER (stmt));
10649 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10650 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10651 BLOCK_NUMBER (stmt));
10652 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10653 decls_for_scope (stmt, subr_die, depth);
10654 current_function_has_inlines = 1;
10656 else
10657 /* We may get here if we're the outer block of function A that was
10658 inlined into function B that was inlined into function C. When
10659 generating debugging info for C, dwarf2out_abstract_function(B)
10660 would mark all inlined blocks as abstract, including this one.
10661 So, we wouldn't (and shouldn't) expect labels to be generated
10662 for this one. Instead, just emit debugging info for
10663 declarations within the block. This is particularly important
10664 in the case of initializers of arguments passed from B to us:
10665 if they're statement expressions containing declarations, we
10666 wouldn't generate dies for their abstract variables, and then,
10667 when generating dies for the real variables, we'd die (pun
10668 intended :-) */
10669 gen_lexical_block_die (stmt, context_die, depth);
10672 /* Generate a DIE for a field in a record, or structure. */
10674 static void
10675 gen_field_die (decl, context_die)
10676 tree decl;
10677 dw_die_ref context_die;
10679 dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl);
10681 add_name_and_src_coords_attributes (decl_die, decl);
10682 add_type_attribute (decl_die, member_declared_type (decl),
10683 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10684 context_die);
10686 if (DECL_BIT_FIELD_TYPE (decl))
10688 add_byte_size_attribute (decl_die, decl);
10689 add_bit_size_attribute (decl_die, decl);
10690 add_bit_offset_attribute (decl_die, decl);
10693 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10694 add_data_member_location_attribute (decl_die, decl);
10696 if (DECL_ARTIFICIAL (decl))
10697 add_AT_flag (decl_die, DW_AT_artificial, 1);
10699 if (TREE_PROTECTED (decl))
10700 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10701 else if (TREE_PRIVATE (decl))
10702 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10705 #if 0
10706 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10707 Use modified_type_die instead.
10708 We keep this code here just in case these types of DIEs may be needed to
10709 represent certain things in other languages (e.g. Pascal) someday. */
10711 static void
10712 gen_pointer_type_die (type, context_die)
10713 tree type;
10714 dw_die_ref context_die;
10716 dw_die_ref ptr_die
10717 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
10719 equate_type_number_to_die (type, ptr_die);
10720 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10721 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10724 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10725 Use modified_type_die instead.
10726 We keep this code here just in case these types of DIEs may be needed to
10727 represent certain things in other languages (e.g. Pascal) someday. */
10729 static void
10730 gen_reference_type_die (type, context_die)
10731 tree type;
10732 dw_die_ref context_die;
10734 dw_die_ref ref_die
10735 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
10737 equate_type_number_to_die (type, ref_die);
10738 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10739 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10741 #endif
10743 /* Generate a DIE for a pointer to a member type. */
10745 static void
10746 gen_ptr_to_mbr_type_die (type, context_die)
10747 tree type;
10748 dw_die_ref context_die;
10750 dw_die_ref ptr_die
10751 = new_die (DW_TAG_ptr_to_member_type,
10752 scope_die_for (type, context_die), type);
10754 equate_type_number_to_die (type, ptr_die);
10755 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10756 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10757 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10760 /* Generate the DIE for the compilation unit. */
10762 static dw_die_ref
10763 gen_compile_unit_die (filename)
10764 const char *filename;
10766 dw_die_ref die;
10767 char producer[250];
10768 const char *wd = getpwd ();
10769 const char *language_string = lang_hooks.name;
10770 int language;
10772 die = new_die (DW_TAG_compile_unit, NULL, NULL);
10773 add_name_attribute (die, filename);
10775 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10776 add_AT_string (die, DW_AT_comp_dir, wd);
10778 sprintf (producer, "%s %s", language_string, version_string);
10780 #ifdef MIPS_DEBUGGING_INFO
10781 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10782 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10783 not appear in the producer string, the debugger reaches the conclusion
10784 that the object file is stripped and has no debugging information.
10785 To get the MIPS/SGI debugger to believe that there is debugging
10786 information in the object file, we add a -g to the producer string. */
10787 if (debug_info_level > DINFO_LEVEL_TERSE)
10788 strcat (producer, " -g");
10789 #endif
10791 add_AT_string (die, DW_AT_producer, producer);
10793 if (strcmp (language_string, "GNU C++") == 0)
10794 language = DW_LANG_C_plus_plus;
10795 else if (strcmp (language_string, "GNU Ada") == 0)
10796 language = DW_LANG_Ada83;
10797 else if (strcmp (language_string, "GNU F77") == 0)
10798 language = DW_LANG_Fortran77;
10799 else if (strcmp (language_string, "GNU Pascal") == 0)
10800 language = DW_LANG_Pascal83;
10801 else if (strcmp (language_string, "GNU Java") == 0)
10802 language = DW_LANG_Java;
10803 else
10804 language = DW_LANG_C89;
10806 add_AT_unsigned (die, DW_AT_language, language);
10807 return die;
10810 /* Generate a DIE for a string type. */
10812 static void
10813 gen_string_type_die (type, context_die)
10814 tree type;
10815 dw_die_ref context_die;
10817 dw_die_ref type_die
10818 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
10820 equate_type_number_to_die (type, type_die);
10822 /* ??? Fudge the string length attribute for now.
10823 TODO: add string length info. */
10824 #if 0
10825 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10826 bound_representation (upper_bound, 0, 'u');
10827 #endif
10830 /* Generate the DIE for a base class. */
10832 static void
10833 gen_inheritance_die (binfo, context_die)
10834 tree binfo;
10835 dw_die_ref context_die;
10837 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
10839 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10840 add_data_member_location_attribute (die, binfo);
10842 if (TREE_VIA_VIRTUAL (binfo))
10843 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10845 if (TREE_VIA_PUBLIC (binfo))
10846 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10847 else if (TREE_VIA_PROTECTED (binfo))
10848 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10851 /* Generate a DIE for a class member. */
10853 static void
10854 gen_member_die (type, context_die)
10855 tree type;
10856 dw_die_ref context_die;
10858 tree member;
10859 dw_die_ref child;
10861 /* If this is not an incomplete type, output descriptions of each of its
10862 members. Note that as we output the DIEs necessary to represent the
10863 members of this record or union type, we will also be trying to output
10864 DIEs to represent the *types* of those members. However the `type'
10865 function (above) will specifically avoid generating type DIEs for member
10866 types *within* the list of member DIEs for this (containing) type except
10867 for those types (of members) which are explicitly marked as also being
10868 members of this (containing) type themselves. The g++ front- end can
10869 force any given type to be treated as a member of some other (containing)
10870 type by setting the TYPE_CONTEXT of the given (member) type to point to
10871 the TREE node representing the appropriate (containing) type. */
10873 /* First output info about the base classes. */
10874 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10876 tree bases = TYPE_BINFO_BASETYPES (type);
10877 int n_bases = TREE_VEC_LENGTH (bases);
10878 int i;
10880 for (i = 0; i < n_bases; i++)
10881 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10884 /* Now output info about the data members and type members. */
10885 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10887 /* If we thought we were generating minimal debug info for TYPE
10888 and then changed our minds, some of the member declarations
10889 may have already been defined. Don't define them again, but
10890 do put them in the right order. */
10892 child = lookup_decl_die (member);
10893 if (child)
10894 splice_child_die (context_die, child);
10895 else
10896 gen_decl_die (member, context_die);
10899 /* Now output info about the function members (if any). */
10900 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10902 /* Don't include clones in the member list. */
10903 if (DECL_ABSTRACT_ORIGIN (member))
10904 continue;
10906 child = lookup_decl_die (member);
10907 if (child)
10908 splice_child_die (context_die, child);
10909 else
10910 gen_decl_die (member, context_die);
10914 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10915 is set, we pretend that the type was never defined, so we only get the
10916 member DIEs needed by later specification DIEs. */
10918 static void
10919 gen_struct_or_union_type_die (type, context_die)
10920 tree type;
10921 dw_die_ref context_die;
10923 dw_die_ref type_die = lookup_type_die (type);
10924 dw_die_ref scope_die = 0;
10925 int nested = 0;
10926 int complete = (TYPE_SIZE (type)
10927 && (! TYPE_STUB_DECL (type)
10928 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10930 if (type_die && ! complete)
10931 return;
10933 if (TYPE_CONTEXT (type) != NULL_TREE
10934 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10935 nested = 1;
10937 scope_die = scope_die_for (type, context_die);
10939 if (! type_die || (nested && scope_die == comp_unit_die))
10940 /* First occurrence of type or toplevel definition of nested class. */
10942 dw_die_ref old_die = type_die;
10944 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10945 ? DW_TAG_structure_type : DW_TAG_union_type,
10946 scope_die, type);
10947 equate_type_number_to_die (type, type_die);
10948 if (old_die)
10949 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10950 else
10951 add_name_attribute (type_die, type_tag (type));
10953 else
10954 remove_AT (type_die, DW_AT_declaration);
10956 /* If this type has been completed, then give it a byte_size attribute and
10957 then give a list of members. */
10958 if (complete)
10960 /* Prevent infinite recursion in cases where the type of some member of
10961 this type is expressed in terms of this type itself. */
10962 TREE_ASM_WRITTEN (type) = 1;
10963 add_byte_size_attribute (type_die, type);
10964 if (TYPE_STUB_DECL (type) != NULL_TREE)
10965 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10967 /* If the first reference to this type was as the return type of an
10968 inline function, then it may not have a parent. Fix this now. */
10969 if (type_die->die_parent == NULL)
10970 add_child_die (scope_die, type_die);
10972 push_decl_scope (type);
10973 gen_member_die (type, type_die);
10974 pop_decl_scope ();
10976 /* GNU extension: Record what type our vtable lives in. */
10977 if (TYPE_VFIELD (type))
10979 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10981 gen_type_die (vtype, context_die);
10982 add_AT_die_ref (type_die, DW_AT_containing_type,
10983 lookup_type_die (vtype));
10986 else
10988 add_AT_flag (type_die, DW_AT_declaration, 1);
10990 /* We don't need to do this for function-local types. */
10991 if (TYPE_STUB_DECL (type)
10992 && ! decl_function_context (TYPE_STUB_DECL (type)))
10993 VARRAY_PUSH_TREE (incomplete_types, type);
10997 /* Generate a DIE for a subroutine _type_. */
10999 static void
11000 gen_subroutine_type_die (type, context_die)
11001 tree type;
11002 dw_die_ref context_die;
11004 tree return_type = TREE_TYPE (type);
11005 dw_die_ref subr_die
11006 = new_die (DW_TAG_subroutine_type,
11007 scope_die_for (type, context_die), type);
11009 equate_type_number_to_die (type, subr_die);
11010 add_prototyped_attribute (subr_die, type);
11011 add_type_attribute (subr_die, return_type, 0, 0, context_die);
11012 gen_formal_types_die (type, subr_die);
11015 /* Generate a DIE for a type definition */
11017 static void
11018 gen_typedef_die (decl, context_die)
11019 tree decl;
11020 dw_die_ref context_die;
11022 dw_die_ref type_die;
11023 tree origin;
11025 if (TREE_ASM_WRITTEN (decl))
11026 return;
11028 TREE_ASM_WRITTEN (decl) = 1;
11029 type_die = new_die (DW_TAG_typedef, context_die, decl);
11030 origin = decl_ultimate_origin (decl);
11031 if (origin != NULL)
11032 add_abstract_origin_attribute (type_die, origin);
11033 else
11035 tree type;
11037 add_name_and_src_coords_attributes (type_die, decl);
11038 if (DECL_ORIGINAL_TYPE (decl))
11040 type = DECL_ORIGINAL_TYPE (decl);
11042 if (type == TREE_TYPE (decl))
11043 abort ();
11044 else
11045 equate_type_number_to_die (TREE_TYPE (decl), type_die);
11047 else
11048 type = TREE_TYPE (decl);
11050 add_type_attribute (type_die, type, TREE_READONLY (decl),
11051 TREE_THIS_VOLATILE (decl), context_die);
11054 if (DECL_ABSTRACT (decl))
11055 equate_decl_number_to_die (decl, type_die);
11058 /* Generate a type description DIE. */
11060 static void
11061 gen_type_die (type, context_die)
11062 tree type;
11063 dw_die_ref context_die;
11065 int need_pop;
11067 if (type == NULL_TREE || type == error_mark_node)
11068 return;
11070 /* We are going to output a DIE to represent the unqualified version
11071 of this type (i.e. without any const or volatile qualifiers) so
11072 get the main variant (i.e. the unqualified version) of this type
11073 now. (Vectors are special because the debugging info is in the
11074 cloned type itself). */
11075 if (TREE_CODE (type) != VECTOR_TYPE)
11076 type = type_main_variant (type);
11078 if (TREE_ASM_WRITTEN (type))
11079 return;
11081 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11082 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
11084 /* Prevent broken recursion; we can't hand off to the same type. */
11085 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type)
11086 abort ();
11088 TREE_ASM_WRITTEN (type) = 1;
11089 gen_decl_die (TYPE_NAME (type), context_die);
11090 return;
11093 switch (TREE_CODE (type))
11095 case ERROR_MARK:
11096 break;
11098 case POINTER_TYPE:
11099 case REFERENCE_TYPE:
11100 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11101 ensures that the gen_type_die recursion will terminate even if the
11102 type is recursive. Recursive types are possible in Ada. */
11103 /* ??? We could perhaps do this for all types before the switch
11104 statement. */
11105 TREE_ASM_WRITTEN (type) = 1;
11107 /* For these types, all that is required is that we output a DIE (or a
11108 set of DIEs) to represent the "basis" type. */
11109 gen_type_die (TREE_TYPE (type), context_die);
11110 break;
11112 case OFFSET_TYPE:
11113 /* This code is used for C++ pointer-to-data-member types.
11114 Output a description of the relevant class type. */
11115 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
11117 /* Output a description of the type of the object pointed to. */
11118 gen_type_die (TREE_TYPE (type), context_die);
11120 /* Now output a DIE to represent this pointer-to-data-member type
11121 itself. */
11122 gen_ptr_to_mbr_type_die (type, context_die);
11123 break;
11125 case SET_TYPE:
11126 gen_type_die (TYPE_DOMAIN (type), context_die);
11127 gen_set_type_die (type, context_die);
11128 break;
11130 case FILE_TYPE:
11131 gen_type_die (TREE_TYPE (type), context_die);
11132 abort (); /* No way to represent these in Dwarf yet! */
11133 break;
11135 case FUNCTION_TYPE:
11136 /* Force out return type (in case it wasn't forced out already). */
11137 gen_type_die (TREE_TYPE (type), context_die);
11138 gen_subroutine_type_die (type, context_die);
11139 break;
11141 case METHOD_TYPE:
11142 /* Force out return type (in case it wasn't forced out already). */
11143 gen_type_die (TREE_TYPE (type), context_die);
11144 gen_subroutine_type_die (type, context_die);
11145 break;
11147 case ARRAY_TYPE:
11148 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
11150 gen_type_die (TREE_TYPE (type), context_die);
11151 gen_string_type_die (type, context_die);
11153 else
11154 gen_array_type_die (type, context_die);
11155 break;
11157 case VECTOR_TYPE:
11158 gen_array_type_die (type, context_die);
11159 break;
11161 case ENUMERAL_TYPE:
11162 case RECORD_TYPE:
11163 case UNION_TYPE:
11164 case QUAL_UNION_TYPE:
11165 /* If this is a nested type whose containing class hasn't been written
11166 out yet, writing it out will cover this one, too. This does not apply
11167 to instantiations of member class templates; they need to be added to
11168 the containing class as they are generated. FIXME: This hurts the
11169 idea of combining type decls from multiple TUs, since we can't predict
11170 what set of template instantiations we'll get. */
11171 if (TYPE_CONTEXT (type)
11172 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
11173 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
11175 gen_type_die (TYPE_CONTEXT (type), context_die);
11177 if (TREE_ASM_WRITTEN (type))
11178 return;
11180 /* If that failed, attach ourselves to the stub. */
11181 push_decl_scope (TYPE_CONTEXT (type));
11182 context_die = lookup_type_die (TYPE_CONTEXT (type));
11183 need_pop = 1;
11185 else
11186 need_pop = 0;
11188 if (TREE_CODE (type) == ENUMERAL_TYPE)
11189 gen_enumeration_type_die (type, context_die);
11190 else
11191 gen_struct_or_union_type_die (type, context_die);
11193 if (need_pop)
11194 pop_decl_scope ();
11196 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11197 it up if it is ever completed. gen_*_type_die will set it for us
11198 when appropriate. */
11199 return;
11201 case VOID_TYPE:
11202 case INTEGER_TYPE:
11203 case REAL_TYPE:
11204 case COMPLEX_TYPE:
11205 case BOOLEAN_TYPE:
11206 case CHAR_TYPE:
11207 /* No DIEs needed for fundamental types. */
11208 break;
11210 case LANG_TYPE:
11211 /* No Dwarf representation currently defined. */
11212 break;
11214 default:
11215 abort ();
11218 TREE_ASM_WRITTEN (type) = 1;
11221 /* Generate a DIE for a tagged type instantiation. */
11223 static void
11224 gen_tagged_type_instantiation_die (type, context_die)
11225 tree type;
11226 dw_die_ref context_die;
11228 if (type == NULL_TREE || type == error_mark_node)
11229 return;
11231 /* We are going to output a DIE to represent the unqualified version of
11232 this type (i.e. without any const or volatile qualifiers) so make sure
11233 that we have the main variant (i.e. the unqualified version) of this
11234 type now. */
11235 if (type != type_main_variant (type))
11236 abort ();
11238 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11239 an instance of an unresolved type. */
11241 switch (TREE_CODE (type))
11243 case ERROR_MARK:
11244 break;
11246 case ENUMERAL_TYPE:
11247 gen_inlined_enumeration_type_die (type, context_die);
11248 break;
11250 case RECORD_TYPE:
11251 gen_inlined_structure_type_die (type, context_die);
11252 break;
11254 case UNION_TYPE:
11255 case QUAL_UNION_TYPE:
11256 gen_inlined_union_type_die (type, context_die);
11257 break;
11259 default:
11260 abort ();
11264 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11265 things which are local to the given block. */
11267 static void
11268 gen_block_die (stmt, context_die, depth)
11269 tree stmt;
11270 dw_die_ref context_die;
11271 int depth;
11273 int must_output_die = 0;
11274 tree origin;
11275 tree decl;
11276 enum tree_code origin_code;
11278 /* Ignore blocks never really used to make RTL. */
11279 if (stmt == NULL_TREE || !TREE_USED (stmt)
11280 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11281 return;
11283 /* If the block is one fragment of a non-contiguous block, do not
11284 process the variables, since they will have been done by the
11285 origin block. Do process subblocks. */
11286 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11288 tree sub;
11290 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
11291 gen_block_die (sub, context_die, depth + 1);
11293 return;
11296 /* Determine the "ultimate origin" of this block. This block may be an
11297 inlined instance of an inlined instance of inline function, so we have
11298 to trace all of the way back through the origin chain to find out what
11299 sort of node actually served as the original seed for the creation of
11300 the current block. */
11301 origin = block_ultimate_origin (stmt);
11302 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11304 /* Determine if we need to output any Dwarf DIEs at all to represent this
11305 block. */
11306 if (origin_code == FUNCTION_DECL)
11307 /* The outer scopes for inlinings *must* always be represented. We
11308 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11309 must_output_die = 1;
11310 else
11312 /* In the case where the current block represents an inlining of the
11313 "body block" of an inline function, we must *NOT* output any DIE for
11314 this block because we have already output a DIE to represent the whole
11315 inlined function scope and the "body block" of any function doesn't
11316 really represent a different scope according to ANSI C rules. So we
11317 check here to make sure that this block does not represent a "body
11318 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11319 if (! is_body_block (origin ? origin : stmt))
11321 /* Determine if this block directly contains any "significant"
11322 local declarations which we will need to output DIEs for. */
11323 if (debug_info_level > DINFO_LEVEL_TERSE)
11324 /* We are not in terse mode so *any* local declaration counts
11325 as being a "significant" one. */
11326 must_output_die = (BLOCK_VARS (stmt) != NULL);
11327 else
11328 /* We are in terse mode, so only local (nested) function
11329 definitions count as "significant" local declarations. */
11330 for (decl = BLOCK_VARS (stmt);
11331 decl != NULL; decl = TREE_CHAIN (decl))
11332 if (TREE_CODE (decl) == FUNCTION_DECL
11333 && DECL_INITIAL (decl))
11335 must_output_die = 1;
11336 break;
11341 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11342 DIE for any block which contains no significant local declarations at
11343 all. Rather, in such cases we just call `decls_for_scope' so that any
11344 needed Dwarf info for any sub-blocks will get properly generated. Note
11345 that in terse mode, our definition of what constitutes a "significant"
11346 local declaration gets restricted to include only inlined function
11347 instances and local (nested) function definitions. */
11348 if (must_output_die)
11350 if (origin_code == FUNCTION_DECL)
11351 gen_inlined_subroutine_die (stmt, context_die, depth);
11352 else
11353 gen_lexical_block_die (stmt, context_die, depth);
11355 else
11356 decls_for_scope (stmt, context_die, depth);
11359 /* Generate all of the decls declared within a given scope and (recursively)
11360 all of its sub-blocks. */
11362 static void
11363 decls_for_scope (stmt, context_die, depth)
11364 tree stmt;
11365 dw_die_ref context_die;
11366 int depth;
11368 tree decl;
11369 tree subblocks;
11371 /* Ignore blocks never really used to make RTL. */
11372 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11373 return;
11375 /* Output the DIEs to represent all of the data objects and typedefs
11376 declared directly within this block but not within any nested
11377 sub-blocks. Also, nested function and tag DIEs have been
11378 generated with a parent of NULL; fix that up now. */
11379 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
11381 dw_die_ref die;
11383 if (TREE_CODE (decl) == FUNCTION_DECL)
11384 die = lookup_decl_die (decl);
11385 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11386 die = lookup_type_die (TREE_TYPE (decl));
11387 else
11388 die = NULL;
11390 if (die != NULL && die->die_parent == NULL)
11391 add_child_die (context_die, die);
11392 else
11393 gen_decl_die (decl, context_die);
11396 /* Output the DIEs to represent all sub-blocks (and the items declared
11397 therein) of this block. */
11398 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11399 subblocks != NULL;
11400 subblocks = BLOCK_CHAIN (subblocks))
11401 gen_block_die (subblocks, context_die, depth + 1);
11404 /* Is this a typedef we can avoid emitting? */
11406 static inline int
11407 is_redundant_typedef (decl)
11408 tree decl;
11410 if (TYPE_DECL_IS_STUB (decl))
11411 return 1;
11413 if (DECL_ARTIFICIAL (decl)
11414 && DECL_CONTEXT (decl)
11415 && is_tagged_type (DECL_CONTEXT (decl))
11416 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11417 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11418 /* Also ignore the artificial member typedef for the class name. */
11419 return 1;
11421 return 0;
11424 /* Generate Dwarf debug information for a decl described by DECL. */
11426 static void
11427 gen_decl_die (decl, context_die)
11428 tree decl;
11429 dw_die_ref context_die;
11431 tree origin;
11433 if (DECL_P (decl) && DECL_IGNORED_P (decl))
11434 return;
11436 switch (TREE_CODE (decl))
11438 case ERROR_MARK:
11439 break;
11441 case CONST_DECL:
11442 /* The individual enumerators of an enum type get output when we output
11443 the Dwarf representation of the relevant enum type itself. */
11444 break;
11446 case FUNCTION_DECL:
11447 /* Don't output any DIEs to represent mere function declarations,
11448 unless they are class members or explicit block externs. */
11449 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11450 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11451 break;
11453 /* If we're emitting a clone, emit info for the abstract instance. */
11454 if (DECL_ORIGIN (decl) != decl)
11455 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11457 /* If we're emitting an out-of-line copy of an inline function,
11458 emit info for the abstract instance and set up to refer to it. */
11459 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11460 && ! class_scope_p (context_die)
11461 /* dwarf2out_abstract_function won't emit a die if this is just
11462 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11463 that case, because that works only if we have a die. */
11464 && DECL_INITIAL (decl) != NULL_TREE)
11466 dwarf2out_abstract_function (decl);
11467 set_decl_origin_self (decl);
11470 /* Otherwise we're emitting the primary DIE for this decl. */
11471 else if (debug_info_level > DINFO_LEVEL_TERSE)
11473 /* Before we describe the FUNCTION_DECL itself, make sure that we
11474 have described its return type. */
11475 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11477 /* And its virtual context. */
11478 if (DECL_VINDEX (decl) != NULL_TREE)
11479 gen_type_die (DECL_CONTEXT (decl), context_die);
11481 /* And its containing type. */
11482 origin = decl_class_context (decl);
11483 if (origin != NULL_TREE)
11484 gen_type_die_for_member (origin, decl, context_die);
11487 /* Now output a DIE to represent the function itself. */
11488 gen_subprogram_die (decl, context_die);
11489 break;
11491 case TYPE_DECL:
11492 /* If we are in terse mode, don't generate any DIEs to represent any
11493 actual typedefs. */
11494 if (debug_info_level <= DINFO_LEVEL_TERSE)
11495 break;
11497 /* In the special case of a TYPE_DECL node representing the declaration
11498 of some type tag, if the given TYPE_DECL is marked as having been
11499 instantiated from some other (original) TYPE_DECL node (e.g. one which
11500 was generated within the original definition of an inline function) we
11501 have to generate a special (abbreviated) DW_TAG_structure_type,
11502 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11503 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11505 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11506 break;
11509 if (is_redundant_typedef (decl))
11510 gen_type_die (TREE_TYPE (decl), context_die);
11511 else
11512 /* Output a DIE to represent the typedef itself. */
11513 gen_typedef_die (decl, context_die);
11514 break;
11516 case LABEL_DECL:
11517 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11518 gen_label_die (decl, context_die);
11519 break;
11521 case VAR_DECL:
11522 /* If we are in terse mode, don't generate any DIEs to represent any
11523 variable declarations or definitions. */
11524 if (debug_info_level <= DINFO_LEVEL_TERSE)
11525 break;
11527 /* Output any DIEs that are needed to specify the type of this data
11528 object. */
11529 gen_type_die (TREE_TYPE (decl), context_die);
11531 /* And its containing type. */
11532 origin = decl_class_context (decl);
11533 if (origin != NULL_TREE)
11534 gen_type_die_for_member (origin, decl, context_die);
11536 /* Now output the DIE to represent the data object itself. This gets
11537 complicated because of the possibility that the VAR_DECL really
11538 represents an inlined instance of a formal parameter for an inline
11539 function. */
11540 origin = decl_ultimate_origin (decl);
11541 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11542 gen_formal_parameter_die (decl, context_die);
11543 else
11544 gen_variable_die (decl, context_die);
11545 break;
11547 case FIELD_DECL:
11548 /* Ignore the nameless fields that are used to skip bits but handle C++
11549 anonymous unions. */
11550 if (DECL_NAME (decl) != NULL_TREE
11551 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11553 gen_type_die (member_declared_type (decl), context_die);
11554 gen_field_die (decl, context_die);
11556 break;
11558 case PARM_DECL:
11559 gen_type_die (TREE_TYPE (decl), context_die);
11560 gen_formal_parameter_die (decl, context_die);
11561 break;
11563 case NAMESPACE_DECL:
11564 /* Ignore for now. */
11565 break;
11567 default:
11568 abort ();
11572 static void
11573 mark_limbo_die_list (ptr)
11574 void *ptr ATTRIBUTE_UNUSED;
11576 limbo_die_node *node;
11577 for (node = limbo_die_list; node; node = node->next)
11578 ggc_mark_tree (node->created_for);
11581 /* Add Ada "use" clause information for SGI Workshop debugger. */
11583 void
11584 dwarf2out_add_library_unit_info (filename, context_list)
11585 const char *filename;
11586 const char *context_list;
11588 unsigned int file_index;
11590 if (filename != NULL)
11592 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
11593 tree context_list_decl
11594 = build_decl (LABEL_DECL, get_identifier (context_list),
11595 void_type_node);
11597 TREE_PUBLIC (context_list_decl) = TRUE;
11598 add_name_attribute (unit_die, context_list);
11599 file_index = lookup_filename (filename);
11600 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11601 add_pubname (context_list_decl, unit_die);
11605 /* Output debug information for global decl DECL. Called from toplev.c after
11606 compilation proper has finished. */
11608 static void
11609 dwarf2out_global_decl (decl)
11610 tree decl;
11612 /* Output DWARF2 information for file-scope tentative data object
11613 declarations, file-scope (extern) function declarations (which had no
11614 corresponding body) and file-scope tagged type declarations and
11615 definitions which have not yet been forced out. */
11616 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11617 dwarf2out_decl (decl);
11620 /* Write the debugging output for DECL. */
11622 void
11623 dwarf2out_decl (decl)
11624 tree decl;
11626 dw_die_ref context_die = comp_unit_die;
11628 switch (TREE_CODE (decl))
11630 case ERROR_MARK:
11631 return;
11633 case FUNCTION_DECL:
11634 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11635 builtin function. Explicit programmer-supplied declarations of
11636 these same functions should NOT be ignored however. */
11637 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11638 return;
11640 /* What we would really like to do here is to filter out all mere
11641 file-scope declarations of file-scope functions which are never
11642 referenced later within this translation unit (and keep all of ones
11643 that *are* referenced later on) but we aren't clairvoyant, so we have
11644 no idea which functions will be referenced in the future (i.e. later
11645 on within the current translation unit). So here we just ignore all
11646 file-scope function declarations which are not also definitions. If
11647 and when the debugger needs to know something about these functions,
11648 it will have to hunt around and find the DWARF information associated
11649 with the definition of the function.
11651 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11652 nodes represent definitions and which ones represent mere
11653 declarations. We have to check DECL_INITIAL instead. That's because
11654 the C front-end supports some weird semantics for "extern inline"
11655 function definitions. These can get inlined within the current
11656 translation unit (an thus, we need to generate Dwarf info for their
11657 abstract instances so that the Dwarf info for the concrete inlined
11658 instances can have something to refer to) but the compiler never
11659 generates any out-of-lines instances of such things (despite the fact
11660 that they *are* definitions).
11662 The important point is that the C front-end marks these "extern
11663 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11664 them anyway. Note that the C++ front-end also plays some similar games
11665 for inline function definitions appearing within include files which
11666 also contain `#pragma interface' pragmas. */
11667 if (DECL_INITIAL (decl) == NULL_TREE)
11668 return;
11670 /* If we're a nested function, initially use a parent of NULL; if we're
11671 a plain function, this will be fixed up in decls_for_scope. If
11672 we're a method, it will be ignored, since we already have a DIE. */
11673 if (decl_function_context (decl))
11674 context_die = NULL;
11675 break;
11677 case VAR_DECL:
11678 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11679 declaration and if the declaration was never even referenced from
11680 within this entire compilation unit. We suppress these DIEs in
11681 order to save space in the .debug section (by eliminating entries
11682 which are probably useless). Note that we must not suppress
11683 block-local extern declarations (whether used or not) because that
11684 would screw-up the debugger's name lookup mechanism and cause it to
11685 miss things which really ought to be in scope at a given point. */
11686 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11687 return;
11689 /* If we are in terse mode, don't generate any DIEs to represent any
11690 variable declarations or definitions. */
11691 if (debug_info_level <= DINFO_LEVEL_TERSE)
11692 return;
11693 break;
11695 case TYPE_DECL:
11696 /* Don't emit stubs for types unless they are needed by other DIEs. */
11697 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11698 return;
11700 /* Don't bother trying to generate any DIEs to represent any of the
11701 normal built-in types for the language we are compiling. */
11702 if (DECL_SOURCE_LINE (decl) == 0)
11704 /* OK, we need to generate one for `bool' so GDB knows what type
11705 comparisons have. */
11706 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11707 == DW_LANG_C_plus_plus)
11708 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
11709 && ! DECL_IGNORED_P (decl))
11710 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11712 return;
11715 /* If we are in terse mode, don't generate any DIEs for types. */
11716 if (debug_info_level <= DINFO_LEVEL_TERSE)
11717 return;
11719 /* If we're a function-scope tag, initially use a parent of NULL;
11720 this will be fixed up in decls_for_scope. */
11721 if (decl_function_context (decl))
11722 context_die = NULL;
11724 break;
11726 default:
11727 return;
11730 gen_decl_die (decl, context_die);
11733 /* Output a marker (i.e. a label) for the beginning of the generated code for
11734 a lexical block. */
11736 static void
11737 dwarf2out_begin_block (line, blocknum)
11738 unsigned int line ATTRIBUTE_UNUSED;
11739 unsigned int blocknum;
11741 function_section (current_function_decl);
11742 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11745 /* Output a marker (i.e. a label) for the end of the generated code for a
11746 lexical block. */
11748 static void
11749 dwarf2out_end_block (line, blocknum)
11750 unsigned int line ATTRIBUTE_UNUSED;
11751 unsigned int blocknum;
11753 function_section (current_function_decl);
11754 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11757 /* Returns nonzero if it is appropriate not to emit any debugging
11758 information for BLOCK, because it doesn't contain any instructions.
11760 Don't allow this for blocks with nested functions or local classes
11761 as we would end up with orphans, and in the presence of scheduling
11762 we may end up calling them anyway. */
11764 static bool
11765 dwarf2out_ignore_block (block)
11766 tree block;
11768 tree decl;
11770 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11771 if (TREE_CODE (decl) == FUNCTION_DECL
11772 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11773 return 0;
11775 return 1;
11778 /* Lookup FILE_NAME (in the list of filenames that we know about here in
11779 dwarf2out.c) and return its "index". The index of each (known) filename is
11780 just a unique number which is associated with only that one filename. We
11781 need such numbers for the sake of generating labels (in the .debug_sfnames
11782 section) and references to those files numbers (in the .debug_srcinfo
11783 and.debug_macinfo sections). If the filename given as an argument is not
11784 found in our current list, add it to the list and assign it the next
11785 available unique index number. In order to speed up searches, we remember
11786 the index of the filename was looked up last. This handles the majority of
11787 all searches. */
11789 static unsigned
11790 lookup_filename (file_name)
11791 const char *file_name;
11793 unsigned i;
11795 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11796 if (strcmp (file_name, "<internal>") == 0
11797 || strcmp (file_name, "<built-in>") == 0)
11798 return 0;
11800 /* Check to see if the file name that was searched on the previous
11801 call matches this file name. If so, return the index. */
11802 if (file_table.last_lookup_index != 0)
11803 if (0 == strcmp (file_name,
11804 file_table.table[file_table.last_lookup_index]))
11805 return file_table.last_lookup_index;
11807 /* Didn't match the previous lookup, search the table */
11808 for (i = 1; i < file_table.in_use; i++)
11809 if (strcmp (file_name, file_table.table[i]) == 0)
11811 file_table.last_lookup_index = i;
11812 return i;
11815 /* Prepare to add a new table entry by making sure there is enough space in
11816 the table to do so. If not, expand the current table. */
11817 if (i == file_table.allocated)
11819 file_table.allocated = i + FILE_TABLE_INCREMENT;
11820 file_table.table = (char **)
11821 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11824 /* Add the new entry to the end of the filename table. */
11825 file_table.table[i] = xstrdup (file_name);
11826 file_table.in_use = i + 1;
11827 file_table.last_lookup_index = i;
11829 if (DWARF2_ASM_LINE_DEBUG_INFO)
11831 fprintf (asm_out_file, "\t.file %u ", i);
11832 output_quoted_string (asm_out_file, file_name);
11833 fputc ('\n', asm_out_file);
11836 return i;
11839 static void
11840 init_file_table ()
11842 /* Allocate the initial hunk of the file_table. */
11843 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11844 file_table.allocated = FILE_TABLE_INCREMENT;
11846 /* Skip the first entry - file numbers begin at 1. */
11847 file_table.in_use = 1;
11848 file_table.last_lookup_index = 0;
11851 /* Output a label to mark the beginning of a source code line entry
11852 and record information relating to this source line, in
11853 'line_info_table' for later output of the .debug_line section. */
11855 static void
11856 dwarf2out_source_line (line, filename)
11857 unsigned int line;
11858 const char *filename;
11860 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11862 function_section (current_function_decl);
11864 /* If requested, emit something human-readable. */
11865 if (flag_debug_asm)
11866 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11867 filename, line);
11869 if (DWARF2_ASM_LINE_DEBUG_INFO)
11871 unsigned file_num = lookup_filename (filename);
11873 /* Emit the .loc directive understood by GNU as. */
11874 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11876 /* Indicate that line number info exists. */
11877 line_info_table_in_use++;
11879 /* Indicate that multiple line number tables exist. */
11880 if (DECL_SECTION_NAME (current_function_decl))
11881 separate_line_info_table_in_use++;
11883 else if (DECL_SECTION_NAME (current_function_decl))
11885 dw_separate_line_info_ref line_info;
11886 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11887 separate_line_info_table_in_use);
11889 /* expand the line info table if necessary */
11890 if (separate_line_info_table_in_use
11891 == separate_line_info_table_allocated)
11893 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11894 separate_line_info_table
11895 = (dw_separate_line_info_ref)
11896 xrealloc (separate_line_info_table,
11897 separate_line_info_table_allocated
11898 * sizeof (dw_separate_line_info_entry));
11901 /* Add the new entry at the end of the line_info_table. */
11902 line_info
11903 = &separate_line_info_table[separate_line_info_table_in_use++];
11904 line_info->dw_file_num = lookup_filename (filename);
11905 line_info->dw_line_num = line;
11906 line_info->function = current_funcdef_number;
11908 else
11910 dw_line_info_ref line_info;
11912 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11913 line_info_table_in_use);
11915 /* Expand the line info table if necessary. */
11916 if (line_info_table_in_use == line_info_table_allocated)
11918 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11919 line_info_table
11920 = (dw_line_info_ref)
11921 xrealloc (line_info_table,
11922 (line_info_table_allocated
11923 * sizeof (dw_line_info_entry)));
11926 /* Add the new entry at the end of the line_info_table. */
11927 line_info = &line_info_table[line_info_table_in_use++];
11928 line_info->dw_file_num = lookup_filename (filename);
11929 line_info->dw_line_num = line;
11934 /* Record the beginning of a new source file. */
11936 static void
11937 dwarf2out_start_source_file (lineno, filename)
11938 unsigned int lineno;
11939 const char *filename;
11941 if (flag_eliminate_dwarf2_dups)
11943 /* Record the beginning of the file for break_out_includes. */
11944 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
11945 add_AT_string (bincl_die, DW_AT_name, filename);
11948 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11950 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11951 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11952 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11953 lineno);
11954 dw2_asm_output_data_uleb128 (lookup_filename (filename),
11955 "Filename we just started");
11959 /* Record the end of a source file. */
11961 static void
11962 dwarf2out_end_source_file (lineno)
11963 unsigned int lineno ATTRIBUTE_UNUSED;
11965 if (flag_eliminate_dwarf2_dups)
11966 /* Record the end of the file for break_out_includes. */
11967 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
11969 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11971 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11972 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11976 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11977 the tail part of the directive line, i.e. the part which is past the
11978 initial whitespace, #, whitespace, directive-name, whitespace part. */
11980 static void
11981 dwarf2out_define (lineno, buffer)
11982 unsigned lineno ATTRIBUTE_UNUSED;
11983 const char *buffer ATTRIBUTE_UNUSED;
11985 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11987 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11988 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11989 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11990 dw2_asm_output_nstring (buffer, -1, "The macro");
11994 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11995 the tail part of the directive line, i.e. the part which is past the
11996 initial whitespace, #, whitespace, directive-name, whitespace part. */
11998 static void
11999 dwarf2out_undef (lineno, buffer)
12000 unsigned lineno ATTRIBUTE_UNUSED;
12001 const char *buffer ATTRIBUTE_UNUSED;
12003 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12005 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12006 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
12007 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12008 dw2_asm_output_nstring (buffer, -1, "The macro");
12012 /* Set up for Dwarf output at the start of compilation. */
12014 static void
12015 dwarf2out_init (main_input_filename)
12016 const char *main_input_filename;
12018 init_file_table ();
12020 /* Remember the name of the primary input file. */
12021 primary_filename = main_input_filename;
12023 /* Add it to the file table first, under the assumption that we'll
12024 be emitting line number data for it first, which avoids having
12025 to add an initial DW_LNS_set_file. */
12026 lookup_filename (main_input_filename);
12028 /* Allocate the initial hunk of the decl_die_table. */
12029 decl_die_table
12030 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
12031 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
12032 decl_die_table_in_use = 0;
12034 /* Allocate the initial hunk of the decl_scope_table. */
12035 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
12036 ggc_add_tree_varray_root (&decl_scope_table, 1);
12038 /* Allocate the initial hunk of the abbrev_die_table. */
12039 abbrev_die_table
12040 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
12041 sizeof (dw_die_ref));
12042 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
12043 /* Zero-th entry is allocated, but unused */
12044 abbrev_die_table_in_use = 1;
12046 /* Allocate the initial hunk of the line_info_table. */
12047 line_info_table
12048 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
12049 sizeof (dw_line_info_entry));
12050 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
12052 /* Zero-th entry is allocated, but unused */
12053 line_info_table_in_use = 1;
12055 /* Generate the initial DIE for the .debug section. Note that the (string)
12056 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12057 will (typically) be a relative pathname and that this pathname should be
12058 taken as being relative to the directory from which the compiler was
12059 invoked when the given (base) source file was compiled. */
12060 comp_unit_die = gen_compile_unit_die (main_input_filename);
12062 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
12063 ggc_add_tree_varray_root (&incomplete_types, 1);
12065 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
12066 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
12068 ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list);
12070 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
12071 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
12072 DEBUG_ABBREV_SECTION_LABEL, 0);
12073 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12074 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
12075 else
12076 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
12078 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
12079 DEBUG_INFO_SECTION_LABEL, 0);
12080 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
12081 DEBUG_LINE_SECTION_LABEL, 0);
12082 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
12083 DEBUG_RANGES_SECTION_LABEL, 0);
12084 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12085 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
12086 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
12087 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
12088 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12089 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
12091 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12093 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12094 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
12095 DEBUG_MACINFO_SECTION_LABEL, 0);
12096 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
12099 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12101 text_section ();
12102 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
12106 /* Allocate a string in .debug_str hash table. */
12108 static hashnode
12109 indirect_string_alloc (tab)
12110 hash_table *tab ATTRIBUTE_UNUSED;
12112 struct indirect_string_node *node;
12114 node = xmalloc (sizeof (struct indirect_string_node));
12115 node->refcount = 0;
12116 node->form = 0;
12117 node->label = NULL;
12119 return (hashnode) node;
12122 /* A helper function for dwarf2out_finish called through
12123 ht_forall. Emit one queued .debug_str string. */
12125 static int
12126 output_indirect_string (pfile, h, v)
12127 struct cpp_reader *pfile ATTRIBUTE_UNUSED;
12128 hashnode h;
12129 const PTR v ATTRIBUTE_UNUSED;
12131 struct indirect_string_node *node = (struct indirect_string_node *) h;
12133 if (node->form == DW_FORM_strp)
12135 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
12136 ASM_OUTPUT_LABEL (asm_out_file, node->label);
12137 assemble_string ((const char *) HT_STR (&node->id),
12138 HT_LEN (&node->id) + 1);
12141 return 1;
12144 /* Output stuff that dwarf requires at the end of every file,
12145 and generate the DWARF-2 debugging info. */
12147 static void
12148 dwarf2out_finish (input_filename)
12149 const char *input_filename ATTRIBUTE_UNUSED;
12151 limbo_die_node *node, *next_node;
12152 dw_die_ref die = 0;
12154 /* Traverse the limbo die list, and add parent/child links. The only
12155 dies without parents that should be here are concrete instances of
12156 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12157 For concrete instances, we can get the parent die from the abstract
12158 instance. */
12159 for (node = limbo_die_list; node; node = next_node)
12161 next_node = node->next;
12162 die = node->die;
12164 if (die->die_parent == NULL)
12166 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
12167 tree context;
12169 if (origin)
12170 add_child_die (origin->die_parent, die);
12171 else if (die == comp_unit_die)
12173 /* If this was an expression for a bound involved in a function
12174 return type, it may be a SAVE_EXPR for which we weren't able
12175 to find a DIE previously. So try now. */
12176 else if (node->created_for
12177 && TREE_CODE (node->created_for) == SAVE_EXPR
12178 && 0 != (origin = (lookup_decl_die
12179 (SAVE_EXPR_CONTEXT
12180 (node->created_for)))))
12181 add_child_die (origin, die);
12182 else if (errorcount > 0 || sorrycount > 0)
12183 /* It's OK to be confused by errors in the input. */
12184 add_child_die (comp_unit_die, die);
12185 else if (node->created_for
12186 && ((DECL_P (node->created_for)
12187 && (context = DECL_CONTEXT (node->created_for)))
12188 || (TYPE_P (node->created_for)
12189 && (context = TYPE_CONTEXT (node->created_for))))
12190 && TREE_CODE (context) == FUNCTION_DECL)
12192 /* In certain situations, the lexical block containing a
12193 nested function can be optimized away, which results
12194 in the nested function die being orphaned. Likewise
12195 with the return type of that nested function. Force
12196 this to be a child of the containing function. */
12197 origin = lookup_decl_die (context);
12198 if (! origin)
12199 abort ();
12200 add_child_die (origin, die);
12202 else
12203 abort ();
12206 free (node);
12209 limbo_die_list = NULL;
12211 /* Walk through the list of incomplete types again, trying once more to
12212 emit full debugging info for them. */
12213 retry_incomplete_types ();
12215 /* We need to reverse all the dies before break_out_includes, or
12216 we'll see the end of an include file before the beginning. */
12217 reverse_all_dies (comp_unit_die);
12219 /* Generate separate CUs for each of the include files we've seen.
12220 They will go into limbo_die_list. */
12221 if (flag_eliminate_dwarf2_dups)
12222 break_out_includes (comp_unit_die);
12224 /* Traverse the DIE's and add add sibling attributes to those DIE's
12225 that have children. */
12226 add_sibling_attributes (comp_unit_die);
12227 for (node = limbo_die_list; node; node = node->next)
12228 add_sibling_attributes (node->die);
12230 /* Output a terminator label for the .text section. */
12231 text_section ();
12232 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
12234 /* Output the source line correspondence table. We must do this
12235 even if there is no line information. Otherwise, on an empty
12236 translation unit, we will generate a present, but empty,
12237 .debug_info section. IRIX 6.5 `nm' will then complain when
12238 examining the file. */
12239 if (! DWARF2_ASM_LINE_DEBUG_INFO)
12241 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12242 output_line_info ();
12245 /* Output location list section if necessary. */
12246 if (have_location_lists)
12248 /* Output the location lists info. */
12249 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
12250 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
12251 DEBUG_LOC_SECTION_LABEL, 0);
12252 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
12253 output_location_lists (die);
12254 have_location_lists = 0;
12257 /* We can only use the low/high_pc attributes if all of the code was
12258 in .text. */
12259 if (separate_line_info_table_in_use == 0)
12261 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
12262 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
12265 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12266 "base address". Use zero so that these addresses become absolute. */
12267 else if (have_location_lists || ranges_table_in_use)
12268 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
12270 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12271 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
12272 debug_line_section_label);
12274 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12275 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
12277 /* Output all of the compilation units. We put the main one last so that
12278 the offsets are available to output_pubnames. */
12279 for (node = limbo_die_list; node; node = node->next)
12280 output_comp_unit (node->die);
12282 output_comp_unit (comp_unit_die);
12284 /* Output the abbreviation table. */
12285 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12286 output_abbrev_section ();
12288 /* Output public names table if necessary. */
12289 if (pubname_table_in_use)
12291 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
12292 output_pubnames ();
12295 /* Output the address range information. We only put functions in the arange
12296 table, so don't write it out if we don't have any. */
12297 if (fde_table_in_use)
12299 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
12300 output_aranges ();
12303 /* Output ranges section if necessary. */
12304 if (ranges_table_in_use)
12306 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
12307 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12308 output_ranges ();
12311 /* Have to end the primary source file. */
12312 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12314 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12315 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12316 dw2_asm_output_data (1, 0, "End compilation unit");
12319 /* If we emitted any DW_FORM_strp form attribute, output the string
12320 table too. */
12321 if (debug_str_hash)
12322 ht_forall (debug_str_hash, output_indirect_string, NULL);
12324 #endif /* DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO */