* pt.c (instantiate_decl): Tell the repository code about the
[official-gcc.git] / gcc / dwarf2out.c
bloba0610801005c0f69b26346be2db48bf1758f7ed9
1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Emit .debug_line header even when there are no functions, since
27 the file numbers are used by .debug_info. Alternately, leave
28 out locations for types and decls.
29 Avoid talking about ctors and op= for PODs.
30 Factor out common prologue sequences into multiple CIEs. */
32 /* The first part of this file deals with the DWARF 2 frame unwind
33 information, which is also used by the GCC efficient exception handling
34 mechanism. The second part, controlled only by an #ifdef
35 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 information. */
38 #include "config.h"
39 #include "system.h"
40 #include "tree.h"
41 #include "flags.h"
42 #include "rtl.h"
43 #include "hard-reg-set.h"
44 #include "regs.h"
45 #include "insn-config.h"
46 #include "reload.h"
47 #include "function.h"
48 #include "output.h"
49 #include "expr.h"
50 #include "except.h"
51 #include "dwarf2.h"
52 #include "dwarf2out.h"
53 #include "dwarf2asm.h"
54 #include "toplev.h"
55 #include "varray.h"
56 #include "ggc.h"
57 #include "md5.h"
58 #include "tm_p.h"
60 /* DWARF2 Abbreviation Glossary:
61 CFA = Canonical Frame Address
62 a fixed address on the stack which identifies a call frame.
63 We define it to be the value of SP just before the call insn.
64 The CFA register and offset, which may change during the course
65 of the function, are used to calculate its value at runtime.
66 CFI = Call Frame Instruction
67 an instruction for the DWARF2 abstract machine
68 CIE = Common Information Entry
69 information describing information common to one or more FDEs
70 DIE = Debugging Information Entry
71 FDE = Frame Description Entry
72 information describing the stack call frame, in particular,
73 how to restore registers
75 DW_CFA_... = DWARF2 CFA call frame instruction
76 DW_TAG_... = DWARF2 DIE tag */
78 /* Decide whether we want to emit frame unwind information for the current
79 translation unit. */
81 int
82 dwarf2out_do_frame ()
84 return (write_symbols == DWARF2_DEBUG
85 #ifdef DWARF2_FRAME_INFO
86 || DWARF2_FRAME_INFO
87 #endif
88 #ifdef DWARF2_UNWIND_INFO
89 || flag_unwind_tables
90 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
91 #endif
95 /* The number of the current function definition for which debugging
96 information is being generated. These numbers range from 1 up to the
97 maximum number of function definitions contained within the current
98 compilation unit. These numbers are used to create unique label id's
99 unique to each function definition. */
100 unsigned current_funcdef_number = 0;
102 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
104 /* How to start an assembler comment. */
105 #ifndef ASM_COMMENT_START
106 #define ASM_COMMENT_START ";#"
107 #endif
109 typedef struct dw_cfi_struct *dw_cfi_ref;
110 typedef struct dw_fde_struct *dw_fde_ref;
111 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
113 /* Call frames are described using a sequence of Call Frame
114 Information instructions. The register number, offset
115 and address fields are provided as possible operands;
116 their use is selected by the opcode field. */
118 typedef union dw_cfi_oprnd_struct
120 unsigned long dw_cfi_reg_num;
121 long int dw_cfi_offset;
122 const char *dw_cfi_addr;
123 struct dw_loc_descr_struct *dw_cfi_loc;
125 dw_cfi_oprnd;
127 typedef struct dw_cfi_struct
129 dw_cfi_ref dw_cfi_next;
130 enum dwarf_call_frame_info dw_cfi_opc;
131 dw_cfi_oprnd dw_cfi_oprnd1;
132 dw_cfi_oprnd dw_cfi_oprnd2;
134 dw_cfi_node;
136 /* This is how we define the location of the CFA. We use to handle it
137 as REG + OFFSET all the time, but now it can be more complex.
138 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
139 Instead of passing around REG and OFFSET, we pass a copy
140 of this structure. */
141 typedef struct cfa_loc
143 unsigned long reg;
144 long offset;
145 long base_offset;
146 int indirect; /* 1 if CFA is accessed via a dereference. */
147 } dw_cfa_location;
149 /* All call frame descriptions (FDE's) in the GCC generated DWARF
150 refer to a single Common Information Entry (CIE), defined at
151 the beginning of the .debug_frame section. This used of a single
152 CIE obviates the need to keep track of multiple CIE's
153 in the DWARF generation routines below. */
155 typedef struct dw_fde_struct
157 const char *dw_fde_begin;
158 const char *dw_fde_current_label;
159 const char *dw_fde_end;
160 dw_cfi_ref dw_fde_cfi;
161 unsigned funcdef_number;
162 unsigned nothrow : 1;
163 unsigned uses_eh_lsda : 1;
165 dw_fde_node;
167 /* Maximum size (in bytes) of an artificially generated label. */
168 #define MAX_ARTIFICIAL_LABEL_BYTES 30
170 /* The size of the target's pointer type. */
171 #ifndef PTR_SIZE
172 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
173 #endif
175 /* The size of addresses as they appear in the Dwarf 2 data.
176 Some architectures use word addresses to refer to code locations,
177 but Dwarf 2 info always uses byte addresses. On such machines,
178 Dwarf 2 addresses need to be larger than the architecture's
179 pointers. */
180 #ifndef DWARF2_ADDR_SIZE
181 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
182 #endif
184 /* The size in bytes of a DWARF field indicating an offset or length
185 relative to a debug info section, specified to be 4 bytes in the
186 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
187 as PTR_SIZE. */
189 #ifndef DWARF_OFFSET_SIZE
190 #define DWARF_OFFSET_SIZE 4
191 #endif
193 #define DWARF_VERSION 2
195 /* Round SIZE up to the nearest BOUNDARY. */
196 #define DWARF_ROUND(SIZE,BOUNDARY) \
197 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
199 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
200 #ifndef DWARF_CIE_DATA_ALIGNMENT
201 #ifdef STACK_GROWS_DOWNWARD
202 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
203 #else
204 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
205 #endif
206 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
208 /* A pointer to the base of a table that contains frame description
209 information for each routine. */
210 static dw_fde_ref fde_table;
212 /* Number of elements currently allocated for fde_table. */
213 static unsigned fde_table_allocated;
215 /* Number of elements in fde_table currently in use. */
216 static unsigned fde_table_in_use;
218 /* Size (in elements) of increments by which we may expand the
219 fde_table. */
220 #define FDE_TABLE_INCREMENT 256
222 /* A list of call frame insns for the CIE. */
223 static dw_cfi_ref cie_cfi_head;
225 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
226 attribute that accelerates the lookup of the FDE associated
227 with the subprogram. This variable holds the table index of the FDE
228 associated with the current function (body) definition. */
229 static unsigned current_funcdef_fde;
231 /* Forward declarations for functions defined in this file. */
233 static char *stripattributes PARAMS ((const char *));
234 static const char *dwarf_cfi_name PARAMS ((unsigned));
235 static dw_cfi_ref new_cfi PARAMS ((void));
236 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
237 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
238 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
239 static void lookup_cfa PARAMS ((dw_cfa_location *));
240 static void reg_save PARAMS ((const char *, unsigned,
241 unsigned, long));
242 static void initial_return_save PARAMS ((rtx));
243 static long stack_adjust_offset PARAMS ((rtx));
244 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
245 static void output_call_frame_info PARAMS ((int));
246 static void dwarf2out_stack_adjust PARAMS ((rtx));
247 static void queue_reg_save PARAMS ((const char *, rtx, long));
248 static void flush_queued_reg_saves PARAMS ((void));
249 static bool clobbers_queued_reg_save PARAMS ((rtx));
250 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
252 /* Support for complex CFA locations. */
253 static void output_cfa_loc PARAMS ((dw_cfi_ref));
254 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
255 struct dw_loc_descr_struct *));
256 static struct dw_loc_descr_struct *build_cfa_loc
257 PARAMS ((dw_cfa_location *));
258 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
260 /* How to start an assembler comment. */
261 #ifndef ASM_COMMENT_START
262 #define ASM_COMMENT_START ";#"
263 #endif
265 /* Data and reference forms for relocatable data. */
266 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
267 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
269 /* Pseudo-op for defining a new section. */
270 #ifndef SECTION_ASM_OP
271 #define SECTION_ASM_OP "\t.section\t"
272 #endif
274 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
275 print the SECTION_ASM_OP and the section name. The default here works for
276 almost all svr4 assemblers, except for the sparc, where the section name
277 must be enclosed in double quotes. (See sparcv4.h). */
278 #ifndef SECTION_FORMAT
279 #ifdef PUSHSECTION_FORMAT
280 #define SECTION_FORMAT PUSHSECTION_FORMAT
281 #else
282 #define SECTION_FORMAT "%s%s\n"
283 #endif
284 #endif
286 #ifndef FRAME_SECTION
287 #define FRAME_SECTION ".debug_frame"
288 #endif
290 #ifndef FUNC_BEGIN_LABEL
291 #define FUNC_BEGIN_LABEL "LFB"
292 #endif
293 #ifndef FUNC_END_LABEL
294 #define FUNC_END_LABEL "LFE"
295 #endif
296 #define CIE_AFTER_SIZE_LABEL "LSCIE"
297 #define CIE_END_LABEL "LECIE"
298 #define CIE_LENGTH_LABEL "LLCIE"
299 #define FDE_LABEL "LSFDE"
300 #define FDE_AFTER_SIZE_LABEL "LASFDE"
301 #define FDE_END_LABEL "LEFDE"
302 #define FDE_LENGTH_LABEL "LLFDE"
303 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
304 #define LINE_NUMBER_END_LABEL "LELT"
305 #define LN_PROLOG_AS_LABEL "LASLTP"
306 #define LN_PROLOG_END_LABEL "LELTP"
307 #define DIE_LABEL_PREFIX "DW"
309 /* Definitions of defaults for various types of primitive assembly language
310 output operations. These may be overridden from within the tm.h file,
311 but typically, that is unnecessary. */
313 #ifndef ASM_OUTPUT_SECTION
314 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
315 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
316 #endif
318 #ifdef SET_ASM_OP
319 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
320 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
321 do { \
322 fprintf (FILE, "%s", SET_ASM_OP); \
323 assemble_name (FILE, SY); \
324 fputc (',', FILE); \
325 assemble_name (FILE, HI); \
326 fputc ('-', FILE); \
327 assemble_name (FILE, LO); \
328 } while (0)
329 #endif
330 #endif /* SET_ASM_OP */
332 /* The DWARF 2 CFA column which tracks the return address. Normally this
333 is the column for PC, or the first column after all of the hard
334 registers. */
335 #ifndef DWARF_FRAME_RETURN_COLUMN
336 #ifdef PC_REGNUM
337 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
338 #else
339 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
340 #endif
341 #endif
343 /* The mapping from gcc register number to DWARF 2 CFA column number. By
344 default, we just provide columns for all registers. */
345 #ifndef DWARF_FRAME_REGNUM
346 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
347 #endif
349 /* Hook used by __throw. */
352 expand_builtin_dwarf_fp_regnum ()
354 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
357 /* The offset from the incoming value of %sp to the top of the stack frame
358 for the current function. */
359 #ifndef INCOMING_FRAME_SP_OFFSET
360 #define INCOMING_FRAME_SP_OFFSET 0
361 #endif
363 /* Return a pointer to a copy of the section string name S with all
364 attributes stripped off, and an asterisk prepended (for assemble_name). */
366 static inline char *
367 stripattributes (s)
368 const char *s;
370 char *stripped = xmalloc (strlen (s) + 2);
371 char *p = stripped;
373 *p++ = '*';
375 while (*s && *s != ',')
376 *p++ = *s++;
378 *p = '\0';
379 return stripped;
382 /* Generate code to initialize the register size table. */
384 void
385 expand_builtin_init_dwarf_reg_sizes (address)
386 tree address;
388 int i;
389 enum machine_mode mode = TYPE_MODE (char_type_node);
390 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
391 rtx mem = gen_rtx_MEM (mode, addr);
393 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
395 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
396 int size = GET_MODE_SIZE (reg_raw_mode[i]);
398 if (offset < 0)
399 continue;
401 emit_move_insn (change_address (mem, mode,
402 plus_constant (addr, offset)),
403 GEN_INT (size));
407 /* Convert a DWARF call frame info. operation to its string name */
409 static const char *
410 dwarf_cfi_name (cfi_opc)
411 register unsigned cfi_opc;
413 switch (cfi_opc)
415 case DW_CFA_advance_loc:
416 return "DW_CFA_advance_loc";
417 case DW_CFA_offset:
418 return "DW_CFA_offset";
419 case DW_CFA_restore:
420 return "DW_CFA_restore";
421 case DW_CFA_nop:
422 return "DW_CFA_nop";
423 case DW_CFA_set_loc:
424 return "DW_CFA_set_loc";
425 case DW_CFA_advance_loc1:
426 return "DW_CFA_advance_loc1";
427 case DW_CFA_advance_loc2:
428 return "DW_CFA_advance_loc2";
429 case DW_CFA_advance_loc4:
430 return "DW_CFA_advance_loc4";
431 case DW_CFA_offset_extended:
432 return "DW_CFA_offset_extended";
433 case DW_CFA_restore_extended:
434 return "DW_CFA_restore_extended";
435 case DW_CFA_undefined:
436 return "DW_CFA_undefined";
437 case DW_CFA_same_value:
438 return "DW_CFA_same_value";
439 case DW_CFA_register:
440 return "DW_CFA_register";
441 case DW_CFA_remember_state:
442 return "DW_CFA_remember_state";
443 case DW_CFA_restore_state:
444 return "DW_CFA_restore_state";
445 case DW_CFA_def_cfa:
446 return "DW_CFA_def_cfa";
447 case DW_CFA_def_cfa_register:
448 return "DW_CFA_def_cfa_register";
449 case DW_CFA_def_cfa_offset:
450 return "DW_CFA_def_cfa_offset";
451 case DW_CFA_def_cfa_expression:
452 return "DW_CFA_def_cfa_expression";
454 /* SGI/MIPS specific */
455 case DW_CFA_MIPS_advance_loc8:
456 return "DW_CFA_MIPS_advance_loc8";
458 /* GNU extensions */
459 case DW_CFA_GNU_window_save:
460 return "DW_CFA_GNU_window_save";
461 case DW_CFA_GNU_args_size:
462 return "DW_CFA_GNU_args_size";
463 case DW_CFA_GNU_negative_offset_extended:
464 return "DW_CFA_GNU_negative_offset_extended";
466 default:
467 return "DW_CFA_<unknown>";
471 /* Return a pointer to a newly allocated Call Frame Instruction. */
473 static inline dw_cfi_ref
474 new_cfi ()
476 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
478 cfi->dw_cfi_next = NULL;
479 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
480 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
482 return cfi;
485 /* Add a Call Frame Instruction to list of instructions. */
487 static inline void
488 add_cfi (list_head, cfi)
489 register dw_cfi_ref *list_head;
490 register dw_cfi_ref cfi;
492 register dw_cfi_ref *p;
494 /* Find the end of the chain. */
495 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
498 *p = cfi;
501 /* Generate a new label for the CFI info to refer to. */
503 char *
504 dwarf2out_cfi_label ()
506 static char label[20];
507 static unsigned long label_num = 0;
509 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
510 ASM_OUTPUT_LABEL (asm_out_file, label);
512 return label;
515 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
516 or to the CIE if LABEL is NULL. */
518 static void
519 add_fde_cfi (label, cfi)
520 register const char *label;
521 register dw_cfi_ref cfi;
523 if (label)
525 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
527 if (*label == 0)
528 label = dwarf2out_cfi_label ();
530 if (fde->dw_fde_current_label == NULL
531 || strcmp (label, fde->dw_fde_current_label) != 0)
533 register dw_cfi_ref xcfi;
535 fde->dw_fde_current_label = label = xstrdup (label);
537 /* Set the location counter to the new label. */
538 xcfi = new_cfi ();
539 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
540 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
541 add_cfi (&fde->dw_fde_cfi, xcfi);
544 add_cfi (&fde->dw_fde_cfi, cfi);
547 else
548 add_cfi (&cie_cfi_head, cfi);
551 /* Subroutine of lookup_cfa. */
553 static inline void
554 lookup_cfa_1 (cfi, loc)
555 register dw_cfi_ref cfi;
556 register dw_cfa_location *loc;
558 switch (cfi->dw_cfi_opc)
560 case DW_CFA_def_cfa_offset:
561 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
562 break;
563 case DW_CFA_def_cfa_register:
564 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
565 break;
566 case DW_CFA_def_cfa:
567 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
568 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
569 break;
570 case DW_CFA_def_cfa_expression:
571 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
572 break;
573 default:
574 break;
578 /* Find the previous value for the CFA. */
580 static void
581 lookup_cfa (loc)
582 register dw_cfa_location *loc;
584 register dw_cfi_ref cfi;
586 loc->reg = (unsigned long) -1;
587 loc->offset = 0;
588 loc->indirect = 0;
589 loc->base_offset = 0;
591 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
592 lookup_cfa_1 (cfi, loc);
594 if (fde_table_in_use)
596 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
597 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
598 lookup_cfa_1 (cfi, loc);
602 /* The current rule for calculating the DWARF2 canonical frame address. */
603 static dw_cfa_location cfa;
605 /* The register used for saving registers to the stack, and its offset
606 from the CFA. */
607 static dw_cfa_location cfa_store;
609 /* The running total of the size of arguments pushed onto the stack. */
610 static long args_size;
612 /* The last args_size we actually output. */
613 static long old_args_size;
615 /* Entry point to update the canonical frame address (CFA).
616 LABEL is passed to add_fde_cfi. The value of CFA is now to be
617 calculated from REG+OFFSET. */
619 void
620 dwarf2out_def_cfa (label, reg, offset)
621 register const char *label;
622 unsigned reg;
623 long offset;
625 dw_cfa_location loc;
626 loc.indirect = 0;
627 loc.base_offset = 0;
628 loc.reg = reg;
629 loc.offset = offset;
630 def_cfa_1 (label, &loc);
633 /* This routine does the actual work. The CFA is now calculated from
634 the dw_cfa_location structure. */
635 static void
636 def_cfa_1 (label, loc_p)
637 register const char *label;
638 dw_cfa_location *loc_p;
640 register dw_cfi_ref cfi;
641 dw_cfa_location old_cfa, loc;
643 cfa = *loc_p;
644 loc = *loc_p;
646 if (cfa_store.reg == loc.reg && loc.indirect == 0)
647 cfa_store.offset = loc.offset;
649 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
650 lookup_cfa (&old_cfa);
652 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
653 loc.indirect == old_cfa.indirect)
655 if (loc.indirect == 0
656 || loc.base_offset == old_cfa.base_offset)
657 /* Nothing changed so no need to issue any call frame
658 instructions. */
659 return;
662 cfi = new_cfi ();
664 if (loc.reg == old_cfa.reg && !loc.indirect)
666 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
667 indicating the CFA register did not change but the offset
668 did. */
669 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
670 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
673 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
674 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
675 && !loc.indirect)
677 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
678 indicating the CFA register has changed to <register> but the
679 offset has not changed. */
680 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
681 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
683 #endif
685 else if (loc.indirect == 0)
687 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
688 indicating the CFA register has changed to <register> with
689 the specified offset. */
690 cfi->dw_cfi_opc = DW_CFA_def_cfa;
691 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
692 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
694 else
696 /* Construct a DW_CFA_def_cfa_expression instruction to
697 calculate the CFA using a full location expression since no
698 register-offset pair is available. */
699 struct dw_loc_descr_struct *loc_list;
700 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
701 loc_list = build_cfa_loc (&loc);
702 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
705 add_fde_cfi (label, cfi);
708 /* Add the CFI for saving a register. REG is the CFA column number.
709 LABEL is passed to add_fde_cfi.
710 If SREG is -1, the register is saved at OFFSET from the CFA;
711 otherwise it is saved in SREG. */
713 static void
714 reg_save (label, reg, sreg, offset)
715 register const char *label;
716 register unsigned reg;
717 register unsigned sreg;
718 register long offset;
720 register dw_cfi_ref cfi = new_cfi ();
722 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
724 /* The following comparison is correct. -1 is used to indicate that
725 the value isn't a register number. */
726 if (sreg == (unsigned int) -1)
728 if (reg & ~0x3f)
729 /* The register number won't fit in 6 bits, so we have to use
730 the long form. */
731 cfi->dw_cfi_opc = DW_CFA_offset_extended;
732 else
733 cfi->dw_cfi_opc = DW_CFA_offset;
735 #ifdef ENABLE_CHECKING
737 /* If we get an offset that is not a multiple of
738 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
739 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
740 description. */
741 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
743 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
744 abort ();
746 #endif
747 offset /= DWARF_CIE_DATA_ALIGNMENT;
748 if (offset < 0)
750 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
751 offset = -offset;
753 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
755 else if (sreg == reg)
756 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
757 return;
758 else
760 cfi->dw_cfi_opc = DW_CFA_register;
761 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
764 add_fde_cfi (label, cfi);
767 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
768 This CFI tells the unwinder that it needs to restore the window registers
769 from the previous frame's window save area.
771 ??? Perhaps we should note in the CIE where windows are saved (instead of
772 assuming 0(cfa)) and what registers are in the window. */
774 void
775 dwarf2out_window_save (label)
776 register const char *label;
778 register dw_cfi_ref cfi = new_cfi ();
779 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
780 add_fde_cfi (label, cfi);
783 /* Add a CFI to update the running total of the size of arguments
784 pushed onto the stack. */
786 void
787 dwarf2out_args_size (label, size)
788 const char *label;
789 long size;
791 register dw_cfi_ref cfi;
793 if (size == old_args_size)
794 return;
795 old_args_size = size;
797 cfi = new_cfi ();
798 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
799 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
800 add_fde_cfi (label, cfi);
803 /* Entry point for saving a register to the stack. REG is the GCC register
804 number. LABEL and OFFSET are passed to reg_save. */
806 void
807 dwarf2out_reg_save (label, reg, offset)
808 register const char *label;
809 register unsigned reg;
810 register long offset;
812 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
815 /* Entry point for saving the return address in the stack.
816 LABEL and OFFSET are passed to reg_save. */
818 void
819 dwarf2out_return_save (label, offset)
820 register const char *label;
821 register long offset;
823 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
826 /* Entry point for saving the return address in a register.
827 LABEL and SREG are passed to reg_save. */
829 void
830 dwarf2out_return_reg (label, sreg)
831 register const char *label;
832 register unsigned sreg;
834 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
837 /* Record the initial position of the return address. RTL is
838 INCOMING_RETURN_ADDR_RTX. */
840 static void
841 initial_return_save (rtl)
842 register rtx rtl;
844 unsigned int reg = (unsigned int) -1;
845 long offset = 0;
847 switch (GET_CODE (rtl))
849 case REG:
850 /* RA is in a register. */
851 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
852 break;
853 case MEM:
854 /* RA is on the stack. */
855 rtl = XEXP (rtl, 0);
856 switch (GET_CODE (rtl))
858 case REG:
859 if (REGNO (rtl) != STACK_POINTER_REGNUM)
860 abort ();
861 offset = 0;
862 break;
863 case PLUS:
864 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
865 abort ();
866 offset = INTVAL (XEXP (rtl, 1));
867 break;
868 case MINUS:
869 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
870 abort ();
871 offset = -INTVAL (XEXP (rtl, 1));
872 break;
873 default:
874 abort ();
876 break;
877 case PLUS:
878 /* The return address is at some offset from any value we can
879 actually load. For instance, on the SPARC it is in %i7+8. Just
880 ignore the offset for now; it doesn't matter for unwinding frames. */
881 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
882 abort ();
883 initial_return_save (XEXP (rtl, 0));
884 return;
885 default:
886 abort ();
889 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
892 /* Given a SET, calculate the amount of stack adjustment it
893 contains. */
895 static long
896 stack_adjust_offset (pattern)
897 rtx pattern;
899 rtx src = SET_SRC (pattern);
900 rtx dest = SET_DEST (pattern);
901 long offset = 0;
902 enum rtx_code code;
904 if (dest == stack_pointer_rtx)
906 /* (set (reg sp) (plus (reg sp) (const_int))) */
907 code = GET_CODE (src);
908 if (! (code == PLUS || code == MINUS)
909 || XEXP (src, 0) != stack_pointer_rtx
910 || GET_CODE (XEXP (src, 1)) != CONST_INT)
911 return 0;
913 offset = INTVAL (XEXP (src, 1));
915 else if (GET_CODE (dest) == MEM)
917 /* (set (mem (pre_dec (reg sp))) (foo)) */
918 src = XEXP (dest, 0);
919 code = GET_CODE (src);
921 if (! (code == PRE_DEC || code == PRE_INC
922 || code == PRE_MODIFY)
923 || XEXP (src, 0) != stack_pointer_rtx)
924 return 0;
926 if (code == PRE_MODIFY)
928 rtx val = XEXP (XEXP (src, 1), 1);
929 /* We handle only adjustments by constant amount. */
930 if (GET_CODE (XEXP (src, 1)) != PLUS ||
931 GET_CODE (val) != CONST_INT)
932 abort();
933 offset = -INTVAL (val);
935 else offset = GET_MODE_SIZE (GET_MODE (dest));
937 else
938 return 0;
940 if (code == PLUS || code == PRE_INC)
941 offset = -offset;
943 return offset;
946 /* Check INSN to see if it looks like a push or a stack adjustment, and
947 make a note of it if it does. EH uses this information to find out how
948 much extra space it needs to pop off the stack. */
950 static void
951 dwarf2out_stack_adjust (insn)
952 rtx insn;
954 long offset;
955 const char *label;
957 if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN)
959 /* Extract the size of the args from the CALL rtx itself. */
961 insn = PATTERN (insn);
962 if (GET_CODE (insn) == PARALLEL)
963 insn = XVECEXP (insn, 0, 0);
964 if (GET_CODE (insn) == SET)
965 insn = SET_SRC (insn);
966 if (GET_CODE (insn) != CALL)
967 abort ();
968 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
969 return;
972 /* If only calls can throw, and we have a frame pointer,
973 save up adjustments until we see the CALL_INSN. */
974 else if (! flag_non_call_exceptions
975 && cfa.reg != STACK_POINTER_REGNUM)
976 return;
978 if (GET_CODE (insn) == BARRIER)
980 /* When we see a BARRIER, we know to reset args_size to 0. Usually
981 the compiler will have already emitted a stack adjustment, but
982 doesn't bother for calls to noreturn functions. */
983 #ifdef STACK_GROWS_DOWNWARD
984 offset = -args_size;
985 #else
986 offset = args_size;
987 #endif
989 else if (GET_CODE (PATTERN (insn)) == SET)
991 offset = stack_adjust_offset (PATTERN (insn));
993 else if (GET_CODE (PATTERN (insn)) == PARALLEL
994 || GET_CODE (PATTERN (insn)) == SEQUENCE)
996 /* There may be stack adjustments inside compound insns. Search
997 for them. */
998 int j;
1000 offset = 0;
1001 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1003 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1004 if (GET_CODE (pattern) == SET)
1005 offset += stack_adjust_offset (pattern);
1008 else
1009 return;
1011 if (offset == 0)
1012 return;
1014 if (cfa.reg == STACK_POINTER_REGNUM)
1015 cfa.offset += offset;
1017 #ifndef STACK_GROWS_DOWNWARD
1018 offset = -offset;
1019 #endif
1020 args_size += offset;
1021 if (args_size < 0)
1022 args_size = 0;
1024 label = dwarf2out_cfi_label ();
1025 def_cfa_1 (label, &cfa);
1026 dwarf2out_args_size (label, args_size);
1029 /* We delay emitting a register save until either (a) we reach the end
1030 of the prologue or (b) the register is clobbered. This clusters
1031 register saves so that there are fewer pc advances. */
1033 struct queued_reg_save
1035 struct queued_reg_save *next;
1036 rtx reg;
1037 long cfa_offset;
1040 static struct queued_reg_save *queued_reg_saves;
1041 static const char *last_reg_save_label;
1043 static void
1044 queue_reg_save (label, reg, offset)
1045 const char *label;
1046 rtx reg;
1047 long offset;
1049 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1051 q->next = queued_reg_saves;
1052 q->reg = reg;
1053 q->cfa_offset = offset;
1054 queued_reg_saves = q;
1056 last_reg_save_label = label;
1059 static void
1060 flush_queued_reg_saves ()
1062 struct queued_reg_save *q, *next;
1064 for (q = queued_reg_saves; q ; q = next)
1066 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1067 next = q->next;
1068 free (q);
1071 queued_reg_saves = NULL;
1072 last_reg_save_label = NULL;
1075 static bool
1076 clobbers_queued_reg_save (insn)
1077 rtx insn;
1079 struct queued_reg_save *q;
1081 for (q = queued_reg_saves; q ; q = q->next)
1082 if (modified_in_p (q->reg, insn))
1083 return true;
1085 return false;
1089 /* A temporary register holding an integral value used in adjusting SP
1090 or setting up the store_reg. The "offset" field holds the integer
1091 value, not an offset. */
1092 static dw_cfa_location cfa_temp;
1094 /* Record call frame debugging information for an expression EXPR,
1095 which either sets SP or FP (adjusting how we calculate the frame
1096 address) or saves a register to the stack. LABEL indicates the
1097 address of EXPR.
1099 This function encodes a state machine mapping rtxes to actions on
1100 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1101 users need not read the source code.
1103 The High-Level Picture
1105 Changes in the register we use to calculate the CFA: Currently we
1106 assume that if you copy the CFA register into another register, we
1107 should take the other one as the new CFA register; this seems to
1108 work pretty well. If it's wrong for some target, it's simple
1109 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1111 Changes in the register we use for saving registers to the stack:
1112 This is usually SP, but not always. Again, we deduce that if you
1113 copy SP into another register (and SP is not the CFA register),
1114 then the new register is the one we will be using for register
1115 saves. This also seems to work.
1117 Register saves: There's not much guesswork about this one; if
1118 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1119 register save, and the register used to calculate the destination
1120 had better be the one we think we're using for this purpose.
1122 Except: If the register being saved is the CFA register, and the
1123 offset is non-zero, we are saving the CFA, so we assume we have to
1124 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1125 the intent is to save the value of SP from the previous frame.
1127 Invariants / Summaries of Rules
1129 cfa current rule for calculating the CFA. It usually
1130 consists of a register and an offset.
1131 cfa_store register used by prologue code to save things to the stack
1132 cfa_store.offset is the offset from the value of
1133 cfa_store.reg to the actual CFA
1134 cfa_temp register holding an integral value. cfa_temp.offset
1135 stores the value, which will be used to adjust the
1136 stack pointer. cfa_temp is also used like cfa_store,
1137 to track stores to the stack via fp or a temp reg.
1139 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1140 with cfa.reg as the first operand changes the cfa.reg and its
1141 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1142 cfa_temp.offset.
1144 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1145 expression yielding a constant. This sets cfa_temp.reg
1146 and cfa_temp.offset.
1148 Rule 5: Create a new register cfa_store used to save items to the
1149 stack.
1151 Rules 10-14: Save a register to the stack. Define offset as the
1152 difference of the original location and cfa_store's
1153 location (or cfa_temp's location if cfa_temp is used).
1155 The Rules
1157 "{a,b}" indicates a choice of a xor b.
1158 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1160 Rule 1:
1161 (set <reg1> <reg2>:cfa.reg)
1162 effects: cfa.reg = <reg1>
1163 cfa.offset unchanged
1164 cfa_temp.reg = <reg1>
1165 cfa_temp.offset = cfa.offset
1167 Rule 2:
1168 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1169 effects: cfa.reg = sp if fp used
1170 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1171 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1172 if cfa_store.reg==sp
1174 Rule 3:
1175 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1176 effects: cfa.reg = fp
1177 cfa_offset += +/- <const_int>
1179 Rule 4:
1180 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1181 constraints: <reg1> != fp
1182 <reg1> != sp
1183 effects: cfa.reg = <reg1>
1184 cfa_temp.reg = <reg1>
1185 cfa_temp.offset = cfa.offset
1187 Rule 5:
1188 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1189 constraints: <reg1> != fp
1190 <reg1> != sp
1191 effects: cfa_store.reg = <reg1>
1192 cfa_store.offset = cfa.offset - cfa_temp.offset
1194 Rule 6:
1195 (set <reg> <const_int>)
1196 effects: cfa_temp.reg = <reg>
1197 cfa_temp.offset = <const_int>
1199 Rule 7:
1200 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1201 effects: cfa_temp.reg = <reg1>
1202 cfa_temp.offset |= <const_int>
1204 Rule 8:
1205 (set <reg> (high <exp>))
1206 effects: none
1208 Rule 9:
1209 (set <reg> (lo_sum <exp> <const_int>))
1210 effects: cfa_temp.reg = <reg>
1211 cfa_temp.offset = <const_int>
1213 Rule 10:
1214 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1215 effects: cfa_store.offset -= <const_int>
1216 cfa.offset = cfa_store.offset if cfa.reg == sp
1217 cfa.reg = sp
1218 cfa.base_offset = -cfa_store.offset
1220 Rule 11:
1221 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1222 effects: cfa_store.offset += -/+ mode_size(mem)
1223 cfa.offset = cfa_store.offset if cfa.reg == sp
1224 cfa.reg = sp
1225 cfa.base_offset = -cfa_store.offset
1227 Rule 12:
1228 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>)
1229 effects: cfa.reg = <reg1>
1230 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1232 Rule 13:
1233 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1234 effects: cfa.reg = <reg1>
1235 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1237 Rule 14:
1238 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1239 effects: cfa.reg = <reg1>
1240 cfa.base_offset = -cfa_temp.offset
1241 cfa_temp.offset -= mode_size(mem) */
1243 static void
1244 dwarf2out_frame_debug_expr (expr, label)
1245 rtx expr;
1246 const char *label;
1248 rtx src, dest;
1249 long offset;
1251 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1252 the PARALLEL independently. The first element is always processed if
1253 it is a SET. This is for backward compatibility. Other elements
1254 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1255 flag is set in them. */
1257 if (GET_CODE (expr) == PARALLEL
1258 || GET_CODE (expr) == SEQUENCE)
1260 int par_index;
1261 int limit = XVECLEN (expr, 0);
1263 for (par_index = 0; par_index < limit; par_index++)
1265 rtx x = XVECEXP (expr, 0, par_index);
1267 if (GET_CODE (x) == SET &&
1268 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1269 dwarf2out_frame_debug_expr (x, label);
1271 return;
1274 if (GET_CODE (expr) != SET)
1275 abort ();
1277 src = SET_SRC (expr);
1278 dest = SET_DEST (expr);
1280 switch (GET_CODE (dest))
1282 case REG:
1283 /* Rule 1 */
1284 /* Update the CFA rule wrt SP or FP. Make sure src is
1285 relative to the current CFA register. */
1286 switch (GET_CODE (src))
1288 /* Setting FP from SP. */
1289 case REG:
1290 if (cfa.reg == (unsigned) REGNO (src))
1291 /* OK. */
1293 else
1294 abort ();
1296 /* We used to require that dest be either SP or FP, but the
1297 ARM copies SP to a temporary register, and from there to
1298 FP. So we just rely on the backends to only set
1299 RTX_FRAME_RELATED_P on appropriate insns. */
1300 cfa.reg = REGNO (dest);
1301 cfa_temp.reg = cfa.reg;
1302 cfa_temp.offset = cfa.offset;
1303 break;
1305 case PLUS:
1306 case MINUS:
1307 case LO_SUM:
1308 if (dest == stack_pointer_rtx)
1310 /* Rule 2 */
1311 /* Adjusting SP. */
1312 switch (GET_CODE (XEXP (src, 1)))
1314 case CONST_INT:
1315 offset = INTVAL (XEXP (src, 1));
1316 break;
1317 case REG:
1318 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1319 abort ();
1320 offset = cfa_temp.offset;
1321 break;
1322 default:
1323 abort ();
1326 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1328 /* Restoring SP from FP in the epilogue. */
1329 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1330 abort ();
1331 cfa.reg = STACK_POINTER_REGNUM;
1333 else if (GET_CODE (src) == LO_SUM)
1334 /* Assume we've set the source reg of the LO_SUM from sp. */
1336 else if (XEXP (src, 0) != stack_pointer_rtx)
1337 abort ();
1339 if (GET_CODE (src) != MINUS)
1340 offset = -offset;
1341 if (cfa.reg == STACK_POINTER_REGNUM)
1342 cfa.offset += offset;
1343 if (cfa_store.reg == STACK_POINTER_REGNUM)
1344 cfa_store.offset += offset;
1346 else if (dest == hard_frame_pointer_rtx)
1348 /* Rule 3 */
1349 /* Either setting the FP from an offset of the SP,
1350 or adjusting the FP */
1351 if (! frame_pointer_needed)
1352 abort ();
1354 if (GET_CODE (XEXP (src, 0)) == REG
1355 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1356 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1358 offset = INTVAL (XEXP (src, 1));
1359 if (GET_CODE (src) != MINUS)
1360 offset = -offset;
1361 cfa.offset += offset;
1362 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1364 else
1365 abort ();
1367 else
1369 if (GET_CODE (src) == MINUS)
1370 abort ();
1372 /* Rule 4 */
1373 if (GET_CODE (XEXP (src, 0)) == REG
1374 && REGNO (XEXP (src, 0)) == cfa.reg
1375 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1377 /* Setting a temporary CFA register that will be copied
1378 into the FP later on. */
1379 offset = - INTVAL (XEXP (src, 1));
1380 cfa.offset += offset;
1381 cfa.reg = REGNO (dest);
1382 /* Or used to save regs to the stack. */
1383 cfa_temp.reg = cfa.reg;
1384 cfa_temp.offset = cfa.offset;
1386 /* Rule 5 */
1387 else if (GET_CODE (XEXP (src, 0)) == REG
1388 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1389 && XEXP (src, 1) == stack_pointer_rtx)
1391 /* Setting a scratch register that we will use instead
1392 of SP for saving registers to the stack. */
1393 if (cfa.reg != STACK_POINTER_REGNUM)
1394 abort ();
1395 cfa_store.reg = REGNO (dest);
1396 cfa_store.offset = cfa.offset - cfa_temp.offset;
1398 /* Rule 9 */
1399 else if (GET_CODE (src) == LO_SUM
1400 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1402 cfa_temp.reg = REGNO (dest);
1403 cfa_temp.offset = INTVAL (XEXP (src, 1));
1405 else
1406 abort ();
1408 break;
1410 /* Rule 6 */
1411 case CONST_INT:
1412 cfa_temp.reg = REGNO (dest);
1413 cfa_temp.offset = INTVAL (src);
1414 break;
1416 /* Rule 7 */
1417 case IOR:
1418 if (GET_CODE (XEXP (src, 0)) != REG
1419 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1420 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1421 abort ();
1422 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1423 cfa_temp.reg = REGNO (dest);
1424 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1425 break;
1427 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1428 which will fill in all of the bits. */
1429 /* Rule 8 */
1430 case HIGH:
1431 break;
1433 default:
1434 abort ();
1436 def_cfa_1 (label, &cfa);
1437 break;
1439 case MEM:
1440 if (GET_CODE (src) != REG)
1441 abort ();
1443 /* Saving a register to the stack. Make sure dest is relative to the
1444 CFA register. */
1445 switch (GET_CODE (XEXP (dest, 0)))
1447 /* Rule 10 */
1448 /* With a push. */
1449 case PRE_MODIFY:
1450 /* We can't handle variable size modifications. */
1451 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1452 abort();
1453 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1455 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1456 || cfa_store.reg != STACK_POINTER_REGNUM)
1457 abort ();
1458 cfa_store.offset += offset;
1459 if (cfa.reg == STACK_POINTER_REGNUM)
1460 cfa.offset = cfa_store.offset;
1462 offset = -cfa_store.offset;
1463 break;
1464 /* Rule 11 */
1465 case PRE_INC:
1466 case PRE_DEC:
1467 offset = GET_MODE_SIZE (GET_MODE (dest));
1468 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1469 offset = -offset;
1471 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1472 || cfa_store.reg != STACK_POINTER_REGNUM)
1473 abort ();
1474 cfa_store.offset += offset;
1475 if (cfa.reg == STACK_POINTER_REGNUM)
1476 cfa.offset = cfa_store.offset;
1478 offset = -cfa_store.offset;
1479 break;
1481 /* Rule 12 */
1482 /* With an offset. */
1483 case PLUS:
1484 case MINUS:
1485 case LO_SUM:
1486 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1487 abort ();
1488 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1489 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1490 offset = -offset;
1492 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1493 offset -= cfa_store.offset;
1494 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1495 offset -= cfa_temp.offset;
1496 else
1497 abort ();
1498 break;
1500 /* Rule 13 */
1501 /* Without an offset. */
1502 case REG:
1503 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1504 offset = -cfa_store.offset;
1505 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1506 offset = -cfa_temp.offset;
1507 else
1508 abort ();
1509 break;
1511 /* Rule 14 */
1512 case POST_INC:
1513 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1514 abort ();
1515 offset = -cfa_temp.offset;
1516 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1517 break;
1519 default:
1520 abort ();
1523 if (REGNO (src) != STACK_POINTER_REGNUM
1524 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1525 && (unsigned) REGNO (src) == cfa.reg)
1527 /* We're storing the current CFA reg into the stack. */
1529 if (cfa.offset == 0)
1531 /* If the source register is exactly the CFA, assume
1532 we're saving SP like any other register; this happens
1533 on the ARM. */
1535 def_cfa_1 (label, &cfa);
1536 queue_reg_save (label, stack_pointer_rtx, offset);
1537 break;
1539 else
1541 /* Otherwise, we'll need to look in the stack to
1542 calculate the CFA. */
1544 rtx x = XEXP (dest, 0);
1545 if (GET_CODE (x) != REG)
1546 x = XEXP (x, 0);
1547 if (GET_CODE (x) != REG)
1548 abort ();
1549 cfa.reg = (unsigned) REGNO (x);
1550 cfa.base_offset = offset;
1551 cfa.indirect = 1;
1552 def_cfa_1 (label, &cfa);
1553 break;
1557 def_cfa_1 (label, &cfa);
1558 queue_reg_save (label, src, offset);
1559 break;
1561 default:
1562 abort ();
1566 /* Record call frame debugging information for INSN, which either
1567 sets SP or FP (adjusting how we calculate the frame address) or saves a
1568 register to the stack. If INSN is NULL_RTX, initialize our state. */
1570 void
1571 dwarf2out_frame_debug (insn)
1572 rtx insn;
1574 const char *label;
1575 rtx src;
1577 if (insn == NULL_RTX)
1579 /* Flush any queued register saves. */
1580 flush_queued_reg_saves ();
1582 /* Set up state for generating call frame debug info. */
1583 lookup_cfa (&cfa);
1584 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1585 abort ();
1586 cfa.reg = STACK_POINTER_REGNUM;
1587 cfa_store = cfa;
1588 cfa_temp.reg = -1;
1589 cfa_temp.offset = 0;
1590 return;
1593 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1594 flush_queued_reg_saves ();
1596 if (! RTX_FRAME_RELATED_P (insn))
1598 if (!ACCUMULATE_OUTGOING_ARGS)
1599 dwarf2out_stack_adjust (insn);
1600 return;
1603 label = dwarf2out_cfi_label ();
1605 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1606 if (src)
1607 insn = XEXP (src, 0);
1608 else
1609 insn = PATTERN (insn);
1611 dwarf2out_frame_debug_expr (insn, label);
1614 /* Output a Call Frame Information opcode and its operand(s). */
1616 static void
1617 output_cfi (cfi, fde, for_eh)
1618 register dw_cfi_ref cfi;
1619 register dw_fde_ref fde;
1620 int for_eh;
1622 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1624 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1625 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1626 "DW_CFA_advance_loc 0x%lx",
1627 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1629 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1631 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1632 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1633 "DW_CFA_offset, column 0x%lx",
1634 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1635 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1637 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1639 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1640 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1641 "DW_CFA_restore, column 0x%lx",
1642 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1644 else
1646 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1647 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1649 switch (cfi->dw_cfi_opc)
1651 case DW_CFA_set_loc:
1652 if (for_eh)
1653 dw2_asm_output_encoded_addr_rtx (
1654 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1655 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1656 NULL);
1657 else
1658 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1659 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1660 break;
1661 case DW_CFA_advance_loc1:
1662 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1663 fde->dw_fde_current_label, NULL);
1664 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1665 break;
1666 case DW_CFA_advance_loc2:
1667 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1668 fde->dw_fde_current_label, NULL);
1669 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1670 break;
1671 case DW_CFA_advance_loc4:
1672 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1673 fde->dw_fde_current_label, NULL);
1674 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1675 break;
1676 case DW_CFA_MIPS_advance_loc8:
1677 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1678 fde->dw_fde_current_label, NULL);
1679 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1680 break;
1681 case DW_CFA_offset_extended:
1682 case DW_CFA_GNU_negative_offset_extended:
1683 case DW_CFA_def_cfa:
1684 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1685 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1686 break;
1687 case DW_CFA_restore_extended:
1688 case DW_CFA_undefined:
1689 case DW_CFA_same_value:
1690 case DW_CFA_def_cfa_register:
1691 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1692 break;
1693 case DW_CFA_register:
1694 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1695 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1696 break;
1697 case DW_CFA_def_cfa_offset:
1698 case DW_CFA_GNU_args_size:
1699 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1700 break;
1701 case DW_CFA_GNU_window_save:
1702 break;
1703 case DW_CFA_def_cfa_expression:
1704 output_cfa_loc (cfi);
1705 break;
1706 default:
1707 break;
1712 /* Output the call frame information used to used to record information
1713 that relates to calculating the frame pointer, and records the
1714 location of saved registers. */
1716 static void
1717 output_call_frame_info (for_eh)
1718 int for_eh;
1720 register unsigned long i;
1721 register dw_fde_ref fde;
1722 register dw_cfi_ref cfi;
1723 char l1[20], l2[20];
1724 int any_lsda_needed = 0;
1725 char augmentation[6];
1726 int augmentation_size;
1727 int fde_encoding = DW_EH_PE_absptr;
1728 int per_encoding = DW_EH_PE_absptr;
1729 int lsda_encoding = DW_EH_PE_absptr;
1731 /* If we don't have any functions we'll want to unwind out of, don't
1732 emit any EH unwind information. */
1733 if (for_eh)
1735 int any_eh_needed = 0;
1736 for (i = 0; i < fde_table_in_use; ++i)
1737 if (fde_table[i].uses_eh_lsda)
1738 any_eh_needed = any_lsda_needed = 1;
1739 else if (! fde_table[i].nothrow)
1740 any_eh_needed = 1;
1742 if (! any_eh_needed)
1743 return;
1746 /* We're going to be generating comments, so turn on app. */
1747 if (flag_debug_asm)
1748 app_enable ();
1750 if (for_eh)
1752 #ifdef EH_FRAME_SECTION
1753 EH_FRAME_SECTION ();
1754 #else
1755 tree label = get_file_function_name ('F');
1757 force_data_section ();
1758 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1759 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1760 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1761 #endif
1762 assemble_label ("__FRAME_BEGIN__");
1764 else
1765 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1767 /* Output the CIE. */
1768 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1769 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1770 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1771 "Length of Common Information Entry");
1772 ASM_OUTPUT_LABEL (asm_out_file, l1);
1774 /* Now that the CIE pointer is PC-relative for EH,
1775 use 0 to identify the CIE. */
1776 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1777 (for_eh ? 0 : DW_CIE_ID),
1778 "CIE Identifier Tag");
1780 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1782 augmentation[0] = 0;
1783 augmentation_size = 0;
1784 if (for_eh)
1786 char *p;
1788 /* Augmentation:
1789 z Indicates that a uleb128 is present to size the
1790 augmentation section.
1791 L Indicates the encoding (and thus presence) of
1792 an LSDA pointer in the FDE augmentation.
1793 R Indicates a non-default pointer encoding for
1794 FDE code pointers.
1795 P Indicates the presence of an encoding + language
1796 personality routine in the CIE augmentation. */
1798 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1799 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1800 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1802 p = augmentation + 1;
1803 if (eh_personality_libfunc)
1805 *p++ = 'P';
1806 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1808 if (any_lsda_needed)
1810 *p++ = 'L';
1811 augmentation_size += 1;
1813 if (fde_encoding != DW_EH_PE_absptr)
1815 *p++ = 'R';
1816 augmentation_size += 1;
1818 if (p > augmentation + 1)
1820 augmentation[0] = 'z';
1821 *p = '\0';
1824 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1825 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1827 int offset = ( 4 /* Length */
1828 + 4 /* CIE Id */
1829 + 1 /* CIE version */
1830 + strlen (augmentation) + 1 /* Augmentation */
1831 + size_of_uleb128 (1) /* Code alignment */
1832 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1833 + 1 /* RA column */
1834 + 1 /* Augmentation size */
1835 + 1 /* Personality encoding */ );
1836 int pad = -offset & (PTR_SIZE - 1);
1838 augmentation_size += pad;
1840 /* Augmentations should be small, so there's scarce need to
1841 iterate for a solution. Die if we exceed one uleb128 byte. */
1842 if (size_of_uleb128 (augmentation_size) != 1)
1843 abort ();
1846 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1848 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1850 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1851 "CIE Data Alignment Factor");
1853 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1855 if (augmentation[0])
1857 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1858 if (eh_personality_libfunc)
1860 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1861 eh_data_format_name (per_encoding));
1862 dw2_asm_output_encoded_addr_rtx (per_encoding,
1863 eh_personality_libfunc, NULL);
1865 if (any_lsda_needed)
1866 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1867 eh_data_format_name (lsda_encoding));
1868 if (fde_encoding != DW_EH_PE_absptr)
1869 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1870 eh_data_format_name (fde_encoding));
1873 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1874 output_cfi (cfi, NULL, for_eh);
1876 /* Pad the CIE out to an address sized boundary. */
1877 ASM_OUTPUT_ALIGN (asm_out_file,
1878 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1879 ASM_OUTPUT_LABEL (asm_out_file, l2);
1881 /* Loop through all of the FDE's. */
1882 for (i = 0; i < fde_table_in_use; ++i)
1884 fde = &fde_table[i];
1886 /* Don't emit EH unwind info for leaf functions that don't need it. */
1887 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1888 continue;
1890 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1891 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1892 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1893 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1894 "FDE Length");
1895 ASM_OUTPUT_LABEL (asm_out_file, l1);
1897 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1898 emits a target dependent sized offset when for_eh is not true.
1899 This inconsistency may confuse gdb. The only case where we need a
1900 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1901 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1902 though in order to be compatible with the dwarf_fde struct in frame.c.
1903 If the for_eh case is changed, then the struct in frame.c has
1904 to be adjusted appropriately. */
1905 if (for_eh)
1906 dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset");
1907 else
1908 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
1909 stripattributes (FRAME_SECTION),
1910 "FDE CIE offset");
1912 if (for_eh)
1914 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1915 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1916 "FDE initial location");
1917 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1918 fde->dw_fde_end, fde->dw_fde_begin,
1919 "FDE address range");
1921 else
1923 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1924 "FDE initial location");
1925 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1926 fde->dw_fde_end, fde->dw_fde_begin,
1927 "FDE address range");
1930 if (augmentation[0])
1932 if (any_lsda_needed)
1934 int size = size_of_encoded_value (lsda_encoding);
1936 if (lsda_encoding == DW_EH_PE_aligned)
1938 int offset = ( 4 /* Length */
1939 + 4 /* CIE offset */
1940 + 2 * size_of_encoded_value (fde_encoding)
1941 + 1 /* Augmentation size */ );
1942 int pad = -offset & (PTR_SIZE - 1);
1944 size += pad;
1945 if (size_of_uleb128 (size) != 1)
1946 abort ();
1949 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1951 if (fde->uses_eh_lsda)
1953 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
1954 fde->funcdef_number);
1955 dw2_asm_output_encoded_addr_rtx (
1956 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
1957 "Language Specific Data Area");
1959 else
1961 if (lsda_encoding == DW_EH_PE_aligned)
1962 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1963 dw2_asm_output_data (size_of_encoded_value (lsda_encoding),
1964 0, "Language Specific Data Area (none)");
1967 else
1968 dw2_asm_output_data_uleb128 (0, "Augmentation size");
1971 /* Loop through the Call Frame Instructions associated with
1972 this FDE. */
1973 fde->dw_fde_current_label = fde->dw_fde_begin;
1974 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1975 output_cfi (cfi, fde, for_eh);
1977 /* Pad the FDE out to an address sized boundary. */
1978 ASM_OUTPUT_ALIGN (asm_out_file,
1979 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1980 ASM_OUTPUT_LABEL (asm_out_file, l2);
1983 #ifndef EH_FRAME_SECTION
1984 if (for_eh)
1985 dw2_asm_output_data (4, 0, "End of Table");
1986 #endif
1987 #ifdef MIPS_DEBUGGING_INFO
1988 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1989 get a value of 0. Putting .align 0 after the label fixes it. */
1990 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1991 #endif
1993 /* Turn off app to make assembly quicker. */
1994 if (flag_debug_asm)
1995 app_disable ();
1998 /* Output a marker (i.e. a label) for the beginning of a function, before
1999 the prologue. */
2001 void
2002 dwarf2out_begin_prologue ()
2004 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2005 register dw_fde_ref fde;
2007 current_function_func_begin_label = 0;
2009 #ifdef IA64_UNWIND_INFO
2010 /* ??? current_function_func_begin_label is also used by except.c
2011 for call-site information. We must emit this label if it might
2012 be used. */
2013 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2014 && ! dwarf2out_do_frame ())
2015 return;
2016 #else
2017 if (! dwarf2out_do_frame ())
2018 return;
2019 #endif
2021 ++current_funcdef_number;
2023 function_section (current_function_decl);
2024 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2025 current_funcdef_number);
2026 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2027 current_funcdef_number);
2028 current_function_func_begin_label = get_identifier (label);
2030 #ifdef IA64_UNWIND_INFO
2031 /* We can elide the fde allocation if we're not emitting debug info. */
2032 if (! dwarf2out_do_frame ())
2033 return;
2034 #endif
2036 /* Expand the fde table if necessary. */
2037 if (fde_table_in_use == fde_table_allocated)
2039 fde_table_allocated += FDE_TABLE_INCREMENT;
2040 fde_table
2041 = (dw_fde_ref) xrealloc (fde_table,
2042 fde_table_allocated * sizeof (dw_fde_node));
2045 /* Record the FDE associated with this function. */
2046 current_funcdef_fde = fde_table_in_use;
2048 /* Add the new FDE at the end of the fde_table. */
2049 fde = &fde_table[fde_table_in_use++];
2050 fde->dw_fde_begin = xstrdup (label);
2051 fde->dw_fde_current_label = NULL;
2052 fde->dw_fde_end = NULL;
2053 fde->dw_fde_cfi = NULL;
2054 fde->funcdef_number = current_funcdef_number;
2055 fde->nothrow = current_function_nothrow;
2056 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2058 args_size = old_args_size = 0;
2061 /* Output a marker (i.e. a label) for the absolute end of the generated code
2062 for a function definition. This gets called *after* the epilogue code has
2063 been generated. */
2065 void
2066 dwarf2out_end_epilogue ()
2068 dw_fde_ref fde;
2069 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2071 /* Output a label to mark the endpoint of the code generated for this
2072 function. */
2073 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2074 ASM_OUTPUT_LABEL (asm_out_file, label);
2075 fde = &fde_table[fde_table_in_use - 1];
2076 fde->dw_fde_end = xstrdup (label);
2079 void
2080 dwarf2out_frame_init ()
2082 /* Allocate the initial hunk of the fde_table. */
2083 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2084 fde_table_allocated = FDE_TABLE_INCREMENT;
2085 fde_table_in_use = 0;
2087 /* Generate the CFA instructions common to all FDE's. Do it now for the
2088 sake of lookup_cfa. */
2090 #ifdef DWARF2_UNWIND_INFO
2091 /* On entry, the Canonical Frame Address is at SP. */
2092 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2093 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2094 #endif
2097 void
2098 dwarf2out_frame_finish ()
2100 /* Output call frame information. */
2101 #ifdef MIPS_DEBUGGING_INFO
2102 if (write_symbols == DWARF2_DEBUG)
2103 output_call_frame_info (0);
2104 if (flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
2105 output_call_frame_info (1);
2106 #else
2107 if (write_symbols == DWARF2_DEBUG
2108 || flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
2109 output_call_frame_info (1);
2110 #endif
2113 /* And now, the subset of the debugging information support code necessary
2114 for emitting location expressions. */
2116 typedef struct dw_val_struct *dw_val_ref;
2117 typedef struct die_struct *dw_die_ref;
2118 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2120 /* Each DIE may have a series of attribute/value pairs. Values
2121 can take on several forms. The forms that are used in this
2122 implementation are listed below. */
2124 typedef enum
2126 dw_val_class_addr,
2127 dw_val_class_loc,
2128 dw_val_class_const,
2129 dw_val_class_unsigned_const,
2130 dw_val_class_long_long,
2131 dw_val_class_float,
2132 dw_val_class_flag,
2133 dw_val_class_die_ref,
2134 dw_val_class_fde_ref,
2135 dw_val_class_lbl_id,
2136 dw_val_class_lbl_offset,
2137 dw_val_class_str
2139 dw_val_class;
2141 /* Describe a double word constant value. */
2142 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2144 typedef struct dw_long_long_struct
2146 unsigned long hi;
2147 unsigned long low;
2149 dw_long_long_const;
2151 /* Describe a floating point constant value. */
2153 typedef struct dw_fp_struct
2155 long *array;
2156 unsigned length;
2158 dw_float_const;
2160 /* The dw_val_node describes an attribute's value, as it is
2161 represented internally. */
2163 typedef struct dw_val_struct
2165 dw_val_class val_class;
2166 union
2168 rtx val_addr;
2169 dw_loc_descr_ref val_loc;
2170 long int val_int;
2171 long unsigned val_unsigned;
2172 dw_long_long_const val_long_long;
2173 dw_float_const val_float;
2174 struct {
2175 dw_die_ref die;
2176 int external;
2177 } val_die_ref;
2178 unsigned val_fde_index;
2179 char *val_str;
2180 char *val_lbl_id;
2181 unsigned char val_flag;
2185 dw_val_node;
2187 /* Locations in memory are described using a sequence of stack machine
2188 operations. */
2190 typedef struct dw_loc_descr_struct
2192 dw_loc_descr_ref dw_loc_next;
2193 enum dwarf_location_atom dw_loc_opc;
2194 dw_val_node dw_loc_oprnd1;
2195 dw_val_node dw_loc_oprnd2;
2196 int dw_loc_addr;
2198 dw_loc_descr_node;
2200 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2201 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2202 unsigned long,
2203 unsigned long));
2204 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2205 dw_loc_descr_ref));
2206 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2207 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2208 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2209 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2211 /* Convert a DWARF stack opcode into its string name. */
2213 static const char *
2214 dwarf_stack_op_name (op)
2215 register unsigned op;
2217 switch (op)
2219 case DW_OP_addr:
2220 return "DW_OP_addr";
2221 case DW_OP_deref:
2222 return "DW_OP_deref";
2223 case DW_OP_const1u:
2224 return "DW_OP_const1u";
2225 case DW_OP_const1s:
2226 return "DW_OP_const1s";
2227 case DW_OP_const2u:
2228 return "DW_OP_const2u";
2229 case DW_OP_const2s:
2230 return "DW_OP_const2s";
2231 case DW_OP_const4u:
2232 return "DW_OP_const4u";
2233 case DW_OP_const4s:
2234 return "DW_OP_const4s";
2235 case DW_OP_const8u:
2236 return "DW_OP_const8u";
2237 case DW_OP_const8s:
2238 return "DW_OP_const8s";
2239 case DW_OP_constu:
2240 return "DW_OP_constu";
2241 case DW_OP_consts:
2242 return "DW_OP_consts";
2243 case DW_OP_dup:
2244 return "DW_OP_dup";
2245 case DW_OP_drop:
2246 return "DW_OP_drop";
2247 case DW_OP_over:
2248 return "DW_OP_over";
2249 case DW_OP_pick:
2250 return "DW_OP_pick";
2251 case DW_OP_swap:
2252 return "DW_OP_swap";
2253 case DW_OP_rot:
2254 return "DW_OP_rot";
2255 case DW_OP_xderef:
2256 return "DW_OP_xderef";
2257 case DW_OP_abs:
2258 return "DW_OP_abs";
2259 case DW_OP_and:
2260 return "DW_OP_and";
2261 case DW_OP_div:
2262 return "DW_OP_div";
2263 case DW_OP_minus:
2264 return "DW_OP_minus";
2265 case DW_OP_mod:
2266 return "DW_OP_mod";
2267 case DW_OP_mul:
2268 return "DW_OP_mul";
2269 case DW_OP_neg:
2270 return "DW_OP_neg";
2271 case DW_OP_not:
2272 return "DW_OP_not";
2273 case DW_OP_or:
2274 return "DW_OP_or";
2275 case DW_OP_plus:
2276 return "DW_OP_plus";
2277 case DW_OP_plus_uconst:
2278 return "DW_OP_plus_uconst";
2279 case DW_OP_shl:
2280 return "DW_OP_shl";
2281 case DW_OP_shr:
2282 return "DW_OP_shr";
2283 case DW_OP_shra:
2284 return "DW_OP_shra";
2285 case DW_OP_xor:
2286 return "DW_OP_xor";
2287 case DW_OP_bra:
2288 return "DW_OP_bra";
2289 case DW_OP_eq:
2290 return "DW_OP_eq";
2291 case DW_OP_ge:
2292 return "DW_OP_ge";
2293 case DW_OP_gt:
2294 return "DW_OP_gt";
2295 case DW_OP_le:
2296 return "DW_OP_le";
2297 case DW_OP_lt:
2298 return "DW_OP_lt";
2299 case DW_OP_ne:
2300 return "DW_OP_ne";
2301 case DW_OP_skip:
2302 return "DW_OP_skip";
2303 case DW_OP_lit0:
2304 return "DW_OP_lit0";
2305 case DW_OP_lit1:
2306 return "DW_OP_lit1";
2307 case DW_OP_lit2:
2308 return "DW_OP_lit2";
2309 case DW_OP_lit3:
2310 return "DW_OP_lit3";
2311 case DW_OP_lit4:
2312 return "DW_OP_lit4";
2313 case DW_OP_lit5:
2314 return "DW_OP_lit5";
2315 case DW_OP_lit6:
2316 return "DW_OP_lit6";
2317 case DW_OP_lit7:
2318 return "DW_OP_lit7";
2319 case DW_OP_lit8:
2320 return "DW_OP_lit8";
2321 case DW_OP_lit9:
2322 return "DW_OP_lit9";
2323 case DW_OP_lit10:
2324 return "DW_OP_lit10";
2325 case DW_OP_lit11:
2326 return "DW_OP_lit11";
2327 case DW_OP_lit12:
2328 return "DW_OP_lit12";
2329 case DW_OP_lit13:
2330 return "DW_OP_lit13";
2331 case DW_OP_lit14:
2332 return "DW_OP_lit14";
2333 case DW_OP_lit15:
2334 return "DW_OP_lit15";
2335 case DW_OP_lit16:
2336 return "DW_OP_lit16";
2337 case DW_OP_lit17:
2338 return "DW_OP_lit17";
2339 case DW_OP_lit18:
2340 return "DW_OP_lit18";
2341 case DW_OP_lit19:
2342 return "DW_OP_lit19";
2343 case DW_OP_lit20:
2344 return "DW_OP_lit20";
2345 case DW_OP_lit21:
2346 return "DW_OP_lit21";
2347 case DW_OP_lit22:
2348 return "DW_OP_lit22";
2349 case DW_OP_lit23:
2350 return "DW_OP_lit23";
2351 case DW_OP_lit24:
2352 return "DW_OP_lit24";
2353 case DW_OP_lit25:
2354 return "DW_OP_lit25";
2355 case DW_OP_lit26:
2356 return "DW_OP_lit26";
2357 case DW_OP_lit27:
2358 return "DW_OP_lit27";
2359 case DW_OP_lit28:
2360 return "DW_OP_lit28";
2361 case DW_OP_lit29:
2362 return "DW_OP_lit29";
2363 case DW_OP_lit30:
2364 return "DW_OP_lit30";
2365 case DW_OP_lit31:
2366 return "DW_OP_lit31";
2367 case DW_OP_reg0:
2368 return "DW_OP_reg0";
2369 case DW_OP_reg1:
2370 return "DW_OP_reg1";
2371 case DW_OP_reg2:
2372 return "DW_OP_reg2";
2373 case DW_OP_reg3:
2374 return "DW_OP_reg3";
2375 case DW_OP_reg4:
2376 return "DW_OP_reg4";
2377 case DW_OP_reg5:
2378 return "DW_OP_reg5";
2379 case DW_OP_reg6:
2380 return "DW_OP_reg6";
2381 case DW_OP_reg7:
2382 return "DW_OP_reg7";
2383 case DW_OP_reg8:
2384 return "DW_OP_reg8";
2385 case DW_OP_reg9:
2386 return "DW_OP_reg9";
2387 case DW_OP_reg10:
2388 return "DW_OP_reg10";
2389 case DW_OP_reg11:
2390 return "DW_OP_reg11";
2391 case DW_OP_reg12:
2392 return "DW_OP_reg12";
2393 case DW_OP_reg13:
2394 return "DW_OP_reg13";
2395 case DW_OP_reg14:
2396 return "DW_OP_reg14";
2397 case DW_OP_reg15:
2398 return "DW_OP_reg15";
2399 case DW_OP_reg16:
2400 return "DW_OP_reg16";
2401 case DW_OP_reg17:
2402 return "DW_OP_reg17";
2403 case DW_OP_reg18:
2404 return "DW_OP_reg18";
2405 case DW_OP_reg19:
2406 return "DW_OP_reg19";
2407 case DW_OP_reg20:
2408 return "DW_OP_reg20";
2409 case DW_OP_reg21:
2410 return "DW_OP_reg21";
2411 case DW_OP_reg22:
2412 return "DW_OP_reg22";
2413 case DW_OP_reg23:
2414 return "DW_OP_reg23";
2415 case DW_OP_reg24:
2416 return "DW_OP_reg24";
2417 case DW_OP_reg25:
2418 return "DW_OP_reg25";
2419 case DW_OP_reg26:
2420 return "DW_OP_reg26";
2421 case DW_OP_reg27:
2422 return "DW_OP_reg27";
2423 case DW_OP_reg28:
2424 return "DW_OP_reg28";
2425 case DW_OP_reg29:
2426 return "DW_OP_reg29";
2427 case DW_OP_reg30:
2428 return "DW_OP_reg30";
2429 case DW_OP_reg31:
2430 return "DW_OP_reg31";
2431 case DW_OP_breg0:
2432 return "DW_OP_breg0";
2433 case DW_OP_breg1:
2434 return "DW_OP_breg1";
2435 case DW_OP_breg2:
2436 return "DW_OP_breg2";
2437 case DW_OP_breg3:
2438 return "DW_OP_breg3";
2439 case DW_OP_breg4:
2440 return "DW_OP_breg4";
2441 case DW_OP_breg5:
2442 return "DW_OP_breg5";
2443 case DW_OP_breg6:
2444 return "DW_OP_breg6";
2445 case DW_OP_breg7:
2446 return "DW_OP_breg7";
2447 case DW_OP_breg8:
2448 return "DW_OP_breg8";
2449 case DW_OP_breg9:
2450 return "DW_OP_breg9";
2451 case DW_OP_breg10:
2452 return "DW_OP_breg10";
2453 case DW_OP_breg11:
2454 return "DW_OP_breg11";
2455 case DW_OP_breg12:
2456 return "DW_OP_breg12";
2457 case DW_OP_breg13:
2458 return "DW_OP_breg13";
2459 case DW_OP_breg14:
2460 return "DW_OP_breg14";
2461 case DW_OP_breg15:
2462 return "DW_OP_breg15";
2463 case DW_OP_breg16:
2464 return "DW_OP_breg16";
2465 case DW_OP_breg17:
2466 return "DW_OP_breg17";
2467 case DW_OP_breg18:
2468 return "DW_OP_breg18";
2469 case DW_OP_breg19:
2470 return "DW_OP_breg19";
2471 case DW_OP_breg20:
2472 return "DW_OP_breg20";
2473 case DW_OP_breg21:
2474 return "DW_OP_breg21";
2475 case DW_OP_breg22:
2476 return "DW_OP_breg22";
2477 case DW_OP_breg23:
2478 return "DW_OP_breg23";
2479 case DW_OP_breg24:
2480 return "DW_OP_breg24";
2481 case DW_OP_breg25:
2482 return "DW_OP_breg25";
2483 case DW_OP_breg26:
2484 return "DW_OP_breg26";
2485 case DW_OP_breg27:
2486 return "DW_OP_breg27";
2487 case DW_OP_breg28:
2488 return "DW_OP_breg28";
2489 case DW_OP_breg29:
2490 return "DW_OP_breg29";
2491 case DW_OP_breg30:
2492 return "DW_OP_breg30";
2493 case DW_OP_breg31:
2494 return "DW_OP_breg31";
2495 case DW_OP_regx:
2496 return "DW_OP_regx";
2497 case DW_OP_fbreg:
2498 return "DW_OP_fbreg";
2499 case DW_OP_bregx:
2500 return "DW_OP_bregx";
2501 case DW_OP_piece:
2502 return "DW_OP_piece";
2503 case DW_OP_deref_size:
2504 return "DW_OP_deref_size";
2505 case DW_OP_xderef_size:
2506 return "DW_OP_xderef_size";
2507 case DW_OP_nop:
2508 return "DW_OP_nop";
2509 default:
2510 return "OP_<unknown>";
2514 /* Return a pointer to a newly allocated location description. Location
2515 descriptions are simple expression terms that can be strung
2516 together to form more complicated location (address) descriptions. */
2518 static inline dw_loc_descr_ref
2519 new_loc_descr (op, oprnd1, oprnd2)
2520 register enum dwarf_location_atom op;
2521 register unsigned long oprnd1;
2522 register unsigned long oprnd2;
2524 /* Use xcalloc here so we clear out all of the long_long constant in
2525 the union. */
2526 register dw_loc_descr_ref descr
2527 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2529 descr->dw_loc_opc = op;
2530 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2531 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2532 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2533 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2535 return descr;
2538 /* Add a location description term to a location description expression. */
2540 static inline void
2541 add_loc_descr (list_head, descr)
2542 register dw_loc_descr_ref *list_head;
2543 register dw_loc_descr_ref descr;
2545 register dw_loc_descr_ref *d;
2547 /* Find the end of the chain. */
2548 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2551 *d = descr;
2554 /* Return the size of a location descriptor. */
2556 static unsigned long
2557 size_of_loc_descr (loc)
2558 register dw_loc_descr_ref loc;
2560 register unsigned long size = 1;
2562 switch (loc->dw_loc_opc)
2564 case DW_OP_addr:
2565 size += DWARF2_ADDR_SIZE;
2566 break;
2567 case DW_OP_const1u:
2568 case DW_OP_const1s:
2569 size += 1;
2570 break;
2571 case DW_OP_const2u:
2572 case DW_OP_const2s:
2573 size += 2;
2574 break;
2575 case DW_OP_const4u:
2576 case DW_OP_const4s:
2577 size += 4;
2578 break;
2579 case DW_OP_const8u:
2580 case DW_OP_const8s:
2581 size += 8;
2582 break;
2583 case DW_OP_constu:
2584 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2585 break;
2586 case DW_OP_consts:
2587 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2588 break;
2589 case DW_OP_pick:
2590 size += 1;
2591 break;
2592 case DW_OP_plus_uconst:
2593 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2594 break;
2595 case DW_OP_skip:
2596 case DW_OP_bra:
2597 size += 2;
2598 break;
2599 case DW_OP_breg0:
2600 case DW_OP_breg1:
2601 case DW_OP_breg2:
2602 case DW_OP_breg3:
2603 case DW_OP_breg4:
2604 case DW_OP_breg5:
2605 case DW_OP_breg6:
2606 case DW_OP_breg7:
2607 case DW_OP_breg8:
2608 case DW_OP_breg9:
2609 case DW_OP_breg10:
2610 case DW_OP_breg11:
2611 case DW_OP_breg12:
2612 case DW_OP_breg13:
2613 case DW_OP_breg14:
2614 case DW_OP_breg15:
2615 case DW_OP_breg16:
2616 case DW_OP_breg17:
2617 case DW_OP_breg18:
2618 case DW_OP_breg19:
2619 case DW_OP_breg20:
2620 case DW_OP_breg21:
2621 case DW_OP_breg22:
2622 case DW_OP_breg23:
2623 case DW_OP_breg24:
2624 case DW_OP_breg25:
2625 case DW_OP_breg26:
2626 case DW_OP_breg27:
2627 case DW_OP_breg28:
2628 case DW_OP_breg29:
2629 case DW_OP_breg30:
2630 case DW_OP_breg31:
2631 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2632 break;
2633 case DW_OP_regx:
2634 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2635 break;
2636 case DW_OP_fbreg:
2637 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2638 break;
2639 case DW_OP_bregx:
2640 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2641 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2642 break;
2643 case DW_OP_piece:
2644 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2645 break;
2646 case DW_OP_deref_size:
2647 case DW_OP_xderef_size:
2648 size += 1;
2649 break;
2650 default:
2651 break;
2654 return size;
2657 /* Return the size of a series of location descriptors. */
2659 static unsigned long
2660 size_of_locs (loc)
2661 register dw_loc_descr_ref loc;
2663 register unsigned long size = 0;
2665 for (; loc != NULL; loc = loc->dw_loc_next)
2667 loc->dw_loc_addr = size;
2668 size += size_of_loc_descr (loc);
2671 return size;
2674 /* Output location description stack opcode's operands (if any). */
2676 static void
2677 output_loc_operands (loc)
2678 register dw_loc_descr_ref loc;
2680 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2681 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2683 switch (loc->dw_loc_opc)
2685 #ifdef DWARF2_DEBUGGING_INFO
2686 case DW_OP_addr:
2687 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2688 break;
2689 case DW_OP_const2u:
2690 case DW_OP_const2s:
2691 dw2_asm_output_data (2, val1->v.val_int, NULL);
2692 break;
2693 case DW_OP_const4u:
2694 case DW_OP_const4s:
2695 dw2_asm_output_data (4, val1->v.val_int, NULL);
2696 break;
2697 case DW_OP_const8u:
2698 case DW_OP_const8s:
2699 if (HOST_BITS_PER_LONG < 64)
2700 abort ();
2701 dw2_asm_output_data (8, val1->v.val_int, NULL);
2702 break;
2703 case DW_OP_skip:
2704 case DW_OP_bra:
2706 int offset;
2708 if (val1->val_class == dw_val_class_loc)
2709 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2710 else
2711 abort ();
2713 dw2_asm_output_data (2, offset, NULL);
2715 break;
2716 #else
2717 case DW_OP_addr:
2718 case DW_OP_const2u:
2719 case DW_OP_const2s:
2720 case DW_OP_const4u:
2721 case DW_OP_const4s:
2722 case DW_OP_const8u:
2723 case DW_OP_const8s:
2724 case DW_OP_skip:
2725 case DW_OP_bra:
2726 /* We currently don't make any attempt to make sure these are
2727 aligned properly like we do for the main unwind info, so
2728 don't support emitting things larger than a byte if we're
2729 only doing unwinding. */
2730 abort ();
2731 #endif
2732 case DW_OP_const1u:
2733 case DW_OP_const1s:
2734 dw2_asm_output_data (1, val1->v.val_int, NULL);
2735 break;
2736 case DW_OP_constu:
2737 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2738 break;
2739 case DW_OP_consts:
2740 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2741 break;
2742 case DW_OP_pick:
2743 dw2_asm_output_data (1, val1->v.val_int, NULL);
2744 break;
2745 case DW_OP_plus_uconst:
2746 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2747 break;
2748 case DW_OP_breg0:
2749 case DW_OP_breg1:
2750 case DW_OP_breg2:
2751 case DW_OP_breg3:
2752 case DW_OP_breg4:
2753 case DW_OP_breg5:
2754 case DW_OP_breg6:
2755 case DW_OP_breg7:
2756 case DW_OP_breg8:
2757 case DW_OP_breg9:
2758 case DW_OP_breg10:
2759 case DW_OP_breg11:
2760 case DW_OP_breg12:
2761 case DW_OP_breg13:
2762 case DW_OP_breg14:
2763 case DW_OP_breg15:
2764 case DW_OP_breg16:
2765 case DW_OP_breg17:
2766 case DW_OP_breg18:
2767 case DW_OP_breg19:
2768 case DW_OP_breg20:
2769 case DW_OP_breg21:
2770 case DW_OP_breg22:
2771 case DW_OP_breg23:
2772 case DW_OP_breg24:
2773 case DW_OP_breg25:
2774 case DW_OP_breg26:
2775 case DW_OP_breg27:
2776 case DW_OP_breg28:
2777 case DW_OP_breg29:
2778 case DW_OP_breg30:
2779 case DW_OP_breg31:
2780 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2781 break;
2782 case DW_OP_regx:
2783 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2784 break;
2785 case DW_OP_fbreg:
2786 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2787 break;
2788 case DW_OP_bregx:
2789 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2790 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2791 break;
2792 case DW_OP_piece:
2793 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2794 break;
2795 case DW_OP_deref_size:
2796 case DW_OP_xderef_size:
2797 dw2_asm_output_data (1, val1->v.val_int, NULL);
2798 break;
2799 default:
2800 /* Other codes have no operands. */
2801 break;
2805 /* Output a sequence of location operations. */
2807 static void
2808 output_loc_sequence (loc)
2809 dw_loc_descr_ref loc;
2811 for (; loc != NULL; loc = loc->dw_loc_next)
2813 /* Output the opcode. */
2814 dw2_asm_output_data (1, loc->dw_loc_opc,
2815 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2817 /* Output the operand(s) (if any). */
2818 output_loc_operands (loc);
2822 /* This routine will generate the correct assembly data for a location
2823 description based on a cfi entry with a complex address. */
2825 static void
2826 output_cfa_loc (cfi)
2827 dw_cfi_ref cfi;
2829 dw_loc_descr_ref loc;
2830 unsigned long size;
2832 /* Output the size of the block. */
2833 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2834 size = size_of_locs (loc);
2835 dw2_asm_output_data_uleb128 (size, NULL);
2837 /* Now output the operations themselves. */
2838 output_loc_sequence (loc);
2841 /* This function builds a dwarf location descriptor seqeunce from
2842 a dw_cfa_location. */
2844 static struct dw_loc_descr_struct *
2845 build_cfa_loc (cfa)
2846 dw_cfa_location *cfa;
2848 struct dw_loc_descr_struct *head, *tmp;
2850 if (cfa->indirect == 0)
2851 abort ();
2853 if (cfa->base_offset)
2855 if (cfa->reg <= 31)
2856 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2857 else
2858 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2860 else if (cfa->reg <= 31)
2861 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2862 else
2863 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2864 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2865 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2866 add_loc_descr (&head, tmp);
2867 if (cfa->offset != 0)
2869 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2870 add_loc_descr (&head, tmp);
2872 return head;
2875 /* This function fills in aa dw_cfa_location structure from a
2876 dwarf location descriptor sequence. */
2878 static void
2879 get_cfa_from_loc_descr (cfa, loc)
2880 dw_cfa_location *cfa;
2881 struct dw_loc_descr_struct *loc;
2883 struct dw_loc_descr_struct *ptr;
2884 cfa->offset = 0;
2885 cfa->base_offset = 0;
2886 cfa->indirect = 0;
2887 cfa->reg = -1;
2889 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2891 enum dwarf_location_atom op = ptr->dw_loc_opc;
2892 switch (op)
2894 case DW_OP_reg0:
2895 case DW_OP_reg1:
2896 case DW_OP_reg2:
2897 case DW_OP_reg3:
2898 case DW_OP_reg4:
2899 case DW_OP_reg5:
2900 case DW_OP_reg6:
2901 case DW_OP_reg7:
2902 case DW_OP_reg8:
2903 case DW_OP_reg9:
2904 case DW_OP_reg10:
2905 case DW_OP_reg11:
2906 case DW_OP_reg12:
2907 case DW_OP_reg13:
2908 case DW_OP_reg14:
2909 case DW_OP_reg15:
2910 case DW_OP_reg16:
2911 case DW_OP_reg17:
2912 case DW_OP_reg18:
2913 case DW_OP_reg19:
2914 case DW_OP_reg20:
2915 case DW_OP_reg21:
2916 case DW_OP_reg22:
2917 case DW_OP_reg23:
2918 case DW_OP_reg24:
2919 case DW_OP_reg25:
2920 case DW_OP_reg26:
2921 case DW_OP_reg27:
2922 case DW_OP_reg28:
2923 case DW_OP_reg29:
2924 case DW_OP_reg30:
2925 case DW_OP_reg31:
2926 cfa->reg = op - DW_OP_reg0;
2927 break;
2928 case DW_OP_regx:
2929 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2930 break;
2931 case DW_OP_breg0:
2932 case DW_OP_breg1:
2933 case DW_OP_breg2:
2934 case DW_OP_breg3:
2935 case DW_OP_breg4:
2936 case DW_OP_breg5:
2937 case DW_OP_breg6:
2938 case DW_OP_breg7:
2939 case DW_OP_breg8:
2940 case DW_OP_breg9:
2941 case DW_OP_breg10:
2942 case DW_OP_breg11:
2943 case DW_OP_breg12:
2944 case DW_OP_breg13:
2945 case DW_OP_breg14:
2946 case DW_OP_breg15:
2947 case DW_OP_breg16:
2948 case DW_OP_breg17:
2949 case DW_OP_breg18:
2950 case DW_OP_breg19:
2951 case DW_OP_breg20:
2952 case DW_OP_breg21:
2953 case DW_OP_breg22:
2954 case DW_OP_breg23:
2955 case DW_OP_breg24:
2956 case DW_OP_breg25:
2957 case DW_OP_breg26:
2958 case DW_OP_breg27:
2959 case DW_OP_breg28:
2960 case DW_OP_breg29:
2961 case DW_OP_breg30:
2962 case DW_OP_breg31:
2963 cfa->reg = op - DW_OP_breg0;
2964 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2965 break;
2966 case DW_OP_bregx:
2967 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2968 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2969 break;
2970 case DW_OP_deref:
2971 cfa->indirect = 1;
2972 break;
2973 case DW_OP_plus_uconst:
2974 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2975 break;
2976 default:
2977 internal_error ("DW_LOC_OP %s not implememnted\n",
2978 dwarf_stack_op_name (ptr->dw_loc_opc));
2982 #endif /* .debug_frame support */
2984 /* And now, the support for symbolic debugging information. */
2985 #ifdef DWARF2_DEBUGGING_INFO
2987 /* NOTE: In the comments in this file, many references are made to
2988 "Debugging Information Entries". This term is abbreviated as `DIE'
2989 throughout the remainder of this file. */
2991 /* An internal representation of the DWARF output is built, and then
2992 walked to generate the DWARF debugging info. The walk of the internal
2993 representation is done after the entire program has been compiled.
2994 The types below are used to describe the internal representation. */
2996 /* Various DIE's use offsets relative to the beginning of the
2997 .debug_info section to refer to each other. */
2999 typedef long int dw_offset;
3001 /* Define typedefs here to avoid circular dependencies. */
3003 typedef struct dw_attr_struct *dw_attr_ref;
3004 typedef struct dw_line_info_struct *dw_line_info_ref;
3005 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3006 typedef struct pubname_struct *pubname_ref;
3007 typedef dw_die_ref *arange_ref;
3009 /* Each entry in the line_info_table maintains the file and
3010 line number associated with the label generated for that
3011 entry. The label gives the PC value associated with
3012 the line number entry. */
3014 typedef struct dw_line_info_struct
3016 unsigned long dw_file_num;
3017 unsigned long dw_line_num;
3019 dw_line_info_entry;
3021 /* Line information for functions in separate sections; each one gets its
3022 own sequence. */
3023 typedef struct dw_separate_line_info_struct
3025 unsigned long dw_file_num;
3026 unsigned long dw_line_num;
3027 unsigned long function;
3029 dw_separate_line_info_entry;
3031 /* Each DIE attribute has a field specifying the attribute kind,
3032 a link to the next attribute in the chain, and an attribute value.
3033 Attributes are typically linked below the DIE they modify. */
3035 typedef struct dw_attr_struct
3037 enum dwarf_attribute dw_attr;
3038 dw_attr_ref dw_attr_next;
3039 dw_val_node dw_attr_val;
3041 dw_attr_node;
3043 /* The Debugging Information Entry (DIE) structure */
3045 typedef struct die_struct
3047 enum dwarf_tag die_tag;
3048 char *die_symbol;
3049 dw_attr_ref die_attr;
3050 dw_die_ref die_parent;
3051 dw_die_ref die_child;
3052 dw_die_ref die_sib;
3053 dw_offset die_offset;
3054 unsigned long die_abbrev;
3055 int die_mark;
3057 die_node;
3059 /* The pubname structure */
3061 typedef struct pubname_struct
3063 dw_die_ref die;
3064 char *name;
3066 pubname_entry;
3068 /* The limbo die list structure. */
3069 typedef struct limbo_die_struct
3071 dw_die_ref die;
3072 struct limbo_die_struct *next;
3074 limbo_die_node;
3076 /* How to start an assembler comment. */
3077 #ifndef ASM_COMMENT_START
3078 #define ASM_COMMENT_START ";#"
3079 #endif
3081 /* Define a macro which returns non-zero for a TYPE_DECL which was
3082 implicitly generated for a tagged type.
3084 Note that unlike the gcc front end (which generates a NULL named
3085 TYPE_DECL node for each complete tagged type, each array type, and
3086 each function type node created) the g++ front end generates a
3087 _named_ TYPE_DECL node for each tagged type node created.
3088 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3089 generate a DW_TAG_typedef DIE for them. */
3091 #define TYPE_DECL_IS_STUB(decl) \
3092 (DECL_NAME (decl) == NULL_TREE \
3093 || (DECL_ARTIFICIAL (decl) \
3094 && is_tagged_type (TREE_TYPE (decl)) \
3095 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3096 /* This is necessary for stub decls that \
3097 appear in nested inline functions. */ \
3098 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3099 && (decl_ultimate_origin (decl) \
3100 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3102 /* Information concerning the compilation unit's programming
3103 language, and compiler version. */
3105 extern int flag_traditional;
3107 /* Fixed size portion of the DWARF compilation unit header. */
3108 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3110 /* Fixed size portion of debugging line information prolog. */
3111 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3113 /* Fixed size portion of public names info. */
3114 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3116 /* Fixed size portion of the address range info. */
3117 #define DWARF_ARANGES_HEADER_SIZE \
3118 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3119 - DWARF_OFFSET_SIZE)
3121 /* Size of padding portion in the address range info. It must be
3122 aligned to twice the pointer size. */
3123 #define DWARF_ARANGES_PAD_SIZE \
3124 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3125 - (2 * DWARF_OFFSET_SIZE + 4))
3127 /* Use assembler line directives if available. */
3128 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3129 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3130 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3131 #else
3132 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3133 #endif
3134 #endif
3136 /* Define the architecture-dependent minimum instruction length (in bytes).
3137 In this implementation of DWARF, this field is used for information
3138 purposes only. Since GCC generates assembly language, we have
3139 no a priori knowledge of how many instruction bytes are generated
3140 for each source line, and therefore can use only the DW_LNE_set_address
3141 and DW_LNS_fixed_advance_pc line information commands. */
3143 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3144 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3145 #endif
3147 /* Minimum line offset in a special line info. opcode.
3148 This value was chosen to give a reasonable range of values. */
3149 #define DWARF_LINE_BASE -10
3151 /* First special line opcde - leave room for the standard opcodes. */
3152 #define DWARF_LINE_OPCODE_BASE 10
3154 /* Range of line offsets in a special line info. opcode. */
3155 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3157 /* Flag that indicates the initial value of the is_stmt_start flag.
3158 In the present implementation, we do not mark any lines as
3159 the beginning of a source statement, because that information
3160 is not made available by the GCC front-end. */
3161 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3163 /* This location is used by calc_die_sizes() to keep track
3164 the offset of each DIE within the .debug_info section. */
3165 static unsigned long next_die_offset;
3167 /* Record the root of the DIE's built for the current compilation unit. */
3168 static dw_die_ref comp_unit_die;
3170 /* A list of DIEs with a NULL parent waiting to be relocated. */
3171 static limbo_die_node *limbo_die_list = 0;
3173 /* Structure used by lookup_filename to manage sets of filenames. */
3174 struct file_table
3176 char **table;
3177 unsigned allocated;
3178 unsigned in_use;
3179 unsigned last_lookup_index;
3182 /* Size (in elements) of increments by which we may expand the filename
3183 table. */
3184 #define FILE_TABLE_INCREMENT 64
3186 /* Filenames referenced by this compilation unit. */
3187 static struct file_table file_table;
3189 /* Local pointer to the name of the main input file. Initialized in
3190 dwarf2out_init. */
3191 static const char *primary_filename;
3193 /* A pointer to the base of a table of references to DIE's that describe
3194 declarations. The table is indexed by DECL_UID() which is a unique
3195 number identifying each decl. */
3196 static dw_die_ref *decl_die_table;
3198 /* Number of elements currently allocated for the decl_die_table. */
3199 static unsigned decl_die_table_allocated;
3201 /* Number of elements in decl_die_table currently in use. */
3202 static unsigned decl_die_table_in_use;
3204 /* Size (in elements) of increments by which we may expand the
3205 decl_die_table. */
3206 #define DECL_DIE_TABLE_INCREMENT 256
3208 /* A pointer to the base of a table of references to declaration
3209 scopes. This table is a display which tracks the nesting
3210 of declaration scopes at the current scope and containing
3211 scopes. This table is used to find the proper place to
3212 define type declaration DIE's. */
3213 static tree *decl_scope_table;
3215 /* Number of elements currently allocated for the decl_scope_table. */
3216 static int decl_scope_table_allocated;
3218 /* Current level of nesting of declaration scopes. */
3219 static int decl_scope_depth;
3221 /* Size (in elements) of increments by which we may expand the
3222 decl_scope_table. */
3223 #define DECL_SCOPE_TABLE_INCREMENT 64
3225 /* A pointer to the base of a list of references to DIE's that
3226 are uniquely identified by their tag, presence/absence of
3227 children DIE's, and list of attribute/value pairs. */
3228 static dw_die_ref *abbrev_die_table;
3230 /* Number of elements currently allocated for abbrev_die_table. */
3231 static unsigned abbrev_die_table_allocated;
3233 /* Number of elements in type_die_table currently in use. */
3234 static unsigned abbrev_die_table_in_use;
3236 /* Size (in elements) of increments by which we may expand the
3237 abbrev_die_table. */
3238 #define ABBREV_DIE_TABLE_INCREMENT 256
3240 /* A pointer to the base of a table that contains line information
3241 for each source code line in .text in the compilation unit. */
3242 static dw_line_info_ref line_info_table;
3244 /* Number of elements currently allocated for line_info_table. */
3245 static unsigned line_info_table_allocated;
3247 /* Number of elements in separate_line_info_table currently in use. */
3248 static unsigned separate_line_info_table_in_use;
3250 /* A pointer to the base of a table that contains line information
3251 for each source code line outside of .text in the compilation unit. */
3252 static dw_separate_line_info_ref separate_line_info_table;
3254 /* Number of elements currently allocated for separate_line_info_table. */
3255 static unsigned separate_line_info_table_allocated;
3257 /* Number of elements in line_info_table currently in use. */
3258 static unsigned line_info_table_in_use;
3260 /* Size (in elements) of increments by which we may expand the
3261 line_info_table. */
3262 #define LINE_INFO_TABLE_INCREMENT 1024
3264 /* A pointer to the base of a table that contains a list of publicly
3265 accessible names. */
3266 static pubname_ref pubname_table;
3268 /* Number of elements currently allocated for pubname_table. */
3269 static unsigned pubname_table_allocated;
3271 /* Number of elements in pubname_table currently in use. */
3272 static unsigned pubname_table_in_use;
3274 /* Size (in elements) of increments by which we may expand the
3275 pubname_table. */
3276 #define PUBNAME_TABLE_INCREMENT 64
3278 /* A pointer to the base of a table that contains a list of publicly
3279 accessible names. */
3280 static arange_ref arange_table;
3282 /* Number of elements currently allocated for arange_table. */
3283 static unsigned arange_table_allocated;
3285 /* Number of elements in arange_table currently in use. */
3286 static unsigned arange_table_in_use;
3288 /* Size (in elements) of increments by which we may expand the
3289 arange_table. */
3290 #define ARANGE_TABLE_INCREMENT 64
3292 /* A pointer to the base of a list of incomplete types which might be
3293 completed at some later time. */
3295 static tree *incomplete_types_list;
3297 /* Number of elements currently allocated for the incomplete_types_list. */
3298 static unsigned incomplete_types_allocated;
3300 /* Number of elements of incomplete_types_list currently in use. */
3301 static unsigned incomplete_types;
3303 /* Size (in elements) of increments by which we may expand the incomplete
3304 types list. Actually, a single hunk of space of this size should
3305 be enough for most typical programs. */
3306 #define INCOMPLETE_TYPES_INCREMENT 64
3308 /* Record whether the function being analyzed contains inlined functions. */
3309 static int current_function_has_inlines;
3310 #if 0 && defined (MIPS_DEBUGGING_INFO)
3311 static int comp_unit_has_inlines;
3312 #endif
3314 /* Array of RTXes referenced by the debugging information, which therefore
3315 must be kept around forever. We do this rather than perform GC on
3316 the dwarf info because almost all of the dwarf info lives forever, and
3317 it's easier to support non-GC frontends this way. */
3318 static varray_type used_rtx_varray;
3320 /* Forward declarations for functions defined in this file. */
3322 static int is_pseudo_reg PARAMS ((rtx));
3323 static tree type_main_variant PARAMS ((tree));
3324 static int is_tagged_type PARAMS ((tree));
3325 static const char *dwarf_tag_name PARAMS ((unsigned));
3326 static const char *dwarf_attr_name PARAMS ((unsigned));
3327 static const char *dwarf_form_name PARAMS ((unsigned));
3328 #if 0
3329 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3330 #endif
3331 static tree decl_ultimate_origin PARAMS ((tree));
3332 static tree block_ultimate_origin PARAMS ((tree));
3333 static tree decl_class_context PARAMS ((tree));
3334 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3335 static void add_AT_flag PARAMS ((dw_die_ref,
3336 enum dwarf_attribute,
3337 unsigned));
3338 static void add_AT_int PARAMS ((dw_die_ref,
3339 enum dwarf_attribute, long));
3340 static void add_AT_unsigned PARAMS ((dw_die_ref,
3341 enum dwarf_attribute,
3342 unsigned long));
3343 static void add_AT_long_long PARAMS ((dw_die_ref,
3344 enum dwarf_attribute,
3345 unsigned long,
3346 unsigned long));
3347 static void add_AT_float PARAMS ((dw_die_ref,
3348 enum dwarf_attribute,
3349 unsigned, long *));
3350 static void add_AT_string PARAMS ((dw_die_ref,
3351 enum dwarf_attribute,
3352 const char *));
3353 static void add_AT_die_ref PARAMS ((dw_die_ref,
3354 enum dwarf_attribute,
3355 dw_die_ref));
3356 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3357 enum dwarf_attribute,
3358 unsigned));
3359 static void add_AT_loc PARAMS ((dw_die_ref,
3360 enum dwarf_attribute,
3361 dw_loc_descr_ref));
3362 static void add_AT_addr PARAMS ((dw_die_ref,
3363 enum dwarf_attribute,
3364 rtx));
3365 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3366 enum dwarf_attribute,
3367 const char *));
3368 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3369 enum dwarf_attribute,
3370 const char *));
3371 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3372 enum dwarf_attribute));
3373 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3374 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3375 static const char *get_AT_string PARAMS ((dw_die_ref,
3376 enum dwarf_attribute));
3377 static int get_AT_flag PARAMS ((dw_die_ref,
3378 enum dwarf_attribute));
3379 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3380 enum dwarf_attribute));
3381 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3382 enum dwarf_attribute));
3383 static int is_c_family PARAMS ((void));
3384 static int is_java PARAMS ((void));
3385 static int is_fortran PARAMS ((void));
3386 static void remove_AT PARAMS ((dw_die_ref,
3387 enum dwarf_attribute));
3388 static void remove_children PARAMS ((dw_die_ref));
3389 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3390 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3391 static dw_die_ref lookup_type_die PARAMS ((tree));
3392 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3393 static dw_die_ref lookup_decl_die PARAMS ((tree));
3394 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3395 static void print_spaces PARAMS ((FILE *));
3396 static void print_die PARAMS ((dw_die_ref, FILE *));
3397 static void print_dwarf_line_table PARAMS ((FILE *));
3398 static void reverse_die_lists PARAMS ((dw_die_ref));
3399 static void reverse_all_dies PARAMS ((dw_die_ref));
3400 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3401 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3402 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3403 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3404 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3405 static void compute_section_prefix PARAMS ((dw_die_ref));
3406 static int is_type_die PARAMS ((dw_die_ref));
3407 static int is_comdat_die PARAMS ((dw_die_ref));
3408 static int is_symbol_die PARAMS ((dw_die_ref));
3409 static char *gen_internal_sym PARAMS ((void));
3410 static void assign_symbol_names PARAMS ((dw_die_ref));
3411 static void break_out_includes PARAMS ((dw_die_ref));
3412 static void add_sibling_attributes PARAMS ((dw_die_ref));
3413 static void build_abbrev_table PARAMS ((dw_die_ref));
3414 static unsigned long size_of_string PARAMS ((const char *));
3415 static int constant_size PARAMS ((long unsigned));
3416 static unsigned long size_of_die PARAMS ((dw_die_ref));
3417 static void calc_die_sizes PARAMS ((dw_die_ref));
3418 static void mark_dies PARAMS ((dw_die_ref));
3419 static void unmark_dies PARAMS ((dw_die_ref));
3420 static unsigned long size_of_pubnames PARAMS ((void));
3421 static unsigned long size_of_aranges PARAMS ((void));
3422 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3423 static void output_value_format PARAMS ((dw_attr_ref));
3424 static void output_abbrev_section PARAMS ((void));
3425 static void output_die_symbol PARAMS ((dw_die_ref));
3426 static void output_die PARAMS ((dw_die_ref));
3427 static void output_compilation_unit_header PARAMS ((void));
3428 static void output_comp_unit PARAMS ((dw_die_ref));
3429 static const char *dwarf2_name PARAMS ((tree, int));
3430 static void add_pubname PARAMS ((tree, dw_die_ref));
3431 static void output_pubnames PARAMS ((void));
3432 static void add_arange PARAMS ((tree, dw_die_ref));
3433 static void output_aranges PARAMS ((void));
3434 static void output_line_info PARAMS ((void));
3435 static void output_file_names PARAMS ((void));
3436 static dw_die_ref base_type_die PARAMS ((tree));
3437 static tree root_type PARAMS ((tree));
3438 static int is_base_type PARAMS ((tree));
3439 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3440 static int type_is_enum PARAMS ((tree));
3441 static unsigned int reg_number PARAMS ((rtx));
3442 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3443 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3444 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3445 static int is_based_loc PARAMS ((rtx));
3446 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3447 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3448 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3449 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3450 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3451 static tree field_type PARAMS ((tree));
3452 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3453 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3454 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3455 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3456 static void add_AT_location_description PARAMS ((dw_die_ref,
3457 enum dwarf_attribute, rtx));
3458 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3459 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3460 static rtx rtl_for_decl_location PARAMS ((tree));
3461 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3462 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3463 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3464 static void add_bound_info PARAMS ((dw_die_ref,
3465 enum dwarf_attribute, tree));
3466 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3467 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3468 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3469 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3470 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3471 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3472 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3473 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3474 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3475 static void push_decl_scope PARAMS ((tree));
3476 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3477 static void pop_decl_scope PARAMS ((void));
3478 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3479 dw_die_ref));
3480 static const char *type_tag PARAMS ((tree));
3481 static tree member_declared_type PARAMS ((tree));
3482 #if 0
3483 static const char *decl_start_label PARAMS ((tree));
3484 #endif
3485 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3486 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3487 #if 0
3488 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3489 #endif
3490 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3491 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3492 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3493 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3494 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3495 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3496 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3497 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3498 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3499 static void gen_label_die PARAMS ((tree, dw_die_ref));
3500 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3501 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3502 static void gen_field_die PARAMS ((tree, dw_die_ref));
3503 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3504 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3505 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3506 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3507 static void gen_member_die PARAMS ((tree, dw_die_ref));
3508 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3509 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3510 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3511 static void gen_type_die PARAMS ((tree, dw_die_ref));
3512 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3513 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3514 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3515 static int is_redundant_typedef PARAMS ((tree));
3516 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3517 static unsigned lookup_filename PARAMS ((const char *));
3518 static void init_file_table PARAMS ((void));
3519 static void add_incomplete_type PARAMS ((tree));
3520 static void retry_incomplete_types PARAMS ((void));
3521 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3522 static rtx save_rtx PARAMS ((rtx));
3523 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3524 static int file_info_cmp PARAMS ((const void *, const void *));
3526 /* Section names used to hold DWARF debugging information. */
3527 #ifndef DEBUG_INFO_SECTION
3528 #define DEBUG_INFO_SECTION ".debug_info"
3529 #endif
3530 #ifndef ABBREV_SECTION
3531 #define ABBREV_SECTION ".debug_abbrev"
3532 #endif
3533 #ifndef ARANGES_SECTION
3534 #define ARANGES_SECTION ".debug_aranges"
3535 #endif
3536 #ifndef DW_MACINFO_SECTION
3537 #define DW_MACINFO_SECTION ".debug_macinfo"
3538 #endif
3539 #ifndef DEBUG_LINE_SECTION
3540 #define DEBUG_LINE_SECTION ".debug_line"
3541 #endif
3542 #ifndef LOC_SECTION
3543 #define LOC_SECTION ".debug_loc"
3544 #endif
3545 #ifndef PUBNAMES_SECTION
3546 #define PUBNAMES_SECTION ".debug_pubnames"
3547 #endif
3548 #ifndef STR_SECTION
3549 #define STR_SECTION ".debug_str"
3550 #endif
3552 /* Standard ELF section names for compiled code and data. */
3553 #ifndef TEXT_SECTION
3554 #define TEXT_SECTION ".text"
3555 #endif
3556 #ifndef DATA_SECTION
3557 #define DATA_SECTION ".data"
3558 #endif
3559 #ifndef BSS_SECTION
3560 #define BSS_SECTION ".bss"
3561 #endif
3563 /* Labels we insert at beginning sections we can reference instead of
3564 the section names themselves. */
3566 #ifndef TEXT_SECTION_LABEL
3567 #define TEXT_SECTION_LABEL "Ltext"
3568 #endif
3569 #ifndef DEBUG_LINE_SECTION_LABEL
3570 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3571 #endif
3572 #ifndef DEBUG_INFO_SECTION_LABEL
3573 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3574 #endif
3575 #ifndef ABBREV_SECTION_LABEL
3576 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3577 #endif
3579 /* Definitions of defaults for formats and names of various special
3580 (artificial) labels which may be generated within this file (when the -g
3581 options is used and DWARF_DEBUGGING_INFO is in effect.
3582 If necessary, these may be overridden from within the tm.h file, but
3583 typically, overriding these defaults is unnecessary. */
3585 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3586 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3587 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3588 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3589 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3591 #ifndef TEXT_END_LABEL
3592 #define TEXT_END_LABEL "Letext"
3593 #endif
3594 #ifndef DATA_END_LABEL
3595 #define DATA_END_LABEL "Ledata"
3596 #endif
3597 #ifndef BSS_END_LABEL
3598 #define BSS_END_LABEL "Lebss"
3599 #endif
3600 #ifndef BLOCK_BEGIN_LABEL
3601 #define BLOCK_BEGIN_LABEL "LBB"
3602 #endif
3603 #ifndef BLOCK_END_LABEL
3604 #define BLOCK_END_LABEL "LBE"
3605 #endif
3606 #ifndef BODY_BEGIN_LABEL
3607 #define BODY_BEGIN_LABEL "Lbb"
3608 #endif
3609 #ifndef BODY_END_LABEL
3610 #define BODY_END_LABEL "Lbe"
3611 #endif
3612 #ifndef LINE_CODE_LABEL
3613 #define LINE_CODE_LABEL "LM"
3614 #endif
3615 #ifndef SEPARATE_LINE_CODE_LABEL
3616 #define SEPARATE_LINE_CODE_LABEL "LSM"
3617 #endif
3619 /* We allow a language front-end to designate a function that is to be
3620 called to "demangle" any name before it it put into a DIE. */
3622 static const char *(*demangle_name_func) PARAMS ((const char *));
3624 void
3625 dwarf2out_set_demangle_name_func (func)
3626 const char *(*func) PARAMS ((const char *));
3628 demangle_name_func = func;
3631 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3632 that means adding it to used_rtx_varray. If not, that means making
3633 a copy on the permanent_obstack. */
3635 static rtx
3636 save_rtx (orig)
3637 register rtx orig;
3639 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3641 return orig;
3644 /* Test if rtl node points to a pseudo register. */
3646 static inline int
3647 is_pseudo_reg (rtl)
3648 register rtx rtl;
3650 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3651 || (GET_CODE (rtl) == SUBREG
3652 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3655 /* Return a reference to a type, with its const and volatile qualifiers
3656 removed. */
3658 static inline tree
3659 type_main_variant (type)
3660 register tree type;
3662 type = TYPE_MAIN_VARIANT (type);
3664 /* There really should be only one main variant among any group of variants
3665 of a given type (and all of the MAIN_VARIANT values for all members of
3666 the group should point to that one type) but sometimes the C front-end
3667 messes this up for array types, so we work around that bug here. */
3669 if (TREE_CODE (type) == ARRAY_TYPE)
3670 while (type != TYPE_MAIN_VARIANT (type))
3671 type = TYPE_MAIN_VARIANT (type);
3673 return type;
3676 /* Return non-zero if the given type node represents a tagged type. */
3678 static inline int
3679 is_tagged_type (type)
3680 register tree type;
3682 register enum tree_code code = TREE_CODE (type);
3684 return (code == RECORD_TYPE || code == UNION_TYPE
3685 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3688 /* Convert a DIE tag into its string name. */
3690 static const char *
3691 dwarf_tag_name (tag)
3692 register unsigned tag;
3694 switch (tag)
3696 case DW_TAG_padding:
3697 return "DW_TAG_padding";
3698 case DW_TAG_array_type:
3699 return "DW_TAG_array_type";
3700 case DW_TAG_class_type:
3701 return "DW_TAG_class_type";
3702 case DW_TAG_entry_point:
3703 return "DW_TAG_entry_point";
3704 case DW_TAG_enumeration_type:
3705 return "DW_TAG_enumeration_type";
3706 case DW_TAG_formal_parameter:
3707 return "DW_TAG_formal_parameter";
3708 case DW_TAG_imported_declaration:
3709 return "DW_TAG_imported_declaration";
3710 case DW_TAG_label:
3711 return "DW_TAG_label";
3712 case DW_TAG_lexical_block:
3713 return "DW_TAG_lexical_block";
3714 case DW_TAG_member:
3715 return "DW_TAG_member";
3716 case DW_TAG_pointer_type:
3717 return "DW_TAG_pointer_type";
3718 case DW_TAG_reference_type:
3719 return "DW_TAG_reference_type";
3720 case DW_TAG_compile_unit:
3721 return "DW_TAG_compile_unit";
3722 case DW_TAG_string_type:
3723 return "DW_TAG_string_type";
3724 case DW_TAG_structure_type:
3725 return "DW_TAG_structure_type";
3726 case DW_TAG_subroutine_type:
3727 return "DW_TAG_subroutine_type";
3728 case DW_TAG_typedef:
3729 return "DW_TAG_typedef";
3730 case DW_TAG_union_type:
3731 return "DW_TAG_union_type";
3732 case DW_TAG_unspecified_parameters:
3733 return "DW_TAG_unspecified_parameters";
3734 case DW_TAG_variant:
3735 return "DW_TAG_variant";
3736 case DW_TAG_common_block:
3737 return "DW_TAG_common_block";
3738 case DW_TAG_common_inclusion:
3739 return "DW_TAG_common_inclusion";
3740 case DW_TAG_inheritance:
3741 return "DW_TAG_inheritance";
3742 case DW_TAG_inlined_subroutine:
3743 return "DW_TAG_inlined_subroutine";
3744 case DW_TAG_module:
3745 return "DW_TAG_module";
3746 case DW_TAG_ptr_to_member_type:
3747 return "DW_TAG_ptr_to_member_type";
3748 case DW_TAG_set_type:
3749 return "DW_TAG_set_type";
3750 case DW_TAG_subrange_type:
3751 return "DW_TAG_subrange_type";
3752 case DW_TAG_with_stmt:
3753 return "DW_TAG_with_stmt";
3754 case DW_TAG_access_declaration:
3755 return "DW_TAG_access_declaration";
3756 case DW_TAG_base_type:
3757 return "DW_TAG_base_type";
3758 case DW_TAG_catch_block:
3759 return "DW_TAG_catch_block";
3760 case DW_TAG_const_type:
3761 return "DW_TAG_const_type";
3762 case DW_TAG_constant:
3763 return "DW_TAG_constant";
3764 case DW_TAG_enumerator:
3765 return "DW_TAG_enumerator";
3766 case DW_TAG_file_type:
3767 return "DW_TAG_file_type";
3768 case DW_TAG_friend:
3769 return "DW_TAG_friend";
3770 case DW_TAG_namelist:
3771 return "DW_TAG_namelist";
3772 case DW_TAG_namelist_item:
3773 return "DW_TAG_namelist_item";
3774 case DW_TAG_packed_type:
3775 return "DW_TAG_packed_type";
3776 case DW_TAG_subprogram:
3777 return "DW_TAG_subprogram";
3778 case DW_TAG_template_type_param:
3779 return "DW_TAG_template_type_param";
3780 case DW_TAG_template_value_param:
3781 return "DW_TAG_template_value_param";
3782 case DW_TAG_thrown_type:
3783 return "DW_TAG_thrown_type";
3784 case DW_TAG_try_block:
3785 return "DW_TAG_try_block";
3786 case DW_TAG_variant_part:
3787 return "DW_TAG_variant_part";
3788 case DW_TAG_variable:
3789 return "DW_TAG_variable";
3790 case DW_TAG_volatile_type:
3791 return "DW_TAG_volatile_type";
3792 case DW_TAG_MIPS_loop:
3793 return "DW_TAG_MIPS_loop";
3794 case DW_TAG_format_label:
3795 return "DW_TAG_format_label";
3796 case DW_TAG_function_template:
3797 return "DW_TAG_function_template";
3798 case DW_TAG_class_template:
3799 return "DW_TAG_class_template";
3800 case DW_TAG_GNU_BINCL:
3801 return "DW_TAG_GNU_BINCL";
3802 case DW_TAG_GNU_EINCL:
3803 return "DW_TAG_GNU_EINCL";
3804 default:
3805 return "DW_TAG_<unknown>";
3809 /* Convert a DWARF attribute code into its string name. */
3811 static const char *
3812 dwarf_attr_name (attr)
3813 register unsigned attr;
3815 switch (attr)
3817 case DW_AT_sibling:
3818 return "DW_AT_sibling";
3819 case DW_AT_location:
3820 return "DW_AT_location";
3821 case DW_AT_name:
3822 return "DW_AT_name";
3823 case DW_AT_ordering:
3824 return "DW_AT_ordering";
3825 case DW_AT_subscr_data:
3826 return "DW_AT_subscr_data";
3827 case DW_AT_byte_size:
3828 return "DW_AT_byte_size";
3829 case DW_AT_bit_offset:
3830 return "DW_AT_bit_offset";
3831 case DW_AT_bit_size:
3832 return "DW_AT_bit_size";
3833 case DW_AT_element_list:
3834 return "DW_AT_element_list";
3835 case DW_AT_stmt_list:
3836 return "DW_AT_stmt_list";
3837 case DW_AT_low_pc:
3838 return "DW_AT_low_pc";
3839 case DW_AT_high_pc:
3840 return "DW_AT_high_pc";
3841 case DW_AT_language:
3842 return "DW_AT_language";
3843 case DW_AT_member:
3844 return "DW_AT_member";
3845 case DW_AT_discr:
3846 return "DW_AT_discr";
3847 case DW_AT_discr_value:
3848 return "DW_AT_discr_value";
3849 case DW_AT_visibility:
3850 return "DW_AT_visibility";
3851 case DW_AT_import:
3852 return "DW_AT_import";
3853 case DW_AT_string_length:
3854 return "DW_AT_string_length";
3855 case DW_AT_common_reference:
3856 return "DW_AT_common_reference";
3857 case DW_AT_comp_dir:
3858 return "DW_AT_comp_dir";
3859 case DW_AT_const_value:
3860 return "DW_AT_const_value";
3861 case DW_AT_containing_type:
3862 return "DW_AT_containing_type";
3863 case DW_AT_default_value:
3864 return "DW_AT_default_value";
3865 case DW_AT_inline:
3866 return "DW_AT_inline";
3867 case DW_AT_is_optional:
3868 return "DW_AT_is_optional";
3869 case DW_AT_lower_bound:
3870 return "DW_AT_lower_bound";
3871 case DW_AT_producer:
3872 return "DW_AT_producer";
3873 case DW_AT_prototyped:
3874 return "DW_AT_prototyped";
3875 case DW_AT_return_addr:
3876 return "DW_AT_return_addr";
3877 case DW_AT_start_scope:
3878 return "DW_AT_start_scope";
3879 case DW_AT_stride_size:
3880 return "DW_AT_stride_size";
3881 case DW_AT_upper_bound:
3882 return "DW_AT_upper_bound";
3883 case DW_AT_abstract_origin:
3884 return "DW_AT_abstract_origin";
3885 case DW_AT_accessibility:
3886 return "DW_AT_accessibility";
3887 case DW_AT_address_class:
3888 return "DW_AT_address_class";
3889 case DW_AT_artificial:
3890 return "DW_AT_artificial";
3891 case DW_AT_base_types:
3892 return "DW_AT_base_types";
3893 case DW_AT_calling_convention:
3894 return "DW_AT_calling_convention";
3895 case DW_AT_count:
3896 return "DW_AT_count";
3897 case DW_AT_data_member_location:
3898 return "DW_AT_data_member_location";
3899 case DW_AT_decl_column:
3900 return "DW_AT_decl_column";
3901 case DW_AT_decl_file:
3902 return "DW_AT_decl_file";
3903 case DW_AT_decl_line:
3904 return "DW_AT_decl_line";
3905 case DW_AT_declaration:
3906 return "DW_AT_declaration";
3907 case DW_AT_discr_list:
3908 return "DW_AT_discr_list";
3909 case DW_AT_encoding:
3910 return "DW_AT_encoding";
3911 case DW_AT_external:
3912 return "DW_AT_external";
3913 case DW_AT_frame_base:
3914 return "DW_AT_frame_base";
3915 case DW_AT_friend:
3916 return "DW_AT_friend";
3917 case DW_AT_identifier_case:
3918 return "DW_AT_identifier_case";
3919 case DW_AT_macro_info:
3920 return "DW_AT_macro_info";
3921 case DW_AT_namelist_items:
3922 return "DW_AT_namelist_items";
3923 case DW_AT_priority:
3924 return "DW_AT_priority";
3925 case DW_AT_segment:
3926 return "DW_AT_segment";
3927 case DW_AT_specification:
3928 return "DW_AT_specification";
3929 case DW_AT_static_link:
3930 return "DW_AT_static_link";
3931 case DW_AT_type:
3932 return "DW_AT_type";
3933 case DW_AT_use_location:
3934 return "DW_AT_use_location";
3935 case DW_AT_variable_parameter:
3936 return "DW_AT_variable_parameter";
3937 case DW_AT_virtuality:
3938 return "DW_AT_virtuality";
3939 case DW_AT_vtable_elem_location:
3940 return "DW_AT_vtable_elem_location";
3942 case DW_AT_MIPS_fde:
3943 return "DW_AT_MIPS_fde";
3944 case DW_AT_MIPS_loop_begin:
3945 return "DW_AT_MIPS_loop_begin";
3946 case DW_AT_MIPS_tail_loop_begin:
3947 return "DW_AT_MIPS_tail_loop_begin";
3948 case DW_AT_MIPS_epilog_begin:
3949 return "DW_AT_MIPS_epilog_begin";
3950 case DW_AT_MIPS_loop_unroll_factor:
3951 return "DW_AT_MIPS_loop_unroll_factor";
3952 case DW_AT_MIPS_software_pipeline_depth:
3953 return "DW_AT_MIPS_software_pipeline_depth";
3954 case DW_AT_MIPS_linkage_name:
3955 return "DW_AT_MIPS_linkage_name";
3956 case DW_AT_MIPS_stride:
3957 return "DW_AT_MIPS_stride";
3958 case DW_AT_MIPS_abstract_name:
3959 return "DW_AT_MIPS_abstract_name";
3960 case DW_AT_MIPS_clone_origin:
3961 return "DW_AT_MIPS_clone_origin";
3962 case DW_AT_MIPS_has_inlines:
3963 return "DW_AT_MIPS_has_inlines";
3965 case DW_AT_sf_names:
3966 return "DW_AT_sf_names";
3967 case DW_AT_src_info:
3968 return "DW_AT_src_info";
3969 case DW_AT_mac_info:
3970 return "DW_AT_mac_info";
3971 case DW_AT_src_coords:
3972 return "DW_AT_src_coords";
3973 case DW_AT_body_begin:
3974 return "DW_AT_body_begin";
3975 case DW_AT_body_end:
3976 return "DW_AT_body_end";
3977 default:
3978 return "DW_AT_<unknown>";
3982 /* Convert a DWARF value form code into its string name. */
3984 static const char *
3985 dwarf_form_name (form)
3986 register unsigned form;
3988 switch (form)
3990 case DW_FORM_addr:
3991 return "DW_FORM_addr";
3992 case DW_FORM_block2:
3993 return "DW_FORM_block2";
3994 case DW_FORM_block4:
3995 return "DW_FORM_block4";
3996 case DW_FORM_data2:
3997 return "DW_FORM_data2";
3998 case DW_FORM_data4:
3999 return "DW_FORM_data4";
4000 case DW_FORM_data8:
4001 return "DW_FORM_data8";
4002 case DW_FORM_string:
4003 return "DW_FORM_string";
4004 case DW_FORM_block:
4005 return "DW_FORM_block";
4006 case DW_FORM_block1:
4007 return "DW_FORM_block1";
4008 case DW_FORM_data1:
4009 return "DW_FORM_data1";
4010 case DW_FORM_flag:
4011 return "DW_FORM_flag";
4012 case DW_FORM_sdata:
4013 return "DW_FORM_sdata";
4014 case DW_FORM_strp:
4015 return "DW_FORM_strp";
4016 case DW_FORM_udata:
4017 return "DW_FORM_udata";
4018 case DW_FORM_ref_addr:
4019 return "DW_FORM_ref_addr";
4020 case DW_FORM_ref1:
4021 return "DW_FORM_ref1";
4022 case DW_FORM_ref2:
4023 return "DW_FORM_ref2";
4024 case DW_FORM_ref4:
4025 return "DW_FORM_ref4";
4026 case DW_FORM_ref8:
4027 return "DW_FORM_ref8";
4028 case DW_FORM_ref_udata:
4029 return "DW_FORM_ref_udata";
4030 case DW_FORM_indirect:
4031 return "DW_FORM_indirect";
4032 default:
4033 return "DW_FORM_<unknown>";
4037 /* Convert a DWARF type code into its string name. */
4039 #if 0
4040 static const char *
4041 dwarf_type_encoding_name (enc)
4042 register unsigned enc;
4044 switch (enc)
4046 case DW_ATE_address:
4047 return "DW_ATE_address";
4048 case DW_ATE_boolean:
4049 return "DW_ATE_boolean";
4050 case DW_ATE_complex_float:
4051 return "DW_ATE_complex_float";
4052 case DW_ATE_float:
4053 return "DW_ATE_float";
4054 case DW_ATE_signed:
4055 return "DW_ATE_signed";
4056 case DW_ATE_signed_char:
4057 return "DW_ATE_signed_char";
4058 case DW_ATE_unsigned:
4059 return "DW_ATE_unsigned";
4060 case DW_ATE_unsigned_char:
4061 return "DW_ATE_unsigned_char";
4062 default:
4063 return "DW_ATE_<unknown>";
4066 #endif
4068 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4069 instance of an inlined instance of a decl which is local to an inline
4070 function, so we have to trace all of the way back through the origin chain
4071 to find out what sort of node actually served as the original seed for the
4072 given block. */
4074 static tree
4075 decl_ultimate_origin (decl)
4076 register tree decl;
4078 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4079 nodes in the function to point to themselves; ignore that if
4080 we're trying to output the abstract instance of this function. */
4081 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4082 return NULL_TREE;
4084 #ifdef ENABLE_CHECKING
4085 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4086 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4087 most distant ancestor, this should never happen. */
4088 abort ();
4089 #endif
4091 return DECL_ABSTRACT_ORIGIN (decl);
4094 /* Determine the "ultimate origin" of a block. The block may be an inlined
4095 instance of an inlined instance of a block which is local to an inline
4096 function, so we have to trace all of the way back through the origin chain
4097 to find out what sort of node actually served as the original seed for the
4098 given block. */
4100 static tree
4101 block_ultimate_origin (block)
4102 register tree block;
4104 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4106 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4107 nodes in the function to point to themselves; ignore that if
4108 we're trying to output the abstract instance of this function. */
4109 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4110 return NULL_TREE;
4112 if (immediate_origin == NULL_TREE)
4113 return NULL_TREE;
4114 else
4116 register tree ret_val;
4117 register tree lookahead = immediate_origin;
4121 ret_val = lookahead;
4122 lookahead = (TREE_CODE (ret_val) == BLOCK)
4123 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4124 : NULL;
4126 while (lookahead != NULL && lookahead != ret_val);
4128 return ret_val;
4132 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4133 of a virtual function may refer to a base class, so we check the 'this'
4134 parameter. */
4136 static tree
4137 decl_class_context (decl)
4138 tree decl;
4140 tree context = NULL_TREE;
4142 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4143 context = DECL_CONTEXT (decl);
4144 else
4145 context = TYPE_MAIN_VARIANT
4146 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4148 if (context && !TYPE_P (context))
4149 context = NULL_TREE;
4151 return context;
4154 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4155 addition order, and correct that in reverse_all_dies. */
4157 static inline void
4158 add_dwarf_attr (die, attr)
4159 register dw_die_ref die;
4160 register dw_attr_ref attr;
4162 if (die != NULL && attr != NULL)
4164 attr->dw_attr_next = die->die_attr;
4165 die->die_attr = attr;
4169 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4170 static inline dw_val_class
4171 AT_class (a)
4172 dw_attr_ref a;
4174 return a->dw_attr_val.val_class;
4177 /* Add a flag value attribute to a DIE. */
4179 static inline void
4180 add_AT_flag (die, attr_kind, flag)
4181 register dw_die_ref die;
4182 register enum dwarf_attribute attr_kind;
4183 register unsigned flag;
4185 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4187 attr->dw_attr_next = NULL;
4188 attr->dw_attr = attr_kind;
4189 attr->dw_attr_val.val_class = dw_val_class_flag;
4190 attr->dw_attr_val.v.val_flag = flag;
4191 add_dwarf_attr (die, attr);
4194 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4195 static inline unsigned
4196 AT_flag (a)
4197 register dw_attr_ref a;
4199 if (a && AT_class (a) == dw_val_class_flag)
4200 return a->dw_attr_val.v.val_flag;
4202 abort ();
4205 /* Add a signed integer attribute value to a DIE. */
4207 static inline void
4208 add_AT_int (die, attr_kind, int_val)
4209 register dw_die_ref die;
4210 register enum dwarf_attribute attr_kind;
4211 register long int int_val;
4213 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4215 attr->dw_attr_next = NULL;
4216 attr->dw_attr = attr_kind;
4217 attr->dw_attr_val.val_class = dw_val_class_const;
4218 attr->dw_attr_val.v.val_int = int_val;
4219 add_dwarf_attr (die, attr);
4222 static inline long int AT_int PARAMS ((dw_attr_ref));
4223 static inline long int
4224 AT_int (a)
4225 register dw_attr_ref a;
4227 if (a && AT_class (a) == dw_val_class_const)
4228 return a->dw_attr_val.v.val_int;
4230 abort ();
4233 /* Add an unsigned integer attribute value to a DIE. */
4235 static inline void
4236 add_AT_unsigned (die, attr_kind, unsigned_val)
4237 register dw_die_ref die;
4238 register enum dwarf_attribute attr_kind;
4239 register unsigned long unsigned_val;
4241 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4243 attr->dw_attr_next = NULL;
4244 attr->dw_attr = attr_kind;
4245 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4246 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4247 add_dwarf_attr (die, attr);
4250 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4251 static inline unsigned long
4252 AT_unsigned (a)
4253 register dw_attr_ref a;
4255 if (a && AT_class (a) == dw_val_class_unsigned_const)
4256 return a->dw_attr_val.v.val_unsigned;
4258 abort ();
4261 /* Add an unsigned double integer attribute value to a DIE. */
4263 static inline void
4264 add_AT_long_long (die, attr_kind, val_hi, val_low)
4265 register dw_die_ref die;
4266 register enum dwarf_attribute attr_kind;
4267 register unsigned long val_hi;
4268 register unsigned long val_low;
4270 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4272 attr->dw_attr_next = NULL;
4273 attr->dw_attr = attr_kind;
4274 attr->dw_attr_val.val_class = dw_val_class_long_long;
4275 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4276 attr->dw_attr_val.v.val_long_long.low = val_low;
4277 add_dwarf_attr (die, attr);
4280 /* Add a floating point attribute value to a DIE and return it. */
4282 static inline void
4283 add_AT_float (die, attr_kind, length, array)
4284 register dw_die_ref die;
4285 register enum dwarf_attribute attr_kind;
4286 register unsigned length;
4287 register long *array;
4289 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4291 attr->dw_attr_next = NULL;
4292 attr->dw_attr = attr_kind;
4293 attr->dw_attr_val.val_class = dw_val_class_float;
4294 attr->dw_attr_val.v.val_float.length = length;
4295 attr->dw_attr_val.v.val_float.array = array;
4296 add_dwarf_attr (die, attr);
4299 /* Add a string attribute value to a DIE. */
4301 static inline void
4302 add_AT_string (die, attr_kind, str)
4303 register dw_die_ref die;
4304 register enum dwarf_attribute attr_kind;
4305 register const char *str;
4307 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4309 attr->dw_attr_next = NULL;
4310 attr->dw_attr = attr_kind;
4311 attr->dw_attr_val.val_class = dw_val_class_str;
4312 attr->dw_attr_val.v.val_str = xstrdup (str);
4313 add_dwarf_attr (die, attr);
4316 static inline const char *AT_string PARAMS ((dw_attr_ref));
4317 static inline const char *
4318 AT_string (a)
4319 register dw_attr_ref a;
4321 if (a && AT_class (a) == dw_val_class_str)
4322 return a->dw_attr_val.v.val_str;
4324 abort ();
4327 /* Add a DIE reference attribute value to a DIE. */
4329 static inline void
4330 add_AT_die_ref (die, attr_kind, targ_die)
4331 register dw_die_ref die;
4332 register enum dwarf_attribute attr_kind;
4333 register dw_die_ref targ_die;
4335 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4337 attr->dw_attr_next = NULL;
4338 attr->dw_attr = attr_kind;
4339 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4340 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4341 attr->dw_attr_val.v.val_die_ref.external = 0;
4342 add_dwarf_attr (die, attr);
4345 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4346 static inline dw_die_ref
4347 AT_ref (a)
4348 register dw_attr_ref a;
4350 if (a && AT_class (a) == dw_val_class_die_ref)
4351 return a->dw_attr_val.v.val_die_ref.die;
4353 abort ();
4356 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4357 static inline int
4358 AT_ref_external (a)
4359 register dw_attr_ref a;
4361 if (a && AT_class (a) == dw_val_class_die_ref)
4362 return a->dw_attr_val.v.val_die_ref.external;
4364 return 0;
4367 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4368 static inline void
4369 set_AT_ref_external (a, i)
4370 register dw_attr_ref a;
4371 int i;
4373 if (a && AT_class (a) == dw_val_class_die_ref)
4374 a->dw_attr_val.v.val_die_ref.external = i;
4375 else
4376 abort ();
4379 /* Add an FDE reference attribute value to a DIE. */
4381 static inline void
4382 add_AT_fde_ref (die, attr_kind, targ_fde)
4383 register dw_die_ref die;
4384 register enum dwarf_attribute attr_kind;
4385 register unsigned targ_fde;
4387 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4389 attr->dw_attr_next = NULL;
4390 attr->dw_attr = attr_kind;
4391 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4392 attr->dw_attr_val.v.val_fde_index = targ_fde;
4393 add_dwarf_attr (die, attr);
4396 /* Add a location description attribute value to a DIE. */
4398 static inline void
4399 add_AT_loc (die, attr_kind, loc)
4400 register dw_die_ref die;
4401 register enum dwarf_attribute attr_kind;
4402 register dw_loc_descr_ref loc;
4404 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4406 attr->dw_attr_next = NULL;
4407 attr->dw_attr = attr_kind;
4408 attr->dw_attr_val.val_class = dw_val_class_loc;
4409 attr->dw_attr_val.v.val_loc = loc;
4410 add_dwarf_attr (die, attr);
4413 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4414 static inline dw_loc_descr_ref
4415 AT_loc (a)
4416 register dw_attr_ref a;
4418 if (a && AT_class (a) == dw_val_class_loc)
4419 return a->dw_attr_val.v.val_loc;
4421 abort ();
4424 /* Add an address constant attribute value to a DIE. */
4426 static inline void
4427 add_AT_addr (die, attr_kind, addr)
4428 register dw_die_ref die;
4429 register enum dwarf_attribute attr_kind;
4430 rtx addr;
4432 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4434 attr->dw_attr_next = NULL;
4435 attr->dw_attr = attr_kind;
4436 attr->dw_attr_val.val_class = dw_val_class_addr;
4437 attr->dw_attr_val.v.val_addr = addr;
4438 add_dwarf_attr (die, attr);
4441 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4442 static inline rtx
4443 AT_addr (a)
4444 register dw_attr_ref a;
4446 if (a && AT_class (a) == dw_val_class_addr)
4447 return a->dw_attr_val.v.val_addr;
4449 abort ();
4452 /* Add a label identifier attribute value to a DIE. */
4454 static inline void
4455 add_AT_lbl_id (die, attr_kind, lbl_id)
4456 register dw_die_ref die;
4457 register enum dwarf_attribute attr_kind;
4458 register const char *lbl_id;
4460 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4462 attr->dw_attr_next = NULL;
4463 attr->dw_attr = attr_kind;
4464 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4465 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4466 add_dwarf_attr (die, attr);
4469 /* Add a section offset attribute value to a DIE. */
4471 static inline void
4472 add_AT_lbl_offset (die, attr_kind, label)
4473 register dw_die_ref die;
4474 register enum dwarf_attribute attr_kind;
4475 register const char *label;
4477 register 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_lbl_offset;
4482 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4483 add_dwarf_attr (die, attr);
4486 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4487 static inline const char *
4488 AT_lbl (a)
4489 register dw_attr_ref a;
4491 if (a && (AT_class (a) == dw_val_class_lbl_id
4492 || AT_class (a) == dw_val_class_lbl_offset))
4493 return a->dw_attr_val.v.val_lbl_id;
4495 abort ();
4498 /* Get the attribute of type attr_kind. */
4500 static inline dw_attr_ref
4501 get_AT (die, attr_kind)
4502 register dw_die_ref die;
4503 register enum dwarf_attribute attr_kind;
4505 register dw_attr_ref a;
4506 register dw_die_ref spec = NULL;
4508 if (die != NULL)
4510 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4512 if (a->dw_attr == attr_kind)
4513 return a;
4515 if (a->dw_attr == DW_AT_specification
4516 || a->dw_attr == DW_AT_abstract_origin)
4517 spec = AT_ref (a);
4520 if (spec)
4521 return get_AT (spec, attr_kind);
4524 return NULL;
4527 /* Return the "low pc" attribute value, typically associated with
4528 a subprogram DIE. Return null if the "low pc" attribute is
4529 either not prsent, or if it cannot be represented as an
4530 assembler label identifier. */
4532 static inline const char *
4533 get_AT_low_pc (die)
4534 register dw_die_ref die;
4536 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4537 return a ? AT_lbl (a) : NULL;
4540 /* Return the "high pc" attribute value, typically associated with
4541 a subprogram DIE. Return null if the "high pc" attribute is
4542 either not prsent, or if it cannot be represented as an
4543 assembler label identifier. */
4545 static inline const char *
4546 get_AT_hi_pc (die)
4547 register dw_die_ref die;
4549 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4550 return a ? AT_lbl (a) : NULL;
4553 /* Return the value of the string attribute designated by ATTR_KIND, or
4554 NULL if it is not present. */
4556 static inline const char *
4557 get_AT_string (die, attr_kind)
4558 register dw_die_ref die;
4559 register enum dwarf_attribute attr_kind;
4561 register dw_attr_ref a = get_AT (die, attr_kind);
4562 return a ? AT_string (a) : NULL;
4565 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4566 if it is not present. */
4568 static inline int
4569 get_AT_flag (die, attr_kind)
4570 register dw_die_ref die;
4571 register enum dwarf_attribute attr_kind;
4573 register dw_attr_ref a = get_AT (die, attr_kind);
4574 return a ? AT_flag (a) : 0;
4577 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4578 if it is not present. */
4580 static inline unsigned
4581 get_AT_unsigned (die, attr_kind)
4582 register dw_die_ref die;
4583 register enum dwarf_attribute attr_kind;
4585 register dw_attr_ref a = get_AT (die, attr_kind);
4586 return a ? AT_unsigned (a) : 0;
4589 static inline dw_die_ref
4590 get_AT_ref (die, attr_kind)
4591 dw_die_ref die;
4592 register enum dwarf_attribute attr_kind;
4594 register dw_attr_ref a = get_AT (die, attr_kind);
4595 return a ? AT_ref (a) : NULL;
4598 static inline int
4599 is_c_family ()
4601 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4603 return (lang == DW_LANG_C || lang == DW_LANG_C89
4604 || lang == DW_LANG_C_plus_plus);
4607 static inline int
4608 is_fortran ()
4610 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4612 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4615 static inline int
4616 is_java ()
4618 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4620 return (lang == DW_LANG_Java);
4623 /* Free up the memory used by A. */
4625 static inline void free_AT PARAMS ((dw_attr_ref));
4626 static inline void
4627 free_AT (a)
4628 dw_attr_ref a;
4630 switch (AT_class (a))
4632 case dw_val_class_str:
4633 case dw_val_class_lbl_id:
4634 case dw_val_class_lbl_offset:
4635 free (a->dw_attr_val.v.val_str);
4636 break;
4638 case dw_val_class_float:
4639 free (a->dw_attr_val.v.val_float.array);
4640 break;
4642 default:
4643 break;
4646 free (a);
4649 /* Remove the specified attribute if present. */
4651 static void
4652 remove_AT (die, attr_kind)
4653 register dw_die_ref die;
4654 register enum dwarf_attribute attr_kind;
4656 register dw_attr_ref *p;
4657 register dw_attr_ref removed = NULL;
4659 if (die != NULL)
4661 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4662 if ((*p)->dw_attr == attr_kind)
4664 removed = *p;
4665 *p = (*p)->dw_attr_next;
4666 break;
4669 if (removed != 0)
4670 free_AT (removed);
4674 /* Free up the memory used by DIE. */
4676 static inline void free_die PARAMS ((dw_die_ref));
4677 static inline void
4678 free_die (die)
4679 dw_die_ref die;
4681 remove_children (die);
4682 free (die);
4685 /* Discard the children of this DIE. */
4687 static void
4688 remove_children (die)
4689 register dw_die_ref die;
4691 register dw_die_ref child_die = die->die_child;
4693 die->die_child = NULL;
4695 while (child_die != NULL)
4697 register dw_die_ref tmp_die = child_die;
4698 register dw_attr_ref a;
4700 child_die = child_die->die_sib;
4702 for (a = tmp_die->die_attr; a != NULL;)
4704 register dw_attr_ref tmp_a = a;
4706 a = a->dw_attr_next;
4707 free_AT (tmp_a);
4710 free_die (tmp_die);
4714 /* Add a child DIE below its parent. We build the lists up in reverse
4715 addition order, and correct that in reverse_all_dies. */
4717 static inline void
4718 add_child_die (die, child_die)
4719 register dw_die_ref die;
4720 register dw_die_ref child_die;
4722 if (die != NULL && child_die != NULL)
4724 if (die == child_die)
4725 abort ();
4726 child_die->die_parent = die;
4727 child_die->die_sib = die->die_child;
4728 die->die_child = child_die;
4732 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4733 is the specification, to the front of PARENT's list of children. */
4735 static void
4736 splice_child_die (parent, child)
4737 dw_die_ref parent, child;
4739 dw_die_ref *p;
4741 /* We want the declaration DIE from inside the class, not the
4742 specification DIE at toplevel. */
4743 if (child->die_parent != parent)
4745 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4746 if (tmp)
4747 child = tmp;
4750 if (child->die_parent != parent
4751 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4752 abort ();
4754 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4755 if (*p == child)
4757 *p = child->die_sib;
4758 break;
4761 child->die_sib = parent->die_child;
4762 parent->die_child = child;
4765 /* Return a pointer to a newly created DIE node. */
4767 static inline dw_die_ref
4768 new_die (tag_value, parent_die)
4769 register enum dwarf_tag tag_value;
4770 register dw_die_ref parent_die;
4772 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4774 die->die_tag = tag_value;
4776 if (parent_die != NULL)
4777 add_child_die (parent_die, die);
4778 else
4780 limbo_die_node *limbo_node;
4782 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4783 limbo_node->die = die;
4784 limbo_node->next = limbo_die_list;
4785 limbo_die_list = limbo_node;
4788 return die;
4791 /* Return the DIE associated with the given type specifier. */
4793 static inline dw_die_ref
4794 lookup_type_die (type)
4795 register tree type;
4797 if (TREE_CODE (type) == VECTOR_TYPE)
4798 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4799 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4802 /* Equate a DIE to a given type specifier. */
4804 static inline void
4805 equate_type_number_to_die (type, type_die)
4806 register tree type;
4807 register dw_die_ref type_die;
4809 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4812 /* Return the DIE associated with a given declaration. */
4814 static inline dw_die_ref
4815 lookup_decl_die (decl)
4816 register tree decl;
4818 register unsigned decl_id = DECL_UID (decl);
4820 return (decl_id < decl_die_table_in_use
4821 ? decl_die_table[decl_id] : NULL);
4824 /* Equate a DIE to a particular declaration. */
4826 static void
4827 equate_decl_number_to_die (decl, decl_die)
4828 register tree decl;
4829 register dw_die_ref decl_die;
4831 register unsigned decl_id = DECL_UID (decl);
4832 register unsigned num_allocated;
4834 if (decl_id >= decl_die_table_allocated)
4836 num_allocated
4837 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4838 / DECL_DIE_TABLE_INCREMENT)
4839 * DECL_DIE_TABLE_INCREMENT;
4841 decl_die_table
4842 = (dw_die_ref *) xrealloc (decl_die_table,
4843 sizeof (dw_die_ref) * num_allocated);
4845 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4846 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4847 decl_die_table_allocated = num_allocated;
4850 if (decl_id >= decl_die_table_in_use)
4851 decl_die_table_in_use = (decl_id + 1);
4853 decl_die_table[decl_id] = decl_die;
4856 /* Keep track of the number of spaces used to indent the
4857 output of the debugging routines that print the structure of
4858 the DIE internal representation. */
4859 static int print_indent;
4861 /* Indent the line the number of spaces given by print_indent. */
4863 static inline void
4864 print_spaces (outfile)
4865 FILE *outfile;
4867 fprintf (outfile, "%*s", print_indent, "");
4870 /* Print the information associated with a given DIE, and its children.
4871 This routine is a debugging aid only. */
4873 static void
4874 print_die (die, outfile)
4875 dw_die_ref die;
4876 FILE *outfile;
4878 register dw_attr_ref a;
4879 register dw_die_ref c;
4881 print_spaces (outfile);
4882 fprintf (outfile, "DIE %4lu: %s\n",
4883 die->die_offset, dwarf_tag_name (die->die_tag));
4884 print_spaces (outfile);
4885 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4886 fprintf (outfile, " offset: %lu\n", die->die_offset);
4888 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4890 print_spaces (outfile);
4891 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4893 switch (AT_class (a))
4895 case dw_val_class_addr:
4896 fprintf (outfile, "address");
4897 break;
4898 case dw_val_class_loc:
4899 fprintf (outfile, "location descriptor");
4900 break;
4901 case dw_val_class_const:
4902 fprintf (outfile, "%ld", AT_int (a));
4903 break;
4904 case dw_val_class_unsigned_const:
4905 fprintf (outfile, "%lu", AT_unsigned (a));
4906 break;
4907 case dw_val_class_long_long:
4908 fprintf (outfile, "constant (%lu,%lu)",
4909 a->dw_attr_val.v.val_long_long.hi,
4910 a->dw_attr_val.v.val_long_long.low);
4911 break;
4912 case dw_val_class_float:
4913 fprintf (outfile, "floating-point constant");
4914 break;
4915 case dw_val_class_flag:
4916 fprintf (outfile, "%u", AT_flag (a));
4917 break;
4918 case dw_val_class_die_ref:
4919 if (AT_ref (a) != NULL)
4921 if (AT_ref (a)->die_symbol)
4922 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
4923 else
4924 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4926 else
4927 fprintf (outfile, "die -> <null>");
4928 break;
4929 case dw_val_class_lbl_id:
4930 case dw_val_class_lbl_offset:
4931 fprintf (outfile, "label: %s", AT_lbl (a));
4932 break;
4933 case dw_val_class_str:
4934 if (AT_string (a) != NULL)
4935 fprintf (outfile, "\"%s\"", AT_string (a));
4936 else
4937 fprintf (outfile, "<null>");
4938 break;
4939 default:
4940 break;
4943 fprintf (outfile, "\n");
4946 if (die->die_child != NULL)
4948 print_indent += 4;
4949 for (c = die->die_child; c != NULL; c = c->die_sib)
4950 print_die (c, outfile);
4952 print_indent -= 4;
4954 if (print_indent == 0)
4955 fprintf (outfile, "\n");
4958 /* Print the contents of the source code line number correspondence table.
4959 This routine is a debugging aid only. */
4961 static void
4962 print_dwarf_line_table (outfile)
4963 FILE *outfile;
4965 register unsigned i;
4966 register dw_line_info_ref line_info;
4968 fprintf (outfile, "\n\nDWARF source line information\n");
4969 for (i = 1; i < line_info_table_in_use; ++i)
4971 line_info = &line_info_table[i];
4972 fprintf (outfile, "%5d: ", i);
4973 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
4974 fprintf (outfile, "%6ld", line_info->dw_line_num);
4975 fprintf (outfile, "\n");
4978 fprintf (outfile, "\n\n");
4981 /* Print the information collected for a given DIE. */
4983 void
4984 debug_dwarf_die (die)
4985 dw_die_ref die;
4987 print_die (die, stderr);
4990 /* Print all DWARF information collected for the compilation unit.
4991 This routine is a debugging aid only. */
4993 void
4994 debug_dwarf ()
4996 print_indent = 0;
4997 print_die (comp_unit_die, stderr);
4998 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4999 print_dwarf_line_table (stderr);
5002 /* We build up the lists of children and attributes by pushing new ones
5003 onto the beginning of the list. Reverse the lists for DIE so that
5004 they are in order of addition. */
5006 static void
5007 reverse_die_lists (die)
5008 register dw_die_ref die;
5010 register dw_die_ref c, cp, cn;
5011 register dw_attr_ref a, ap, an;
5013 for (a = die->die_attr, ap = 0; a; a = an)
5015 an = a->dw_attr_next;
5016 a->dw_attr_next = ap;
5017 ap = a;
5019 die->die_attr = ap;
5021 for (c = die->die_child, cp = 0; c; c = cn)
5023 cn = c->die_sib;
5024 c->die_sib = cp;
5025 cp = c;
5027 die->die_child = cp;
5030 /* reverse_die_lists only reverses the single die you pass it. Since
5031 we used to reverse all dies in add_sibling_attributes, which runs
5032 through all the dies, it would reverse all the dies. Now, however,
5033 since we don't call reverse_die_lists in add_sibling_attributes, we
5034 need a routine to recursively reverse all the dies. This is that
5035 routine. */
5037 static void
5038 reverse_all_dies (die)
5039 register dw_die_ref die;
5041 register dw_die_ref c;
5043 reverse_die_lists (die);
5045 for (c = die->die_child; c; c = c->die_sib)
5046 reverse_all_dies (c);
5049 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5050 the CU for the enclosing include file, if any. BINCL_DIE is the
5051 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5052 include file. */
5054 static dw_die_ref
5055 push_new_compile_unit (old_unit, bincl_die)
5056 dw_die_ref old_unit, bincl_die;
5058 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5059 dw_die_ref new_unit = gen_compile_unit_die (filename);
5060 new_unit->die_sib = old_unit;
5061 return new_unit;
5064 /* Close an include-file CU and reopen the enclosing one. */
5066 static dw_die_ref
5067 pop_compile_unit (old_unit)
5068 dw_die_ref old_unit;
5070 dw_die_ref new_unit = old_unit->die_sib;
5071 old_unit->die_sib = NULL;
5072 return new_unit;
5075 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5076 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5078 /* Calculate the checksum of a location expression. */
5080 static inline void
5081 loc_checksum (loc, ctx)
5082 dw_loc_descr_ref loc;
5083 struct md5_ctx *ctx;
5085 PROCESS (loc->dw_loc_opc);
5086 PROCESS (loc->dw_loc_oprnd1);
5087 PROCESS (loc->dw_loc_oprnd2);
5090 /* Calculate the checksum of an attribute. */
5092 static void
5093 attr_checksum (at, ctx)
5094 dw_attr_ref at;
5095 struct md5_ctx *ctx;
5097 dw_loc_descr_ref loc;
5098 rtx r;
5100 PROCESS (at->dw_attr);
5102 /* We don't care about differences in file numbering. */
5103 if (at->dw_attr == DW_AT_decl_file
5104 /* Or that this was compiled with a different compiler snapshot; if
5105 the output is the same, that's what matters. */
5106 || at->dw_attr == DW_AT_producer)
5107 return;
5109 switch (AT_class (at))
5111 case dw_val_class_const:
5112 PROCESS (at->dw_attr_val.v.val_int);
5113 break;
5114 case dw_val_class_unsigned_const:
5115 PROCESS (at->dw_attr_val.v.val_unsigned);
5116 break;
5117 case dw_val_class_long_long:
5118 PROCESS (at->dw_attr_val.v.val_long_long);
5119 break;
5120 case dw_val_class_float:
5121 PROCESS (at->dw_attr_val.v.val_float);
5122 break;
5123 case dw_val_class_flag:
5124 PROCESS (at->dw_attr_val.v.val_flag);
5125 break;
5127 case dw_val_class_str:
5128 PROCESS_STRING (AT_string (at));
5129 break;
5130 case dw_val_class_addr:
5131 r = AT_addr (at);
5132 switch (GET_CODE (r))
5134 case SYMBOL_REF:
5135 PROCESS_STRING (XSTR (r, 0));
5136 break;
5138 default:
5139 abort ();
5141 break;
5143 case dw_val_class_loc:
5144 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5145 loc_checksum (loc, ctx);
5146 break;
5148 case dw_val_class_die_ref:
5149 if (AT_ref (at)->die_offset)
5150 PROCESS (AT_ref (at)->die_offset);
5151 /* FIXME else use target die name or something. */
5153 case dw_val_class_fde_ref:
5154 case dw_val_class_lbl_id:
5155 case dw_val_class_lbl_offset:
5157 default:
5158 break;
5162 /* Calculate the checksum of a DIE. */
5164 static void
5165 die_checksum (die, ctx)
5166 dw_die_ref die;
5167 struct md5_ctx *ctx;
5169 dw_die_ref c;
5170 dw_attr_ref a;
5172 PROCESS (die->die_tag);
5174 for (a = die->die_attr; a; a = a->dw_attr_next)
5175 attr_checksum (a, ctx);
5177 for (c = die->die_child; c; c = c->die_sib)
5178 die_checksum (c, ctx);
5181 #undef PROCESS
5182 #undef PROCESS_STRING
5184 /* The prefix to attach to symbols on DIEs in the current comdat debug
5185 info section. */
5186 static char *comdat_symbol_id;
5188 /* The index of the current symbol within the current comdat CU. */
5189 static unsigned int comdat_symbol_number;
5191 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5192 children, and set comdat_symbol_id accordingly. */
5194 static void
5195 compute_section_prefix (unit_die)
5196 dw_die_ref unit_die;
5198 char *p, *name;
5199 int i;
5200 unsigned char checksum[16];
5201 struct md5_ctx ctx;
5203 md5_init_ctx (&ctx);
5204 die_checksum (unit_die, &ctx);
5205 md5_finish_ctx (&ctx, checksum);
5207 p = lbasename (get_AT_string (unit_die, DW_AT_name));
5208 name = (char *) alloca (strlen (p) + 64);
5209 sprintf (name, "%s.", p);
5211 clean_symbol_name (name);
5213 p = name + strlen (name);
5214 for (i = 0; i < 4; ++i)
5216 sprintf (p, "%.2x", checksum[i]);
5217 p += 2;
5220 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5221 comdat_symbol_number = 0;
5224 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5226 static int
5227 is_type_die (die)
5228 dw_die_ref die;
5230 switch (die->die_tag)
5232 case DW_TAG_array_type:
5233 case DW_TAG_class_type:
5234 case DW_TAG_enumeration_type:
5235 case DW_TAG_pointer_type:
5236 case DW_TAG_reference_type:
5237 case DW_TAG_string_type:
5238 case DW_TAG_structure_type:
5239 case DW_TAG_subroutine_type:
5240 case DW_TAG_union_type:
5241 case DW_TAG_ptr_to_member_type:
5242 case DW_TAG_set_type:
5243 case DW_TAG_subrange_type:
5244 case DW_TAG_base_type:
5245 case DW_TAG_const_type:
5246 case DW_TAG_file_type:
5247 case DW_TAG_packed_type:
5248 case DW_TAG_volatile_type:
5249 return 1;
5250 default:
5251 return 0;
5255 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5256 Basically, we want to choose the bits that are likely to be shared between
5257 compilations (types) and leave out the bits that are specific to individual
5258 compilations (functions). */
5260 static int
5261 is_comdat_die (c)
5262 dw_die_ref c;
5264 #if 1
5265 /* I think we want to leave base types and __vtbl_ptr_type in the
5266 main CU, as we do for stabs. The advantage is a greater
5267 likelihood of sharing between objects that don't include headers
5268 in the same order (and therefore would put the base types in a
5269 different comdat). jason 8/28/00 */
5270 if (c->die_tag == DW_TAG_base_type)
5271 return 0;
5273 if (c->die_tag == DW_TAG_pointer_type
5274 || c->die_tag == DW_TAG_reference_type
5275 || c->die_tag == DW_TAG_const_type
5276 || c->die_tag == DW_TAG_volatile_type)
5278 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5279 return t ? is_comdat_die (t) : 0;
5281 #endif
5283 return is_type_die (c);
5286 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5287 compilation unit. */
5289 static int
5290 is_symbol_die (c)
5291 dw_die_ref c;
5293 if (is_type_die (c))
5294 return 1;
5295 if (get_AT (c, DW_AT_declaration)
5296 && ! get_AT (c, DW_AT_specification))
5297 return 1;
5298 return 0;
5301 static char *
5302 gen_internal_sym ()
5304 char buf[256];
5305 static int label_num;
5306 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5307 return xstrdup (buf);
5310 /* Assign symbols to all worthy DIEs under DIE. */
5312 static void
5313 assign_symbol_names (die)
5314 register dw_die_ref die;
5316 register dw_die_ref c;
5318 if (is_symbol_die (die))
5320 if (comdat_symbol_id)
5322 char *p = alloca (strlen (comdat_symbol_id) + 64);
5323 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5324 comdat_symbol_id, comdat_symbol_number++);
5325 die->die_symbol = xstrdup (p);
5327 else
5328 die->die_symbol = gen_internal_sym ();
5331 for (c = die->die_child; c != NULL; c = c->die_sib)
5332 assign_symbol_names (c);
5335 /* Traverse the DIE (which is always comp_unit_die), and set up
5336 additional compilation units for each of the include files we see
5337 bracketed by BINCL/EINCL. */
5339 static void
5340 break_out_includes (die)
5341 register dw_die_ref die;
5343 dw_die_ref *ptr;
5344 register dw_die_ref unit = NULL;
5345 limbo_die_node *node;
5347 for (ptr = &(die->die_child); *ptr; )
5349 register dw_die_ref c = *ptr;
5351 if (c->die_tag == DW_TAG_GNU_BINCL
5352 || c->die_tag == DW_TAG_GNU_EINCL
5353 || (unit && is_comdat_die (c)))
5355 /* This DIE is for a secondary CU; remove it from the main one. */
5356 *ptr = c->die_sib;
5358 if (c->die_tag == DW_TAG_GNU_BINCL)
5360 unit = push_new_compile_unit (unit, c);
5361 free_die (c);
5363 else if (c->die_tag == DW_TAG_GNU_EINCL)
5365 unit = pop_compile_unit (unit);
5366 free_die (c);
5368 else
5369 add_child_die (unit, c);
5371 else
5373 /* Leave this DIE in the main CU. */
5374 ptr = &(c->die_sib);
5375 continue;
5379 #if 0
5380 /* We can only use this in debugging, since the frontend doesn't check
5381 to make sure that we leave every include file we enter. */
5382 if (unit != NULL)
5383 abort ();
5384 #endif
5386 assign_symbol_names (die);
5387 for (node = limbo_die_list; node; node = node->next)
5389 compute_section_prefix (node->die);
5390 assign_symbol_names (node->die);
5394 /* Traverse the DIE and add a sibling attribute if it may have the
5395 effect of speeding up access to siblings. To save some space,
5396 avoid generating sibling attributes for DIE's without children. */
5398 static void
5399 add_sibling_attributes (die)
5400 register dw_die_ref die;
5402 register dw_die_ref c;
5404 if (die->die_tag != DW_TAG_compile_unit
5405 && die->die_sib && die->die_child != NULL)
5406 /* Add the sibling link to the front of the attribute list. */
5407 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5409 for (c = die->die_child; c != NULL; c = c->die_sib)
5410 add_sibling_attributes (c);
5413 /* The format of each DIE (and its attribute value pairs)
5414 is encoded in an abbreviation table. This routine builds the
5415 abbreviation table and assigns a unique abbreviation id for
5416 each abbreviation entry. The children of each die are visited
5417 recursively. */
5419 static void
5420 build_abbrev_table (die)
5421 register dw_die_ref die;
5423 register unsigned long abbrev_id;
5424 register unsigned long n_alloc;
5425 register dw_die_ref c;
5426 register dw_attr_ref d_attr, a_attr;
5428 /* Scan the DIE references, and mark as external any that refer to
5429 DIEs from other CUs (i.e. those which are not marked). */
5430 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5432 if (AT_class (d_attr) == dw_val_class_die_ref
5433 && AT_ref (d_attr)->die_mark == 0)
5435 if (AT_ref (d_attr)->die_symbol == 0)
5436 abort ();
5437 set_AT_ref_external (d_attr, 1);
5441 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5443 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5445 if (abbrev->die_tag == die->die_tag)
5447 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5449 a_attr = abbrev->die_attr;
5450 d_attr = die->die_attr;
5452 while (a_attr != NULL && d_attr != NULL)
5454 if ((a_attr->dw_attr != d_attr->dw_attr)
5455 || (value_format (a_attr) != value_format (d_attr)))
5456 break;
5458 a_attr = a_attr->dw_attr_next;
5459 d_attr = d_attr->dw_attr_next;
5462 if (a_attr == NULL && d_attr == NULL)
5463 break;
5468 if (abbrev_id >= abbrev_die_table_in_use)
5470 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5472 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5473 abbrev_die_table
5474 = (dw_die_ref *) xrealloc (abbrev_die_table,
5475 sizeof (dw_die_ref) * n_alloc);
5477 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5478 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5479 abbrev_die_table_allocated = n_alloc;
5482 ++abbrev_die_table_in_use;
5483 abbrev_die_table[abbrev_id] = die;
5486 die->die_abbrev = abbrev_id;
5487 for (c = die->die_child; c != NULL; c = c->die_sib)
5488 build_abbrev_table (c);
5491 /* Return the size of a string, including the null byte.
5493 This used to treat backslashes as escapes, and hence they were not included
5494 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5495 which treats a backslash as a backslash, escaping it if necessary, and hence
5496 we must include them in the count. */
5498 static unsigned long
5499 size_of_string (str)
5500 register const char *str;
5502 return strlen (str) + 1;
5505 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5507 static int
5508 constant_size (value)
5509 long unsigned value;
5511 int log;
5513 if (value == 0)
5514 log = 0;
5515 else
5516 log = floor_log2 (value);
5518 log = log / 8;
5519 log = 1 << (floor_log2 (log) + 1);
5521 return log;
5524 /* Return the size of a DIE, as it is represented in the
5525 .debug_info section. */
5527 static unsigned long
5528 size_of_die (die)
5529 register dw_die_ref die;
5531 register unsigned long size = 0;
5532 register dw_attr_ref a;
5534 size += size_of_uleb128 (die->die_abbrev);
5535 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5537 switch (AT_class (a))
5539 case dw_val_class_addr:
5540 size += DWARF2_ADDR_SIZE;
5541 break;
5542 case dw_val_class_loc:
5544 register unsigned long lsize = size_of_locs (AT_loc (a));
5546 /* Block length. */
5547 size += constant_size (lsize);
5548 size += lsize;
5550 break;
5551 case dw_val_class_const:
5552 size += size_of_sleb128 (AT_int (a));
5553 break;
5554 case dw_val_class_unsigned_const:
5555 size += constant_size (AT_unsigned (a));
5556 break;
5557 case dw_val_class_long_long:
5558 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5559 break;
5560 case dw_val_class_float:
5561 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5562 break;
5563 case dw_val_class_flag:
5564 size += 1;
5565 break;
5566 case dw_val_class_die_ref:
5567 size += DWARF_OFFSET_SIZE;
5568 break;
5569 case dw_val_class_fde_ref:
5570 size += DWARF_OFFSET_SIZE;
5571 break;
5572 case dw_val_class_lbl_id:
5573 size += DWARF2_ADDR_SIZE;
5574 break;
5575 case dw_val_class_lbl_offset:
5576 size += DWARF_OFFSET_SIZE;
5577 break;
5578 case dw_val_class_str:
5579 size += size_of_string (AT_string (a));
5580 break;
5581 default:
5582 abort ();
5586 return size;
5589 /* Size the debugging information associated with a given DIE.
5590 Visits the DIE's children recursively. Updates the global
5591 variable next_die_offset, on each time through. Uses the
5592 current value of next_die_offset to update the die_offset
5593 field in each DIE. */
5595 static void
5596 calc_die_sizes (die)
5597 dw_die_ref die;
5599 register dw_die_ref c;
5600 die->die_offset = next_die_offset;
5601 next_die_offset += size_of_die (die);
5603 for (c = die->die_child; c != NULL; c = c->die_sib)
5604 calc_die_sizes (c);
5606 if (die->die_child != NULL)
5607 /* Count the null byte used to terminate sibling lists. */
5608 next_die_offset += 1;
5611 /* Set the marks for a die and its children. We do this so
5612 that we know whether or not a reference needs to use FORM_ref_addr; only
5613 DIEs in the same CU will be marked. We used to clear out the offset
5614 and use that as the flag, but ran into ordering problems. */
5616 static void
5617 mark_dies (die)
5618 dw_die_ref die;
5620 register dw_die_ref c;
5621 die->die_mark = 1;
5622 for (c = die->die_child; c; c = c->die_sib)
5623 mark_dies (c);
5626 /* Clear the marks for a die and its children. */
5628 static void
5629 unmark_dies (die)
5630 dw_die_ref die;
5632 register dw_die_ref c;
5633 die->die_mark = 0;
5634 for (c = die->die_child; c; c = c->die_sib)
5635 unmark_dies (c);
5638 /* Return the size of the .debug_pubnames table generated for the
5639 compilation unit. */
5641 static unsigned long
5642 size_of_pubnames ()
5644 register unsigned long size;
5645 register unsigned i;
5647 size = DWARF_PUBNAMES_HEADER_SIZE;
5648 for (i = 0; i < pubname_table_in_use; ++i)
5650 register pubname_ref p = &pubname_table[i];
5651 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5654 size += DWARF_OFFSET_SIZE;
5655 return size;
5658 /* Return the size of the information in the .debug_aranges section. */
5660 static unsigned long
5661 size_of_aranges ()
5663 register unsigned long size;
5665 size = DWARF_ARANGES_HEADER_SIZE;
5667 /* Count the address/length pair for this compilation unit. */
5668 size += 2 * DWARF2_ADDR_SIZE;
5669 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5671 /* Count the two zero words used to terminated the address range table. */
5672 size += 2 * DWARF2_ADDR_SIZE;
5673 return size;
5676 /* Select the encoding of an attribute value. */
5678 static enum dwarf_form
5679 value_format (a)
5680 dw_attr_ref a;
5682 switch (a->dw_attr_val.val_class)
5684 case dw_val_class_addr:
5685 return DW_FORM_addr;
5686 case dw_val_class_loc:
5687 switch (constant_size (size_of_locs (AT_loc (a))))
5689 case 1:
5690 return DW_FORM_block1;
5691 case 2:
5692 return DW_FORM_block2;
5693 default:
5694 abort ();
5696 case dw_val_class_const:
5697 return DW_FORM_sdata;
5698 case dw_val_class_unsigned_const:
5699 switch (constant_size (AT_unsigned (a)))
5701 case 1:
5702 return DW_FORM_data1;
5703 case 2:
5704 return DW_FORM_data2;
5705 case 4:
5706 return DW_FORM_data4;
5707 case 8:
5708 return DW_FORM_data8;
5709 default:
5710 abort ();
5712 case dw_val_class_long_long:
5713 return DW_FORM_block1;
5714 case dw_val_class_float:
5715 return DW_FORM_block1;
5716 case dw_val_class_flag:
5717 return DW_FORM_flag;
5718 case dw_val_class_die_ref:
5719 if (AT_ref_external (a))
5720 return DW_FORM_ref_addr;
5721 else
5722 return DW_FORM_ref;
5723 case dw_val_class_fde_ref:
5724 return DW_FORM_data;
5725 case dw_val_class_lbl_id:
5726 return DW_FORM_addr;
5727 case dw_val_class_lbl_offset:
5728 return DW_FORM_data;
5729 case dw_val_class_str:
5730 return DW_FORM_string;
5731 default:
5732 abort ();
5736 /* Output the encoding of an attribute value. */
5738 static void
5739 output_value_format (a)
5740 dw_attr_ref a;
5742 enum dwarf_form form = value_format (a);
5743 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
5746 /* Output the .debug_abbrev section which defines the DIE abbreviation
5747 table. */
5749 static void
5750 output_abbrev_section ()
5752 unsigned long abbrev_id;
5754 dw_attr_ref a_attr;
5755 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5757 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5759 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
5761 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
5762 dwarf_tag_name (abbrev->die_tag));
5764 if (abbrev->die_child != NULL)
5765 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
5766 else
5767 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
5769 for (a_attr = abbrev->die_attr; a_attr != NULL;
5770 a_attr = a_attr->dw_attr_next)
5772 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
5773 dwarf_attr_name (a_attr->dw_attr));
5774 output_value_format (a_attr);
5777 dw2_asm_output_data (1, 0, NULL);
5778 dw2_asm_output_data (1, 0, NULL);
5781 /* Terminate the table. */
5782 dw2_asm_output_data (1, 0, NULL);
5785 /* Output a symbol we can use to refer to this DIE from another CU. */
5787 static inline void
5788 output_die_symbol (die)
5789 register dw_die_ref die;
5791 char *sym = die->die_symbol;
5793 if (sym == 0)
5794 return;
5796 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5797 /* We make these global, not weak; if the target doesn't support
5798 .linkonce, it doesn't support combining the sections, so debugging
5799 will break. */
5800 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5801 ASM_OUTPUT_LABEL (asm_out_file, sym);
5804 /* Output the DIE and its attributes. Called recursively to generate
5805 the definitions of each child DIE. */
5807 static void
5808 output_die (die)
5809 register dw_die_ref die;
5811 register dw_attr_ref a;
5812 register dw_die_ref c;
5813 register unsigned long size;
5815 /* If someone in another CU might refer to us, set up a symbol for
5816 them to point to. */
5817 if (die->die_symbol)
5818 output_die_symbol (die);
5820 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
5821 die->die_offset, dwarf_tag_name (die->die_tag));
5823 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5825 const char *name = dwarf_attr_name (a->dw_attr);
5827 switch (AT_class (a))
5829 case dw_val_class_addr:
5830 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
5831 break;
5833 case dw_val_class_loc:
5834 size = size_of_locs (AT_loc (a));
5836 /* Output the block length for this list of location operations. */
5837 dw2_asm_output_data (constant_size (size), size, "%s", name);
5839 output_loc_sequence (AT_loc (a));
5840 break;
5842 case dw_val_class_const:
5843 /* ??? It would be slightly more efficient to use a scheme like is
5844 used for unsigned constants below, but gdb 4.x does not sign
5845 extend. Gdb 5.x does sign extend. */
5846 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
5847 break;
5849 case dw_val_class_unsigned_const:
5850 dw2_asm_output_data (constant_size (AT_unsigned (a)),
5851 AT_unsigned (a), "%s", name);
5852 break;
5854 case dw_val_class_long_long:
5856 unsigned HOST_WIDE_INT first, second;
5858 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5859 "%s", name);
5861 if (WORDS_BIG_ENDIAN)
5863 first = a->dw_attr_val.v.val_long_long.hi;
5864 second = a->dw_attr_val.v.val_long_long.low;
5866 else
5868 first = a->dw_attr_val.v.val_long_long.low;
5869 second = a->dw_attr_val.v.val_long_long.hi;
5871 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5872 first, "long long constant");
5873 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5874 second, NULL);
5876 break;
5878 case dw_val_class_float:
5880 register unsigned int i;
5882 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
5883 "%s", name);
5885 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5886 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
5887 "fp constant word %u", i);
5888 break;
5891 case dw_val_class_flag:
5892 dw2_asm_output_data (1, AT_flag (a), "%s", name);
5893 break;
5895 case dw_val_class_die_ref:
5896 if (AT_ref_external (a))
5898 char *sym = AT_ref (a)->die_symbol;
5899 if (sym == 0)
5900 abort ();
5901 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
5903 else if (AT_ref (a)->die_offset == 0)
5904 abort ();
5905 else
5906 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
5907 "%s", name);
5908 break;
5910 case dw_val_class_fde_ref:
5912 char l1[20];
5913 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
5914 a->dw_attr_val.v.val_fde_index * 2);
5915 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
5917 break;
5919 case dw_val_class_lbl_id:
5920 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
5921 break;
5923 case dw_val_class_lbl_offset:
5924 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
5925 break;
5927 case dw_val_class_str:
5928 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
5929 break;
5931 default:
5932 abort ();
5936 for (c = die->die_child; c != NULL; c = c->die_sib)
5937 output_die (c);
5939 if (die->die_child != NULL)
5941 /* Add null byte to terminate sibling list. */
5942 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
5943 die->die_offset);
5947 /* Output the compilation unit that appears at the beginning of the
5948 .debug_info section, and precedes the DIE descriptions. */
5950 static void
5951 output_compilation_unit_header ()
5953 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
5954 "Length of Compilation Unit Info");
5956 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
5958 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
5959 "Offset Into Abbrev. Section");
5961 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
5964 /* Output the compilation unit DIE and its children. */
5966 static void
5967 output_comp_unit (die)
5968 dw_die_ref die;
5970 const char *secname;
5972 /* Even if there are no children of this DIE, we must output the
5973 information about the compilation unit. Otherwise, on an empty
5974 translation unit, we will generate a present, but empty,
5975 .debug_info section. IRIX 6.5 `nm' will then complain when
5976 examining the file.
5978 Mark all the DIEs in this CU so we know which get local refs. */
5979 mark_dies (die);
5981 build_abbrev_table (die);
5983 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
5984 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
5985 calc_die_sizes (die);
5987 if (die->die_symbol)
5989 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
5990 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
5991 secname = tmp;
5992 die->die_symbol = NULL;
5994 else
5995 secname = (const char *) DEBUG_INFO_SECTION;
5997 /* Output debugging information. */
5998 ASM_OUTPUT_SECTION (asm_out_file, secname);
5999 output_compilation_unit_header ();
6000 output_die (die);
6002 /* Leave the marks on the main CU, so we can check them in
6003 output_pubnames. */
6004 if (die->die_symbol)
6005 unmark_dies (die);
6008 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6009 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6010 argument list, and maybe the scope. */
6012 static const char *
6013 dwarf2_name (decl, scope)
6014 tree decl;
6015 int scope;
6017 return (*decl_printable_name) (decl, scope ? 1 : 0);
6020 /* Add a new entry to .debug_pubnames if appropriate. */
6022 static void
6023 add_pubname (decl, die)
6024 tree decl;
6025 dw_die_ref die;
6027 pubname_ref p;
6029 if (! TREE_PUBLIC (decl))
6030 return;
6032 if (pubname_table_in_use == pubname_table_allocated)
6034 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6035 pubname_table = (pubname_ref) xrealloc
6036 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6039 p = &pubname_table[pubname_table_in_use++];
6040 p->die = die;
6042 p->name = xstrdup (dwarf2_name (decl, 1));
6045 /* Output the public names table used to speed up access to externally
6046 visible names. For now, only generate entries for externally
6047 visible procedures. */
6049 static void
6050 output_pubnames ()
6052 register unsigned i;
6053 register unsigned long pubnames_length = size_of_pubnames ();
6055 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6056 "Length of Public Names Info");
6058 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6060 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6061 "Offset of Compilation Unit Info");
6063 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6064 "Compilation Unit Length");
6066 for (i = 0; i < pubname_table_in_use; ++i)
6068 register pubname_ref pub = &pubname_table[i];
6070 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6071 if (pub->die->die_mark == 0)
6072 abort ();
6074 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6075 "DIE offset");
6077 dw2_asm_output_nstring (pub->name, -1, "external name");
6080 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6083 /* Add a new entry to .debug_aranges if appropriate. */
6085 static void
6086 add_arange (decl, die)
6087 tree decl;
6088 dw_die_ref die;
6090 if (! DECL_SECTION_NAME (decl))
6091 return;
6093 if (arange_table_in_use == arange_table_allocated)
6095 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6096 arange_table
6097 = (arange_ref) xrealloc (arange_table,
6098 arange_table_allocated * sizeof (dw_die_ref));
6101 arange_table[arange_table_in_use++] = die;
6104 /* Output the information that goes into the .debug_aranges table.
6105 Namely, define the beginning and ending address range of the
6106 text section generated for this compilation unit. */
6108 static void
6109 output_aranges ()
6111 register unsigned i;
6112 register unsigned long aranges_length = size_of_aranges ();
6114 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6115 "Length of Address Ranges Info");
6117 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6119 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6120 "Offset of Compilation Unit Info");
6122 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6124 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6126 /* We need to align to twice the pointer size here. */
6127 if (DWARF_ARANGES_PAD_SIZE)
6129 /* Pad using a 2 byte words so that padding is correct for any
6130 pointer size. */
6131 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6132 2 * DWARF2_ADDR_SIZE);
6133 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6134 dw2_asm_output_data (2, 0, NULL);
6137 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6138 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6139 text_section_label, "Length");
6141 for (i = 0; i < arange_table_in_use; ++i)
6143 dw_die_ref die = arange_table[i];
6145 /* We shouldn't see aranges for DIEs outside of the main CU. */
6146 if (die->die_mark == 0)
6147 abort ();
6149 if (die->die_tag == DW_TAG_subprogram)
6151 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6152 "Address");
6153 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6154 get_AT_low_pc (die), "Length");
6156 else
6158 /* A static variable; extract the symbol from DW_AT_location.
6159 Note that this code isn't currently hit, as we only emit
6160 aranges for functions (jason 9/23/99). */
6162 dw_attr_ref a = get_AT (die, DW_AT_location);
6163 dw_loc_descr_ref loc;
6164 if (! a || AT_class (a) != dw_val_class_loc)
6165 abort ();
6167 loc = AT_loc (a);
6168 if (loc->dw_loc_opc != DW_OP_addr)
6169 abort ();
6171 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6172 loc->dw_loc_oprnd1.v.val_addr, "Address");
6173 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6174 get_AT_unsigned (die, DW_AT_byte_size),
6175 "Length");
6179 /* Output the terminator words. */
6180 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6181 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6185 /* Data structure containing information about input files. */
6186 struct file_info
6188 char *path; /* Complete file name. */
6189 char *fname; /* File name part. */
6190 int length; /* Length of entire string. */
6191 int file_idx; /* Index in input file table. */
6192 int dir_idx; /* Index in directory table. */
6195 /* Data structure containing information about directories with source
6196 files. */
6197 struct dir_info
6199 char *path; /* Path including directory name. */
6200 int length; /* Path length. */
6201 int prefix; /* Index of directory entry which is a prefix. */
6202 int count; /* Number of files in this directory. */
6203 int dir_idx; /* Index of directory used as base. */
6204 int used; /* Used in the end? */
6207 /* Callback function for file_info comparison. We sort by looking at
6208 the directories in the path. */
6209 static int
6210 file_info_cmp (p1, p2)
6211 const void *p1;
6212 const void *p2;
6214 const struct file_info *s1 = p1;
6215 const struct file_info *s2 = p2;
6216 unsigned char *cp1;
6217 unsigned char *cp2;
6219 /* Take care of file names without directories. */
6220 if (s1->path == s1->fname)
6221 return -1;
6222 else if (s2->path == s2->fname)
6223 return 1;
6225 cp1 = (unsigned char *) s1->path;
6226 cp2 = (unsigned char *) s2->path;
6228 while (1)
6230 ++cp1;
6231 ++cp2;
6232 /* Reached the end of the first path? */
6233 if (cp1 == (unsigned char *) s1->fname)
6234 /* It doesn't really matter in which order files from the
6235 same directory are sorted in. Therefore don't test for
6236 the second path reaching the end. */
6237 return -1;
6238 else if (cp2 == (unsigned char *) s2->fname)
6239 return 1;
6241 /* Character of current path component the same? */
6242 if (*cp1 != *cp2)
6243 return *cp1 - *cp2;
6247 /* Output the directory table and the file name table. We try to minimize
6248 the total amount of memory needed. A heuristic is used to avoid large
6249 slowdowns with many input files. */
6250 static void
6251 output_file_names ()
6253 struct file_info *files;
6254 struct dir_info *dirs;
6255 int *saved;
6256 int *savehere;
6257 int *backmap;
6258 int ndirs;
6259 int idx_offset;
6260 int i;
6261 int idx;
6263 /* Allocate the various arrays we need. */
6264 files = (struct file_info *) alloca (file_table.in_use
6265 * sizeof (struct file_info));
6266 dirs = (struct dir_info *) alloca (file_table.in_use
6267 * sizeof (struct dir_info));
6269 /* Sort the file names. */
6270 for (i = 1; i < (int) file_table.in_use; ++i)
6272 char *f;
6274 /* Skip all leading "./". */
6275 f = file_table.table[i];
6276 while (f[0] == '.' && f[1] == '/')
6277 f += 2;
6279 /* Create a new array entry. */
6280 files[i].path = f;
6281 files[i].length = strlen (f);
6282 files[i].file_idx = i;
6284 /* Search for the file name part. */
6285 f = strrchr (f, '/');
6286 files[i].fname = f == NULL ? files[i].path : f + 1;
6288 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6290 /* Find all the different directories used. */
6291 dirs[0].path = files[1].path;
6292 dirs[0].length = files[1].fname - files[1].path;
6293 dirs[0].prefix = -1;
6294 dirs[0].count = 1;
6295 dirs[0].dir_idx = 0;
6296 dirs[0].used = 0;
6297 files[1].dir_idx = 0;
6298 ndirs = 1;
6300 for (i = 2; i < (int) file_table.in_use; ++i)
6301 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6302 && memcmp (dirs[ndirs - 1].path, files[i].path,
6303 dirs[ndirs - 1].length) == 0)
6305 /* Same directory as last entry. */
6306 files[i].dir_idx = ndirs - 1;
6307 ++dirs[ndirs - 1].count;
6309 else
6311 int j;
6313 /* This is a new directory. */
6314 dirs[ndirs].path = files[i].path;
6315 dirs[ndirs].length = files[i].fname - files[i].path;
6316 dirs[ndirs].count = 1;
6317 dirs[ndirs].dir_idx = ndirs;
6318 dirs[ndirs].used = 0;
6319 files[i].dir_idx = ndirs;
6321 /* Search for a prefix. */
6322 dirs[ndirs].prefix = -1;
6323 for (j = 0; j < ndirs; ++j)
6324 if (dirs[j].length < dirs[ndirs].length
6325 && dirs[j].length > 1
6326 && (dirs[ndirs].prefix == -1
6327 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6328 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6329 dirs[ndirs].prefix = j;
6331 ++ndirs;
6334 /* Now to the actual work. We have to find a subset of the
6335 directories which allow expressing the file name using references
6336 to the directory table with the least amount of characters. We
6337 do not do an exhaustive search where we would have to check out
6338 every combination of every single possible prefix. Instead we
6339 use a heuristic which provides nearly optimal results in most
6340 cases and never is much off. */
6341 saved = (int *) alloca (ndirs * sizeof (int));
6342 savehere = (int *) alloca (ndirs * sizeof (int));
6344 memset (saved, '\0', ndirs * sizeof (saved[0]));
6345 for (i = 0; i < ndirs; ++i)
6347 int j;
6348 int total;
6350 /* We can always save some space for the current directory. But
6351 this does not mean it will be enough to justify adding the
6352 directory. */
6353 savehere[i] = dirs[i].length;
6354 total = (savehere[i] - saved[i]) * dirs[i].count;
6356 for (j = i + 1; j < ndirs; ++j)
6358 savehere[j] = 0;
6360 if (saved[j] < dirs[i].length)
6362 /* Determine whether the dirs[i] path is a prefix of the
6363 dirs[j] path. */
6364 int k;
6366 k = dirs[j].prefix;
6367 while (k != -1 && k != i)
6368 k = dirs[k].prefix;
6370 if (k == i)
6372 /* Yes it is. We can possibly safe some memory but
6373 writing the filenames in dirs[j] relative to
6374 dirs[i]. */
6375 savehere[j] = dirs[i].length;
6376 total += (savehere[j] - saved[j]) * dirs[j].count;
6381 /* Check whether we can safe enough to justify adding the dirs[i]
6382 directory. */
6383 if (total > dirs[i].length + 1)
6385 /* It's worthwhile adding. */
6386 for (j = i; j < ndirs; ++j)
6387 if (savehere[j] > 0)
6389 /* Remember how much we saved for this directory so far. */
6390 saved[j] = savehere[j];
6392 /* Remember the prefix directory. */
6393 dirs[j].dir_idx = i;
6398 /* We have to emit them in the order they appear in the file_table
6399 array since the index is used in the debug info generation. To
6400 do this efficiently we generate a back-mapping of the indices
6401 first. */
6402 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6403 for (i = 1; i < (int) file_table.in_use; ++i)
6405 backmap[files[i].file_idx] = i;
6406 /* Mark this directory as used. */
6407 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6410 /* That was it. We are ready to emit the information. First the
6411 directory name table. Here we have to make sure that the first
6412 actually emitted directory name has the index one. Zero is
6413 reserved for the current working directory. Make sure we do not
6414 confuse these indices with the one for the constructed table
6415 (even though most of the time they are identical). */
6416 idx = 1;
6417 idx_offset = dirs[0].length > 0 ? 1 : 0;
6418 for (i = 1 - idx_offset; i < ndirs; ++i)
6419 if (dirs[i].used != 0)
6421 dirs[i].used = idx++;
6422 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6423 "Directory Entry: 0x%x", dirs[i].used);
6425 dw2_asm_output_data (1, 0, "End directory table");
6427 /* Correct the index for the current working directory entry if it
6428 exists. */
6429 if (idx_offset == 0)
6430 dirs[0].used = 0;
6432 /* Now write all the file names. */
6433 for (i = 1; i < (int) file_table.in_use; ++i)
6435 int file_idx = backmap[i];
6436 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6438 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6439 "File Entry: 0x%x", i);
6441 /* Include directory index. */
6442 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6444 /* Modification time. */
6445 dw2_asm_output_data_uleb128 (0, NULL);
6447 /* File length in bytes. */
6448 dw2_asm_output_data_uleb128 (0, NULL);
6450 dw2_asm_output_data (1, 0, "End file name table");
6454 /* Output the source line number correspondence information. This
6455 information goes into the .debug_line section. */
6457 static void
6458 output_line_info ()
6460 char l1[20], l2[20], p1[20], p2[20];
6461 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6462 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6463 register unsigned opc;
6464 register unsigned n_op_args;
6465 register unsigned long lt_index;
6466 register unsigned long current_line;
6467 register long line_offset;
6468 register long line_delta;
6469 register unsigned long current_file;
6470 register unsigned long function;
6472 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6473 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6474 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6475 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6477 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6478 "Length of Source Line Info");
6479 ASM_OUTPUT_LABEL (asm_out_file, l1);
6481 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6483 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6484 ASM_OUTPUT_LABEL (asm_out_file, p1);
6486 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6487 "Minimum Instruction Length");
6489 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6490 "Default is_stmt_start flag");
6492 dw2_asm_output_data (1, DWARF_LINE_BASE,
6493 "Line Base Value (Special Opcodes)");
6495 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6496 "Line Range Value (Special Opcodes)");
6498 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6499 "Special Opcode Base");
6501 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6503 switch (opc)
6505 case DW_LNS_advance_pc:
6506 case DW_LNS_advance_line:
6507 case DW_LNS_set_file:
6508 case DW_LNS_set_column:
6509 case DW_LNS_fixed_advance_pc:
6510 n_op_args = 1;
6511 break;
6512 default:
6513 n_op_args = 0;
6514 break;
6517 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6518 opc, n_op_args);
6521 /* Write out the information about the files we use. */
6522 output_file_names ();
6523 ASM_OUTPUT_LABEL (asm_out_file, p2);
6525 /* We used to set the address register to the first location in the text
6526 section here, but that didn't accomplish anything since we already
6527 have a line note for the opening brace of the first function. */
6529 /* Generate the line number to PC correspondence table, encoded as
6530 a series of state machine operations. */
6531 current_file = 1;
6532 current_line = 1;
6533 strcpy (prev_line_label, text_section_label);
6534 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6536 register dw_line_info_ref line_info = &line_info_table[lt_index];
6538 #if 0
6539 /* Disable this optimization for now; GDB wants to see two line notes
6540 at the beginning of a function so it can find the end of the
6541 prologue. */
6543 /* Don't emit anything for redundant notes. Just updating the
6544 address doesn't accomplish anything, because we already assume
6545 that anything after the last address is this line. */
6546 if (line_info->dw_line_num == current_line
6547 && line_info->dw_file_num == current_file)
6548 continue;
6549 #endif
6551 /* Emit debug info for the address of the current line.
6553 Unfortunately, we have little choice here currently, and must always
6554 use the most general form. Gcc does not know the address delta
6555 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
6556 attributes which will give an upper bound on the address range. We
6557 could perhaps use length attributes to determine when it is safe to
6558 use DW_LNS_fixed_advance_pc. */
6560 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6561 if (0)
6563 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6564 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6565 "DW_LNS_fixed_advance_pc");
6566 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6568 else
6570 /* This can handle any delta. This takes
6571 4+DWARF2_ADDR_SIZE bytes. */
6572 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6573 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6574 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6575 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6577 strcpy (prev_line_label, line_label);
6579 /* Emit debug info for the source file of the current line, if
6580 different from the previous line. */
6581 if (line_info->dw_file_num != current_file)
6583 current_file = line_info->dw_file_num;
6584 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6585 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6586 file_table.table[current_file]);
6589 /* Emit debug info for the current line number, choosing the encoding
6590 that uses the least amount of space. */
6591 if (line_info->dw_line_num != current_line)
6593 line_offset = line_info->dw_line_num - current_line;
6594 line_delta = line_offset - DWARF_LINE_BASE;
6595 current_line = line_info->dw_line_num;
6596 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6598 /* This can handle deltas from -10 to 234, using the current
6599 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6600 takes 1 byte. */
6601 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6602 "line %lu", current_line);
6604 else
6606 /* This can handle any delta. This takes at least 4 bytes,
6607 depending on the value being encoded. */
6608 dw2_asm_output_data (1, DW_LNS_advance_line,
6609 "advance to line %lu", current_line);
6610 dw2_asm_output_data_sleb128 (line_offset, NULL);
6611 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6614 else
6616 /* We still need to start a new row, so output a copy insn. */
6617 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6621 /* Emit debug info for the address of the end of the function. */
6622 if (0)
6624 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6625 "DW_LNS_fixed_advance_pc");
6626 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
6628 else
6630 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6631 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6632 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6633 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
6636 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6637 dw2_asm_output_data_uleb128 (1, NULL);
6638 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6640 function = 0;
6641 current_file = 1;
6642 current_line = 1;
6643 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6645 register dw_separate_line_info_ref line_info
6646 = &separate_line_info_table[lt_index];
6648 #if 0
6649 /* Don't emit anything for redundant notes. */
6650 if (line_info->dw_line_num == current_line
6651 && line_info->dw_file_num == current_file
6652 && line_info->function == function)
6653 goto cont;
6654 #endif
6656 /* Emit debug info for the address of the current line. If this is
6657 a new function, or the first line of a function, then we need
6658 to handle it differently. */
6659 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6660 lt_index);
6661 if (function != line_info->function)
6663 function = line_info->function;
6665 /* Set the address register to the first line in the function */
6666 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6667 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6668 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6669 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6671 else
6673 /* ??? See the DW_LNS_advance_pc comment above. */
6674 if (0)
6676 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6677 "DW_LNS_fixed_advance_pc");
6678 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6680 else
6682 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6683 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6684 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6685 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6688 strcpy (prev_line_label, line_label);
6690 /* Emit debug info for the source file of the current line, if
6691 different from the previous line. */
6692 if (line_info->dw_file_num != current_file)
6694 current_file = line_info->dw_file_num;
6695 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6696 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6697 file_table.table[current_file]);
6700 /* Emit debug info for the current line number, choosing the encoding
6701 that uses the least amount of space. */
6702 if (line_info->dw_line_num != current_line)
6704 line_offset = line_info->dw_line_num - current_line;
6705 line_delta = line_offset - DWARF_LINE_BASE;
6706 current_line = line_info->dw_line_num;
6707 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6708 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6709 "line %lu", current_line);
6710 else
6712 dw2_asm_output_data (1, DW_LNS_advance_line,
6713 "advance to line %lu", current_line);
6714 dw2_asm_output_data_sleb128 (line_offset, NULL);
6715 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6718 else
6719 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6721 #if 0
6722 cont:
6723 #endif
6724 ++lt_index;
6726 /* If we're done with a function, end its sequence. */
6727 if (lt_index == separate_line_info_table_in_use
6728 || separate_line_info_table[lt_index].function != function)
6730 current_file = 1;
6731 current_line = 1;
6733 /* Emit debug info for the address of the end of the function. */
6734 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6735 if (0)
6737 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6738 "DW_LNS_fixed_advance_pc");
6739 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6741 else
6743 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6744 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6745 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6746 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6749 /* Output the marker for the end of this sequence. */
6750 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6751 dw2_asm_output_data_uleb128 (1, NULL);
6752 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6756 /* Output the marker for the end of the line number info. */
6757 ASM_OUTPUT_LABEL (asm_out_file, l2);
6760 /* Given a pointer to a tree node for some base type, return a pointer to
6761 a DIE that describes the given type.
6763 This routine must only be called for GCC type nodes that correspond to
6764 Dwarf base (fundamental) types. */
6766 static dw_die_ref
6767 base_type_die (type)
6768 register tree type;
6770 register dw_die_ref base_type_result;
6771 register const char *type_name;
6772 register enum dwarf_type encoding;
6773 register tree name = TYPE_NAME (type);
6775 if (TREE_CODE (type) == ERROR_MARK
6776 || TREE_CODE (type) == VOID_TYPE)
6777 return 0;
6779 if (name)
6781 if (TREE_CODE (name) == TYPE_DECL)
6782 name = DECL_NAME (name);
6784 type_name = IDENTIFIER_POINTER (name);
6786 else
6787 type_name = "__unknown__";
6789 switch (TREE_CODE (type))
6791 case INTEGER_TYPE:
6792 /* Carefully distinguish the C character types, without messing
6793 up if the language is not C. Note that we check only for the names
6794 that contain spaces; other names might occur by coincidence in other
6795 languages. */
6796 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6797 && (type == char_type_node
6798 || ! strcmp (type_name, "signed char")
6799 || ! strcmp (type_name, "unsigned char"))))
6801 if (TREE_UNSIGNED (type))
6802 encoding = DW_ATE_unsigned;
6803 else
6804 encoding = DW_ATE_signed;
6805 break;
6807 /* else fall through. */
6809 case CHAR_TYPE:
6810 /* GNU Pascal/Ada CHAR type. Not used in C. */
6811 if (TREE_UNSIGNED (type))
6812 encoding = DW_ATE_unsigned_char;
6813 else
6814 encoding = DW_ATE_signed_char;
6815 break;
6817 case REAL_TYPE:
6818 encoding = DW_ATE_float;
6819 break;
6821 /* Dwarf2 doesn't know anything about complex ints, so use
6822 a user defined type for it. */
6823 case COMPLEX_TYPE:
6824 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6825 encoding = DW_ATE_complex_float;
6826 else
6827 encoding = DW_ATE_lo_user;
6828 break;
6830 case BOOLEAN_TYPE:
6831 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6832 encoding = DW_ATE_boolean;
6833 break;
6835 default:
6836 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6839 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6840 if (demangle_name_func)
6841 type_name = (*demangle_name_func) (type_name);
6843 add_AT_string (base_type_result, DW_AT_name, type_name);
6844 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6845 int_size_in_bytes (type));
6846 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6848 return base_type_result;
6851 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6852 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6853 a given type is generally the same as the given type, except that if the
6854 given type is a pointer or reference type, then the root type of the given
6855 type is the root type of the "basis" type for the pointer or reference
6856 type. (This definition of the "root" type is recursive.) Also, the root
6857 type of a `const' qualified type or a `volatile' qualified type is the
6858 root type of the given type without the qualifiers. */
6860 static tree
6861 root_type (type)
6862 register tree type;
6864 if (TREE_CODE (type) == ERROR_MARK)
6865 return error_mark_node;
6867 switch (TREE_CODE (type))
6869 case ERROR_MARK:
6870 return error_mark_node;
6872 case POINTER_TYPE:
6873 case REFERENCE_TYPE:
6874 return type_main_variant (root_type (TREE_TYPE (type)));
6876 default:
6877 return type_main_variant (type);
6881 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6882 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6884 static inline int
6885 is_base_type (type)
6886 register tree type;
6888 switch (TREE_CODE (type))
6890 case ERROR_MARK:
6891 case VOID_TYPE:
6892 case INTEGER_TYPE:
6893 case REAL_TYPE:
6894 case COMPLEX_TYPE:
6895 case BOOLEAN_TYPE:
6896 case CHAR_TYPE:
6897 return 1;
6899 case SET_TYPE:
6900 case ARRAY_TYPE:
6901 case RECORD_TYPE:
6902 case UNION_TYPE:
6903 case QUAL_UNION_TYPE:
6904 case ENUMERAL_TYPE:
6905 case FUNCTION_TYPE:
6906 case METHOD_TYPE:
6907 case POINTER_TYPE:
6908 case REFERENCE_TYPE:
6909 case FILE_TYPE:
6910 case OFFSET_TYPE:
6911 case LANG_TYPE:
6912 case VECTOR_TYPE:
6913 return 0;
6915 default:
6916 abort ();
6919 return 0;
6922 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6923 entry that chains various modifiers in front of the given type. */
6925 static dw_die_ref
6926 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6927 register tree type;
6928 register int is_const_type;
6929 register int is_volatile_type;
6930 register dw_die_ref context_die;
6932 register enum tree_code code = TREE_CODE (type);
6933 register dw_die_ref mod_type_die = NULL;
6934 register dw_die_ref sub_die = NULL;
6935 register tree item_type = NULL;
6937 if (code != ERROR_MARK)
6939 tree qualified_type;
6941 /* See if we already have the appropriately qualified variant of
6942 this type. */
6943 qualified_type
6944 = get_qualified_type (type,
6945 ((is_const_type ? TYPE_QUAL_CONST : 0)
6946 | (is_volatile_type
6947 ? TYPE_QUAL_VOLATILE : 0)));
6948 /* If we do, then we can just use its DIE, if it exists. */
6949 if (qualified_type)
6951 mod_type_die = lookup_type_die (qualified_type);
6952 if (mod_type_die)
6953 return mod_type_die;
6956 /* Handle C typedef types. */
6957 if (qualified_type && TYPE_NAME (qualified_type)
6958 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
6959 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
6961 tree type_name = TYPE_NAME (qualified_type);
6962 tree dtype = TREE_TYPE (type_name);
6963 if (qualified_type == dtype)
6965 /* For a named type, use the typedef. */
6966 gen_type_die (qualified_type, context_die);
6967 mod_type_die = lookup_type_die (qualified_type);
6970 else if (is_const_type < TYPE_READONLY (dtype)
6971 || is_volatile_type < TYPE_VOLATILE (dtype))
6972 /* cv-unqualified version of named type. Just use the unnamed
6973 type to which it refers. */
6974 mod_type_die
6975 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
6976 is_const_type, is_volatile_type,
6977 context_die);
6978 /* Else cv-qualified version of named type; fall through. */
6981 if (mod_type_die)
6982 /* OK. */
6984 else if (is_const_type)
6986 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6987 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6989 else if (is_volatile_type)
6991 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6992 sub_die = modified_type_die (type, 0, 0, context_die);
6994 else if (code == POINTER_TYPE)
6996 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6997 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6998 #if 0
6999 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7000 #endif
7001 item_type = TREE_TYPE (type);
7003 else if (code == REFERENCE_TYPE)
7005 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7006 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7007 #if 0
7008 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7009 #endif
7010 item_type = TREE_TYPE (type);
7012 else if (is_base_type (type))
7013 mod_type_die = base_type_die (type);
7014 else
7016 gen_type_die (type, context_die);
7018 /* We have to get the type_main_variant here (and pass that to the
7019 `lookup_type_die' routine) because the ..._TYPE node we have
7020 might simply be a *copy* of some original type node (where the
7021 copy was created to help us keep track of typedef names) and
7022 that copy might have a different TYPE_UID from the original
7023 ..._TYPE node. */
7024 mod_type_die = lookup_type_die (type_main_variant (type));
7025 if (mod_type_die == NULL)
7026 abort ();
7029 /* We want to equate the qualified type to the die below. */
7030 if (qualified_type)
7031 type = qualified_type;
7034 equate_type_number_to_die (type, mod_type_die);
7035 if (item_type)
7036 /* We must do this after the equate_type_number_to_die call, in case
7037 this is a recursive type. This ensures that the modified_type_die
7038 recursion will terminate even if the type is recursive. Recursive
7039 types are possible in Ada. */
7040 sub_die = modified_type_die (item_type,
7041 TYPE_READONLY (item_type),
7042 TYPE_VOLATILE (item_type),
7043 context_die);
7045 if (sub_die != NULL)
7046 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7048 return mod_type_die;
7051 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7052 an enumerated type. */
7054 static inline int
7055 type_is_enum (type)
7056 register tree type;
7058 return TREE_CODE (type) == ENUMERAL_TYPE;
7061 /* Return the register number described by a given RTL node. */
7063 static unsigned int
7064 reg_number (rtl)
7065 register rtx rtl;
7067 register unsigned regno = REGNO (rtl);
7069 if (regno >= FIRST_PSEUDO_REGISTER)
7071 warning ("internal regno botch: regno = %d\n", regno);
7072 regno = 0;
7075 regno = DBX_REGISTER_NUMBER (regno);
7076 return regno;
7079 /* Return a location descriptor that designates a machine register. */
7081 static dw_loc_descr_ref
7082 reg_loc_descriptor (rtl)
7083 register rtx rtl;
7085 register dw_loc_descr_ref loc_result = NULL;
7086 register unsigned reg = reg_number (rtl);
7088 if (reg <= 31)
7089 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7090 else
7091 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7093 return loc_result;
7096 /* Return a location descriptor that designates a constant. */
7098 static dw_loc_descr_ref
7099 int_loc_descriptor (i)
7100 HOST_WIDE_INT i;
7102 enum dwarf_location_atom op;
7104 /* Pick the smallest representation of a constant, rather than just
7105 defaulting to the LEB encoding. */
7106 if (i >= 0)
7108 if (i <= 31)
7109 op = DW_OP_lit0 + i;
7110 else if (i <= 0xff)
7111 op = DW_OP_const1u;
7112 else if (i <= 0xffff)
7113 op = DW_OP_const2u;
7114 else if (HOST_BITS_PER_WIDE_INT == 32
7115 || i <= 0xffffffff)
7116 op = DW_OP_const4u;
7117 else
7118 op = DW_OP_constu;
7120 else
7122 if (i >= -0x80)
7123 op = DW_OP_const1s;
7124 else if (i >= -0x8000)
7125 op = DW_OP_const2s;
7126 else if (HOST_BITS_PER_WIDE_INT == 32
7127 || i >= -0x80000000)
7128 op = DW_OP_const4s;
7129 else
7130 op = DW_OP_consts;
7133 return new_loc_descr (op, i, 0);
7136 /* Return a location descriptor that designates a base+offset location. */
7138 static dw_loc_descr_ref
7139 based_loc_descr (reg, offset)
7140 unsigned reg;
7141 long int offset;
7143 register dw_loc_descr_ref loc_result;
7144 /* For the "frame base", we use the frame pointer or stack pointer
7145 registers, since the RTL for local variables is relative to one of
7146 them. */
7147 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7148 ? HARD_FRAME_POINTER_REGNUM
7149 : STACK_POINTER_REGNUM);
7151 if (reg == fp_reg)
7152 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7153 else if (reg <= 31)
7154 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7155 else
7156 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7158 return loc_result;
7161 /* Return true if this RTL expression describes a base+offset calculation. */
7163 static inline int
7164 is_based_loc (rtl)
7165 register rtx rtl;
7167 return (GET_CODE (rtl) == PLUS
7168 && ((GET_CODE (XEXP (rtl, 0)) == REG
7169 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7172 /* The following routine converts the RTL for a variable or parameter
7173 (resident in memory) into an equivalent Dwarf representation of a
7174 mechanism for getting the address of that same variable onto the top of a
7175 hypothetical "address evaluation" stack.
7177 When creating memory location descriptors, we are effectively transforming
7178 the RTL for a memory-resident object into its Dwarf postfix expression
7179 equivalent. This routine recursively descends an RTL tree, turning
7180 it into Dwarf postfix code as it goes.
7182 MODE is the mode of the memory reference, needed to handle some
7183 autoincrement addressing modes. */
7185 static dw_loc_descr_ref
7186 mem_loc_descriptor (rtl, mode)
7187 register rtx rtl;
7188 enum machine_mode mode;
7190 dw_loc_descr_ref mem_loc_result = NULL;
7191 /* Note that for a dynamically sized array, the location we will generate a
7192 description of here will be the lowest numbered location which is
7193 actually within the array. That's *not* necessarily the same as the
7194 zeroth element of the array. */
7196 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7197 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7198 #endif
7200 switch (GET_CODE (rtl))
7202 case POST_INC:
7203 case POST_DEC:
7204 case POST_MODIFY:
7205 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7206 just fall into the SUBREG code. */
7208 /* Fall through. */
7210 case SUBREG:
7211 /* The case of a subreg may arise when we have a local (register)
7212 variable or a formal (register) parameter which doesn't quite fill
7213 up an entire register. For now, just assume that it is
7214 legitimate to make the Dwarf info refer to the whole register which
7215 contains the given subreg. */
7216 rtl = SUBREG_REG (rtl);
7218 /* Fall through. */
7220 case REG:
7221 /* Whenever a register number forms a part of the description of the
7222 method for calculating the (dynamic) address of a memory resident
7223 object, DWARF rules require the register number be referred to as
7224 a "base register". This distinction is not based in any way upon
7225 what category of register the hardware believes the given register
7226 belongs to. This is strictly DWARF terminology we're dealing with
7227 here. Note that in cases where the location of a memory-resident
7228 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7229 OP_CONST (0)) the actual DWARF location descriptor that we generate
7230 may just be OP_BASEREG (basereg). This may look deceptively like
7231 the object in question was allocated to a register (rather than in
7232 memory) so DWARF consumers need to be aware of the subtle
7233 distinction between OP_REG and OP_BASEREG. */
7234 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7235 break;
7237 case MEM:
7238 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7239 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7240 break;
7242 case LABEL_REF:
7243 /* Some ports can transform a symbol ref into a label ref, because
7244 the symbol ref is too far away and has to be dumped into a constant
7245 pool. */
7246 case CONST:
7247 case SYMBOL_REF:
7248 /* Alternatively, the symbol in the constant pool can be referenced
7249 by a different symbol. */
7250 if (GET_CODE (rtl) == SYMBOL_REF
7251 && CONSTANT_POOL_ADDRESS_P (rtl))
7253 rtx tmp = get_pool_constant (rtl);
7254 /* Doesn't work for floating point constants. */
7255 if (! (GET_CODE (tmp) == CONST_DOUBLE && GET_MODE (tmp) != VOIDmode))
7256 rtl = tmp;
7260 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7261 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7262 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7263 break;
7265 case PRE_MODIFY:
7266 /* Extract the PLUS expression nested inside and fall into
7267 PLUS code bellow. */
7268 rtl = XEXP (rtl, 1);
7269 goto plus;
7271 case PRE_INC:
7272 case PRE_DEC:
7273 /* Turn these into a PLUS expression and fall into the PLUS code
7274 below. */
7275 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7276 GEN_INT (GET_CODE (rtl) == PRE_INC
7277 ? GET_MODE_UNIT_SIZE (mode)
7278 : -GET_MODE_UNIT_SIZE (mode)));
7280 /* Fall through. */
7282 case PLUS:
7283 plus:
7284 if (is_based_loc (rtl))
7285 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7286 INTVAL (XEXP (rtl, 1)));
7287 else
7289 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7291 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7292 && INTVAL (XEXP (rtl, 1)) >= 0)
7294 add_loc_descr (&mem_loc_result,
7295 new_loc_descr (DW_OP_plus_uconst,
7296 INTVAL (XEXP (rtl, 1)), 0));
7298 else
7300 add_loc_descr (&mem_loc_result,
7301 mem_loc_descriptor (XEXP (rtl, 1), mode));
7302 add_loc_descr (&mem_loc_result,
7303 new_loc_descr (DW_OP_plus, 0, 0));
7306 break;
7308 case MULT:
7309 /* If a pseudo-reg is optimized away, it is possible for it to
7310 be replaced with a MEM containing a multiply. */
7311 add_loc_descr (&mem_loc_result,
7312 mem_loc_descriptor (XEXP (rtl, 0), mode));
7313 add_loc_descr (&mem_loc_result,
7314 mem_loc_descriptor (XEXP (rtl, 1), mode));
7315 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7316 break;
7318 case CONST_INT:
7319 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7320 break;
7322 default:
7323 abort ();
7326 return mem_loc_result;
7329 /* Return a descriptor that describes the concatenation of two locations.
7330 This is typically a complex variable. */
7332 static dw_loc_descr_ref
7333 concat_loc_descriptor (x0, x1)
7334 register rtx x0, x1;
7336 dw_loc_descr_ref cc_loc_result = NULL;
7338 if (!is_pseudo_reg (x0)
7339 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7340 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7341 add_loc_descr (&cc_loc_result,
7342 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7344 if (!is_pseudo_reg (x1)
7345 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7346 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7347 add_loc_descr (&cc_loc_result,
7348 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7350 return cc_loc_result;
7353 /* Output a proper Dwarf location descriptor for a variable or parameter
7354 which is either allocated in a register or in a memory location. For a
7355 register, we just generate an OP_REG and the register number. For a
7356 memory location we provide a Dwarf postfix expression describing how to
7357 generate the (dynamic) address of the object onto the address stack. */
7359 static dw_loc_descr_ref
7360 loc_descriptor (rtl)
7361 register rtx rtl;
7363 dw_loc_descr_ref loc_result = NULL;
7364 switch (GET_CODE (rtl))
7366 case SUBREG:
7367 /* The case of a subreg may arise when we have a local (register)
7368 variable or a formal (register) parameter which doesn't quite fill
7369 up an entire register. For now, just assume that it is
7370 legitimate to make the Dwarf info refer to the whole register which
7371 contains the given subreg. */
7372 rtl = SUBREG_REG (rtl);
7374 /* Fall through. */
7376 case REG:
7377 loc_result = reg_loc_descriptor (rtl);
7378 break;
7380 case MEM:
7381 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7382 break;
7384 case CONCAT:
7385 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7386 break;
7388 default:
7389 abort ();
7392 return loc_result;
7395 /* Similar, but generate the descriptor from trees instead of rtl.
7396 This comes up particularly with variable length arrays. */
7398 static dw_loc_descr_ref
7399 loc_descriptor_from_tree (loc, addressp)
7400 tree loc;
7401 int addressp;
7403 dw_loc_descr_ref ret = NULL;
7404 int indirect_size = 0;
7405 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7406 enum dwarf_location_atom op;
7408 /* ??? Most of the time we do not take proper care for sign/zero
7409 extending the values properly. Hopefully this won't be a real
7410 problem... */
7412 switch (TREE_CODE (loc))
7414 case ERROR_MARK:
7415 break;
7417 case WITH_RECORD_EXPR:
7418 /* This case involves extracting fields from an object to determine the
7419 position of other fields. We don't try to encode this here. The
7420 only user of this is Ada, which encodes the needed information using
7421 the names of types. */
7422 return ret;
7424 case VAR_DECL:
7425 case PARM_DECL:
7427 rtx rtl = rtl_for_decl_location (loc);
7428 enum machine_mode mode = DECL_MODE (loc);
7430 if (rtl == NULL_RTX)
7431 break;
7432 else if (CONSTANT_P (rtl))
7434 ret = new_loc_descr (DW_OP_addr, 0, 0);
7435 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7436 ret->dw_loc_oprnd1.v.val_addr = rtl;
7437 indirect_size = GET_MODE_SIZE (mode);
7439 else
7441 if (GET_CODE (rtl) == MEM)
7443 indirect_size = GET_MODE_SIZE (mode);
7444 rtl = XEXP (rtl, 0);
7446 ret = mem_loc_descriptor (rtl, mode);
7449 break;
7451 case INDIRECT_REF:
7452 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7453 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7454 break;
7456 case NOP_EXPR:
7457 case CONVERT_EXPR:
7458 case NON_LVALUE_EXPR:
7459 case SAVE_EXPR:
7460 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7462 case COMPONENT_REF:
7463 case BIT_FIELD_REF:
7464 case ARRAY_REF:
7466 tree obj, offset;
7467 HOST_WIDE_INT bitsize, bitpos, bytepos;
7468 enum machine_mode mode;
7469 int volatilep;
7470 unsigned int alignment;
7472 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7473 &unsignedp, &volatilep, &alignment);
7474 ret = loc_descriptor_from_tree (obj, 1);
7476 if (offset != NULL_TREE)
7478 /* Variable offset. */
7479 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7480 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7483 if (addressp)
7485 /* We cannot address anything not on a unit boundary. */
7486 if (bitpos % BITS_PER_UNIT != 0)
7487 abort ();
7489 else
7491 if (bitpos % BITS_PER_UNIT != 0
7492 || bitsize % BITS_PER_UNIT != 0)
7494 /* ??? We could handle this by loading and shifting etc.
7495 Wait until someone needs it before expending the effort. */
7496 abort ();
7499 indirect_size = bitsize / BITS_PER_UNIT;
7502 bytepos = bitpos / BITS_PER_UNIT;
7503 if (bytepos > 0)
7504 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7505 else if (bytepos < 0)
7507 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7508 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7510 break;
7513 case INTEGER_CST:
7514 if (host_integerp (loc, 0))
7515 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7516 break;
7518 case BIT_AND_EXPR:
7519 op = DW_OP_and;
7520 goto do_binop;
7521 case BIT_XOR_EXPR:
7522 op = DW_OP_xor;
7523 goto do_binop;
7524 case BIT_IOR_EXPR:
7525 op = DW_OP_or;
7526 goto do_binop;
7527 case TRUNC_DIV_EXPR:
7528 op = DW_OP_div;
7529 goto do_binop;
7530 case MINUS_EXPR:
7531 op = DW_OP_minus;
7532 goto do_binop;
7533 case TRUNC_MOD_EXPR:
7534 op = DW_OP_mod;
7535 goto do_binop;
7536 case MULT_EXPR:
7537 op = DW_OP_mul;
7538 goto do_binop;
7539 case LSHIFT_EXPR:
7540 op = DW_OP_shl;
7541 goto do_binop;
7542 case RSHIFT_EXPR:
7543 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7544 goto do_binop;
7545 case PLUS_EXPR:
7546 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7547 && host_integerp (TREE_OPERAND (loc, 1), 0))
7549 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7550 add_loc_descr (&ret,
7551 new_loc_descr (DW_OP_plus_uconst,
7552 tree_low_cst (TREE_OPERAND (loc, 1),
7554 0));
7555 break;
7557 op = DW_OP_plus;
7558 goto do_binop;
7559 case LE_EXPR:
7560 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7561 break;
7562 op = DW_OP_le;
7563 goto do_binop;
7564 case GE_EXPR:
7565 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7566 break;
7567 op = DW_OP_ge;
7568 goto do_binop;
7569 case LT_EXPR:
7570 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7571 break;
7572 op = DW_OP_lt;
7573 goto do_binop;
7574 case GT_EXPR:
7575 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7576 break;
7577 op = DW_OP_gt;
7578 goto do_binop;
7579 case EQ_EXPR:
7580 op = DW_OP_eq;
7581 goto do_binop;
7582 case NE_EXPR:
7583 op = DW_OP_ne;
7584 goto do_binop;
7586 do_binop:
7587 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7588 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7589 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7590 break;
7592 case BIT_NOT_EXPR:
7593 op = DW_OP_not;
7594 goto do_unop;
7595 case ABS_EXPR:
7596 op = DW_OP_abs;
7597 goto do_unop;
7598 case NEGATE_EXPR:
7599 op = DW_OP_neg;
7600 goto do_unop;
7602 do_unop:
7603 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7604 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7605 break;
7607 case MAX_EXPR:
7608 loc = build (COND_EXPR, TREE_TYPE (loc),
7609 build (LT_EXPR, integer_type_node,
7610 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
7611 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
7612 /* FALLTHRU */
7614 case COND_EXPR:
7616 dw_loc_descr_ref bra_node, jump_node, tmp;
7618 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7619 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
7620 add_loc_descr (&ret, bra_node);
7622 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
7623 add_loc_descr (&ret, tmp);
7624 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
7625 add_loc_descr (&ret, jump_node);
7627 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
7628 add_loc_descr (&ret, tmp);
7629 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7630 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
7632 /* ??? Need a node to point the skip at. Use a nop. */
7633 tmp = new_loc_descr (DW_OP_nop, 0, 0);
7634 add_loc_descr (&ret, tmp);
7635 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7636 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
7638 break;
7640 default:
7641 abort ();
7644 /* If we can't fill the request for an address, die. */
7645 if (addressp && indirect_size == 0)
7646 abort ();
7648 /* If we've got an address and don't want one, dereference. */
7649 if (!addressp && indirect_size > 0)
7651 if (indirect_size > DWARF2_ADDR_SIZE)
7652 abort ();
7653 if (indirect_size == DWARF2_ADDR_SIZE)
7654 op = DW_OP_deref;
7655 else
7656 op = DW_OP_deref_size;
7657 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
7660 return ret;
7663 /* Given a value, round it up to the lowest multiple of `boundary'
7664 which is not less than the value itself. */
7666 static inline HOST_WIDE_INT
7667 ceiling (value, boundary)
7668 HOST_WIDE_INT value;
7669 unsigned int boundary;
7671 return (((value + boundary - 1) / boundary) * boundary);
7674 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7675 pointer to the declared type for the relevant field variable, or return
7676 `integer_type_node' if the given node turns out to be an
7677 ERROR_MARK node. */
7679 static inline tree
7680 field_type (decl)
7681 register tree decl;
7683 register tree type;
7685 if (TREE_CODE (decl) == ERROR_MARK)
7686 return integer_type_node;
7688 type = DECL_BIT_FIELD_TYPE (decl);
7689 if (type == NULL_TREE)
7690 type = TREE_TYPE (decl);
7692 return type;
7695 /* Given a pointer to a tree node, return the alignment in bits for
7696 it, or else return BITS_PER_WORD if the node actually turns out to
7697 be an ERROR_MARK node. */
7699 static inline unsigned
7700 simple_type_align_in_bits (type)
7701 register tree type;
7703 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7706 static inline unsigned
7707 simple_decl_align_in_bits (decl)
7708 register tree decl;
7710 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
7713 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7714 node, return the size in bits for the type if it is a constant, or else
7715 return the alignment for the type if the type's size is not constant, or
7716 else return BITS_PER_WORD if the type actually turns out to be an
7717 ERROR_MARK node. */
7719 static inline unsigned HOST_WIDE_INT
7720 simple_type_size_in_bits (type)
7721 register tree type;
7723 tree type_size_tree;
7725 if (TREE_CODE (type) == ERROR_MARK)
7726 return BITS_PER_WORD;
7727 type_size_tree = TYPE_SIZE (type);
7729 if (type_size_tree == NULL_TREE)
7730 return 0;
7731 if (! host_integerp (type_size_tree, 1))
7732 return TYPE_ALIGN (type);
7733 return tree_low_cst (type_size_tree, 1);
7736 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7737 return the byte offset of the lowest addressed byte of the "containing
7738 object" for the given FIELD_DECL, or return 0 if we are unable to
7739 determine what that offset is, either because the argument turns out to
7740 be a pointer to an ERROR_MARK node, or because the offset is actually
7741 variable. (We can't handle the latter case just yet). */
7743 static HOST_WIDE_INT
7744 field_byte_offset (decl)
7745 register tree decl;
7747 unsigned int type_align_in_bits;
7748 unsigned int decl_align_in_bits;
7749 unsigned HOST_WIDE_INT type_size_in_bits;
7750 HOST_WIDE_INT object_offset_in_bits;
7751 HOST_WIDE_INT object_offset_in_bytes;
7752 tree type;
7753 tree field_size_tree;
7754 HOST_WIDE_INT bitpos_int;
7755 HOST_WIDE_INT deepest_bitpos;
7756 unsigned HOST_WIDE_INT field_size_in_bits;
7758 if (TREE_CODE (decl) == ERROR_MARK)
7759 return 0;
7761 if (TREE_CODE (decl) != FIELD_DECL)
7762 abort ();
7764 type = field_type (decl);
7765 field_size_tree = DECL_SIZE (decl);
7767 /* The size could be unspecified if there was an error, or for
7768 a flexible array member. */
7769 if (! field_size_tree)
7770 field_size_tree = bitsize_zero_node;
7772 /* We cannot yet cope with fields whose positions are variable, so
7773 for now, when we see such things, we simply return 0. Someday, we may
7774 be able to handle such cases, but it will be damn difficult. */
7775 if (! host_integerp (bit_position (decl), 0))
7776 return 0;
7778 bitpos_int = int_bit_position (decl);
7780 /* If we don't know the size of the field, pretend it's a full word. */
7781 if (host_integerp (field_size_tree, 1))
7782 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7783 else
7784 field_size_in_bits = BITS_PER_WORD;
7786 type_size_in_bits = simple_type_size_in_bits (type);
7787 type_align_in_bits = simple_type_align_in_bits (type);
7788 decl_align_in_bits = simple_decl_align_in_bits (decl);
7790 /* Note that the GCC front-end doesn't make any attempt to keep track of
7791 the starting bit offset (relative to the start of the containing
7792 structure type) of the hypothetical "containing object" for a bit-
7793 field. Thus, when computing the byte offset value for the start of the
7794 "containing object" of a bit-field, we must deduce this information on
7795 our own. This can be rather tricky to do in some cases. For example,
7796 handling the following structure type definition when compiling for an
7797 i386/i486 target (which only aligns long long's to 32-bit boundaries)
7798 can be very tricky:
7800 struct S { int field1; long long field2:31; };
7802 Fortunately, there is a simple rule-of-thumb which can be
7803 used in such cases. When compiling for an i386/i486, GCC will allocate
7804 8 bytes for the structure shown above. It decides to do this based upon
7805 one simple rule for bit-field allocation. Quite simply, GCC allocates
7806 each "containing object" for each bit-field at the first (i.e. lowest
7807 addressed) legitimate alignment boundary (based upon the required
7808 minimum alignment for the declared type of the field) which it can
7809 possibly use, subject to the condition that there is still enough
7810 available space remaining in the containing object (when allocated at
7811 the selected point) to fully accommodate all of the bits of the
7812 bit-field itself. This simple rule makes it obvious why GCC allocates
7813 8 bytes for each object of the structure type shown above. When looking
7814 for a place to allocate the "containing object" for `field2', the
7815 compiler simply tries to allocate a 64-bit "containing object" at each
7816 successive 32-bit boundary (starting at zero) until it finds a place to
7817 allocate that 64- bit field such that at least 31 contiguous (and
7818 previously unallocated) bits remain within that selected 64 bit field.
7819 (As it turns out, for the example above, the compiler finds that it is
7820 OK to allocate the "containing object" 64-bit field at bit-offset zero
7821 within the structure type.) Here we attempt to work backwards from the
7822 limited set of facts we're given, and we try to deduce from those facts,
7823 where GCC must have believed that the containing object started (within
7824 the structure type). The value we deduce is then used (by the callers of
7825 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
7826 for fields (both bit-fields and, in the case of DW_AT_location, regular
7827 fields as well). */
7829 /* Figure out the bit-distance from the start of the structure to the
7830 "deepest" bit of the bit-field. */
7831 deepest_bitpos = bitpos_int + field_size_in_bits;
7833 /* This is the tricky part. Use some fancy footwork to deduce where the
7834 lowest addressed bit of the containing object must be. */
7835 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
7837 /* Round up to type_align by default. This works best for bitfields. */
7838 object_offset_in_bits += type_align_in_bits - 1;
7839 object_offset_in_bits /= type_align_in_bits;
7840 object_offset_in_bits *= type_align_in_bits;
7842 if (object_offset_in_bits > bitpos_int)
7844 /* Sigh, the decl must be packed. */
7845 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
7847 /* Round up to decl_align instead. */
7848 object_offset_in_bits += decl_align_in_bits - 1;
7849 object_offset_in_bits /= decl_align_in_bits;
7850 object_offset_in_bits *= decl_align_in_bits;
7853 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
7855 return object_offset_in_bytes;
7858 /* The following routines define various Dwarf attributes and any data
7859 associated with them. */
7861 /* Add a location description attribute value to a DIE.
7863 This emits location attributes suitable for whole variables and
7864 whole parameters. Note that the location attributes for struct fields are
7865 generated by the routine `data_member_location_attribute' below. */
7867 static void
7868 add_AT_location_description (die, attr_kind, rtl)
7869 dw_die_ref die;
7870 enum dwarf_attribute attr_kind;
7871 register rtx rtl;
7873 /* Handle a special case. If we are about to output a location descriptor
7874 for a variable or parameter which has been optimized out of existence,
7875 don't do that. A variable which has been optimized out
7876 of existence will have a DECL_RTL value which denotes a pseudo-reg.
7877 Currently, in some rare cases, variables can have DECL_RTL values which
7878 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
7879 elsewhere in the compiler. We treat such cases as if the variable(s) in
7880 question had been optimized out of existence. */
7882 if (is_pseudo_reg (rtl)
7883 || (GET_CODE (rtl) == MEM
7884 && is_pseudo_reg (XEXP (rtl, 0)))
7885 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
7886 references the internal argument pointer (a pseudo) in a function
7887 where all references to the internal argument pointer were
7888 eliminated via the optimizers. */
7889 || (GET_CODE (rtl) == MEM
7890 && GET_CODE (XEXP (rtl, 0)) == PLUS
7891 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
7892 || (GET_CODE (rtl) == CONCAT
7893 && is_pseudo_reg (XEXP (rtl, 0))
7894 && is_pseudo_reg (XEXP (rtl, 1))))
7895 return;
7897 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
7900 /* Attach the specialized form of location attribute used for data
7901 members of struct and union types. In the special case of a
7902 FIELD_DECL node which represents a bit-field, the "offset" part
7903 of this special location descriptor must indicate the distance
7904 in bytes from the lowest-addressed byte of the containing struct
7905 or union type to the lowest-addressed byte of the "containing
7906 object" for the bit-field. (See the `field_byte_offset' function
7907 above).. For any given bit-field, the "containing object" is a
7908 hypothetical object (of some integral or enum type) within which
7909 the given bit-field lives. The type of this hypothetical
7910 "containing object" is always the same as the declared type of
7911 the individual bit-field itself (for GCC anyway... the DWARF
7912 spec doesn't actually mandate this). Note that it is the size
7913 (in bytes) of the hypothetical "containing object" which will
7914 be given in the DW_AT_byte_size attribute for this bit-field.
7915 (See the `byte_size_attribute' function below.) It is also used
7916 when calculating the value of the DW_AT_bit_offset attribute.
7917 (See the `bit_offset_attribute' function below). */
7919 static void
7920 add_data_member_location_attribute (die, decl)
7921 register dw_die_ref die;
7922 register tree decl;
7924 register unsigned long offset;
7925 register dw_loc_descr_ref loc_descr;
7926 register enum dwarf_location_atom op;
7928 if (TREE_CODE (decl) == TREE_VEC)
7929 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
7930 else
7931 offset = field_byte_offset (decl);
7933 /* The DWARF2 standard says that we should assume that the structure address
7934 is already on the stack, so we can specify a structure field address
7935 by using DW_OP_plus_uconst. */
7937 #ifdef MIPS_DEBUGGING_INFO
7938 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
7939 correctly. It works only if we leave the offset on the stack. */
7940 op = DW_OP_constu;
7941 #else
7942 op = DW_OP_plus_uconst;
7943 #endif
7945 loc_descr = new_loc_descr (op, offset, 0);
7946 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
7949 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
7950 does not have a "location" either in memory or in a register. These
7951 things can arise in GNU C when a constant is passed as an actual parameter
7952 to an inlined function. They can also arise in C++ where declared
7953 constants do not necessarily get memory "homes". */
7955 static void
7956 add_const_value_attribute (die, rtl)
7957 register dw_die_ref die;
7958 register rtx rtl;
7960 switch (GET_CODE (rtl))
7962 case CONST_INT:
7963 /* Note that a CONST_INT rtx could represent either an integer
7964 or a floating-point constant. A CONST_INT is used whenever
7965 the constant will fit into a single word. In all such
7966 cases, the original mode of the constant value is wiped
7967 out, and the CONST_INT rtx is assigned VOIDmode. */
7969 HOST_WIDE_INT val = INTVAL (rtl);
7971 /* ??? We really should be using HOST_WIDE_INT throughout. */
7972 if (val < 0)
7974 if ((long) val != val)
7975 abort ();
7976 add_AT_int (die, DW_AT_const_value, (long) val);
7978 else
7980 if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
7981 abort ();
7982 add_AT_int (die, DW_AT_const_value, (unsigned long) val);
7985 break;
7987 case CONST_DOUBLE:
7988 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
7989 floating-point constant. A CONST_DOUBLE is used whenever the
7990 constant requires more than one word in order to be adequately
7991 represented. We output CONST_DOUBLEs as blocks. */
7993 register enum machine_mode mode = GET_MODE (rtl);
7995 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
7997 register unsigned length = GET_MODE_SIZE (mode) / 4;
7998 long *array = (long *) xmalloc (sizeof (long) * length);
7999 REAL_VALUE_TYPE rv;
8001 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8002 switch (mode)
8004 case SFmode:
8005 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8006 break;
8008 case DFmode:
8009 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8010 break;
8012 case XFmode:
8013 case TFmode:
8014 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8015 break;
8017 default:
8018 abort ();
8021 add_AT_float (die, DW_AT_const_value, length, array);
8023 else
8025 /* ??? We really should be using HOST_WIDE_INT throughout. */
8026 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8027 abort ();
8028 add_AT_long_long (die, DW_AT_const_value,
8029 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8032 break;
8034 case CONST_STRING:
8035 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8036 break;
8038 case SYMBOL_REF:
8039 case LABEL_REF:
8040 case CONST:
8041 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8042 break;
8044 case PLUS:
8045 /* In cases where an inlined instance of an inline function is passed
8046 the address of an `auto' variable (which is local to the caller) we
8047 can get a situation where the DECL_RTL of the artificial local
8048 variable (for the inlining) which acts as a stand-in for the
8049 corresponding formal parameter (of the inline function) will look
8050 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8051 exactly a compile-time constant expression, but it isn't the address
8052 of the (artificial) local variable either. Rather, it represents the
8053 *value* which the artificial local variable always has during its
8054 lifetime. We currently have no way to represent such quasi-constant
8055 values in Dwarf, so for now we just punt and generate nothing. */
8056 break;
8058 default:
8059 /* No other kinds of rtx should be possible here. */
8060 abort ();
8065 /* Returns RTL for DECL indicating the location the debugger should
8066 use to find the value of DECL at runtime. Returns NULL_RTX if
8067 there is no such location, or if a satisfactory location could not
8068 be determined. */
8070 static rtx
8071 rtl_for_decl_location (decl)
8072 tree decl;
8074 register rtx rtl;
8076 /* This function should not be called with an abstract declaration,
8077 since such things have no location. */
8078 if (DECL_ABSTRACT (decl))
8079 abort ();
8081 /* Here we have to decide where we are going to say the parameter "lives"
8082 (as far as the debugger is concerned). We only have a couple of
8083 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8085 DECL_RTL normally indicates where the parameter lives during most of the
8086 activation of the function. If optimization is enabled however, this
8087 could be either NULL or else a pseudo-reg. Both of those cases indicate
8088 that the parameter doesn't really live anywhere (as far as the code
8089 generation parts of GCC are concerned) during most of the function's
8090 activation. That will happen (for example) if the parameter is never
8091 referenced within the function.
8093 We could just generate a location descriptor here for all non-NULL
8094 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8095 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8096 where DECL_RTL is NULL or is a pseudo-reg.
8098 Note however that we can only get away with using DECL_INCOMING_RTL as
8099 a backup substitute for DECL_RTL in certain limited cases. In cases
8100 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8101 we can be sure that the parameter was passed using the same type as it is
8102 declared to have within the function, and that its DECL_INCOMING_RTL
8103 points us to a place where a value of that type is passed.
8105 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8106 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8107 because in these cases DECL_INCOMING_RTL points us to a value of some
8108 type which is *different* from the type of the parameter itself. Thus,
8109 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8110 such cases, the debugger would end up (for example) trying to fetch a
8111 `float' from a place which actually contains the first part of a
8112 `double'. That would lead to really incorrect and confusing
8113 output at debug-time.
8115 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8116 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8117 are a couple of exceptions however. On little-endian machines we can
8118 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8119 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8120 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8121 when (on a little-endian machine) a non-prototyped function has a
8122 parameter declared to be of type `short' or `char'. In such cases,
8123 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8124 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8125 passed `int' value. If the debugger then uses that address to fetch
8126 a `short' or a `char' (on a little-endian machine) the result will be
8127 the correct data, so we allow for such exceptional cases below.
8129 Note that our goal here is to describe the place where the given formal
8130 parameter lives during most of the function's activation (i.e. between
8131 the end of the prologue and the start of the epilogue). We'll do that
8132 as best as we can. Note however that if the given formal parameter is
8133 modified sometime during the execution of the function, then a stack
8134 backtrace (at debug-time) will show the function as having been
8135 called with the *new* value rather than the value which was
8136 originally passed in. This happens rarely enough that it is not
8137 a major problem, but it *is* a problem, and I'd like to fix it.
8139 A future version of dwarf2out.c may generate two additional
8140 attributes for any given DW_TAG_formal_parameter DIE which will
8141 describe the "passed type" and the "passed location" for the
8142 given formal parameter in addition to the attributes we now
8143 generate to indicate the "declared type" and the "active
8144 location" for each parameter. This additional set of attributes
8145 could be used by debuggers for stack backtraces. Separately, note
8146 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8147 NULL also. This happens (for example) for inlined-instances of
8148 inline function formal parameters which are never referenced.
8149 This really shouldn't be happening. All PARM_DECL nodes should
8150 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8151 doesn't currently generate these values for inlined instances of
8152 inline function parameters, so when we see such cases, we are
8153 just out-of-luck for the time being (until integrate.c
8154 gets fixed). */
8156 /* Use DECL_RTL as the "location" unless we find something better. */
8157 rtl = DECL_RTL_IF_SET (decl);
8159 if (TREE_CODE (decl) == PARM_DECL)
8161 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8163 tree declared_type = type_main_variant (TREE_TYPE (decl));
8164 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8166 /* This decl represents a formal parameter which was optimized out.
8167 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8168 all* cases where (rtl == NULL_RTX) just below. */
8169 if (declared_type == passed_type)
8170 rtl = DECL_INCOMING_RTL (decl);
8171 else if (! BYTES_BIG_ENDIAN
8172 && TREE_CODE (declared_type) == INTEGER_TYPE
8173 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8174 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8175 rtl = DECL_INCOMING_RTL (decl);
8178 /* If the parm was passed in registers, but lives on the stack, then
8179 make a big endian correction if the mode of the type of the
8180 parameter is not the same as the mode of the rtl. */
8181 /* ??? This is the same series of checks that are made in dbxout.c before
8182 we reach the big endian correction code there. It isn't clear if all
8183 of these checks are necessary here, but keeping them all is the safe
8184 thing to do. */
8185 else if (GET_CODE (rtl) == MEM
8186 && XEXP (rtl, 0) != const0_rtx
8187 && ! CONSTANT_P (XEXP (rtl, 0))
8188 /* Not passed in memory. */
8189 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8190 /* Not passed by invisible reference. */
8191 && (GET_CODE (XEXP (rtl, 0)) != REG
8192 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8193 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8194 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8195 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8196 #endif
8198 /* Big endian correction check. */
8199 && BYTES_BIG_ENDIAN
8200 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8201 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8202 < UNITS_PER_WORD))
8204 int offset = (UNITS_PER_WORD
8205 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8206 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8207 plus_constant (XEXP (rtl, 0), offset));
8211 if (rtl != NULL_RTX)
8213 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8214 #ifdef LEAF_REG_REMAP
8215 if (current_function_uses_only_leaf_regs)
8216 leaf_renumber_regs_insn (rtl);
8217 #endif
8220 return rtl;
8223 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8224 data attribute for a variable or a parameter. We generate the
8225 DW_AT_const_value attribute only in those cases where the given variable
8226 or parameter does not have a true "location" either in memory or in a
8227 register. This can happen (for example) when a constant is passed as an
8228 actual argument in a call to an inline function. (It's possible that
8229 these things can crop up in other ways also.) Note that one type of
8230 constant value which can be passed into an inlined function is a constant
8231 pointer. This can happen for example if an actual argument in an inlined
8232 function call evaluates to a compile-time constant address. */
8234 static void
8235 add_location_or_const_value_attribute (die, decl)
8236 register dw_die_ref die;
8237 register tree decl;
8239 register rtx rtl;
8241 if (TREE_CODE (decl) == ERROR_MARK)
8242 return;
8244 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8245 abort ();
8247 rtl = rtl_for_decl_location (decl);
8248 if (rtl == NULL_RTX)
8249 return;
8251 switch (GET_CODE (rtl))
8253 case ADDRESSOF:
8254 /* The address of a variable that was optimized away; don't emit
8255 anything. */
8256 break;
8258 case CONST_INT:
8259 case CONST_DOUBLE:
8260 case CONST_STRING:
8261 case SYMBOL_REF:
8262 case LABEL_REF:
8263 case CONST:
8264 case PLUS:
8265 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8266 add_const_value_attribute (die, rtl);
8267 break;
8269 case MEM:
8270 case REG:
8271 case SUBREG:
8272 case CONCAT:
8273 add_AT_location_description (die, DW_AT_location, rtl);
8274 break;
8276 default:
8277 abort ();
8281 /* If we don't have a copy of this variable in memory for some reason (such
8282 as a C++ member constant that doesn't have an out-of-line definition),
8283 we should tell the debugger about the constant value. */
8285 static void
8286 tree_add_const_value_attribute (var_die, decl)
8287 dw_die_ref var_die;
8288 tree decl;
8290 tree init = DECL_INITIAL (decl);
8291 tree type = TREE_TYPE (decl);
8293 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8294 && initializer_constant_valid_p (init, type) == null_pointer_node)
8295 /* OK */;
8296 else
8297 return;
8299 switch (TREE_CODE (type))
8301 case INTEGER_TYPE:
8302 if (host_integerp (init, 0))
8303 add_AT_unsigned (var_die, DW_AT_const_value,
8304 TREE_INT_CST_LOW (init));
8305 else
8306 add_AT_long_long (var_die, DW_AT_const_value,
8307 TREE_INT_CST_HIGH (init),
8308 TREE_INT_CST_LOW (init));
8309 break;
8311 default:;
8315 /* Generate an DW_AT_name attribute given some string value to be included as
8316 the value of the attribute. */
8318 static inline void
8319 add_name_attribute (die, name_string)
8320 register dw_die_ref die;
8321 register const char *name_string;
8323 if (name_string != NULL && *name_string != 0)
8325 if (demangle_name_func)
8326 name_string = (*demangle_name_func) (name_string);
8328 add_AT_string (die, DW_AT_name, name_string);
8332 /* Given a tree node describing an array bound (either lower or upper) output
8333 a representation for that bound. */
8335 static void
8336 add_bound_info (subrange_die, bound_attr, bound)
8337 register dw_die_ref subrange_die;
8338 register enum dwarf_attribute bound_attr;
8339 register tree bound;
8341 /* If this is an Ada unconstrained array type, then don't emit any debug
8342 info because the array bounds are unknown. They are parameterized when
8343 the type is instantiated. */
8344 if (contains_placeholder_p (bound))
8345 return;
8347 switch (TREE_CODE (bound))
8349 case ERROR_MARK:
8350 return;
8352 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8353 case INTEGER_CST:
8354 if (! host_integerp (bound, 0)
8355 || (bound_attr == DW_AT_lower_bound
8356 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8357 || (is_fortran () && integer_onep (bound)))))
8358 /* use the default */
8360 else
8361 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8362 break;
8364 case CONVERT_EXPR:
8365 case NOP_EXPR:
8366 case NON_LVALUE_EXPR:
8367 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8368 break;
8370 case SAVE_EXPR:
8371 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8372 access the upper bound values may be bogus. If they refer to a
8373 register, they may only describe how to get at these values at the
8374 points in the generated code right after they have just been
8375 computed. Worse yet, in the typical case, the upper bound values
8376 will not even *be* computed in the optimized code (though the
8377 number of elements will), so these SAVE_EXPRs are entirely
8378 bogus. In order to compensate for this fact, we check here to see
8379 if optimization is enabled, and if so, we don't add an attribute
8380 for the (unknown and unknowable) upper bound. This should not
8381 cause too much trouble for existing (stupid?) debuggers because
8382 they have to deal with empty upper bounds location descriptions
8383 anyway in order to be able to deal with incomplete array types.
8384 Of course an intelligent debugger (GDB?) should be able to
8385 comprehend that a missing upper bound specification in a array
8386 type used for a storage class `auto' local array variable
8387 indicates that the upper bound is both unknown (at compile- time)
8388 and unknowable (at run-time) due to optimization.
8390 We assume that a MEM rtx is safe because gcc wouldn't put the
8391 value there unless it was going to be used repeatedly in the
8392 function, i.e. for cleanups. */
8393 if (SAVE_EXPR_RTL (bound)
8394 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8396 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8397 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8398 register rtx loc = SAVE_EXPR_RTL (bound);
8400 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8401 it references an outer function's frame. */
8403 if (GET_CODE (loc) == MEM)
8405 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8407 if (XEXP (loc, 0) != new_addr)
8408 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8411 add_AT_flag (decl_die, DW_AT_artificial, 1);
8412 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8413 add_AT_location_description (decl_die, DW_AT_location, loc);
8414 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8417 /* Else leave out the attribute. */
8418 break;
8420 case VAR_DECL:
8421 case PARM_DECL:
8423 dw_die_ref decl_die = lookup_decl_die (bound);
8425 /* ??? Can this happen, or should the variable have been bound
8426 first? Probably it can, since I imagine that we try to create
8427 the types of parameters in the order in which they exist in
8428 the list, and won't have created a forward reference to a
8429 later parameter. */
8430 if (decl_die != NULL)
8431 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8432 break;
8435 default:
8437 /* Otherwise try to create a stack operation procedure to
8438 evaluate the value of the array bound. */
8440 dw_die_ref ctx, decl_die;
8441 dw_loc_descr_ref loc;
8443 /* If the CURRENT_FUNCTION_DECL is abstract, then we cannot
8444 compute the array bound based on the location of the BOUND,
8445 since the BOUND does not really exist. Therefore, we
8446 simply omit the bound information.
8448 Ideally, we would do better, and express the computation in
8449 some other way. */
8450 if (DECL_ABSTRACT (current_function_decl))
8451 break;
8453 loc = loc_descriptor_from_tree (bound, 0);
8454 if (loc == NULL)
8455 break;
8457 ctx = lookup_decl_die (current_function_decl);
8459 decl_die = new_die (DW_TAG_variable, ctx);
8460 add_AT_flag (decl_die, DW_AT_artificial, 1);
8461 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8462 add_AT_loc (decl_die, DW_AT_location, loc);
8464 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8465 break;
8470 /* Note that the block of subscript information for an array type also
8471 includes information about the element type of type given array type. */
8473 static void
8474 add_subscript_info (type_die, type)
8475 register dw_die_ref type_die;
8476 register tree type;
8478 #ifndef MIPS_DEBUGGING_INFO
8479 register unsigned dimension_number;
8480 #endif
8481 register tree lower, upper;
8482 register dw_die_ref subrange_die;
8484 /* The GNU compilers represent multidimensional array types as sequences of
8485 one dimensional array types whose element types are themselves array
8486 types. Here we squish that down, so that each multidimensional array
8487 type gets only one array_type DIE in the Dwarf debugging info. The draft
8488 Dwarf specification say that we are allowed to do this kind of
8489 compression in C (because there is no difference between an array or
8490 arrays and a multidimensional array in C) but for other source languages
8491 (e.g. Ada) we probably shouldn't do this. */
8493 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8494 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8495 We work around this by disabling this feature. See also
8496 gen_array_type_die. */
8497 #ifndef MIPS_DEBUGGING_INFO
8498 for (dimension_number = 0;
8499 TREE_CODE (type) == ARRAY_TYPE;
8500 type = TREE_TYPE (type), dimension_number++)
8502 #endif
8503 register tree domain = TYPE_DOMAIN (type);
8505 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8506 and (in GNU C only) variable bounds. Handle all three forms
8507 here. */
8508 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8509 if (domain)
8511 /* We have an array type with specified bounds. */
8512 lower = TYPE_MIN_VALUE (domain);
8513 upper = TYPE_MAX_VALUE (domain);
8515 /* define the index type. */
8516 if (TREE_TYPE (domain))
8518 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8519 TREE_TYPE field. We can't emit debug info for this
8520 because it is an unnamed integral type. */
8521 if (TREE_CODE (domain) == INTEGER_TYPE
8522 && TYPE_NAME (domain) == NULL_TREE
8523 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8524 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8526 else
8527 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8528 type_die);
8531 /* ??? If upper is NULL, the array has unspecified length,
8532 but it does have a lower bound. This happens with Fortran
8533 dimension arr(N:*)
8534 Since the debugger is definitely going to need to know N
8535 to produce useful results, go ahead and output the lower
8536 bound solo, and hope the debugger can cope. */
8538 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8539 if (upper)
8540 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8542 else
8543 /* We have an array type with an unspecified length. The DWARF-2
8544 spec does not say how to handle this; let's just leave out the
8545 bounds. */
8548 #ifndef MIPS_DEBUGGING_INFO
8550 #endif
8553 static void
8554 add_byte_size_attribute (die, tree_node)
8555 dw_die_ref die;
8556 register tree tree_node;
8558 register unsigned size;
8560 switch (TREE_CODE (tree_node))
8562 case ERROR_MARK:
8563 size = 0;
8564 break;
8565 case ENUMERAL_TYPE:
8566 case RECORD_TYPE:
8567 case UNION_TYPE:
8568 case QUAL_UNION_TYPE:
8569 size = int_size_in_bytes (tree_node);
8570 break;
8571 case FIELD_DECL:
8572 /* For a data member of a struct or union, the DW_AT_byte_size is
8573 generally given as the number of bytes normally allocated for an
8574 object of the *declared* type of the member itself. This is true
8575 even for bit-fields. */
8576 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8577 break;
8578 default:
8579 abort ();
8582 /* Note that `size' might be -1 when we get to this point. If it is, that
8583 indicates that the byte size of the entity in question is variable. We
8584 have no good way of expressing this fact in Dwarf at the present time,
8585 so just let the -1 pass on through. */
8587 add_AT_unsigned (die, DW_AT_byte_size, size);
8590 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8591 which specifies the distance in bits from the highest order bit of the
8592 "containing object" for the bit-field to the highest order bit of the
8593 bit-field itself.
8595 For any given bit-field, the "containing object" is a hypothetical
8596 object (of some integral or enum type) within which the given bit-field
8597 lives. The type of this hypothetical "containing object" is always the
8598 same as the declared type of the individual bit-field itself. The
8599 determination of the exact location of the "containing object" for a
8600 bit-field is rather complicated. It's handled by the
8601 `field_byte_offset' function (above).
8603 Note that it is the size (in bytes) of the hypothetical "containing object"
8604 which will be given in the DW_AT_byte_size attribute for this bit-field.
8605 (See `byte_size_attribute' above). */
8607 static inline void
8608 add_bit_offset_attribute (die, decl)
8609 register dw_die_ref die;
8610 register tree decl;
8612 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8613 tree type = DECL_BIT_FIELD_TYPE (decl);
8614 HOST_WIDE_INT bitpos_int;
8615 HOST_WIDE_INT highest_order_object_bit_offset;
8616 HOST_WIDE_INT highest_order_field_bit_offset;
8617 HOST_WIDE_INT unsigned bit_offset;
8619 /* Must be a field and a bit field. */
8620 if (!type
8621 || TREE_CODE (decl) != FIELD_DECL)
8622 abort ();
8624 /* We can't yet handle bit-fields whose offsets are variable, so if we
8625 encounter such things, just return without generating any attribute
8626 whatsoever. Likewise for variable or too large size. */
8627 if (! host_integerp (bit_position (decl), 0)
8628 || ! host_integerp (DECL_SIZE (decl), 1))
8629 return;
8631 bitpos_int = int_bit_position (decl);
8633 /* Note that the bit offset is always the distance (in bits) from the
8634 highest-order bit of the "containing object" to the highest-order bit of
8635 the bit-field itself. Since the "high-order end" of any object or field
8636 is different on big-endian and little-endian machines, the computation
8637 below must take account of these differences. */
8638 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8639 highest_order_field_bit_offset = bitpos_int;
8641 if (! BYTES_BIG_ENDIAN)
8643 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8644 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8647 bit_offset
8648 = (! BYTES_BIG_ENDIAN
8649 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8650 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8652 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8655 /* For a FIELD_DECL node which represents a bit field, output an attribute
8656 which specifies the length in bits of the given field. */
8658 static inline void
8659 add_bit_size_attribute (die, decl)
8660 register dw_die_ref die;
8661 register tree decl;
8663 /* Must be a field and a bit field. */
8664 if (TREE_CODE (decl) != FIELD_DECL
8665 || ! DECL_BIT_FIELD_TYPE (decl))
8666 abort ();
8668 if (host_integerp (DECL_SIZE (decl), 1))
8669 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8672 /* If the compiled language is ANSI C, then add a 'prototyped'
8673 attribute, if arg types are given for the parameters of a function. */
8675 static inline void
8676 add_prototyped_attribute (die, func_type)
8677 register dw_die_ref die;
8678 register tree func_type;
8680 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8681 && TYPE_ARG_TYPES (func_type) != NULL)
8682 add_AT_flag (die, DW_AT_prototyped, 1);
8685 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8686 by looking in either the type declaration or object declaration
8687 equate table. */
8689 static inline void
8690 add_abstract_origin_attribute (die, origin)
8691 register dw_die_ref die;
8692 register tree origin;
8694 dw_die_ref origin_die = NULL;
8696 if (TREE_CODE (origin) != FUNCTION_DECL)
8698 /* We may have gotten separated from the block for the inlined
8699 function, if we're in an exception handler or some such; make
8700 sure that the abstract function has been written out.
8702 Doing this for nested functions is wrong, however; functions are
8703 distinct units, and our context might not even be inline. */
8704 tree fn = origin;
8705 if (TYPE_P (fn))
8706 fn = TYPE_STUB_DECL (fn);
8707 fn = decl_function_context (fn);
8708 if (fn)
8709 dwarf2out_abstract_function (fn);
8712 if (DECL_P (origin))
8713 origin_die = lookup_decl_die (origin);
8714 else if (TYPE_P (origin))
8715 origin_die = lookup_type_die (origin);
8717 if (origin_die == NULL)
8718 abort ();
8720 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8723 /* We do not currently support the pure_virtual attribute. */
8725 static inline void
8726 add_pure_or_virtual_attribute (die, func_decl)
8727 register dw_die_ref die;
8728 register tree func_decl;
8730 if (DECL_VINDEX (func_decl))
8732 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8734 if (host_integerp (DECL_VINDEX (func_decl), 0))
8735 add_AT_loc (die, DW_AT_vtable_elem_location,
8736 new_loc_descr (DW_OP_constu,
8737 tree_low_cst (DECL_VINDEX (func_decl), 0),
8738 0));
8740 /* GNU extension: Record what type this method came from originally. */
8741 if (debug_info_level > DINFO_LEVEL_TERSE)
8742 add_AT_die_ref (die, DW_AT_containing_type,
8743 lookup_type_die (DECL_CONTEXT (func_decl)));
8747 /* Add source coordinate attributes for the given decl. */
8749 static void
8750 add_src_coords_attributes (die, decl)
8751 register dw_die_ref die;
8752 register tree decl;
8754 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
8756 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8757 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8760 /* Add an DW_AT_name attribute and source coordinate attribute for the
8761 given decl, but only if it actually has a name. */
8763 static void
8764 add_name_and_src_coords_attributes (die, decl)
8765 register dw_die_ref die;
8766 register tree decl;
8768 register tree decl_name;
8770 decl_name = DECL_NAME (decl);
8771 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8773 add_name_attribute (die, dwarf2_name (decl, 0));
8774 if (! DECL_ARTIFICIAL (decl))
8775 add_src_coords_attributes (die, decl);
8777 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8778 && TREE_PUBLIC (decl)
8779 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
8780 && !DECL_ABSTRACT (decl))
8781 add_AT_string (die, DW_AT_MIPS_linkage_name,
8782 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8786 /* Push a new declaration scope. */
8788 static void
8789 push_decl_scope (scope)
8790 tree scope;
8792 /* Make room in the decl_scope_table, if necessary. */
8793 if (decl_scope_table_allocated == decl_scope_depth)
8795 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
8796 decl_scope_table
8797 = (tree *) xrealloc (decl_scope_table,
8798 decl_scope_table_allocated * sizeof (tree));
8801 decl_scope_table[decl_scope_depth] = scope;
8802 decl_scope_depth++;
8805 /* Pop a declaration scope. */
8806 static inline void
8807 pop_decl_scope ()
8809 if (decl_scope_depth <= 0)
8810 abort ();
8811 --decl_scope_depth;
8814 /* Return the DIE for the scope that immediately contains this type.
8815 Non-named types get global scope. Named types nested in other
8816 types get their containing scope if it's open, or global scope
8817 otherwise. All other types (i.e. function-local named types) get
8818 the current active scope. */
8820 static dw_die_ref
8821 scope_die_for (t, context_die)
8822 register tree t;
8823 register dw_die_ref context_die;
8825 register dw_die_ref scope_die = NULL;
8826 register tree containing_scope;
8827 register int i;
8829 /* Non-types always go in the current scope. */
8830 if (! TYPE_P (t))
8831 abort ();
8833 containing_scope = TYPE_CONTEXT (t);
8835 /* Ignore namespaces for the moment. */
8836 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
8837 containing_scope = NULL_TREE;
8839 /* Ignore function type "scopes" from the C frontend. They mean that
8840 a tagged type is local to a parmlist of a function declarator, but
8841 that isn't useful to DWARF. */
8842 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
8843 containing_scope = NULL_TREE;
8845 if (containing_scope == NULL_TREE)
8846 scope_die = comp_unit_die;
8847 else if (TYPE_P (containing_scope))
8849 /* For types, we can just look up the appropriate DIE. But
8850 first we check to see if we're in the middle of emitting it
8851 so we know where the new DIE should go. */
8853 for (i = decl_scope_depth - 1; i >= 0; --i)
8854 if (decl_scope_table[i] == containing_scope)
8855 break;
8857 if (i < 0)
8859 if (debug_info_level > DINFO_LEVEL_TERSE
8860 && !TREE_ASM_WRITTEN (containing_scope))
8861 abort ();
8863 /* If none of the current dies are suitable, we get file scope. */
8864 scope_die = comp_unit_die;
8866 else
8867 scope_die = lookup_type_die (containing_scope);
8869 else
8870 scope_die = context_die;
8872 return scope_die;
8875 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
8877 static inline int local_scope_p PARAMS ((dw_die_ref));
8878 static inline int
8879 local_scope_p (context_die)
8880 dw_die_ref context_die;
8882 for (; context_die; context_die = context_die->die_parent)
8883 if (context_die->die_tag == DW_TAG_inlined_subroutine
8884 || context_die->die_tag == DW_TAG_subprogram)
8885 return 1;
8886 return 0;
8889 /* Returns nonzero iff CONTEXT_DIE is a class. */
8891 static inline int class_scope_p PARAMS ((dw_die_ref));
8892 static inline int
8893 class_scope_p (context_die)
8894 dw_die_ref context_die;
8896 return (context_die
8897 && (context_die->die_tag == DW_TAG_structure_type
8898 || context_die->die_tag == DW_TAG_union_type));
8901 /* Many forms of DIEs require a "type description" attribute. This
8902 routine locates the proper "type descriptor" die for the type given
8903 by 'type', and adds an DW_AT_type attribute below the given die. */
8905 static void
8906 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
8907 register dw_die_ref object_die;
8908 register tree type;
8909 register int decl_const;
8910 register int decl_volatile;
8911 register dw_die_ref context_die;
8913 register enum tree_code code = TREE_CODE (type);
8914 register dw_die_ref type_die = NULL;
8916 /* ??? If this type is an unnamed subrange type of an integral or
8917 floating-point type, use the inner type. This is because we have no
8918 support for unnamed types in base_type_die. This can happen if this is
8919 an Ada subrange type. Correct solution is emit a subrange type die. */
8920 if ((code == INTEGER_TYPE || code == REAL_TYPE)
8921 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
8922 type = TREE_TYPE (type), code = TREE_CODE (type);
8924 if (code == ERROR_MARK)
8925 return;
8927 /* Handle a special case. For functions whose return type is void, we
8928 generate *no* type attribute. (Note that no object may have type
8929 `void', so this only applies to function return types). */
8930 if (code == VOID_TYPE)
8931 return;
8933 type_die = modified_type_die (type,
8934 decl_const || TYPE_READONLY (type),
8935 decl_volatile || TYPE_VOLATILE (type),
8936 context_die);
8937 if (type_die != NULL)
8938 add_AT_die_ref (object_die, DW_AT_type, type_die);
8941 /* Given a tree pointer to a struct, class, union, or enum type node, return
8942 a pointer to the (string) tag name for the given type, or zero if the type
8943 was declared without a tag. */
8945 static const char *
8946 type_tag (type)
8947 register tree type;
8949 register const char *name = 0;
8951 if (TYPE_NAME (type) != 0)
8953 register tree t = 0;
8955 /* Find the IDENTIFIER_NODE for the type name. */
8956 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
8957 t = TYPE_NAME (type);
8959 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
8960 a TYPE_DECL node, regardless of whether or not a `typedef' was
8961 involved. */
8962 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8963 && ! DECL_IGNORED_P (TYPE_NAME (type)))
8964 t = DECL_NAME (TYPE_NAME (type));
8966 /* Now get the name as a string, or invent one. */
8967 if (t != 0)
8968 name = IDENTIFIER_POINTER (t);
8971 return (name == 0 || *name == '\0') ? 0 : name;
8974 /* Return the type associated with a data member, make a special check
8975 for bit field types. */
8977 static inline tree
8978 member_declared_type (member)
8979 register tree member;
8981 return (DECL_BIT_FIELD_TYPE (member)
8982 ? DECL_BIT_FIELD_TYPE (member)
8983 : TREE_TYPE (member));
8986 /* Get the decl's label, as described by its RTL. This may be different
8987 from the DECL_NAME name used in the source file. */
8989 #if 0
8990 static const char *
8991 decl_start_label (decl)
8992 register tree decl;
8994 rtx x;
8995 const char *fnname;
8996 x = DECL_RTL (decl);
8997 if (GET_CODE (x) != MEM)
8998 abort ();
9000 x = XEXP (x, 0);
9001 if (GET_CODE (x) != SYMBOL_REF)
9002 abort ();
9004 fnname = XSTR (x, 0);
9005 return fnname;
9007 #endif
9009 /* These routines generate the internal representation of the DIE's for
9010 the compilation unit. Debugging information is collected by walking
9011 the declaration trees passed in from dwarf2out_decl(). */
9013 static void
9014 gen_array_type_die (type, context_die)
9015 register tree type;
9016 register dw_die_ref context_die;
9018 register dw_die_ref scope_die = scope_die_for (type, context_die);
9019 register dw_die_ref array_die;
9020 register tree element_type;
9022 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9023 the inner array type comes before the outer array type. Thus we must
9024 call gen_type_die before we call new_die. See below also. */
9025 #ifdef MIPS_DEBUGGING_INFO
9026 gen_type_die (TREE_TYPE (type), context_die);
9027 #endif
9029 array_die = new_die (DW_TAG_array_type, scope_die);
9031 #if 0
9032 /* We default the array ordering. SDB will probably do
9033 the right things even if DW_AT_ordering is not present. It's not even
9034 an issue until we start to get into multidimensional arrays anyway. If
9035 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9036 then we'll have to put the DW_AT_ordering attribute back in. (But if
9037 and when we find out that we need to put these in, we will only do so
9038 for multidimensional arrays. */
9039 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9040 #endif
9042 #ifdef MIPS_DEBUGGING_INFO
9043 /* The SGI compilers handle arrays of unknown bound by setting
9044 AT_declaration and not emitting any subrange DIEs. */
9045 if (! TYPE_DOMAIN (type))
9046 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9047 else
9048 #endif
9049 add_subscript_info (array_die, type);
9051 add_name_attribute (array_die, type_tag (type));
9052 equate_type_number_to_die (type, array_die);
9054 /* Add representation of the type of the elements of this array type. */
9055 element_type = TREE_TYPE (type);
9057 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9058 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9059 We work around this by disabling this feature. See also
9060 add_subscript_info. */
9061 #ifndef MIPS_DEBUGGING_INFO
9062 while (TREE_CODE (element_type) == ARRAY_TYPE)
9063 element_type = TREE_TYPE (element_type);
9065 gen_type_die (element_type, context_die);
9066 #endif
9068 add_type_attribute (array_die, element_type, 0, 0, context_die);
9071 static void
9072 gen_set_type_die (type, context_die)
9073 register tree type;
9074 register dw_die_ref context_die;
9076 register dw_die_ref type_die
9077 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9079 equate_type_number_to_die (type, type_die);
9080 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9083 #if 0
9084 static void
9085 gen_entry_point_die (decl, context_die)
9086 register tree decl;
9087 register dw_die_ref context_die;
9089 register tree origin = decl_ultimate_origin (decl);
9090 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9091 if (origin != NULL)
9092 add_abstract_origin_attribute (decl_die, origin);
9093 else
9095 add_name_and_src_coords_attributes (decl_die, decl);
9096 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9097 0, 0, context_die);
9100 if (DECL_ABSTRACT (decl))
9101 equate_decl_number_to_die (decl, decl_die);
9102 else
9103 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9105 #endif
9107 /* Remember a type in the incomplete_types_list. */
9109 static void
9110 add_incomplete_type (type)
9111 tree type;
9113 if (incomplete_types == incomplete_types_allocated)
9115 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9116 incomplete_types_list
9117 = (tree *) xrealloc (incomplete_types_list,
9118 sizeof (tree) * incomplete_types_allocated);
9121 incomplete_types_list[incomplete_types++] = type;
9124 /* Walk through the list of incomplete types again, trying once more to
9125 emit full debugging info for them. */
9127 static void
9128 retry_incomplete_types ()
9130 register tree type;
9132 while (incomplete_types)
9134 --incomplete_types;
9135 type = incomplete_types_list[incomplete_types];
9136 gen_type_die (type, comp_unit_die);
9140 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9142 static void
9143 gen_inlined_enumeration_type_die (type, context_die)
9144 register tree type;
9145 register dw_die_ref context_die;
9147 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9148 context_die);
9149 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9150 be incomplete and such types are not marked. */
9151 add_abstract_origin_attribute (type_die, type);
9154 /* Generate a DIE to represent an inlined instance of a structure type. */
9156 static void
9157 gen_inlined_structure_type_die (type, context_die)
9158 register tree type;
9159 register dw_die_ref context_die;
9161 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9163 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9164 be incomplete and such types are not marked. */
9165 add_abstract_origin_attribute (type_die, type);
9168 /* Generate a DIE to represent an inlined instance of a union type. */
9170 static void
9171 gen_inlined_union_type_die (type, context_die)
9172 register tree type;
9173 register dw_die_ref context_die;
9175 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9177 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9178 be incomplete and such types are not marked. */
9179 add_abstract_origin_attribute (type_die, type);
9182 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9183 include all of the information about the enumeration values also. Each
9184 enumerated type name/value is listed as a child of the enumerated type
9185 DIE. */
9187 static void
9188 gen_enumeration_type_die (type, context_die)
9189 register tree type;
9190 register dw_die_ref context_die;
9192 register dw_die_ref type_die = lookup_type_die (type);
9194 if (type_die == NULL)
9196 type_die = new_die (DW_TAG_enumeration_type,
9197 scope_die_for (type, context_die));
9198 equate_type_number_to_die (type, type_die);
9199 add_name_attribute (type_die, type_tag (type));
9201 else if (! TYPE_SIZE (type))
9202 return;
9203 else
9204 remove_AT (type_die, DW_AT_declaration);
9206 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9207 given enum type is incomplete, do not generate the DW_AT_byte_size
9208 attribute or the DW_AT_element_list attribute. */
9209 if (TYPE_SIZE (type))
9211 register tree link;
9213 TREE_ASM_WRITTEN (type) = 1;
9214 add_byte_size_attribute (type_die, type);
9215 if (TYPE_STUB_DECL (type) != NULL_TREE)
9216 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9218 /* If the first reference to this type was as the return type of an
9219 inline function, then it may not have a parent. Fix this now. */
9220 if (type_die->die_parent == NULL)
9221 add_child_die (scope_die_for (type, context_die), type_die);
9223 for (link = TYPE_FIELDS (type);
9224 link != NULL; link = TREE_CHAIN (link))
9226 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9228 add_name_attribute (enum_die,
9229 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9231 if (host_integerp (TREE_VALUE (link), 0))
9233 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9234 add_AT_int (enum_die, DW_AT_const_value,
9235 tree_low_cst (TREE_VALUE (link), 0));
9236 else
9237 add_AT_unsigned (enum_die, DW_AT_const_value,
9238 tree_low_cst (TREE_VALUE (link), 0));
9242 else
9243 add_AT_flag (type_die, DW_AT_declaration, 1);
9246 /* Generate a DIE to represent either a real live formal parameter decl or to
9247 represent just the type of some formal parameter position in some function
9248 type.
9250 Note that this routine is a bit unusual because its argument may be a
9251 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9252 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9253 node. If it's the former then this function is being called to output a
9254 DIE to represent a formal parameter object (or some inlining thereof). If
9255 it's the latter, then this function is only being called to output a
9256 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9257 argument type of some subprogram type. */
9259 static dw_die_ref
9260 gen_formal_parameter_die (node, context_die)
9261 register tree node;
9262 register dw_die_ref context_die;
9264 register dw_die_ref parm_die
9265 = new_die (DW_TAG_formal_parameter, context_die);
9266 register tree origin;
9268 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9270 case 'd':
9271 origin = decl_ultimate_origin (node);
9272 if (origin != NULL)
9273 add_abstract_origin_attribute (parm_die, origin);
9274 else
9276 add_name_and_src_coords_attributes (parm_die, node);
9277 add_type_attribute (parm_die, TREE_TYPE (node),
9278 TREE_READONLY (node),
9279 TREE_THIS_VOLATILE (node),
9280 context_die);
9281 if (DECL_ARTIFICIAL (node))
9282 add_AT_flag (parm_die, DW_AT_artificial, 1);
9285 equate_decl_number_to_die (node, parm_die);
9286 if (! DECL_ABSTRACT (node))
9287 add_location_or_const_value_attribute (parm_die, node);
9289 break;
9291 case 't':
9292 /* We were called with some kind of a ..._TYPE node. */
9293 add_type_attribute (parm_die, node, 0, 0, context_die);
9294 break;
9296 default:
9297 abort ();
9300 return parm_die;
9303 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9304 at the end of an (ANSI prototyped) formal parameters list. */
9306 static void
9307 gen_unspecified_parameters_die (decl_or_type, context_die)
9308 register tree decl_or_type ATTRIBUTE_UNUSED;
9309 register dw_die_ref context_die;
9311 new_die (DW_TAG_unspecified_parameters, context_die);
9314 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9315 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9316 parameters as specified in some function type specification (except for
9317 those which appear as part of a function *definition*). */
9319 static void
9320 gen_formal_types_die (function_or_method_type, context_die)
9321 register tree function_or_method_type;
9322 register dw_die_ref context_die;
9324 register tree link;
9325 register tree formal_type = NULL;
9326 register tree first_parm_type;
9327 tree arg;
9329 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9331 arg = DECL_ARGUMENTS (function_or_method_type);
9332 function_or_method_type = TREE_TYPE (function_or_method_type);
9334 else
9335 arg = NULL_TREE;
9337 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9339 /* Make our first pass over the list of formal parameter types and output a
9340 DW_TAG_formal_parameter DIE for each one. */
9341 for (link = first_parm_type; link; )
9343 register dw_die_ref parm_die;
9345 formal_type = TREE_VALUE (link);
9346 if (formal_type == void_type_node)
9347 break;
9349 /* Output a (nameless) DIE to represent the formal parameter itself. */
9350 parm_die = gen_formal_parameter_die (formal_type, context_die);
9351 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9352 && link == first_parm_type)
9353 || (arg && DECL_ARTIFICIAL (arg)))
9354 add_AT_flag (parm_die, DW_AT_artificial, 1);
9356 link = TREE_CHAIN (link);
9357 if (arg)
9358 arg = TREE_CHAIN (arg);
9361 /* If this function type has an ellipsis, add a
9362 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9363 if (formal_type != void_type_node)
9364 gen_unspecified_parameters_die (function_or_method_type, context_die);
9366 /* Make our second (and final) pass over the list of formal parameter types
9367 and output DIEs to represent those types (as necessary). */
9368 for (link = TYPE_ARG_TYPES (function_or_method_type);
9369 link;
9370 link = TREE_CHAIN (link))
9372 formal_type = TREE_VALUE (link);
9373 if (formal_type == void_type_node)
9374 break;
9376 gen_type_die (formal_type, context_die);
9380 /* We want to generate the DIE for TYPE so that we can generate the
9381 die for MEMBER, which has been defined; we will need to refer back
9382 to the member declaration nested within TYPE. If we're trying to
9383 generate minimal debug info for TYPE, processing TYPE won't do the
9384 trick; we need to attach the member declaration by hand. */
9386 static void
9387 gen_type_die_for_member (type, member, context_die)
9388 tree type, member;
9389 dw_die_ref context_die;
9391 gen_type_die (type, context_die);
9393 /* If we're trying to avoid duplicate debug info, we may not have
9394 emitted the member decl for this function. Emit it now. */
9395 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9396 && ! lookup_decl_die (member))
9398 if (decl_ultimate_origin (member))
9399 abort ();
9401 push_decl_scope (type);
9402 if (TREE_CODE (member) == FUNCTION_DECL)
9403 gen_subprogram_die (member, lookup_type_die (type));
9404 else
9405 gen_variable_die (member, lookup_type_die (type));
9406 pop_decl_scope ();
9410 /* Generate the DWARF2 info for the "abstract" instance
9411 of a function which we may later generate inlined and/or
9412 out-of-line instances of. */
9414 void
9415 dwarf2out_abstract_function (decl)
9416 tree decl;
9418 register dw_die_ref old_die;
9419 tree save_fn;
9420 tree context;
9421 int was_abstract = DECL_ABSTRACT (decl);
9423 /* Make sure we have the actual abstract inline, not a clone. */
9424 decl = DECL_ORIGIN (decl);
9426 old_die = lookup_decl_die (decl);
9427 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9428 /* We've already generated the abstract instance. */
9429 return;
9431 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9432 we don't get confused by DECL_ABSTRACT. */
9433 context = decl_class_context (decl);
9434 if (context)
9435 gen_type_die_for_member
9436 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9438 /* Pretend we've just finished compiling this function. */
9439 save_fn = current_function_decl;
9440 current_function_decl = decl;
9442 set_decl_abstract_flags (decl, 1);
9443 dwarf2out_decl (decl);
9444 if (! was_abstract)
9445 set_decl_abstract_flags (decl, 0);
9447 current_function_decl = save_fn;
9450 /* Generate a DIE to represent a declared function (either file-scope or
9451 block-local). */
9453 static void
9454 gen_subprogram_die (decl, context_die)
9455 register tree decl;
9456 register dw_die_ref context_die;
9458 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9459 register tree origin = decl_ultimate_origin (decl);
9460 register dw_die_ref subr_die;
9461 register rtx fp_reg;
9462 register tree fn_arg_types;
9463 register tree outer_scope;
9464 register dw_die_ref old_die = lookup_decl_die (decl);
9465 register int declaration = (current_function_decl != decl
9466 || class_scope_p (context_die));
9468 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9469 be true, if we started to generate the abstract instance of an inline,
9470 decided to output its containing class, and proceeded to emit the
9471 declaration of the inline from the member list for the class. In that
9472 case, `declaration' takes priority; we'll get back to the abstract
9473 instance when we're done with the class. */
9475 /* The class-scope declaration DIE must be the primary DIE. */
9476 if (origin && declaration && class_scope_p (context_die))
9478 origin = NULL;
9479 if (old_die)
9480 abort ();
9483 if (origin != NULL)
9485 if (declaration && ! local_scope_p (context_die))
9486 abort ();
9488 /* Fixup die_parent for the abstract instance of a nested
9489 inline function. */
9490 if (old_die && old_die->die_parent == NULL)
9491 add_child_die (context_die, old_die);
9493 subr_die = new_die (DW_TAG_subprogram, context_die);
9494 add_abstract_origin_attribute (subr_die, origin);
9496 else if (old_die)
9498 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9500 if (!get_AT_flag (old_die, DW_AT_declaration)
9501 /* We can have a normal definition following an inline one in the
9502 case of redefinition of GNU C extern inlines.
9503 It seems reasonable to use AT_specification in this case. */
9504 && !get_AT_unsigned (old_die, DW_AT_inline))
9506 /* ??? This can happen if there is a bug in the program, for
9507 instance, if it has duplicate function definitions. Ideally,
9508 we should detect this case and ignore it. For now, if we have
9509 already reported an error, any error at all, then assume that
9510 we got here because of a input error, not a dwarf2 bug. */
9511 if (errorcount)
9512 return;
9513 abort ();
9516 /* If the definition comes from the same place as the declaration,
9517 maybe use the old DIE. We always want the DIE for this function
9518 that has the *_pc attributes to be under comp_unit_die so the
9519 debugger can find it. We also need to do this for abstract
9520 instances of inlines, since the spec requires the out-of-line copy
9521 to have the same parent. For local class methods, this doesn't
9522 apply; we just use the old DIE. */
9523 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9524 && (DECL_ARTIFICIAL (decl)
9525 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9526 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9527 == (unsigned) DECL_SOURCE_LINE (decl)))))
9529 subr_die = old_die;
9531 /* Clear out the declaration attribute and the parm types. */
9532 remove_AT (subr_die, DW_AT_declaration);
9533 remove_children (subr_die);
9535 else
9537 subr_die = new_die (DW_TAG_subprogram, context_die);
9538 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9539 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9540 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9541 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9542 != (unsigned) DECL_SOURCE_LINE (decl))
9543 add_AT_unsigned
9544 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9547 else
9549 subr_die = new_die (DW_TAG_subprogram, context_die);
9551 if (TREE_PUBLIC (decl))
9552 add_AT_flag (subr_die, DW_AT_external, 1);
9554 add_name_and_src_coords_attributes (subr_die, decl);
9555 if (debug_info_level > DINFO_LEVEL_TERSE)
9557 register tree type = TREE_TYPE (decl);
9559 add_prototyped_attribute (subr_die, type);
9560 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9563 add_pure_or_virtual_attribute (subr_die, decl);
9564 if (DECL_ARTIFICIAL (decl))
9565 add_AT_flag (subr_die, DW_AT_artificial, 1);
9566 if (TREE_PROTECTED (decl))
9567 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9568 else if (TREE_PRIVATE (decl))
9569 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9572 if (declaration)
9574 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9576 add_AT_flag (subr_die, DW_AT_declaration, 1);
9578 /* The first time we see a member function, it is in the context of
9579 the class to which it belongs. We make sure of this by emitting
9580 the class first. The next time is the definition, which is
9581 handled above. The two may come from the same source text. */
9582 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9583 equate_decl_number_to_die (decl, subr_die);
9586 else if (DECL_ABSTRACT (decl))
9588 if (DECL_INLINE (decl) && !flag_no_inline)
9590 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9591 inline functions, but not for extern inline functions.
9592 We can't get this completely correct because information
9593 about whether the function was declared inline is not
9594 saved anywhere. */
9595 if (DECL_DEFER_OUTPUT (decl))
9596 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9597 else
9598 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9600 else
9601 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9603 equate_decl_number_to_die (decl, subr_die);
9605 else if (!DECL_EXTERNAL (decl))
9607 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9608 equate_decl_number_to_die (decl, subr_die);
9610 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9611 current_funcdef_number);
9612 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9613 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9614 current_funcdef_number);
9615 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9617 add_pubname (decl, subr_die);
9618 add_arange (decl, subr_die);
9620 #ifdef MIPS_DEBUGGING_INFO
9621 /* Add a reference to the FDE for this routine. */
9622 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9623 #endif
9625 /* Define the "frame base" location for this routine. We use the
9626 frame pointer or stack pointer registers, since the RTL for local
9627 variables is relative to one of them. */
9628 fp_reg
9629 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9630 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9632 #if 0
9633 /* ??? This fails for nested inline functions, because context_display
9634 is not part of the state saved/restored for inline functions. */
9635 if (current_function_needs_context)
9636 add_AT_location_description (subr_die, DW_AT_static_link,
9637 lookup_static_chain (decl));
9638 #endif
9641 /* Now output descriptions of the arguments for this function. This gets
9642 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9643 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9644 `...' at the end of the formal parameter list. In order to find out if
9645 there was a trailing ellipsis or not, we must instead look at the type
9646 associated with the FUNCTION_DECL. This will be a node of type
9647 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9648 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9649 an ellipsis at the end. */
9651 /* In the case where we are describing a mere function declaration, all we
9652 need to do here (and all we *can* do here) is to describe the *types* of
9653 its formal parameters. */
9654 if (debug_info_level <= DINFO_LEVEL_TERSE)
9656 else if (declaration)
9657 gen_formal_types_die (decl, subr_die);
9658 else
9660 /* Generate DIEs to represent all known formal parameters */
9661 register tree arg_decls = DECL_ARGUMENTS (decl);
9662 register tree parm;
9664 /* When generating DIEs, generate the unspecified_parameters DIE
9665 instead if we come across the arg "__builtin_va_alist" */
9666 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9667 if (TREE_CODE (parm) == PARM_DECL)
9669 if (DECL_NAME (parm)
9670 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9671 "__builtin_va_alist"))
9672 gen_unspecified_parameters_die (parm, subr_die);
9673 else
9674 gen_decl_die (parm, subr_die);
9677 /* Decide whether we need a unspecified_parameters DIE at the end.
9678 There are 2 more cases to do this for: 1) the ansi ... declaration -
9679 this is detectable when the end of the arg list is not a
9680 void_type_node 2) an unprototyped function declaration (not a
9681 definition). This just means that we have no info about the
9682 parameters at all. */
9683 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9684 if (fn_arg_types != NULL)
9686 /* this is the prototyped case, check for ... */
9687 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9688 gen_unspecified_parameters_die (decl, subr_die);
9690 else if (DECL_INITIAL (decl) == NULL_TREE)
9691 gen_unspecified_parameters_die (decl, subr_die);
9694 /* Output Dwarf info for all of the stuff within the body of the function
9695 (if it has one - it may be just a declaration). */
9696 outer_scope = DECL_INITIAL (decl);
9698 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9699 node created to represent a function. This outermost BLOCK actually
9700 represents the outermost binding contour for the function, i.e. the
9701 contour in which the function's formal parameters and labels get
9702 declared. Curiously, it appears that the front end doesn't actually
9703 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9704 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9705 list for the function instead.) The BLOCK_VARS list for the
9706 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9707 the function however, and we output DWARF info for those in
9708 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9709 node representing the function's outermost pair of curly braces, and
9710 any blocks used for the base and member initializers of a C++
9711 constructor function. */
9712 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9714 current_function_has_inlines = 0;
9715 decls_for_scope (outer_scope, subr_die, 0);
9717 #if 0 && defined (MIPS_DEBUGGING_INFO)
9718 if (current_function_has_inlines)
9720 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9721 if (! comp_unit_has_inlines)
9723 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9724 comp_unit_has_inlines = 1;
9727 #endif
9731 /* Generate a DIE to represent a declared data object. */
9733 static void
9734 gen_variable_die (decl, context_die)
9735 register tree decl;
9736 register dw_die_ref context_die;
9738 register tree origin = decl_ultimate_origin (decl);
9739 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9741 dw_die_ref old_die = lookup_decl_die (decl);
9742 int declaration = (DECL_EXTERNAL (decl)
9743 || class_scope_p (context_die));
9745 if (origin != NULL)
9746 add_abstract_origin_attribute (var_die, origin);
9747 /* Loop unrolling can create multiple blocks that refer to the same
9748 static variable, so we must test for the DW_AT_declaration flag. */
9749 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9750 copy decls and set the DECL_ABSTRACT flag on them instead of
9751 sharing them. */
9752 else if (old_die && TREE_STATIC (decl)
9753 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9755 /* This is a definition of a C++ class level static. */
9756 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9757 if (DECL_NAME (decl))
9759 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9761 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9762 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9764 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9765 != (unsigned) DECL_SOURCE_LINE (decl))
9767 add_AT_unsigned (var_die, DW_AT_decl_line,
9768 DECL_SOURCE_LINE (decl));
9771 else
9773 add_name_and_src_coords_attributes (var_die, decl);
9774 add_type_attribute (var_die, TREE_TYPE (decl),
9775 TREE_READONLY (decl),
9776 TREE_THIS_VOLATILE (decl), context_die);
9778 if (TREE_PUBLIC (decl))
9779 add_AT_flag (var_die, DW_AT_external, 1);
9781 if (DECL_ARTIFICIAL (decl))
9782 add_AT_flag (var_die, DW_AT_artificial, 1);
9784 if (TREE_PROTECTED (decl))
9785 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9787 else if (TREE_PRIVATE (decl))
9788 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9791 if (declaration)
9792 add_AT_flag (var_die, DW_AT_declaration, 1);
9794 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9795 equate_decl_number_to_die (decl, var_die);
9797 if (! declaration && ! DECL_ABSTRACT (decl))
9799 add_location_or_const_value_attribute (var_die, decl);
9800 add_pubname (decl, var_die);
9802 else
9803 tree_add_const_value_attribute (var_die, decl);
9806 /* Generate a DIE to represent a label identifier. */
9808 static void
9809 gen_label_die (decl, context_die)
9810 register tree decl;
9811 register dw_die_ref context_die;
9813 register tree origin = decl_ultimate_origin (decl);
9814 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
9815 register rtx insn;
9816 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9818 if (origin != NULL)
9819 add_abstract_origin_attribute (lbl_die, origin);
9820 else
9821 add_name_and_src_coords_attributes (lbl_die, decl);
9823 if (DECL_ABSTRACT (decl))
9824 equate_decl_number_to_die (decl, lbl_die);
9825 else
9827 insn = DECL_RTL (decl);
9829 /* Deleted labels are programmer specified labels which have been
9830 eliminated because of various optimisations. We still emit them
9831 here so that it is possible to put breakpoints on them. */
9832 if (GET_CODE (insn) == CODE_LABEL
9833 || ((GET_CODE (insn) == NOTE
9834 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
9836 /* When optimization is enabled (via -O) some parts of the compiler
9837 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
9838 represent source-level labels which were explicitly declared by
9839 the user. This really shouldn't be happening though, so catch
9840 it if it ever does happen. */
9841 if (INSN_DELETED_P (insn))
9842 abort ();
9844 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
9845 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
9850 /* Generate a DIE for a lexical block. */
9852 static void
9853 gen_lexical_block_die (stmt, context_die, depth)
9854 register tree stmt;
9855 register dw_die_ref context_die;
9856 int depth;
9858 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
9859 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9861 if (! BLOCK_ABSTRACT (stmt))
9863 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9864 BLOCK_NUMBER (stmt));
9865 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
9866 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9867 BLOCK_NUMBER (stmt));
9868 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
9871 decls_for_scope (stmt, stmt_die, depth);
9874 /* Generate a DIE for an inlined subprogram. */
9876 static void
9877 gen_inlined_subroutine_die (stmt, context_die, depth)
9878 register tree stmt;
9879 register dw_die_ref context_die;
9880 int depth;
9882 if (! BLOCK_ABSTRACT (stmt))
9884 register dw_die_ref subr_die
9885 = new_die (DW_TAG_inlined_subroutine, context_die);
9886 register tree decl = block_ultimate_origin (stmt);
9887 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9889 /* Emit info for the abstract instance first, if we haven't yet. */
9890 dwarf2out_abstract_function (decl);
9892 add_abstract_origin_attribute (subr_die, decl);
9893 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9894 BLOCK_NUMBER (stmt));
9895 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
9896 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9897 BLOCK_NUMBER (stmt));
9898 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
9899 decls_for_scope (stmt, subr_die, depth);
9900 current_function_has_inlines = 1;
9904 /* Generate a DIE for a field in a record, or structure. */
9906 static void
9907 gen_field_die (decl, context_die)
9908 register tree decl;
9909 register dw_die_ref context_die;
9911 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
9913 add_name_and_src_coords_attributes (decl_die, decl);
9914 add_type_attribute (decl_die, member_declared_type (decl),
9915 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
9916 context_die);
9918 /* If this is a bit field... */
9919 if (DECL_BIT_FIELD_TYPE (decl))
9921 add_byte_size_attribute (decl_die, decl);
9922 add_bit_size_attribute (decl_die, decl);
9923 add_bit_offset_attribute (decl_die, decl);
9926 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
9927 add_data_member_location_attribute (decl_die, decl);
9929 if (DECL_ARTIFICIAL (decl))
9930 add_AT_flag (decl_die, DW_AT_artificial, 1);
9932 if (TREE_PROTECTED (decl))
9933 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
9935 else if (TREE_PRIVATE (decl))
9936 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
9939 #if 0
9940 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9941 Use modified_type_die instead.
9942 We keep this code here just in case these types of DIEs may be needed to
9943 represent certain things in other languages (e.g. Pascal) someday. */
9944 static void
9945 gen_pointer_type_die (type, context_die)
9946 register tree type;
9947 register dw_die_ref context_die;
9949 register dw_die_ref ptr_die
9950 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
9952 equate_type_number_to_die (type, ptr_die);
9953 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9954 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9957 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9958 Use modified_type_die instead.
9959 We keep this code here just in case these types of DIEs may be needed to
9960 represent certain things in other languages (e.g. Pascal) someday. */
9961 static void
9962 gen_reference_type_die (type, context_die)
9963 register tree type;
9964 register dw_die_ref context_die;
9966 register dw_die_ref ref_die
9967 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
9969 equate_type_number_to_die (type, ref_die);
9970 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
9971 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9973 #endif
9975 /* Generate a DIE for a pointer to a member type. */
9976 static void
9977 gen_ptr_to_mbr_type_die (type, context_die)
9978 register tree type;
9979 register dw_die_ref context_die;
9981 register dw_die_ref ptr_die
9982 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
9984 equate_type_number_to_die (type, ptr_die);
9985 add_AT_die_ref (ptr_die, DW_AT_containing_type,
9986 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
9987 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9990 /* Generate the DIE for the compilation unit. */
9992 static dw_die_ref
9993 gen_compile_unit_die (filename)
9994 register const char *filename;
9996 register dw_die_ref die;
9997 char producer[250];
9998 const char *wd = getpwd ();
9999 int language;
10001 die = new_die (DW_TAG_compile_unit, NULL);
10002 add_name_attribute (die, filename);
10004 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10005 add_AT_string (die, DW_AT_comp_dir, wd);
10007 sprintf (producer, "%s %s", language_string, version_string);
10009 #ifdef MIPS_DEBUGGING_INFO
10010 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10011 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10012 not appear in the producer string, the debugger reaches the conclusion
10013 that the object file is stripped and has no debugging information.
10014 To get the MIPS/SGI debugger to believe that there is debugging
10015 information in the object file, we add a -g to the producer string. */
10016 if (debug_info_level > DINFO_LEVEL_TERSE)
10017 strcat (producer, " -g");
10018 #endif
10020 add_AT_string (die, DW_AT_producer, producer);
10022 if (strcmp (language_string, "GNU C++") == 0)
10023 language = DW_LANG_C_plus_plus;
10024 else if (strcmp (language_string, "GNU Ada") == 0)
10025 language = DW_LANG_Ada83;
10026 else if (strcmp (language_string, "GNU F77") == 0)
10027 language = DW_LANG_Fortran77;
10028 else if (strcmp (language_string, "GNU Pascal") == 0)
10029 language = DW_LANG_Pascal83;
10030 else if (strcmp (language_string, "GNU Java") == 0)
10031 language = DW_LANG_Java;
10032 else if (flag_traditional)
10033 language = DW_LANG_C;
10034 else
10035 language = DW_LANG_C89;
10037 add_AT_unsigned (die, DW_AT_language, language);
10039 return die;
10042 /* Generate a DIE for a string type. */
10044 static void
10045 gen_string_type_die (type, context_die)
10046 register tree type;
10047 register dw_die_ref context_die;
10049 register dw_die_ref type_die
10050 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10052 equate_type_number_to_die (type, type_die);
10054 /* Fudge the string length attribute for now. */
10056 /* TODO: add string length info.
10057 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10058 bound_representation (upper_bound, 0, 'u'); */
10061 /* Generate the DIE for a base class. */
10063 static void
10064 gen_inheritance_die (binfo, context_die)
10065 register tree binfo;
10066 register dw_die_ref context_die;
10068 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10070 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10071 add_data_member_location_attribute (die, binfo);
10073 if (TREE_VIA_VIRTUAL (binfo))
10074 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10075 if (TREE_VIA_PUBLIC (binfo))
10076 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10077 else if (TREE_VIA_PROTECTED (binfo))
10078 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10081 /* Generate a DIE for a class member. */
10083 static void
10084 gen_member_die (type, context_die)
10085 register tree type;
10086 register dw_die_ref context_die;
10088 register tree member;
10089 dw_die_ref child;
10091 /* If this is not an incomplete type, output descriptions of each of its
10092 members. Note that as we output the DIEs necessary to represent the
10093 members of this record or union type, we will also be trying to output
10094 DIEs to represent the *types* of those members. However the `type'
10095 function (above) will specifically avoid generating type DIEs for member
10096 types *within* the list of member DIEs for this (containing) type execpt
10097 for those types (of members) which are explicitly marked as also being
10098 members of this (containing) type themselves. The g++ front- end can
10099 force any given type to be treated as a member of some other
10100 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10101 to point to the TREE node representing the appropriate (containing)
10102 type. */
10104 /* First output info about the base classes. */
10105 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10107 register tree bases = TYPE_BINFO_BASETYPES (type);
10108 register int n_bases = TREE_VEC_LENGTH (bases);
10109 register int i;
10111 for (i = 0; i < n_bases; i++)
10112 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10115 /* Now output info about the data members and type members. */
10116 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10118 /* If we thought we were generating minimal debug info for TYPE
10119 and then changed our minds, some of the member declarations
10120 may have already been defined. Don't define them again, but
10121 do put them in the right order. */
10123 child = lookup_decl_die (member);
10124 if (child)
10125 splice_child_die (context_die, child);
10126 else
10127 gen_decl_die (member, context_die);
10130 /* Now output info about the function members (if any). */
10131 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10133 /* Don't include clones in the member list. */
10134 if (DECL_ABSTRACT_ORIGIN (member))
10135 continue;
10137 child = lookup_decl_die (member);
10138 if (child)
10139 splice_child_die (context_die, child);
10140 else
10141 gen_decl_die (member, context_die);
10145 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10146 is set, we pretend that the type was never defined, so we only get the
10147 member DIEs needed by later specification DIEs. */
10149 static void
10150 gen_struct_or_union_type_die (type, context_die)
10151 register tree type;
10152 register dw_die_ref context_die;
10154 register dw_die_ref type_die = lookup_type_die (type);
10155 register dw_die_ref scope_die = 0;
10156 register int nested = 0;
10157 int complete = (TYPE_SIZE (type)
10158 && (! TYPE_STUB_DECL (type)
10159 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10161 if (type_die && ! complete)
10162 return;
10164 if (TYPE_CONTEXT (type) != NULL_TREE
10165 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10166 nested = 1;
10168 scope_die = scope_die_for (type, context_die);
10170 if (! type_die || (nested && scope_die == comp_unit_die))
10171 /* First occurrence of type or toplevel definition of nested class. */
10173 register dw_die_ref old_die = type_die;
10175 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10176 ? DW_TAG_structure_type : DW_TAG_union_type,
10177 scope_die);
10178 equate_type_number_to_die (type, type_die);
10179 if (old_die)
10180 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10181 else
10182 add_name_attribute (type_die, type_tag (type));
10184 else
10185 remove_AT (type_die, DW_AT_declaration);
10187 /* If this type has been completed, then give it a byte_size attribute and
10188 then give a list of members. */
10189 if (complete)
10191 /* Prevent infinite recursion in cases where the type of some member of
10192 this type is expressed in terms of this type itself. */
10193 TREE_ASM_WRITTEN (type) = 1;
10194 add_byte_size_attribute (type_die, type);
10195 if (TYPE_STUB_DECL (type) != NULL_TREE)
10196 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10198 /* If the first reference to this type was as the return type of an
10199 inline function, then it may not have a parent. Fix this now. */
10200 if (type_die->die_parent == NULL)
10201 add_child_die (scope_die, type_die);
10203 push_decl_scope (type);
10204 gen_member_die (type, type_die);
10205 pop_decl_scope ();
10207 /* GNU extension: Record what type our vtable lives in. */
10208 if (TYPE_VFIELD (type))
10210 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10212 gen_type_die (vtype, context_die);
10213 add_AT_die_ref (type_die, DW_AT_containing_type,
10214 lookup_type_die (vtype));
10217 else
10219 add_AT_flag (type_die, DW_AT_declaration, 1);
10221 /* We don't need to do this for function-local types. */
10222 if (! decl_function_context (TYPE_STUB_DECL (type)))
10223 add_incomplete_type (type);
10227 /* Generate a DIE for a subroutine _type_. */
10229 static void
10230 gen_subroutine_type_die (type, context_die)
10231 register tree type;
10232 register dw_die_ref context_die;
10234 register tree return_type = TREE_TYPE (type);
10235 register dw_die_ref subr_die
10236 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10238 equate_type_number_to_die (type, subr_die);
10239 add_prototyped_attribute (subr_die, type);
10240 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10241 gen_formal_types_die (type, subr_die);
10244 /* Generate a DIE for a type definition */
10246 static void
10247 gen_typedef_die (decl, context_die)
10248 register tree decl;
10249 register dw_die_ref context_die;
10251 register dw_die_ref type_die;
10252 register tree origin;
10254 if (TREE_ASM_WRITTEN (decl))
10255 return;
10256 TREE_ASM_WRITTEN (decl) = 1;
10258 type_die = new_die (DW_TAG_typedef, context_die);
10259 origin = decl_ultimate_origin (decl);
10260 if (origin != NULL)
10261 add_abstract_origin_attribute (type_die, origin);
10262 else
10264 register tree type;
10265 add_name_and_src_coords_attributes (type_die, decl);
10266 if (DECL_ORIGINAL_TYPE (decl))
10268 type = DECL_ORIGINAL_TYPE (decl);
10270 if (type == TREE_TYPE (decl))
10271 abort ();
10272 else
10273 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10275 else
10276 type = TREE_TYPE (decl);
10277 add_type_attribute (type_die, type, TREE_READONLY (decl),
10278 TREE_THIS_VOLATILE (decl), context_die);
10281 if (DECL_ABSTRACT (decl))
10282 equate_decl_number_to_die (decl, type_die);
10285 /* Generate a type description DIE. */
10287 static void
10288 gen_type_die (type, context_die)
10289 register tree type;
10290 register dw_die_ref context_die;
10292 int need_pop;
10294 if (type == NULL_TREE || type == error_mark_node)
10295 return;
10297 /* We are going to output a DIE to represent the unqualified version of
10298 this type (i.e. without any const or volatile qualifiers) so get the
10299 main variant (i.e. the unqualified version) of this type now. */
10300 type = type_main_variant (type);
10302 if (TREE_ASM_WRITTEN (type))
10303 return;
10305 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10306 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10308 TREE_ASM_WRITTEN (type) = 1;
10309 gen_decl_die (TYPE_NAME (type), context_die);
10310 return;
10313 switch (TREE_CODE (type))
10315 case ERROR_MARK:
10316 break;
10318 case POINTER_TYPE:
10319 case REFERENCE_TYPE:
10320 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10321 ensures that the gen_type_die recursion will terminate even if the
10322 type is recursive. Recursive types are possible in Ada. */
10323 /* ??? We could perhaps do this for all types before the switch
10324 statement. */
10325 TREE_ASM_WRITTEN (type) = 1;
10327 /* For these types, all that is required is that we output a DIE (or a
10328 set of DIEs) to represent the "basis" type. */
10329 gen_type_die (TREE_TYPE (type), context_die);
10330 break;
10332 case OFFSET_TYPE:
10333 /* This code is used for C++ pointer-to-data-member types.
10334 Output a description of the relevant class type. */
10335 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10337 /* Output a description of the type of the object pointed to. */
10338 gen_type_die (TREE_TYPE (type), context_die);
10340 /* Now output a DIE to represent this pointer-to-data-member type
10341 itself. */
10342 gen_ptr_to_mbr_type_die (type, context_die);
10343 break;
10345 case SET_TYPE:
10346 gen_type_die (TYPE_DOMAIN (type), context_die);
10347 gen_set_type_die (type, context_die);
10348 break;
10350 case FILE_TYPE:
10351 gen_type_die (TREE_TYPE (type), context_die);
10352 abort (); /* No way to represent these in Dwarf yet! */
10353 break;
10355 case FUNCTION_TYPE:
10356 /* Force out return type (in case it wasn't forced out already). */
10357 gen_type_die (TREE_TYPE (type), context_die);
10358 gen_subroutine_type_die (type, context_die);
10359 break;
10361 case METHOD_TYPE:
10362 /* Force out return type (in case it wasn't forced out already). */
10363 gen_type_die (TREE_TYPE (type), context_die);
10364 gen_subroutine_type_die (type, context_die);
10365 break;
10367 case ARRAY_TYPE:
10368 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10370 gen_type_die (TREE_TYPE (type), context_die);
10371 gen_string_type_die (type, context_die);
10373 else
10374 gen_array_type_die (type, context_die);
10375 break;
10377 case VECTOR_TYPE:
10378 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10379 break;
10381 case ENUMERAL_TYPE:
10382 case RECORD_TYPE:
10383 case UNION_TYPE:
10384 case QUAL_UNION_TYPE:
10385 /* If this is a nested type whose containing class hasn't been
10386 written out yet, writing it out will cover this one, too.
10387 This does not apply to instantiations of member class templates;
10388 they need to be added to the containing class as they are
10389 generated. FIXME: This hurts the idea of combining type decls
10390 from multiple TUs, since we can't predict what set of template
10391 instantiations we'll get. */
10392 if (TYPE_CONTEXT (type)
10393 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10394 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10396 gen_type_die (TYPE_CONTEXT (type), context_die);
10398 if (TREE_ASM_WRITTEN (type))
10399 return;
10401 /* If that failed, attach ourselves to the stub. */
10402 push_decl_scope (TYPE_CONTEXT (type));
10403 context_die = lookup_type_die (TYPE_CONTEXT (type));
10404 need_pop = 1;
10406 else
10407 need_pop = 0;
10409 if (TREE_CODE (type) == ENUMERAL_TYPE)
10410 gen_enumeration_type_die (type, context_die);
10411 else
10412 gen_struct_or_union_type_die (type, context_die);
10414 if (need_pop)
10415 pop_decl_scope ();
10417 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10418 it up if it is ever completed. gen_*_type_die will set it for us
10419 when appropriate. */
10420 return;
10422 case VOID_TYPE:
10423 case INTEGER_TYPE:
10424 case REAL_TYPE:
10425 case COMPLEX_TYPE:
10426 case BOOLEAN_TYPE:
10427 case CHAR_TYPE:
10428 /* No DIEs needed for fundamental types. */
10429 break;
10431 case LANG_TYPE:
10432 /* No Dwarf representation currently defined. */
10433 break;
10435 default:
10436 abort ();
10439 TREE_ASM_WRITTEN (type) = 1;
10442 /* Generate a DIE for a tagged type instantiation. */
10444 static void
10445 gen_tagged_type_instantiation_die (type, context_die)
10446 register tree type;
10447 register dw_die_ref context_die;
10449 if (type == NULL_TREE || type == error_mark_node)
10450 return;
10452 /* We are going to output a DIE to represent the unqualified version of
10453 this type (i.e. without any const or volatile qualifiers) so make sure
10454 that we have the main variant (i.e. the unqualified version) of this
10455 type now. */
10456 if (type != type_main_variant (type))
10457 abort ();
10459 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10460 an instance of an unresolved type. */
10462 switch (TREE_CODE (type))
10464 case ERROR_MARK:
10465 break;
10467 case ENUMERAL_TYPE:
10468 gen_inlined_enumeration_type_die (type, context_die);
10469 break;
10471 case RECORD_TYPE:
10472 gen_inlined_structure_type_die (type, context_die);
10473 break;
10475 case UNION_TYPE:
10476 case QUAL_UNION_TYPE:
10477 gen_inlined_union_type_die (type, context_die);
10478 break;
10480 default:
10481 abort ();
10485 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10486 things which are local to the given block. */
10488 static void
10489 gen_block_die (stmt, context_die, depth)
10490 register tree stmt;
10491 register dw_die_ref context_die;
10492 int depth;
10494 register int must_output_die = 0;
10495 register tree origin;
10496 register tree decl;
10497 register enum tree_code origin_code;
10499 /* Ignore blocks never really used to make RTL. */
10501 if (stmt == NULL_TREE || !TREE_USED (stmt)
10502 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10503 return;
10505 /* Determine the "ultimate origin" of this block. This block may be an
10506 inlined instance of an inlined instance of inline function, so we have
10507 to trace all of the way back through the origin chain to find out what
10508 sort of node actually served as the original seed for the creation of
10509 the current block. */
10510 origin = block_ultimate_origin (stmt);
10511 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10513 /* Determine if we need to output any Dwarf DIEs at all to represent this
10514 block. */
10515 if (origin_code == FUNCTION_DECL)
10516 /* The outer scopes for inlinings *must* always be represented. We
10517 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10518 must_output_die = 1;
10519 else
10521 /* In the case where the current block represents an inlining of the
10522 "body block" of an inline function, we must *NOT* output any DIE for
10523 this block because we have already output a DIE to represent the
10524 whole inlined function scope and the "body block" of any function
10525 doesn't really represent a different scope according to ANSI C
10526 rules. So we check here to make sure that this block does not
10527 represent a "body block inlining" before trying to set the
10528 `must_output_die' flag. */
10529 if (! is_body_block (origin ? origin : stmt))
10531 /* Determine if this block directly contains any "significant"
10532 local declarations which we will need to output DIEs for. */
10533 if (debug_info_level > DINFO_LEVEL_TERSE)
10534 /* We are not in terse mode so *any* local declaration counts
10535 as being a "significant" one. */
10536 must_output_die = (BLOCK_VARS (stmt) != NULL);
10537 else
10538 /* We are in terse mode, so only local (nested) function
10539 definitions count as "significant" local declarations. */
10540 for (decl = BLOCK_VARS (stmt);
10541 decl != NULL; decl = TREE_CHAIN (decl))
10542 if (TREE_CODE (decl) == FUNCTION_DECL
10543 && DECL_INITIAL (decl))
10545 must_output_die = 1;
10546 break;
10551 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10552 DIE for any block which contains no significant local declarations at
10553 all. Rather, in such cases we just call `decls_for_scope' so that any
10554 needed Dwarf info for any sub-blocks will get properly generated. Note
10555 that in terse mode, our definition of what constitutes a "significant"
10556 local declaration gets restricted to include only inlined function
10557 instances and local (nested) function definitions. */
10558 if (must_output_die)
10560 if (origin_code == FUNCTION_DECL)
10561 gen_inlined_subroutine_die (stmt, context_die, depth);
10562 else
10563 gen_lexical_block_die (stmt, context_die, depth);
10565 else
10566 decls_for_scope (stmt, context_die, depth);
10569 /* Generate all of the decls declared within a given scope and (recursively)
10570 all of its sub-blocks. */
10572 static void
10573 decls_for_scope (stmt, context_die, depth)
10574 register tree stmt;
10575 register dw_die_ref context_die;
10576 int depth;
10578 register tree decl;
10579 register tree subblocks;
10581 /* Ignore blocks never really used to make RTL. */
10582 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10583 return;
10585 /* Output the DIEs to represent all of the data objects and typedefs
10586 declared directly within this block but not within any nested
10587 sub-blocks. Also, nested function and tag DIEs have been
10588 generated with a parent of NULL; fix that up now. */
10589 for (decl = BLOCK_VARS (stmt);
10590 decl != NULL; decl = TREE_CHAIN (decl))
10592 register dw_die_ref die;
10594 if (TREE_CODE (decl) == FUNCTION_DECL)
10595 die = lookup_decl_die (decl);
10596 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10597 die = lookup_type_die (TREE_TYPE (decl));
10598 else
10599 die = NULL;
10601 if (die != NULL && die->die_parent == NULL)
10602 add_child_die (context_die, die);
10603 else
10604 gen_decl_die (decl, context_die);
10607 /* Output the DIEs to represent all sub-blocks (and the items declared
10608 therein) of this block. */
10609 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10610 subblocks != NULL;
10611 subblocks = BLOCK_CHAIN (subblocks))
10612 gen_block_die (subblocks, context_die, depth + 1);
10615 /* Is this a typedef we can avoid emitting? */
10617 static inline int
10618 is_redundant_typedef (decl)
10619 register tree decl;
10621 if (TYPE_DECL_IS_STUB (decl))
10622 return 1;
10624 if (DECL_ARTIFICIAL (decl)
10625 && DECL_CONTEXT (decl)
10626 && is_tagged_type (DECL_CONTEXT (decl))
10627 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10628 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10629 /* Also ignore the artificial member typedef for the class name. */
10630 return 1;
10632 return 0;
10635 /* Generate Dwarf debug information for a decl described by DECL. */
10637 static void
10638 gen_decl_die (decl, context_die)
10639 register tree decl;
10640 register dw_die_ref context_die;
10642 register tree origin;
10644 if (TREE_CODE (decl) == ERROR_MARK)
10645 return;
10647 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10648 if (DECL_IGNORED_P (decl))
10649 return;
10651 switch (TREE_CODE (decl))
10653 case CONST_DECL:
10654 /* The individual enumerators of an enum type get output when we output
10655 the Dwarf representation of the relevant enum type itself. */
10656 break;
10658 case FUNCTION_DECL:
10659 /* Don't output any DIEs to represent mere function declarations,
10660 unless they are class members or explicit block externs. */
10661 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10662 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10663 break;
10665 /* If we're emitting a clone, emit info for the abstract instance. */
10666 if (DECL_ORIGIN (decl) != decl)
10667 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
10668 /* If we're emitting an out-of-line copy of an inline function,
10669 emit info for the abstract instance and set up to refer to it. */
10670 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10671 && ! class_scope_p (context_die)
10672 /* dwarf2out_abstract_function won't emit a die if this is just
10673 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10674 that case, because that works only if we have a die. */
10675 && DECL_INITIAL (decl) != NULL_TREE)
10677 dwarf2out_abstract_function (decl);
10678 set_decl_origin_self (decl);
10680 /* Otherwise we're emitting the primary DIE for this decl. */
10681 else if (debug_info_level > DINFO_LEVEL_TERSE)
10683 /* Before we describe the FUNCTION_DECL itself, make sure that we
10684 have described its return type. */
10685 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10687 /* And its virtual context. */
10688 if (DECL_VINDEX (decl) != NULL_TREE)
10689 gen_type_die (DECL_CONTEXT (decl), context_die);
10691 /* And its containing type. */
10692 origin = decl_class_context (decl);
10693 if (origin != NULL_TREE)
10694 gen_type_die_for_member (origin, decl, context_die);
10697 /* Now output a DIE to represent the function itself. */
10698 gen_subprogram_die (decl, context_die);
10699 break;
10701 case TYPE_DECL:
10702 /* If we are in terse mode, don't generate any DIEs to represent any
10703 actual typedefs. */
10704 if (debug_info_level <= DINFO_LEVEL_TERSE)
10705 break;
10707 /* In the special case of a TYPE_DECL node representing the
10708 declaration of some type tag, if the given TYPE_DECL is marked as
10709 having been instantiated from some other (original) TYPE_DECL node
10710 (e.g. one which was generated within the original definition of an
10711 inline function) we have to generate a special (abbreviated)
10712 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10713 DIE here. */
10714 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10716 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10717 break;
10720 if (is_redundant_typedef (decl))
10721 gen_type_die (TREE_TYPE (decl), context_die);
10722 else
10723 /* Output a DIE to represent the typedef itself. */
10724 gen_typedef_die (decl, context_die);
10725 break;
10727 case LABEL_DECL:
10728 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10729 gen_label_die (decl, context_die);
10730 break;
10732 case VAR_DECL:
10733 /* If we are in terse mode, don't generate any DIEs to represent any
10734 variable declarations or definitions. */
10735 if (debug_info_level <= DINFO_LEVEL_TERSE)
10736 break;
10738 /* Output any DIEs that are needed to specify the type of this data
10739 object. */
10740 gen_type_die (TREE_TYPE (decl), context_die);
10742 /* And its containing type. */
10743 origin = decl_class_context (decl);
10744 if (origin != NULL_TREE)
10745 gen_type_die_for_member (origin, decl, context_die);
10747 /* Now output the DIE to represent the data object itself. This gets
10748 complicated because of the possibility that the VAR_DECL really
10749 represents an inlined instance of a formal parameter for an inline
10750 function. */
10751 origin = decl_ultimate_origin (decl);
10752 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10753 gen_formal_parameter_die (decl, context_die);
10754 else
10755 gen_variable_die (decl, context_die);
10756 break;
10758 case FIELD_DECL:
10759 /* Ignore the nameless fields that are used to skip bits, but
10760 handle C++ anonymous unions. */
10761 if (DECL_NAME (decl) != NULL_TREE
10762 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10764 gen_type_die (member_declared_type (decl), context_die);
10765 gen_field_die (decl, context_die);
10767 break;
10769 case PARM_DECL:
10770 gen_type_die (TREE_TYPE (decl), context_die);
10771 gen_formal_parameter_die (decl, context_die);
10772 break;
10774 case NAMESPACE_DECL:
10775 /* Ignore for now. */
10776 break;
10778 default:
10779 abort ();
10783 /* Add Ada "use" clause information for SGI Workshop debugger. */
10785 void
10786 dwarf2out_add_library_unit_info (filename, context_list)
10787 const char *filename;
10788 const char *context_list;
10790 unsigned int file_index;
10792 if (filename != NULL)
10794 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10795 tree context_list_decl
10796 = build_decl (LABEL_DECL, get_identifier (context_list),
10797 void_type_node);
10799 TREE_PUBLIC (context_list_decl) = TRUE;
10800 add_name_attribute (unit_die, context_list);
10801 file_index = lookup_filename (filename);
10802 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10803 add_pubname (context_list_decl, unit_die);
10807 /* Write the debugging output for DECL. */
10809 void
10810 dwarf2out_decl (decl)
10811 register tree decl;
10813 register dw_die_ref context_die = comp_unit_die;
10815 if (TREE_CODE (decl) == ERROR_MARK)
10816 return;
10818 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10819 if (DECL_IGNORED_P (decl))
10820 return;
10822 switch (TREE_CODE (decl))
10824 case FUNCTION_DECL:
10825 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
10826 builtin function. Explicit programmer-supplied declarations of
10827 these same functions should NOT be ignored however. */
10828 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
10829 return;
10831 /* What we would really like to do here is to filter out all mere
10832 file-scope declarations of file-scope functions which are never
10833 referenced later within this translation unit (and keep all of ones
10834 that *are* referenced later on) but we aren't clairvoyant, so we have
10835 no idea which functions will be referenced in the future (i.e. later
10836 on within the current translation unit). So here we just ignore all
10837 file-scope function declarations which are not also definitions. If
10838 and when the debugger needs to know something about these functions,
10839 it will have to hunt around and find the DWARF information associated
10840 with the definition of the function. Note that we can't just check
10841 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
10842 definitions and which ones represent mere declarations. We have to
10843 check `DECL_INITIAL' instead. That's because the C front-end
10844 supports some weird semantics for "extern inline" function
10845 definitions. These can get inlined within the current translation
10846 unit (an thus, we need to generate DWARF info for their abstract
10847 instances so that the DWARF info for the concrete inlined instances
10848 can have something to refer to) but the compiler never generates any
10849 out-of-lines instances of such things (despite the fact that they
10850 *are* definitions). The important point is that the C front-end
10851 marks these "extern inline" functions as DECL_EXTERNAL, but we need
10852 to generate DWARF for them anyway. Note that the C++ front-end also
10853 plays some similar games for inline function definitions appearing
10854 within include files which also contain
10855 `#pragma interface' pragmas. */
10856 if (DECL_INITIAL (decl) == NULL_TREE)
10857 return;
10859 /* If we're a nested function, initially use a parent of NULL; if we're
10860 a plain function, this will be fixed up in decls_for_scope. If
10861 we're a method, it will be ignored, since we already have a DIE. */
10862 if (decl_function_context (decl))
10863 context_die = NULL;
10865 break;
10867 case VAR_DECL:
10868 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
10869 declaration and if the declaration was never even referenced from
10870 within this entire compilation unit. We suppress these DIEs in
10871 order to save space in the .debug section (by eliminating entries
10872 which are probably useless). Note that we must not suppress
10873 block-local extern declarations (whether used or not) because that
10874 would screw-up the debugger's name lookup mechanism and cause it to
10875 miss things which really ought to be in scope at a given point. */
10876 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
10877 return;
10879 /* If we are in terse mode, don't generate any DIEs to represent any
10880 variable declarations or definitions. */
10881 if (debug_info_level <= DINFO_LEVEL_TERSE)
10882 return;
10883 break;
10885 case TYPE_DECL:
10886 /* Don't emit stubs for types unless they are needed by other DIEs. */
10887 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
10888 return;
10890 /* Don't bother trying to generate any DIEs to represent any of the
10891 normal built-in types for the language we are compiling. */
10892 if (DECL_SOURCE_LINE (decl) == 0)
10894 /* OK, we need to generate one for `bool' so GDB knows what type
10895 comparisons have. */
10896 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
10897 == DW_LANG_C_plus_plus)
10898 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
10899 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
10901 return;
10904 /* If we are in terse mode, don't generate any DIEs for types. */
10905 if (debug_info_level <= DINFO_LEVEL_TERSE)
10906 return;
10908 /* If we're a function-scope tag, initially use a parent of NULL;
10909 this will be fixed up in decls_for_scope. */
10910 if (decl_function_context (decl))
10911 context_die = NULL;
10913 break;
10915 default:
10916 return;
10919 gen_decl_die (decl, context_die);
10922 /* Output a marker (i.e. a label) for the beginning of the generated code for
10923 a lexical block. */
10925 void
10926 dwarf2out_begin_block (blocknum)
10927 register unsigned blocknum;
10929 function_section (current_function_decl);
10930 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
10933 /* Output a marker (i.e. a label) for the end of the generated code for a
10934 lexical block. */
10936 void
10937 dwarf2out_end_block (blocknum)
10938 register unsigned blocknum;
10940 function_section (current_function_decl);
10941 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
10944 /* Returns nonzero if it is appropriate not to emit any debugging
10945 information for BLOCK, because it doesn't contain any instructions.
10947 Don't allow this for blocks with nested functions or local classes
10948 as we would end up with orphans, and in the presence of scheduling
10949 we may end up calling them anyway. */
10952 dwarf2out_ignore_block (block)
10953 tree block;
10955 tree decl;
10956 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
10957 if (TREE_CODE (decl) == FUNCTION_DECL
10958 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
10959 return 0;
10960 return 1;
10963 /* Lookup a filename (in the list of filenames that we know about here in
10964 dwarf2out.c) and return its "index". The index of each (known) filename is
10965 just a unique number which is associated with only that one filename.
10966 We need such numbers for the sake of generating labels
10967 (in the .debug_sfnames section) and references to those
10968 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
10969 If the filename given as an argument is not found in our current list,
10970 add it to the list and assign it the next available unique index number.
10971 In order to speed up searches, we remember the index of the filename
10972 was looked up last. This handles the majority of all searches. */
10974 static unsigned
10975 lookup_filename (file_name)
10976 const char *file_name;
10978 register unsigned i;
10980 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
10981 if (strcmp (file_name, "<internal>") == 0
10982 || strcmp (file_name, "<built-in>") == 0)
10983 return 0;
10985 /* Check to see if the file name that was searched on the previous
10986 call matches this file name. If so, return the index. */
10987 if (file_table.last_lookup_index != 0)
10988 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
10989 return file_table.last_lookup_index;
10991 /* Didn't match the previous lookup, search the table */
10992 for (i = 1; i < file_table.in_use; ++i)
10993 if (strcmp (file_name, file_table.table[i]) == 0)
10995 file_table.last_lookup_index = i;
10996 return i;
10999 /* Prepare to add a new table entry by making sure there is enough space in
11000 the table to do so. If not, expand the current table. */
11001 if (i == file_table.allocated)
11003 file_table.allocated = i + FILE_TABLE_INCREMENT;
11004 file_table.table = (char **)
11005 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11008 /* Add the new entry to the end of the filename table. */
11009 file_table.table[i] = xstrdup (file_name);
11010 file_table.in_use = i + 1;
11011 file_table.last_lookup_index = i;
11013 if (DWARF2_ASM_LINE_DEBUG_INFO)
11014 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11016 return i;
11019 static void
11020 init_file_table ()
11022 /* Allocate the initial hunk of the file_table. */
11023 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11024 file_table.allocated = FILE_TABLE_INCREMENT;
11026 /* Skip the first entry - file numbers begin at 1. */
11027 file_table.in_use = 1;
11028 file_table.last_lookup_index = 0;
11031 /* Output a label to mark the beginning of a source code line entry
11032 and record information relating to this source line, in
11033 'line_info_table' for later output of the .debug_line section. */
11035 void
11036 dwarf2out_line (filename, line)
11037 register const char *filename;
11038 register unsigned line;
11040 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11042 function_section (current_function_decl);
11044 if (DWARF2_ASM_LINE_DEBUG_INFO)
11046 unsigned file_num = lookup_filename (filename);
11048 /* Emit the .loc directive understood by GNU as. */
11049 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11051 /* Indicate that line number info exists. */
11052 ++line_info_table_in_use;
11054 /* Indicate that multiple line number tables exist. */
11055 if (DECL_SECTION_NAME (current_function_decl))
11056 ++separate_line_info_table_in_use;
11058 else if (DECL_SECTION_NAME (current_function_decl))
11060 register dw_separate_line_info_ref line_info;
11061 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11062 separate_line_info_table_in_use);
11063 if (flag_debug_asm)
11064 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11065 filename, line);
11067 /* expand the line info table if necessary */
11068 if (separate_line_info_table_in_use
11069 == separate_line_info_table_allocated)
11071 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11072 separate_line_info_table
11073 = (dw_separate_line_info_ref)
11074 xrealloc (separate_line_info_table,
11075 separate_line_info_table_allocated
11076 * sizeof (dw_separate_line_info_entry));
11079 /* Add the new entry at the end of the line_info_table. */
11080 line_info
11081 = &separate_line_info_table[separate_line_info_table_in_use++];
11082 line_info->dw_file_num = lookup_filename (filename);
11083 line_info->dw_line_num = line;
11084 line_info->function = current_funcdef_number;
11086 else
11088 register dw_line_info_ref line_info;
11090 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11091 line_info_table_in_use);
11092 if (flag_debug_asm)
11093 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11094 filename, line);
11096 /* Expand the line info table if necessary. */
11097 if (line_info_table_in_use == line_info_table_allocated)
11099 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11100 line_info_table
11101 = (dw_line_info_ref)
11102 xrealloc (line_info_table,
11103 (line_info_table_allocated
11104 * sizeof (dw_line_info_entry)));
11107 /* Add the new entry at the end of the line_info_table. */
11108 line_info = &line_info_table[line_info_table_in_use++];
11109 line_info->dw_file_num = lookup_filename (filename);
11110 line_info->dw_line_num = line;
11115 /* Record the beginning of a new source file, for later output
11116 of the .debug_macinfo section. At present, unimplemented. */
11118 void
11119 dwarf2out_start_source_file (filename)
11120 register const char *filename ATTRIBUTE_UNUSED;
11122 if (flag_eliminate_dwarf2_dups)
11124 /* Record the beginning of the file for break_out_includes. */
11125 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11126 add_AT_string (bincl_die, DW_AT_name, filename);
11130 /* Record the end of a source file, for later output
11131 of the .debug_macinfo section. At present, unimplemented. */
11133 void
11134 dwarf2out_end_source_file ()
11136 if (flag_eliminate_dwarf2_dups)
11138 /* Record the end of the file for break_out_includes. */
11139 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11143 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11144 the tail part of the directive line, i.e. the part which is past the
11145 initial whitespace, #, whitespace, directive-name, whitespace part. */
11147 void
11148 dwarf2out_define (lineno, buffer)
11149 register unsigned lineno ATTRIBUTE_UNUSED;
11150 register const char *buffer ATTRIBUTE_UNUSED;
11152 static int initialized = 0;
11153 if (!initialized)
11155 dwarf2out_start_source_file (primary_filename);
11156 initialized = 1;
11160 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11161 the tail part of the directive line, i.e. the part which is past the
11162 initial whitespace, #, whitespace, directive-name, whitespace part. */
11164 void
11165 dwarf2out_undef (lineno, buffer)
11166 register unsigned lineno ATTRIBUTE_UNUSED;
11167 register const char *buffer ATTRIBUTE_UNUSED;
11171 /* Set up for Dwarf output at the start of compilation. */
11173 void
11174 dwarf2out_init (asm_out_file, main_input_filename)
11175 register FILE *asm_out_file;
11176 register const char *main_input_filename;
11178 init_file_table ();
11180 /* Remember the name of the primary input file. */
11181 primary_filename = main_input_filename;
11183 /* Add it to the file table first, under the assumption that we'll
11184 be emitting line number data for it first, which avoids having
11185 to add an initial DW_LNS_set_file. */
11186 lookup_filename (main_input_filename);
11188 /* Allocate the initial hunk of the decl_die_table. */
11189 decl_die_table
11190 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11191 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11192 decl_die_table_in_use = 0;
11194 /* Allocate the initial hunk of the decl_scope_table. */
11195 decl_scope_table
11196 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11197 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11198 decl_scope_depth = 0;
11200 /* Allocate the initial hunk of the abbrev_die_table. */
11201 abbrev_die_table
11202 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11203 sizeof (dw_die_ref));
11204 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11205 /* Zero-th entry is allocated, but unused */
11206 abbrev_die_table_in_use = 1;
11208 /* Allocate the initial hunk of the line_info_table. */
11209 line_info_table
11210 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11211 sizeof (dw_line_info_entry));
11212 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11213 /* Zero-th entry is allocated, but unused */
11214 line_info_table_in_use = 1;
11216 /* Generate the initial DIE for the .debug section. Note that the (string)
11217 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11218 will (typically) be a relative pathname and that this pathname should be
11219 taken as being relative to the directory from which the compiler was
11220 invoked when the given (base) source file was compiled. */
11221 comp_unit_die = gen_compile_unit_die (main_input_filename);
11223 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11224 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11226 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11227 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
11228 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11229 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11230 else
11231 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11232 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11233 DEBUG_INFO_SECTION_LABEL, 0);
11234 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11235 DEBUG_LINE_SECTION_LABEL, 0);
11237 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11238 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11239 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11241 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11242 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11244 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11245 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11246 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11247 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11250 /* Output stuff that dwarf requires at the end of every file,
11251 and generate the DWARF-2 debugging info. */
11253 void
11254 dwarf2out_finish ()
11256 limbo_die_node *node, *next_node;
11257 dw_die_ref die;
11259 /* Traverse the limbo die list, and add parent/child links. The only
11260 dies without parents that should be here are concrete instances of
11261 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11262 For concrete instances, we can get the parent die from the abstract
11263 instance. */
11264 for (node = limbo_die_list; node; node = next_node)
11266 next_node = node->next;
11267 die = node->die;
11269 if (die->die_parent == NULL)
11271 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11272 if (origin)
11273 add_child_die (origin->die_parent, die);
11274 else if (die == comp_unit_die)
11276 else
11277 abort ();
11279 free (node);
11281 limbo_die_list = NULL;
11283 /* Walk through the list of incomplete types again, trying once more to
11284 emit full debugging info for them. */
11285 retry_incomplete_types ();
11287 /* We need to reverse all the dies before break_out_includes, or
11288 we'll see the end of an include file before the beginning. */
11289 reverse_all_dies (comp_unit_die);
11291 /* Generate separate CUs for each of the include files we've seen.
11292 They will go into limbo_die_list. */
11293 if (flag_eliminate_dwarf2_dups)
11294 break_out_includes (comp_unit_die);
11296 /* Traverse the DIE's and add add sibling attributes to those DIE's
11297 that have children. */
11298 add_sibling_attributes (comp_unit_die);
11299 for (node = limbo_die_list; node; node = node->next)
11300 add_sibling_attributes (node->die);
11302 /* Output a terminator label for the .text section. */
11303 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11304 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11306 #if 0
11307 /* Output a terminator label for the .data section. */
11308 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11309 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11311 /* Output a terminator label for the .bss section. */
11312 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11313 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11314 #endif
11316 /* Output the source line correspondence table. We must do this
11317 even if there is no line information. Otherwise, on an empty
11318 translation unit, we will generate a present, but empty,
11319 .debug_info section. IRIX 6.5 `nm' will then complain when
11320 examining the file. */
11321 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11323 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11324 output_line_info ();
11327 /* We can only use the low/high_pc attributes if all of the code was
11328 in .text. */
11329 if (separate_line_info_table_in_use == 0)
11331 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11332 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11335 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11336 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11337 debug_line_section_label);
11339 #if 0 /* unimplemented */
11340 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11341 add_AT_unsigned (die, DW_AT_macro_info, 0);
11342 #endif
11344 /* Output all of the compilation units. We put the main one last so that
11345 the offsets are available to output_pubnames. */
11346 for (node = limbo_die_list; node; node = node->next)
11347 output_comp_unit (node->die);
11348 output_comp_unit (comp_unit_die);
11350 /* Output the abbreviation table. */
11351 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11352 output_abbrev_section ();
11354 if (pubname_table_in_use)
11356 /* Output public names table. */
11357 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11358 output_pubnames ();
11361 /* We only put functions in the arange table, so don't write it out if
11362 we don't have any. */
11363 if (fde_table_in_use)
11365 /* Output the address range information. */
11366 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11367 output_aranges ();
11370 /* At this point, we've switched sections like mad, but we've done
11371 so behind the back of varasm.c. Unfortunately, used
11372 named_section to switch sections doesn't work either; GAS 2.9.5
11373 is not pleased by:
11375 .section debug_aranges,"a",@progbits
11377 on i686-pc-linux-gnu.
11379 By calling force_data_section, we get varasm.c synched back up
11380 with reality. That makes subsequent calls to text_section and
11381 such make sense. */
11382 force_data_section ();
11384 #endif /* DWARF2_DEBUGGING_INFO */