stl_bvector.h (swap(_Bit_reference,_Bit_reference)): Move/rename...
[official-gcc.git] / gcc / dwarf2out.c
blobf4b0ee7ff5d93b3e4bcbe08eebaa645969a2a81e
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 < FIRST_PSEUDO_REGISTER; i++)
424 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
426 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
427 HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]);
429 if (offset < 0)
430 continue;
432 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
436 /* Convert a DWARF call frame info. operation to its string name */
438 static const char *
439 dwarf_cfi_name (cfi_opc)
440 unsigned cfi_opc;
442 switch (cfi_opc)
444 case DW_CFA_advance_loc:
445 return "DW_CFA_advance_loc";
446 case DW_CFA_offset:
447 return "DW_CFA_offset";
448 case DW_CFA_restore:
449 return "DW_CFA_restore";
450 case DW_CFA_nop:
451 return "DW_CFA_nop";
452 case DW_CFA_set_loc:
453 return "DW_CFA_set_loc";
454 case DW_CFA_advance_loc1:
455 return "DW_CFA_advance_loc1";
456 case DW_CFA_advance_loc2:
457 return "DW_CFA_advance_loc2";
458 case DW_CFA_advance_loc4:
459 return "DW_CFA_advance_loc4";
460 case DW_CFA_offset_extended:
461 return "DW_CFA_offset_extended";
462 case DW_CFA_restore_extended:
463 return "DW_CFA_restore_extended";
464 case DW_CFA_undefined:
465 return "DW_CFA_undefined";
466 case DW_CFA_same_value:
467 return "DW_CFA_same_value";
468 case DW_CFA_register:
469 return "DW_CFA_register";
470 case DW_CFA_remember_state:
471 return "DW_CFA_remember_state";
472 case DW_CFA_restore_state:
473 return "DW_CFA_restore_state";
474 case DW_CFA_def_cfa:
475 return "DW_CFA_def_cfa";
476 case DW_CFA_def_cfa_register:
477 return "DW_CFA_def_cfa_register";
478 case DW_CFA_def_cfa_offset:
479 return "DW_CFA_def_cfa_offset";
481 /* DWARF 3 */
482 case DW_CFA_def_cfa_expression:
483 return "DW_CFA_def_cfa_expression";
484 case DW_CFA_expression:
485 return "DW_CFA_expression";
486 case DW_CFA_offset_extended_sf:
487 return "DW_CFA_offset_extended_sf";
488 case DW_CFA_def_cfa_sf:
489 return "DW_CFA_def_cfa_sf";
490 case DW_CFA_def_cfa_offset_sf:
491 return "DW_CFA_def_cfa_offset_sf";
493 /* SGI/MIPS specific */
494 case DW_CFA_MIPS_advance_loc8:
495 return "DW_CFA_MIPS_advance_loc8";
497 /* GNU extensions */
498 case DW_CFA_GNU_window_save:
499 return "DW_CFA_GNU_window_save";
500 case DW_CFA_GNU_args_size:
501 return "DW_CFA_GNU_args_size";
502 case DW_CFA_GNU_negative_offset_extended:
503 return "DW_CFA_GNU_negative_offset_extended";
505 default:
506 return "DW_CFA_<unknown>";
510 /* Return a pointer to a newly allocated Call Frame Instruction. */
512 static inline dw_cfi_ref
513 new_cfi ()
515 dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
517 cfi->dw_cfi_next = NULL;
518 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
519 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
521 return cfi;
524 /* Add a Call Frame Instruction to list of instructions. */
526 static inline void
527 add_cfi (list_head, cfi)
528 dw_cfi_ref *list_head;
529 dw_cfi_ref cfi;
531 dw_cfi_ref *p;
533 /* Find the end of the chain. */
534 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
537 *p = cfi;
540 /* Generate a new label for the CFI info to refer to. */
542 char *
543 dwarf2out_cfi_label ()
545 static char label[20];
546 static unsigned long label_num = 0;
548 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
549 ASM_OUTPUT_LABEL (asm_out_file, label);
550 return label;
553 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
554 or to the CIE if LABEL is NULL. */
556 static void
557 add_fde_cfi (label, cfi)
558 const char *label;
559 dw_cfi_ref cfi;
561 if (label)
563 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
565 if (*label == 0)
566 label = dwarf2out_cfi_label ();
568 if (fde->dw_fde_current_label == NULL
569 || strcmp (label, fde->dw_fde_current_label) != 0)
571 dw_cfi_ref xcfi;
573 fde->dw_fde_current_label = label = xstrdup (label);
575 /* Set the location counter to the new label. */
576 xcfi = new_cfi ();
577 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
578 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
579 add_cfi (&fde->dw_fde_cfi, xcfi);
582 add_cfi (&fde->dw_fde_cfi, cfi);
585 else
586 add_cfi (&cie_cfi_head, cfi);
589 /* Subroutine of lookup_cfa. */
591 static inline void
592 lookup_cfa_1 (cfi, loc)
593 dw_cfi_ref cfi;
594 dw_cfa_location *loc;
596 switch (cfi->dw_cfi_opc)
598 case DW_CFA_def_cfa_offset:
599 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
600 break;
601 case DW_CFA_def_cfa_register:
602 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
603 break;
604 case DW_CFA_def_cfa:
605 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
606 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
607 break;
608 case DW_CFA_def_cfa_expression:
609 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
610 break;
611 default:
612 break;
616 /* Find the previous value for the CFA. */
618 static void
619 lookup_cfa (loc)
620 dw_cfa_location *loc;
622 dw_cfi_ref cfi;
624 loc->reg = (unsigned long) -1;
625 loc->offset = 0;
626 loc->indirect = 0;
627 loc->base_offset = 0;
629 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
630 lookup_cfa_1 (cfi, loc);
632 if (fde_table_in_use)
634 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
635 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
636 lookup_cfa_1 (cfi, loc);
640 /* The current rule for calculating the DWARF2 canonical frame address. */
641 static dw_cfa_location cfa;
643 /* The register used for saving registers to the stack, and its offset
644 from the CFA. */
645 static dw_cfa_location cfa_store;
647 /* The running total of the size of arguments pushed onto the stack. */
648 static long args_size;
650 /* The last args_size we actually output. */
651 static long old_args_size;
653 /* Entry point to update the canonical frame address (CFA).
654 LABEL is passed to add_fde_cfi. The value of CFA is now to be
655 calculated from REG+OFFSET. */
657 void
658 dwarf2out_def_cfa (label, reg, offset)
659 const char *label;
660 unsigned reg;
661 long offset;
663 dw_cfa_location loc;
664 loc.indirect = 0;
665 loc.base_offset = 0;
666 loc.reg = reg;
667 loc.offset = offset;
668 def_cfa_1 (label, &loc);
671 /* This routine does the actual work. The CFA is now calculated from
672 the dw_cfa_location structure. */
674 static void
675 def_cfa_1 (label, loc_p)
676 const char *label;
677 dw_cfa_location *loc_p;
679 dw_cfi_ref cfi;
680 dw_cfa_location old_cfa, loc;
682 cfa = *loc_p;
683 loc = *loc_p;
685 if (cfa_store.reg == loc.reg && loc.indirect == 0)
686 cfa_store.offset = loc.offset;
688 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
689 lookup_cfa (&old_cfa);
691 /* If nothing changed, no need to issue any call frame instructions. */
692 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
693 && loc.indirect == old_cfa.indirect
694 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
695 return;
697 cfi = new_cfi ();
699 if (loc.reg == old_cfa.reg && !loc.indirect)
701 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
702 indicating the CFA register did not change but the offset
703 did. */
704 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
705 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
708 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
709 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
710 && !loc.indirect)
712 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
713 indicating the CFA register has changed to <register> but the
714 offset has not changed. */
715 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
716 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
718 #endif
720 else if (loc.indirect == 0)
722 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
723 indicating the CFA register has changed to <register> with
724 the specified offset. */
725 cfi->dw_cfi_opc = DW_CFA_def_cfa;
726 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
727 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
729 else
731 /* Construct a DW_CFA_def_cfa_expression instruction to
732 calculate the CFA using a full location expression since no
733 register-offset pair is available. */
734 struct dw_loc_descr_struct *loc_list;
736 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
737 loc_list = build_cfa_loc (&loc);
738 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
741 add_fde_cfi (label, cfi);
744 /* Add the CFI for saving a register. REG is the CFA column number.
745 LABEL is passed to add_fde_cfi.
746 If SREG is -1, the register is saved at OFFSET from the CFA;
747 otherwise it is saved in SREG. */
749 static void
750 reg_save (label, reg, sreg, offset)
751 const char *label;
752 unsigned reg;
753 unsigned sreg;
754 long offset;
756 dw_cfi_ref cfi = new_cfi ();
758 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
760 /* The following comparison is correct. -1 is used to indicate that
761 the value isn't a register number. */
762 if (sreg == (unsigned int) -1)
764 if (reg & ~0x3f)
765 /* The register number won't fit in 6 bits, so we have to use
766 the long form. */
767 cfi->dw_cfi_opc = DW_CFA_offset_extended;
768 else
769 cfi->dw_cfi_opc = DW_CFA_offset;
771 #ifdef ENABLE_CHECKING
773 /* If we get an offset that is not a multiple of
774 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
775 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
776 description. */
777 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
779 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
780 abort ();
782 #endif
783 offset /= DWARF_CIE_DATA_ALIGNMENT;
784 if (offset < 0)
785 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
787 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
789 else if (sreg == reg)
790 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
791 return;
792 else
794 cfi->dw_cfi_opc = DW_CFA_register;
795 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
798 add_fde_cfi (label, cfi);
801 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
802 This CFI tells the unwinder that it needs to restore the window registers
803 from the previous frame's window save area.
805 ??? Perhaps we should note in the CIE where windows are saved (instead of
806 assuming 0(cfa)) and what registers are in the window. */
808 void
809 dwarf2out_window_save (label)
810 const char *label;
812 dw_cfi_ref cfi = new_cfi ();
814 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
815 add_fde_cfi (label, cfi);
818 /* Add a CFI to update the running total of the size of arguments
819 pushed onto the stack. */
821 void
822 dwarf2out_args_size (label, size)
823 const char *label;
824 long size;
826 dw_cfi_ref cfi;
828 if (size == old_args_size)
829 return;
831 old_args_size = size;
833 cfi = new_cfi ();
834 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
835 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
836 add_fde_cfi (label, cfi);
839 /* Entry point for saving a register to the stack. REG is the GCC register
840 number. LABEL and OFFSET are passed to reg_save. */
842 void
843 dwarf2out_reg_save (label, reg, offset)
844 const char *label;
845 unsigned reg;
846 long offset;
848 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
851 /* Entry point for saving the return address in the stack.
852 LABEL and OFFSET are passed to reg_save. */
854 void
855 dwarf2out_return_save (label, offset)
856 const char *label;
857 long offset;
859 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
862 /* Entry point for saving the return address in a register.
863 LABEL and SREG are passed to reg_save. */
865 void
866 dwarf2out_return_reg (label, sreg)
867 const char *label;
868 unsigned sreg;
870 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
873 /* Record the initial position of the return address. RTL is
874 INCOMING_RETURN_ADDR_RTX. */
876 static void
877 initial_return_save (rtl)
878 rtx rtl;
880 unsigned int reg = (unsigned int) -1;
881 HOST_WIDE_INT offset = 0;
883 switch (GET_CODE (rtl))
885 case REG:
886 /* RA is in a register. */
887 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
888 break;
890 case MEM:
891 /* RA is on the stack. */
892 rtl = XEXP (rtl, 0);
893 switch (GET_CODE (rtl))
895 case REG:
896 if (REGNO (rtl) != STACK_POINTER_REGNUM)
897 abort ();
898 offset = 0;
899 break;
901 case PLUS:
902 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
903 abort ();
904 offset = INTVAL (XEXP (rtl, 1));
905 break;
907 case MINUS:
908 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
909 abort ();
910 offset = -INTVAL (XEXP (rtl, 1));
911 break;
913 default:
914 abort ();
917 break;
919 case PLUS:
920 /* The return address is at some offset from any value we can
921 actually load. For instance, on the SPARC it is in %i7+8. Just
922 ignore the offset for now; it doesn't matter for unwinding frames. */
923 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
924 abort ();
925 initial_return_save (XEXP (rtl, 0));
926 return;
928 default:
929 abort ();
932 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
935 /* Given a SET, calculate the amount of stack adjustment it
936 contains. */
938 static long
939 stack_adjust_offset (pattern)
940 rtx pattern;
942 rtx src = SET_SRC (pattern);
943 rtx dest = SET_DEST (pattern);
944 HOST_WIDE_INT offset = 0;
945 enum rtx_code code;
947 if (dest == stack_pointer_rtx)
949 /* (set (reg sp) (plus (reg sp) (const_int))) */
950 code = GET_CODE (src);
951 if (! (code == PLUS || code == MINUS)
952 || XEXP (src, 0) != stack_pointer_rtx
953 || GET_CODE (XEXP (src, 1)) != CONST_INT)
954 return 0;
956 offset = INTVAL (XEXP (src, 1));
957 if (code == PLUS)
958 offset = -offset;
960 else if (GET_CODE (dest) == MEM)
962 /* (set (mem (pre_dec (reg sp))) (foo)) */
963 src = XEXP (dest, 0);
964 code = GET_CODE (src);
966 switch (code)
968 case PRE_MODIFY:
969 case POST_MODIFY:
970 if (XEXP (src, 0) == stack_pointer_rtx)
972 rtx val = XEXP (XEXP (src, 1), 1);
973 /* We handle only adjustments by constant amount. */
974 if (GET_CODE (XEXP (src, 1)) != PLUS ||
975 GET_CODE (val) != CONST_INT)
976 abort ();
977 offset = -INTVAL (val);
978 break;
980 return 0;
982 case PRE_DEC:
983 case POST_DEC:
984 if (XEXP (src, 0) == stack_pointer_rtx)
986 offset = GET_MODE_SIZE (GET_MODE (dest));
987 break;
989 return 0;
991 case PRE_INC:
992 case POST_INC:
993 if (XEXP (src, 0) == stack_pointer_rtx)
995 offset = -GET_MODE_SIZE (GET_MODE (dest));
996 break;
998 return 0;
1000 default:
1001 return 0;
1004 else
1005 return 0;
1007 return offset;
1010 /* Check INSN to see if it looks like a push or a stack adjustment, and
1011 make a note of it if it does. EH uses this information to find out how
1012 much extra space it needs to pop off the stack. */
1014 static void
1015 dwarf2out_stack_adjust (insn)
1016 rtx insn;
1018 HOST_WIDE_INT offset;
1019 const char *label;
1020 int i;
1022 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1024 /* Extract the size of the args from the CALL rtx itself. */
1025 insn = PATTERN (insn);
1026 if (GET_CODE (insn) == PARALLEL)
1027 insn = XVECEXP (insn, 0, 0);
1028 if (GET_CODE (insn) == SET)
1029 insn = SET_SRC (insn);
1030 if (GET_CODE (insn) != CALL)
1031 abort ();
1033 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1034 return;
1037 /* If only calls can throw, and we have a frame pointer,
1038 save up adjustments until we see the CALL_INSN. */
1039 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1040 return;
1042 if (GET_CODE (insn) == BARRIER)
1044 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1045 the compiler will have already emitted a stack adjustment, but
1046 doesn't bother for calls to noreturn functions. */
1047 #ifdef STACK_GROWS_DOWNWARD
1048 offset = -args_size;
1049 #else
1050 offset = args_size;
1051 #endif
1053 else if (GET_CODE (PATTERN (insn)) == SET)
1054 offset = stack_adjust_offset (PATTERN (insn));
1055 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1056 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1058 /* There may be stack adjustments inside compound insns. Search
1059 for them. */
1060 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1061 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1062 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1064 else
1065 return;
1067 if (offset == 0)
1068 return;
1070 if (cfa.reg == STACK_POINTER_REGNUM)
1071 cfa.offset += offset;
1073 #ifndef STACK_GROWS_DOWNWARD
1074 offset = -offset;
1075 #endif
1077 args_size += offset;
1078 if (args_size < 0)
1079 args_size = 0;
1081 label = dwarf2out_cfi_label ();
1082 def_cfa_1 (label, &cfa);
1083 dwarf2out_args_size (label, args_size);
1086 /* We delay emitting a register save until either (a) we reach the end
1087 of the prologue or (b) the register is clobbered. This clusters
1088 register saves so that there are fewer pc advances. */
1090 struct queued_reg_save
1092 struct queued_reg_save *next;
1093 rtx reg;
1094 long cfa_offset;
1097 static struct queued_reg_save *queued_reg_saves;
1098 static const char *last_reg_save_label;
1100 static void
1101 queue_reg_save (label, reg, offset)
1102 const char *label;
1103 rtx reg;
1104 long offset;
1106 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1108 q->next = queued_reg_saves;
1109 q->reg = reg;
1110 q->cfa_offset = offset;
1111 queued_reg_saves = q;
1113 last_reg_save_label = label;
1116 static void
1117 flush_queued_reg_saves ()
1119 struct queued_reg_save *q, *next;
1121 for (q = queued_reg_saves; q; q = next)
1123 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1124 next = q->next;
1125 free (q);
1128 queued_reg_saves = NULL;
1129 last_reg_save_label = NULL;
1132 static bool
1133 clobbers_queued_reg_save (insn)
1134 rtx insn;
1136 struct queued_reg_save *q;
1138 for (q = queued_reg_saves; q; q = q->next)
1139 if (modified_in_p (q->reg, insn))
1140 return true;
1142 return false;
1146 /* A temporary register holding an integral value used in adjusting SP
1147 or setting up the store_reg. The "offset" field holds the integer
1148 value, not an offset. */
1149 static dw_cfa_location cfa_temp;
1151 /* Record call frame debugging information for an expression EXPR,
1152 which either sets SP or FP (adjusting how we calculate the frame
1153 address) or saves a register to the stack. LABEL indicates the
1154 address of EXPR.
1156 This function encodes a state machine mapping rtxes to actions on
1157 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1158 users need not read the source code.
1160 The High-Level Picture
1162 Changes in the register we use to calculate the CFA: Currently we
1163 assume that if you copy the CFA register into another register, we
1164 should take the other one as the new CFA register; this seems to
1165 work pretty well. If it's wrong for some target, it's simple
1166 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1168 Changes in the register we use for saving registers to the stack:
1169 This is usually SP, but not always. Again, we deduce that if you
1170 copy SP into another register (and SP is not the CFA register),
1171 then the new register is the one we will be using for register
1172 saves. This also seems to work.
1174 Register saves: There's not much guesswork about this one; if
1175 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1176 register save, and the register used to calculate the destination
1177 had better be the one we think we're using for this purpose.
1179 Except: If the register being saved is the CFA register, and the
1180 offset is non-zero, we are saving the CFA, so we assume we have to
1181 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1182 the intent is to save the value of SP from the previous frame.
1184 Invariants / Summaries of Rules
1186 cfa current rule for calculating the CFA. It usually
1187 consists of a register and an offset.
1188 cfa_store register used by prologue code to save things to the stack
1189 cfa_store.offset is the offset from the value of
1190 cfa_store.reg to the actual CFA
1191 cfa_temp register holding an integral value. cfa_temp.offset
1192 stores the value, which will be used to adjust the
1193 stack pointer. cfa_temp is also used like cfa_store,
1194 to track stores to the stack via fp or a temp reg.
1196 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1197 with cfa.reg as the first operand changes the cfa.reg and its
1198 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1199 cfa_temp.offset.
1201 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1202 expression yielding a constant. This sets cfa_temp.reg
1203 and cfa_temp.offset.
1205 Rule 5: Create a new register cfa_store used to save items to the
1206 stack.
1208 Rules 10-14: Save a register to the stack. Define offset as the
1209 difference of the original location and cfa_store's
1210 location (or cfa_temp's location if cfa_temp is used).
1212 The Rules
1214 "{a,b}" indicates a choice of a xor b.
1215 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1217 Rule 1:
1218 (set <reg1> <reg2>:cfa.reg)
1219 effects: cfa.reg = <reg1>
1220 cfa.offset unchanged
1221 cfa_temp.reg = <reg1>
1222 cfa_temp.offset = cfa.offset
1224 Rule 2:
1225 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1226 {<const_int>,<reg>:cfa_temp.reg}))
1227 effects: cfa.reg = sp if fp used
1228 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1229 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1230 if cfa_store.reg==sp
1232 Rule 3:
1233 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1234 effects: cfa.reg = fp
1235 cfa_offset += +/- <const_int>
1237 Rule 4:
1238 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1239 constraints: <reg1> != fp
1240 <reg1> != sp
1241 effects: cfa.reg = <reg1>
1242 cfa_temp.reg = <reg1>
1243 cfa_temp.offset = cfa.offset
1245 Rule 5:
1246 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1247 constraints: <reg1> != fp
1248 <reg1> != sp
1249 effects: cfa_store.reg = <reg1>
1250 cfa_store.offset = cfa.offset - cfa_temp.offset
1252 Rule 6:
1253 (set <reg> <const_int>)
1254 effects: cfa_temp.reg = <reg>
1255 cfa_temp.offset = <const_int>
1257 Rule 7:
1258 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1259 effects: cfa_temp.reg = <reg1>
1260 cfa_temp.offset |= <const_int>
1262 Rule 8:
1263 (set <reg> (high <exp>))
1264 effects: none
1266 Rule 9:
1267 (set <reg> (lo_sum <exp> <const_int>))
1268 effects: cfa_temp.reg = <reg>
1269 cfa_temp.offset = <const_int>
1271 Rule 10:
1272 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1273 effects: cfa_store.offset -= <const_int>
1274 cfa.offset = cfa_store.offset if cfa.reg == sp
1275 cfa.reg = sp
1276 cfa.base_offset = -cfa_store.offset
1278 Rule 11:
1279 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1280 effects: cfa_store.offset += -/+ mode_size(mem)
1281 cfa.offset = cfa_store.offset if cfa.reg == sp
1282 cfa.reg = sp
1283 cfa.base_offset = -cfa_store.offset
1285 Rule 12:
1286 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1288 <reg2>)
1289 effects: cfa.reg = <reg1>
1290 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1292 Rule 13:
1293 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1294 effects: cfa.reg = <reg1>
1295 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1297 Rule 14:
1298 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1299 effects: cfa.reg = <reg1>
1300 cfa.base_offset = -cfa_temp.offset
1301 cfa_temp.offset -= mode_size(mem) */
1303 static void
1304 dwarf2out_frame_debug_expr (expr, label)
1305 rtx expr;
1306 const char *label;
1308 rtx src, dest;
1309 HOST_WIDE_INT offset;
1311 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1312 the PARALLEL independently. The first element is always processed if
1313 it is a SET. This is for backward compatibility. Other elements
1314 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1315 flag is set in them. */
1316 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1318 int par_index;
1319 int limit = XVECLEN (expr, 0);
1321 for (par_index = 0; par_index < limit; par_index++)
1322 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1323 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1324 || par_index == 0))
1325 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1327 return;
1330 if (GET_CODE (expr) != SET)
1331 abort ();
1333 src = SET_SRC (expr);
1334 dest = SET_DEST (expr);
1336 switch (GET_CODE (dest))
1338 case REG:
1339 /* Rule 1 */
1340 /* Update the CFA rule wrt SP or FP. Make sure src is
1341 relative to the current CFA register. */
1342 switch (GET_CODE (src))
1344 /* Setting FP from SP. */
1345 case REG:
1346 if (cfa.reg == (unsigned) REGNO (src))
1347 /* OK. */
1349 else
1350 abort ();
1352 /* We used to require that dest be either SP or FP, but the
1353 ARM copies SP to a temporary register, and from there to
1354 FP. So we just rely on the backends to only set
1355 RTX_FRAME_RELATED_P on appropriate insns. */
1356 cfa.reg = REGNO (dest);
1357 cfa_temp.reg = cfa.reg;
1358 cfa_temp.offset = cfa.offset;
1359 break;
1361 case PLUS:
1362 case MINUS:
1363 case LO_SUM:
1364 if (dest == stack_pointer_rtx)
1366 /* Rule 2 */
1367 /* Adjusting SP. */
1368 switch (GET_CODE (XEXP (src, 1)))
1370 case CONST_INT:
1371 offset = INTVAL (XEXP (src, 1));
1372 break;
1373 case REG:
1374 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1375 abort ();
1376 offset = cfa_temp.offset;
1377 break;
1378 default:
1379 abort ();
1382 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1384 /* Restoring SP from FP in the epilogue. */
1385 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1386 abort ();
1387 cfa.reg = STACK_POINTER_REGNUM;
1389 else if (GET_CODE (src) == LO_SUM)
1390 /* Assume we've set the source reg of the LO_SUM from sp. */
1392 else if (XEXP (src, 0) != stack_pointer_rtx)
1393 abort ();
1395 if (GET_CODE (src) != MINUS)
1396 offset = -offset;
1397 if (cfa.reg == STACK_POINTER_REGNUM)
1398 cfa.offset += offset;
1399 if (cfa_store.reg == STACK_POINTER_REGNUM)
1400 cfa_store.offset += offset;
1402 else if (dest == hard_frame_pointer_rtx)
1404 /* Rule 3 */
1405 /* Either setting the FP from an offset of the SP,
1406 or adjusting the FP */
1407 if (! frame_pointer_needed)
1408 abort ();
1410 if (GET_CODE (XEXP (src, 0)) == REG
1411 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1412 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1414 offset = INTVAL (XEXP (src, 1));
1415 if (GET_CODE (src) != MINUS)
1416 offset = -offset;
1417 cfa.offset += offset;
1418 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1420 else
1421 abort ();
1423 else
1425 if (GET_CODE (src) == MINUS)
1426 abort ();
1428 /* Rule 4 */
1429 if (GET_CODE (XEXP (src, 0)) == REG
1430 && REGNO (XEXP (src, 0)) == cfa.reg
1431 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1433 /* Setting a temporary CFA register that will be copied
1434 into the FP later on. */
1435 offset = - INTVAL (XEXP (src, 1));
1436 cfa.offset += offset;
1437 cfa.reg = REGNO (dest);
1438 /* Or used to save regs to the stack. */
1439 cfa_temp.reg = cfa.reg;
1440 cfa_temp.offset = cfa.offset;
1443 /* Rule 5 */
1444 else if (GET_CODE (XEXP (src, 0)) == REG
1445 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1446 && XEXP (src, 1) == stack_pointer_rtx)
1448 /* Setting a scratch register that we will use instead
1449 of SP for saving registers to the stack. */
1450 if (cfa.reg != STACK_POINTER_REGNUM)
1451 abort ();
1452 cfa_store.reg = REGNO (dest);
1453 cfa_store.offset = cfa.offset - cfa_temp.offset;
1456 /* Rule 9 */
1457 else if (GET_CODE (src) == LO_SUM
1458 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1460 cfa_temp.reg = REGNO (dest);
1461 cfa_temp.offset = INTVAL (XEXP (src, 1));
1463 else
1464 abort ();
1466 break;
1468 /* Rule 6 */
1469 case CONST_INT:
1470 cfa_temp.reg = REGNO (dest);
1471 cfa_temp.offset = INTVAL (src);
1472 break;
1474 /* Rule 7 */
1475 case IOR:
1476 if (GET_CODE (XEXP (src, 0)) != REG
1477 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1478 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1479 abort ();
1481 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1482 cfa_temp.reg = REGNO (dest);
1483 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1484 break;
1486 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1487 which will fill in all of the bits. */
1488 /* Rule 8 */
1489 case HIGH:
1490 break;
1492 default:
1493 abort ();
1496 def_cfa_1 (label, &cfa);
1497 break;
1499 case MEM:
1500 if (GET_CODE (src) != REG)
1501 abort ();
1503 /* Saving a register to the stack. Make sure dest is relative to the
1504 CFA register. */
1505 switch (GET_CODE (XEXP (dest, 0)))
1507 /* Rule 10 */
1508 /* With a push. */
1509 case PRE_MODIFY:
1510 /* We can't handle variable size modifications. */
1511 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1512 abort ();
1513 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1515 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1516 || cfa_store.reg != STACK_POINTER_REGNUM)
1517 abort ();
1519 cfa_store.offset += offset;
1520 if (cfa.reg == STACK_POINTER_REGNUM)
1521 cfa.offset = cfa_store.offset;
1523 offset = -cfa_store.offset;
1524 break;
1526 /* Rule 11 */
1527 case PRE_INC:
1528 case PRE_DEC:
1529 offset = GET_MODE_SIZE (GET_MODE (dest));
1530 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1531 offset = -offset;
1533 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1534 || cfa_store.reg != STACK_POINTER_REGNUM)
1535 abort ();
1537 cfa_store.offset += offset;
1538 if (cfa.reg == STACK_POINTER_REGNUM)
1539 cfa.offset = cfa_store.offset;
1541 offset = -cfa_store.offset;
1542 break;
1544 /* Rule 12 */
1545 /* With an offset. */
1546 case PLUS:
1547 case MINUS:
1548 case LO_SUM:
1549 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1550 abort ();
1551 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1552 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1553 offset = -offset;
1555 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1556 offset -= cfa_store.offset;
1557 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1558 offset -= cfa_temp.offset;
1559 else
1560 abort ();
1561 break;
1563 /* Rule 13 */
1564 /* Without an offset. */
1565 case REG:
1566 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1567 offset = -cfa_store.offset;
1568 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1569 offset = -cfa_temp.offset;
1570 else
1571 abort ();
1572 break;
1574 /* Rule 14 */
1575 case POST_INC:
1576 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1577 abort ();
1578 offset = -cfa_temp.offset;
1579 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1580 break;
1582 default:
1583 abort ();
1586 if (REGNO (src) != STACK_POINTER_REGNUM
1587 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1588 && (unsigned) REGNO (src) == cfa.reg)
1590 /* We're storing the current CFA reg into the stack. */
1592 if (cfa.offset == 0)
1594 /* If the source register is exactly the CFA, assume
1595 we're saving SP like any other register; this happens
1596 on the ARM. */
1597 def_cfa_1 (label, &cfa);
1598 queue_reg_save (label, stack_pointer_rtx, offset);
1599 break;
1601 else
1603 /* Otherwise, we'll need to look in the stack to
1604 calculate the CFA. */
1605 rtx x = XEXP (dest, 0);
1607 if (GET_CODE (x) != REG)
1608 x = XEXP (x, 0);
1609 if (GET_CODE (x) != REG)
1610 abort ();
1612 cfa.reg = REGNO (x);
1613 cfa.base_offset = offset;
1614 cfa.indirect = 1;
1615 def_cfa_1 (label, &cfa);
1616 break;
1620 def_cfa_1 (label, &cfa);
1621 queue_reg_save (label, src, offset);
1622 break;
1624 default:
1625 abort ();
1629 /* Record call frame debugging information for INSN, which either
1630 sets SP or FP (adjusting how we calculate the frame address) or saves a
1631 register to the stack. If INSN is NULL_RTX, initialize our state. */
1633 void
1634 dwarf2out_frame_debug (insn)
1635 rtx insn;
1637 const char *label;
1638 rtx src;
1640 if (insn == NULL_RTX)
1642 /* Flush any queued register saves. */
1643 flush_queued_reg_saves ();
1645 /* Set up state for generating call frame debug info. */
1646 lookup_cfa (&cfa);
1647 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1648 abort ();
1650 cfa.reg = STACK_POINTER_REGNUM;
1651 cfa_store = cfa;
1652 cfa_temp.reg = -1;
1653 cfa_temp.offset = 0;
1654 return;
1657 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1658 flush_queued_reg_saves ();
1660 if (! RTX_FRAME_RELATED_P (insn))
1662 if (!ACCUMULATE_OUTGOING_ARGS)
1663 dwarf2out_stack_adjust (insn);
1665 return;
1668 label = dwarf2out_cfi_label ();
1669 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1670 if (src)
1671 insn = XEXP (src, 0);
1672 else
1673 insn = PATTERN (insn);
1675 dwarf2out_frame_debug_expr (insn, label);
1678 /* Output a Call Frame Information opcode and its operand(s). */
1680 static void
1681 output_cfi (cfi, fde, for_eh)
1682 dw_cfi_ref cfi;
1683 dw_fde_ref fde;
1684 int for_eh;
1686 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1687 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1688 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1689 "DW_CFA_advance_loc 0x%lx",
1690 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1691 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1693 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1694 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1695 "DW_CFA_offset, column 0x%lx",
1696 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1697 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1699 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1700 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1701 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1702 "DW_CFA_restore, column 0x%lx",
1703 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1704 else
1706 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1707 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1709 switch (cfi->dw_cfi_opc)
1711 case DW_CFA_set_loc:
1712 if (for_eh)
1713 dw2_asm_output_encoded_addr_rtx (
1714 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1715 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1716 NULL);
1717 else
1718 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1719 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1720 break;
1722 case DW_CFA_advance_loc1:
1723 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1724 fde->dw_fde_current_label, NULL);
1725 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1726 break;
1728 case DW_CFA_advance_loc2:
1729 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1730 fde->dw_fde_current_label, NULL);
1731 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1732 break;
1734 case DW_CFA_advance_loc4:
1735 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1736 fde->dw_fde_current_label, NULL);
1737 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1738 break;
1740 case DW_CFA_MIPS_advance_loc8:
1741 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1742 fde->dw_fde_current_label, NULL);
1743 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1744 break;
1746 case DW_CFA_offset_extended:
1747 case DW_CFA_def_cfa:
1748 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1749 NULL);
1750 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1751 break;
1753 case DW_CFA_offset_extended_sf:
1754 case DW_CFA_def_cfa_sf:
1755 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1756 NULL);
1757 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1758 break;
1760 case DW_CFA_restore_extended:
1761 case DW_CFA_undefined:
1762 case DW_CFA_same_value:
1763 case DW_CFA_def_cfa_register:
1764 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1765 NULL);
1766 break;
1768 case DW_CFA_register:
1769 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1770 NULL);
1771 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1772 NULL);
1773 break;
1775 case DW_CFA_def_cfa_offset:
1776 case DW_CFA_GNU_args_size:
1777 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1778 break;
1780 case DW_CFA_def_cfa_offset_sf:
1781 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1782 break;
1784 case DW_CFA_GNU_window_save:
1785 break;
1787 case DW_CFA_def_cfa_expression:
1788 case DW_CFA_expression:
1789 output_cfa_loc (cfi);
1790 break;
1792 case DW_CFA_GNU_negative_offset_extended:
1793 /* Obsoleted by DW_CFA_offset_extended_sf. */
1794 abort ();
1796 default:
1797 break;
1802 /* Output the call frame information used to used to record information
1803 that relates to calculating the frame pointer, and records the
1804 location of saved registers. */
1806 static void
1807 output_call_frame_info (for_eh)
1808 int for_eh;
1810 unsigned int i;
1811 dw_fde_ref fde;
1812 dw_cfi_ref cfi;
1813 char l1[20], l2[20], section_start_label[20];
1814 int any_lsda_needed = 0;
1815 char augmentation[6];
1816 int augmentation_size;
1817 int fde_encoding = DW_EH_PE_absptr;
1818 int per_encoding = DW_EH_PE_absptr;
1819 int lsda_encoding = DW_EH_PE_absptr;
1821 /* Don't emit a CIE if there won't be any FDEs. */
1822 if (fde_table_in_use == 0)
1823 return;
1825 /* If we don't have any functions we'll want to unwind out of, don't emit any
1826 EH unwind information. */
1827 if (for_eh)
1829 int any_eh_needed = flag_asynchronous_unwind_tables;
1831 for (i = 0; i < fde_table_in_use; i++)
1832 if (fde_table[i].uses_eh_lsda)
1833 any_eh_needed = any_lsda_needed = 1;
1834 else if (! fde_table[i].nothrow)
1835 any_eh_needed = 1;
1837 if (! any_eh_needed)
1838 return;
1841 /* We're going to be generating comments, so turn on app. */
1842 if (flag_debug_asm)
1843 app_enable ();
1845 if (for_eh)
1846 (*targetm.asm_out.eh_frame_section) ();
1847 else
1848 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1850 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1851 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1853 /* Output the CIE. */
1854 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1855 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1856 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1857 "Length of Common Information Entry");
1858 ASM_OUTPUT_LABEL (asm_out_file, l1);
1860 /* Now that the CIE pointer is PC-relative for EH,
1861 use 0 to identify the CIE. */
1862 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1863 (for_eh ? 0 : DW_CIE_ID),
1864 "CIE Identifier Tag");
1866 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1868 augmentation[0] = 0;
1869 augmentation_size = 0;
1870 if (for_eh)
1872 char *p;
1874 /* Augmentation:
1875 z Indicates that a uleb128 is present to size the
1876 augmentation section.
1877 L Indicates the encoding (and thus presence) of
1878 an LSDA pointer in the FDE augmentation.
1879 R Indicates a non-default pointer encoding for
1880 FDE code pointers.
1881 P Indicates the presence of an encoding + language
1882 personality routine in the CIE augmentation. */
1884 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1885 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1886 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1888 p = augmentation + 1;
1889 if (eh_personality_libfunc)
1891 *p++ = 'P';
1892 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1894 if (any_lsda_needed)
1896 *p++ = 'L';
1897 augmentation_size += 1;
1899 if (fde_encoding != DW_EH_PE_absptr)
1901 *p++ = 'R';
1902 augmentation_size += 1;
1904 if (p > augmentation + 1)
1906 augmentation[0] = 'z';
1907 *p = '\0';
1910 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1911 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1913 int offset = ( 4 /* Length */
1914 + 4 /* CIE Id */
1915 + 1 /* CIE version */
1916 + strlen (augmentation) + 1 /* Augmentation */
1917 + size_of_uleb128 (1) /* Code alignment */
1918 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1919 + 1 /* RA column */
1920 + 1 /* Augmentation size */
1921 + 1 /* Personality encoding */ );
1922 int pad = -offset & (PTR_SIZE - 1);
1924 augmentation_size += pad;
1926 /* Augmentations should be small, so there's scarce need to
1927 iterate for a solution. Die if we exceed one uleb128 byte. */
1928 if (size_of_uleb128 (augmentation_size) != 1)
1929 abort ();
1933 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1934 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1935 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1936 "CIE Data Alignment Factor");
1937 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1939 if (augmentation[0])
1941 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1942 if (eh_personality_libfunc)
1944 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1945 eh_data_format_name (per_encoding));
1946 dw2_asm_output_encoded_addr_rtx (per_encoding,
1947 eh_personality_libfunc, NULL);
1950 if (any_lsda_needed)
1951 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1952 eh_data_format_name (lsda_encoding));
1954 if (fde_encoding != DW_EH_PE_absptr)
1955 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1956 eh_data_format_name (fde_encoding));
1959 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1960 output_cfi (cfi, NULL, for_eh);
1962 /* Pad the CIE out to an address sized boundary. */
1963 ASM_OUTPUT_ALIGN (asm_out_file,
1964 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1965 ASM_OUTPUT_LABEL (asm_out_file, l2);
1967 /* Loop through all of the FDE's. */
1968 for (i = 0; i < fde_table_in_use; i++)
1970 fde = &fde_table[i];
1972 /* Don't emit EH unwind info for leaf functions that don't need it. */
1973 if (!flag_asynchronous_unwind_tables && for_eh && fde->nothrow
1974 && ! fde->uses_eh_lsda)
1975 continue;
1977 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1978 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1979 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1980 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1981 "FDE Length");
1982 ASM_OUTPUT_LABEL (asm_out_file, l1);
1984 if (for_eh)
1985 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
1986 else
1987 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
1988 "FDE CIE offset");
1990 if (for_eh)
1992 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1993 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1994 "FDE initial location");
1995 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1996 fde->dw_fde_end, fde->dw_fde_begin,
1997 "FDE address range");
1999 else
2001 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2002 "FDE initial location");
2003 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2004 fde->dw_fde_end, fde->dw_fde_begin,
2005 "FDE address range");
2008 if (augmentation[0])
2010 if (any_lsda_needed)
2012 int size = size_of_encoded_value (lsda_encoding);
2014 if (lsda_encoding == DW_EH_PE_aligned)
2016 int offset = ( 4 /* Length */
2017 + 4 /* CIE offset */
2018 + 2 * size_of_encoded_value (fde_encoding)
2019 + 1 /* Augmentation size */ );
2020 int pad = -offset & (PTR_SIZE - 1);
2022 size += pad;
2023 if (size_of_uleb128 (size) != 1)
2024 abort ();
2027 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2029 if (fde->uses_eh_lsda)
2031 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2032 fde->funcdef_number);
2033 dw2_asm_output_encoded_addr_rtx (
2034 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2035 "Language Specific Data Area");
2037 else
2039 if (lsda_encoding == DW_EH_PE_aligned)
2040 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2041 dw2_asm_output_data
2042 (size_of_encoded_value (lsda_encoding), 0,
2043 "Language Specific Data Area (none)");
2046 else
2047 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2050 /* Loop through the Call Frame Instructions associated with
2051 this FDE. */
2052 fde->dw_fde_current_label = fde->dw_fde_begin;
2053 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2054 output_cfi (cfi, fde, for_eh);
2056 /* Pad the FDE out to an address sized boundary. */
2057 ASM_OUTPUT_ALIGN (asm_out_file,
2058 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2059 ASM_OUTPUT_LABEL (asm_out_file, l2);
2062 #ifndef EH_FRAME_SECTION_NAME
2063 if (for_eh)
2064 dw2_asm_output_data (4, 0, "End of Table");
2065 #endif
2066 #ifdef MIPS_DEBUGGING_INFO
2067 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2068 get a value of 0. Putting .align 0 after the label fixes it. */
2069 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2070 #endif
2072 /* Turn off app to make assembly quicker. */
2073 if (flag_debug_asm)
2074 app_disable ();
2077 /* Output a marker (i.e. a label) for the beginning of a function, before
2078 the prologue. */
2080 void
2081 dwarf2out_begin_prologue (line, file)
2082 unsigned int line ATTRIBUTE_UNUSED;
2083 const char *file ATTRIBUTE_UNUSED;
2085 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2086 dw_fde_ref fde;
2088 current_function_func_begin_label = 0;
2090 #ifdef IA64_UNWIND_INFO
2091 /* ??? current_function_func_begin_label is also used by except.c
2092 for call-site information. We must emit this label if it might
2093 be used. */
2094 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2095 && ! dwarf2out_do_frame ())
2096 return;
2097 #else
2098 if (! dwarf2out_do_frame ())
2099 return;
2100 #endif
2102 current_funcdef_number++;
2103 function_section (current_function_decl);
2104 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2105 current_funcdef_number);
2106 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2107 current_funcdef_number);
2108 current_function_func_begin_label = get_identifier (label);
2110 #ifdef IA64_UNWIND_INFO
2111 /* We can elide the fde allocation if we're not emitting debug info. */
2112 if (! dwarf2out_do_frame ())
2113 return;
2114 #endif
2116 /* Expand the fde table if necessary. */
2117 if (fde_table_in_use == fde_table_allocated)
2119 fde_table_allocated += FDE_TABLE_INCREMENT;
2120 fde_table
2121 = (dw_fde_ref) xrealloc (fde_table,
2122 fde_table_allocated * sizeof (dw_fde_node));
2125 /* Record the FDE associated with this function. */
2126 current_funcdef_fde = fde_table_in_use;
2128 /* Add the new FDE at the end of the fde_table. */
2129 fde = &fde_table[fde_table_in_use++];
2130 fde->dw_fde_begin = xstrdup (label);
2131 fde->dw_fde_current_label = NULL;
2132 fde->dw_fde_end = NULL;
2133 fde->dw_fde_cfi = NULL;
2134 fde->funcdef_number = current_funcdef_number;
2135 fde->nothrow = current_function_nothrow;
2136 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2138 args_size = old_args_size = 0;
2140 /* We only want to output line number information for the genuine dwarf2
2141 prologue case, not the eh frame case. */
2142 #ifdef DWARF2_DEBUGGING_INFO
2143 if (file)
2144 dwarf2out_source_line (line, file);
2145 #endif
2148 /* Output a marker (i.e. a label) for the absolute end of the generated code
2149 for a function definition. This gets called *after* the epilogue code has
2150 been generated. */
2152 void
2153 dwarf2out_end_epilogue ()
2155 dw_fde_ref fde;
2156 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2158 /* Output a label to mark the endpoint of the code generated for this
2159 function. */
2160 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2161 ASM_OUTPUT_LABEL (asm_out_file, label);
2162 fde = &fde_table[fde_table_in_use - 1];
2163 fde->dw_fde_end = xstrdup (label);
2166 void
2167 dwarf2out_frame_init ()
2169 /* Allocate the initial hunk of the fde_table. */
2170 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2171 fde_table_allocated = FDE_TABLE_INCREMENT;
2172 fde_table_in_use = 0;
2174 /* Generate the CFA instructions common to all FDE's. Do it now for the
2175 sake of lookup_cfa. */
2177 #ifdef DWARF2_UNWIND_INFO
2178 /* On entry, the Canonical Frame Address is at SP. */
2179 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2180 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2181 #endif
2184 void
2185 dwarf2out_frame_finish ()
2187 /* Output call frame information. */
2188 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2189 output_call_frame_info (0);
2191 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2192 output_call_frame_info (1);
2195 /* And now, the subset of the debugging information support code necessary
2196 for emitting location expressions. */
2198 typedef struct dw_val_struct *dw_val_ref;
2199 typedef struct die_struct *dw_die_ref;
2200 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2201 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2203 /* Each DIE may have a series of attribute/value pairs. Values
2204 can take on several forms. The forms that are used in this
2205 implementation are listed below. */
2207 typedef enum
2209 dw_val_class_addr,
2210 dw_val_class_offset,
2211 dw_val_class_loc,
2212 dw_val_class_loc_list,
2213 dw_val_class_range_list,
2214 dw_val_class_const,
2215 dw_val_class_unsigned_const,
2216 dw_val_class_long_long,
2217 dw_val_class_float,
2218 dw_val_class_flag,
2219 dw_val_class_die_ref,
2220 dw_val_class_fde_ref,
2221 dw_val_class_lbl_id,
2222 dw_val_class_lbl_offset,
2223 dw_val_class_str
2225 dw_val_class;
2227 /* Describe a double word constant value. */
2228 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2230 typedef struct dw_long_long_struct
2232 unsigned long hi;
2233 unsigned long low;
2235 dw_long_long_const;
2237 /* Describe a floating point constant value. */
2239 typedef struct dw_fp_struct
2241 long *array;
2242 unsigned length;
2244 dw_float_const;
2246 /* The dw_val_node describes an attribute's value, as it is
2247 represented internally. */
2249 typedef struct dw_val_struct
2251 dw_val_class val_class;
2252 union
2254 rtx val_addr;
2255 long unsigned val_offset;
2256 dw_loc_list_ref val_loc_list;
2257 dw_loc_descr_ref val_loc;
2258 long int val_int;
2259 long unsigned val_unsigned;
2260 dw_long_long_const val_long_long;
2261 dw_float_const val_float;
2262 struct
2264 dw_die_ref die;
2265 int external;
2266 } val_die_ref;
2267 unsigned val_fde_index;
2268 struct indirect_string_node *val_str;
2269 char *val_lbl_id;
2270 unsigned char val_flag;
2274 dw_val_node;
2276 /* Locations in memory are described using a sequence of stack machine
2277 operations. */
2279 typedef struct dw_loc_descr_struct
2281 dw_loc_descr_ref dw_loc_next;
2282 enum dwarf_location_atom dw_loc_opc;
2283 dw_val_node dw_loc_oprnd1;
2284 dw_val_node dw_loc_oprnd2;
2285 int dw_loc_addr;
2287 dw_loc_descr_node;
2289 /* Location lists are ranges + location descriptions for that range,
2290 so you can track variables that are in different places over
2291 their entire life. */
2292 typedef struct dw_loc_list_struct
2294 dw_loc_list_ref dw_loc_next;
2295 const char *begin; /* Label for begin address of range */
2296 const char *end; /* Label for end address of range */
2297 char *ll_symbol; /* Label for beginning of location list.
2298 Only on head of list */
2299 const char *section; /* Section this loclist is relative to */
2300 dw_loc_descr_ref expr;
2301 } dw_loc_list_node;
2303 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2304 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2305 unsigned long,
2306 unsigned long));
2307 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2308 dw_loc_descr_ref));
2309 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2310 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2311 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2312 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2314 /* Convert a DWARF stack opcode into its string name. */
2316 static const char *
2317 dwarf_stack_op_name (op)
2318 unsigned op;
2320 switch (op)
2322 case DW_OP_addr:
2323 return "DW_OP_addr";
2324 case DW_OP_deref:
2325 return "DW_OP_deref";
2326 case DW_OP_const1u:
2327 return "DW_OP_const1u";
2328 case DW_OP_const1s:
2329 return "DW_OP_const1s";
2330 case DW_OP_const2u:
2331 return "DW_OP_const2u";
2332 case DW_OP_const2s:
2333 return "DW_OP_const2s";
2334 case DW_OP_const4u:
2335 return "DW_OP_const4u";
2336 case DW_OP_const4s:
2337 return "DW_OP_const4s";
2338 case DW_OP_const8u:
2339 return "DW_OP_const8u";
2340 case DW_OP_const8s:
2341 return "DW_OP_const8s";
2342 case DW_OP_constu:
2343 return "DW_OP_constu";
2344 case DW_OP_consts:
2345 return "DW_OP_consts";
2346 case DW_OP_dup:
2347 return "DW_OP_dup";
2348 case DW_OP_drop:
2349 return "DW_OP_drop";
2350 case DW_OP_over:
2351 return "DW_OP_over";
2352 case DW_OP_pick:
2353 return "DW_OP_pick";
2354 case DW_OP_swap:
2355 return "DW_OP_swap";
2356 case DW_OP_rot:
2357 return "DW_OP_rot";
2358 case DW_OP_xderef:
2359 return "DW_OP_xderef";
2360 case DW_OP_abs:
2361 return "DW_OP_abs";
2362 case DW_OP_and:
2363 return "DW_OP_and";
2364 case DW_OP_div:
2365 return "DW_OP_div";
2366 case DW_OP_minus:
2367 return "DW_OP_minus";
2368 case DW_OP_mod:
2369 return "DW_OP_mod";
2370 case DW_OP_mul:
2371 return "DW_OP_mul";
2372 case DW_OP_neg:
2373 return "DW_OP_neg";
2374 case DW_OP_not:
2375 return "DW_OP_not";
2376 case DW_OP_or:
2377 return "DW_OP_or";
2378 case DW_OP_plus:
2379 return "DW_OP_plus";
2380 case DW_OP_plus_uconst:
2381 return "DW_OP_plus_uconst";
2382 case DW_OP_shl:
2383 return "DW_OP_shl";
2384 case DW_OP_shr:
2385 return "DW_OP_shr";
2386 case DW_OP_shra:
2387 return "DW_OP_shra";
2388 case DW_OP_xor:
2389 return "DW_OP_xor";
2390 case DW_OP_bra:
2391 return "DW_OP_bra";
2392 case DW_OP_eq:
2393 return "DW_OP_eq";
2394 case DW_OP_ge:
2395 return "DW_OP_ge";
2396 case DW_OP_gt:
2397 return "DW_OP_gt";
2398 case DW_OP_le:
2399 return "DW_OP_le";
2400 case DW_OP_lt:
2401 return "DW_OP_lt";
2402 case DW_OP_ne:
2403 return "DW_OP_ne";
2404 case DW_OP_skip:
2405 return "DW_OP_skip";
2406 case DW_OP_lit0:
2407 return "DW_OP_lit0";
2408 case DW_OP_lit1:
2409 return "DW_OP_lit1";
2410 case DW_OP_lit2:
2411 return "DW_OP_lit2";
2412 case DW_OP_lit3:
2413 return "DW_OP_lit3";
2414 case DW_OP_lit4:
2415 return "DW_OP_lit4";
2416 case DW_OP_lit5:
2417 return "DW_OP_lit5";
2418 case DW_OP_lit6:
2419 return "DW_OP_lit6";
2420 case DW_OP_lit7:
2421 return "DW_OP_lit7";
2422 case DW_OP_lit8:
2423 return "DW_OP_lit8";
2424 case DW_OP_lit9:
2425 return "DW_OP_lit9";
2426 case DW_OP_lit10:
2427 return "DW_OP_lit10";
2428 case DW_OP_lit11:
2429 return "DW_OP_lit11";
2430 case DW_OP_lit12:
2431 return "DW_OP_lit12";
2432 case DW_OP_lit13:
2433 return "DW_OP_lit13";
2434 case DW_OP_lit14:
2435 return "DW_OP_lit14";
2436 case DW_OP_lit15:
2437 return "DW_OP_lit15";
2438 case DW_OP_lit16:
2439 return "DW_OP_lit16";
2440 case DW_OP_lit17:
2441 return "DW_OP_lit17";
2442 case DW_OP_lit18:
2443 return "DW_OP_lit18";
2444 case DW_OP_lit19:
2445 return "DW_OP_lit19";
2446 case DW_OP_lit20:
2447 return "DW_OP_lit20";
2448 case DW_OP_lit21:
2449 return "DW_OP_lit21";
2450 case DW_OP_lit22:
2451 return "DW_OP_lit22";
2452 case DW_OP_lit23:
2453 return "DW_OP_lit23";
2454 case DW_OP_lit24:
2455 return "DW_OP_lit24";
2456 case DW_OP_lit25:
2457 return "DW_OP_lit25";
2458 case DW_OP_lit26:
2459 return "DW_OP_lit26";
2460 case DW_OP_lit27:
2461 return "DW_OP_lit27";
2462 case DW_OP_lit28:
2463 return "DW_OP_lit28";
2464 case DW_OP_lit29:
2465 return "DW_OP_lit29";
2466 case DW_OP_lit30:
2467 return "DW_OP_lit30";
2468 case DW_OP_lit31:
2469 return "DW_OP_lit31";
2470 case DW_OP_reg0:
2471 return "DW_OP_reg0";
2472 case DW_OP_reg1:
2473 return "DW_OP_reg1";
2474 case DW_OP_reg2:
2475 return "DW_OP_reg2";
2476 case DW_OP_reg3:
2477 return "DW_OP_reg3";
2478 case DW_OP_reg4:
2479 return "DW_OP_reg4";
2480 case DW_OP_reg5:
2481 return "DW_OP_reg5";
2482 case DW_OP_reg6:
2483 return "DW_OP_reg6";
2484 case DW_OP_reg7:
2485 return "DW_OP_reg7";
2486 case DW_OP_reg8:
2487 return "DW_OP_reg8";
2488 case DW_OP_reg9:
2489 return "DW_OP_reg9";
2490 case DW_OP_reg10:
2491 return "DW_OP_reg10";
2492 case DW_OP_reg11:
2493 return "DW_OP_reg11";
2494 case DW_OP_reg12:
2495 return "DW_OP_reg12";
2496 case DW_OP_reg13:
2497 return "DW_OP_reg13";
2498 case DW_OP_reg14:
2499 return "DW_OP_reg14";
2500 case DW_OP_reg15:
2501 return "DW_OP_reg15";
2502 case DW_OP_reg16:
2503 return "DW_OP_reg16";
2504 case DW_OP_reg17:
2505 return "DW_OP_reg17";
2506 case DW_OP_reg18:
2507 return "DW_OP_reg18";
2508 case DW_OP_reg19:
2509 return "DW_OP_reg19";
2510 case DW_OP_reg20:
2511 return "DW_OP_reg20";
2512 case DW_OP_reg21:
2513 return "DW_OP_reg21";
2514 case DW_OP_reg22:
2515 return "DW_OP_reg22";
2516 case DW_OP_reg23:
2517 return "DW_OP_reg23";
2518 case DW_OP_reg24:
2519 return "DW_OP_reg24";
2520 case DW_OP_reg25:
2521 return "DW_OP_reg25";
2522 case DW_OP_reg26:
2523 return "DW_OP_reg26";
2524 case DW_OP_reg27:
2525 return "DW_OP_reg27";
2526 case DW_OP_reg28:
2527 return "DW_OP_reg28";
2528 case DW_OP_reg29:
2529 return "DW_OP_reg29";
2530 case DW_OP_reg30:
2531 return "DW_OP_reg30";
2532 case DW_OP_reg31:
2533 return "DW_OP_reg31";
2534 case DW_OP_breg0:
2535 return "DW_OP_breg0";
2536 case DW_OP_breg1:
2537 return "DW_OP_breg1";
2538 case DW_OP_breg2:
2539 return "DW_OP_breg2";
2540 case DW_OP_breg3:
2541 return "DW_OP_breg3";
2542 case DW_OP_breg4:
2543 return "DW_OP_breg4";
2544 case DW_OP_breg5:
2545 return "DW_OP_breg5";
2546 case DW_OP_breg6:
2547 return "DW_OP_breg6";
2548 case DW_OP_breg7:
2549 return "DW_OP_breg7";
2550 case DW_OP_breg8:
2551 return "DW_OP_breg8";
2552 case DW_OP_breg9:
2553 return "DW_OP_breg9";
2554 case DW_OP_breg10:
2555 return "DW_OP_breg10";
2556 case DW_OP_breg11:
2557 return "DW_OP_breg11";
2558 case DW_OP_breg12:
2559 return "DW_OP_breg12";
2560 case DW_OP_breg13:
2561 return "DW_OP_breg13";
2562 case DW_OP_breg14:
2563 return "DW_OP_breg14";
2564 case DW_OP_breg15:
2565 return "DW_OP_breg15";
2566 case DW_OP_breg16:
2567 return "DW_OP_breg16";
2568 case DW_OP_breg17:
2569 return "DW_OP_breg17";
2570 case DW_OP_breg18:
2571 return "DW_OP_breg18";
2572 case DW_OP_breg19:
2573 return "DW_OP_breg19";
2574 case DW_OP_breg20:
2575 return "DW_OP_breg20";
2576 case DW_OP_breg21:
2577 return "DW_OP_breg21";
2578 case DW_OP_breg22:
2579 return "DW_OP_breg22";
2580 case DW_OP_breg23:
2581 return "DW_OP_breg23";
2582 case DW_OP_breg24:
2583 return "DW_OP_breg24";
2584 case DW_OP_breg25:
2585 return "DW_OP_breg25";
2586 case DW_OP_breg26:
2587 return "DW_OP_breg26";
2588 case DW_OP_breg27:
2589 return "DW_OP_breg27";
2590 case DW_OP_breg28:
2591 return "DW_OP_breg28";
2592 case DW_OP_breg29:
2593 return "DW_OP_breg29";
2594 case DW_OP_breg30:
2595 return "DW_OP_breg30";
2596 case DW_OP_breg31:
2597 return "DW_OP_breg31";
2598 case DW_OP_regx:
2599 return "DW_OP_regx";
2600 case DW_OP_fbreg:
2601 return "DW_OP_fbreg";
2602 case DW_OP_bregx:
2603 return "DW_OP_bregx";
2604 case DW_OP_piece:
2605 return "DW_OP_piece";
2606 case DW_OP_deref_size:
2607 return "DW_OP_deref_size";
2608 case DW_OP_xderef_size:
2609 return "DW_OP_xderef_size";
2610 case DW_OP_nop:
2611 return "DW_OP_nop";
2612 default:
2613 return "OP_<unknown>";
2617 /* Return a pointer to a newly allocated location description. Location
2618 descriptions are simple expression terms that can be strung
2619 together to form more complicated location (address) descriptions. */
2621 static inline dw_loc_descr_ref
2622 new_loc_descr (op, oprnd1, oprnd2)
2623 enum dwarf_location_atom op;
2624 unsigned long oprnd1;
2625 unsigned long oprnd2;
2627 /* Use xcalloc here so we clear out all of the long_long constant in
2628 the union. */
2629 dw_loc_descr_ref descr
2630 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2632 descr->dw_loc_opc = op;
2633 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2634 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2635 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2636 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2638 return descr;
2642 /* Add a location description term to a location description expression. */
2644 static inline void
2645 add_loc_descr (list_head, descr)
2646 dw_loc_descr_ref *list_head;
2647 dw_loc_descr_ref descr;
2649 dw_loc_descr_ref *d;
2651 /* Find the end of the chain. */
2652 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2655 *d = descr;
2658 /* Return the size of a location descriptor. */
2660 static unsigned long
2661 size_of_loc_descr (loc)
2662 dw_loc_descr_ref loc;
2664 unsigned long size = 1;
2666 switch (loc->dw_loc_opc)
2668 case DW_OP_addr:
2669 size += DWARF2_ADDR_SIZE;
2670 break;
2671 case DW_OP_const1u:
2672 case DW_OP_const1s:
2673 size += 1;
2674 break;
2675 case DW_OP_const2u:
2676 case DW_OP_const2s:
2677 size += 2;
2678 break;
2679 case DW_OP_const4u:
2680 case DW_OP_const4s:
2681 size += 4;
2682 break;
2683 case DW_OP_const8u:
2684 case DW_OP_const8s:
2685 size += 8;
2686 break;
2687 case DW_OP_constu:
2688 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2689 break;
2690 case DW_OP_consts:
2691 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2692 break;
2693 case DW_OP_pick:
2694 size += 1;
2695 break;
2696 case DW_OP_plus_uconst:
2697 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2698 break;
2699 case DW_OP_skip:
2700 case DW_OP_bra:
2701 size += 2;
2702 break;
2703 case DW_OP_breg0:
2704 case DW_OP_breg1:
2705 case DW_OP_breg2:
2706 case DW_OP_breg3:
2707 case DW_OP_breg4:
2708 case DW_OP_breg5:
2709 case DW_OP_breg6:
2710 case DW_OP_breg7:
2711 case DW_OP_breg8:
2712 case DW_OP_breg9:
2713 case DW_OP_breg10:
2714 case DW_OP_breg11:
2715 case DW_OP_breg12:
2716 case DW_OP_breg13:
2717 case DW_OP_breg14:
2718 case DW_OP_breg15:
2719 case DW_OP_breg16:
2720 case DW_OP_breg17:
2721 case DW_OP_breg18:
2722 case DW_OP_breg19:
2723 case DW_OP_breg20:
2724 case DW_OP_breg21:
2725 case DW_OP_breg22:
2726 case DW_OP_breg23:
2727 case DW_OP_breg24:
2728 case DW_OP_breg25:
2729 case DW_OP_breg26:
2730 case DW_OP_breg27:
2731 case DW_OP_breg28:
2732 case DW_OP_breg29:
2733 case DW_OP_breg30:
2734 case DW_OP_breg31:
2735 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2736 break;
2737 case DW_OP_regx:
2738 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2739 break;
2740 case DW_OP_fbreg:
2741 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2742 break;
2743 case DW_OP_bregx:
2744 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2745 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2746 break;
2747 case DW_OP_piece:
2748 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2749 break;
2750 case DW_OP_deref_size:
2751 case DW_OP_xderef_size:
2752 size += 1;
2753 break;
2754 default:
2755 break;
2758 return size;
2761 /* Return the size of a series of location descriptors. */
2763 static unsigned long
2764 size_of_locs (loc)
2765 dw_loc_descr_ref loc;
2767 unsigned long size;
2769 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2771 loc->dw_loc_addr = size;
2772 size += size_of_loc_descr (loc);
2775 return size;
2778 /* Output location description stack opcode's operands (if any). */
2780 static void
2781 output_loc_operands (loc)
2782 dw_loc_descr_ref loc;
2784 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2785 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2787 switch (loc->dw_loc_opc)
2789 #ifdef DWARF2_DEBUGGING_INFO
2790 case DW_OP_addr:
2791 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2792 break;
2793 case DW_OP_const2u:
2794 case DW_OP_const2s:
2795 dw2_asm_output_data (2, val1->v.val_int, NULL);
2796 break;
2797 case DW_OP_const4u:
2798 case DW_OP_const4s:
2799 dw2_asm_output_data (4, val1->v.val_int, NULL);
2800 break;
2801 case DW_OP_const8u:
2802 case DW_OP_const8s:
2803 if (HOST_BITS_PER_LONG < 64)
2804 abort ();
2805 dw2_asm_output_data (8, val1->v.val_int, NULL);
2806 break;
2807 case DW_OP_skip:
2808 case DW_OP_bra:
2810 int offset;
2812 if (val1->val_class == dw_val_class_loc)
2813 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2814 else
2815 abort ();
2817 dw2_asm_output_data (2, offset, NULL);
2819 break;
2820 #else
2821 case DW_OP_addr:
2822 case DW_OP_const2u:
2823 case DW_OP_const2s:
2824 case DW_OP_const4u:
2825 case DW_OP_const4s:
2826 case DW_OP_const8u:
2827 case DW_OP_const8s:
2828 case DW_OP_skip:
2829 case DW_OP_bra:
2830 /* We currently don't make any attempt to make sure these are
2831 aligned properly like we do for the main unwind info, so
2832 don't support emitting things larger than a byte if we're
2833 only doing unwinding. */
2834 abort ();
2835 #endif
2836 case DW_OP_const1u:
2837 case DW_OP_const1s:
2838 dw2_asm_output_data (1, val1->v.val_int, NULL);
2839 break;
2840 case DW_OP_constu:
2841 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2842 break;
2843 case DW_OP_consts:
2844 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2845 break;
2846 case DW_OP_pick:
2847 dw2_asm_output_data (1, val1->v.val_int, NULL);
2848 break;
2849 case DW_OP_plus_uconst:
2850 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2851 break;
2852 case DW_OP_breg0:
2853 case DW_OP_breg1:
2854 case DW_OP_breg2:
2855 case DW_OP_breg3:
2856 case DW_OP_breg4:
2857 case DW_OP_breg5:
2858 case DW_OP_breg6:
2859 case DW_OP_breg7:
2860 case DW_OP_breg8:
2861 case DW_OP_breg9:
2862 case DW_OP_breg10:
2863 case DW_OP_breg11:
2864 case DW_OP_breg12:
2865 case DW_OP_breg13:
2866 case DW_OP_breg14:
2867 case DW_OP_breg15:
2868 case DW_OP_breg16:
2869 case DW_OP_breg17:
2870 case DW_OP_breg18:
2871 case DW_OP_breg19:
2872 case DW_OP_breg20:
2873 case DW_OP_breg21:
2874 case DW_OP_breg22:
2875 case DW_OP_breg23:
2876 case DW_OP_breg24:
2877 case DW_OP_breg25:
2878 case DW_OP_breg26:
2879 case DW_OP_breg27:
2880 case DW_OP_breg28:
2881 case DW_OP_breg29:
2882 case DW_OP_breg30:
2883 case DW_OP_breg31:
2884 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2885 break;
2886 case DW_OP_regx:
2887 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2888 break;
2889 case DW_OP_fbreg:
2890 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2891 break;
2892 case DW_OP_bregx:
2893 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2894 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2895 break;
2896 case DW_OP_piece:
2897 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2898 break;
2899 case DW_OP_deref_size:
2900 case DW_OP_xderef_size:
2901 dw2_asm_output_data (1, val1->v.val_int, NULL);
2902 break;
2903 default:
2904 /* Other codes have no operands. */
2905 break;
2909 /* Output a sequence of location operations. */
2911 static void
2912 output_loc_sequence (loc)
2913 dw_loc_descr_ref loc;
2915 for (; loc != NULL; loc = loc->dw_loc_next)
2917 /* Output the opcode. */
2918 dw2_asm_output_data (1, loc->dw_loc_opc,
2919 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2921 /* Output the operand(s) (if any). */
2922 output_loc_operands (loc);
2926 /* This routine will generate the correct assembly data for a location
2927 description based on a cfi entry with a complex address. */
2929 static void
2930 output_cfa_loc (cfi)
2931 dw_cfi_ref cfi;
2933 dw_loc_descr_ref loc;
2934 unsigned long size;
2936 /* Output the size of the block. */
2937 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2938 size = size_of_locs (loc);
2939 dw2_asm_output_data_uleb128 (size, NULL);
2941 /* Now output the operations themselves. */
2942 output_loc_sequence (loc);
2945 /* This function builds a dwarf location descriptor sequence from
2946 a dw_cfa_location. */
2948 static struct dw_loc_descr_struct *
2949 build_cfa_loc (cfa)
2950 dw_cfa_location *cfa;
2952 struct dw_loc_descr_struct *head, *tmp;
2954 if (cfa->indirect == 0)
2955 abort ();
2957 if (cfa->base_offset)
2959 if (cfa->reg <= 31)
2960 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2961 else
2962 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2964 else if (cfa->reg <= 31)
2965 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2966 else
2967 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2969 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2970 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2971 add_loc_descr (&head, tmp);
2972 if (cfa->offset != 0)
2974 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2975 add_loc_descr (&head, tmp);
2978 return head;
2981 /* This function fills in aa dw_cfa_location structure from a dwarf location
2982 descriptor sequence. */
2984 static void
2985 get_cfa_from_loc_descr (cfa, loc)
2986 dw_cfa_location *cfa;
2987 struct dw_loc_descr_struct *loc;
2989 struct dw_loc_descr_struct *ptr;
2990 cfa->offset = 0;
2991 cfa->base_offset = 0;
2992 cfa->indirect = 0;
2993 cfa->reg = -1;
2995 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2997 enum dwarf_location_atom op = ptr->dw_loc_opc;
2999 switch (op)
3001 case DW_OP_reg0:
3002 case DW_OP_reg1:
3003 case DW_OP_reg2:
3004 case DW_OP_reg3:
3005 case DW_OP_reg4:
3006 case DW_OP_reg5:
3007 case DW_OP_reg6:
3008 case DW_OP_reg7:
3009 case DW_OP_reg8:
3010 case DW_OP_reg9:
3011 case DW_OP_reg10:
3012 case DW_OP_reg11:
3013 case DW_OP_reg12:
3014 case DW_OP_reg13:
3015 case DW_OP_reg14:
3016 case DW_OP_reg15:
3017 case DW_OP_reg16:
3018 case DW_OP_reg17:
3019 case DW_OP_reg18:
3020 case DW_OP_reg19:
3021 case DW_OP_reg20:
3022 case DW_OP_reg21:
3023 case DW_OP_reg22:
3024 case DW_OP_reg23:
3025 case DW_OP_reg24:
3026 case DW_OP_reg25:
3027 case DW_OP_reg26:
3028 case DW_OP_reg27:
3029 case DW_OP_reg28:
3030 case DW_OP_reg29:
3031 case DW_OP_reg30:
3032 case DW_OP_reg31:
3033 cfa->reg = op - DW_OP_reg0;
3034 break;
3035 case DW_OP_regx:
3036 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3037 break;
3038 case DW_OP_breg0:
3039 case DW_OP_breg1:
3040 case DW_OP_breg2:
3041 case DW_OP_breg3:
3042 case DW_OP_breg4:
3043 case DW_OP_breg5:
3044 case DW_OP_breg6:
3045 case DW_OP_breg7:
3046 case DW_OP_breg8:
3047 case DW_OP_breg9:
3048 case DW_OP_breg10:
3049 case DW_OP_breg11:
3050 case DW_OP_breg12:
3051 case DW_OP_breg13:
3052 case DW_OP_breg14:
3053 case DW_OP_breg15:
3054 case DW_OP_breg16:
3055 case DW_OP_breg17:
3056 case DW_OP_breg18:
3057 case DW_OP_breg19:
3058 case DW_OP_breg20:
3059 case DW_OP_breg21:
3060 case DW_OP_breg22:
3061 case DW_OP_breg23:
3062 case DW_OP_breg24:
3063 case DW_OP_breg25:
3064 case DW_OP_breg26:
3065 case DW_OP_breg27:
3066 case DW_OP_breg28:
3067 case DW_OP_breg29:
3068 case DW_OP_breg30:
3069 case DW_OP_breg31:
3070 cfa->reg = op - DW_OP_breg0;
3071 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3072 break;
3073 case DW_OP_bregx:
3074 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3075 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3076 break;
3077 case DW_OP_deref:
3078 cfa->indirect = 1;
3079 break;
3080 case DW_OP_plus_uconst:
3081 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3082 break;
3083 default:
3084 internal_error ("DW_LOC_OP %s not implemented\n",
3085 dwarf_stack_op_name (ptr->dw_loc_opc));
3089 #endif /* .debug_frame support */
3091 /* And now, the support for symbolic debugging information. */
3092 #ifdef DWARF2_DEBUGGING_INFO
3094 /* .debug_str support. */
3095 static hashnode indirect_string_alloc PARAMS ((hash_table *));
3096 static int output_indirect_string PARAMS ((struct cpp_reader *,
3097 hashnode, const PTR));
3100 static void dwarf2out_init PARAMS ((const char *));
3101 static void dwarf2out_finish PARAMS ((const char *));
3102 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3103 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3104 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3105 static void dwarf2out_end_source_file PARAMS ((unsigned));
3106 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3107 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3108 static bool dwarf2out_ignore_block PARAMS ((tree));
3109 static void dwarf2out_global_decl PARAMS ((tree));
3110 static void dwarf2out_abstract_function PARAMS ((tree));
3112 /* The debug hooks structure. */
3114 const struct gcc_debug_hooks dwarf2_debug_hooks =
3116 dwarf2out_init,
3117 dwarf2out_finish,
3118 dwarf2out_define,
3119 dwarf2out_undef,
3120 dwarf2out_start_source_file,
3121 dwarf2out_end_source_file,
3122 dwarf2out_begin_block,
3123 dwarf2out_end_block,
3124 dwarf2out_ignore_block,
3125 dwarf2out_source_line,
3126 dwarf2out_begin_prologue,
3127 debug_nothing_int, /* end_prologue */
3128 dwarf2out_end_epilogue,
3129 debug_nothing_tree, /* begin_function */
3130 debug_nothing_int, /* end_function */
3131 dwarf2out_decl, /* function_decl */
3132 dwarf2out_global_decl,
3133 debug_nothing_tree, /* deferred_inline_function */
3134 /* The DWARF 2 backend tries to reduce debugging bloat by not
3135 emitting the abstract description of inline functions until
3136 something tries to reference them. */
3137 dwarf2out_abstract_function, /* outlining_inline_function */
3138 debug_nothing_rtx /* label */
3141 /* NOTE: In the comments in this file, many references are made to
3142 "Debugging Information Entries". This term is abbreviated as `DIE'
3143 throughout the remainder of this file. */
3145 /* An internal representation of the DWARF output is built, and then
3146 walked to generate the DWARF debugging info. The walk of the internal
3147 representation is done after the entire program has been compiled.
3148 The types below are used to describe the internal representation. */
3150 /* Various DIE's use offsets relative to the beginning of the
3151 .debug_info section to refer to each other. */
3153 typedef long int dw_offset;
3155 /* Define typedefs here to avoid circular dependencies. */
3157 typedef struct dw_attr_struct *dw_attr_ref;
3158 typedef struct dw_line_info_struct *dw_line_info_ref;
3159 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3160 typedef struct pubname_struct *pubname_ref;
3161 typedef struct dw_ranges_struct *dw_ranges_ref;
3163 /* Each entry in the line_info_table maintains the file and
3164 line number associated with the label generated for that
3165 entry. The label gives the PC value associated with
3166 the line number entry. */
3168 typedef struct dw_line_info_struct
3170 unsigned long dw_file_num;
3171 unsigned long dw_line_num;
3173 dw_line_info_entry;
3175 /* Line information for functions in separate sections; each one gets its
3176 own sequence. */
3177 typedef struct dw_separate_line_info_struct
3179 unsigned long dw_file_num;
3180 unsigned long dw_line_num;
3181 unsigned long function;
3183 dw_separate_line_info_entry;
3185 /* Each DIE attribute has a field specifying the attribute kind,
3186 a link to the next attribute in the chain, and an attribute value.
3187 Attributes are typically linked below the DIE they modify. */
3189 typedef struct dw_attr_struct
3191 enum dwarf_attribute dw_attr;
3192 dw_attr_ref dw_attr_next;
3193 dw_val_node dw_attr_val;
3195 dw_attr_node;
3197 /* The Debugging Information Entry (DIE) structure */
3199 typedef struct die_struct
3201 enum dwarf_tag die_tag;
3202 char *die_symbol;
3203 dw_attr_ref die_attr;
3204 dw_die_ref die_parent;
3205 dw_die_ref die_child;
3206 dw_die_ref die_sib;
3207 dw_offset die_offset;
3208 unsigned long die_abbrev;
3209 int die_mark;
3211 die_node;
3213 /* The pubname structure */
3215 typedef struct pubname_struct
3217 dw_die_ref die;
3218 char *name;
3220 pubname_entry;
3222 struct dw_ranges_struct
3224 int block_num;
3227 /* The limbo die list structure. */
3228 typedef struct limbo_die_struct
3230 dw_die_ref die;
3231 tree created_for;
3232 struct limbo_die_struct *next;
3234 limbo_die_node;
3236 /* How to start an assembler comment. */
3237 #ifndef ASM_COMMENT_START
3238 #define ASM_COMMENT_START ";#"
3239 #endif
3241 /* Define a macro which returns non-zero for a TYPE_DECL which was
3242 implicitly generated for a tagged type.
3244 Note that unlike the gcc front end (which generates a NULL named
3245 TYPE_DECL node for each complete tagged type, each array type, and
3246 each function type node created) the g++ front end generates a
3247 _named_ TYPE_DECL node for each tagged type node created.
3248 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3249 generate a DW_TAG_typedef DIE for them. */
3251 #define TYPE_DECL_IS_STUB(decl) \
3252 (DECL_NAME (decl) == NULL_TREE \
3253 || (DECL_ARTIFICIAL (decl) \
3254 && is_tagged_type (TREE_TYPE (decl)) \
3255 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3256 /* This is necessary for stub decls that \
3257 appear in nested inline functions. */ \
3258 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3259 && (decl_ultimate_origin (decl) \
3260 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3262 /* Information concerning the compilation unit's programming
3263 language, and compiler version. */
3265 /* Fixed size portion of the DWARF compilation unit header. */
3266 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3268 /* Fixed size portion of debugging line information prolog. */
3269 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3271 /* Fixed size portion of public names info. */
3272 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3274 /* Fixed size portion of the address range info. */
3275 #define DWARF_ARANGES_HEADER_SIZE \
3276 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3277 - DWARF_OFFSET_SIZE)
3279 /* Size of padding portion in the address range info. It must be
3280 aligned to twice the pointer size. */
3281 #define DWARF_ARANGES_PAD_SIZE \
3282 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3283 - (2 * DWARF_OFFSET_SIZE + 4))
3285 /* Use assembler line directives if available. */
3286 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3287 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3288 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3289 #else
3290 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3291 #endif
3292 #endif
3294 /* Minimum line offset in a special line info. opcode.
3295 This value was chosen to give a reasonable range of values. */
3296 #define DWARF_LINE_BASE -10
3298 /* First special line opcode - leave room for the standard opcodes. */
3299 #define DWARF_LINE_OPCODE_BASE 10
3301 /* Range of line offsets in a special line info. opcode. */
3302 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3304 /* Flag that indicates the initial value of the is_stmt_start flag.
3305 In the present implementation, we do not mark any lines as
3306 the beginning of a source statement, because that information
3307 is not made available by the GCC front-end. */
3308 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3310 /* This location is used by calc_die_sizes() to keep track
3311 the offset of each DIE within the .debug_info section. */
3312 static unsigned long next_die_offset;
3314 /* Record the root of the DIE's built for the current compilation unit. */
3315 static dw_die_ref comp_unit_die;
3317 /* A list of DIEs with a NULL parent waiting to be relocated. */
3318 static limbo_die_node *limbo_die_list = 0;
3320 /* Structure used by lookup_filename to manage sets of filenames. */
3321 struct file_table
3323 char **table;
3324 unsigned allocated;
3325 unsigned in_use;
3326 unsigned last_lookup_index;
3329 /* Size (in elements) of increments by which we may expand the filename
3330 table. */
3331 #define FILE_TABLE_INCREMENT 64
3333 /* Filenames referenced by this compilation unit. */
3334 static struct file_table file_table;
3336 /* Local pointer to the name of the main input file. Initialized in
3337 dwarf2out_init. */
3338 static const char *primary_filename;
3340 /* A pointer to the base of a table of references to DIE's that describe
3341 declarations. The table is indexed by DECL_UID() which is a unique
3342 number identifying each decl. */
3343 static dw_die_ref *decl_die_table;
3345 /* Number of elements currently allocated for the decl_die_table. */
3346 static unsigned decl_die_table_allocated;
3348 /* Number of elements in decl_die_table currently in use. */
3349 static unsigned decl_die_table_in_use;
3351 /* Size (in elements) of increments by which we may expand the
3352 decl_die_table. */
3353 #define DECL_DIE_TABLE_INCREMENT 256
3355 /* A pointer to the base of a table of references to declaration
3356 scopes. This table is a display which tracks the nesting
3357 of declaration scopes at the current scope and containing
3358 scopes. This table is used to find the proper place to
3359 define type declaration DIE's. */
3360 varray_type decl_scope_table;
3362 /* A pointer to the base of a list of references to DIE's that
3363 are uniquely identified by their tag, presence/absence of
3364 children DIE's, and list of attribute/value pairs. */
3365 static dw_die_ref *abbrev_die_table;
3367 /* Number of elements currently allocated for abbrev_die_table. */
3368 static unsigned abbrev_die_table_allocated;
3370 /* Number of elements in type_die_table currently in use. */
3371 static unsigned abbrev_die_table_in_use;
3373 /* Size (in elements) of increments by which we may expand the
3374 abbrev_die_table. */
3375 #define ABBREV_DIE_TABLE_INCREMENT 256
3377 /* A pointer to the base of a table that contains line information
3378 for each source code line in .text in the compilation unit. */
3379 static dw_line_info_ref line_info_table;
3381 /* Number of elements currently allocated for line_info_table. */
3382 static unsigned line_info_table_allocated;
3384 /* Number of elements in separate_line_info_table currently in use. */
3385 static unsigned separate_line_info_table_in_use;
3387 /* A pointer to the base of a table that contains line information
3388 for each source code line outside of .text in the compilation unit. */
3389 static dw_separate_line_info_ref separate_line_info_table;
3391 /* Number of elements currently allocated for separate_line_info_table. */
3392 static unsigned separate_line_info_table_allocated;
3394 /* Number of elements in line_info_table currently in use. */
3395 static unsigned line_info_table_in_use;
3397 /* Size (in elements) of increments by which we may expand the
3398 line_info_table. */
3399 #define LINE_INFO_TABLE_INCREMENT 1024
3401 /* A pointer to the base of a table that contains a list of publicly
3402 accessible names. */
3403 static pubname_ref pubname_table;
3405 /* Number of elements currently allocated for pubname_table. */
3406 static unsigned pubname_table_allocated;
3408 /* Number of elements in pubname_table currently in use. */
3409 static unsigned pubname_table_in_use;
3411 /* Size (in elements) of increments by which we may expand the
3412 pubname_table. */
3413 #define PUBNAME_TABLE_INCREMENT 64
3415 /* Array of dies for which we should generate .debug_arange info. */
3416 static dw_die_ref *arange_table;
3418 /* Number of elements currently allocated for arange_table. */
3419 static unsigned arange_table_allocated;
3421 /* Number of elements in arange_table currently in use. */
3422 static unsigned arange_table_in_use;
3424 /* Size (in elements) of increments by which we may expand the
3425 arange_table. */
3426 #define ARANGE_TABLE_INCREMENT 64
3428 /* Array of dies for which we should generate .debug_ranges info. */
3429 static dw_ranges_ref ranges_table;
3431 /* Number of elements currently allocated for ranges_table. */
3432 static unsigned ranges_table_allocated;
3434 /* Number of elements in ranges_table currently in use. */
3435 static unsigned ranges_table_in_use;
3437 /* Size (in elements) of increments by which we may expand the
3438 ranges_table. */
3439 #define RANGES_TABLE_INCREMENT 64
3441 /* Whether we have location lists that need outputting */
3442 static unsigned have_location_lists;
3444 /* A pointer to the base of a list of incomplete types which might be
3445 completed at some later time. incomplete_types_list needs to be a VARRAY
3446 because we want to tell the garbage collector about it. */
3447 varray_type incomplete_types;
3449 /* Record whether the function being analyzed contains inlined functions. */
3450 static int current_function_has_inlines;
3451 #if 0 && defined (MIPS_DEBUGGING_INFO)
3452 static int comp_unit_has_inlines;
3453 #endif
3455 /* Array of RTXes referenced by the debugging information, which therefore
3456 must be kept around forever. This is a GC root. */
3457 static varray_type used_rtx_varray;
3459 /* Forward declarations for functions defined in this file. */
3461 static int is_pseudo_reg PARAMS ((rtx));
3462 static tree type_main_variant PARAMS ((tree));
3463 static int is_tagged_type PARAMS ((tree));
3464 static const char *dwarf_tag_name PARAMS ((unsigned));
3465 static const char *dwarf_attr_name PARAMS ((unsigned));
3466 static const char *dwarf_form_name PARAMS ((unsigned));
3467 #if 0
3468 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3469 #endif
3470 static tree decl_ultimate_origin PARAMS ((tree));
3471 static tree block_ultimate_origin PARAMS ((tree));
3472 static tree decl_class_context PARAMS ((tree));
3473 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3474 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
3475 static void add_AT_flag PARAMS ((dw_die_ref,
3476 enum dwarf_attribute,
3477 unsigned));
3478 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3479 static void add_AT_int PARAMS ((dw_die_ref,
3480 enum dwarf_attribute, long));
3481 static inline long int AT_int PARAMS ((dw_attr_ref));
3482 static void add_AT_unsigned PARAMS ((dw_die_ref,
3483 enum dwarf_attribute,
3484 unsigned long));
3485 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
3486 static void add_AT_long_long PARAMS ((dw_die_ref,
3487 enum dwarf_attribute,
3488 unsigned long,
3489 unsigned long));
3490 static void add_AT_float PARAMS ((dw_die_ref,
3491 enum dwarf_attribute,
3492 unsigned, long *));
3493 static void add_AT_string PARAMS ((dw_die_ref,
3494 enum dwarf_attribute,
3495 const char *));
3496 static inline const char *AT_string PARAMS ((dw_attr_ref));
3497 static int AT_string_form PARAMS ((dw_attr_ref));
3498 static void add_AT_die_ref PARAMS ((dw_die_ref,
3499 enum dwarf_attribute,
3500 dw_die_ref));
3501 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
3502 static inline int AT_ref_external PARAMS ((dw_attr_ref));
3503 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
3504 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3505 enum dwarf_attribute,
3506 unsigned));
3507 static void add_AT_loc PARAMS ((dw_die_ref,
3508 enum dwarf_attribute,
3509 dw_loc_descr_ref));
3510 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
3511 static void add_AT_loc_list PARAMS ((dw_die_ref,
3512 enum dwarf_attribute,
3513 dw_loc_list_ref));
3514 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
3515 static void add_AT_addr PARAMS ((dw_die_ref,
3516 enum dwarf_attribute,
3517 rtx));
3518 static inline rtx AT_addr PARAMS ((dw_attr_ref));
3519 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3520 enum dwarf_attribute,
3521 const char *));
3522 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3523 enum dwarf_attribute,
3524 const char *));
3525 static void add_AT_offset PARAMS ((dw_die_ref,
3526 enum dwarf_attribute,
3527 unsigned long));
3528 static void add_AT_range_list PARAMS ((dw_die_ref,
3529 enum dwarf_attribute,
3530 unsigned long));
3531 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
3532 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3533 enum dwarf_attribute));
3534 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3535 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3536 static const char *get_AT_string PARAMS ((dw_die_ref,
3537 enum dwarf_attribute));
3538 static int get_AT_flag PARAMS ((dw_die_ref,
3539 enum dwarf_attribute));
3540 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3541 enum dwarf_attribute));
3542 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3543 enum dwarf_attribute));
3544 static int is_c_family PARAMS ((void));
3545 static int is_cxx PARAMS ((void));
3546 static int is_java PARAMS ((void));
3547 static int is_fortran PARAMS ((void));
3548 static void remove_AT PARAMS ((dw_die_ref,
3549 enum dwarf_attribute));
3550 static inline void free_die PARAMS ((dw_die_ref));
3551 static void remove_children PARAMS ((dw_die_ref));
3552 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3553 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref,
3554 tree));
3555 static dw_die_ref lookup_type_die PARAMS ((tree));
3556 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3557 static dw_die_ref lookup_decl_die PARAMS ((tree));
3558 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3559 static void print_spaces PARAMS ((FILE *));
3560 static void print_die PARAMS ((dw_die_ref, FILE *));
3561 static void print_dwarf_line_table PARAMS ((FILE *));
3562 static void reverse_die_lists PARAMS ((dw_die_ref));
3563 static void reverse_all_dies PARAMS ((dw_die_ref));
3564 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3565 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3566 static void loc_checksum PARAMS ((dw_loc_descr_ref,
3567 struct md5_ctx *));
3568 static void attr_checksum PARAMS ((dw_attr_ref,
3569 struct md5_ctx *));
3570 static void die_checksum PARAMS ((dw_die_ref,
3571 struct md5_ctx *));
3572 static void compute_section_prefix PARAMS ((dw_die_ref));
3573 static int is_type_die PARAMS ((dw_die_ref));
3574 static int is_comdat_die PARAMS ((dw_die_ref));
3575 static int is_symbol_die PARAMS ((dw_die_ref));
3576 static void assign_symbol_names PARAMS ((dw_die_ref));
3577 static void break_out_includes PARAMS ((dw_die_ref));
3578 static void add_sibling_attributes PARAMS ((dw_die_ref));
3579 static void build_abbrev_table PARAMS ((dw_die_ref));
3580 static void output_location_lists PARAMS ((dw_die_ref));
3581 static int constant_size PARAMS ((long unsigned));
3582 static unsigned long size_of_die PARAMS ((dw_die_ref));
3583 static void calc_die_sizes PARAMS ((dw_die_ref));
3584 static void mark_dies PARAMS ((dw_die_ref));
3585 static void unmark_dies PARAMS ((dw_die_ref));
3586 static unsigned long size_of_pubnames PARAMS ((void));
3587 static unsigned long size_of_aranges PARAMS ((void));
3588 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3589 static void output_value_format PARAMS ((dw_attr_ref));
3590 static void output_abbrev_section PARAMS ((void));
3591 static void output_die_symbol PARAMS ((dw_die_ref));
3592 static void output_die PARAMS ((dw_die_ref));
3593 static void output_compilation_unit_header PARAMS ((void));
3594 static void output_comp_unit PARAMS ((dw_die_ref));
3595 static const char *dwarf2_name PARAMS ((tree, int));
3596 static void add_pubname PARAMS ((tree, dw_die_ref));
3597 static void output_pubnames PARAMS ((void));
3598 static void add_arange PARAMS ((tree, dw_die_ref));
3599 static void output_aranges PARAMS ((void));
3600 static unsigned int add_ranges PARAMS ((tree));
3601 static void output_ranges PARAMS ((void));
3602 static void output_line_info PARAMS ((void));
3603 static void output_file_names PARAMS ((void));
3604 static dw_die_ref base_type_die PARAMS ((tree));
3605 static tree root_type PARAMS ((tree));
3606 static int is_base_type PARAMS ((tree));
3607 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3608 static int type_is_enum PARAMS ((tree));
3609 static unsigned int reg_number PARAMS ((rtx));
3610 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3611 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3612 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3613 static int is_based_loc PARAMS ((rtx));
3614 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3615 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3616 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3617 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3618 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3619 static tree field_type PARAMS ((tree));
3620 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3621 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3622 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3623 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3624 static void add_AT_location_description PARAMS ((dw_die_ref,
3625 enum dwarf_attribute, rtx));
3626 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3627 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3628 static rtx rtl_for_decl_location PARAMS ((tree));
3629 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3630 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3631 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3632 static void add_bound_info PARAMS ((dw_die_ref,
3633 enum dwarf_attribute, tree));
3634 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3635 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3636 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3637 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3638 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3639 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3640 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3641 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3642 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3643 static void push_decl_scope PARAMS ((tree));
3644 static void pop_decl_scope PARAMS ((void));
3645 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3646 static inline int local_scope_p PARAMS ((dw_die_ref));
3647 static inline int class_scope_p PARAMS ((dw_die_ref));
3648 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3649 dw_die_ref));
3650 static const char *type_tag PARAMS ((tree));
3651 static tree member_declared_type PARAMS ((tree));
3652 #if 0
3653 static const char *decl_start_label PARAMS ((tree));
3654 #endif
3655 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3656 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3657 #if 0
3658 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3659 #endif
3660 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3661 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3662 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3663 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3664 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3665 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3666 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3667 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3668 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3669 static void gen_label_die PARAMS ((tree, dw_die_ref));
3670 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3671 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3672 static void gen_field_die PARAMS ((tree, dw_die_ref));
3673 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3674 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3675 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3676 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3677 static void gen_member_die PARAMS ((tree, dw_die_ref));
3678 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3679 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3680 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3681 static void gen_type_die PARAMS ((tree, dw_die_ref));
3682 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3683 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3684 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3685 static int is_redundant_typedef PARAMS ((tree));
3686 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3687 static unsigned lookup_filename PARAMS ((const char *));
3688 static void init_file_table PARAMS ((void));
3689 static void retry_incomplete_types PARAMS ((void));
3690 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3691 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3692 static int file_info_cmp PARAMS ((const void *, const void *));
3693 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3694 const char *, const char *,
3695 const char *, unsigned));
3696 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3697 dw_loc_descr_ref,
3698 const char *, const char *, const char *));
3699 static void output_loc_list PARAMS ((dw_loc_list_ref));
3700 static char *gen_internal_sym PARAMS ((const char *));
3701 static void mark_limbo_die_list PARAMS ((void *));
3703 /* Section names used to hold DWARF debugging information. */
3704 #ifndef DEBUG_INFO_SECTION
3705 #define DEBUG_INFO_SECTION ".debug_info"
3706 #endif
3707 #ifndef DEBUG_ABBREV_SECTION
3708 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3709 #endif
3710 #ifndef DEBUG_ARANGES_SECTION
3711 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3712 #endif
3713 #ifndef DEBUG_MACINFO_SECTION
3714 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3715 #endif
3716 #ifndef DEBUG_LINE_SECTION
3717 #define DEBUG_LINE_SECTION ".debug_line"
3718 #endif
3719 #ifndef DEBUG_LOC_SECTION
3720 #define DEBUG_LOC_SECTION ".debug_loc"
3721 #endif
3722 #ifndef DEBUG_PUBNAMES_SECTION
3723 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3724 #endif
3725 #ifndef DEBUG_STR_SECTION
3726 #define DEBUG_STR_SECTION ".debug_str"
3727 #endif
3728 #ifndef DEBUG_RANGES_SECTION
3729 #define DEBUG_RANGES_SECTION ".debug_ranges"
3730 #endif
3732 /* Standard ELF section names for compiled code and data. */
3733 #ifndef TEXT_SECTION_NAME
3734 #define TEXT_SECTION_NAME ".text"
3735 #endif
3737 /* Section flags for .debug_str section. */
3738 #ifdef HAVE_GAS_SHF_MERGE
3739 #define DEBUG_STR_SECTION_FLAGS \
3740 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3741 #else
3742 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3743 #endif
3745 /* Labels we insert at beginning sections we can reference instead of
3746 the section names themselves. */
3748 #ifndef TEXT_SECTION_LABEL
3749 #define TEXT_SECTION_LABEL "Ltext"
3750 #endif
3751 #ifndef DEBUG_LINE_SECTION_LABEL
3752 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3753 #endif
3754 #ifndef DEBUG_INFO_SECTION_LABEL
3755 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3756 #endif
3757 #ifndef DEBUG_ABBREV_SECTION_LABEL
3758 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3759 #endif
3760 #ifndef DEBUG_LOC_SECTION_LABEL
3761 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3762 #endif
3763 #ifndef DEBUG_RANGES_SECTION_LABEL
3764 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3765 #endif
3766 #ifndef DEBUG_MACINFO_SECTION_LABEL
3767 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3768 #endif
3770 /* Definitions of defaults for formats and names of various special
3771 (artificial) labels which may be generated within this file (when the -g
3772 options is used and DWARF_DEBUGGING_INFO is in effect.
3773 If necessary, these may be overridden from within the tm.h file, but
3774 typically, overriding these defaults is unnecessary. */
3776 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3777 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3778 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3779 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3780 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3781 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3782 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3783 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3785 #ifndef TEXT_END_LABEL
3786 #define TEXT_END_LABEL "Letext"
3787 #endif
3788 #ifndef DATA_END_LABEL
3789 #define DATA_END_LABEL "Ledata"
3790 #endif
3791 #ifndef BSS_END_LABEL
3792 #define BSS_END_LABEL "Lebss"
3793 #endif
3794 #ifndef BLOCK_BEGIN_LABEL
3795 #define BLOCK_BEGIN_LABEL "LBB"
3796 #endif
3797 #ifndef BLOCK_END_LABEL
3798 #define BLOCK_END_LABEL "LBE"
3799 #endif
3800 #ifndef BODY_BEGIN_LABEL
3801 #define BODY_BEGIN_LABEL "Lbb"
3802 #endif
3803 #ifndef BODY_END_LABEL
3804 #define BODY_END_LABEL "Lbe"
3805 #endif
3806 #ifndef LINE_CODE_LABEL
3807 #define LINE_CODE_LABEL "LM"
3808 #endif
3809 #ifndef SEPARATE_LINE_CODE_LABEL
3810 #define SEPARATE_LINE_CODE_LABEL "LSM"
3811 #endif
3813 /* We allow a language front-end to designate a function that is to be
3814 called to "demangle" any name before it it put into a DIE. */
3816 static const char *(*demangle_name_func) PARAMS ((const char *));
3818 void
3819 dwarf2out_set_demangle_name_func (func)
3820 const char *(*func) PARAMS ((const char *));
3822 demangle_name_func = func;
3825 /* Test if rtl node points to a pseudo register. */
3827 static inline int
3828 is_pseudo_reg (rtl)
3829 rtx rtl;
3831 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3832 || (GET_CODE (rtl) == SUBREG
3833 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3836 /* Return a reference to a type, with its const and volatile qualifiers
3837 removed. */
3839 static inline tree
3840 type_main_variant (type)
3841 tree type;
3843 type = TYPE_MAIN_VARIANT (type);
3845 /* ??? There really should be only one main variant among any group of
3846 variants of a given type (and all of the MAIN_VARIANT values for all
3847 members of the group should point to that one type) but sometimes the C
3848 front-end messes this up for array types, so we work around that bug
3849 here. */
3850 if (TREE_CODE (type) == ARRAY_TYPE)
3851 while (type != TYPE_MAIN_VARIANT (type))
3852 type = TYPE_MAIN_VARIANT (type);
3854 return type;
3857 /* Return non-zero if the given type node represents a tagged type. */
3859 static inline int
3860 is_tagged_type (type)
3861 tree type;
3863 enum tree_code code = TREE_CODE (type);
3865 return (code == RECORD_TYPE || code == UNION_TYPE
3866 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3869 /* Convert a DIE tag into its string name. */
3871 static const char *
3872 dwarf_tag_name (tag)
3873 unsigned tag;
3875 switch (tag)
3877 case DW_TAG_padding:
3878 return "DW_TAG_padding";
3879 case DW_TAG_array_type:
3880 return "DW_TAG_array_type";
3881 case DW_TAG_class_type:
3882 return "DW_TAG_class_type";
3883 case DW_TAG_entry_point:
3884 return "DW_TAG_entry_point";
3885 case DW_TAG_enumeration_type:
3886 return "DW_TAG_enumeration_type";
3887 case DW_TAG_formal_parameter:
3888 return "DW_TAG_formal_parameter";
3889 case DW_TAG_imported_declaration:
3890 return "DW_TAG_imported_declaration";
3891 case DW_TAG_label:
3892 return "DW_TAG_label";
3893 case DW_TAG_lexical_block:
3894 return "DW_TAG_lexical_block";
3895 case DW_TAG_member:
3896 return "DW_TAG_member";
3897 case DW_TAG_pointer_type:
3898 return "DW_TAG_pointer_type";
3899 case DW_TAG_reference_type:
3900 return "DW_TAG_reference_type";
3901 case DW_TAG_compile_unit:
3902 return "DW_TAG_compile_unit";
3903 case DW_TAG_string_type:
3904 return "DW_TAG_string_type";
3905 case DW_TAG_structure_type:
3906 return "DW_TAG_structure_type";
3907 case DW_TAG_subroutine_type:
3908 return "DW_TAG_subroutine_type";
3909 case DW_TAG_typedef:
3910 return "DW_TAG_typedef";
3911 case DW_TAG_union_type:
3912 return "DW_TAG_union_type";
3913 case DW_TAG_unspecified_parameters:
3914 return "DW_TAG_unspecified_parameters";
3915 case DW_TAG_variant:
3916 return "DW_TAG_variant";
3917 case DW_TAG_common_block:
3918 return "DW_TAG_common_block";
3919 case DW_TAG_common_inclusion:
3920 return "DW_TAG_common_inclusion";
3921 case DW_TAG_inheritance:
3922 return "DW_TAG_inheritance";
3923 case DW_TAG_inlined_subroutine:
3924 return "DW_TAG_inlined_subroutine";
3925 case DW_TAG_module:
3926 return "DW_TAG_module";
3927 case DW_TAG_ptr_to_member_type:
3928 return "DW_TAG_ptr_to_member_type";
3929 case DW_TAG_set_type:
3930 return "DW_TAG_set_type";
3931 case DW_TAG_subrange_type:
3932 return "DW_TAG_subrange_type";
3933 case DW_TAG_with_stmt:
3934 return "DW_TAG_with_stmt";
3935 case DW_TAG_access_declaration:
3936 return "DW_TAG_access_declaration";
3937 case DW_TAG_base_type:
3938 return "DW_TAG_base_type";
3939 case DW_TAG_catch_block:
3940 return "DW_TAG_catch_block";
3941 case DW_TAG_const_type:
3942 return "DW_TAG_const_type";
3943 case DW_TAG_constant:
3944 return "DW_TAG_constant";
3945 case DW_TAG_enumerator:
3946 return "DW_TAG_enumerator";
3947 case DW_TAG_file_type:
3948 return "DW_TAG_file_type";
3949 case DW_TAG_friend:
3950 return "DW_TAG_friend";
3951 case DW_TAG_namelist:
3952 return "DW_TAG_namelist";
3953 case DW_TAG_namelist_item:
3954 return "DW_TAG_namelist_item";
3955 case DW_TAG_packed_type:
3956 return "DW_TAG_packed_type";
3957 case DW_TAG_subprogram:
3958 return "DW_TAG_subprogram";
3959 case DW_TAG_template_type_param:
3960 return "DW_TAG_template_type_param";
3961 case DW_TAG_template_value_param:
3962 return "DW_TAG_template_value_param";
3963 case DW_TAG_thrown_type:
3964 return "DW_TAG_thrown_type";
3965 case DW_TAG_try_block:
3966 return "DW_TAG_try_block";
3967 case DW_TAG_variant_part:
3968 return "DW_TAG_variant_part";
3969 case DW_TAG_variable:
3970 return "DW_TAG_variable";
3971 case DW_TAG_volatile_type:
3972 return "DW_TAG_volatile_type";
3973 case DW_TAG_MIPS_loop:
3974 return "DW_TAG_MIPS_loop";
3975 case DW_TAG_format_label:
3976 return "DW_TAG_format_label";
3977 case DW_TAG_function_template:
3978 return "DW_TAG_function_template";
3979 case DW_TAG_class_template:
3980 return "DW_TAG_class_template";
3981 case DW_TAG_GNU_BINCL:
3982 return "DW_TAG_GNU_BINCL";
3983 case DW_TAG_GNU_EINCL:
3984 return "DW_TAG_GNU_EINCL";
3985 default:
3986 return "DW_TAG_<unknown>";
3990 /* Convert a DWARF attribute code into its string name. */
3992 static const char *
3993 dwarf_attr_name (attr)
3994 unsigned attr;
3996 switch (attr)
3998 case DW_AT_sibling:
3999 return "DW_AT_sibling";
4000 case DW_AT_location:
4001 return "DW_AT_location";
4002 case DW_AT_name:
4003 return "DW_AT_name";
4004 case DW_AT_ordering:
4005 return "DW_AT_ordering";
4006 case DW_AT_subscr_data:
4007 return "DW_AT_subscr_data";
4008 case DW_AT_byte_size:
4009 return "DW_AT_byte_size";
4010 case DW_AT_bit_offset:
4011 return "DW_AT_bit_offset";
4012 case DW_AT_bit_size:
4013 return "DW_AT_bit_size";
4014 case DW_AT_element_list:
4015 return "DW_AT_element_list";
4016 case DW_AT_stmt_list:
4017 return "DW_AT_stmt_list";
4018 case DW_AT_low_pc:
4019 return "DW_AT_low_pc";
4020 case DW_AT_high_pc:
4021 return "DW_AT_high_pc";
4022 case DW_AT_language:
4023 return "DW_AT_language";
4024 case DW_AT_member:
4025 return "DW_AT_member";
4026 case DW_AT_discr:
4027 return "DW_AT_discr";
4028 case DW_AT_discr_value:
4029 return "DW_AT_discr_value";
4030 case DW_AT_visibility:
4031 return "DW_AT_visibility";
4032 case DW_AT_import:
4033 return "DW_AT_import";
4034 case DW_AT_string_length:
4035 return "DW_AT_string_length";
4036 case DW_AT_common_reference:
4037 return "DW_AT_common_reference";
4038 case DW_AT_comp_dir:
4039 return "DW_AT_comp_dir";
4040 case DW_AT_const_value:
4041 return "DW_AT_const_value";
4042 case DW_AT_containing_type:
4043 return "DW_AT_containing_type";
4044 case DW_AT_default_value:
4045 return "DW_AT_default_value";
4046 case DW_AT_inline:
4047 return "DW_AT_inline";
4048 case DW_AT_is_optional:
4049 return "DW_AT_is_optional";
4050 case DW_AT_lower_bound:
4051 return "DW_AT_lower_bound";
4052 case DW_AT_producer:
4053 return "DW_AT_producer";
4054 case DW_AT_prototyped:
4055 return "DW_AT_prototyped";
4056 case DW_AT_return_addr:
4057 return "DW_AT_return_addr";
4058 case DW_AT_start_scope:
4059 return "DW_AT_start_scope";
4060 case DW_AT_stride_size:
4061 return "DW_AT_stride_size";
4062 case DW_AT_upper_bound:
4063 return "DW_AT_upper_bound";
4064 case DW_AT_abstract_origin:
4065 return "DW_AT_abstract_origin";
4066 case DW_AT_accessibility:
4067 return "DW_AT_accessibility";
4068 case DW_AT_address_class:
4069 return "DW_AT_address_class";
4070 case DW_AT_artificial:
4071 return "DW_AT_artificial";
4072 case DW_AT_base_types:
4073 return "DW_AT_base_types";
4074 case DW_AT_calling_convention:
4075 return "DW_AT_calling_convention";
4076 case DW_AT_count:
4077 return "DW_AT_count";
4078 case DW_AT_data_member_location:
4079 return "DW_AT_data_member_location";
4080 case DW_AT_decl_column:
4081 return "DW_AT_decl_column";
4082 case DW_AT_decl_file:
4083 return "DW_AT_decl_file";
4084 case DW_AT_decl_line:
4085 return "DW_AT_decl_line";
4086 case DW_AT_declaration:
4087 return "DW_AT_declaration";
4088 case DW_AT_discr_list:
4089 return "DW_AT_discr_list";
4090 case DW_AT_encoding:
4091 return "DW_AT_encoding";
4092 case DW_AT_external:
4093 return "DW_AT_external";
4094 case DW_AT_frame_base:
4095 return "DW_AT_frame_base";
4096 case DW_AT_friend:
4097 return "DW_AT_friend";
4098 case DW_AT_identifier_case:
4099 return "DW_AT_identifier_case";
4100 case DW_AT_macro_info:
4101 return "DW_AT_macro_info";
4102 case DW_AT_namelist_items:
4103 return "DW_AT_namelist_items";
4104 case DW_AT_priority:
4105 return "DW_AT_priority";
4106 case DW_AT_segment:
4107 return "DW_AT_segment";
4108 case DW_AT_specification:
4109 return "DW_AT_specification";
4110 case DW_AT_static_link:
4111 return "DW_AT_static_link";
4112 case DW_AT_type:
4113 return "DW_AT_type";
4114 case DW_AT_use_location:
4115 return "DW_AT_use_location";
4116 case DW_AT_variable_parameter:
4117 return "DW_AT_variable_parameter";
4118 case DW_AT_virtuality:
4119 return "DW_AT_virtuality";
4120 case DW_AT_vtable_elem_location:
4121 return "DW_AT_vtable_elem_location";
4123 case DW_AT_allocated:
4124 return "DW_AT_allocated";
4125 case DW_AT_associated:
4126 return "DW_AT_associated";
4127 case DW_AT_data_location:
4128 return "DW_AT_data_location";
4129 case DW_AT_stride:
4130 return "DW_AT_stride";
4131 case DW_AT_entry_pc:
4132 return "DW_AT_entry_pc";
4133 case DW_AT_use_UTF8:
4134 return "DW_AT_use_UTF8";
4135 case DW_AT_extension:
4136 return "DW_AT_extension";
4137 case DW_AT_ranges:
4138 return "DW_AT_ranges";
4139 case DW_AT_trampoline:
4140 return "DW_AT_trampoline";
4141 case DW_AT_call_column:
4142 return "DW_AT_call_column";
4143 case DW_AT_call_file:
4144 return "DW_AT_call_file";
4145 case DW_AT_call_line:
4146 return "DW_AT_call_line";
4148 case DW_AT_MIPS_fde:
4149 return "DW_AT_MIPS_fde";
4150 case DW_AT_MIPS_loop_begin:
4151 return "DW_AT_MIPS_loop_begin";
4152 case DW_AT_MIPS_tail_loop_begin:
4153 return "DW_AT_MIPS_tail_loop_begin";
4154 case DW_AT_MIPS_epilog_begin:
4155 return "DW_AT_MIPS_epilog_begin";
4156 case DW_AT_MIPS_loop_unroll_factor:
4157 return "DW_AT_MIPS_loop_unroll_factor";
4158 case DW_AT_MIPS_software_pipeline_depth:
4159 return "DW_AT_MIPS_software_pipeline_depth";
4160 case DW_AT_MIPS_linkage_name:
4161 return "DW_AT_MIPS_linkage_name";
4162 case DW_AT_MIPS_stride:
4163 return "DW_AT_MIPS_stride";
4164 case DW_AT_MIPS_abstract_name:
4165 return "DW_AT_MIPS_abstract_name";
4166 case DW_AT_MIPS_clone_origin:
4167 return "DW_AT_MIPS_clone_origin";
4168 case DW_AT_MIPS_has_inlines:
4169 return "DW_AT_MIPS_has_inlines";
4171 case DW_AT_sf_names:
4172 return "DW_AT_sf_names";
4173 case DW_AT_src_info:
4174 return "DW_AT_src_info";
4175 case DW_AT_mac_info:
4176 return "DW_AT_mac_info";
4177 case DW_AT_src_coords:
4178 return "DW_AT_src_coords";
4179 case DW_AT_body_begin:
4180 return "DW_AT_body_begin";
4181 case DW_AT_body_end:
4182 return "DW_AT_body_end";
4183 case DW_AT_GNU_vector:
4184 return "DW_AT_GNU_vector";
4186 case DW_AT_VMS_rtnbeg_pd_address:
4187 return "DW_AT_VMS_rtnbeg_pd_address";
4189 default:
4190 return "DW_AT_<unknown>";
4194 /* Convert a DWARF value form code into its string name. */
4196 static const char *
4197 dwarf_form_name (form)
4198 unsigned form;
4200 switch (form)
4202 case DW_FORM_addr:
4203 return "DW_FORM_addr";
4204 case DW_FORM_block2:
4205 return "DW_FORM_block2";
4206 case DW_FORM_block4:
4207 return "DW_FORM_block4";
4208 case DW_FORM_data2:
4209 return "DW_FORM_data2";
4210 case DW_FORM_data4:
4211 return "DW_FORM_data4";
4212 case DW_FORM_data8:
4213 return "DW_FORM_data8";
4214 case DW_FORM_string:
4215 return "DW_FORM_string";
4216 case DW_FORM_block:
4217 return "DW_FORM_block";
4218 case DW_FORM_block1:
4219 return "DW_FORM_block1";
4220 case DW_FORM_data1:
4221 return "DW_FORM_data1";
4222 case DW_FORM_flag:
4223 return "DW_FORM_flag";
4224 case DW_FORM_sdata:
4225 return "DW_FORM_sdata";
4226 case DW_FORM_strp:
4227 return "DW_FORM_strp";
4228 case DW_FORM_udata:
4229 return "DW_FORM_udata";
4230 case DW_FORM_ref_addr:
4231 return "DW_FORM_ref_addr";
4232 case DW_FORM_ref1:
4233 return "DW_FORM_ref1";
4234 case DW_FORM_ref2:
4235 return "DW_FORM_ref2";
4236 case DW_FORM_ref4:
4237 return "DW_FORM_ref4";
4238 case DW_FORM_ref8:
4239 return "DW_FORM_ref8";
4240 case DW_FORM_ref_udata:
4241 return "DW_FORM_ref_udata";
4242 case DW_FORM_indirect:
4243 return "DW_FORM_indirect";
4244 default:
4245 return "DW_FORM_<unknown>";
4249 /* Convert a DWARF type code into its string name. */
4251 #if 0
4252 static const char *
4253 dwarf_type_encoding_name (enc)
4254 unsigned enc;
4256 switch (enc)
4258 case DW_ATE_address:
4259 return "DW_ATE_address";
4260 case DW_ATE_boolean:
4261 return "DW_ATE_boolean";
4262 case DW_ATE_complex_float:
4263 return "DW_ATE_complex_float";
4264 case DW_ATE_float:
4265 return "DW_ATE_float";
4266 case DW_ATE_signed:
4267 return "DW_ATE_signed";
4268 case DW_ATE_signed_char:
4269 return "DW_ATE_signed_char";
4270 case DW_ATE_unsigned:
4271 return "DW_ATE_unsigned";
4272 case DW_ATE_unsigned_char:
4273 return "DW_ATE_unsigned_char";
4274 default:
4275 return "DW_ATE_<unknown>";
4278 #endif
4280 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4281 instance of an inlined instance of a decl which is local to an inline
4282 function, so we have to trace all of the way back through the origin chain
4283 to find out what sort of node actually served as the original seed for the
4284 given block. */
4286 static tree
4287 decl_ultimate_origin (decl)
4288 tree decl;
4290 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4291 nodes in the function to point to themselves; ignore that if
4292 we're trying to output the abstract instance of this function. */
4293 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4294 return NULL_TREE;
4296 #ifdef ENABLE_CHECKING
4297 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4298 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4299 most distant ancestor, this should never happen. */
4300 abort ();
4301 #endif
4303 return DECL_ABSTRACT_ORIGIN (decl);
4306 /* Determine the "ultimate origin" of a block. The block may be an inlined
4307 instance of an inlined instance of a block which is local to an inline
4308 function, so we have to trace all of the way back through the origin chain
4309 to find out what sort of node actually served as the original seed for the
4310 given block. */
4312 static tree
4313 block_ultimate_origin (block)
4314 tree block;
4316 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4318 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4319 nodes in the function to point to themselves; ignore that if
4320 we're trying to output the abstract instance of this function. */
4321 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4322 return NULL_TREE;
4324 if (immediate_origin == NULL_TREE)
4325 return NULL_TREE;
4326 else
4328 tree ret_val;
4329 tree lookahead = immediate_origin;
4333 ret_val = lookahead;
4334 lookahead = (TREE_CODE (ret_val) == BLOCK
4335 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4337 while (lookahead != NULL && lookahead != ret_val);
4339 return ret_val;
4343 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4344 of a virtual function may refer to a base class, so we check the 'this'
4345 parameter. */
4347 static tree
4348 decl_class_context (decl)
4349 tree decl;
4351 tree context = NULL_TREE;
4353 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4354 context = DECL_CONTEXT (decl);
4355 else
4356 context = TYPE_MAIN_VARIANT
4357 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4359 if (context && !TYPE_P (context))
4360 context = NULL_TREE;
4362 return context;
4365 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4366 addition order, and correct that in reverse_all_dies. */
4368 static inline void
4369 add_dwarf_attr (die, attr)
4370 dw_die_ref die;
4371 dw_attr_ref attr;
4373 if (die != NULL && attr != NULL)
4375 attr->dw_attr_next = die->die_attr;
4376 die->die_attr = attr;
4380 static inline dw_val_class
4381 AT_class (a)
4382 dw_attr_ref a;
4384 return a->dw_attr_val.val_class;
4387 /* Add a flag value attribute to a DIE. */
4389 static inline void
4390 add_AT_flag (die, attr_kind, flag)
4391 dw_die_ref die;
4392 enum dwarf_attribute attr_kind;
4393 unsigned flag;
4395 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4397 attr->dw_attr_next = NULL;
4398 attr->dw_attr = attr_kind;
4399 attr->dw_attr_val.val_class = dw_val_class_flag;
4400 attr->dw_attr_val.v.val_flag = flag;
4401 add_dwarf_attr (die, attr);
4404 static inline unsigned
4405 AT_flag (a)
4406 dw_attr_ref a;
4408 if (a && AT_class (a) == dw_val_class_flag)
4409 return a->dw_attr_val.v.val_flag;
4411 abort ();
4414 /* Add a signed integer attribute value to a DIE. */
4416 static inline void
4417 add_AT_int (die, attr_kind, int_val)
4418 dw_die_ref die;
4419 enum dwarf_attribute attr_kind;
4420 long int int_val;
4422 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4424 attr->dw_attr_next = NULL;
4425 attr->dw_attr = attr_kind;
4426 attr->dw_attr_val.val_class = dw_val_class_const;
4427 attr->dw_attr_val.v.val_int = int_val;
4428 add_dwarf_attr (die, attr);
4431 static inline long int
4432 AT_int (a)
4433 dw_attr_ref a;
4435 if (a && AT_class (a) == dw_val_class_const)
4436 return a->dw_attr_val.v.val_int;
4438 abort ();
4441 /* Add an unsigned integer attribute value to a DIE. */
4443 static inline void
4444 add_AT_unsigned (die, attr_kind, unsigned_val)
4445 dw_die_ref die;
4446 enum dwarf_attribute attr_kind;
4447 unsigned long unsigned_val;
4449 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4451 attr->dw_attr_next = NULL;
4452 attr->dw_attr = attr_kind;
4453 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4454 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4455 add_dwarf_attr (die, attr);
4458 static inline unsigned long
4459 AT_unsigned (a)
4460 dw_attr_ref a;
4462 if (a && AT_class (a) == dw_val_class_unsigned_const)
4463 return a->dw_attr_val.v.val_unsigned;
4465 abort ();
4468 /* Add an unsigned double integer attribute value to a DIE. */
4470 static inline void
4471 add_AT_long_long (die, attr_kind, val_hi, val_low)
4472 dw_die_ref die;
4473 enum dwarf_attribute attr_kind;
4474 unsigned long val_hi;
4475 unsigned long val_low;
4477 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4479 attr->dw_attr_next = NULL;
4480 attr->dw_attr = attr_kind;
4481 attr->dw_attr_val.val_class = dw_val_class_long_long;
4482 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4483 attr->dw_attr_val.v.val_long_long.low = val_low;
4484 add_dwarf_attr (die, attr);
4487 /* Add a floating point attribute value to a DIE and return it. */
4489 static inline void
4490 add_AT_float (die, attr_kind, length, array)
4491 dw_die_ref die;
4492 enum dwarf_attribute attr_kind;
4493 unsigned length;
4494 long *array;
4496 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4498 attr->dw_attr_next = NULL;
4499 attr->dw_attr = attr_kind;
4500 attr->dw_attr_val.val_class = dw_val_class_float;
4501 attr->dw_attr_val.v.val_float.length = length;
4502 attr->dw_attr_val.v.val_float.array = array;
4503 add_dwarf_attr (die, attr);
4506 /* Add a string attribute value to a DIE. */
4508 static inline void
4509 add_AT_string (die, attr_kind, str)
4510 dw_die_ref die;
4511 enum dwarf_attribute attr_kind;
4512 const char *str;
4514 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4515 struct indirect_string_node *node;
4517 if (! debug_str_hash)
4519 debug_str_hash = ht_create (10);
4520 debug_str_hash->alloc_node = indirect_string_alloc;
4523 node = (struct indirect_string_node *)
4524 ht_lookup (debug_str_hash, (const unsigned char *) str,
4525 strlen (str), HT_ALLOC);
4526 node->refcount++;
4528 attr->dw_attr_next = NULL;
4529 attr->dw_attr = attr_kind;
4530 attr->dw_attr_val.val_class = dw_val_class_str;
4531 attr->dw_attr_val.v.val_str = node;
4532 add_dwarf_attr (die, attr);
4535 static inline const char *
4536 AT_string (a)
4537 dw_attr_ref a;
4539 if (a && AT_class (a) == dw_val_class_str)
4540 return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id);
4542 abort ();
4545 /* Find out whether a string should be output inline in DIE
4546 or out-of-line in .debug_str section. */
4548 static int
4549 AT_string_form (a)
4550 dw_attr_ref a;
4552 if (a && AT_class (a) == dw_val_class_str)
4554 struct indirect_string_node *node;
4555 unsigned int len;
4556 extern int const_labelno;
4557 char label[32];
4559 node = a->dw_attr_val.v.val_str;
4560 if (node->form)
4561 return node->form;
4563 len = HT_LEN (&node->id) + 1;
4565 /* If the string is shorter or equal to the size of the reference, it is
4566 always better to put it inline. */
4567 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4568 return node->form = DW_FORM_string;
4570 /* If we cannot expect the linker to merge strings in .debug_str
4571 section, only put it into .debug_str if it is worth even in this
4572 single module. */
4573 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4574 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4575 return node->form = DW_FORM_string;
4577 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4578 ++const_labelno;
4579 node->label = xstrdup (label);
4581 return node->form = DW_FORM_strp;
4584 abort ();
4587 /* Add a DIE reference attribute value to a DIE. */
4589 static inline void
4590 add_AT_die_ref (die, attr_kind, targ_die)
4591 dw_die_ref die;
4592 enum dwarf_attribute attr_kind;
4593 dw_die_ref targ_die;
4595 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4597 attr->dw_attr_next = NULL;
4598 attr->dw_attr = attr_kind;
4599 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4600 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4601 attr->dw_attr_val.v.val_die_ref.external = 0;
4602 add_dwarf_attr (die, attr);
4605 static inline dw_die_ref
4606 AT_ref (a)
4607 dw_attr_ref a;
4609 if (a && AT_class (a) == dw_val_class_die_ref)
4610 return a->dw_attr_val.v.val_die_ref.die;
4612 abort ();
4615 static inline int
4616 AT_ref_external (a)
4617 dw_attr_ref a;
4619 if (a && AT_class (a) == dw_val_class_die_ref)
4620 return a->dw_attr_val.v.val_die_ref.external;
4622 return 0;
4625 static inline void
4626 set_AT_ref_external (a, i)
4627 dw_attr_ref a;
4628 int i;
4630 if (a && AT_class (a) == dw_val_class_die_ref)
4631 a->dw_attr_val.v.val_die_ref.external = i;
4632 else
4633 abort ();
4636 /* Add an FDE reference attribute value to a DIE. */
4638 static inline void
4639 add_AT_fde_ref (die, attr_kind, targ_fde)
4640 dw_die_ref die;
4641 enum dwarf_attribute attr_kind;
4642 unsigned targ_fde;
4644 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4646 attr->dw_attr_next = NULL;
4647 attr->dw_attr = attr_kind;
4648 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4649 attr->dw_attr_val.v.val_fde_index = targ_fde;
4650 add_dwarf_attr (die, attr);
4653 /* Add a location description attribute value to a DIE. */
4655 static inline void
4656 add_AT_loc (die, attr_kind, loc)
4657 dw_die_ref die;
4658 enum dwarf_attribute attr_kind;
4659 dw_loc_descr_ref loc;
4661 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4663 attr->dw_attr_next = NULL;
4664 attr->dw_attr = attr_kind;
4665 attr->dw_attr_val.val_class = dw_val_class_loc;
4666 attr->dw_attr_val.v.val_loc = loc;
4667 add_dwarf_attr (die, attr);
4670 static inline dw_loc_descr_ref
4671 AT_loc (a)
4672 dw_attr_ref a;
4674 if (a && AT_class (a) == dw_val_class_loc)
4675 return a->dw_attr_val.v.val_loc;
4677 abort ();
4680 static inline void
4681 add_AT_loc_list (die, attr_kind, loc_list)
4682 dw_die_ref die;
4683 enum dwarf_attribute attr_kind;
4684 dw_loc_list_ref loc_list;
4686 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4688 attr->dw_attr_next = NULL;
4689 attr->dw_attr = attr_kind;
4690 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4691 attr->dw_attr_val.v.val_loc_list = loc_list;
4692 add_dwarf_attr (die, attr);
4693 have_location_lists = 1;
4696 static inline dw_loc_list_ref
4697 AT_loc_list (a)
4698 dw_attr_ref a;
4700 if (a && AT_class (a) == dw_val_class_loc_list)
4701 return a->dw_attr_val.v.val_loc_list;
4703 abort ();
4706 /* Add an address constant attribute value to a DIE. */
4708 static inline void
4709 add_AT_addr (die, attr_kind, addr)
4710 dw_die_ref die;
4711 enum dwarf_attribute attr_kind;
4712 rtx addr;
4714 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4716 attr->dw_attr_next = NULL;
4717 attr->dw_attr = attr_kind;
4718 attr->dw_attr_val.val_class = dw_val_class_addr;
4719 attr->dw_attr_val.v.val_addr = addr;
4720 add_dwarf_attr (die, attr);
4723 static inline rtx
4724 AT_addr (a)
4725 dw_attr_ref a;
4727 if (a && AT_class (a) == dw_val_class_addr)
4728 return a->dw_attr_val.v.val_addr;
4730 abort ();
4733 /* Add a label identifier attribute value to a DIE. */
4735 static inline void
4736 add_AT_lbl_id (die, attr_kind, lbl_id)
4737 dw_die_ref die;
4738 enum dwarf_attribute attr_kind;
4739 const char *lbl_id;
4741 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4743 attr->dw_attr_next = NULL;
4744 attr->dw_attr = attr_kind;
4745 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4746 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4747 add_dwarf_attr (die, attr);
4750 /* Add a section offset attribute value to a DIE. */
4752 static inline void
4753 add_AT_lbl_offset (die, attr_kind, label)
4754 dw_die_ref die;
4755 enum dwarf_attribute attr_kind;
4756 const char *label;
4758 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4760 attr->dw_attr_next = NULL;
4761 attr->dw_attr = attr_kind;
4762 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4763 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4764 add_dwarf_attr (die, attr);
4767 /* Add an offset attribute value to a DIE. */
4769 static inline void
4770 add_AT_offset (die, attr_kind, offset)
4771 dw_die_ref die;
4772 enum dwarf_attribute attr_kind;
4773 unsigned long offset;
4775 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4777 attr->dw_attr_next = NULL;
4778 attr->dw_attr = attr_kind;
4779 attr->dw_attr_val.val_class = dw_val_class_offset;
4780 attr->dw_attr_val.v.val_offset = offset;
4781 add_dwarf_attr (die, attr);
4784 /* Add an range_list attribute value to a DIE. */
4786 static void
4787 add_AT_range_list (die, attr_kind, offset)
4788 dw_die_ref die;
4789 enum dwarf_attribute attr_kind;
4790 unsigned long offset;
4792 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4794 attr->dw_attr_next = NULL;
4795 attr->dw_attr = attr_kind;
4796 attr->dw_attr_val.val_class = dw_val_class_range_list;
4797 attr->dw_attr_val.v.val_offset = offset;
4798 add_dwarf_attr (die, attr);
4801 static inline const char *
4802 AT_lbl (a)
4803 dw_attr_ref a;
4805 if (a && (AT_class (a) == dw_val_class_lbl_id
4806 || AT_class (a) == dw_val_class_lbl_offset))
4807 return a->dw_attr_val.v.val_lbl_id;
4809 abort ();
4812 /* Get the attribute of type attr_kind. */
4814 static inline dw_attr_ref
4815 get_AT (die, attr_kind)
4816 dw_die_ref die;
4817 enum dwarf_attribute attr_kind;
4819 dw_attr_ref a;
4820 dw_die_ref spec = NULL;
4822 if (die != NULL)
4824 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4825 if (a->dw_attr == attr_kind)
4826 return a;
4827 else if (a->dw_attr == DW_AT_specification
4828 || a->dw_attr == DW_AT_abstract_origin)
4829 spec = AT_ref (a);
4831 if (spec)
4832 return get_AT (spec, attr_kind);
4835 return NULL;
4838 /* Return the "low pc" attribute value, typically associated with a subprogram
4839 DIE. Return null if the "low pc" attribute is either not present, or if it
4840 cannot be represented as an assembler label identifier. */
4842 static inline const char *
4843 get_AT_low_pc (die)
4844 dw_die_ref die;
4846 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4848 return a ? AT_lbl (a) : NULL;
4851 /* Return the "high pc" attribute value, typically associated with a subprogram
4852 DIE. Return null if the "high pc" attribute is either not present, or if it
4853 cannot be represented as an assembler label identifier. */
4855 static inline const char *
4856 get_AT_hi_pc (die)
4857 dw_die_ref die;
4859 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4861 return a ? AT_lbl (a) : NULL;
4864 /* Return the value of the string attribute designated by ATTR_KIND, or
4865 NULL if it is not present. */
4867 static inline const char *
4868 get_AT_string (die, attr_kind)
4869 dw_die_ref die;
4870 enum dwarf_attribute attr_kind;
4872 dw_attr_ref a = get_AT (die, attr_kind);
4874 return a ? AT_string (a) : NULL;
4877 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4878 if it is not present. */
4880 static inline int
4881 get_AT_flag (die, attr_kind)
4882 dw_die_ref die;
4883 enum dwarf_attribute attr_kind;
4885 dw_attr_ref a = get_AT (die, attr_kind);
4887 return a ? AT_flag (a) : 0;
4890 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4891 if it is not present. */
4893 static inline unsigned
4894 get_AT_unsigned (die, attr_kind)
4895 dw_die_ref die;
4896 enum dwarf_attribute attr_kind;
4898 dw_attr_ref a = get_AT (die, attr_kind);
4900 return a ? AT_unsigned (a) : 0;
4903 static inline dw_die_ref
4904 get_AT_ref (die, attr_kind)
4905 dw_die_ref die;
4906 enum dwarf_attribute attr_kind;
4908 dw_attr_ref a = get_AT (die, attr_kind);
4910 return a ? AT_ref (a) : NULL;
4913 static inline int
4914 is_c_family ()
4916 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4918 return (lang == DW_LANG_C || lang == DW_LANG_C89
4919 || lang == DW_LANG_C_plus_plus);
4922 static inline int
4923 is_cxx ()
4925 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4926 == DW_LANG_C_plus_plus);
4929 static inline int
4930 is_fortran ()
4932 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4934 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4937 static inline int
4938 is_java ()
4940 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4942 return (lang == DW_LANG_Java);
4945 /* Free up the memory used by A. */
4947 static inline void free_AT PARAMS ((dw_attr_ref));
4948 static inline void
4949 free_AT (a)
4950 dw_attr_ref a;
4952 switch (AT_class (a))
4954 case dw_val_class_str:
4955 if (a->dw_attr_val.v.val_str->refcount)
4956 a->dw_attr_val.v.val_str->refcount--;
4957 break;
4959 case dw_val_class_lbl_id:
4960 case dw_val_class_lbl_offset:
4961 free (a->dw_attr_val.v.val_lbl_id);
4962 break;
4964 case dw_val_class_float:
4965 free (a->dw_attr_val.v.val_float.array);
4966 break;
4968 default:
4969 break;
4972 free (a);
4975 /* Remove the specified attribute if present. */
4977 static void
4978 remove_AT (die, attr_kind)
4979 dw_die_ref die;
4980 enum dwarf_attribute attr_kind;
4982 dw_attr_ref *p;
4983 dw_attr_ref removed = NULL;
4985 if (die != NULL)
4987 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4988 if ((*p)->dw_attr == attr_kind)
4990 removed = *p;
4991 *p = (*p)->dw_attr_next;
4992 break;
4995 if (removed != 0)
4996 free_AT (removed);
5000 /* Free up the memory used by DIE. */
5002 static inline void
5003 free_die (die)
5004 dw_die_ref die;
5006 remove_children (die);
5007 free (die);
5010 /* Discard the children of this DIE. */
5012 static void
5013 remove_children (die)
5014 dw_die_ref die;
5016 dw_die_ref child_die = die->die_child;
5018 die->die_child = NULL;
5020 while (child_die != NULL)
5022 dw_die_ref tmp_die = child_die;
5023 dw_attr_ref a;
5025 child_die = child_die->die_sib;
5027 for (a = tmp_die->die_attr; a != NULL;)
5029 dw_attr_ref tmp_a = a;
5031 a = a->dw_attr_next;
5032 free_AT (tmp_a);
5035 free_die (tmp_die);
5039 /* Add a child DIE below its parent. We build the lists up in reverse
5040 addition order, and correct that in reverse_all_dies. */
5042 static inline void
5043 add_child_die (die, child_die)
5044 dw_die_ref die;
5045 dw_die_ref child_die;
5047 if (die != NULL && child_die != NULL)
5049 if (die == child_die)
5050 abort ();
5052 child_die->die_parent = die;
5053 child_die->die_sib = die->die_child;
5054 die->die_child = child_die;
5058 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5059 is the specification, to the front of PARENT's list of children. */
5061 static void
5062 splice_child_die (parent, child)
5063 dw_die_ref parent, child;
5065 dw_die_ref *p;
5067 /* We want the declaration DIE from inside the class, not the
5068 specification DIE at toplevel. */
5069 if (child->die_parent != parent)
5071 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5073 if (tmp)
5074 child = tmp;
5077 if (child->die_parent != parent
5078 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
5079 abort ();
5081 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5082 if (*p == child)
5084 *p = child->die_sib;
5085 break;
5088 child->die_sib = parent->die_child;
5089 parent->die_child = child;
5092 /* Return a pointer to a newly created DIE node. */
5094 static inline dw_die_ref
5095 new_die (tag_value, parent_die, t)
5096 enum dwarf_tag tag_value;
5097 dw_die_ref parent_die;
5098 tree t;
5100 dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5102 die->die_tag = tag_value;
5104 if (parent_die != NULL)
5105 add_child_die (parent_die, die);
5106 else
5108 limbo_die_node *limbo_node;
5110 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5111 limbo_node->die = die;
5112 limbo_node->created_for = t;
5113 limbo_node->next = limbo_die_list;
5114 limbo_die_list = limbo_node;
5117 return die;
5120 /* Return the DIE associated with the given type specifier. */
5122 static inline dw_die_ref
5123 lookup_type_die (type)
5124 tree type;
5126 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
5129 /* Equate a DIE to a given type specifier. */
5131 static inline void
5132 equate_type_number_to_die (type, type_die)
5133 tree type;
5134 dw_die_ref type_die;
5136 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
5139 /* Return the DIE associated with a given declaration. */
5141 static inline dw_die_ref
5142 lookup_decl_die (decl)
5143 tree decl;
5145 unsigned decl_id = DECL_UID (decl);
5147 return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
5150 /* Equate a DIE to a particular declaration. */
5152 static void
5153 equate_decl_number_to_die (decl, decl_die)
5154 tree decl;
5155 dw_die_ref decl_die;
5157 unsigned int decl_id = DECL_UID (decl);
5158 unsigned int num_allocated;
5160 if (decl_id >= decl_die_table_allocated)
5162 num_allocated
5163 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5164 / DECL_DIE_TABLE_INCREMENT)
5165 * DECL_DIE_TABLE_INCREMENT;
5167 decl_die_table
5168 = (dw_die_ref *) xrealloc (decl_die_table,
5169 sizeof (dw_die_ref) * num_allocated);
5171 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5172 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5173 decl_die_table_allocated = num_allocated;
5176 if (decl_id >= decl_die_table_in_use)
5177 decl_die_table_in_use = (decl_id + 1);
5179 decl_die_table[decl_id] = decl_die;
5182 /* Keep track of the number of spaces used to indent the
5183 output of the debugging routines that print the structure of
5184 the DIE internal representation. */
5185 static int print_indent;
5187 /* Indent the line the number of spaces given by print_indent. */
5189 static inline void
5190 print_spaces (outfile)
5191 FILE *outfile;
5193 fprintf (outfile, "%*s", print_indent, "");
5196 /* Print the information associated with a given DIE, and its children.
5197 This routine is a debugging aid only. */
5199 static void
5200 print_die (die, outfile)
5201 dw_die_ref die;
5202 FILE *outfile;
5204 dw_attr_ref a;
5205 dw_die_ref c;
5207 print_spaces (outfile);
5208 fprintf (outfile, "DIE %4lu: %s\n",
5209 die->die_offset, dwarf_tag_name (die->die_tag));
5210 print_spaces (outfile);
5211 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5212 fprintf (outfile, " offset: %lu\n", die->die_offset);
5214 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5216 print_spaces (outfile);
5217 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5219 switch (AT_class (a))
5221 case dw_val_class_addr:
5222 fprintf (outfile, "address");
5223 break;
5224 case dw_val_class_offset:
5225 fprintf (outfile, "offset");
5226 break;
5227 case dw_val_class_loc:
5228 fprintf (outfile, "location descriptor");
5229 break;
5230 case dw_val_class_loc_list:
5231 fprintf (outfile, "location list -> label:%s",
5232 AT_loc_list (a)->ll_symbol);
5233 break;
5234 case dw_val_class_range_list:
5235 fprintf (outfile, "range list");
5236 break;
5237 case dw_val_class_const:
5238 fprintf (outfile, "%ld", AT_int (a));
5239 break;
5240 case dw_val_class_unsigned_const:
5241 fprintf (outfile, "%lu", AT_unsigned (a));
5242 break;
5243 case dw_val_class_long_long:
5244 fprintf (outfile, "constant (%lu,%lu)",
5245 a->dw_attr_val.v.val_long_long.hi,
5246 a->dw_attr_val.v.val_long_long.low);
5247 break;
5248 case dw_val_class_float:
5249 fprintf (outfile, "floating-point constant");
5250 break;
5251 case dw_val_class_flag:
5252 fprintf (outfile, "%u", AT_flag (a));
5253 break;
5254 case dw_val_class_die_ref:
5255 if (AT_ref (a) != NULL)
5257 if (AT_ref (a)->die_symbol)
5258 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5259 else
5260 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5262 else
5263 fprintf (outfile, "die -> <null>");
5264 break;
5265 case dw_val_class_lbl_id:
5266 case dw_val_class_lbl_offset:
5267 fprintf (outfile, "label: %s", AT_lbl (a));
5268 break;
5269 case dw_val_class_str:
5270 if (AT_string (a) != NULL)
5271 fprintf (outfile, "\"%s\"", AT_string (a));
5272 else
5273 fprintf (outfile, "<null>");
5274 break;
5275 default:
5276 break;
5279 fprintf (outfile, "\n");
5282 if (die->die_child != NULL)
5284 print_indent += 4;
5285 for (c = die->die_child; c != NULL; c = c->die_sib)
5286 print_die (c, outfile);
5288 print_indent -= 4;
5290 if (print_indent == 0)
5291 fprintf (outfile, "\n");
5294 /* Print the contents of the source code line number correspondence table.
5295 This routine is a debugging aid only. */
5297 static void
5298 print_dwarf_line_table (outfile)
5299 FILE *outfile;
5301 unsigned i;
5302 dw_line_info_ref line_info;
5304 fprintf (outfile, "\n\nDWARF source line information\n");
5305 for (i = 1; i < line_info_table_in_use; i++)
5307 line_info = &line_info_table[i];
5308 fprintf (outfile, "%5d: ", i);
5309 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5310 fprintf (outfile, "%6ld", line_info->dw_line_num);
5311 fprintf (outfile, "\n");
5314 fprintf (outfile, "\n\n");
5317 /* Print the information collected for a given DIE. */
5319 void
5320 debug_dwarf_die (die)
5321 dw_die_ref die;
5323 print_die (die, stderr);
5326 /* Print all DWARF information collected for the compilation unit.
5327 This routine is a debugging aid only. */
5329 void
5330 debug_dwarf ()
5332 print_indent = 0;
5333 print_die (comp_unit_die, stderr);
5334 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5335 print_dwarf_line_table (stderr);
5338 /* We build up the lists of children and attributes by pushing new ones
5339 onto the beginning of the list. Reverse the lists for DIE so that
5340 they are in order of addition. */
5342 static void
5343 reverse_die_lists (die)
5344 dw_die_ref die;
5346 dw_die_ref c, cp, cn;
5347 dw_attr_ref a, ap, an;
5349 for (a = die->die_attr, ap = 0; a; a = an)
5351 an = a->dw_attr_next;
5352 a->dw_attr_next = ap;
5353 ap = a;
5356 die->die_attr = ap;
5358 for (c = die->die_child, cp = 0; c; c = cn)
5360 cn = c->die_sib;
5361 c->die_sib = cp;
5362 cp = c;
5365 die->die_child = cp;
5368 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5369 reverse all dies in add_sibling_attributes, which runs through all the dies,
5370 it would reverse all the dies. Now, however, since we don't call
5371 reverse_die_lists in add_sibling_attributes, we need a routine to
5372 recursively reverse all the dies. This is that routine. */
5374 static void
5375 reverse_all_dies (die)
5376 dw_die_ref die;
5378 dw_die_ref c;
5380 reverse_die_lists (die);
5382 for (c = die->die_child; c; c = c->die_sib)
5383 reverse_all_dies (c);
5386 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5387 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5388 DIE that marks the start of the DIEs for this include file. */
5390 static dw_die_ref
5391 push_new_compile_unit (old_unit, bincl_die)
5392 dw_die_ref old_unit, bincl_die;
5394 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5395 dw_die_ref new_unit = gen_compile_unit_die (filename);
5397 new_unit->die_sib = old_unit;
5398 return new_unit;
5401 /* Close an include-file CU and reopen the enclosing one. */
5403 static dw_die_ref
5404 pop_compile_unit (old_unit)
5405 dw_die_ref old_unit;
5407 dw_die_ref new_unit = old_unit->die_sib;
5409 old_unit->die_sib = NULL;
5410 return new_unit;
5413 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5414 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5416 /* Calculate the checksum of a location expression. */
5418 static inline void
5419 loc_checksum (loc, ctx)
5420 dw_loc_descr_ref loc;
5421 struct md5_ctx *ctx;
5423 CHECKSUM (loc->dw_loc_opc);
5424 CHECKSUM (loc->dw_loc_oprnd1);
5425 CHECKSUM (loc->dw_loc_oprnd2);
5428 /* Calculate the checksum of an attribute. */
5430 static void
5431 attr_checksum (at, ctx)
5432 dw_attr_ref at;
5433 struct md5_ctx *ctx;
5435 dw_loc_descr_ref loc;
5436 rtx r;
5438 CHECKSUM (at->dw_attr);
5440 /* We don't care about differences in file numbering. */
5441 if (at->dw_attr == DW_AT_decl_file
5442 /* Or that this was compiled with a different compiler snapshot; if
5443 the output is the same, that's what matters. */
5444 || at->dw_attr == DW_AT_producer)
5445 return;
5447 switch (AT_class (at))
5449 case dw_val_class_const:
5450 CHECKSUM (at->dw_attr_val.v.val_int);
5451 break;
5452 case dw_val_class_unsigned_const:
5453 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5454 break;
5455 case dw_val_class_long_long:
5456 CHECKSUM (at->dw_attr_val.v.val_long_long);
5457 break;
5458 case dw_val_class_float:
5459 CHECKSUM (at->dw_attr_val.v.val_float);
5460 break;
5461 case dw_val_class_flag:
5462 CHECKSUM (at->dw_attr_val.v.val_flag);
5463 break;
5464 case dw_val_class_str:
5465 CHECKSUM_STRING (AT_string (at));
5466 break;
5468 case dw_val_class_addr:
5469 r = AT_addr (at);
5470 switch (GET_CODE (r))
5472 case SYMBOL_REF:
5473 CHECKSUM_STRING (XSTR (r, 0));
5474 break;
5476 default:
5477 abort ();
5479 break;
5481 case dw_val_class_offset:
5482 CHECKSUM (at->dw_attr_val.v.val_offset);
5483 break;
5485 case dw_val_class_loc:
5486 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5487 loc_checksum (loc, ctx);
5488 break;
5490 case dw_val_class_die_ref:
5491 if (AT_ref (at)->die_offset)
5492 CHECKSUM (AT_ref (at)->die_offset);
5493 /* FIXME else use target die name or something. */
5495 case dw_val_class_fde_ref:
5496 case dw_val_class_lbl_id:
5497 case dw_val_class_lbl_offset:
5498 break;
5500 default:
5501 break;
5505 /* Calculate the checksum of a DIE. */
5507 static void
5508 die_checksum (die, ctx)
5509 dw_die_ref die;
5510 struct md5_ctx *ctx;
5512 dw_die_ref c;
5513 dw_attr_ref a;
5515 CHECKSUM (die->die_tag);
5517 for (a = die->die_attr; a; a = a->dw_attr_next)
5518 attr_checksum (a, ctx);
5520 for (c = die->die_child; c; c = c->die_sib)
5521 die_checksum (c, ctx);
5524 #undef CHECKSUM
5525 #undef CHECKSUM_STRING
5527 /* The prefix to attach to symbols on DIEs in the current comdat debug
5528 info section. */
5529 static char *comdat_symbol_id;
5531 /* The index of the current symbol within the current comdat CU. */
5532 static unsigned int comdat_symbol_number;
5534 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5535 children, and set comdat_symbol_id accordingly. */
5537 static void
5538 compute_section_prefix (unit_die)
5539 dw_die_ref unit_die;
5541 const char *base = lbasename (get_AT_string (unit_die, DW_AT_name));
5542 char *name = (char *) alloca (strlen (base) + 64);
5543 char *p;
5544 int i;
5545 unsigned char checksum[16];
5546 struct md5_ctx ctx;
5548 /* Compute the checksum of the DIE, then append part of it as hex digits to
5549 the name filename of the unit. */
5551 md5_init_ctx (&ctx);
5552 die_checksum (unit_die, &ctx);
5553 md5_finish_ctx (&ctx, checksum);
5555 sprintf (name, "%s.", base);
5556 clean_symbol_name (name);
5558 p = name + strlen (name);
5559 for (i = 0; i < 4; i++)
5561 sprintf (p, "%.2x", checksum[i]);
5562 p += 2;
5565 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5566 comdat_symbol_number = 0;
5569 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5571 static int
5572 is_type_die (die)
5573 dw_die_ref die;
5575 switch (die->die_tag)
5577 case DW_TAG_array_type:
5578 case DW_TAG_class_type:
5579 case DW_TAG_enumeration_type:
5580 case DW_TAG_pointer_type:
5581 case DW_TAG_reference_type:
5582 case DW_TAG_string_type:
5583 case DW_TAG_structure_type:
5584 case DW_TAG_subroutine_type:
5585 case DW_TAG_union_type:
5586 case DW_TAG_ptr_to_member_type:
5587 case DW_TAG_set_type:
5588 case DW_TAG_subrange_type:
5589 case DW_TAG_base_type:
5590 case DW_TAG_const_type:
5591 case DW_TAG_file_type:
5592 case DW_TAG_packed_type:
5593 case DW_TAG_volatile_type:
5594 return 1;
5595 default:
5596 return 0;
5600 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5601 Basically, we want to choose the bits that are likely to be shared between
5602 compilations (types) and leave out the bits that are specific to individual
5603 compilations (functions). */
5605 static int
5606 is_comdat_die (c)
5607 dw_die_ref c;
5609 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5610 we do for stabs. The advantage is a greater likelihood of sharing between
5611 objects that don't include headers in the same order (and therefore would
5612 put the base types in a different comdat). jason 8/28/00 */
5614 if (c->die_tag == DW_TAG_base_type)
5615 return 0;
5617 if (c->die_tag == DW_TAG_pointer_type
5618 || c->die_tag == DW_TAG_reference_type
5619 || c->die_tag == DW_TAG_const_type
5620 || c->die_tag == DW_TAG_volatile_type)
5622 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5624 return t ? is_comdat_die (t) : 0;
5627 return is_type_die (c);
5630 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5631 compilation unit. */
5633 static int
5634 is_symbol_die (c)
5635 dw_die_ref c;
5637 return (is_type_die (c)
5638 || (get_AT (c, DW_AT_declaration)
5639 && !get_AT (c, DW_AT_specification)));
5642 static char *
5643 gen_internal_sym (prefix)
5644 const char *prefix;
5646 char buf[256];
5647 static int label_num;
5649 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5650 return xstrdup (buf);
5653 /* Assign symbols to all worthy DIEs under DIE. */
5655 static void
5656 assign_symbol_names (die)
5657 dw_die_ref die;
5659 dw_die_ref c;
5661 if (is_symbol_die (die))
5663 if (comdat_symbol_id)
5665 char *p = alloca (strlen (comdat_symbol_id) + 64);
5667 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5668 comdat_symbol_id, comdat_symbol_number++);
5669 die->die_symbol = xstrdup (p);
5671 else
5672 die->die_symbol = gen_internal_sym ("LDIE");
5675 for (c = die->die_child; c != NULL; c = c->die_sib)
5676 assign_symbol_names (c);
5679 /* Traverse the DIE (which is always comp_unit_die), and set up
5680 additional compilation units for each of the include files we see
5681 bracketed by BINCL/EINCL. */
5683 static void
5684 break_out_includes (die)
5685 dw_die_ref die;
5687 dw_die_ref *ptr;
5688 dw_die_ref unit = NULL;
5689 limbo_die_node *node;
5691 for (ptr = &(die->die_child); *ptr;)
5693 dw_die_ref c = *ptr;
5695 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
5696 || (unit && is_comdat_die (c)))
5698 /* This DIE is for a secondary CU; remove it from the main one. */
5699 *ptr = c->die_sib;
5701 if (c->die_tag == DW_TAG_GNU_BINCL)
5703 unit = push_new_compile_unit (unit, c);
5704 free_die (c);
5706 else if (c->die_tag == DW_TAG_GNU_EINCL)
5708 unit = pop_compile_unit (unit);
5709 free_die (c);
5711 else
5712 add_child_die (unit, c);
5714 else
5716 /* Leave this DIE in the main CU. */
5717 ptr = &(c->die_sib);
5718 continue;
5722 #if 0
5723 /* We can only use this in debugging, since the frontend doesn't check
5724 to make sure that we leave every include file we enter. */
5725 if (unit != NULL)
5726 abort ();
5727 #endif
5729 assign_symbol_names (die);
5730 for (node = limbo_die_list; node; node = node->next)
5732 compute_section_prefix (node->die);
5733 assign_symbol_names (node->die);
5737 /* Traverse the DIE and add a sibling attribute if it may have the
5738 effect of speeding up access to siblings. To save some space,
5739 avoid generating sibling attributes for DIE's without children. */
5741 static void
5742 add_sibling_attributes (die)
5743 dw_die_ref die;
5745 dw_die_ref c;
5747 if (die->die_tag != DW_TAG_compile_unit
5748 && die->die_sib && die->die_child != NULL)
5749 /* Add the sibling link to the front of the attribute list. */
5750 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5752 for (c = die->die_child; c != NULL; c = c->die_sib)
5753 add_sibling_attributes (c);
5756 /* Output all location lists for the DIE and its children. */
5758 static void
5759 output_location_lists (die)
5760 dw_die_ref die;
5762 dw_die_ref c;
5763 dw_attr_ref d_attr;
5765 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5766 if (AT_class (d_attr) == dw_val_class_loc_list)
5767 output_loc_list (AT_loc_list (d_attr));
5769 for (c = die->die_child; c != NULL; c = c->die_sib)
5770 output_location_lists (c);
5774 /* The format of each DIE (and its attribute value pairs) is encoded in an
5775 abbreviation table. This routine builds the abbreviation table and assigns
5776 a unique abbreviation id for each abbreviation entry. The children of each
5777 die are visited recursively. */
5779 static void
5780 build_abbrev_table (die)
5781 dw_die_ref die;
5783 unsigned long abbrev_id;
5784 unsigned int n_alloc;
5785 dw_die_ref c;
5786 dw_attr_ref d_attr, a_attr;
5788 /* Scan the DIE references, and mark as external any that refer to
5789 DIEs from other CUs (i.e. those which are not marked). */
5790 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5791 if (AT_class (d_attr) == dw_val_class_die_ref
5792 && AT_ref (d_attr)->die_mark == 0)
5794 if (AT_ref (d_attr)->die_symbol == 0)
5795 abort ();
5797 set_AT_ref_external (d_attr, 1);
5800 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5802 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5804 if (abbrev->die_tag == die->die_tag)
5806 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5808 a_attr = abbrev->die_attr;
5809 d_attr = die->die_attr;
5811 while (a_attr != NULL && d_attr != NULL)
5813 if ((a_attr->dw_attr != d_attr->dw_attr)
5814 || (value_format (a_attr) != value_format (d_attr)))
5815 break;
5817 a_attr = a_attr->dw_attr_next;
5818 d_attr = d_attr->dw_attr_next;
5821 if (a_attr == NULL && d_attr == NULL)
5822 break;
5827 if (abbrev_id >= abbrev_die_table_in_use)
5829 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5831 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5832 abbrev_die_table
5833 = (dw_die_ref *) xrealloc (abbrev_die_table,
5834 sizeof (dw_die_ref) * n_alloc);
5836 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5837 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5838 abbrev_die_table_allocated = n_alloc;
5841 ++abbrev_die_table_in_use;
5842 abbrev_die_table[abbrev_id] = die;
5845 die->die_abbrev = abbrev_id;
5846 for (c = die->die_child; c != NULL; c = c->die_sib)
5847 build_abbrev_table (c);
5850 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5852 static int
5853 constant_size (value)
5854 long unsigned value;
5856 int log;
5858 if (value == 0)
5859 log = 0;
5860 else
5861 log = floor_log2 (value);
5863 log = log / 8;
5864 log = 1 << (floor_log2 (log) + 1);
5866 return log;
5869 /* Return the size of a DIE as it is represented in the
5870 .debug_info section. */
5872 static unsigned long
5873 size_of_die (die)
5874 dw_die_ref die;
5876 unsigned long size = 0;
5877 dw_attr_ref a;
5879 size += size_of_uleb128 (die->die_abbrev);
5880 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5882 switch (AT_class (a))
5884 case dw_val_class_addr:
5885 size += DWARF2_ADDR_SIZE;
5886 break;
5887 case dw_val_class_offset:
5888 size += DWARF_OFFSET_SIZE;
5889 break;
5890 case dw_val_class_loc:
5892 unsigned long lsize = size_of_locs (AT_loc (a));
5894 /* Block length. */
5895 size += constant_size (lsize);
5896 size += lsize;
5898 break;
5899 case dw_val_class_loc_list:
5900 size += DWARF_OFFSET_SIZE;
5901 break;
5902 case dw_val_class_range_list:
5903 size += DWARF_OFFSET_SIZE;
5904 break;
5905 case dw_val_class_const:
5906 size += size_of_sleb128 (AT_int (a));
5907 break;
5908 case dw_val_class_unsigned_const:
5909 size += constant_size (AT_unsigned (a));
5910 break;
5911 case dw_val_class_long_long:
5912 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5913 break;
5914 case dw_val_class_float:
5915 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5916 break;
5917 case dw_val_class_flag:
5918 size += 1;
5919 break;
5920 case dw_val_class_die_ref:
5921 size += DWARF_OFFSET_SIZE;
5922 break;
5923 case dw_val_class_fde_ref:
5924 size += DWARF_OFFSET_SIZE;
5925 break;
5926 case dw_val_class_lbl_id:
5927 size += DWARF2_ADDR_SIZE;
5928 break;
5929 case dw_val_class_lbl_offset:
5930 size += DWARF_OFFSET_SIZE;
5931 break;
5932 case dw_val_class_str:
5933 if (AT_string_form (a) == DW_FORM_strp)
5934 size += DWARF_OFFSET_SIZE;
5935 else
5936 size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1;
5937 break;
5938 default:
5939 abort ();
5943 return size;
5946 /* Size the debugging information associated with a given DIE. Visits the
5947 DIE's children recursively. Updates the global variable next_die_offset, on
5948 each time through. Uses the current value of next_die_offset to update the
5949 die_offset field in each DIE. */
5951 static void
5952 calc_die_sizes (die)
5953 dw_die_ref die;
5955 dw_die_ref c;
5957 die->die_offset = next_die_offset;
5958 next_die_offset += size_of_die (die);
5960 for (c = die->die_child; c != NULL; c = c->die_sib)
5961 calc_die_sizes (c);
5963 if (die->die_child != NULL)
5964 /* Count the null byte used to terminate sibling lists. */
5965 next_die_offset += 1;
5968 /* Set the marks for a die and its children. We do this so
5969 that we know whether or not a reference needs to use FORM_ref_addr; only
5970 DIEs in the same CU will be marked. We used to clear out the offset
5971 and use that as the flag, but ran into ordering problems. */
5973 static void
5974 mark_dies (die)
5975 dw_die_ref die;
5977 dw_die_ref c;
5979 die->die_mark = 1;
5980 for (c = die->die_child; c; c = c->die_sib)
5981 mark_dies (c);
5984 /* Clear the marks for a die and its children. */
5986 static void
5987 unmark_dies (die)
5988 dw_die_ref die;
5990 dw_die_ref c;
5992 die->die_mark = 0;
5993 for (c = die->die_child; c; c = c->die_sib)
5994 unmark_dies (c);
5997 /* Return the size of the .debug_pubnames table generated for the
5998 compilation unit. */
6000 static unsigned long
6001 size_of_pubnames ()
6003 unsigned long size;
6004 unsigned i;
6006 size = DWARF_PUBNAMES_HEADER_SIZE;
6007 for (i = 0; i < pubname_table_in_use; i++)
6009 pubname_ref p = &pubname_table[i];
6010 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
6013 size += DWARF_OFFSET_SIZE;
6014 return size;
6017 /* Return the size of the information in the .debug_aranges section. */
6019 static unsigned long
6020 size_of_aranges ()
6022 unsigned long size;
6024 size = DWARF_ARANGES_HEADER_SIZE;
6026 /* Count the address/length pair for this compilation unit. */
6027 size += 2 * DWARF2_ADDR_SIZE;
6028 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6030 /* Count the two zero words used to terminated the address range table. */
6031 size += 2 * DWARF2_ADDR_SIZE;
6032 return size;
6035 /* Select the encoding of an attribute value. */
6037 static enum dwarf_form
6038 value_format (a)
6039 dw_attr_ref a;
6041 switch (a->dw_attr_val.val_class)
6043 case dw_val_class_addr:
6044 return DW_FORM_addr;
6045 case dw_val_class_range_list:
6046 case dw_val_class_offset:
6047 if (DWARF_OFFSET_SIZE == 4)
6048 return DW_FORM_data4;
6049 if (DWARF_OFFSET_SIZE == 8)
6050 return DW_FORM_data8;
6051 abort ();
6052 case dw_val_class_loc_list:
6053 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6054 .debug_loc section */
6055 return DW_FORM_data4;
6056 case dw_val_class_loc:
6057 switch (constant_size (size_of_locs (AT_loc (a))))
6059 case 1:
6060 return DW_FORM_block1;
6061 case 2:
6062 return DW_FORM_block2;
6063 default:
6064 abort ();
6066 case dw_val_class_const:
6067 return DW_FORM_sdata;
6068 case dw_val_class_unsigned_const:
6069 switch (constant_size (AT_unsigned (a)))
6071 case 1:
6072 return DW_FORM_data1;
6073 case 2:
6074 return DW_FORM_data2;
6075 case 4:
6076 return DW_FORM_data4;
6077 case 8:
6078 return DW_FORM_data8;
6079 default:
6080 abort ();
6082 case dw_val_class_long_long:
6083 return DW_FORM_block1;
6084 case dw_val_class_float:
6085 return DW_FORM_block1;
6086 case dw_val_class_flag:
6087 return DW_FORM_flag;
6088 case dw_val_class_die_ref:
6089 if (AT_ref_external (a))
6090 return DW_FORM_ref_addr;
6091 else
6092 return DW_FORM_ref;
6093 case dw_val_class_fde_ref:
6094 return DW_FORM_data;
6095 case dw_val_class_lbl_id:
6096 return DW_FORM_addr;
6097 case dw_val_class_lbl_offset:
6098 return DW_FORM_data;
6099 case dw_val_class_str:
6100 return AT_string_form (a);
6102 default:
6103 abort ();
6107 /* Output the encoding of an attribute value. */
6109 static void
6110 output_value_format (a)
6111 dw_attr_ref a;
6113 enum dwarf_form form = value_format (a);
6115 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6118 /* Output the .debug_abbrev section which defines the DIE abbreviation
6119 table. */
6121 static void
6122 output_abbrev_section ()
6124 unsigned long abbrev_id;
6126 dw_attr_ref a_attr;
6128 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6130 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6132 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6133 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6134 dwarf_tag_name (abbrev->die_tag));
6136 if (abbrev->die_child != NULL)
6137 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6138 else
6139 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6141 for (a_attr = abbrev->die_attr; a_attr != NULL;
6142 a_attr = a_attr->dw_attr_next)
6144 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6145 dwarf_attr_name (a_attr->dw_attr));
6146 output_value_format (a_attr);
6149 dw2_asm_output_data (1, 0, NULL);
6150 dw2_asm_output_data (1, 0, NULL);
6153 /* Terminate the table. */
6154 dw2_asm_output_data (1, 0, NULL);
6157 /* Output a symbol we can use to refer to this DIE from another CU. */
6159 static inline void
6160 output_die_symbol (die)
6161 dw_die_ref die;
6163 char *sym = die->die_symbol;
6165 if (sym == 0)
6166 return;
6168 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6169 /* We make these global, not weak; if the target doesn't support
6170 .linkonce, it doesn't support combining the sections, so debugging
6171 will break. */
6172 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6174 ASM_OUTPUT_LABEL (asm_out_file, sym);
6177 /* Return a new location list, given the begin and end range, and the
6178 expression. gensym tells us whether to generate a new internal symbol for
6179 this location list node, which is done for the head of the list only. */
6181 static inline dw_loc_list_ref
6182 new_loc_list (expr, begin, end, section, gensym)
6183 dw_loc_descr_ref expr;
6184 const char *begin;
6185 const char *end;
6186 const char *section;
6187 unsigned gensym;
6189 dw_loc_list_ref retlist
6190 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6192 retlist->begin = begin;
6193 retlist->end = end;
6194 retlist->expr = expr;
6195 retlist->section = section;
6196 if (gensym)
6197 retlist->ll_symbol = gen_internal_sym ("LLST");
6199 return retlist;
6202 /* Add a location description expression to a location list */
6204 static inline void
6205 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6206 dw_loc_list_ref *list_head;
6207 dw_loc_descr_ref descr;
6208 const char *begin;
6209 const char *end;
6210 const char *section;
6212 dw_loc_list_ref *d;
6214 /* Find the end of the chain. */
6215 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6218 /* Add a new location list node to the list */
6219 *d = new_loc_list (descr, begin, end, section, 0);
6222 /* Output the location list given to us */
6224 static void
6225 output_loc_list (list_head)
6226 dw_loc_list_ref list_head;
6228 dw_loc_list_ref curr = list_head;
6230 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6232 /* ??? This shouldn't be needed now that we've forced the
6233 compilation unit base address to zero when there is code
6234 in more than one section. */
6235 if (strcmp (curr->section, ".text") == 0)
6237 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6238 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
6239 "Location list base address specifier fake entry");
6240 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6241 "Location list base address specifier base");
6244 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
6246 unsigned long size;
6248 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6249 "Location list begin address (%s)",
6250 list_head->ll_symbol);
6251 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6252 "Location list end address (%s)",
6253 list_head->ll_symbol);
6254 size = size_of_locs (curr->expr);
6256 /* Output the block length for this list of location operations. */
6257 if (size > 0xffff)
6258 abort ();
6259 dw2_asm_output_data (2, size, "%s", "Location expression size");
6261 output_loc_sequence (curr->expr);
6264 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6265 "Location list terminator begin (%s)",
6266 list_head->ll_symbol);
6267 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6268 "Location list terminator end (%s)",
6269 list_head->ll_symbol);
6272 /* Output the DIE and its attributes. Called recursively to generate
6273 the definitions of each child DIE. */
6275 static void
6276 output_die (die)
6277 dw_die_ref die;
6279 dw_attr_ref a;
6280 dw_die_ref c;
6281 unsigned long size;
6283 /* If someone in another CU might refer to us, set up a symbol for
6284 them to point to. */
6285 if (die->die_symbol)
6286 output_die_symbol (die);
6288 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6289 die->die_offset, dwarf_tag_name (die->die_tag));
6291 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6293 const char *name = dwarf_attr_name (a->dw_attr);
6295 switch (AT_class (a))
6297 case dw_val_class_addr:
6298 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6299 break;
6301 case dw_val_class_offset:
6302 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6303 "%s", name);
6304 break;
6306 case dw_val_class_range_list:
6308 char *p = strchr (ranges_section_label, '\0');
6310 sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset);
6311 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6312 "%s", name);
6313 *p = '\0';
6315 break;
6317 case dw_val_class_loc:
6318 size = size_of_locs (AT_loc (a));
6320 /* Output the block length for this list of location operations. */
6321 dw2_asm_output_data (constant_size (size), size, "%s", name);
6323 output_loc_sequence (AT_loc (a));
6324 break;
6326 case dw_val_class_const:
6327 /* ??? It would be slightly more efficient to use a scheme like is
6328 used for unsigned constants below, but gdb 4.x does not sign
6329 extend. Gdb 5.x does sign extend. */
6330 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6331 break;
6333 case dw_val_class_unsigned_const:
6334 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6335 AT_unsigned (a), "%s", name);
6336 break;
6338 case dw_val_class_long_long:
6340 unsigned HOST_WIDE_INT first, second;
6342 dw2_asm_output_data (1,
6343 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6344 "%s", name);
6346 if (WORDS_BIG_ENDIAN)
6348 first = a->dw_attr_val.v.val_long_long.hi;
6349 second = a->dw_attr_val.v.val_long_long.low;
6351 else
6353 first = a->dw_attr_val.v.val_long_long.low;
6354 second = a->dw_attr_val.v.val_long_long.hi;
6357 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6358 first, "long long constant");
6359 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6360 second, NULL);
6362 break;
6364 case dw_val_class_float:
6366 unsigned int i;
6368 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6369 "%s", name);
6371 for (i = 0; i < a->dw_attr_val.v.val_float.length; i++)
6372 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6373 "fp constant word %u", i);
6374 break;
6377 case dw_val_class_flag:
6378 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6379 break;
6381 case dw_val_class_loc_list:
6383 char *sym = AT_loc_list (a)->ll_symbol;
6385 if (sym == 0)
6386 abort ();
6387 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6388 loc_section_label, "%s", name);
6390 break;
6392 case dw_val_class_die_ref:
6393 if (AT_ref_external (a))
6395 char *sym = AT_ref (a)->die_symbol;
6397 if (sym == 0)
6398 abort ();
6399 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6401 else if (AT_ref (a)->die_offset == 0)
6402 abort ();
6403 else
6404 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6405 "%s", name);
6406 break;
6408 case dw_val_class_fde_ref:
6410 char l1[20];
6412 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6413 a->dw_attr_val.v.val_fde_index * 2);
6414 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6416 break;
6418 case dw_val_class_lbl_id:
6419 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6420 break;
6422 case dw_val_class_lbl_offset:
6423 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6424 break;
6426 case dw_val_class_str:
6427 if (AT_string_form (a) == DW_FORM_strp)
6428 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6429 a->dw_attr_val.v.val_str->label,
6430 "%s: \"%s\"", name, AT_string (a));
6431 else
6432 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6433 break;
6435 default:
6436 abort ();
6440 for (c = die->die_child; c != NULL; c = c->die_sib)
6441 output_die (c);
6443 /* Add null byte to terminate sibling list. */
6444 if (die->die_child != NULL)
6445 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6446 die->die_offset);
6449 /* Output the compilation unit that appears at the beginning of the
6450 .debug_info section, and precedes the DIE descriptions. */
6452 static void
6453 output_compilation_unit_header ()
6455 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6456 "Length of Compilation Unit Info");
6457 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6458 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6459 "Offset Into Abbrev. Section");
6460 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6463 /* Output the compilation unit DIE and its children. */
6465 static void
6466 output_comp_unit (die)
6467 dw_die_ref die;
6469 const char *secname;
6471 /* Even if there are no children of this DIE, we must output the information
6472 about the compilation unit. Otherwise, on an empty translation unit, we
6473 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6474 will then complain when examining the file. First mark all the DIEs in
6475 this CU so we know which get local refs. */
6476 mark_dies (die);
6478 build_abbrev_table (die);
6480 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6481 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6482 calc_die_sizes (die);
6484 if (die->die_symbol)
6486 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6488 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6489 secname = tmp;
6490 die->die_symbol = NULL;
6492 else
6493 secname = (const char *) DEBUG_INFO_SECTION;
6495 /* Output debugging information. */
6496 named_section_flags (secname, SECTION_DEBUG);
6497 output_compilation_unit_header ();
6498 output_die (die);
6500 /* Leave the marks on the main CU, so we can check them in
6501 output_pubnames. */
6502 if (die->die_symbol)
6503 unmark_dies (die);
6506 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6507 output of lang_hooks.decl_printable_name for C++ looks like
6508 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6510 static const char *
6511 dwarf2_name (decl, scope)
6512 tree decl;
6513 int scope;
6515 return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0);
6518 /* Add a new entry to .debug_pubnames if appropriate. */
6520 static void
6521 add_pubname (decl, die)
6522 tree decl;
6523 dw_die_ref die;
6525 pubname_ref p;
6527 if (! TREE_PUBLIC (decl))
6528 return;
6530 if (pubname_table_in_use == pubname_table_allocated)
6532 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6533 pubname_table
6534 = (pubname_ref) xrealloc (pubname_table,
6535 (pubname_table_allocated
6536 * sizeof (pubname_entry)));
6539 p = &pubname_table[pubname_table_in_use++];
6540 p->die = die;
6541 p->name = xstrdup (dwarf2_name (decl, 1));
6544 /* Output the public names table used to speed up access to externally
6545 visible names. For now, only generate entries for externally
6546 visible procedures. */
6548 static void
6549 output_pubnames ()
6551 unsigned i;
6552 unsigned long pubnames_length = size_of_pubnames ();
6554 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6555 "Length of Public Names Info");
6556 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6557 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6558 "Offset of Compilation Unit Info");
6559 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6560 "Compilation Unit Length");
6562 for (i = 0; i < pubname_table_in_use; i++)
6564 pubname_ref pub = &pubname_table[i];
6566 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6567 if (pub->die->die_mark == 0)
6568 abort ();
6570 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6571 "DIE offset");
6573 dw2_asm_output_nstring (pub->name, -1, "external name");
6576 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6579 /* Add a new entry to .debug_aranges if appropriate. */
6581 static void
6582 add_arange (decl, die)
6583 tree decl;
6584 dw_die_ref die;
6586 if (! DECL_SECTION_NAME (decl))
6587 return;
6589 if (arange_table_in_use == arange_table_allocated)
6591 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6592 arange_table = (dw_die_ref *)
6593 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6596 arange_table[arange_table_in_use++] = die;
6599 /* Output the information that goes into the .debug_aranges table.
6600 Namely, define the beginning and ending address range of the
6601 text section generated for this compilation unit. */
6603 static void
6604 output_aranges ()
6606 unsigned i;
6607 unsigned long aranges_length = size_of_aranges ();
6609 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6610 "Length of Address Ranges Info");
6611 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6612 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6613 "Offset of Compilation Unit Info");
6614 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6615 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6617 /* We need to align to twice the pointer size here. */
6618 if (DWARF_ARANGES_PAD_SIZE)
6620 /* Pad using a 2 byte words so that padding is correct for any
6621 pointer size. */
6622 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6623 2 * DWARF2_ADDR_SIZE);
6624 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6625 dw2_asm_output_data (2, 0, NULL);
6628 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6629 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6630 text_section_label, "Length");
6632 for (i = 0; i < arange_table_in_use; i++)
6634 dw_die_ref die = arange_table[i];
6636 /* We shouldn't see aranges for DIEs outside of the main CU. */
6637 if (die->die_mark == 0)
6638 abort ();
6640 if (die->die_tag == DW_TAG_subprogram)
6642 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6643 "Address");
6644 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6645 get_AT_low_pc (die), "Length");
6647 else
6649 /* A static variable; extract the symbol from DW_AT_location.
6650 Note that this code isn't currently hit, as we only emit
6651 aranges for functions (jason 9/23/99). */
6652 dw_attr_ref a = get_AT (die, DW_AT_location);
6653 dw_loc_descr_ref loc;
6655 if (! a || AT_class (a) != dw_val_class_loc)
6656 abort ();
6658 loc = AT_loc (a);
6659 if (loc->dw_loc_opc != DW_OP_addr)
6660 abort ();
6662 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6663 loc->dw_loc_oprnd1.v.val_addr, "Address");
6664 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6665 get_AT_unsigned (die, DW_AT_byte_size),
6666 "Length");
6670 /* Output the terminator words. */
6671 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6672 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6675 /* Add a new entry to .debug_ranges. Return the offset at which it
6676 was placed. */
6678 static unsigned int
6679 add_ranges (block)
6680 tree block;
6682 unsigned int in_use = ranges_table_in_use;
6684 if (in_use == ranges_table_allocated)
6686 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6687 ranges_table = (dw_ranges_ref)
6688 xrealloc (ranges_table, (ranges_table_allocated
6689 * sizeof (struct dw_ranges_struct)));
6692 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6693 ranges_table_in_use = in_use + 1;
6695 return in_use * 2 * DWARF2_ADDR_SIZE;
6698 static void
6699 output_ranges ()
6701 unsigned i;
6702 static const char *const start_fmt = "Offset 0x%x";
6703 const char *fmt = start_fmt;
6705 for (i = 0; i < ranges_table_in_use; i++)
6707 int block_num = ranges_table[i].block_num;
6709 if (block_num)
6711 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6712 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6714 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6715 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6717 /* If all code is in the text section, then the compilation
6718 unit base address defaults to DW_AT_low_pc, which is the
6719 base of the text section. */
6720 if (separate_line_info_table_in_use == 0)
6722 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6723 text_section_label,
6724 fmt, i * 2 * DWARF2_ADDR_SIZE);
6725 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6726 text_section_label, NULL);
6729 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6730 compilation unit base address to zero, which allows us to
6731 use absolute addresses, and not worry about whether the
6732 target supports cross-section arithmetic. */
6733 else
6735 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6736 fmt, i * 2 * DWARF2_ADDR_SIZE);
6737 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6740 fmt = NULL;
6742 else
6744 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6745 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6746 fmt = start_fmt;
6751 /* Data structure containing information about input files. */
6752 struct file_info
6754 char *path; /* Complete file name. */
6755 char *fname; /* File name part. */
6756 int length; /* Length of entire string. */
6757 int file_idx; /* Index in input file table. */
6758 int dir_idx; /* Index in directory table. */
6761 /* Data structure containing information about directories with source
6762 files. */
6763 struct dir_info
6765 char *path; /* Path including directory name. */
6766 int length; /* Path length. */
6767 int prefix; /* Index of directory entry which is a prefix. */
6768 int count; /* Number of files in this directory. */
6769 int dir_idx; /* Index of directory used as base. */
6770 int used; /* Used in the end? */
6773 /* Callback function for file_info comparison. We sort by looking at
6774 the directories in the path. */
6776 static int
6777 file_info_cmp (p1, p2)
6778 const void *p1;
6779 const void *p2;
6781 const struct file_info *s1 = p1;
6782 const struct file_info *s2 = p2;
6783 unsigned char *cp1;
6784 unsigned char *cp2;
6786 /* Take care of file names without directories. We need to make sure that
6787 we return consistent values to qsort since some will get confused if
6788 we return the same value when identical operands are passed in opposite
6789 orders. So if neither has a directory, return 0 and otherwise return
6790 1 or -1 depending on which one has the directory. */
6791 if ((s1->path == s1->fname || s2->path == s2->fname))
6792 return (s2->path == s2->fname) - (s1->path == s1->fname);
6794 cp1 = (unsigned char *) s1->path;
6795 cp2 = (unsigned char *) s2->path;
6797 while (1)
6799 ++cp1;
6800 ++cp2;
6801 /* Reached the end of the first path? If so, handle like above. */
6802 if ((cp1 == (unsigned char *) s1->fname)
6803 || (cp2 == (unsigned char *) s2->fname))
6804 return ((cp2 == (unsigned char *) s2->fname)
6805 - (cp1 == (unsigned char *) s1->fname));
6807 /* Character of current path component the same? */
6808 else if (*cp1 != *cp2)
6809 return *cp1 - *cp2;
6813 /* Output the directory table and the file name table. We try to minimize
6814 the total amount of memory needed. A heuristic is used to avoid large
6815 slowdowns with many input files. */
6817 static void
6818 output_file_names ()
6820 struct file_info *files;
6821 struct dir_info *dirs;
6822 int *saved;
6823 int *savehere;
6824 int *backmap;
6825 int ndirs;
6826 int idx_offset;
6827 int i;
6828 int idx;
6830 /* Allocate the various arrays we need. */
6831 files = (struct file_info *) alloca (file_table.in_use
6832 * sizeof (struct file_info));
6833 dirs = (struct dir_info *) alloca (file_table.in_use
6834 * sizeof (struct dir_info));
6836 /* Sort the file names. */
6837 for (i = 1; i < (int) file_table.in_use; i++)
6839 char *f;
6841 /* Skip all leading "./". */
6842 f = file_table.table[i];
6843 while (f[0] == '.' && f[1] == '/')
6844 f += 2;
6846 /* Create a new array entry. */
6847 files[i].path = f;
6848 files[i].length = strlen (f);
6849 files[i].file_idx = i;
6851 /* Search for the file name part. */
6852 f = strrchr (f, '/');
6853 files[i].fname = f == NULL ? files[i].path : f + 1;
6856 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6858 /* Find all the different directories used. */
6859 dirs[0].path = files[1].path;
6860 dirs[0].length = files[1].fname - files[1].path;
6861 dirs[0].prefix = -1;
6862 dirs[0].count = 1;
6863 dirs[0].dir_idx = 0;
6864 dirs[0].used = 0;
6865 files[1].dir_idx = 0;
6866 ndirs = 1;
6868 for (i = 2; i < (int) file_table.in_use; i++)
6869 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6870 && memcmp (dirs[ndirs - 1].path, files[i].path,
6871 dirs[ndirs - 1].length) == 0)
6873 /* Same directory as last entry. */
6874 files[i].dir_idx = ndirs - 1;
6875 ++dirs[ndirs - 1].count;
6877 else
6879 int j;
6881 /* This is a new directory. */
6882 dirs[ndirs].path = files[i].path;
6883 dirs[ndirs].length = files[i].fname - files[i].path;
6884 dirs[ndirs].count = 1;
6885 dirs[ndirs].dir_idx = ndirs;
6886 dirs[ndirs].used = 0;
6887 files[i].dir_idx = ndirs;
6889 /* Search for a prefix. */
6890 dirs[ndirs].prefix = -1;
6891 for (j = 0; j < ndirs; j++)
6892 if (dirs[j].length < dirs[ndirs].length
6893 && dirs[j].length > 1
6894 && (dirs[ndirs].prefix == -1
6895 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6896 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6897 dirs[ndirs].prefix = j;
6899 ++ndirs;
6902 /* Now to the actual work. We have to find a subset of the directories which
6903 allow expressing the file name using references to the directory table
6904 with the least amount of characters. We do not do an exhaustive search
6905 where we would have to check out every combination of every single
6906 possible prefix. Instead we use a heuristic which provides nearly optimal
6907 results in most cases and never is much off. */
6908 saved = (int *) alloca (ndirs * sizeof (int));
6909 savehere = (int *) alloca (ndirs * sizeof (int));
6911 memset (saved, '\0', ndirs * sizeof (saved[0]));
6912 for (i = 0; i < ndirs; i++)
6914 int j;
6915 int total;
6917 /* We can always save some space for the current directory. But this
6918 does not mean it will be enough to justify adding the directory. */
6919 savehere[i] = dirs[i].length;
6920 total = (savehere[i] - saved[i]) * dirs[i].count;
6922 for (j = i + 1; j < ndirs; j++)
6924 savehere[j] = 0;
6925 if (saved[j] < dirs[i].length)
6927 /* Determine whether the dirs[i] path is a prefix of the
6928 dirs[j] path. */
6929 int k;
6931 k = dirs[j].prefix;
6932 while (k != -1 && k != i)
6933 k = dirs[k].prefix;
6935 if (k == i)
6937 /* Yes it is. We can possibly safe some memory but
6938 writing the filenames in dirs[j] relative to
6939 dirs[i]. */
6940 savehere[j] = dirs[i].length;
6941 total += (savehere[j] - saved[j]) * dirs[j].count;
6946 /* Check whether we can safe enough to justify adding the dirs[i]
6947 directory. */
6948 if (total > dirs[i].length + 1)
6950 /* It's worthwhile adding. */
6951 for (j = i; j < ndirs; j++)
6952 if (savehere[j] > 0)
6954 /* Remember how much we saved for this directory so far. */
6955 saved[j] = savehere[j];
6957 /* Remember the prefix directory. */
6958 dirs[j].dir_idx = i;
6963 /* We have to emit them in the order they appear in the file_table array
6964 since the index is used in the debug info generation. To do this
6965 efficiently we generate a back-mapping of the indices first. */
6966 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6967 for (i = 1; i < (int) file_table.in_use; i++)
6969 backmap[files[i].file_idx] = i;
6971 /* Mark this directory as used. */
6972 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6975 /* That was it. We are ready to emit the information. First emit the
6976 directory name table. We have to make sure the first actually emitted
6977 directory name has index one; zero is reserved for the current working
6978 directory. Make sure we do not confuse these indices with the one for the
6979 constructed table (even though most of the time they are identical). */
6980 idx = 1;
6981 idx_offset = dirs[0].length > 0 ? 1 : 0;
6982 for (i = 1 - idx_offset; i < ndirs; i++)
6983 if (dirs[i].used != 0)
6985 dirs[i].used = idx++;
6986 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6987 "Directory Entry: 0x%x", dirs[i].used);
6990 dw2_asm_output_data (1, 0, "End directory table");
6992 /* Correct the index for the current working directory entry if it
6993 exists. */
6994 if (idx_offset == 0)
6995 dirs[0].used = 0;
6997 /* Now write all the file names. */
6998 for (i = 1; i < (int) file_table.in_use; i++)
7000 int file_idx = backmap[i];
7001 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
7003 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
7004 "File Entry: 0x%x", i);
7006 /* Include directory index. */
7007 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
7009 /* Modification time. */
7010 dw2_asm_output_data_uleb128 (0, NULL);
7012 /* File length in bytes. */
7013 dw2_asm_output_data_uleb128 (0, NULL);
7016 dw2_asm_output_data (1, 0, "End file name table");
7020 /* Output the source line number correspondence information. This
7021 information goes into the .debug_line section. */
7023 static void
7024 output_line_info ()
7026 char l1[20], l2[20], p1[20], p2[20];
7027 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7028 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7029 unsigned opc;
7030 unsigned n_op_args;
7031 unsigned long lt_index;
7032 unsigned long current_line;
7033 long line_offset;
7034 long line_delta;
7035 unsigned long current_file;
7036 unsigned long function;
7038 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7039 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7040 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7041 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7043 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7044 "Length of Source Line Info");
7045 ASM_OUTPUT_LABEL (asm_out_file, l1);
7047 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7048 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7049 ASM_OUTPUT_LABEL (asm_out_file, p1);
7051 /* Define the architecture-dependent minimum instruction length (in
7052 bytes). In this implementation of DWARF, this field is used for
7053 information purposes only. Since GCC generates assembly language,
7054 we have no a priori knowledge of how many instruction bytes are
7055 generated for each source line, and therefore can use only the
7056 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7057 commands. Accordingly, we fix this as `1', which is "correct
7058 enough" for all architectures, and don't let the target override. */
7059 dw2_asm_output_data (1, 1,
7060 "Minimum Instruction Length");
7062 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7063 "Default is_stmt_start flag");
7064 dw2_asm_output_data (1, DWARF_LINE_BASE,
7065 "Line Base Value (Special Opcodes)");
7066 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7067 "Line Range Value (Special Opcodes)");
7068 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7069 "Special Opcode Base");
7071 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7073 switch (opc)
7075 case DW_LNS_advance_pc:
7076 case DW_LNS_advance_line:
7077 case DW_LNS_set_file:
7078 case DW_LNS_set_column:
7079 case DW_LNS_fixed_advance_pc:
7080 n_op_args = 1;
7081 break;
7082 default:
7083 n_op_args = 0;
7084 break;
7087 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7088 opc, n_op_args);
7091 /* Write out the information about the files we use. */
7092 output_file_names ();
7093 ASM_OUTPUT_LABEL (asm_out_file, p2);
7095 /* We used to set the address register to the first location in the text
7096 section here, but that didn't accomplish anything since we already
7097 have a line note for the opening brace of the first function. */
7099 /* Generate the line number to PC correspondence table, encoded as
7100 a series of state machine operations. */
7101 current_file = 1;
7102 current_line = 1;
7103 strcpy (prev_line_label, text_section_label);
7104 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7106 dw_line_info_ref line_info = &line_info_table[lt_index];
7108 #if 0
7109 /* Disable this optimization for now; GDB wants to see two line notes
7110 at the beginning of a function so it can find the end of the
7111 prologue. */
7113 /* Don't emit anything for redundant notes. Just updating the
7114 address doesn't accomplish anything, because we already assume
7115 that anything after the last address is this line. */
7116 if (line_info->dw_line_num == current_line
7117 && line_info->dw_file_num == current_file)
7118 continue;
7119 #endif
7121 /* Emit debug info for the address of the current line.
7123 Unfortunately, we have little choice here currently, and must always
7124 use the most general form. GCC does not know the address delta
7125 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7126 attributes which will give an upper bound on the address range. We
7127 could perhaps use length attributes to determine when it is safe to
7128 use DW_LNS_fixed_advance_pc. */
7130 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7131 if (0)
7133 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7134 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7135 "DW_LNS_fixed_advance_pc");
7136 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7138 else
7140 /* This can handle any delta. This takes
7141 4+DWARF2_ADDR_SIZE bytes. */
7142 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7143 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7144 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7145 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7148 strcpy (prev_line_label, line_label);
7150 /* Emit debug info for the source file of the current line, if
7151 different from the previous line. */
7152 if (line_info->dw_file_num != current_file)
7154 current_file = line_info->dw_file_num;
7155 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7156 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7157 file_table.table[current_file]);
7160 /* Emit debug info for the current line number, choosing the encoding
7161 that uses the least amount of space. */
7162 if (line_info->dw_line_num != current_line)
7164 line_offset = line_info->dw_line_num - current_line;
7165 line_delta = line_offset - DWARF_LINE_BASE;
7166 current_line = line_info->dw_line_num;
7167 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7168 /* This can handle deltas from -10 to 234, using the current
7169 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7170 takes 1 byte. */
7171 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7172 "line %lu", current_line);
7173 else
7175 /* This can handle any delta. This takes at least 4 bytes,
7176 depending on the value being encoded. */
7177 dw2_asm_output_data (1, DW_LNS_advance_line,
7178 "advance to line %lu", current_line);
7179 dw2_asm_output_data_sleb128 (line_offset, NULL);
7180 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7183 else
7184 /* We still need to start a new row, so output a copy insn. */
7185 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7188 /* Emit debug info for the address of the end of the function. */
7189 if (0)
7191 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7192 "DW_LNS_fixed_advance_pc");
7193 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7195 else
7197 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7198 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7199 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7200 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7203 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7204 dw2_asm_output_data_uleb128 (1, NULL);
7205 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7207 function = 0;
7208 current_file = 1;
7209 current_line = 1;
7210 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7212 dw_separate_line_info_ref line_info
7213 = &separate_line_info_table[lt_index];
7215 #if 0
7216 /* Don't emit anything for redundant notes. */
7217 if (line_info->dw_line_num == current_line
7218 && line_info->dw_file_num == current_file
7219 && line_info->function == function)
7220 goto cont;
7221 #endif
7223 /* Emit debug info for the address of the current line. If this is
7224 a new function, or the first line of a function, then we need
7225 to handle it differently. */
7226 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7227 lt_index);
7228 if (function != line_info->function)
7230 function = line_info->function;
7232 /* Set the address register to the first line in the function */
7233 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7234 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7235 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7236 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7238 else
7240 /* ??? See the DW_LNS_advance_pc comment above. */
7241 if (0)
7243 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7244 "DW_LNS_fixed_advance_pc");
7245 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7247 else
7249 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7250 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7251 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7252 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7256 strcpy (prev_line_label, line_label);
7258 /* Emit debug info for the source file of the current line, if
7259 different from the previous line. */
7260 if (line_info->dw_file_num != current_file)
7262 current_file = line_info->dw_file_num;
7263 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7264 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7265 file_table.table[current_file]);
7268 /* Emit debug info for the current line number, choosing the encoding
7269 that uses the least amount of space. */
7270 if (line_info->dw_line_num != current_line)
7272 line_offset = line_info->dw_line_num - current_line;
7273 line_delta = line_offset - DWARF_LINE_BASE;
7274 current_line = line_info->dw_line_num;
7275 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7276 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7277 "line %lu", current_line);
7278 else
7280 dw2_asm_output_data (1, DW_LNS_advance_line,
7281 "advance to line %lu", current_line);
7282 dw2_asm_output_data_sleb128 (line_offset, NULL);
7283 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7286 else
7287 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7289 #if 0
7290 cont:
7291 #endif
7293 lt_index++;
7295 /* If we're done with a function, end its sequence. */
7296 if (lt_index == separate_line_info_table_in_use
7297 || separate_line_info_table[lt_index].function != function)
7299 current_file = 1;
7300 current_line = 1;
7302 /* Emit debug info for the address of the end of the function. */
7303 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7304 if (0)
7306 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7307 "DW_LNS_fixed_advance_pc");
7308 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7310 else
7312 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7313 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7314 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7315 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7318 /* Output the marker for the end of this sequence. */
7319 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7320 dw2_asm_output_data_uleb128 (1, NULL);
7321 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7325 /* Output the marker for the end of the line number info. */
7326 ASM_OUTPUT_LABEL (asm_out_file, l2);
7329 /* Given a pointer to a tree node for some base type, return a pointer to
7330 a DIE that describes the given type.
7332 This routine must only be called for GCC type nodes that correspond to
7333 Dwarf base (fundamental) types. */
7335 static dw_die_ref
7336 base_type_die (type)
7337 tree type;
7339 dw_die_ref base_type_result;
7340 const char *type_name;
7341 enum dwarf_type encoding;
7342 tree name = TYPE_NAME (type);
7344 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7345 return 0;
7347 if (name)
7349 if (TREE_CODE (name) == TYPE_DECL)
7350 name = DECL_NAME (name);
7352 type_name = IDENTIFIER_POINTER (name);
7354 else
7355 type_name = "__unknown__";
7357 switch (TREE_CODE (type))
7359 case INTEGER_TYPE:
7360 /* Carefully distinguish the C character types, without messing
7361 up if the language is not C. Note that we check only for the names
7362 that contain spaces; other names might occur by coincidence in other
7363 languages. */
7364 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7365 && (type == char_type_node
7366 || ! strcmp (type_name, "signed char")
7367 || ! strcmp (type_name, "unsigned char"))))
7369 if (TREE_UNSIGNED (type))
7370 encoding = DW_ATE_unsigned;
7371 else
7372 encoding = DW_ATE_signed;
7373 break;
7375 /* else fall through. */
7377 case CHAR_TYPE:
7378 /* GNU Pascal/Ada CHAR type. Not used in C. */
7379 if (TREE_UNSIGNED (type))
7380 encoding = DW_ATE_unsigned_char;
7381 else
7382 encoding = DW_ATE_signed_char;
7383 break;
7385 case REAL_TYPE:
7386 encoding = DW_ATE_float;
7387 break;
7389 /* Dwarf2 doesn't know anything about complex ints, so use
7390 a user defined type for it. */
7391 case COMPLEX_TYPE:
7392 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7393 encoding = DW_ATE_complex_float;
7394 else
7395 encoding = DW_ATE_lo_user;
7396 break;
7398 case BOOLEAN_TYPE:
7399 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7400 encoding = DW_ATE_boolean;
7401 break;
7403 default:
7404 /* No other TREE_CODEs are Dwarf fundamental types. */
7405 abort ();
7408 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
7409 if (demangle_name_func)
7410 type_name = (*demangle_name_func) (type_name);
7412 add_AT_string (base_type_result, DW_AT_name, type_name);
7413 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7414 int_size_in_bytes (type));
7415 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7417 return base_type_result;
7420 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7421 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7422 a given type is generally the same as the given type, except that if the
7423 given type is a pointer or reference type, then the root type of the given
7424 type is the root type of the "basis" type for the pointer or reference
7425 type. (This definition of the "root" type is recursive.) Also, the root
7426 type of a `const' qualified type or a `volatile' qualified type is the
7427 root type of the given type without the qualifiers. */
7429 static tree
7430 root_type (type)
7431 tree type;
7433 if (TREE_CODE (type) == ERROR_MARK)
7434 return error_mark_node;
7436 switch (TREE_CODE (type))
7438 case ERROR_MARK:
7439 return error_mark_node;
7441 case POINTER_TYPE:
7442 case REFERENCE_TYPE:
7443 return type_main_variant (root_type (TREE_TYPE (type)));
7445 default:
7446 return type_main_variant (type);
7450 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7451 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7453 static inline int
7454 is_base_type (type)
7455 tree type;
7457 switch (TREE_CODE (type))
7459 case ERROR_MARK:
7460 case VOID_TYPE:
7461 case INTEGER_TYPE:
7462 case REAL_TYPE:
7463 case COMPLEX_TYPE:
7464 case BOOLEAN_TYPE:
7465 case CHAR_TYPE:
7466 return 1;
7468 case SET_TYPE:
7469 case ARRAY_TYPE:
7470 case RECORD_TYPE:
7471 case UNION_TYPE:
7472 case QUAL_UNION_TYPE:
7473 case ENUMERAL_TYPE:
7474 case FUNCTION_TYPE:
7475 case METHOD_TYPE:
7476 case POINTER_TYPE:
7477 case REFERENCE_TYPE:
7478 case FILE_TYPE:
7479 case OFFSET_TYPE:
7480 case LANG_TYPE:
7481 case VECTOR_TYPE:
7482 return 0;
7484 default:
7485 abort ();
7488 return 0;
7491 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7492 entry that chains various modifiers in front of the given type. */
7494 static dw_die_ref
7495 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7496 tree type;
7497 int is_const_type;
7498 int is_volatile_type;
7499 dw_die_ref context_die;
7501 enum tree_code code = TREE_CODE (type);
7502 dw_die_ref mod_type_die = NULL;
7503 dw_die_ref sub_die = NULL;
7504 tree item_type = NULL;
7506 if (code != ERROR_MARK)
7508 tree qualified_type;
7510 /* See if we already have the appropriately qualified variant of
7511 this type. */
7512 qualified_type
7513 = get_qualified_type (type,
7514 ((is_const_type ? TYPE_QUAL_CONST : 0)
7515 | (is_volatile_type
7516 ? TYPE_QUAL_VOLATILE : 0)));
7518 /* If we do, then we can just use its DIE, if it exists. */
7519 if (qualified_type)
7521 mod_type_die = lookup_type_die (qualified_type);
7522 if (mod_type_die)
7523 return mod_type_die;
7526 /* Handle C typedef types. */
7527 if (qualified_type && TYPE_NAME (qualified_type)
7528 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7529 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7531 tree type_name = TYPE_NAME (qualified_type);
7532 tree dtype = TREE_TYPE (type_name);
7534 if (qualified_type == dtype)
7536 /* For a named type, use the typedef. */
7537 gen_type_die (qualified_type, context_die);
7538 mod_type_die = lookup_type_die (qualified_type);
7540 else if (is_const_type < TYPE_READONLY (dtype)
7541 || is_volatile_type < TYPE_VOLATILE (dtype))
7542 /* cv-unqualified version of named type. Just use the unnamed
7543 type to which it refers. */
7544 mod_type_die
7545 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7546 is_const_type, is_volatile_type,
7547 context_die);
7549 /* Else cv-qualified version of named type; fall through. */
7552 if (mod_type_die)
7553 /* OK. */
7555 else if (is_const_type)
7557 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
7558 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7560 else if (is_volatile_type)
7562 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
7563 sub_die = modified_type_die (type, 0, 0, context_die);
7565 else if (code == POINTER_TYPE)
7567 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
7568 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7569 #if 0
7570 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7571 #endif
7572 item_type = TREE_TYPE (type);
7574 else if (code == REFERENCE_TYPE)
7576 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
7577 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7578 #if 0
7579 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7580 #endif
7581 item_type = TREE_TYPE (type);
7583 else if (is_base_type (type))
7584 mod_type_die = base_type_die (type);
7585 else
7587 gen_type_die (type, context_die);
7589 /* We have to get the type_main_variant here (and pass that to the
7590 `lookup_type_die' routine) because the ..._TYPE node we have
7591 might simply be a *copy* of some original type node (where the
7592 copy was created to help us keep track of typedef names) and
7593 that copy might have a different TYPE_UID from the original
7594 ..._TYPE node. */
7595 if (TREE_CODE (type) != VECTOR_TYPE)
7596 mod_type_die = lookup_type_die (type_main_variant (type));
7597 else
7598 /* Vectors have the debugging information in the type,
7599 not the main variant. */
7600 mod_type_die = lookup_type_die (type);
7601 if (mod_type_die == NULL)
7602 abort ();
7605 /* We want to equate the qualified type to the die below. */
7606 if (qualified_type)
7607 type = qualified_type;
7610 equate_type_number_to_die (type, mod_type_die);
7611 if (item_type)
7612 /* We must do this after the equate_type_number_to_die call, in case
7613 this is a recursive type. This ensures that the modified_type_die
7614 recursion will terminate even if the type is recursive. Recursive
7615 types are possible in Ada. */
7616 sub_die = modified_type_die (item_type,
7617 TYPE_READONLY (item_type),
7618 TYPE_VOLATILE (item_type),
7619 context_die);
7621 if (sub_die != NULL)
7622 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7624 return mod_type_die;
7627 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7628 an enumerated type. */
7630 static inline int
7631 type_is_enum (type)
7632 tree type;
7634 return TREE_CODE (type) == ENUMERAL_TYPE;
7637 /* Return the register number described by a given RTL node. */
7639 static unsigned int
7640 reg_number (rtl)
7641 rtx rtl;
7643 unsigned regno = REGNO (rtl);
7645 if (regno >= FIRST_PSEUDO_REGISTER)
7646 abort ();
7648 return DBX_REGISTER_NUMBER (regno);
7651 /* Return a location descriptor that designates a machine register or
7652 zero if there is no such. */
7654 static dw_loc_descr_ref
7655 reg_loc_descriptor (rtl)
7656 rtx rtl;
7658 dw_loc_descr_ref loc_result = NULL;
7659 unsigned reg;
7661 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7662 return 0;
7664 reg = reg_number (rtl);
7665 if (reg <= 31)
7666 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7667 else
7668 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7670 return loc_result;
7673 /* Return a location descriptor that designates a constant. */
7675 static dw_loc_descr_ref
7676 int_loc_descriptor (i)
7677 HOST_WIDE_INT i;
7679 enum dwarf_location_atom op;
7681 /* Pick the smallest representation of a constant, rather than just
7682 defaulting to the LEB encoding. */
7683 if (i >= 0)
7685 if (i <= 31)
7686 op = DW_OP_lit0 + i;
7687 else if (i <= 0xff)
7688 op = DW_OP_const1u;
7689 else if (i <= 0xffff)
7690 op = DW_OP_const2u;
7691 else if (HOST_BITS_PER_WIDE_INT == 32
7692 || i <= 0xffffffff)
7693 op = DW_OP_const4u;
7694 else
7695 op = DW_OP_constu;
7697 else
7699 if (i >= -0x80)
7700 op = DW_OP_const1s;
7701 else if (i >= -0x8000)
7702 op = DW_OP_const2s;
7703 else if (HOST_BITS_PER_WIDE_INT == 32
7704 || i >= -0x80000000)
7705 op = DW_OP_const4s;
7706 else
7707 op = DW_OP_consts;
7710 return new_loc_descr (op, i, 0);
7713 /* Return a location descriptor that designates a base+offset location. */
7715 static dw_loc_descr_ref
7716 based_loc_descr (reg, offset)
7717 unsigned reg;
7718 long int offset;
7720 dw_loc_descr_ref loc_result;
7721 /* For the "frame base", we use the frame pointer or stack pointer
7722 registers, since the RTL for local variables is relative to one of
7723 them. */
7724 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7725 ? HARD_FRAME_POINTER_REGNUM
7726 : STACK_POINTER_REGNUM);
7728 if (reg == fp_reg)
7729 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7730 else if (reg <= 31)
7731 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7732 else
7733 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7735 return loc_result;
7738 /* Return true if this RTL expression describes a base+offset calculation. */
7740 static inline int
7741 is_based_loc (rtl)
7742 rtx rtl;
7744 return (GET_CODE (rtl) == PLUS
7745 && ((GET_CODE (XEXP (rtl, 0)) == REG
7746 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
7747 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7750 /* The following routine converts the RTL for a variable or parameter
7751 (resident in memory) into an equivalent Dwarf representation of a
7752 mechanism for getting the address of that same variable onto the top of a
7753 hypothetical "address evaluation" stack.
7755 When creating memory location descriptors, we are effectively transforming
7756 the RTL for a memory-resident object into its Dwarf postfix expression
7757 equivalent. This routine recursively descends an RTL tree, turning
7758 it into Dwarf postfix code as it goes.
7760 MODE is the mode of the memory reference, needed to handle some
7761 autoincrement addressing modes.
7763 Return 0 if we can't represent the location. */
7765 static dw_loc_descr_ref
7766 mem_loc_descriptor (rtl, mode)
7767 rtx rtl;
7768 enum machine_mode mode;
7770 dw_loc_descr_ref mem_loc_result = NULL;
7772 /* Note that for a dynamically sized array, the location we will generate a
7773 description of here will be the lowest numbered location which is
7774 actually within the array. That's *not* necessarily the same as the
7775 zeroth element of the array. */
7777 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7778 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7779 #endif
7781 switch (GET_CODE (rtl))
7783 case POST_INC:
7784 case POST_DEC:
7785 case POST_MODIFY:
7786 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7787 just fall into the SUBREG code. */
7789 /* ... fall through ... */
7791 case SUBREG:
7792 /* The case of a subreg may arise when we have a local (register)
7793 variable or a formal (register) parameter which doesn't quite fill
7794 up an entire register. For now, just assume that it is
7795 legitimate to make the Dwarf info refer to the whole register which
7796 contains the given subreg. */
7797 rtl = SUBREG_REG (rtl);
7799 /* ... fall through ... */
7801 case REG:
7802 /* Whenever a register number forms a part of the description of the
7803 method for calculating the (dynamic) address of a memory resident
7804 object, DWARF rules require the register number be referred to as
7805 a "base register". This distinction is not based in any way upon
7806 what category of register the hardware believes the given register
7807 belongs to. This is strictly DWARF terminology we're dealing with
7808 here. Note that in cases where the location of a memory-resident
7809 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7810 OP_CONST (0)) the actual DWARF location descriptor that we generate
7811 may just be OP_BASEREG (basereg). This may look deceptively like
7812 the object in question was allocated to a register (rather than in
7813 memory) so DWARF consumers need to be aware of the subtle
7814 distinction between OP_REG and OP_BASEREG. */
7815 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
7816 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7817 break;
7819 case MEM:
7820 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7821 if (mem_loc_result != 0)
7822 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7823 break;
7825 case LABEL_REF:
7826 /* Some ports can transform a symbol ref into a label ref, because
7827 the symbol ref is too far away and has to be dumped into a constant
7828 pool. */
7829 case CONST:
7830 case SYMBOL_REF:
7831 /* Alternatively, the symbol in the constant pool might be referenced
7832 by a different symbol. */
7833 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
7835 bool marked;
7836 rtx tmp = get_pool_constant_mark (rtl, &marked);
7838 if (GET_CODE (tmp) == SYMBOL_REF)
7840 rtl = tmp;
7841 if (CONSTANT_POOL_ADDRESS_P (tmp))
7842 get_pool_constant_mark (tmp, &marked);
7843 else
7844 marked = true;
7847 /* If all references to this pool constant were optimized away,
7848 it was not output and thus we can't represent it.
7849 FIXME: might try to use DW_OP_const_value here, though
7850 DW_OP_piece complicates it. */
7851 if (!marked)
7852 return 0;
7855 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7856 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7857 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
7858 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
7859 break;
7861 case PRE_MODIFY:
7862 /* Extract the PLUS expression nested inside and fall into
7863 PLUS code below. */
7864 rtl = XEXP (rtl, 1);
7865 goto plus;
7867 case PRE_INC:
7868 case PRE_DEC:
7869 /* Turn these into a PLUS expression and fall into the PLUS code
7870 below. */
7871 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7872 GEN_INT (GET_CODE (rtl) == PRE_INC
7873 ? GET_MODE_UNIT_SIZE (mode)
7874 : -GET_MODE_UNIT_SIZE (mode)));
7876 /* ... fall through ... */
7878 case PLUS:
7879 plus:
7880 if (is_based_loc (rtl))
7881 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7882 INTVAL (XEXP (rtl, 1)));
7883 else
7885 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7886 if (mem_loc_result == 0)
7887 break;
7889 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7890 && INTVAL (XEXP (rtl, 1)) >= 0)
7891 add_loc_descr (&mem_loc_result,
7892 new_loc_descr (DW_OP_plus_uconst,
7893 INTVAL (XEXP (rtl, 1)), 0));
7894 else
7896 add_loc_descr (&mem_loc_result,
7897 mem_loc_descriptor (XEXP (rtl, 1), mode));
7898 add_loc_descr (&mem_loc_result,
7899 new_loc_descr (DW_OP_plus, 0, 0));
7902 break;
7904 case MULT:
7906 /* If a pseudo-reg is optimized away, it is possible for it to
7907 be replaced with a MEM containing a multiply. */
7908 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
7909 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
7911 if (op0 == 0 || op1 == 0)
7912 break;
7914 mem_loc_result = op0;
7915 add_loc_descr (&mem_loc_result, op1);
7916 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7917 break;
7920 case CONST_INT:
7921 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7922 break;
7924 case ADDRESSOF:
7925 /* If this is a MEM, return its address. Otherwise, we can't
7926 represent this. */
7927 if (GET_CODE (XEXP (rtl, 0)) == MEM)
7928 return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode);
7929 else
7930 return 0;
7932 default:
7933 abort ();
7936 return mem_loc_result;
7939 /* Return a descriptor that describes the concatenation of two locations.
7940 This is typically a complex variable. */
7942 static dw_loc_descr_ref
7943 concat_loc_descriptor (x0, x1)
7944 rtx x0, x1;
7946 dw_loc_descr_ref cc_loc_result = NULL;
7947 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
7948 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
7950 if (x0_ref == 0 || x1_ref == 0)
7951 return 0;
7953 cc_loc_result = x0_ref;
7954 add_loc_descr (&cc_loc_result,
7955 new_loc_descr (DW_OP_piece,
7956 GET_MODE_SIZE (GET_MODE (x0)), 0));
7958 add_loc_descr (&cc_loc_result, x1_ref);
7959 add_loc_descr (&cc_loc_result,
7960 new_loc_descr (DW_OP_piece,
7961 GET_MODE_SIZE (GET_MODE (x1)), 0));
7963 return cc_loc_result;
7966 /* Output a proper Dwarf location descriptor for a variable or parameter
7967 which is either allocated in a register or in a memory location. For a
7968 register, we just generate an OP_REG and the register number. For a
7969 memory location we provide a Dwarf postfix expression describing how to
7970 generate the (dynamic) address of the object onto the address stack.
7972 If we don't know how to describe it, return 0. */
7974 static dw_loc_descr_ref
7975 loc_descriptor (rtl)
7976 rtx rtl;
7978 dw_loc_descr_ref loc_result = NULL;
7980 switch (GET_CODE (rtl))
7982 case SUBREG:
7983 /* The case of a subreg may arise when we have a local (register)
7984 variable or a formal (register) parameter which doesn't quite fill
7985 up an entire register. For now, just assume that it is
7986 legitimate to make the Dwarf info refer to the whole register which
7987 contains the given subreg. */
7988 rtl = SUBREG_REG (rtl);
7990 /* ... fall through ... */
7992 case REG:
7993 loc_result = reg_loc_descriptor (rtl);
7994 break;
7996 case MEM:
7997 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7998 break;
8000 case CONCAT:
8001 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8002 break;
8004 default:
8005 abort ();
8008 return loc_result;
8011 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8012 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8013 looking for an address. Otherwise, we return a value. If we can't make a
8014 descriptor, return 0. */
8016 static dw_loc_descr_ref
8017 loc_descriptor_from_tree (loc, addressp)
8018 tree loc;
8019 int addressp;
8021 dw_loc_descr_ref ret, ret1;
8022 int indirect_p = 0;
8023 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
8024 enum dwarf_location_atom op;
8026 /* ??? Most of the time we do not take proper care for sign/zero
8027 extending the values properly. Hopefully this won't be a real
8028 problem... */
8030 switch (TREE_CODE (loc))
8032 case ERROR_MARK:
8033 return 0;
8035 case WITH_RECORD_EXPR:
8036 case PLACEHOLDER_EXPR:
8037 /* This case involves extracting fields from an object to determine the
8038 position of other fields. We don't try to encode this here. The
8039 only user of this is Ada, which encodes the needed information using
8040 the names of types. */
8041 return 0;
8043 case CALL_EXPR:
8044 return 0;
8046 case ADDR_EXPR:
8047 /* We can support this only if we can look through conversions and
8048 find an INDIRECT_EXPR. */
8049 for (loc = TREE_OPERAND (loc, 0);
8050 TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR
8051 || TREE_CODE (loc) == NON_LVALUE_EXPR
8052 || TREE_CODE (loc) == VIEW_CONVERT_EXPR
8053 || TREE_CODE (loc) == SAVE_EXPR;
8054 loc = TREE_OPERAND (loc, 0))
8057 return (TREE_CODE (loc) == INDIRECT_REF
8058 ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp)
8059 : 0);
8061 case VAR_DECL:
8062 case PARM_DECL:
8064 rtx rtl = rtl_for_decl_location (loc);
8066 if (rtl == NULL_RTX)
8067 return 0;
8068 else if (CONSTANT_P (rtl))
8070 ret = new_loc_descr (DW_OP_addr, 0, 0);
8071 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8072 ret->dw_loc_oprnd1.v.val_addr = rtl;
8073 indirect_p = 1;
8075 else
8077 enum machine_mode mode = GET_MODE (rtl);
8079 if (GET_CODE (rtl) == MEM)
8081 indirect_p = 1;
8082 rtl = XEXP (rtl, 0);
8085 ret = mem_loc_descriptor (rtl, mode);
8088 break;
8090 case INDIRECT_REF:
8091 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8092 indirect_p = 1;
8093 break;
8095 case COMPOUND_EXPR:
8096 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
8098 case NOP_EXPR:
8099 case CONVERT_EXPR:
8100 case NON_LVALUE_EXPR:
8101 case VIEW_CONVERT_EXPR:
8102 case SAVE_EXPR:
8103 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8105 case COMPONENT_REF:
8106 case BIT_FIELD_REF:
8107 case ARRAY_REF:
8108 case ARRAY_RANGE_REF:
8110 tree obj, offset;
8111 HOST_WIDE_INT bitsize, bitpos, bytepos;
8112 enum machine_mode mode;
8113 int volatilep;
8115 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8116 &unsignedp, &volatilep);
8118 if (obj == loc)
8119 return 0;
8121 ret = loc_descriptor_from_tree (obj, 1);
8122 if (ret == 0
8123 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
8124 return 0;
8126 if (offset != NULL_TREE)
8128 /* Variable offset. */
8129 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8130 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8133 if (!addressp)
8134 indirect_p = 1;
8136 bytepos = bitpos / BITS_PER_UNIT;
8137 if (bytepos > 0)
8138 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8139 else if (bytepos < 0)
8141 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8142 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8144 break;
8147 case INTEGER_CST:
8148 if (host_integerp (loc, 0))
8149 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8150 else
8151 return 0;
8152 break;
8154 case TRUTH_AND_EXPR:
8155 case TRUTH_ANDIF_EXPR:
8156 case BIT_AND_EXPR:
8157 op = DW_OP_and;
8158 goto do_binop;
8160 case TRUTH_XOR_EXPR:
8161 case BIT_XOR_EXPR:
8162 op = DW_OP_xor;
8163 goto do_binop;
8165 case TRUTH_OR_EXPR:
8166 case TRUTH_ORIF_EXPR:
8167 case BIT_IOR_EXPR:
8168 op = DW_OP_or;
8169 goto do_binop;
8171 case TRUNC_DIV_EXPR:
8172 op = DW_OP_div;
8173 goto do_binop;
8175 case MINUS_EXPR:
8176 op = DW_OP_minus;
8177 goto do_binop;
8179 case TRUNC_MOD_EXPR:
8180 op = DW_OP_mod;
8181 goto do_binop;
8183 case MULT_EXPR:
8184 op = DW_OP_mul;
8185 goto do_binop;
8187 case LSHIFT_EXPR:
8188 op = DW_OP_shl;
8189 goto do_binop;
8191 case RSHIFT_EXPR:
8192 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8193 goto do_binop;
8195 case PLUS_EXPR:
8196 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8197 && host_integerp (TREE_OPERAND (loc, 1), 0))
8199 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8200 if (ret == 0)
8201 return 0;
8203 add_loc_descr (&ret,
8204 new_loc_descr (DW_OP_plus_uconst,
8205 tree_low_cst (TREE_OPERAND (loc, 1),
8207 0));
8208 break;
8211 op = DW_OP_plus;
8212 goto do_binop;
8214 case LE_EXPR:
8215 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8216 return 0;
8218 op = DW_OP_le;
8219 goto do_binop;
8221 case GE_EXPR:
8222 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8223 return 0;
8225 op = DW_OP_ge;
8226 goto do_binop;
8228 case LT_EXPR:
8229 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8230 return 0;
8232 op = DW_OP_lt;
8233 goto do_binop;
8235 case GT_EXPR:
8236 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8237 return 0;
8239 op = DW_OP_gt;
8240 goto do_binop;
8242 case EQ_EXPR:
8243 op = DW_OP_eq;
8244 goto do_binop;
8246 case NE_EXPR:
8247 op = DW_OP_ne;
8248 goto do_binop;
8250 do_binop:
8251 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8252 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8253 if (ret == 0 || ret1 == 0)
8254 return 0;
8256 add_loc_descr (&ret, ret1);
8257 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8258 break;
8260 case TRUTH_NOT_EXPR:
8261 case BIT_NOT_EXPR:
8262 op = DW_OP_not;
8263 goto do_unop;
8265 case ABS_EXPR:
8266 op = DW_OP_abs;
8267 goto do_unop;
8269 case NEGATE_EXPR:
8270 op = DW_OP_neg;
8271 goto do_unop;
8273 do_unop:
8274 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8275 if (ret == 0)
8276 return 0;
8278 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8279 break;
8281 case MAX_EXPR:
8282 loc = build (COND_EXPR, TREE_TYPE (loc),
8283 build (LT_EXPR, integer_type_node,
8284 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8285 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8287 /* ... fall through ... */
8289 case COND_EXPR:
8291 dw_loc_descr_ref lhs
8292 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8293 dw_loc_descr_ref rhs
8294 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8295 dw_loc_descr_ref bra_node, jump_node, tmp;
8297 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8298 if (ret == 0 || lhs == 0 || rhs == 0)
8299 return 0;
8301 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8302 add_loc_descr (&ret, bra_node);
8304 add_loc_descr (&ret, rhs);
8305 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8306 add_loc_descr (&ret, jump_node);
8308 add_loc_descr (&ret, lhs);
8309 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8310 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
8312 /* ??? Need a node to point the skip at. Use a nop. */
8313 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8314 add_loc_descr (&ret, tmp);
8315 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8316 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8318 break;
8320 default:
8321 abort ();
8324 /* Show if we can't fill the request for an address. */
8325 if (addressp && indirect_p == 0)
8326 return 0;
8328 /* If we've got an address and don't want one, dereference. */
8329 if (!addressp && indirect_p > 0)
8331 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8333 if (size > DWARF2_ADDR_SIZE || size == -1)
8334 return 0;
8335 else if (size == DWARF2_ADDR_SIZE)
8336 op = DW_OP_deref;
8337 else
8338 op = DW_OP_deref_size;
8340 add_loc_descr (&ret, new_loc_descr (op, size, 0));
8343 return ret;
8346 /* Given a value, round it up to the lowest multiple of `boundary'
8347 which is not less than the value itself. */
8349 static inline HOST_WIDE_INT
8350 ceiling (value, boundary)
8351 HOST_WIDE_INT value;
8352 unsigned int boundary;
8354 return (((value + boundary - 1) / boundary) * boundary);
8357 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8358 pointer to the declared type for the relevant field variable, or return
8359 `integer_type_node' if the given node turns out to be an
8360 ERROR_MARK node. */
8362 static inline tree
8363 field_type (decl)
8364 tree decl;
8366 tree type;
8368 if (TREE_CODE (decl) == ERROR_MARK)
8369 return integer_type_node;
8371 type = DECL_BIT_FIELD_TYPE (decl);
8372 if (type == NULL_TREE)
8373 type = TREE_TYPE (decl);
8375 return type;
8378 /* Given a pointer to a tree node, return the alignment in bits for
8379 it, or else return BITS_PER_WORD if the node actually turns out to
8380 be an ERROR_MARK node. */
8382 static inline unsigned
8383 simple_type_align_in_bits (type)
8384 tree type;
8386 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8389 static inline unsigned
8390 simple_decl_align_in_bits (decl)
8391 tree decl;
8393 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8396 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8397 node, return the size in bits for the type if it is a constant, or else
8398 return the alignment for the type if the type's size is not constant, or
8399 else return BITS_PER_WORD if the type actually turns out to be an
8400 ERROR_MARK node. */
8402 static inline unsigned HOST_WIDE_INT
8403 simple_type_size_in_bits (type)
8404 tree type;
8407 if (TREE_CODE (type) == ERROR_MARK)
8408 return BITS_PER_WORD;
8409 else if (TYPE_SIZE (type) == NULL_TREE)
8410 return 0;
8411 else if (host_integerp (TYPE_SIZE (type), 1))
8412 return tree_low_cst (TYPE_SIZE (type), 1);
8413 else
8414 return TYPE_ALIGN (type);
8417 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8418 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8419 or return 0 if we are unable to determine what that offset is, either
8420 because the argument turns out to be a pointer to an ERROR_MARK node, or
8421 because the offset is actually variable. (We can't handle the latter case
8422 just yet). */
8424 static HOST_WIDE_INT
8425 field_byte_offset (decl)
8426 tree decl;
8428 unsigned int type_align_in_bits;
8429 unsigned int decl_align_in_bits;
8430 unsigned HOST_WIDE_INT type_size_in_bits;
8431 HOST_WIDE_INT object_offset_in_bits;
8432 tree type;
8433 tree field_size_tree;
8434 HOST_WIDE_INT bitpos_int;
8435 HOST_WIDE_INT deepest_bitpos;
8436 unsigned HOST_WIDE_INT field_size_in_bits;
8438 if (TREE_CODE (decl) == ERROR_MARK)
8439 return 0;
8440 else if (TREE_CODE (decl) != FIELD_DECL)
8441 abort ();
8443 type = field_type (decl);
8444 field_size_tree = DECL_SIZE (decl);
8446 /* The size could be unspecified if there was an error, or for
8447 a flexible array member. */
8448 if (! field_size_tree)
8449 field_size_tree = bitsize_zero_node;
8451 /* We cannot yet cope with fields whose positions are variable, so
8452 for now, when we see such things, we simply return 0. Someday, we may
8453 be able to handle such cases, but it will be damn difficult. */
8454 if (! host_integerp (bit_position (decl), 0))
8455 return 0;
8457 bitpos_int = int_bit_position (decl);
8459 /* If we don't know the size of the field, pretend it's a full word. */
8460 if (host_integerp (field_size_tree, 1))
8461 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8462 else
8463 field_size_in_bits = BITS_PER_WORD;
8465 type_size_in_bits = simple_type_size_in_bits (type);
8466 type_align_in_bits = simple_type_align_in_bits (type);
8467 decl_align_in_bits = simple_decl_align_in_bits (decl);
8469 /* The GCC front-end doesn't make any attempt to keep track of the starting
8470 bit offset (relative to the start of the containing structure type) of the
8471 hypothetical "containing object" for a bit-field. Thus, when computing
8472 the byte offset value for the start of the "containing object" of a
8473 bit-field, we must deduce this information on our own. This can be rather
8474 tricky to do in some cases. For example, handling the following structure
8475 type definition when compiling for an i386/i486 target (which only aligns
8476 long long's to 32-bit boundaries) can be very tricky:
8478 struct S { int field1; long long field2:31; };
8480 Fortunately, there is a simple rule-of-thumb which can be used in such
8481 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8482 structure shown above. It decides to do this based upon one simple rule
8483 for bit-field allocation. GCC allocates each "containing object" for each
8484 bit-field at the first (i.e. lowest addressed) legitimate alignment
8485 boundary (based upon the required minimum alignment for the declared type
8486 of the field) which it can possibly use, subject to the condition that
8487 there is still enough available space remaining in the containing object
8488 (when allocated at the selected point) to fully accommodate all of the
8489 bits of the bit-field itself.
8491 This simple rule makes it obvious why GCC allocates 8 bytes for each
8492 object of the structure type shown above. When looking for a place to
8493 allocate the "containing object" for `field2', the compiler simply tries
8494 to allocate a 64-bit "containing object" at each successive 32-bit
8495 boundary (starting at zero) until it finds a place to allocate that 64-
8496 bit field such that at least 31 contiguous (and previously unallocated)
8497 bits remain within that selected 64 bit field. (As it turns out, for the
8498 example above, the compiler finds it is OK to allocate the "containing
8499 object" 64-bit field at bit-offset zero within the structure type.)
8501 Here we attempt to work backwards from the limited set of facts we're
8502 given, and we try to deduce from those facts, where GCC must have believed
8503 that the containing object started (within the structure type). The value
8504 we deduce is then used (by the callers of this routine) to generate
8505 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8506 and, in the case of DW_AT_location, regular fields as well). */
8508 /* Figure out the bit-distance from the start of the structure to the
8509 "deepest" bit of the bit-field. */
8510 deepest_bitpos = bitpos_int + field_size_in_bits;
8512 /* This is the tricky part. Use some fancy footwork to deduce where the
8513 lowest addressed bit of the containing object must be. */
8514 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8516 /* Round up to type_align by default. This works best for bitfields. */
8517 object_offset_in_bits += type_align_in_bits - 1;
8518 object_offset_in_bits /= type_align_in_bits;
8519 object_offset_in_bits *= type_align_in_bits;
8521 if (object_offset_in_bits > bitpos_int)
8523 /* Sigh, the decl must be packed. */
8524 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8526 /* Round up to decl_align instead. */
8527 object_offset_in_bits += decl_align_in_bits - 1;
8528 object_offset_in_bits /= decl_align_in_bits;
8529 object_offset_in_bits *= decl_align_in_bits;
8532 return object_offset_in_bits / BITS_PER_UNIT;
8535 /* The following routines define various Dwarf attributes and any data
8536 associated with them. */
8538 /* Add a location description attribute value to a DIE.
8540 This emits location attributes suitable for whole variables and
8541 whole parameters. Note that the location attributes for struct fields are
8542 generated by the routine `data_member_location_attribute' below. */
8544 static void
8545 add_AT_location_description (die, attr_kind, rtl)
8546 dw_die_ref die;
8547 enum dwarf_attribute attr_kind;
8548 rtx rtl;
8550 dw_loc_descr_ref descr = loc_descriptor (rtl);
8552 if (descr != 0)
8553 add_AT_loc (die, attr_kind, descr);
8556 /* Attach the specialized form of location attribute used for data members of
8557 struct and union types. In the special case of a FIELD_DECL node which
8558 represents a bit-field, the "offset" part of this special location
8559 descriptor must indicate the distance in bytes from the lowest-addressed
8560 byte of the containing struct or union type to the lowest-addressed byte of
8561 the "containing object" for the bit-field. (See the `field_byte_offset'
8562 function above).
8564 For any given bit-field, the "containing object" is a hypothetical object
8565 (of some integral or enum type) within which the given bit-field lives. The
8566 type of this hypothetical "containing object" is always the same as the
8567 declared type of the individual bit-field itself (for GCC anyway... the
8568 DWARF spec doesn't actually mandate this). Note that it is the size (in
8569 bytes) of the hypothetical "containing object" which will be given in the
8570 DW_AT_byte_size attribute for this bit-field. (See the
8571 `byte_size_attribute' function below.) It is also used when calculating the
8572 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8573 function below.) */
8575 static void
8576 add_data_member_location_attribute (die, decl)
8577 dw_die_ref die;
8578 tree decl;
8580 long offset;
8581 dw_loc_descr_ref loc_descr = 0;
8583 if (TREE_CODE (decl) == TREE_VEC)
8585 /* We're working on the TAG_inheritance for a base class. */
8586 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
8588 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8589 aren't at a fixed offset from all (sub)objects of the same
8590 type. We need to extract the appropriate offset from our
8591 vtable. The following dwarf expression means
8593 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8595 This is specific to the V3 ABI, of course. */
8597 dw_loc_descr_ref tmp;
8599 /* Make a copy of the object address. */
8600 tmp = new_loc_descr (DW_OP_dup, 0, 0);
8601 add_loc_descr (&loc_descr, tmp);
8603 /* Extract the vtable address. */
8604 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8605 add_loc_descr (&loc_descr, tmp);
8607 /* Calculate the address of the offset. */
8608 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
8609 if (offset >= 0)
8610 abort ();
8612 tmp = int_loc_descriptor (-offset);
8613 add_loc_descr (&loc_descr, tmp);
8614 tmp = new_loc_descr (DW_OP_minus, 0, 0);
8615 add_loc_descr (&loc_descr, tmp);
8617 /* Extract the offset. */
8618 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8619 add_loc_descr (&loc_descr, tmp);
8621 /* Add it to the object address. */
8622 tmp = new_loc_descr (DW_OP_plus, 0, 0);
8623 add_loc_descr (&loc_descr, tmp);
8625 else
8626 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8628 else
8629 offset = field_byte_offset (decl);
8631 if (! loc_descr)
8633 enum dwarf_location_atom op;
8635 /* The DWARF2 standard says that we should assume that the structure
8636 address is already on the stack, so we can specify a structure field
8637 address by using DW_OP_plus_uconst. */
8639 #ifdef MIPS_DEBUGGING_INFO
8640 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8641 operator correctly. It works only if we leave the offset on the
8642 stack. */
8643 op = DW_OP_constu;
8644 #else
8645 op = DW_OP_plus_uconst;
8646 #endif
8648 loc_descr = new_loc_descr (op, offset, 0);
8651 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8654 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8655 does not have a "location" either in memory or in a register. These
8656 things can arise in GNU C when a constant is passed as an actual parameter
8657 to an inlined function. They can also arise in C++ where declared
8658 constants do not necessarily get memory "homes". */
8660 static void
8661 add_const_value_attribute (die, rtl)
8662 dw_die_ref die;
8663 rtx rtl;
8665 switch (GET_CODE (rtl))
8667 case CONST_INT:
8668 /* Note that a CONST_INT rtx could represent either an integer
8669 or a floating-point constant. A CONST_INT is used whenever
8670 the constant will fit into a single word. In all such
8671 cases, the original mode of the constant value is wiped
8672 out, and the CONST_INT rtx is assigned VOIDmode. */
8674 HOST_WIDE_INT val = INTVAL (rtl);
8676 /* ??? We really should be using HOST_WIDE_INT throughout. */
8677 if (val < 0 && (long) val == val)
8678 add_AT_int (die, DW_AT_const_value, (long) val);
8679 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
8680 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8681 else
8683 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8684 add_AT_long_long (die, DW_AT_const_value,
8685 val >> HOST_BITS_PER_LONG, val);
8686 #else
8687 abort ();
8688 #endif
8691 break;
8693 case CONST_DOUBLE:
8694 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8695 floating-point constant. A CONST_DOUBLE is used whenever the
8696 constant requires more than one word in order to be adequately
8697 represented. We output CONST_DOUBLEs as blocks. */
8699 enum machine_mode mode = GET_MODE (rtl);
8701 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8703 unsigned length = GET_MODE_SIZE (mode) / 4;
8704 long *array = (long *) xmalloc (sizeof (long) * length);
8705 REAL_VALUE_TYPE rv;
8707 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8708 switch (mode)
8710 case SFmode:
8711 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8712 break;
8714 case DFmode:
8715 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8716 break;
8718 case XFmode:
8719 case TFmode:
8720 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8721 break;
8723 default:
8724 abort ();
8727 add_AT_float (die, DW_AT_const_value, length, array);
8729 else
8731 /* ??? We really should be using HOST_WIDE_INT throughout. */
8732 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8733 abort ();
8735 add_AT_long_long (die, DW_AT_const_value,
8736 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8739 break;
8741 case CONST_STRING:
8742 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8743 break;
8745 case SYMBOL_REF:
8746 case LABEL_REF:
8747 case CONST:
8748 add_AT_addr (die, DW_AT_const_value, rtl);
8749 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
8750 break;
8752 case PLUS:
8753 /* In cases where an inlined instance of an inline function is passed
8754 the address of an `auto' variable (which is local to the caller) we
8755 can get a situation where the DECL_RTL of the artificial local
8756 variable (for the inlining) which acts as a stand-in for the
8757 corresponding formal parameter (of the inline function) will look
8758 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8759 exactly a compile-time constant expression, but it isn't the address
8760 of the (artificial) local variable either. Rather, it represents the
8761 *value* which the artificial local variable always has during its
8762 lifetime. We currently have no way to represent such quasi-constant
8763 values in Dwarf, so for now we just punt and generate nothing. */
8764 break;
8766 default:
8767 /* No other kinds of rtx should be possible here. */
8768 abort ();
8773 static rtx
8774 rtl_for_decl_location (decl)
8775 tree decl;
8777 rtx rtl;
8779 /* Here we have to decide where we are going to say the parameter "lives"
8780 (as far as the debugger is concerned). We only have a couple of
8781 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8783 DECL_RTL normally indicates where the parameter lives during most of the
8784 activation of the function. If optimization is enabled however, this
8785 could be either NULL or else a pseudo-reg. Both of those cases indicate
8786 that the parameter doesn't really live anywhere (as far as the code
8787 generation parts of GCC are concerned) during most of the function's
8788 activation. That will happen (for example) if the parameter is never
8789 referenced within the function.
8791 We could just generate a location descriptor here for all non-NULL
8792 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8793 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8794 where DECL_RTL is NULL or is a pseudo-reg.
8796 Note however that we can only get away with using DECL_INCOMING_RTL as
8797 a backup substitute for DECL_RTL in certain limited cases. In cases
8798 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8799 we can be sure that the parameter was passed using the same type as it is
8800 declared to have within the function, and that its DECL_INCOMING_RTL
8801 points us to a place where a value of that type is passed.
8803 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8804 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8805 because in these cases DECL_INCOMING_RTL points us to a value of some
8806 type which is *different* from the type of the parameter itself. Thus,
8807 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8808 such cases, the debugger would end up (for example) trying to fetch a
8809 `float' from a place which actually contains the first part of a
8810 `double'. That would lead to really incorrect and confusing
8811 output at debug-time.
8813 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8814 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8815 are a couple of exceptions however. On little-endian machines we can
8816 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8817 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8818 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8819 when (on a little-endian machine) a non-prototyped function has a
8820 parameter declared to be of type `short' or `char'. In such cases,
8821 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8822 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8823 passed `int' value. If the debugger then uses that address to fetch
8824 a `short' or a `char' (on a little-endian machine) the result will be
8825 the correct data, so we allow for such exceptional cases below.
8827 Note that our goal here is to describe the place where the given formal
8828 parameter lives during most of the function's activation (i.e. between the
8829 end of the prologue and the start of the epilogue). We'll do that as best
8830 as we can. Note however that if the given formal parameter is modified
8831 sometime during the execution of the function, then a stack backtrace (at
8832 debug-time) will show the function as having been called with the *new*
8833 value rather than the value which was originally passed in. This happens
8834 rarely enough that it is not a major problem, but it *is* a problem, and
8835 I'd like to fix it.
8837 A future version of dwarf2out.c may generate two additional attributes for
8838 any given DW_TAG_formal_parameter DIE which will describe the "passed
8839 type" and the "passed location" for the given formal parameter in addition
8840 to the attributes we now generate to indicate the "declared type" and the
8841 "active location" for each parameter. This additional set of attributes
8842 could be used by debuggers for stack backtraces. Separately, note that
8843 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8844 This happens (for example) for inlined-instances of inline function formal
8845 parameters which are never referenced. This really shouldn't be
8846 happening. All PARM_DECL nodes should get valid non-NULL
8847 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8848 values for inlined instances of inline function parameters, so when we see
8849 such cases, we are just out-of-luck for the time being (until integrate.c
8850 gets fixed). */
8852 /* Use DECL_RTL as the "location" unless we find something better. */
8853 rtl = DECL_RTL_IF_SET (decl);
8855 /* When generating abstract instances, ignore everything except
8856 constants and symbols living in memory. */
8857 if (! reload_completed)
8859 if (rtl
8860 && (CONSTANT_P (rtl)
8861 || (GET_CODE (rtl) == MEM
8862 && CONSTANT_P (XEXP (rtl, 0)))))
8864 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8865 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
8866 #endif
8867 return rtl;
8869 rtl = NULL_RTX;
8871 else if (TREE_CODE (decl) == PARM_DECL)
8873 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8875 tree declared_type = type_main_variant (TREE_TYPE (decl));
8876 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8878 /* This decl represents a formal parameter which was optimized out.
8879 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8880 all cases where (rtl == NULL_RTX) just below. */
8881 if (declared_type == passed_type)
8882 rtl = DECL_INCOMING_RTL (decl);
8883 else if (! BYTES_BIG_ENDIAN
8884 && TREE_CODE (declared_type) == INTEGER_TYPE
8885 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8886 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8887 rtl = DECL_INCOMING_RTL (decl);
8890 /* If the parm was passed in registers, but lives on the stack, then
8891 make a big endian correction if the mode of the type of the
8892 parameter is not the same as the mode of the rtl. */
8893 /* ??? This is the same series of checks that are made in dbxout.c before
8894 we reach the big endian correction code there. It isn't clear if all
8895 of these checks are necessary here, but keeping them all is the safe
8896 thing to do. */
8897 else if (GET_CODE (rtl) == MEM
8898 && XEXP (rtl, 0) != const0_rtx
8899 && ! CONSTANT_P (XEXP (rtl, 0))
8900 /* Not passed in memory. */
8901 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8902 /* Not passed by invisible reference. */
8903 && (GET_CODE (XEXP (rtl, 0)) != REG
8904 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8905 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8906 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8907 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8908 #endif
8910 /* Big endian correction check. */
8911 && BYTES_BIG_ENDIAN
8912 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8913 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8914 < UNITS_PER_WORD))
8916 int offset = (UNITS_PER_WORD
8917 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8919 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8920 plus_constant (XEXP (rtl, 0), offset));
8924 if (rtl != NULL_RTX)
8926 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8927 #ifdef LEAF_REG_REMAP
8928 if (current_function_uses_only_leaf_regs)
8929 leaf_renumber_regs_insn (rtl);
8930 #endif
8933 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8934 and will have been substituted directly into all expressions that use it.
8935 C does not have such a concept, but C++ and other languages do. */
8936 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
8938 /* If a variable is initialized with a string constant without embedded
8939 zeros, build CONST_STRING. */
8940 if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8941 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
8943 tree arrtype = TREE_TYPE (decl);
8944 tree enttype = TREE_TYPE (arrtype);
8945 tree domain = TYPE_DOMAIN (arrtype);
8946 tree init = DECL_INITIAL (decl);
8947 enum machine_mode mode = TYPE_MODE (enttype);
8949 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
8950 && domain
8951 && integer_zerop (TYPE_MIN_VALUE (domain))
8952 && compare_tree_int (TYPE_MAX_VALUE (domain),
8953 TREE_STRING_LENGTH (init) - 1) == 0
8954 && ((size_t) TREE_STRING_LENGTH (init)
8955 == strlen (TREE_STRING_POINTER (init)) + 1))
8956 rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init));
8958 /* If the initializer is something that we know will expand into an
8959 immediate RTL constant, expand it now. Expanding anything else
8960 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
8961 else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST
8962 || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST)
8964 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
8965 EXPAND_INITIALIZER);
8966 /* If expand_expr returns a MEM, it wasn't immediate. */
8967 if (rtl && GET_CODE (rtl) == MEM)
8968 abort ();
8972 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8973 if (rtl)
8974 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
8975 #endif
8976 return rtl;
8979 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8980 data attribute for a variable or a parameter. We generate the
8981 DW_AT_const_value attribute only in those cases where the given variable
8982 or parameter does not have a true "location" either in memory or in a
8983 register. This can happen (for example) when a constant is passed as an
8984 actual argument in a call to an inline function. (It's possible that
8985 these things can crop up in other ways also.) Note that one type of
8986 constant value which can be passed into an inlined function is a constant
8987 pointer. This can happen for example if an actual argument in an inlined
8988 function call evaluates to a compile-time constant address. */
8990 static void
8991 add_location_or_const_value_attribute (die, decl)
8992 dw_die_ref die;
8993 tree decl;
8995 rtx rtl;
8997 if (TREE_CODE (decl) == ERROR_MARK)
8998 return;
8999 else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
9000 abort ();
9002 rtl = rtl_for_decl_location (decl);
9003 if (rtl == NULL_RTX)
9004 return;
9006 /* If we don't look past the constant pool, we risk emitting a
9007 reference to a constant pool entry that isn't referenced from
9008 code, and thus is not emitted. */
9009 rtl = avoid_constant_pool_reference (rtl);
9011 switch (GET_CODE (rtl))
9013 case ADDRESSOF:
9014 /* The address of a variable that was optimized away; don't emit
9015 anything. */
9016 break;
9018 case CONST_INT:
9019 case CONST_DOUBLE:
9020 case CONST_STRING:
9021 case SYMBOL_REF:
9022 case LABEL_REF:
9023 case CONST:
9024 case PLUS:
9025 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9026 add_const_value_attribute (die, rtl);
9027 break;
9029 case MEM:
9030 case REG:
9031 case SUBREG:
9032 case CONCAT:
9033 add_AT_location_description (die, DW_AT_location, rtl);
9034 break;
9036 default:
9037 abort ();
9041 /* If we don't have a copy of this variable in memory for some reason (such
9042 as a C++ member constant that doesn't have an out-of-line definition),
9043 we should tell the debugger about the constant value. */
9045 static void
9046 tree_add_const_value_attribute (var_die, decl)
9047 dw_die_ref var_die;
9048 tree decl;
9050 tree init = DECL_INITIAL (decl);
9051 tree type = TREE_TYPE (decl);
9053 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
9054 && initializer_constant_valid_p (init, type) == null_pointer_node)
9055 /* OK */;
9056 else
9057 return;
9059 switch (TREE_CODE (type))
9061 case INTEGER_TYPE:
9062 if (host_integerp (init, 0))
9063 add_AT_unsigned (var_die, DW_AT_const_value,
9064 tree_low_cst (init, 0));
9065 else
9066 add_AT_long_long (var_die, DW_AT_const_value,
9067 TREE_INT_CST_HIGH (init),
9068 TREE_INT_CST_LOW (init));
9069 break;
9071 default:;
9075 /* Generate an DW_AT_name attribute given some string value to be included as
9076 the value of the attribute. */
9078 static inline void
9079 add_name_attribute (die, name_string)
9080 dw_die_ref die;
9081 const char *name_string;
9083 if (name_string != NULL && *name_string != 0)
9085 if (demangle_name_func)
9086 name_string = (*demangle_name_func) (name_string);
9088 add_AT_string (die, DW_AT_name, name_string);
9092 /* Given a tree node describing an array bound (either lower or upper) output
9093 a representation for that bound. */
9095 static void
9096 add_bound_info (subrange_die, bound_attr, bound)
9097 dw_die_ref subrange_die;
9098 enum dwarf_attribute bound_attr;
9099 tree bound;
9101 switch (TREE_CODE (bound))
9103 case ERROR_MARK:
9104 return;
9106 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9107 case INTEGER_CST:
9108 if (! host_integerp (bound, 0)
9109 || (bound_attr == DW_AT_lower_bound
9110 && (((is_c_family () || is_java ()) && integer_zerop (bound))
9111 || (is_fortran () && integer_onep (bound)))))
9112 /* use the default */
9114 else
9115 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
9116 break;
9118 case CONVERT_EXPR:
9119 case NOP_EXPR:
9120 case NON_LVALUE_EXPR:
9121 case VIEW_CONVERT_EXPR:
9122 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
9123 break;
9125 case SAVE_EXPR:
9126 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9127 access the upper bound values may be bogus. If they refer to a
9128 register, they may only describe how to get at these values at the
9129 points in the generated code right after they have just been
9130 computed. Worse yet, in the typical case, the upper bound values
9131 will not even *be* computed in the optimized code (though the
9132 number of elements will), so these SAVE_EXPRs are entirely
9133 bogus. In order to compensate for this fact, we check here to see
9134 if optimization is enabled, and if so, we don't add an attribute
9135 for the (unknown and unknowable) upper bound. This should not
9136 cause too much trouble for existing (stupid?) debuggers because
9137 they have to deal with empty upper bounds location descriptions
9138 anyway in order to be able to deal with incomplete array types.
9139 Of course an intelligent debugger (GDB?) should be able to
9140 comprehend that a missing upper bound specification in an array
9141 type used for a storage class `auto' local array variable
9142 indicates that the upper bound is both unknown (at compile- time)
9143 and unknowable (at run-time) due to optimization.
9145 We assume that a MEM rtx is safe because gcc wouldn't put the
9146 value there unless it was going to be used repeatedly in the
9147 function, i.e. for cleanups. */
9148 if (SAVE_EXPR_RTL (bound)
9149 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9151 dw_die_ref ctx = lookup_decl_die (current_function_decl);
9152 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound);
9153 rtx loc = SAVE_EXPR_RTL (bound);
9155 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9156 it references an outer function's frame. */
9157 if (GET_CODE (loc) == MEM)
9159 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9161 if (XEXP (loc, 0) != new_addr)
9162 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9165 add_AT_flag (decl_die, DW_AT_artificial, 1);
9166 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9167 add_AT_location_description (decl_die, DW_AT_location, loc);
9168 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9171 /* Else leave out the attribute. */
9172 break;
9174 case VAR_DECL:
9175 case PARM_DECL:
9177 dw_die_ref decl_die = lookup_decl_die (bound);
9179 /* ??? Can this happen, or should the variable have been bound
9180 first? Probably it can, since I imagine that we try to create
9181 the types of parameters in the order in which they exist in
9182 the list, and won't have created a forward reference to a
9183 later parameter. */
9184 if (decl_die != NULL)
9185 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9186 break;
9189 default:
9191 /* Otherwise try to create a stack operation procedure to
9192 evaluate the value of the array bound. */
9194 dw_die_ref ctx, decl_die;
9195 dw_loc_descr_ref loc;
9197 loc = loc_descriptor_from_tree (bound, 0);
9198 if (loc == NULL)
9199 break;
9201 if (current_function_decl == 0)
9202 ctx = comp_unit_die;
9203 else
9204 ctx = lookup_decl_die (current_function_decl);
9206 /* If we weren't able to find a context, it's most likely the case
9207 that we are processing the return type of the function. So
9208 make a SAVE_EXPR to point to it and have the limbo DIE code
9209 find the proper die. The save_expr function doesn't always
9210 make a SAVE_EXPR, so do it ourselves. */
9211 if (ctx == 0)
9212 bound = build (SAVE_EXPR, TREE_TYPE (bound), bound,
9213 current_function_decl, NULL_TREE);
9215 decl_die = new_die (DW_TAG_variable, ctx, bound);
9216 add_AT_flag (decl_die, DW_AT_artificial, 1);
9217 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9218 add_AT_loc (decl_die, DW_AT_location, loc);
9220 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9221 break;
9226 /* Note that the block of subscript information for an array type also
9227 includes information about the element type of type given array type. */
9229 static void
9230 add_subscript_info (type_die, type)
9231 dw_die_ref type_die;
9232 tree type;
9234 #ifndef MIPS_DEBUGGING_INFO
9235 unsigned dimension_number;
9236 #endif
9237 tree lower, upper;
9238 dw_die_ref subrange_die;
9240 /* The GNU compilers represent multidimensional array types as sequences of
9241 one dimensional array types whose element types are themselves array
9242 types. Here we squish that down, so that each multidimensional array
9243 type gets only one array_type DIE in the Dwarf debugging info. The draft
9244 Dwarf specification say that we are allowed to do this kind of
9245 compression in C (because there is no difference between an array or
9246 arrays and a multidimensional array in C) but for other source languages
9247 (e.g. Ada) we probably shouldn't do this. */
9249 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9250 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9251 We work around this by disabling this feature. See also
9252 gen_array_type_die. */
9253 #ifndef MIPS_DEBUGGING_INFO
9254 for (dimension_number = 0;
9255 TREE_CODE (type) == ARRAY_TYPE;
9256 type = TREE_TYPE (type), dimension_number++)
9257 #endif
9259 tree domain = TYPE_DOMAIN (type);
9261 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9262 and (in GNU C only) variable bounds. Handle all three forms
9263 here. */
9264 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
9265 if (domain)
9267 /* We have an array type with specified bounds. */
9268 lower = TYPE_MIN_VALUE (domain);
9269 upper = TYPE_MAX_VALUE (domain);
9271 /* define the index type. */
9272 if (TREE_TYPE (domain))
9274 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9275 TREE_TYPE field. We can't emit debug info for this
9276 because it is an unnamed integral type. */
9277 if (TREE_CODE (domain) == INTEGER_TYPE
9278 && TYPE_NAME (domain) == NULL_TREE
9279 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9280 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9282 else
9283 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9284 type_die);
9287 /* ??? If upper is NULL, the array has unspecified length,
9288 but it does have a lower bound. This happens with Fortran
9289 dimension arr(N:*)
9290 Since the debugger is definitely going to need to know N
9291 to produce useful results, go ahead and output the lower
9292 bound solo, and hope the debugger can cope. */
9294 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9295 if (upper)
9296 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9299 /* Otherwise we have an array type with an unspecified length. The
9300 DWARF-2 spec does not say how to handle this; let's just leave out the
9301 bounds. */
9305 static void
9306 add_byte_size_attribute (die, tree_node)
9307 dw_die_ref die;
9308 tree tree_node;
9310 unsigned size;
9312 switch (TREE_CODE (tree_node))
9314 case ERROR_MARK:
9315 size = 0;
9316 break;
9317 case ENUMERAL_TYPE:
9318 case RECORD_TYPE:
9319 case UNION_TYPE:
9320 case QUAL_UNION_TYPE:
9321 size = int_size_in_bytes (tree_node);
9322 break;
9323 case FIELD_DECL:
9324 /* For a data member of a struct or union, the DW_AT_byte_size is
9325 generally given as the number of bytes normally allocated for an
9326 object of the *declared* type of the member itself. This is true
9327 even for bit-fields. */
9328 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9329 break;
9330 default:
9331 abort ();
9334 /* Note that `size' might be -1 when we get to this point. If it is, that
9335 indicates that the byte size of the entity in question is variable. We
9336 have no good way of expressing this fact in Dwarf at the present time,
9337 so just let the -1 pass on through. */
9338 add_AT_unsigned (die, DW_AT_byte_size, size);
9341 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9342 which specifies the distance in bits from the highest order bit of the
9343 "containing object" for the bit-field to the highest order bit of the
9344 bit-field itself.
9346 For any given bit-field, the "containing object" is a hypothetical object
9347 (of some integral or enum type) within which the given bit-field lives. The
9348 type of this hypothetical "containing object" is always the same as the
9349 declared type of the individual bit-field itself. The determination of the
9350 exact location of the "containing object" for a bit-field is rather
9351 complicated. It's handled by the `field_byte_offset' function (above).
9353 Note that it is the size (in bytes) of the hypothetical "containing object"
9354 which will be given in the DW_AT_byte_size attribute for this bit-field.
9355 (See `byte_size_attribute' above). */
9357 static inline void
9358 add_bit_offset_attribute (die, decl)
9359 dw_die_ref die;
9360 tree decl;
9362 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9363 tree type = DECL_BIT_FIELD_TYPE (decl);
9364 HOST_WIDE_INT bitpos_int;
9365 HOST_WIDE_INT highest_order_object_bit_offset;
9366 HOST_WIDE_INT highest_order_field_bit_offset;
9367 HOST_WIDE_INT unsigned bit_offset;
9369 /* Must be a field and a bit field. */
9370 if (!type
9371 || TREE_CODE (decl) != FIELD_DECL)
9372 abort ();
9374 /* We can't yet handle bit-fields whose offsets are variable, so if we
9375 encounter such things, just return without generating any attribute
9376 whatsoever. Likewise for variable or too large size. */
9377 if (! host_integerp (bit_position (decl), 0)
9378 || ! host_integerp (DECL_SIZE (decl), 1))
9379 return;
9381 bitpos_int = int_bit_position (decl);
9383 /* Note that the bit offset is always the distance (in bits) from the
9384 highest-order bit of the "containing object" to the highest-order bit of
9385 the bit-field itself. Since the "high-order end" of any object or field
9386 is different on big-endian and little-endian machines, the computation
9387 below must take account of these differences. */
9388 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9389 highest_order_field_bit_offset = bitpos_int;
9391 if (! BYTES_BIG_ENDIAN)
9393 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9394 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9397 bit_offset
9398 = (! BYTES_BIG_ENDIAN
9399 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9400 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9402 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9405 /* For a FIELD_DECL node which represents a bit field, output an attribute
9406 which specifies the length in bits of the given field. */
9408 static inline void
9409 add_bit_size_attribute (die, decl)
9410 dw_die_ref die;
9411 tree decl;
9413 /* Must be a field and a bit field. */
9414 if (TREE_CODE (decl) != FIELD_DECL
9415 || ! DECL_BIT_FIELD_TYPE (decl))
9416 abort ();
9418 if (host_integerp (DECL_SIZE (decl), 1))
9419 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9422 /* If the compiled language is ANSI C, then add a 'prototyped'
9423 attribute, if arg types are given for the parameters of a function. */
9425 static inline void
9426 add_prototyped_attribute (die, func_type)
9427 dw_die_ref die;
9428 tree func_type;
9430 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9431 && TYPE_ARG_TYPES (func_type) != NULL)
9432 add_AT_flag (die, DW_AT_prototyped, 1);
9435 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9436 by looking in either the type declaration or object declaration
9437 equate table. */
9439 static inline void
9440 add_abstract_origin_attribute (die, origin)
9441 dw_die_ref die;
9442 tree origin;
9444 dw_die_ref origin_die = NULL;
9446 if (TREE_CODE (origin) != FUNCTION_DECL)
9448 /* We may have gotten separated from the block for the inlined
9449 function, if we're in an exception handler or some such; make
9450 sure that the abstract function has been written out.
9452 Doing this for nested functions is wrong, however; functions are
9453 distinct units, and our context might not even be inline. */
9454 tree fn = origin;
9456 if (TYPE_P (fn))
9457 fn = TYPE_STUB_DECL (fn);
9459 fn = decl_function_context (fn);
9460 if (fn)
9461 dwarf2out_abstract_function (fn);
9464 if (DECL_P (origin))
9465 origin_die = lookup_decl_die (origin);
9466 else if (TYPE_P (origin))
9467 origin_die = lookup_type_die (origin);
9469 if (origin_die == NULL)
9470 abort ();
9472 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9475 /* We do not currently support the pure_virtual attribute. */
9477 static inline void
9478 add_pure_or_virtual_attribute (die, func_decl)
9479 dw_die_ref die;
9480 tree func_decl;
9482 if (DECL_VINDEX (func_decl))
9484 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9486 if (host_integerp (DECL_VINDEX (func_decl), 0))
9487 add_AT_loc (die, DW_AT_vtable_elem_location,
9488 new_loc_descr (DW_OP_constu,
9489 tree_low_cst (DECL_VINDEX (func_decl), 0),
9490 0));
9492 /* GNU extension: Record what type this method came from originally. */
9493 if (debug_info_level > DINFO_LEVEL_TERSE)
9494 add_AT_die_ref (die, DW_AT_containing_type,
9495 lookup_type_die (DECL_CONTEXT (func_decl)));
9499 /* Add source coordinate attributes for the given decl. */
9501 static void
9502 add_src_coords_attributes (die, decl)
9503 dw_die_ref die;
9504 tree decl;
9506 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9508 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9509 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9512 /* Add an DW_AT_name attribute and source coordinate attribute for the
9513 given decl, but only if it actually has a name. */
9515 static void
9516 add_name_and_src_coords_attributes (die, decl)
9517 dw_die_ref die;
9518 tree decl;
9520 tree decl_name;
9522 decl_name = DECL_NAME (decl);
9523 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9525 add_name_attribute (die, dwarf2_name (decl, 0));
9526 if (! DECL_ARTIFICIAL (decl))
9527 add_src_coords_attributes (die, decl);
9529 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9530 && TREE_PUBLIC (decl)
9531 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9532 && !DECL_ABSTRACT (decl))
9533 add_AT_string (die, DW_AT_MIPS_linkage_name,
9534 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9537 #ifdef VMS_DEBUGGING_INFO
9538 /* Get the function's name, as described by its RTL. This may be different
9539 from the DECL_NAME name used in the source file. */
9540 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
9542 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
9543 XEXP (DECL_RTL (decl), 0));
9544 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
9546 #endif
9549 /* Push a new declaration scope. */
9551 static void
9552 push_decl_scope (scope)
9553 tree scope;
9555 VARRAY_PUSH_TREE (decl_scope_table, scope);
9558 /* Pop a declaration scope. */
9560 static inline void
9561 pop_decl_scope ()
9563 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9564 abort ();
9566 VARRAY_POP (decl_scope_table);
9569 /* Return the DIE for the scope that immediately contains this type.
9570 Non-named types get global scope. Named types nested in other
9571 types get their containing scope if it's open, or global scope
9572 otherwise. All other types (i.e. function-local named types) get
9573 the current active scope. */
9575 static dw_die_ref
9576 scope_die_for (t, context_die)
9577 tree t;
9578 dw_die_ref context_die;
9580 dw_die_ref scope_die = NULL;
9581 tree containing_scope;
9582 int i;
9584 /* Non-types always go in the current scope. */
9585 if (! TYPE_P (t))
9586 abort ();
9588 containing_scope = TYPE_CONTEXT (t);
9590 /* Ignore namespaces for the moment. */
9591 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9592 containing_scope = NULL_TREE;
9594 /* Ignore function type "scopes" from the C frontend. They mean that
9595 a tagged type is local to a parmlist of a function declarator, but
9596 that isn't useful to DWARF. */
9597 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9598 containing_scope = NULL_TREE;
9600 if (containing_scope == NULL_TREE)
9601 scope_die = comp_unit_die;
9602 else if (TYPE_P (containing_scope))
9604 /* For types, we can just look up the appropriate DIE. But
9605 first we check to see if we're in the middle of emitting it
9606 so we know where the new DIE should go. */
9607 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9608 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
9609 break;
9611 if (i < 0)
9613 if (debug_info_level > DINFO_LEVEL_TERSE
9614 && !TREE_ASM_WRITTEN (containing_scope))
9615 abort ();
9617 /* If none of the current dies are suitable, we get file scope. */
9618 scope_die = comp_unit_die;
9620 else
9621 scope_die = lookup_type_die (containing_scope);
9623 else
9624 scope_die = context_die;
9626 return scope_die;
9629 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9631 static inline int
9632 local_scope_p (context_die)
9633 dw_die_ref context_die;
9635 for (; context_die; context_die = context_die->die_parent)
9636 if (context_die->die_tag == DW_TAG_inlined_subroutine
9637 || context_die->die_tag == DW_TAG_subprogram)
9638 return 1;
9640 return 0;
9643 /* Returns nonzero if CONTEXT_DIE is a class. */
9645 static inline int
9646 class_scope_p (context_die)
9647 dw_die_ref context_die;
9649 return (context_die
9650 && (context_die->die_tag == DW_TAG_structure_type
9651 || context_die->die_tag == DW_TAG_union_type));
9654 /* Many forms of DIEs require a "type description" attribute. This
9655 routine locates the proper "type descriptor" die for the type given
9656 by 'type', and adds an DW_AT_type attribute below the given die. */
9658 static void
9659 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9660 dw_die_ref object_die;
9661 tree type;
9662 int decl_const;
9663 int decl_volatile;
9664 dw_die_ref context_die;
9666 enum tree_code code = TREE_CODE (type);
9667 dw_die_ref type_die = NULL;
9669 /* ??? If this type is an unnamed subrange type of an integral or
9670 floating-point type, use the inner type. This is because we have no
9671 support for unnamed types in base_type_die. This can happen if this is
9672 an Ada subrange type. Correct solution is emit a subrange type die. */
9673 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9674 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9675 type = TREE_TYPE (type), code = TREE_CODE (type);
9677 if (code == ERROR_MARK
9678 /* Handle a special case. For functions whose return type is void, we
9679 generate *no* type attribute. (Note that no object may have type
9680 `void', so this only applies to function return types). */
9681 || code == VOID_TYPE)
9682 return;
9684 type_die = modified_type_die (type,
9685 decl_const || TYPE_READONLY (type),
9686 decl_volatile || TYPE_VOLATILE (type),
9687 context_die);
9689 if (type_die != NULL)
9690 add_AT_die_ref (object_die, DW_AT_type, type_die);
9693 /* Given a tree pointer to a struct, class, union, or enum type node, return
9694 a pointer to the (string) tag name for the given type, or zero if the type
9695 was declared without a tag. */
9697 static const char *
9698 type_tag (type)
9699 tree type;
9701 const char *name = 0;
9703 if (TYPE_NAME (type) != 0)
9705 tree t = 0;
9707 /* Find the IDENTIFIER_NODE for the type name. */
9708 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9709 t = TYPE_NAME (type);
9711 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9712 a TYPE_DECL node, regardless of whether or not a `typedef' was
9713 involved. */
9714 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9715 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9716 t = DECL_NAME (TYPE_NAME (type));
9718 /* Now get the name as a string, or invent one. */
9719 if (t != 0)
9720 name = IDENTIFIER_POINTER (t);
9723 return (name == 0 || *name == '\0') ? 0 : name;
9726 /* Return the type associated with a data member, make a special check
9727 for bit field types. */
9729 static inline tree
9730 member_declared_type (member)
9731 tree member;
9733 return (DECL_BIT_FIELD_TYPE (member)
9734 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
9737 /* Get the decl's label, as described by its RTL. This may be different
9738 from the DECL_NAME name used in the source file. */
9740 #if 0
9741 static const char *
9742 decl_start_label (decl)
9743 tree decl;
9745 rtx x;
9746 const char *fnname;
9748 x = DECL_RTL (decl);
9749 if (GET_CODE (x) != MEM)
9750 abort ();
9752 x = XEXP (x, 0);
9753 if (GET_CODE (x) != SYMBOL_REF)
9754 abort ();
9756 fnname = XSTR (x, 0);
9757 return fnname;
9759 #endif
9761 /* These routines generate the internal representation of the DIE's for
9762 the compilation unit. Debugging information is collected by walking
9763 the declaration trees passed in from dwarf2out_decl(). */
9765 static void
9766 gen_array_type_die (type, context_die)
9767 tree type;
9768 dw_die_ref context_die;
9770 dw_die_ref scope_die = scope_die_for (type, context_die);
9771 dw_die_ref array_die;
9772 tree element_type;
9774 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9775 the inner array type comes before the outer array type. Thus we must
9776 call gen_type_die before we call new_die. See below also. */
9777 #ifdef MIPS_DEBUGGING_INFO
9778 gen_type_die (TREE_TYPE (type), context_die);
9779 #endif
9781 array_die = new_die (DW_TAG_array_type, scope_die, type);
9782 add_name_attribute (array_die, type_tag (type));
9783 equate_type_number_to_die (type, array_die);
9785 if (TREE_CODE (type) == VECTOR_TYPE)
9787 /* The frontend feeds us a representation for the vector as a struct
9788 containing an array. Pull out the array type. */
9789 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
9790 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
9793 #if 0
9794 /* We default the array ordering. SDB will probably do
9795 the right things even if DW_AT_ordering is not present. It's not even
9796 an issue until we start to get into multidimensional arrays anyway. If
9797 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9798 then we'll have to put the DW_AT_ordering attribute back in. (But if
9799 and when we find out that we need to put these in, we will only do so
9800 for multidimensional arrays. */
9801 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9802 #endif
9804 #ifdef MIPS_DEBUGGING_INFO
9805 /* The SGI compilers handle arrays of unknown bound by setting
9806 AT_declaration and not emitting any subrange DIEs. */
9807 if (! TYPE_DOMAIN (type))
9808 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9809 else
9810 #endif
9811 add_subscript_info (array_die, type);
9813 /* Add representation of the type of the elements of this array type. */
9814 element_type = TREE_TYPE (type);
9816 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9817 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9818 We work around this by disabling this feature. See also
9819 add_subscript_info. */
9820 #ifndef MIPS_DEBUGGING_INFO
9821 while (TREE_CODE (element_type) == ARRAY_TYPE)
9822 element_type = TREE_TYPE (element_type);
9824 gen_type_die (element_type, context_die);
9825 #endif
9827 add_type_attribute (array_die, element_type, 0, 0, context_die);
9830 static void
9831 gen_set_type_die (type, context_die)
9832 tree type;
9833 dw_die_ref context_die;
9835 dw_die_ref type_die
9836 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
9838 equate_type_number_to_die (type, type_die);
9839 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9842 #if 0
9843 static void
9844 gen_entry_point_die (decl, context_die)
9845 tree decl;
9846 dw_die_ref context_die;
9848 tree origin = decl_ultimate_origin (decl);
9849 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
9851 if (origin != NULL)
9852 add_abstract_origin_attribute (decl_die, origin);
9853 else
9855 add_name_and_src_coords_attributes (decl_die, decl);
9856 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9857 0, 0, context_die);
9860 if (DECL_ABSTRACT (decl))
9861 equate_decl_number_to_die (decl, decl_die);
9862 else
9863 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9865 #endif
9867 /* Walk through the list of incomplete types again, trying once more to
9868 emit full debugging info for them. */
9870 static void
9871 retry_incomplete_types ()
9873 int i;
9875 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
9876 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
9879 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9881 static void
9882 gen_inlined_enumeration_type_die (type, context_die)
9883 tree type;
9884 dw_die_ref context_die;
9886 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
9888 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9889 be incomplete and such types are not marked. */
9890 add_abstract_origin_attribute (type_die, type);
9893 /* Generate a DIE to represent an inlined instance of a structure type. */
9895 static void
9896 gen_inlined_structure_type_die (type, context_die)
9897 tree type;
9898 dw_die_ref context_die;
9900 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
9902 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9903 be incomplete and such types are not marked. */
9904 add_abstract_origin_attribute (type_die, type);
9907 /* Generate a DIE to represent an inlined instance of a union type. */
9909 static void
9910 gen_inlined_union_type_die (type, context_die)
9911 tree type;
9912 dw_die_ref context_die;
9914 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
9916 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9917 be incomplete and such types are not marked. */
9918 add_abstract_origin_attribute (type_die, type);
9921 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9922 include all of the information about the enumeration values also. Each
9923 enumerated type name/value is listed as a child of the enumerated type
9924 DIE. */
9926 static void
9927 gen_enumeration_type_die (type, context_die)
9928 tree type;
9929 dw_die_ref context_die;
9931 dw_die_ref type_die = lookup_type_die (type);
9933 if (type_die == NULL)
9935 type_die = new_die (DW_TAG_enumeration_type,
9936 scope_die_for (type, context_die), type);
9937 equate_type_number_to_die (type, type_die);
9938 add_name_attribute (type_die, type_tag (type));
9940 else if (! TYPE_SIZE (type))
9941 return;
9942 else
9943 remove_AT (type_die, DW_AT_declaration);
9945 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9946 given enum type is incomplete, do not generate the DW_AT_byte_size
9947 attribute or the DW_AT_element_list attribute. */
9948 if (TYPE_SIZE (type))
9950 tree link;
9952 TREE_ASM_WRITTEN (type) = 1;
9953 add_byte_size_attribute (type_die, type);
9954 if (TYPE_STUB_DECL (type) != NULL_TREE)
9955 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9957 /* If the first reference to this type was as the return type of an
9958 inline function, then it may not have a parent. Fix this now. */
9959 if (type_die->die_parent == NULL)
9960 add_child_die (scope_die_for (type, context_die), type_die);
9962 for (link = TYPE_FIELDS (type);
9963 link != NULL; link = TREE_CHAIN (link))
9965 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
9967 add_name_attribute (enum_die,
9968 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9970 if (host_integerp (TREE_VALUE (link), 0))
9972 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9973 add_AT_int (enum_die, DW_AT_const_value,
9974 tree_low_cst (TREE_VALUE (link), 0));
9975 else
9976 add_AT_unsigned (enum_die, DW_AT_const_value,
9977 tree_low_cst (TREE_VALUE (link), 0));
9981 else
9982 add_AT_flag (type_die, DW_AT_declaration, 1);
9985 /* Generate a DIE to represent either a real live formal parameter decl or to
9986 represent just the type of some formal parameter position in some function
9987 type.
9989 Note that this routine is a bit unusual because its argument may be a
9990 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9991 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9992 node. If it's the former then this function is being called to output a
9993 DIE to represent a formal parameter object (or some inlining thereof). If
9994 it's the latter, then this function is only being called to output a
9995 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9996 argument type of some subprogram type. */
9998 static dw_die_ref
9999 gen_formal_parameter_die (node, context_die)
10000 tree node;
10001 dw_die_ref context_die;
10003 dw_die_ref parm_die
10004 = new_die (DW_TAG_formal_parameter, context_die, node);
10005 tree origin;
10007 switch (TREE_CODE_CLASS (TREE_CODE (node)))
10009 case 'd':
10010 origin = decl_ultimate_origin (node);
10011 if (origin != NULL)
10012 add_abstract_origin_attribute (parm_die, origin);
10013 else
10015 add_name_and_src_coords_attributes (parm_die, node);
10016 add_type_attribute (parm_die, TREE_TYPE (node),
10017 TREE_READONLY (node),
10018 TREE_THIS_VOLATILE (node),
10019 context_die);
10020 if (DECL_ARTIFICIAL (node))
10021 add_AT_flag (parm_die, DW_AT_artificial, 1);
10024 equate_decl_number_to_die (node, parm_die);
10025 if (! DECL_ABSTRACT (node))
10026 add_location_or_const_value_attribute (parm_die, node);
10028 break;
10030 case 't':
10031 /* We were called with some kind of a ..._TYPE node. */
10032 add_type_attribute (parm_die, node, 0, 0, context_die);
10033 break;
10035 default:
10036 abort ();
10039 return parm_die;
10042 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10043 at the end of an (ANSI prototyped) formal parameters list. */
10045 static void
10046 gen_unspecified_parameters_die (decl_or_type, context_die)
10047 tree decl_or_type;
10048 dw_die_ref context_die;
10050 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
10053 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10054 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10055 parameters as specified in some function type specification (except for
10056 those which appear as part of a function *definition*). */
10058 static void
10059 gen_formal_types_die (function_or_method_type, context_die)
10060 tree function_or_method_type;
10061 dw_die_ref context_die;
10063 tree link;
10064 tree formal_type = NULL;
10065 tree first_parm_type;
10066 tree arg;
10068 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
10070 arg = DECL_ARGUMENTS (function_or_method_type);
10071 function_or_method_type = TREE_TYPE (function_or_method_type);
10073 else
10074 arg = NULL_TREE;
10076 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
10078 /* Make our first pass over the list of formal parameter types and output a
10079 DW_TAG_formal_parameter DIE for each one. */
10080 for (link = first_parm_type; link; )
10082 dw_die_ref parm_die;
10084 formal_type = TREE_VALUE (link);
10085 if (formal_type == void_type_node)
10086 break;
10088 /* Output a (nameless) DIE to represent the formal parameter itself. */
10089 parm_die = gen_formal_parameter_die (formal_type, context_die);
10090 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
10091 && link == first_parm_type)
10092 || (arg && DECL_ARTIFICIAL (arg)))
10093 add_AT_flag (parm_die, DW_AT_artificial, 1);
10095 link = TREE_CHAIN (link);
10096 if (arg)
10097 arg = TREE_CHAIN (arg);
10100 /* If this function type has an ellipsis, add a
10101 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10102 if (formal_type != void_type_node)
10103 gen_unspecified_parameters_die (function_or_method_type, context_die);
10105 /* Make our second (and final) pass over the list of formal parameter types
10106 and output DIEs to represent those types (as necessary). */
10107 for (link = TYPE_ARG_TYPES (function_or_method_type);
10108 link && TREE_VALUE (link);
10109 link = TREE_CHAIN (link))
10110 gen_type_die (TREE_VALUE (link), context_die);
10113 /* We want to generate the DIE for TYPE so that we can generate the
10114 die for MEMBER, which has been defined; we will need to refer back
10115 to the member declaration nested within TYPE. If we're trying to
10116 generate minimal debug info for TYPE, processing TYPE won't do the
10117 trick; we need to attach the member declaration by hand. */
10119 static void
10120 gen_type_die_for_member (type, member, context_die)
10121 tree type, member;
10122 dw_die_ref context_die;
10124 gen_type_die (type, context_die);
10126 /* If we're trying to avoid duplicate debug info, we may not have
10127 emitted the member decl for this function. Emit it now. */
10128 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10129 && ! lookup_decl_die (member))
10131 if (decl_ultimate_origin (member))
10132 abort ();
10134 push_decl_scope (type);
10135 if (TREE_CODE (member) == FUNCTION_DECL)
10136 gen_subprogram_die (member, lookup_type_die (type));
10137 else
10138 gen_variable_die (member, lookup_type_die (type));
10140 pop_decl_scope ();
10144 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10145 may later generate inlined and/or out-of-line instances of. */
10147 static void
10148 dwarf2out_abstract_function (decl)
10149 tree decl;
10151 dw_die_ref old_die;
10152 tree save_fn;
10153 tree context;
10154 int was_abstract = DECL_ABSTRACT (decl);
10156 /* Make sure we have the actual abstract inline, not a clone. */
10157 decl = DECL_ORIGIN (decl);
10159 old_die = lookup_decl_die (decl);
10160 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10161 /* We've already generated the abstract instance. */
10162 return;
10164 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10165 we don't get confused by DECL_ABSTRACT. */
10166 if (debug_info_level > DINFO_LEVEL_TERSE)
10168 context = decl_class_context (decl);
10169 if (context)
10170 gen_type_die_for_member
10171 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
10174 /* Pretend we've just finished compiling this function. */
10175 save_fn = current_function_decl;
10176 current_function_decl = decl;
10178 set_decl_abstract_flags (decl, 1);
10179 dwarf2out_decl (decl);
10180 if (! was_abstract)
10181 set_decl_abstract_flags (decl, 0);
10183 current_function_decl = save_fn;
10186 /* Generate a DIE to represent a declared function (either file-scope or
10187 block-local). */
10189 static void
10190 gen_subprogram_die (decl, context_die)
10191 tree decl;
10192 dw_die_ref context_die;
10194 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10195 tree origin = decl_ultimate_origin (decl);
10196 dw_die_ref subr_die;
10197 rtx fp_reg;
10198 tree fn_arg_types;
10199 tree outer_scope;
10200 dw_die_ref old_die = lookup_decl_die (decl);
10201 int declaration = (current_function_decl != decl
10202 || class_scope_p (context_die));
10204 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10205 started to generate the abstract instance of an inline, decided to output
10206 its containing class, and proceeded to emit the declaration of the inline
10207 from the member list for the class. If so, DECLARATION takes priority;
10208 we'll get back to the abstract instance when done with the class. */
10210 /* The class-scope declaration DIE must be the primary DIE. */
10211 if (origin && declaration && class_scope_p (context_die))
10213 origin = NULL;
10214 if (old_die)
10215 abort ();
10218 if (origin != NULL)
10220 if (declaration && ! local_scope_p (context_die))
10221 abort ();
10223 /* Fixup die_parent for the abstract instance of a nested
10224 inline function. */
10225 if (old_die && old_die->die_parent == NULL)
10226 add_child_die (context_die, old_die);
10228 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10229 add_abstract_origin_attribute (subr_die, origin);
10231 else if (old_die)
10233 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10235 if (!get_AT_flag (old_die, DW_AT_declaration)
10236 /* We can have a normal definition following an inline one in the
10237 case of redefinition of GNU C extern inlines.
10238 It seems reasonable to use AT_specification in this case. */
10239 && !get_AT_unsigned (old_die, DW_AT_inline))
10241 /* ??? This can happen if there is a bug in the program, for
10242 instance, if it has duplicate function definitions. Ideally,
10243 we should detect this case and ignore it. For now, if we have
10244 already reported an error, any error at all, then assume that
10245 we got here because of an input error, not a dwarf2 bug. */
10246 if (errorcount)
10247 return;
10248 abort ();
10251 /* If the definition comes from the same place as the declaration,
10252 maybe use the old DIE. We always want the DIE for this function
10253 that has the *_pc attributes to be under comp_unit_die so the
10254 debugger can find it. We also need to do this for abstract
10255 instances of inlines, since the spec requires the out-of-line copy
10256 to have the same parent. For local class methods, this doesn't
10257 apply; we just use the old DIE. */
10258 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10259 && (DECL_ARTIFICIAL (decl)
10260 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10261 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10262 == (unsigned) DECL_SOURCE_LINE (decl)))))
10264 subr_die = old_die;
10266 /* Clear out the declaration attribute and the parm types. */
10267 remove_AT (subr_die, DW_AT_declaration);
10268 remove_children (subr_die);
10270 else
10272 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10273 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10274 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10275 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10276 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10277 != (unsigned) DECL_SOURCE_LINE (decl))
10278 add_AT_unsigned
10279 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10282 else
10284 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10286 if (TREE_PUBLIC (decl))
10287 add_AT_flag (subr_die, DW_AT_external, 1);
10289 add_name_and_src_coords_attributes (subr_die, decl);
10290 if (debug_info_level > DINFO_LEVEL_TERSE)
10292 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
10293 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
10294 0, 0, context_die);
10297 add_pure_or_virtual_attribute (subr_die, decl);
10298 if (DECL_ARTIFICIAL (decl))
10299 add_AT_flag (subr_die, DW_AT_artificial, 1);
10301 if (TREE_PROTECTED (decl))
10302 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10303 else if (TREE_PRIVATE (decl))
10304 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10307 if (declaration)
10309 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10311 add_AT_flag (subr_die, DW_AT_declaration, 1);
10313 /* The first time we see a member function, it is in the context of
10314 the class to which it belongs. We make sure of this by emitting
10315 the class first. The next time is the definition, which is
10316 handled above. The two may come from the same source text. */
10317 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10318 equate_decl_number_to_die (decl, subr_die);
10321 else if (DECL_ABSTRACT (decl))
10323 if (DECL_INLINE (decl) && !flag_no_inline)
10325 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10326 inline functions, but not for extern inline functions.
10327 We can't get this completely correct because information
10328 about whether the function was declared inline is not
10329 saved anywhere. */
10330 if (DECL_DEFER_OUTPUT (decl))
10331 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10332 else
10333 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10335 else
10336 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10338 equate_decl_number_to_die (decl, subr_die);
10340 else if (!DECL_EXTERNAL (decl))
10342 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10343 equate_decl_number_to_die (decl, subr_die);
10345 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10346 current_funcdef_number);
10347 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10348 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10349 current_funcdef_number);
10350 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10352 add_pubname (decl, subr_die);
10353 add_arange (decl, subr_die);
10355 #ifdef MIPS_DEBUGGING_INFO
10356 /* Add a reference to the FDE for this routine. */
10357 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10358 #endif
10360 /* Define the "frame base" location for this routine. We use the
10361 frame pointer or stack pointer registers, since the RTL for local
10362 variables is relative to one of them. */
10363 fp_reg
10364 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10365 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10367 #if 0
10368 /* ??? This fails for nested inline functions, because context_display
10369 is not part of the state saved/restored for inline functions. */
10370 if (current_function_needs_context)
10371 add_AT_location_description (subr_die, DW_AT_static_link,
10372 lookup_static_chain (decl));
10373 #endif
10376 /* Now output descriptions of the arguments for this function. This gets
10377 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10378 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10379 `...' at the end of the formal parameter list. In order to find out if
10380 there was a trailing ellipsis or not, we must instead look at the type
10381 associated with the FUNCTION_DECL. This will be a node of type
10382 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10383 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10384 an ellipsis at the end. */
10386 /* In the case where we are describing a mere function declaration, all we
10387 need to do here (and all we *can* do here) is to describe the *types* of
10388 its formal parameters. */
10389 if (debug_info_level <= DINFO_LEVEL_TERSE)
10391 else if (declaration)
10392 gen_formal_types_die (decl, subr_die);
10393 else
10395 /* Generate DIEs to represent all known formal parameters */
10396 tree arg_decls = DECL_ARGUMENTS (decl);
10397 tree parm;
10399 /* When generating DIEs, generate the unspecified_parameters DIE
10400 instead if we come across the arg "__builtin_va_alist" */
10401 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10402 if (TREE_CODE (parm) == PARM_DECL)
10404 if (DECL_NAME (parm)
10405 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10406 "__builtin_va_alist"))
10407 gen_unspecified_parameters_die (parm, subr_die);
10408 else
10409 gen_decl_die (parm, subr_die);
10412 /* Decide whether we need an unspecified_parameters DIE at the end.
10413 There are 2 more cases to do this for: 1) the ansi ... declaration -
10414 this is detectable when the end of the arg list is not a
10415 void_type_node 2) an unprototyped function declaration (not a
10416 definition). This just means that we have no info about the
10417 parameters at all. */
10418 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10419 if (fn_arg_types != NULL)
10421 /* this is the prototyped case, check for ... */
10422 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10423 gen_unspecified_parameters_die (decl, subr_die);
10425 else if (DECL_INITIAL (decl) == NULL_TREE)
10426 gen_unspecified_parameters_die (decl, subr_die);
10429 /* Output Dwarf info for all of the stuff within the body of the function
10430 (if it has one - it may be just a declaration). */
10431 outer_scope = DECL_INITIAL (decl);
10433 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10434 a function. This BLOCK actually represents the outermost binding contour
10435 for the function, i.e. the contour in which the function's formal
10436 parameters and labels get declared. Curiously, it appears that the front
10437 end doesn't actually put the PARM_DECL nodes for the current function onto
10438 the BLOCK_VARS list for this outer scope, but are strung off of the
10439 DECL_ARGUMENTS list for the function instead.
10441 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10442 the LABEL_DECL nodes for the function however, and we output DWARF info
10443 for those in decls_for_scope. Just within the `outer_scope' there will be
10444 a BLOCK node representing the function's outermost pair of curly braces,
10445 and any blocks used for the base and member initializers of a C++
10446 constructor function. */
10447 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10449 current_function_has_inlines = 0;
10450 decls_for_scope (outer_scope, subr_die, 0);
10452 #if 0 && defined (MIPS_DEBUGGING_INFO)
10453 if (current_function_has_inlines)
10455 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10456 if (! comp_unit_has_inlines)
10458 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10459 comp_unit_has_inlines = 1;
10462 #endif
10466 /* Generate a DIE to represent a declared data object. */
10468 static void
10469 gen_variable_die (decl, context_die)
10470 tree decl;
10471 dw_die_ref context_die;
10473 tree origin = decl_ultimate_origin (decl);
10474 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
10476 dw_die_ref old_die = lookup_decl_die (decl);
10477 int declaration = (DECL_EXTERNAL (decl)
10478 || class_scope_p (context_die));
10480 if (origin != NULL)
10481 add_abstract_origin_attribute (var_die, origin);
10483 /* Loop unrolling can create multiple blocks that refer to the same
10484 static variable, so we must test for the DW_AT_declaration flag.
10486 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10487 copy decls and set the DECL_ABSTRACT flag on them instead of
10488 sharing them.
10490 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10491 else if (old_die && TREE_STATIC (decl)
10492 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10494 /* This is a definition of a C++ class level static. */
10495 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10496 if (DECL_NAME (decl))
10498 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10500 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10501 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10503 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10504 != (unsigned) DECL_SOURCE_LINE (decl))
10506 add_AT_unsigned (var_die, DW_AT_decl_line,
10507 DECL_SOURCE_LINE (decl));
10510 else
10512 add_name_and_src_coords_attributes (var_die, decl);
10513 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
10514 TREE_THIS_VOLATILE (decl), context_die);
10516 if (TREE_PUBLIC (decl))
10517 add_AT_flag (var_die, DW_AT_external, 1);
10519 if (DECL_ARTIFICIAL (decl))
10520 add_AT_flag (var_die, DW_AT_artificial, 1);
10522 if (TREE_PROTECTED (decl))
10523 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10524 else if (TREE_PRIVATE (decl))
10525 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10528 if (declaration)
10529 add_AT_flag (var_die, DW_AT_declaration, 1);
10531 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10532 equate_decl_number_to_die (decl, var_die);
10534 if (! declaration && ! DECL_ABSTRACT (decl))
10536 add_location_or_const_value_attribute (var_die, decl);
10537 add_pubname (decl, var_die);
10539 else
10540 tree_add_const_value_attribute (var_die, decl);
10543 /* Generate a DIE to represent a label identifier. */
10545 static void
10546 gen_label_die (decl, context_die)
10547 tree decl;
10548 dw_die_ref context_die;
10550 tree origin = decl_ultimate_origin (decl);
10551 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
10552 rtx insn;
10553 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10555 if (origin != NULL)
10556 add_abstract_origin_attribute (lbl_die, origin);
10557 else
10558 add_name_and_src_coords_attributes (lbl_die, decl);
10560 if (DECL_ABSTRACT (decl))
10561 equate_decl_number_to_die (decl, lbl_die);
10562 else
10564 insn = DECL_RTL (decl);
10566 /* Deleted labels are programmer specified labels which have been
10567 eliminated because of various optimisations. We still emit them
10568 here so that it is possible to put breakpoints on them. */
10569 if (GET_CODE (insn) == CODE_LABEL
10570 || ((GET_CODE (insn) == NOTE
10571 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10573 /* When optimization is enabled (via -O) some parts of the compiler
10574 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10575 represent source-level labels which were explicitly declared by
10576 the user. This really shouldn't be happening though, so catch
10577 it if it ever does happen. */
10578 if (INSN_DELETED_P (insn))
10579 abort ();
10581 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10582 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10587 /* Generate a DIE for a lexical block. */
10589 static void
10590 gen_lexical_block_die (stmt, context_die, depth)
10591 tree stmt;
10592 dw_die_ref context_die;
10593 int depth;
10595 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
10596 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10598 if (! BLOCK_ABSTRACT (stmt))
10600 if (BLOCK_FRAGMENT_CHAIN (stmt))
10602 tree chain;
10604 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
10606 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10609 add_ranges (chain);
10610 chain = BLOCK_FRAGMENT_CHAIN (chain);
10612 while (chain);
10613 add_ranges (NULL);
10615 else
10617 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10618 BLOCK_NUMBER (stmt));
10619 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10620 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10621 BLOCK_NUMBER (stmt));
10622 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10626 decls_for_scope (stmt, stmt_die, depth);
10629 /* Generate a DIE for an inlined subprogram. */
10631 static void
10632 gen_inlined_subroutine_die (stmt, context_die, depth)
10633 tree stmt;
10634 dw_die_ref context_die;
10635 int depth;
10637 if (! BLOCK_ABSTRACT (stmt))
10639 dw_die_ref subr_die
10640 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
10641 tree decl = block_ultimate_origin (stmt);
10642 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10644 /* Emit info for the abstract instance first, if we haven't yet. */
10645 dwarf2out_abstract_function (decl);
10647 add_abstract_origin_attribute (subr_die, decl);
10648 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10649 BLOCK_NUMBER (stmt));
10650 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10651 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10652 BLOCK_NUMBER (stmt));
10653 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10654 decls_for_scope (stmt, subr_die, depth);
10655 current_function_has_inlines = 1;
10657 else
10658 /* We may get here if we're the outer block of function A that was
10659 inlined into function B that was inlined into function C. When
10660 generating debugging info for C, dwarf2out_abstract_function(B)
10661 would mark all inlined blocks as abstract, including this one.
10662 So, we wouldn't (and shouldn't) expect labels to be generated
10663 for this one. Instead, just emit debugging info for
10664 declarations within the block. This is particularly important
10665 in the case of initializers of arguments passed from B to us:
10666 if they're statement expressions containing declarations, we
10667 wouldn't generate dies for their abstract variables, and then,
10668 when generating dies for the real variables, we'd die (pun
10669 intended :-) */
10670 gen_lexical_block_die (stmt, context_die, depth);
10673 /* Generate a DIE for a field in a record, or structure. */
10675 static void
10676 gen_field_die (decl, context_die)
10677 tree decl;
10678 dw_die_ref context_die;
10680 dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl);
10682 add_name_and_src_coords_attributes (decl_die, decl);
10683 add_type_attribute (decl_die, member_declared_type (decl),
10684 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10685 context_die);
10687 if (DECL_BIT_FIELD_TYPE (decl))
10689 add_byte_size_attribute (decl_die, decl);
10690 add_bit_size_attribute (decl_die, decl);
10691 add_bit_offset_attribute (decl_die, decl);
10694 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10695 add_data_member_location_attribute (decl_die, decl);
10697 if (DECL_ARTIFICIAL (decl))
10698 add_AT_flag (decl_die, DW_AT_artificial, 1);
10700 if (TREE_PROTECTED (decl))
10701 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10702 else if (TREE_PRIVATE (decl))
10703 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10706 #if 0
10707 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10708 Use modified_type_die instead.
10709 We keep this code here just in case these types of DIEs may be needed to
10710 represent certain things in other languages (e.g. Pascal) someday. */
10712 static void
10713 gen_pointer_type_die (type, context_die)
10714 tree type;
10715 dw_die_ref context_die;
10717 dw_die_ref ptr_die
10718 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
10720 equate_type_number_to_die (type, ptr_die);
10721 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10722 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10725 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10726 Use modified_type_die instead.
10727 We keep this code here just in case these types of DIEs may be needed to
10728 represent certain things in other languages (e.g. Pascal) someday. */
10730 static void
10731 gen_reference_type_die (type, context_die)
10732 tree type;
10733 dw_die_ref context_die;
10735 dw_die_ref ref_die
10736 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
10738 equate_type_number_to_die (type, ref_die);
10739 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10740 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10742 #endif
10744 /* Generate a DIE for a pointer to a member type. */
10746 static void
10747 gen_ptr_to_mbr_type_die (type, context_die)
10748 tree type;
10749 dw_die_ref context_die;
10751 dw_die_ref ptr_die
10752 = new_die (DW_TAG_ptr_to_member_type,
10753 scope_die_for (type, context_die), type);
10755 equate_type_number_to_die (type, ptr_die);
10756 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10757 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10758 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10761 /* Generate the DIE for the compilation unit. */
10763 static dw_die_ref
10764 gen_compile_unit_die (filename)
10765 const char *filename;
10767 dw_die_ref die;
10768 char producer[250];
10769 const char *wd = getpwd ();
10770 const char *language_string = lang_hooks.name;
10771 int language;
10773 die = new_die (DW_TAG_compile_unit, NULL, NULL);
10774 add_name_attribute (die, filename);
10776 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10777 add_AT_string (die, DW_AT_comp_dir, wd);
10779 sprintf (producer, "%s %s", language_string, version_string);
10781 #ifdef MIPS_DEBUGGING_INFO
10782 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10783 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10784 not appear in the producer string, the debugger reaches the conclusion
10785 that the object file is stripped and has no debugging information.
10786 To get the MIPS/SGI debugger to believe that there is debugging
10787 information in the object file, we add a -g to the producer string. */
10788 if (debug_info_level > DINFO_LEVEL_TERSE)
10789 strcat (producer, " -g");
10790 #endif
10792 add_AT_string (die, DW_AT_producer, producer);
10794 if (strcmp (language_string, "GNU C++") == 0)
10795 language = DW_LANG_C_plus_plus;
10796 else if (strcmp (language_string, "GNU Ada") == 0)
10797 language = DW_LANG_Ada83;
10798 else if (strcmp (language_string, "GNU F77") == 0)
10799 language = DW_LANG_Fortran77;
10800 else if (strcmp (language_string, "GNU Pascal") == 0)
10801 language = DW_LANG_Pascal83;
10802 else if (strcmp (language_string, "GNU Java") == 0)
10803 language = DW_LANG_Java;
10804 else
10805 language = DW_LANG_C89;
10807 add_AT_unsigned (die, DW_AT_language, language);
10808 return die;
10811 /* Generate a DIE for a string type. */
10813 static void
10814 gen_string_type_die (type, context_die)
10815 tree type;
10816 dw_die_ref context_die;
10818 dw_die_ref type_die
10819 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
10821 equate_type_number_to_die (type, type_die);
10823 /* ??? Fudge the string length attribute for now.
10824 TODO: add string length info. */
10825 #if 0
10826 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10827 bound_representation (upper_bound, 0, 'u');
10828 #endif
10831 /* Generate the DIE for a base class. */
10833 static void
10834 gen_inheritance_die (binfo, context_die)
10835 tree binfo;
10836 dw_die_ref context_die;
10838 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
10840 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10841 add_data_member_location_attribute (die, binfo);
10843 if (TREE_VIA_VIRTUAL (binfo))
10844 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10846 if (TREE_VIA_PUBLIC (binfo))
10847 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10848 else if (TREE_VIA_PROTECTED (binfo))
10849 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10852 /* Generate a DIE for a class member. */
10854 static void
10855 gen_member_die (type, context_die)
10856 tree type;
10857 dw_die_ref context_die;
10859 tree member;
10860 dw_die_ref child;
10862 /* If this is not an incomplete type, output descriptions of each of its
10863 members. Note that as we output the DIEs necessary to represent the
10864 members of this record or union type, we will also be trying to output
10865 DIEs to represent the *types* of those members. However the `type'
10866 function (above) will specifically avoid generating type DIEs for member
10867 types *within* the list of member DIEs for this (containing) type except
10868 for those types (of members) which are explicitly marked as also being
10869 members of this (containing) type themselves. The g++ front- end can
10870 force any given type to be treated as a member of some other (containing)
10871 type by setting the TYPE_CONTEXT of the given (member) type to point to
10872 the TREE node representing the appropriate (containing) type. */
10874 /* First output info about the base classes. */
10875 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10877 tree bases = TYPE_BINFO_BASETYPES (type);
10878 int n_bases = TREE_VEC_LENGTH (bases);
10879 int i;
10881 for (i = 0; i < n_bases; i++)
10882 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10885 /* Now output info about the data members and type members. */
10886 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10888 /* If we thought we were generating minimal debug info for TYPE
10889 and then changed our minds, some of the member declarations
10890 may have already been defined. Don't define them again, but
10891 do put them in the right order. */
10893 child = lookup_decl_die (member);
10894 if (child)
10895 splice_child_die (context_die, child);
10896 else
10897 gen_decl_die (member, context_die);
10900 /* Now output info about the function members (if any). */
10901 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10903 /* Don't include clones in the member list. */
10904 if (DECL_ABSTRACT_ORIGIN (member))
10905 continue;
10907 child = lookup_decl_die (member);
10908 if (child)
10909 splice_child_die (context_die, child);
10910 else
10911 gen_decl_die (member, context_die);
10915 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10916 is set, we pretend that the type was never defined, so we only get the
10917 member DIEs needed by later specification DIEs. */
10919 static void
10920 gen_struct_or_union_type_die (type, context_die)
10921 tree type;
10922 dw_die_ref context_die;
10924 dw_die_ref type_die = lookup_type_die (type);
10925 dw_die_ref scope_die = 0;
10926 int nested = 0;
10927 int complete = (TYPE_SIZE (type)
10928 && (! TYPE_STUB_DECL (type)
10929 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10931 if (type_die && ! complete)
10932 return;
10934 if (TYPE_CONTEXT (type) != NULL_TREE
10935 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10936 nested = 1;
10938 scope_die = scope_die_for (type, context_die);
10940 if (! type_die || (nested && scope_die == comp_unit_die))
10941 /* First occurrence of type or toplevel definition of nested class. */
10943 dw_die_ref old_die = type_die;
10945 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10946 ? DW_TAG_structure_type : DW_TAG_union_type,
10947 scope_die, type);
10948 equate_type_number_to_die (type, type_die);
10949 if (old_die)
10950 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10951 else
10952 add_name_attribute (type_die, type_tag (type));
10954 else
10955 remove_AT (type_die, DW_AT_declaration);
10957 /* If this type has been completed, then give it a byte_size attribute and
10958 then give a list of members. */
10959 if (complete)
10961 /* Prevent infinite recursion in cases where the type of some member of
10962 this type is expressed in terms of this type itself. */
10963 TREE_ASM_WRITTEN (type) = 1;
10964 add_byte_size_attribute (type_die, type);
10965 if (TYPE_STUB_DECL (type) != NULL_TREE)
10966 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10968 /* If the first reference to this type was as the return type of an
10969 inline function, then it may not have a parent. Fix this now. */
10970 if (type_die->die_parent == NULL)
10971 add_child_die (scope_die, type_die);
10973 push_decl_scope (type);
10974 gen_member_die (type, type_die);
10975 pop_decl_scope ();
10977 /* GNU extension: Record what type our vtable lives in. */
10978 if (TYPE_VFIELD (type))
10980 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10982 gen_type_die (vtype, context_die);
10983 add_AT_die_ref (type_die, DW_AT_containing_type,
10984 lookup_type_die (vtype));
10987 else
10989 add_AT_flag (type_die, DW_AT_declaration, 1);
10991 /* We don't need to do this for function-local types. */
10992 if (TYPE_STUB_DECL (type)
10993 && ! decl_function_context (TYPE_STUB_DECL (type)))
10994 VARRAY_PUSH_TREE (incomplete_types, type);
10998 /* Generate a DIE for a subroutine _type_. */
11000 static void
11001 gen_subroutine_type_die (type, context_die)
11002 tree type;
11003 dw_die_ref context_die;
11005 tree return_type = TREE_TYPE (type);
11006 dw_die_ref subr_die
11007 = new_die (DW_TAG_subroutine_type,
11008 scope_die_for (type, context_die), type);
11010 equate_type_number_to_die (type, subr_die);
11011 add_prototyped_attribute (subr_die, type);
11012 add_type_attribute (subr_die, return_type, 0, 0, context_die);
11013 gen_formal_types_die (type, subr_die);
11016 /* Generate a DIE for a type definition */
11018 static void
11019 gen_typedef_die (decl, context_die)
11020 tree decl;
11021 dw_die_ref context_die;
11023 dw_die_ref type_die;
11024 tree origin;
11026 if (TREE_ASM_WRITTEN (decl))
11027 return;
11029 TREE_ASM_WRITTEN (decl) = 1;
11030 type_die = new_die (DW_TAG_typedef, context_die, decl);
11031 origin = decl_ultimate_origin (decl);
11032 if (origin != NULL)
11033 add_abstract_origin_attribute (type_die, origin);
11034 else
11036 tree type;
11038 add_name_and_src_coords_attributes (type_die, decl);
11039 if (DECL_ORIGINAL_TYPE (decl))
11041 type = DECL_ORIGINAL_TYPE (decl);
11043 if (type == TREE_TYPE (decl))
11044 abort ();
11045 else
11046 equate_type_number_to_die (TREE_TYPE (decl), type_die);
11048 else
11049 type = TREE_TYPE (decl);
11051 add_type_attribute (type_die, type, TREE_READONLY (decl),
11052 TREE_THIS_VOLATILE (decl), context_die);
11055 if (DECL_ABSTRACT (decl))
11056 equate_decl_number_to_die (decl, type_die);
11059 /* Generate a type description DIE. */
11061 static void
11062 gen_type_die (type, context_die)
11063 tree type;
11064 dw_die_ref context_die;
11066 int need_pop;
11068 if (type == NULL_TREE || type == error_mark_node)
11069 return;
11071 /* We are going to output a DIE to represent the unqualified version
11072 of this type (i.e. without any const or volatile qualifiers) so
11073 get the main variant (i.e. the unqualified version) of this type
11074 now. (Vectors are special because the debugging info is in the
11075 cloned type itself). */
11076 if (TREE_CODE (type) != VECTOR_TYPE)
11077 type = type_main_variant (type);
11079 if (TREE_ASM_WRITTEN (type))
11080 return;
11082 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11083 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
11085 /* Prevent broken recursion; we can't hand off to the same type. */
11086 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type)
11087 abort ();
11089 TREE_ASM_WRITTEN (type) = 1;
11090 gen_decl_die (TYPE_NAME (type), context_die);
11091 return;
11094 switch (TREE_CODE (type))
11096 case ERROR_MARK:
11097 break;
11099 case POINTER_TYPE:
11100 case REFERENCE_TYPE:
11101 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11102 ensures that the gen_type_die recursion will terminate even if the
11103 type is recursive. Recursive types are possible in Ada. */
11104 /* ??? We could perhaps do this for all types before the switch
11105 statement. */
11106 TREE_ASM_WRITTEN (type) = 1;
11108 /* For these types, all that is required is that we output a DIE (or a
11109 set of DIEs) to represent the "basis" type. */
11110 gen_type_die (TREE_TYPE (type), context_die);
11111 break;
11113 case OFFSET_TYPE:
11114 /* This code is used for C++ pointer-to-data-member types.
11115 Output a description of the relevant class type. */
11116 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
11118 /* Output a description of the type of the object pointed to. */
11119 gen_type_die (TREE_TYPE (type), context_die);
11121 /* Now output a DIE to represent this pointer-to-data-member type
11122 itself. */
11123 gen_ptr_to_mbr_type_die (type, context_die);
11124 break;
11126 case SET_TYPE:
11127 gen_type_die (TYPE_DOMAIN (type), context_die);
11128 gen_set_type_die (type, context_die);
11129 break;
11131 case FILE_TYPE:
11132 gen_type_die (TREE_TYPE (type), context_die);
11133 abort (); /* No way to represent these in Dwarf yet! */
11134 break;
11136 case FUNCTION_TYPE:
11137 /* Force out return type (in case it wasn't forced out already). */
11138 gen_type_die (TREE_TYPE (type), context_die);
11139 gen_subroutine_type_die (type, context_die);
11140 break;
11142 case METHOD_TYPE:
11143 /* Force out return type (in case it wasn't forced out already). */
11144 gen_type_die (TREE_TYPE (type), context_die);
11145 gen_subroutine_type_die (type, context_die);
11146 break;
11148 case ARRAY_TYPE:
11149 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
11151 gen_type_die (TREE_TYPE (type), context_die);
11152 gen_string_type_die (type, context_die);
11154 else
11155 gen_array_type_die (type, context_die);
11156 break;
11158 case VECTOR_TYPE:
11159 gen_array_type_die (type, context_die);
11160 break;
11162 case ENUMERAL_TYPE:
11163 case RECORD_TYPE:
11164 case UNION_TYPE:
11165 case QUAL_UNION_TYPE:
11166 /* If this is a nested type whose containing class hasn't been written
11167 out yet, writing it out will cover this one, too. This does not apply
11168 to instantiations of member class templates; they need to be added to
11169 the containing class as they are generated. FIXME: This hurts the
11170 idea of combining type decls from multiple TUs, since we can't predict
11171 what set of template instantiations we'll get. */
11172 if (TYPE_CONTEXT (type)
11173 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
11174 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
11176 gen_type_die (TYPE_CONTEXT (type), context_die);
11178 if (TREE_ASM_WRITTEN (type))
11179 return;
11181 /* If that failed, attach ourselves to the stub. */
11182 push_decl_scope (TYPE_CONTEXT (type));
11183 context_die = lookup_type_die (TYPE_CONTEXT (type));
11184 need_pop = 1;
11186 else
11187 need_pop = 0;
11189 if (TREE_CODE (type) == ENUMERAL_TYPE)
11190 gen_enumeration_type_die (type, context_die);
11191 else
11192 gen_struct_or_union_type_die (type, context_die);
11194 if (need_pop)
11195 pop_decl_scope ();
11197 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11198 it up if it is ever completed. gen_*_type_die will set it for us
11199 when appropriate. */
11200 return;
11202 case VOID_TYPE:
11203 case INTEGER_TYPE:
11204 case REAL_TYPE:
11205 case COMPLEX_TYPE:
11206 case BOOLEAN_TYPE:
11207 case CHAR_TYPE:
11208 /* No DIEs needed for fundamental types. */
11209 break;
11211 case LANG_TYPE:
11212 /* No Dwarf representation currently defined. */
11213 break;
11215 default:
11216 abort ();
11219 TREE_ASM_WRITTEN (type) = 1;
11222 /* Generate a DIE for a tagged type instantiation. */
11224 static void
11225 gen_tagged_type_instantiation_die (type, context_die)
11226 tree type;
11227 dw_die_ref context_die;
11229 if (type == NULL_TREE || type == error_mark_node)
11230 return;
11232 /* We are going to output a DIE to represent the unqualified version of
11233 this type (i.e. without any const or volatile qualifiers) so make sure
11234 that we have the main variant (i.e. the unqualified version) of this
11235 type now. */
11236 if (type != type_main_variant (type))
11237 abort ();
11239 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11240 an instance of an unresolved type. */
11242 switch (TREE_CODE (type))
11244 case ERROR_MARK:
11245 break;
11247 case ENUMERAL_TYPE:
11248 gen_inlined_enumeration_type_die (type, context_die);
11249 break;
11251 case RECORD_TYPE:
11252 gen_inlined_structure_type_die (type, context_die);
11253 break;
11255 case UNION_TYPE:
11256 case QUAL_UNION_TYPE:
11257 gen_inlined_union_type_die (type, context_die);
11258 break;
11260 default:
11261 abort ();
11265 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11266 things which are local to the given block. */
11268 static void
11269 gen_block_die (stmt, context_die, depth)
11270 tree stmt;
11271 dw_die_ref context_die;
11272 int depth;
11274 int must_output_die = 0;
11275 tree origin;
11276 tree decl;
11277 enum tree_code origin_code;
11279 /* Ignore blocks never really used to make RTL. */
11280 if (stmt == NULL_TREE || !TREE_USED (stmt)
11281 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11282 return;
11284 /* If the block is one fragment of a non-contiguous block, do not
11285 process the variables, since they will have been done by the
11286 origin block. Do process subblocks. */
11287 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11289 tree sub;
11291 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
11292 gen_block_die (sub, context_die, depth + 1);
11294 return;
11297 /* Determine the "ultimate origin" of this block. This block may be an
11298 inlined instance of an inlined instance of inline function, so we have
11299 to trace all of the way back through the origin chain to find out what
11300 sort of node actually served as the original seed for the creation of
11301 the current block. */
11302 origin = block_ultimate_origin (stmt);
11303 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11305 /* Determine if we need to output any Dwarf DIEs at all to represent this
11306 block. */
11307 if (origin_code == FUNCTION_DECL)
11308 /* The outer scopes for inlinings *must* always be represented. We
11309 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11310 must_output_die = 1;
11311 else
11313 /* In the case where the current block represents an inlining of the
11314 "body block" of an inline function, we must *NOT* output any DIE for
11315 this block because we have already output a DIE to represent the whole
11316 inlined function scope and the "body block" of any function doesn't
11317 really represent a different scope according to ANSI C rules. So we
11318 check here to make sure that this block does not represent a "body
11319 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11320 if (! is_body_block (origin ? origin : stmt))
11322 /* Determine if this block directly contains any "significant"
11323 local declarations which we will need to output DIEs for. */
11324 if (debug_info_level > DINFO_LEVEL_TERSE)
11325 /* We are not in terse mode so *any* local declaration counts
11326 as being a "significant" one. */
11327 must_output_die = (BLOCK_VARS (stmt) != NULL);
11328 else
11329 /* We are in terse mode, so only local (nested) function
11330 definitions count as "significant" local declarations. */
11331 for (decl = BLOCK_VARS (stmt);
11332 decl != NULL; decl = TREE_CHAIN (decl))
11333 if (TREE_CODE (decl) == FUNCTION_DECL
11334 && DECL_INITIAL (decl))
11336 must_output_die = 1;
11337 break;
11342 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11343 DIE for any block which contains no significant local declarations at
11344 all. Rather, in such cases we just call `decls_for_scope' so that any
11345 needed Dwarf info for any sub-blocks will get properly generated. Note
11346 that in terse mode, our definition of what constitutes a "significant"
11347 local declaration gets restricted to include only inlined function
11348 instances and local (nested) function definitions. */
11349 if (must_output_die)
11351 if (origin_code == FUNCTION_DECL)
11352 gen_inlined_subroutine_die (stmt, context_die, depth);
11353 else
11354 gen_lexical_block_die (stmt, context_die, depth);
11356 else
11357 decls_for_scope (stmt, context_die, depth);
11360 /* Generate all of the decls declared within a given scope and (recursively)
11361 all of its sub-blocks. */
11363 static void
11364 decls_for_scope (stmt, context_die, depth)
11365 tree stmt;
11366 dw_die_ref context_die;
11367 int depth;
11369 tree decl;
11370 tree subblocks;
11372 /* Ignore blocks never really used to make RTL. */
11373 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11374 return;
11376 /* Output the DIEs to represent all of the data objects and typedefs
11377 declared directly within this block but not within any nested
11378 sub-blocks. Also, nested function and tag DIEs have been
11379 generated with a parent of NULL; fix that up now. */
11380 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
11382 dw_die_ref die;
11384 if (TREE_CODE (decl) == FUNCTION_DECL)
11385 die = lookup_decl_die (decl);
11386 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11387 die = lookup_type_die (TREE_TYPE (decl));
11388 else
11389 die = NULL;
11391 if (die != NULL && die->die_parent == NULL)
11392 add_child_die (context_die, die);
11393 else
11394 gen_decl_die (decl, context_die);
11397 /* Output the DIEs to represent all sub-blocks (and the items declared
11398 therein) of this block. */
11399 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11400 subblocks != NULL;
11401 subblocks = BLOCK_CHAIN (subblocks))
11402 gen_block_die (subblocks, context_die, depth + 1);
11405 /* Is this a typedef we can avoid emitting? */
11407 static inline int
11408 is_redundant_typedef (decl)
11409 tree decl;
11411 if (TYPE_DECL_IS_STUB (decl))
11412 return 1;
11414 if (DECL_ARTIFICIAL (decl)
11415 && DECL_CONTEXT (decl)
11416 && is_tagged_type (DECL_CONTEXT (decl))
11417 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11418 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11419 /* Also ignore the artificial member typedef for the class name. */
11420 return 1;
11422 return 0;
11425 /* Generate Dwarf debug information for a decl described by DECL. */
11427 static void
11428 gen_decl_die (decl, context_die)
11429 tree decl;
11430 dw_die_ref context_die;
11432 tree origin;
11434 if (DECL_P (decl) && DECL_IGNORED_P (decl))
11435 return;
11437 switch (TREE_CODE (decl))
11439 case ERROR_MARK:
11440 break;
11442 case CONST_DECL:
11443 /* The individual enumerators of an enum type get output when we output
11444 the Dwarf representation of the relevant enum type itself. */
11445 break;
11447 case FUNCTION_DECL:
11448 /* Don't output any DIEs to represent mere function declarations,
11449 unless they are class members or explicit block externs. */
11450 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11451 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11452 break;
11454 /* If we're emitting a clone, emit info for the abstract instance. */
11455 if (DECL_ORIGIN (decl) != decl)
11456 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11458 /* If we're emitting an out-of-line copy of an inline function,
11459 emit info for the abstract instance and set up to refer to it. */
11460 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11461 && ! class_scope_p (context_die)
11462 /* dwarf2out_abstract_function won't emit a die if this is just
11463 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11464 that case, because that works only if we have a die. */
11465 && DECL_INITIAL (decl) != NULL_TREE)
11467 dwarf2out_abstract_function (decl);
11468 set_decl_origin_self (decl);
11471 /* Otherwise we're emitting the primary DIE for this decl. */
11472 else if (debug_info_level > DINFO_LEVEL_TERSE)
11474 /* Before we describe the FUNCTION_DECL itself, make sure that we
11475 have described its return type. */
11476 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11478 /* And its virtual context. */
11479 if (DECL_VINDEX (decl) != NULL_TREE)
11480 gen_type_die (DECL_CONTEXT (decl), context_die);
11482 /* And its containing type. */
11483 origin = decl_class_context (decl);
11484 if (origin != NULL_TREE)
11485 gen_type_die_for_member (origin, decl, context_die);
11488 /* Now output a DIE to represent the function itself. */
11489 gen_subprogram_die (decl, context_die);
11490 break;
11492 case TYPE_DECL:
11493 /* If we are in terse mode, don't generate any DIEs to represent any
11494 actual typedefs. */
11495 if (debug_info_level <= DINFO_LEVEL_TERSE)
11496 break;
11498 /* In the special case of a TYPE_DECL node representing the declaration
11499 of some type tag, if the given TYPE_DECL is marked as having been
11500 instantiated from some other (original) TYPE_DECL node (e.g. one which
11501 was generated within the original definition of an inline function) we
11502 have to generate a special (abbreviated) DW_TAG_structure_type,
11503 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11504 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11506 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11507 break;
11510 if (is_redundant_typedef (decl))
11511 gen_type_die (TREE_TYPE (decl), context_die);
11512 else
11513 /* Output a DIE to represent the typedef itself. */
11514 gen_typedef_die (decl, context_die);
11515 break;
11517 case LABEL_DECL:
11518 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11519 gen_label_die (decl, context_die);
11520 break;
11522 case VAR_DECL:
11523 /* If we are in terse mode, don't generate any DIEs to represent any
11524 variable declarations or definitions. */
11525 if (debug_info_level <= DINFO_LEVEL_TERSE)
11526 break;
11528 /* Output any DIEs that are needed to specify the type of this data
11529 object. */
11530 gen_type_die (TREE_TYPE (decl), context_die);
11532 /* And its containing type. */
11533 origin = decl_class_context (decl);
11534 if (origin != NULL_TREE)
11535 gen_type_die_for_member (origin, decl, context_die);
11537 /* Now output the DIE to represent the data object itself. This gets
11538 complicated because of the possibility that the VAR_DECL really
11539 represents an inlined instance of a formal parameter for an inline
11540 function. */
11541 origin = decl_ultimate_origin (decl);
11542 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11543 gen_formal_parameter_die (decl, context_die);
11544 else
11545 gen_variable_die (decl, context_die);
11546 break;
11548 case FIELD_DECL:
11549 /* Ignore the nameless fields that are used to skip bits but handle C++
11550 anonymous unions. */
11551 if (DECL_NAME (decl) != NULL_TREE
11552 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11554 gen_type_die (member_declared_type (decl), context_die);
11555 gen_field_die (decl, context_die);
11557 break;
11559 case PARM_DECL:
11560 gen_type_die (TREE_TYPE (decl), context_die);
11561 gen_formal_parameter_die (decl, context_die);
11562 break;
11564 case NAMESPACE_DECL:
11565 /* Ignore for now. */
11566 break;
11568 default:
11569 abort ();
11573 static void
11574 mark_limbo_die_list (ptr)
11575 void *ptr ATTRIBUTE_UNUSED;
11577 limbo_die_node *node;
11578 for (node = limbo_die_list; node; node = node->next)
11579 ggc_mark_tree (node->created_for);
11582 /* Add Ada "use" clause information for SGI Workshop debugger. */
11584 void
11585 dwarf2out_add_library_unit_info (filename, context_list)
11586 const char *filename;
11587 const char *context_list;
11589 unsigned int file_index;
11591 if (filename != NULL)
11593 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
11594 tree context_list_decl
11595 = build_decl (LABEL_DECL, get_identifier (context_list),
11596 void_type_node);
11598 TREE_PUBLIC (context_list_decl) = TRUE;
11599 add_name_attribute (unit_die, context_list);
11600 file_index = lookup_filename (filename);
11601 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11602 add_pubname (context_list_decl, unit_die);
11606 /* Output debug information for global decl DECL. Called from toplev.c after
11607 compilation proper has finished. */
11609 static void
11610 dwarf2out_global_decl (decl)
11611 tree decl;
11613 /* Output DWARF2 information for file-scope tentative data object
11614 declarations, file-scope (extern) function declarations (which had no
11615 corresponding body) and file-scope tagged type declarations and
11616 definitions which have not yet been forced out. */
11617 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11618 dwarf2out_decl (decl);
11621 /* Write the debugging output for DECL. */
11623 void
11624 dwarf2out_decl (decl)
11625 tree decl;
11627 dw_die_ref context_die = comp_unit_die;
11629 switch (TREE_CODE (decl))
11631 case ERROR_MARK:
11632 return;
11634 case FUNCTION_DECL:
11635 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11636 builtin function. Explicit programmer-supplied declarations of
11637 these same functions should NOT be ignored however. */
11638 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11639 return;
11641 /* What we would really like to do here is to filter out all mere
11642 file-scope declarations of file-scope functions which are never
11643 referenced later within this translation unit (and keep all of ones
11644 that *are* referenced later on) but we aren't clairvoyant, so we have
11645 no idea which functions will be referenced in the future (i.e. later
11646 on within the current translation unit). So here we just ignore all
11647 file-scope function declarations which are not also definitions. If
11648 and when the debugger needs to know something about these functions,
11649 it will have to hunt around and find the DWARF information associated
11650 with the definition of the function.
11652 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11653 nodes represent definitions and which ones represent mere
11654 declarations. We have to check DECL_INITIAL instead. That's because
11655 the C front-end supports some weird semantics for "extern inline"
11656 function definitions. These can get inlined within the current
11657 translation unit (an thus, we need to generate Dwarf info for their
11658 abstract instances so that the Dwarf info for the concrete inlined
11659 instances can have something to refer to) but the compiler never
11660 generates any out-of-lines instances of such things (despite the fact
11661 that they *are* definitions).
11663 The important point is that the C front-end marks these "extern
11664 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11665 them anyway. Note that the C++ front-end also plays some similar games
11666 for inline function definitions appearing within include files which
11667 also contain `#pragma interface' pragmas. */
11668 if (DECL_INITIAL (decl) == NULL_TREE)
11669 return;
11671 /* If we're a nested function, initially use a parent of NULL; if we're
11672 a plain function, this will be fixed up in decls_for_scope. If
11673 we're a method, it will be ignored, since we already have a DIE. */
11674 if (decl_function_context (decl))
11675 context_die = NULL;
11676 break;
11678 case VAR_DECL:
11679 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11680 declaration and if the declaration was never even referenced from
11681 within this entire compilation unit. We suppress these DIEs in
11682 order to save space in the .debug section (by eliminating entries
11683 which are probably useless). Note that we must not suppress
11684 block-local extern declarations (whether used or not) because that
11685 would screw-up the debugger's name lookup mechanism and cause it to
11686 miss things which really ought to be in scope at a given point. */
11687 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11688 return;
11690 /* If we are in terse mode, don't generate any DIEs to represent any
11691 variable declarations or definitions. */
11692 if (debug_info_level <= DINFO_LEVEL_TERSE)
11693 return;
11694 break;
11696 case TYPE_DECL:
11697 /* Don't emit stubs for types unless they are needed by other DIEs. */
11698 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11699 return;
11701 /* Don't bother trying to generate any DIEs to represent any of the
11702 normal built-in types for the language we are compiling. */
11703 if (DECL_SOURCE_LINE (decl) == 0)
11705 /* OK, we need to generate one for `bool' so GDB knows what type
11706 comparisons have. */
11707 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11708 == DW_LANG_C_plus_plus)
11709 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
11710 && ! DECL_IGNORED_P (decl))
11711 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11713 return;
11716 /* If we are in terse mode, don't generate any DIEs for types. */
11717 if (debug_info_level <= DINFO_LEVEL_TERSE)
11718 return;
11720 /* If we're a function-scope tag, initially use a parent of NULL;
11721 this will be fixed up in decls_for_scope. */
11722 if (decl_function_context (decl))
11723 context_die = NULL;
11725 break;
11727 default:
11728 return;
11731 gen_decl_die (decl, context_die);
11734 /* Output a marker (i.e. a label) for the beginning of the generated code for
11735 a lexical block. */
11737 static void
11738 dwarf2out_begin_block (line, blocknum)
11739 unsigned int line ATTRIBUTE_UNUSED;
11740 unsigned int blocknum;
11742 function_section (current_function_decl);
11743 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11746 /* Output a marker (i.e. a label) for the end of the generated code for a
11747 lexical block. */
11749 static void
11750 dwarf2out_end_block (line, blocknum)
11751 unsigned int line ATTRIBUTE_UNUSED;
11752 unsigned int blocknum;
11754 function_section (current_function_decl);
11755 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11758 /* Returns nonzero if it is appropriate not to emit any debugging
11759 information for BLOCK, because it doesn't contain any instructions.
11761 Don't allow this for blocks with nested functions or local classes
11762 as we would end up with orphans, and in the presence of scheduling
11763 we may end up calling them anyway. */
11765 static bool
11766 dwarf2out_ignore_block (block)
11767 tree block;
11769 tree decl;
11771 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11772 if (TREE_CODE (decl) == FUNCTION_DECL
11773 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11774 return 0;
11776 return 1;
11779 /* Lookup FILE_NAME (in the list of filenames that we know about here in
11780 dwarf2out.c) and return its "index". The index of each (known) filename is
11781 just a unique number which is associated with only that one filename. We
11782 need such numbers for the sake of generating labels (in the .debug_sfnames
11783 section) and references to those files numbers (in the .debug_srcinfo
11784 and.debug_macinfo sections). If the filename given as an argument is not
11785 found in our current list, add it to the list and assign it the next
11786 available unique index number. In order to speed up searches, we remember
11787 the index of the filename was looked up last. This handles the majority of
11788 all searches. */
11790 static unsigned
11791 lookup_filename (file_name)
11792 const char *file_name;
11794 unsigned i;
11796 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11797 if (strcmp (file_name, "<internal>") == 0
11798 || strcmp (file_name, "<built-in>") == 0)
11799 return 0;
11801 /* Check to see if the file name that was searched on the previous
11802 call matches this file name. If so, return the index. */
11803 if (file_table.last_lookup_index != 0)
11804 if (0 == strcmp (file_name,
11805 file_table.table[file_table.last_lookup_index]))
11806 return file_table.last_lookup_index;
11808 /* Didn't match the previous lookup, search the table */
11809 for (i = 1; i < file_table.in_use; i++)
11810 if (strcmp (file_name, file_table.table[i]) == 0)
11812 file_table.last_lookup_index = i;
11813 return i;
11816 /* Prepare to add a new table entry by making sure there is enough space in
11817 the table to do so. If not, expand the current table. */
11818 if (i == file_table.allocated)
11820 file_table.allocated = i + FILE_TABLE_INCREMENT;
11821 file_table.table = (char **)
11822 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11825 /* Add the new entry to the end of the filename table. */
11826 file_table.table[i] = xstrdup (file_name);
11827 file_table.in_use = i + 1;
11828 file_table.last_lookup_index = i;
11830 if (DWARF2_ASM_LINE_DEBUG_INFO)
11832 fprintf (asm_out_file, "\t.file %u ", i);
11833 output_quoted_string (asm_out_file, file_name);
11834 fputc ('\n', asm_out_file);
11837 return i;
11840 static void
11841 init_file_table ()
11843 /* Allocate the initial hunk of the file_table. */
11844 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11845 file_table.allocated = FILE_TABLE_INCREMENT;
11847 /* Skip the first entry - file numbers begin at 1. */
11848 file_table.in_use = 1;
11849 file_table.last_lookup_index = 0;
11852 /* Output a label to mark the beginning of a source code line entry
11853 and record information relating to this source line, in
11854 'line_info_table' for later output of the .debug_line section. */
11856 static void
11857 dwarf2out_source_line (line, filename)
11858 unsigned int line;
11859 const char *filename;
11861 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11863 function_section (current_function_decl);
11865 /* If requested, emit something human-readable. */
11866 if (flag_debug_asm)
11867 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11868 filename, line);
11870 if (DWARF2_ASM_LINE_DEBUG_INFO)
11872 unsigned file_num = lookup_filename (filename);
11874 /* Emit the .loc directive understood by GNU as. */
11875 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11877 /* Indicate that line number info exists. */
11878 line_info_table_in_use++;
11880 /* Indicate that multiple line number tables exist. */
11881 if (DECL_SECTION_NAME (current_function_decl))
11882 separate_line_info_table_in_use++;
11884 else if (DECL_SECTION_NAME (current_function_decl))
11886 dw_separate_line_info_ref line_info;
11887 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11888 separate_line_info_table_in_use);
11890 /* expand the line info table if necessary */
11891 if (separate_line_info_table_in_use
11892 == separate_line_info_table_allocated)
11894 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11895 separate_line_info_table
11896 = (dw_separate_line_info_ref)
11897 xrealloc (separate_line_info_table,
11898 separate_line_info_table_allocated
11899 * sizeof (dw_separate_line_info_entry));
11902 /* Add the new entry at the end of the line_info_table. */
11903 line_info
11904 = &separate_line_info_table[separate_line_info_table_in_use++];
11905 line_info->dw_file_num = lookup_filename (filename);
11906 line_info->dw_line_num = line;
11907 line_info->function = current_funcdef_number;
11909 else
11911 dw_line_info_ref line_info;
11913 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11914 line_info_table_in_use);
11916 /* Expand the line info table if necessary. */
11917 if (line_info_table_in_use == line_info_table_allocated)
11919 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11920 line_info_table
11921 = (dw_line_info_ref)
11922 xrealloc (line_info_table,
11923 (line_info_table_allocated
11924 * sizeof (dw_line_info_entry)));
11927 /* Add the new entry at the end of the line_info_table. */
11928 line_info = &line_info_table[line_info_table_in_use++];
11929 line_info->dw_file_num = lookup_filename (filename);
11930 line_info->dw_line_num = line;
11935 /* Record the beginning of a new source file. */
11937 static void
11938 dwarf2out_start_source_file (lineno, filename)
11939 unsigned int lineno;
11940 const char *filename;
11942 if (flag_eliminate_dwarf2_dups)
11944 /* Record the beginning of the file for break_out_includes. */
11945 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
11946 add_AT_string (bincl_die, DW_AT_name, filename);
11949 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11951 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11952 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11953 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11954 lineno);
11955 dw2_asm_output_data_uleb128 (lookup_filename (filename),
11956 "Filename we just started");
11960 /* Record the end of a source file. */
11962 static void
11963 dwarf2out_end_source_file (lineno)
11964 unsigned int lineno ATTRIBUTE_UNUSED;
11966 if (flag_eliminate_dwarf2_dups)
11967 /* Record the end of the file for break_out_includes. */
11968 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
11970 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11972 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11973 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11977 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11978 the tail part of the directive line, i.e. the part which is past the
11979 initial whitespace, #, whitespace, directive-name, whitespace part. */
11981 static void
11982 dwarf2out_define (lineno, buffer)
11983 unsigned lineno ATTRIBUTE_UNUSED;
11984 const char *buffer ATTRIBUTE_UNUSED;
11986 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11988 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11989 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11990 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11991 dw2_asm_output_nstring (buffer, -1, "The macro");
11995 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11996 the tail part of the directive line, i.e. the part which is past the
11997 initial whitespace, #, whitespace, directive-name, whitespace part. */
11999 static void
12000 dwarf2out_undef (lineno, buffer)
12001 unsigned lineno ATTRIBUTE_UNUSED;
12002 const char *buffer ATTRIBUTE_UNUSED;
12004 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12006 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12007 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
12008 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12009 dw2_asm_output_nstring (buffer, -1, "The macro");
12013 /* Set up for Dwarf output at the start of compilation. */
12015 static void
12016 dwarf2out_init (main_input_filename)
12017 const char *main_input_filename;
12019 init_file_table ();
12021 /* Remember the name of the primary input file. */
12022 primary_filename = main_input_filename;
12024 /* Add it to the file table first, under the assumption that we'll
12025 be emitting line number data for it first, which avoids having
12026 to add an initial DW_LNS_set_file. */
12027 lookup_filename (main_input_filename);
12029 /* Allocate the initial hunk of the decl_die_table. */
12030 decl_die_table
12031 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
12032 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
12033 decl_die_table_in_use = 0;
12035 /* Allocate the initial hunk of the decl_scope_table. */
12036 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
12037 ggc_add_tree_varray_root (&decl_scope_table, 1);
12039 /* Allocate the initial hunk of the abbrev_die_table. */
12040 abbrev_die_table
12041 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
12042 sizeof (dw_die_ref));
12043 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
12044 /* Zero-th entry is allocated, but unused */
12045 abbrev_die_table_in_use = 1;
12047 /* Allocate the initial hunk of the line_info_table. */
12048 line_info_table
12049 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
12050 sizeof (dw_line_info_entry));
12051 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
12053 /* Zero-th entry is allocated, but unused */
12054 line_info_table_in_use = 1;
12056 /* Generate the initial DIE for the .debug section. Note that the (string)
12057 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12058 will (typically) be a relative pathname and that this pathname should be
12059 taken as being relative to the directory from which the compiler was
12060 invoked when the given (base) source file was compiled. */
12061 comp_unit_die = gen_compile_unit_die (main_input_filename);
12063 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
12064 ggc_add_tree_varray_root (&incomplete_types, 1);
12066 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
12067 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
12069 ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list);
12071 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
12072 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
12073 DEBUG_ABBREV_SECTION_LABEL, 0);
12074 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12075 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
12076 else
12077 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
12079 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
12080 DEBUG_INFO_SECTION_LABEL, 0);
12081 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
12082 DEBUG_LINE_SECTION_LABEL, 0);
12083 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
12084 DEBUG_RANGES_SECTION_LABEL, 0);
12085 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12086 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
12087 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
12088 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
12089 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12090 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
12092 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12094 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12095 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
12096 DEBUG_MACINFO_SECTION_LABEL, 0);
12097 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
12100 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12102 text_section ();
12103 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
12107 /* Allocate a string in .debug_str hash table. */
12109 static hashnode
12110 indirect_string_alloc (tab)
12111 hash_table *tab ATTRIBUTE_UNUSED;
12113 struct indirect_string_node *node;
12115 node = xmalloc (sizeof (struct indirect_string_node));
12116 node->refcount = 0;
12117 node->form = 0;
12118 node->label = NULL;
12120 return (hashnode) node;
12123 /* A helper function for dwarf2out_finish called through
12124 ht_forall. Emit one queued .debug_str string. */
12126 static int
12127 output_indirect_string (pfile, h, v)
12128 struct cpp_reader *pfile ATTRIBUTE_UNUSED;
12129 hashnode h;
12130 const PTR v ATTRIBUTE_UNUSED;
12132 struct indirect_string_node *node = (struct indirect_string_node *) h;
12134 if (node->form == DW_FORM_strp)
12136 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
12137 ASM_OUTPUT_LABEL (asm_out_file, node->label);
12138 assemble_string ((const char *) HT_STR (&node->id),
12139 HT_LEN (&node->id) + 1);
12142 return 1;
12145 /* Output stuff that dwarf requires at the end of every file,
12146 and generate the DWARF-2 debugging info. */
12148 static void
12149 dwarf2out_finish (input_filename)
12150 const char *input_filename ATTRIBUTE_UNUSED;
12152 limbo_die_node *node, *next_node;
12153 dw_die_ref die = 0;
12155 /* Traverse the limbo die list, and add parent/child links. The only
12156 dies without parents that should be here are concrete instances of
12157 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12158 For concrete instances, we can get the parent die from the abstract
12159 instance. */
12160 for (node = limbo_die_list; node; node = next_node)
12162 next_node = node->next;
12163 die = node->die;
12165 if (die->die_parent == NULL)
12167 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
12168 tree context;
12170 if (origin)
12171 add_child_die (origin->die_parent, die);
12172 else if (die == comp_unit_die)
12174 /* If this was an expression for a bound involved in a function
12175 return type, it may be a SAVE_EXPR for which we weren't able
12176 to find a DIE previously. So try now. */
12177 else if (node->created_for
12178 && TREE_CODE (node->created_for) == SAVE_EXPR
12179 && 0 != (origin = (lookup_decl_die
12180 (SAVE_EXPR_CONTEXT
12181 (node->created_for)))))
12182 add_child_die (origin, die);
12183 else if (errorcount > 0 || sorrycount > 0)
12184 /* It's OK to be confused by errors in the input. */
12185 add_child_die (comp_unit_die, die);
12186 else if (node->created_for
12187 && ((DECL_P (node->created_for)
12188 && (context = DECL_CONTEXT (node->created_for)))
12189 || (TYPE_P (node->created_for)
12190 && (context = TYPE_CONTEXT (node->created_for))))
12191 && TREE_CODE (context) == FUNCTION_DECL)
12193 /* In certain situations, the lexical block containing a
12194 nested function can be optimized away, which results
12195 in the nested function die being orphaned. Likewise
12196 with the return type of that nested function. Force
12197 this to be a child of the containing function. */
12198 origin = lookup_decl_die (context);
12199 if (! origin)
12200 abort ();
12201 add_child_die (origin, die);
12203 else
12204 abort ();
12207 free (node);
12210 limbo_die_list = NULL;
12212 /* Walk through the list of incomplete types again, trying once more to
12213 emit full debugging info for them. */
12214 retry_incomplete_types ();
12216 /* We need to reverse all the dies before break_out_includes, or
12217 we'll see the end of an include file before the beginning. */
12218 reverse_all_dies (comp_unit_die);
12220 /* Generate separate CUs for each of the include files we've seen.
12221 They will go into limbo_die_list. */
12222 if (flag_eliminate_dwarf2_dups)
12223 break_out_includes (comp_unit_die);
12225 /* Traverse the DIE's and add add sibling attributes to those DIE's
12226 that have children. */
12227 add_sibling_attributes (comp_unit_die);
12228 for (node = limbo_die_list; node; node = node->next)
12229 add_sibling_attributes (node->die);
12231 /* Output a terminator label for the .text section. */
12232 text_section ();
12233 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
12235 /* Output the source line correspondence table. We must do this
12236 even if there is no line information. Otherwise, on an empty
12237 translation unit, we will generate a present, but empty,
12238 .debug_info section. IRIX 6.5 `nm' will then complain when
12239 examining the file. */
12240 if (! DWARF2_ASM_LINE_DEBUG_INFO)
12242 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12243 output_line_info ();
12246 /* Output location list section if necessary. */
12247 if (have_location_lists)
12249 /* Output the location lists info. */
12250 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
12251 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
12252 DEBUG_LOC_SECTION_LABEL, 0);
12253 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
12254 output_location_lists (die);
12255 have_location_lists = 0;
12258 /* We can only use the low/high_pc attributes if all of the code was
12259 in .text. */
12260 if (separate_line_info_table_in_use == 0)
12262 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
12263 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
12266 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12267 "base address". Use zero so that these addresses become absolute. */
12268 else if (have_location_lists || ranges_table_in_use)
12269 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
12271 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12272 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
12273 debug_line_section_label);
12275 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12276 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
12278 /* Output all of the compilation units. We put the main one last so that
12279 the offsets are available to output_pubnames. */
12280 for (node = limbo_die_list; node; node = node->next)
12281 output_comp_unit (node->die);
12283 output_comp_unit (comp_unit_die);
12285 /* Output the abbreviation table. */
12286 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12287 output_abbrev_section ();
12289 /* Output public names table if necessary. */
12290 if (pubname_table_in_use)
12292 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
12293 output_pubnames ();
12296 /* Output the address range information. We only put functions in the arange
12297 table, so don't write it out if we don't have any. */
12298 if (fde_table_in_use)
12300 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
12301 output_aranges ();
12304 /* Output ranges section if necessary. */
12305 if (ranges_table_in_use)
12307 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
12308 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12309 output_ranges ();
12312 /* Have to end the primary source file. */
12313 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12315 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12316 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12317 dw2_asm_output_data (1, 0, "End compilation unit");
12320 /* If we emitted any DW_FORM_strp form attribute, output the string
12321 table too. */
12322 if (debug_str_hash)
12323 ht_forall (debug_str_hash, output_indirect_string, NULL);
12325 #endif /* DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO */