Update version
[official-gcc.git] / gcc / dwarf2out.c
blobc2115481d64204fdcfab0dcf93c510af18d983dc
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 FRAME_BEGIN_LABEL "Lframe"
297 #define CIE_AFTER_SIZE_LABEL "LSCIE"
298 #define CIE_END_LABEL "LECIE"
299 #define CIE_LENGTH_LABEL "LLCIE"
300 #define FDE_LABEL "LSFDE"
301 #define FDE_AFTER_SIZE_LABEL "LASFDE"
302 #define FDE_END_LABEL "LEFDE"
303 #define FDE_LENGTH_LABEL "LLFDE"
304 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
305 #define LINE_NUMBER_END_LABEL "LELT"
306 #define LN_PROLOG_AS_LABEL "LASLTP"
307 #define LN_PROLOG_END_LABEL "LELTP"
308 #define DIE_LABEL_PREFIX "DW"
310 /* Definitions of defaults for various types of primitive assembly language
311 output operations. These may be overridden from within the tm.h file,
312 but typically, that is unnecessary. */
314 #ifndef ASM_OUTPUT_SECTION
315 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
316 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
317 #endif
319 #ifdef SET_ASM_OP
320 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
321 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
322 do { \
323 fprintf (FILE, "%s", SET_ASM_OP); \
324 assemble_name (FILE, SY); \
325 fputc (',', FILE); \
326 assemble_name (FILE, HI); \
327 fputc ('-', FILE); \
328 assemble_name (FILE, LO); \
329 } while (0)
330 #endif
331 #endif /* SET_ASM_OP */
333 /* The DWARF 2 CFA column which tracks the return address. Normally this
334 is the column for PC, or the first column after all of the hard
335 registers. */
336 #ifndef DWARF_FRAME_RETURN_COLUMN
337 #ifdef PC_REGNUM
338 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
339 #else
340 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
341 #endif
342 #endif
344 /* The mapping from gcc register number to DWARF 2 CFA column number. By
345 default, we just provide columns for all registers. */
346 #ifndef DWARF_FRAME_REGNUM
347 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
348 #endif
350 /* Hook used by __throw. */
353 expand_builtin_dwarf_fp_regnum ()
355 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
358 /* The offset from the incoming value of %sp to the top of the stack frame
359 for the current function. */
360 #ifndef INCOMING_FRAME_SP_OFFSET
361 #define INCOMING_FRAME_SP_OFFSET 0
362 #endif
364 /* Return a pointer to a copy of the section string name S with all
365 attributes stripped off, and an asterisk prepended (for assemble_name). */
367 static inline char *
368 stripattributes (s)
369 const char *s;
371 char *stripped = xmalloc (strlen (s) + 2);
372 char *p = stripped;
374 *p++ = '*';
376 while (*s && *s != ',')
377 *p++ = *s++;
379 *p = '\0';
380 return stripped;
383 /* Generate code to initialize the register size table. */
385 void
386 expand_builtin_init_dwarf_reg_sizes (address)
387 tree address;
389 int i;
390 enum machine_mode mode = TYPE_MODE (char_type_node);
391 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
392 rtx mem = gen_rtx_MEM (mode, addr);
394 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
396 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
397 int size = GET_MODE_SIZE (reg_raw_mode[i]);
399 if (offset < 0)
400 continue;
402 emit_move_insn (change_address (mem, mode,
403 plus_constant (addr, offset)),
404 GEN_INT (size));
408 /* Convert a DWARF call frame info. operation to its string name */
410 static const char *
411 dwarf_cfi_name (cfi_opc)
412 register unsigned cfi_opc;
414 switch (cfi_opc)
416 case DW_CFA_advance_loc:
417 return "DW_CFA_advance_loc";
418 case DW_CFA_offset:
419 return "DW_CFA_offset";
420 case DW_CFA_restore:
421 return "DW_CFA_restore";
422 case DW_CFA_nop:
423 return "DW_CFA_nop";
424 case DW_CFA_set_loc:
425 return "DW_CFA_set_loc";
426 case DW_CFA_advance_loc1:
427 return "DW_CFA_advance_loc1";
428 case DW_CFA_advance_loc2:
429 return "DW_CFA_advance_loc2";
430 case DW_CFA_advance_loc4:
431 return "DW_CFA_advance_loc4";
432 case DW_CFA_offset_extended:
433 return "DW_CFA_offset_extended";
434 case DW_CFA_restore_extended:
435 return "DW_CFA_restore_extended";
436 case DW_CFA_undefined:
437 return "DW_CFA_undefined";
438 case DW_CFA_same_value:
439 return "DW_CFA_same_value";
440 case DW_CFA_register:
441 return "DW_CFA_register";
442 case DW_CFA_remember_state:
443 return "DW_CFA_remember_state";
444 case DW_CFA_restore_state:
445 return "DW_CFA_restore_state";
446 case DW_CFA_def_cfa:
447 return "DW_CFA_def_cfa";
448 case DW_CFA_def_cfa_register:
449 return "DW_CFA_def_cfa_register";
450 case DW_CFA_def_cfa_offset:
451 return "DW_CFA_def_cfa_offset";
452 case DW_CFA_def_cfa_expression:
453 return "DW_CFA_def_cfa_expression";
455 /* SGI/MIPS specific */
456 case DW_CFA_MIPS_advance_loc8:
457 return "DW_CFA_MIPS_advance_loc8";
459 /* GNU extensions */
460 case DW_CFA_GNU_window_save:
461 return "DW_CFA_GNU_window_save";
462 case DW_CFA_GNU_args_size:
463 return "DW_CFA_GNU_args_size";
464 case DW_CFA_GNU_negative_offset_extended:
465 return "DW_CFA_GNU_negative_offset_extended";
467 default:
468 return "DW_CFA_<unknown>";
472 /* Return a pointer to a newly allocated Call Frame Instruction. */
474 static inline dw_cfi_ref
475 new_cfi ()
477 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
479 cfi->dw_cfi_next = NULL;
480 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
481 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
483 return cfi;
486 /* Add a Call Frame Instruction to list of instructions. */
488 static inline void
489 add_cfi (list_head, cfi)
490 register dw_cfi_ref *list_head;
491 register dw_cfi_ref cfi;
493 register dw_cfi_ref *p;
495 /* Find the end of the chain. */
496 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
499 *p = cfi;
502 /* Generate a new label for the CFI info to refer to. */
504 char *
505 dwarf2out_cfi_label ()
507 static char label[20];
508 static unsigned long label_num = 0;
510 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
511 ASM_OUTPUT_LABEL (asm_out_file, label);
513 return label;
516 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
517 or to the CIE if LABEL is NULL. */
519 static void
520 add_fde_cfi (label, cfi)
521 register const char *label;
522 register dw_cfi_ref cfi;
524 if (label)
526 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
528 if (*label == 0)
529 label = dwarf2out_cfi_label ();
531 if (fde->dw_fde_current_label == NULL
532 || strcmp (label, fde->dw_fde_current_label) != 0)
534 register dw_cfi_ref xcfi;
536 fde->dw_fde_current_label = label = xstrdup (label);
538 /* Set the location counter to the new label. */
539 xcfi = new_cfi ();
540 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
541 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
542 add_cfi (&fde->dw_fde_cfi, xcfi);
545 add_cfi (&fde->dw_fde_cfi, cfi);
548 else
549 add_cfi (&cie_cfi_head, cfi);
552 /* Subroutine of lookup_cfa. */
554 static inline void
555 lookup_cfa_1 (cfi, loc)
556 register dw_cfi_ref cfi;
557 register dw_cfa_location *loc;
559 switch (cfi->dw_cfi_opc)
561 case DW_CFA_def_cfa_offset:
562 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
563 break;
564 case DW_CFA_def_cfa_register:
565 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
566 break;
567 case DW_CFA_def_cfa:
568 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
569 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
570 break;
571 case DW_CFA_def_cfa_expression:
572 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
573 break;
574 default:
575 break;
579 /* Find the previous value for the CFA. */
581 static void
582 lookup_cfa (loc)
583 register dw_cfa_location *loc;
585 register dw_cfi_ref cfi;
587 loc->reg = (unsigned long) -1;
588 loc->offset = 0;
589 loc->indirect = 0;
590 loc->base_offset = 0;
592 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
593 lookup_cfa_1 (cfi, loc);
595 if (fde_table_in_use)
597 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
598 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
599 lookup_cfa_1 (cfi, loc);
603 /* The current rule for calculating the DWARF2 canonical frame address. */
604 static dw_cfa_location cfa;
606 /* The register used for saving registers to the stack, and its offset
607 from the CFA. */
608 static dw_cfa_location cfa_store;
610 /* The running total of the size of arguments pushed onto the stack. */
611 static long args_size;
613 /* The last args_size we actually output. */
614 static long old_args_size;
616 /* Entry point to update the canonical frame address (CFA).
617 LABEL is passed to add_fde_cfi. The value of CFA is now to be
618 calculated from REG+OFFSET. */
620 void
621 dwarf2out_def_cfa (label, reg, offset)
622 register const char *label;
623 unsigned reg;
624 long offset;
626 dw_cfa_location loc;
627 loc.indirect = 0;
628 loc.base_offset = 0;
629 loc.reg = reg;
630 loc.offset = offset;
631 def_cfa_1 (label, &loc);
634 /* This routine does the actual work. The CFA is now calculated from
635 the dw_cfa_location structure. */
636 static void
637 def_cfa_1 (label, loc_p)
638 register const char *label;
639 dw_cfa_location *loc_p;
641 register dw_cfi_ref cfi;
642 dw_cfa_location old_cfa, loc;
644 cfa = *loc_p;
645 loc = *loc_p;
647 if (cfa_store.reg == loc.reg && loc.indirect == 0)
648 cfa_store.offset = loc.offset;
650 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
651 lookup_cfa (&old_cfa);
653 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
654 loc.indirect == old_cfa.indirect)
656 if (loc.indirect == 0
657 || loc.base_offset == old_cfa.base_offset)
658 /* Nothing changed so no need to issue any call frame
659 instructions. */
660 return;
663 cfi = new_cfi ();
665 if (loc.reg == old_cfa.reg && !loc.indirect)
667 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
668 indicating the CFA register did not change but the offset
669 did. */
670 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
671 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
674 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
675 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
676 && !loc.indirect)
678 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
679 indicating the CFA register has changed to <register> but the
680 offset has not changed. */
681 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
682 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
684 #endif
686 else if (loc.indirect == 0)
688 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
689 indicating the CFA register has changed to <register> with
690 the specified offset. */
691 cfi->dw_cfi_opc = DW_CFA_def_cfa;
692 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
693 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
695 else
697 /* Construct a DW_CFA_def_cfa_expression instruction to
698 calculate the CFA using a full location expression since no
699 register-offset pair is available. */
700 struct dw_loc_descr_struct *loc_list;
701 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
702 loc_list = build_cfa_loc (&loc);
703 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
706 add_fde_cfi (label, cfi);
709 /* Add the CFI for saving a register. REG is the CFA column number.
710 LABEL is passed to add_fde_cfi.
711 If SREG is -1, the register is saved at OFFSET from the CFA;
712 otherwise it is saved in SREG. */
714 static void
715 reg_save (label, reg, sreg, offset)
716 register const char *label;
717 register unsigned reg;
718 register unsigned sreg;
719 register long offset;
721 register dw_cfi_ref cfi = new_cfi ();
723 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
725 /* The following comparison is correct. -1 is used to indicate that
726 the value isn't a register number. */
727 if (sreg == (unsigned int) -1)
729 if (reg & ~0x3f)
730 /* The register number won't fit in 6 bits, so we have to use
731 the long form. */
732 cfi->dw_cfi_opc = DW_CFA_offset_extended;
733 else
734 cfi->dw_cfi_opc = DW_CFA_offset;
736 #ifdef ENABLE_CHECKING
738 /* If we get an offset that is not a multiple of
739 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
740 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
741 description. */
742 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
744 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
745 abort ();
747 #endif
748 offset /= DWARF_CIE_DATA_ALIGNMENT;
749 if (offset < 0)
751 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
752 offset = -offset;
754 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
756 else if (sreg == reg)
757 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
758 return;
759 else
761 cfi->dw_cfi_opc = DW_CFA_register;
762 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
765 add_fde_cfi (label, cfi);
768 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
769 This CFI tells the unwinder that it needs to restore the window registers
770 from the previous frame's window save area.
772 ??? Perhaps we should note in the CIE where windows are saved (instead of
773 assuming 0(cfa)) and what registers are in the window. */
775 void
776 dwarf2out_window_save (label)
777 register const char *label;
779 register dw_cfi_ref cfi = new_cfi ();
780 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
781 add_fde_cfi (label, cfi);
784 /* Add a CFI to update the running total of the size of arguments
785 pushed onto the stack. */
787 void
788 dwarf2out_args_size (label, size)
789 const char *label;
790 long size;
792 register dw_cfi_ref cfi;
794 if (size == old_args_size)
795 return;
796 old_args_size = size;
798 cfi = new_cfi ();
799 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
800 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
801 add_fde_cfi (label, cfi);
804 /* Entry point for saving a register to the stack. REG is the GCC register
805 number. LABEL and OFFSET are passed to reg_save. */
807 void
808 dwarf2out_reg_save (label, reg, offset)
809 register const char *label;
810 register unsigned reg;
811 register long offset;
813 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
816 /* Entry point for saving the return address in the stack.
817 LABEL and OFFSET are passed to reg_save. */
819 void
820 dwarf2out_return_save (label, offset)
821 register const char *label;
822 register long offset;
824 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
827 /* Entry point for saving the return address in a register.
828 LABEL and SREG are passed to reg_save. */
830 void
831 dwarf2out_return_reg (label, sreg)
832 register const char *label;
833 register unsigned sreg;
835 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
838 /* Record the initial position of the return address. RTL is
839 INCOMING_RETURN_ADDR_RTX. */
841 static void
842 initial_return_save (rtl)
843 register rtx rtl;
845 unsigned int reg = (unsigned int) -1;
846 long offset = 0;
848 switch (GET_CODE (rtl))
850 case REG:
851 /* RA is in a register. */
852 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
853 break;
854 case MEM:
855 /* RA is on the stack. */
856 rtl = XEXP (rtl, 0);
857 switch (GET_CODE (rtl))
859 case REG:
860 if (REGNO (rtl) != STACK_POINTER_REGNUM)
861 abort ();
862 offset = 0;
863 break;
864 case PLUS:
865 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
866 abort ();
867 offset = INTVAL (XEXP (rtl, 1));
868 break;
869 case MINUS:
870 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
871 abort ();
872 offset = -INTVAL (XEXP (rtl, 1));
873 break;
874 default:
875 abort ();
877 break;
878 case PLUS:
879 /* The return address is at some offset from any value we can
880 actually load. For instance, on the SPARC it is in %i7+8. Just
881 ignore the offset for now; it doesn't matter for unwinding frames. */
882 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
883 abort ();
884 initial_return_save (XEXP (rtl, 0));
885 return;
886 default:
887 abort ();
890 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
893 /* Given a SET, calculate the amount of stack adjustment it
894 contains. */
896 static long
897 stack_adjust_offset (pattern)
898 rtx pattern;
900 rtx src = SET_SRC (pattern);
901 rtx dest = SET_DEST (pattern);
902 long offset = 0;
903 enum rtx_code code;
905 if (dest == stack_pointer_rtx)
907 /* (set (reg sp) (plus (reg sp) (const_int))) */
908 code = GET_CODE (src);
909 if (! (code == PLUS || code == MINUS)
910 || XEXP (src, 0) != stack_pointer_rtx
911 || GET_CODE (XEXP (src, 1)) != CONST_INT)
912 return 0;
914 offset = INTVAL (XEXP (src, 1));
916 else if (GET_CODE (dest) == MEM)
918 /* (set (mem (pre_dec (reg sp))) (foo)) */
919 src = XEXP (dest, 0);
920 code = GET_CODE (src);
922 if (! (code == PRE_DEC || code == PRE_INC
923 || code == PRE_MODIFY)
924 || XEXP (src, 0) != stack_pointer_rtx)
925 return 0;
927 if (code == PRE_MODIFY)
929 rtx val = XEXP (XEXP (src, 1), 1);
930 /* We handle only adjustments by constant amount. */
931 if (GET_CODE (XEXP (src, 1)) != PLUS ||
932 GET_CODE (val) != CONST_INT)
933 abort();
934 offset = -INTVAL (val);
936 else offset = GET_MODE_SIZE (GET_MODE (dest));
938 else
939 return 0;
941 if (code == PLUS || code == PRE_INC)
942 offset = -offset;
944 return offset;
947 /* Check INSN to see if it looks like a push or a stack adjustment, and
948 make a note of it if it does. EH uses this information to find out how
949 much extra space it needs to pop off the stack. */
951 static void
952 dwarf2out_stack_adjust (insn)
953 rtx insn;
955 long offset;
956 const char *label;
958 if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN)
960 /* Extract the size of the args from the CALL rtx itself. */
962 insn = PATTERN (insn);
963 if (GET_CODE (insn) == PARALLEL)
964 insn = XVECEXP (insn, 0, 0);
965 if (GET_CODE (insn) == SET)
966 insn = SET_SRC (insn);
967 if (GET_CODE (insn) != CALL)
968 abort ();
969 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
970 return;
973 /* If only calls can throw, and we have a frame pointer,
974 save up adjustments until we see the CALL_INSN. */
975 else if (! flag_non_call_exceptions
976 && cfa.reg != STACK_POINTER_REGNUM)
977 return;
979 if (GET_CODE (insn) == BARRIER)
981 /* When we see a BARRIER, we know to reset args_size to 0. Usually
982 the compiler will have already emitted a stack adjustment, but
983 doesn't bother for calls to noreturn functions. */
984 #ifdef STACK_GROWS_DOWNWARD
985 offset = -args_size;
986 #else
987 offset = args_size;
988 #endif
990 else if (GET_CODE (PATTERN (insn)) == SET)
992 offset = stack_adjust_offset (PATTERN (insn));
994 else if (GET_CODE (PATTERN (insn)) == PARALLEL
995 || GET_CODE (PATTERN (insn)) == SEQUENCE)
997 /* There may be stack adjustments inside compound insns. Search
998 for them. */
999 int j;
1001 offset = 0;
1002 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1004 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1005 if (GET_CODE (pattern) == SET)
1006 offset += stack_adjust_offset (pattern);
1009 else
1010 return;
1012 if (offset == 0)
1013 return;
1015 if (cfa.reg == STACK_POINTER_REGNUM)
1016 cfa.offset += offset;
1018 #ifndef STACK_GROWS_DOWNWARD
1019 offset = -offset;
1020 #endif
1021 args_size += offset;
1022 if (args_size < 0)
1023 args_size = 0;
1025 label = dwarf2out_cfi_label ();
1026 def_cfa_1 (label, &cfa);
1027 dwarf2out_args_size (label, args_size);
1030 /* We delay emitting a register save until either (a) we reach the end
1031 of the prologue or (b) the register is clobbered. This clusters
1032 register saves so that there are fewer pc advances. */
1034 struct queued_reg_save
1036 struct queued_reg_save *next;
1037 rtx reg;
1038 long cfa_offset;
1041 static struct queued_reg_save *queued_reg_saves;
1042 static const char *last_reg_save_label;
1044 static void
1045 queue_reg_save (label, reg, offset)
1046 const char *label;
1047 rtx reg;
1048 long offset;
1050 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1052 q->next = queued_reg_saves;
1053 q->reg = reg;
1054 q->cfa_offset = offset;
1055 queued_reg_saves = q;
1057 last_reg_save_label = label;
1060 static void
1061 flush_queued_reg_saves ()
1063 struct queued_reg_save *q, *next;
1065 for (q = queued_reg_saves; q ; q = next)
1067 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1068 next = q->next;
1069 free (q);
1072 queued_reg_saves = NULL;
1073 last_reg_save_label = NULL;
1076 static bool
1077 clobbers_queued_reg_save (insn)
1078 rtx insn;
1080 struct queued_reg_save *q;
1082 for (q = queued_reg_saves; q ; q = q->next)
1083 if (modified_in_p (q->reg, insn))
1084 return true;
1086 return false;
1090 /* A temporary register holding an integral value used in adjusting SP
1091 or setting up the store_reg. The "offset" field holds the integer
1092 value, not an offset. */
1093 static dw_cfa_location cfa_temp;
1095 /* Record call frame debugging information for an expression EXPR,
1096 which either sets SP or FP (adjusting how we calculate the frame
1097 address) or saves a register to the stack. LABEL indicates the
1098 address of EXPR.
1100 This function encodes a state machine mapping rtxes to actions on
1101 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1102 users need not read the source code.
1104 The High-Level Picture
1106 Changes in the register we use to calculate the CFA: Currently we
1107 assume that if you copy the CFA register into another register, we
1108 should take the other one as the new CFA register; this seems to
1109 work pretty well. If it's wrong for some target, it's simple
1110 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1112 Changes in the register we use for saving registers to the stack:
1113 This is usually SP, but not always. Again, we deduce that if you
1114 copy SP into another register (and SP is not the CFA register),
1115 then the new register is the one we will be using for register
1116 saves. This also seems to work.
1118 Register saves: There's not much guesswork about this one; if
1119 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1120 register save, and the register used to calculate the destination
1121 had better be the one we think we're using for this purpose.
1123 Except: If the register being saved is the CFA register, and the
1124 offset is non-zero, we are saving the CFA, so we assume we have to
1125 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1126 the intent is to save the value of SP from the previous frame.
1128 Invariants / Summaries of Rules
1130 cfa current rule for calculating the CFA. It usually
1131 consists of a register and an offset.
1132 cfa_store register used by prologue code to save things to the stack
1133 cfa_store.offset is the offset from the value of
1134 cfa_store.reg to the actual CFA
1135 cfa_temp register holding an integral value. cfa_temp.offset
1136 stores the value, which will be used to adjust the
1137 stack pointer. cfa_temp is also used like cfa_store,
1138 to track stores to the stack via fp or a temp reg.
1140 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1141 with cfa.reg as the first operand changes the cfa.reg and its
1142 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1143 cfa_temp.offset.
1145 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1146 expression yielding a constant. This sets cfa_temp.reg
1147 and cfa_temp.offset.
1149 Rule 5: Create a new register cfa_store used to save items to the
1150 stack.
1152 Rules 10-14: Save a register to the stack. Define offset as the
1153 difference of the original location and cfa_store's
1154 location (or cfa_temp's location if cfa_temp is used).
1156 The Rules
1158 "{a,b}" indicates a choice of a xor b.
1159 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1161 Rule 1:
1162 (set <reg1> <reg2>:cfa.reg)
1163 effects: cfa.reg = <reg1>
1164 cfa.offset unchanged
1165 cfa_temp.reg = <reg1>
1166 cfa_temp.offset = cfa.offset
1168 Rule 2:
1169 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1170 effects: cfa.reg = sp if fp used
1171 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1172 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1173 if cfa_store.reg==sp
1175 Rule 3:
1176 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1177 effects: cfa.reg = fp
1178 cfa_offset += +/- <const_int>
1180 Rule 4:
1181 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1182 constraints: <reg1> != fp
1183 <reg1> != sp
1184 effects: cfa.reg = <reg1>
1185 cfa_temp.reg = <reg1>
1186 cfa_temp.offset = cfa.offset
1188 Rule 5:
1189 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1190 constraints: <reg1> != fp
1191 <reg1> != sp
1192 effects: cfa_store.reg = <reg1>
1193 cfa_store.offset = cfa.offset - cfa_temp.offset
1195 Rule 6:
1196 (set <reg> <const_int>)
1197 effects: cfa_temp.reg = <reg>
1198 cfa_temp.offset = <const_int>
1200 Rule 7:
1201 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1202 effects: cfa_temp.reg = <reg1>
1203 cfa_temp.offset |= <const_int>
1205 Rule 8:
1206 (set <reg> (high <exp>))
1207 effects: none
1209 Rule 9:
1210 (set <reg> (lo_sum <exp> <const_int>))
1211 effects: cfa_temp.reg = <reg>
1212 cfa_temp.offset = <const_int>
1214 Rule 10:
1215 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1216 effects: cfa_store.offset -= <const_int>
1217 cfa.offset = cfa_store.offset if cfa.reg == sp
1218 cfa.reg = sp
1219 cfa.base_offset = -cfa_store.offset
1221 Rule 11:
1222 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1223 effects: cfa_store.offset += -/+ mode_size(mem)
1224 cfa.offset = cfa_store.offset if cfa.reg == sp
1225 cfa.reg = sp
1226 cfa.base_offset = -cfa_store.offset
1228 Rule 12:
1229 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>)
1230 effects: cfa.reg = <reg1>
1231 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1233 Rule 13:
1234 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1235 effects: cfa.reg = <reg1>
1236 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1238 Rule 14:
1239 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1240 effects: cfa.reg = <reg1>
1241 cfa.base_offset = -cfa_temp.offset
1242 cfa_temp.offset -= mode_size(mem) */
1244 static void
1245 dwarf2out_frame_debug_expr (expr, label)
1246 rtx expr;
1247 const char *label;
1249 rtx src, dest;
1250 long offset;
1252 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1253 the PARALLEL independently. The first element is always processed if
1254 it is a SET. This is for backward compatibility. Other elements
1255 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1256 flag is set in them. */
1258 if (GET_CODE (expr) == PARALLEL
1259 || GET_CODE (expr) == SEQUENCE)
1261 int par_index;
1262 int limit = XVECLEN (expr, 0);
1264 for (par_index = 0; par_index < limit; par_index++)
1266 rtx x = XVECEXP (expr, 0, par_index);
1268 if (GET_CODE (x) == SET &&
1269 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1270 dwarf2out_frame_debug_expr (x, label);
1272 return;
1275 if (GET_CODE (expr) != SET)
1276 abort ();
1278 src = SET_SRC (expr);
1279 dest = SET_DEST (expr);
1281 switch (GET_CODE (dest))
1283 case REG:
1284 /* Rule 1 */
1285 /* Update the CFA rule wrt SP or FP. Make sure src is
1286 relative to the current CFA register. */
1287 switch (GET_CODE (src))
1289 /* Setting FP from SP. */
1290 case REG:
1291 if (cfa.reg == (unsigned) REGNO (src))
1292 /* OK. */
1294 else
1295 abort ();
1297 /* We used to require that dest be either SP or FP, but the
1298 ARM copies SP to a temporary register, and from there to
1299 FP. So we just rely on the backends to only set
1300 RTX_FRAME_RELATED_P on appropriate insns. */
1301 cfa.reg = REGNO (dest);
1302 cfa_temp.reg = cfa.reg;
1303 cfa_temp.offset = cfa.offset;
1304 break;
1306 case PLUS:
1307 case MINUS:
1308 case LO_SUM:
1309 if (dest == stack_pointer_rtx)
1311 /* Rule 2 */
1312 /* Adjusting SP. */
1313 switch (GET_CODE (XEXP (src, 1)))
1315 case CONST_INT:
1316 offset = INTVAL (XEXP (src, 1));
1317 break;
1318 case REG:
1319 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1320 abort ();
1321 offset = cfa_temp.offset;
1322 break;
1323 default:
1324 abort ();
1327 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1329 /* Restoring SP from FP in the epilogue. */
1330 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1331 abort ();
1332 cfa.reg = STACK_POINTER_REGNUM;
1334 else if (GET_CODE (src) == LO_SUM)
1335 /* Assume we've set the source reg of the LO_SUM from sp. */
1337 else if (XEXP (src, 0) != stack_pointer_rtx)
1338 abort ();
1340 if (GET_CODE (src) != MINUS)
1341 offset = -offset;
1342 if (cfa.reg == STACK_POINTER_REGNUM)
1343 cfa.offset += offset;
1344 if (cfa_store.reg == STACK_POINTER_REGNUM)
1345 cfa_store.offset += offset;
1347 else if (dest == hard_frame_pointer_rtx)
1349 /* Rule 3 */
1350 /* Either setting the FP from an offset of the SP,
1351 or adjusting the FP */
1352 if (! frame_pointer_needed)
1353 abort ();
1355 if (GET_CODE (XEXP (src, 0)) == REG
1356 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1357 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1359 offset = INTVAL (XEXP (src, 1));
1360 if (GET_CODE (src) != MINUS)
1361 offset = -offset;
1362 cfa.offset += offset;
1363 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1365 else
1366 abort ();
1368 else
1370 if (GET_CODE (src) == MINUS)
1371 abort ();
1373 /* Rule 4 */
1374 if (GET_CODE (XEXP (src, 0)) == REG
1375 && REGNO (XEXP (src, 0)) == cfa.reg
1376 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1378 /* Setting a temporary CFA register that will be copied
1379 into the FP later on. */
1380 offset = - INTVAL (XEXP (src, 1));
1381 cfa.offset += offset;
1382 cfa.reg = REGNO (dest);
1383 /* Or used to save regs to the stack. */
1384 cfa_temp.reg = cfa.reg;
1385 cfa_temp.offset = cfa.offset;
1387 /* Rule 5 */
1388 else if (GET_CODE (XEXP (src, 0)) == REG
1389 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1390 && XEXP (src, 1) == stack_pointer_rtx)
1392 /* Setting a scratch register that we will use instead
1393 of SP for saving registers to the stack. */
1394 if (cfa.reg != STACK_POINTER_REGNUM)
1395 abort ();
1396 cfa_store.reg = REGNO (dest);
1397 cfa_store.offset = cfa.offset - cfa_temp.offset;
1399 /* Rule 9 */
1400 else if (GET_CODE (src) == LO_SUM
1401 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1403 cfa_temp.reg = REGNO (dest);
1404 cfa_temp.offset = INTVAL (XEXP (src, 1));
1406 else
1407 abort ();
1409 break;
1411 /* Rule 6 */
1412 case CONST_INT:
1413 cfa_temp.reg = REGNO (dest);
1414 cfa_temp.offset = INTVAL (src);
1415 break;
1417 /* Rule 7 */
1418 case IOR:
1419 if (GET_CODE (XEXP (src, 0)) != REG
1420 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1421 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1422 abort ();
1423 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1424 cfa_temp.reg = REGNO (dest);
1425 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1426 break;
1428 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1429 which will fill in all of the bits. */
1430 /* Rule 8 */
1431 case HIGH:
1432 break;
1434 default:
1435 abort ();
1437 def_cfa_1 (label, &cfa);
1438 break;
1440 case MEM:
1441 if (GET_CODE (src) != REG)
1442 abort ();
1444 /* Saving a register to the stack. Make sure dest is relative to the
1445 CFA register. */
1446 switch (GET_CODE (XEXP (dest, 0)))
1448 /* Rule 10 */
1449 /* With a push. */
1450 case PRE_MODIFY:
1451 /* We can't handle variable size modifications. */
1452 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1453 abort();
1454 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1456 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1457 || cfa_store.reg != STACK_POINTER_REGNUM)
1458 abort ();
1459 cfa_store.offset += offset;
1460 if (cfa.reg == STACK_POINTER_REGNUM)
1461 cfa.offset = cfa_store.offset;
1463 offset = -cfa_store.offset;
1464 break;
1465 /* Rule 11 */
1466 case PRE_INC:
1467 case PRE_DEC:
1468 offset = GET_MODE_SIZE (GET_MODE (dest));
1469 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1470 offset = -offset;
1472 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1473 || cfa_store.reg != STACK_POINTER_REGNUM)
1474 abort ();
1475 cfa_store.offset += offset;
1476 if (cfa.reg == STACK_POINTER_REGNUM)
1477 cfa.offset = cfa_store.offset;
1479 offset = -cfa_store.offset;
1480 break;
1482 /* Rule 12 */
1483 /* With an offset. */
1484 case PLUS:
1485 case MINUS:
1486 case LO_SUM:
1487 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1488 abort ();
1489 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1490 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1491 offset = -offset;
1493 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1494 offset -= cfa_store.offset;
1495 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1496 offset -= cfa_temp.offset;
1497 else
1498 abort ();
1499 break;
1501 /* Rule 13 */
1502 /* Without an offset. */
1503 case REG:
1504 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1505 offset = -cfa_store.offset;
1506 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1507 offset = -cfa_temp.offset;
1508 else
1509 abort ();
1510 break;
1512 /* Rule 14 */
1513 case POST_INC:
1514 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1515 abort ();
1516 offset = -cfa_temp.offset;
1517 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1518 break;
1520 default:
1521 abort ();
1524 if (REGNO (src) != STACK_POINTER_REGNUM
1525 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1526 && (unsigned) REGNO (src) == cfa.reg)
1528 /* We're storing the current CFA reg into the stack. */
1530 if (cfa.offset == 0)
1532 /* If the source register is exactly the CFA, assume
1533 we're saving SP like any other register; this happens
1534 on the ARM. */
1536 def_cfa_1 (label, &cfa);
1537 queue_reg_save (label, stack_pointer_rtx, offset);
1538 break;
1540 else
1542 /* Otherwise, we'll need to look in the stack to
1543 calculate the CFA. */
1545 rtx x = XEXP (dest, 0);
1546 if (GET_CODE (x) != REG)
1547 x = XEXP (x, 0);
1548 if (GET_CODE (x) != REG)
1549 abort ();
1550 cfa.reg = (unsigned) REGNO (x);
1551 cfa.base_offset = offset;
1552 cfa.indirect = 1;
1553 def_cfa_1 (label, &cfa);
1554 break;
1558 def_cfa_1 (label, &cfa);
1559 queue_reg_save (label, src, offset);
1560 break;
1562 default:
1563 abort ();
1567 /* Record call frame debugging information for INSN, which either
1568 sets SP or FP (adjusting how we calculate the frame address) or saves a
1569 register to the stack. If INSN is NULL_RTX, initialize our state. */
1571 void
1572 dwarf2out_frame_debug (insn)
1573 rtx insn;
1575 const char *label;
1576 rtx src;
1578 if (insn == NULL_RTX)
1580 /* Flush any queued register saves. */
1581 flush_queued_reg_saves ();
1583 /* Set up state for generating call frame debug info. */
1584 lookup_cfa (&cfa);
1585 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1586 abort ();
1587 cfa.reg = STACK_POINTER_REGNUM;
1588 cfa_store = cfa;
1589 cfa_temp.reg = -1;
1590 cfa_temp.offset = 0;
1591 return;
1594 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1595 flush_queued_reg_saves ();
1597 if (! RTX_FRAME_RELATED_P (insn))
1599 if (!ACCUMULATE_OUTGOING_ARGS)
1600 dwarf2out_stack_adjust (insn);
1601 return;
1604 label = dwarf2out_cfi_label ();
1606 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1607 if (src)
1608 insn = XEXP (src, 0);
1609 else
1610 insn = PATTERN (insn);
1612 dwarf2out_frame_debug_expr (insn, label);
1615 /* Output a Call Frame Information opcode and its operand(s). */
1617 static void
1618 output_cfi (cfi, fde, for_eh)
1619 register dw_cfi_ref cfi;
1620 register dw_fde_ref fde;
1621 int for_eh;
1623 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1625 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1626 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1627 "DW_CFA_advance_loc 0x%lx",
1628 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1630 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1632 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1633 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1634 "DW_CFA_offset, column 0x%lx",
1635 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1636 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1638 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1640 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1641 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1642 "DW_CFA_restore, column 0x%lx",
1643 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1645 else
1647 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1648 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1650 switch (cfi->dw_cfi_opc)
1652 case DW_CFA_set_loc:
1653 if (for_eh)
1654 dw2_asm_output_encoded_addr_rtx (
1655 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1656 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1657 NULL);
1658 else
1659 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1660 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1661 break;
1662 case DW_CFA_advance_loc1:
1663 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1664 fde->dw_fde_current_label, NULL);
1665 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1666 break;
1667 case DW_CFA_advance_loc2:
1668 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1669 fde->dw_fde_current_label, NULL);
1670 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1671 break;
1672 case DW_CFA_advance_loc4:
1673 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1674 fde->dw_fde_current_label, NULL);
1675 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1676 break;
1677 case DW_CFA_MIPS_advance_loc8:
1678 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1679 fde->dw_fde_current_label, NULL);
1680 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1681 break;
1682 case DW_CFA_offset_extended:
1683 case DW_CFA_GNU_negative_offset_extended:
1684 case DW_CFA_def_cfa:
1685 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1686 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1687 break;
1688 case DW_CFA_restore_extended:
1689 case DW_CFA_undefined:
1690 case DW_CFA_same_value:
1691 case DW_CFA_def_cfa_register:
1692 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1693 break;
1694 case DW_CFA_register:
1695 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1696 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1697 break;
1698 case DW_CFA_def_cfa_offset:
1699 case DW_CFA_GNU_args_size:
1700 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1701 break;
1702 case DW_CFA_GNU_window_save:
1703 break;
1704 case DW_CFA_def_cfa_expression:
1705 output_cfa_loc (cfi);
1706 break;
1707 default:
1708 break;
1713 /* Output the call frame information used to used to record information
1714 that relates to calculating the frame pointer, and records the
1715 location of saved registers. */
1717 static void
1718 output_call_frame_info (for_eh)
1719 int for_eh;
1721 register unsigned long i;
1722 register dw_fde_ref fde;
1723 register dw_cfi_ref cfi;
1724 char l1[20], l2[20], section_start_label[20];
1725 int any_lsda_needed = 0;
1726 char augmentation[6];
1727 int augmentation_size;
1728 int fde_encoding = DW_EH_PE_absptr;
1729 int per_encoding = DW_EH_PE_absptr;
1730 int lsda_encoding = DW_EH_PE_absptr;
1732 /* If we don't have any functions we'll want to unwind out of, don't
1733 emit any EH unwind information. */
1734 if (for_eh)
1736 int any_eh_needed = 0;
1737 for (i = 0; i < fde_table_in_use; ++i)
1738 if (fde_table[i].uses_eh_lsda)
1739 any_eh_needed = any_lsda_needed = 1;
1740 else if (! fde_table[i].nothrow)
1741 any_eh_needed = 1;
1743 if (! any_eh_needed)
1744 return;
1747 /* We're going to be generating comments, so turn on app. */
1748 if (flag_debug_asm)
1749 app_enable ();
1751 if (for_eh)
1753 #ifdef EH_FRAME_SECTION
1754 EH_FRAME_SECTION ();
1755 #else
1756 tree label = get_file_function_name ('F');
1758 force_data_section ();
1759 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1760 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1761 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1762 #endif
1764 else
1765 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1767 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1768 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1770 /* Output the CIE. */
1771 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1772 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1773 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1774 "Length of Common Information Entry");
1775 ASM_OUTPUT_LABEL (asm_out_file, l1);
1777 /* Now that the CIE pointer is PC-relative for EH,
1778 use 0 to identify the CIE. */
1779 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1780 (for_eh ? 0 : DW_CIE_ID),
1781 "CIE Identifier Tag");
1783 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1785 augmentation[0] = 0;
1786 augmentation_size = 0;
1787 if (for_eh)
1789 char *p;
1791 /* Augmentation:
1792 z Indicates that a uleb128 is present to size the
1793 augmentation section.
1794 L Indicates the encoding (and thus presence) of
1795 an LSDA pointer in the FDE augmentation.
1796 R Indicates a non-default pointer encoding for
1797 FDE code pointers.
1798 P Indicates the presence of an encoding + language
1799 personality routine in the CIE augmentation. */
1801 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1802 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1803 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1805 p = augmentation + 1;
1806 if (eh_personality_libfunc)
1808 *p++ = 'P';
1809 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1811 if (any_lsda_needed)
1813 *p++ = 'L';
1814 augmentation_size += 1;
1816 if (fde_encoding != DW_EH_PE_absptr)
1818 *p++ = 'R';
1819 augmentation_size += 1;
1821 if (p > augmentation + 1)
1823 augmentation[0] = 'z';
1824 *p = '\0';
1827 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1828 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1830 int offset = ( 4 /* Length */
1831 + 4 /* CIE Id */
1832 + 1 /* CIE version */
1833 + strlen (augmentation) + 1 /* Augmentation */
1834 + size_of_uleb128 (1) /* Code alignment */
1835 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1836 + 1 /* RA column */
1837 + 1 /* Augmentation size */
1838 + 1 /* Personality encoding */ );
1839 int pad = -offset & (PTR_SIZE - 1);
1841 augmentation_size += pad;
1843 /* Augmentations should be small, so there's scarce need to
1844 iterate for a solution. Die if we exceed one uleb128 byte. */
1845 if (size_of_uleb128 (augmentation_size) != 1)
1846 abort ();
1849 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1851 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1853 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1854 "CIE Data Alignment Factor");
1856 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1858 if (augmentation[0])
1860 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1861 if (eh_personality_libfunc)
1863 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1864 eh_data_format_name (per_encoding));
1865 dw2_asm_output_encoded_addr_rtx (per_encoding,
1866 eh_personality_libfunc, NULL);
1868 if (any_lsda_needed)
1869 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1870 eh_data_format_name (lsda_encoding));
1871 if (fde_encoding != DW_EH_PE_absptr)
1872 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1873 eh_data_format_name (fde_encoding));
1876 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1877 output_cfi (cfi, NULL, for_eh);
1879 /* Pad the CIE out to an address sized boundary. */
1880 ASM_OUTPUT_ALIGN (asm_out_file,
1881 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1882 ASM_OUTPUT_LABEL (asm_out_file, l2);
1884 /* Loop through all of the FDE's. */
1885 for (i = 0; i < fde_table_in_use; ++i)
1887 fde = &fde_table[i];
1889 /* Don't emit EH unwind info for leaf functions that don't need it. */
1890 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1891 continue;
1893 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1894 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1895 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1896 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1897 "FDE Length");
1898 ASM_OUTPUT_LABEL (asm_out_file, l1);
1900 if (for_eh)
1901 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
1902 else
1903 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
1904 "FDE CIE offset");
1906 if (for_eh)
1908 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1909 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1910 "FDE initial location");
1911 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1912 fde->dw_fde_end, fde->dw_fde_begin,
1913 "FDE address range");
1915 else
1917 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1918 "FDE initial location");
1919 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1920 fde->dw_fde_end, fde->dw_fde_begin,
1921 "FDE address range");
1924 if (augmentation[0])
1926 if (any_lsda_needed)
1928 int size = size_of_encoded_value (lsda_encoding);
1930 if (lsda_encoding == DW_EH_PE_aligned)
1932 int offset = ( 4 /* Length */
1933 + 4 /* CIE offset */
1934 + 2 * size_of_encoded_value (fde_encoding)
1935 + 1 /* Augmentation size */ );
1936 int pad = -offset & (PTR_SIZE - 1);
1938 size += pad;
1939 if (size_of_uleb128 (size) != 1)
1940 abort ();
1943 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1945 if (fde->uses_eh_lsda)
1947 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
1948 fde->funcdef_number);
1949 dw2_asm_output_encoded_addr_rtx (
1950 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
1951 "Language Specific Data Area");
1953 else
1955 if (lsda_encoding == DW_EH_PE_aligned)
1956 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1957 dw2_asm_output_data (size_of_encoded_value (lsda_encoding),
1958 0, "Language Specific Data Area (none)");
1961 else
1962 dw2_asm_output_data_uleb128 (0, "Augmentation size");
1965 /* Loop through the Call Frame Instructions associated with
1966 this FDE. */
1967 fde->dw_fde_current_label = fde->dw_fde_begin;
1968 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1969 output_cfi (cfi, fde, for_eh);
1971 /* Pad the FDE out to an address sized boundary. */
1972 ASM_OUTPUT_ALIGN (asm_out_file,
1973 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1974 ASM_OUTPUT_LABEL (asm_out_file, l2);
1977 #ifndef EH_FRAME_SECTION
1978 if (for_eh)
1979 dw2_asm_output_data (4, 0, "End of Table");
1980 #endif
1981 #ifdef MIPS_DEBUGGING_INFO
1982 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1983 get a value of 0. Putting .align 0 after the label fixes it. */
1984 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1985 #endif
1987 /* Turn off app to make assembly quicker. */
1988 if (flag_debug_asm)
1989 app_disable ();
1992 /* Output a marker (i.e. a label) for the beginning of a function, before
1993 the prologue. */
1995 void
1996 dwarf2out_begin_prologue ()
1998 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1999 register dw_fde_ref fde;
2001 current_function_func_begin_label = 0;
2003 #ifdef IA64_UNWIND_INFO
2004 /* ??? current_function_func_begin_label is also used by except.c
2005 for call-site information. We must emit this label if it might
2006 be used. */
2007 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2008 && ! dwarf2out_do_frame ())
2009 return;
2010 #else
2011 if (! dwarf2out_do_frame ())
2012 return;
2013 #endif
2015 ++current_funcdef_number;
2017 function_section (current_function_decl);
2018 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2019 current_funcdef_number);
2020 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2021 current_funcdef_number);
2022 current_function_func_begin_label = get_identifier (label);
2024 #ifdef IA64_UNWIND_INFO
2025 /* We can elide the fde allocation if we're not emitting debug info. */
2026 if (! dwarf2out_do_frame ())
2027 return;
2028 #endif
2030 /* Expand the fde table if necessary. */
2031 if (fde_table_in_use == fde_table_allocated)
2033 fde_table_allocated += FDE_TABLE_INCREMENT;
2034 fde_table
2035 = (dw_fde_ref) xrealloc (fde_table,
2036 fde_table_allocated * sizeof (dw_fde_node));
2039 /* Record the FDE associated with this function. */
2040 current_funcdef_fde = fde_table_in_use;
2042 /* Add the new FDE at the end of the fde_table. */
2043 fde = &fde_table[fde_table_in_use++];
2044 fde->dw_fde_begin = xstrdup (label);
2045 fde->dw_fde_current_label = NULL;
2046 fde->dw_fde_end = NULL;
2047 fde->dw_fde_cfi = NULL;
2048 fde->funcdef_number = current_funcdef_number;
2049 fde->nothrow = current_function_nothrow;
2050 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2052 args_size = old_args_size = 0;
2055 /* Output a marker (i.e. a label) for the absolute end of the generated code
2056 for a function definition. This gets called *after* the epilogue code has
2057 been generated. */
2059 void
2060 dwarf2out_end_epilogue ()
2062 dw_fde_ref fde;
2063 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2065 /* Output a label to mark the endpoint of the code generated for this
2066 function. */
2067 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2068 ASM_OUTPUT_LABEL (asm_out_file, label);
2069 fde = &fde_table[fde_table_in_use - 1];
2070 fde->dw_fde_end = xstrdup (label);
2073 void
2074 dwarf2out_frame_init ()
2076 /* Allocate the initial hunk of the fde_table. */
2077 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2078 fde_table_allocated = FDE_TABLE_INCREMENT;
2079 fde_table_in_use = 0;
2081 /* Generate the CFA instructions common to all FDE's. Do it now for the
2082 sake of lookup_cfa. */
2084 #ifdef DWARF2_UNWIND_INFO
2085 /* On entry, the Canonical Frame Address is at SP. */
2086 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2087 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2088 #endif
2091 void
2092 dwarf2out_frame_finish ()
2094 /* Output call frame information. */
2095 if (write_symbols == DWARF2_DEBUG)
2096 output_call_frame_info (0);
2097 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2098 output_call_frame_info (1);
2101 /* And now, the subset of the debugging information support code necessary
2102 for emitting location expressions. */
2104 typedef struct dw_val_struct *dw_val_ref;
2105 typedef struct die_struct *dw_die_ref;
2106 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2108 /* Each DIE may have a series of attribute/value pairs. Values
2109 can take on several forms. The forms that are used in this
2110 implementation are listed below. */
2112 typedef enum
2114 dw_val_class_addr,
2115 dw_val_class_loc,
2116 dw_val_class_const,
2117 dw_val_class_unsigned_const,
2118 dw_val_class_long_long,
2119 dw_val_class_float,
2120 dw_val_class_flag,
2121 dw_val_class_die_ref,
2122 dw_val_class_fde_ref,
2123 dw_val_class_lbl_id,
2124 dw_val_class_lbl_offset,
2125 dw_val_class_str
2127 dw_val_class;
2129 /* Describe a double word constant value. */
2130 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2132 typedef struct dw_long_long_struct
2134 unsigned long hi;
2135 unsigned long low;
2137 dw_long_long_const;
2139 /* Describe a floating point constant value. */
2141 typedef struct dw_fp_struct
2143 long *array;
2144 unsigned length;
2146 dw_float_const;
2148 /* The dw_val_node describes an attribute's value, as it is
2149 represented internally. */
2151 typedef struct dw_val_struct
2153 dw_val_class val_class;
2154 union
2156 rtx val_addr;
2157 dw_loc_descr_ref val_loc;
2158 long int val_int;
2159 long unsigned val_unsigned;
2160 dw_long_long_const val_long_long;
2161 dw_float_const val_float;
2162 struct {
2163 dw_die_ref die;
2164 int external;
2165 } val_die_ref;
2166 unsigned val_fde_index;
2167 char *val_str;
2168 char *val_lbl_id;
2169 unsigned char val_flag;
2173 dw_val_node;
2175 /* Locations in memory are described using a sequence of stack machine
2176 operations. */
2178 typedef struct dw_loc_descr_struct
2180 dw_loc_descr_ref dw_loc_next;
2181 enum dwarf_location_atom dw_loc_opc;
2182 dw_val_node dw_loc_oprnd1;
2183 dw_val_node dw_loc_oprnd2;
2184 int dw_loc_addr;
2186 dw_loc_descr_node;
2188 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2189 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2190 unsigned long,
2191 unsigned long));
2192 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2193 dw_loc_descr_ref));
2194 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2195 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2196 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2197 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2199 /* Convert a DWARF stack opcode into its string name. */
2201 static const char *
2202 dwarf_stack_op_name (op)
2203 register unsigned op;
2205 switch (op)
2207 case DW_OP_addr:
2208 return "DW_OP_addr";
2209 case DW_OP_deref:
2210 return "DW_OP_deref";
2211 case DW_OP_const1u:
2212 return "DW_OP_const1u";
2213 case DW_OP_const1s:
2214 return "DW_OP_const1s";
2215 case DW_OP_const2u:
2216 return "DW_OP_const2u";
2217 case DW_OP_const2s:
2218 return "DW_OP_const2s";
2219 case DW_OP_const4u:
2220 return "DW_OP_const4u";
2221 case DW_OP_const4s:
2222 return "DW_OP_const4s";
2223 case DW_OP_const8u:
2224 return "DW_OP_const8u";
2225 case DW_OP_const8s:
2226 return "DW_OP_const8s";
2227 case DW_OP_constu:
2228 return "DW_OP_constu";
2229 case DW_OP_consts:
2230 return "DW_OP_consts";
2231 case DW_OP_dup:
2232 return "DW_OP_dup";
2233 case DW_OP_drop:
2234 return "DW_OP_drop";
2235 case DW_OP_over:
2236 return "DW_OP_over";
2237 case DW_OP_pick:
2238 return "DW_OP_pick";
2239 case DW_OP_swap:
2240 return "DW_OP_swap";
2241 case DW_OP_rot:
2242 return "DW_OP_rot";
2243 case DW_OP_xderef:
2244 return "DW_OP_xderef";
2245 case DW_OP_abs:
2246 return "DW_OP_abs";
2247 case DW_OP_and:
2248 return "DW_OP_and";
2249 case DW_OP_div:
2250 return "DW_OP_div";
2251 case DW_OP_minus:
2252 return "DW_OP_minus";
2253 case DW_OP_mod:
2254 return "DW_OP_mod";
2255 case DW_OP_mul:
2256 return "DW_OP_mul";
2257 case DW_OP_neg:
2258 return "DW_OP_neg";
2259 case DW_OP_not:
2260 return "DW_OP_not";
2261 case DW_OP_or:
2262 return "DW_OP_or";
2263 case DW_OP_plus:
2264 return "DW_OP_plus";
2265 case DW_OP_plus_uconst:
2266 return "DW_OP_plus_uconst";
2267 case DW_OP_shl:
2268 return "DW_OP_shl";
2269 case DW_OP_shr:
2270 return "DW_OP_shr";
2271 case DW_OP_shra:
2272 return "DW_OP_shra";
2273 case DW_OP_xor:
2274 return "DW_OP_xor";
2275 case DW_OP_bra:
2276 return "DW_OP_bra";
2277 case DW_OP_eq:
2278 return "DW_OP_eq";
2279 case DW_OP_ge:
2280 return "DW_OP_ge";
2281 case DW_OP_gt:
2282 return "DW_OP_gt";
2283 case DW_OP_le:
2284 return "DW_OP_le";
2285 case DW_OP_lt:
2286 return "DW_OP_lt";
2287 case DW_OP_ne:
2288 return "DW_OP_ne";
2289 case DW_OP_skip:
2290 return "DW_OP_skip";
2291 case DW_OP_lit0:
2292 return "DW_OP_lit0";
2293 case DW_OP_lit1:
2294 return "DW_OP_lit1";
2295 case DW_OP_lit2:
2296 return "DW_OP_lit2";
2297 case DW_OP_lit3:
2298 return "DW_OP_lit3";
2299 case DW_OP_lit4:
2300 return "DW_OP_lit4";
2301 case DW_OP_lit5:
2302 return "DW_OP_lit5";
2303 case DW_OP_lit6:
2304 return "DW_OP_lit6";
2305 case DW_OP_lit7:
2306 return "DW_OP_lit7";
2307 case DW_OP_lit8:
2308 return "DW_OP_lit8";
2309 case DW_OP_lit9:
2310 return "DW_OP_lit9";
2311 case DW_OP_lit10:
2312 return "DW_OP_lit10";
2313 case DW_OP_lit11:
2314 return "DW_OP_lit11";
2315 case DW_OP_lit12:
2316 return "DW_OP_lit12";
2317 case DW_OP_lit13:
2318 return "DW_OP_lit13";
2319 case DW_OP_lit14:
2320 return "DW_OP_lit14";
2321 case DW_OP_lit15:
2322 return "DW_OP_lit15";
2323 case DW_OP_lit16:
2324 return "DW_OP_lit16";
2325 case DW_OP_lit17:
2326 return "DW_OP_lit17";
2327 case DW_OP_lit18:
2328 return "DW_OP_lit18";
2329 case DW_OP_lit19:
2330 return "DW_OP_lit19";
2331 case DW_OP_lit20:
2332 return "DW_OP_lit20";
2333 case DW_OP_lit21:
2334 return "DW_OP_lit21";
2335 case DW_OP_lit22:
2336 return "DW_OP_lit22";
2337 case DW_OP_lit23:
2338 return "DW_OP_lit23";
2339 case DW_OP_lit24:
2340 return "DW_OP_lit24";
2341 case DW_OP_lit25:
2342 return "DW_OP_lit25";
2343 case DW_OP_lit26:
2344 return "DW_OP_lit26";
2345 case DW_OP_lit27:
2346 return "DW_OP_lit27";
2347 case DW_OP_lit28:
2348 return "DW_OP_lit28";
2349 case DW_OP_lit29:
2350 return "DW_OP_lit29";
2351 case DW_OP_lit30:
2352 return "DW_OP_lit30";
2353 case DW_OP_lit31:
2354 return "DW_OP_lit31";
2355 case DW_OP_reg0:
2356 return "DW_OP_reg0";
2357 case DW_OP_reg1:
2358 return "DW_OP_reg1";
2359 case DW_OP_reg2:
2360 return "DW_OP_reg2";
2361 case DW_OP_reg3:
2362 return "DW_OP_reg3";
2363 case DW_OP_reg4:
2364 return "DW_OP_reg4";
2365 case DW_OP_reg5:
2366 return "DW_OP_reg5";
2367 case DW_OP_reg6:
2368 return "DW_OP_reg6";
2369 case DW_OP_reg7:
2370 return "DW_OP_reg7";
2371 case DW_OP_reg8:
2372 return "DW_OP_reg8";
2373 case DW_OP_reg9:
2374 return "DW_OP_reg9";
2375 case DW_OP_reg10:
2376 return "DW_OP_reg10";
2377 case DW_OP_reg11:
2378 return "DW_OP_reg11";
2379 case DW_OP_reg12:
2380 return "DW_OP_reg12";
2381 case DW_OP_reg13:
2382 return "DW_OP_reg13";
2383 case DW_OP_reg14:
2384 return "DW_OP_reg14";
2385 case DW_OP_reg15:
2386 return "DW_OP_reg15";
2387 case DW_OP_reg16:
2388 return "DW_OP_reg16";
2389 case DW_OP_reg17:
2390 return "DW_OP_reg17";
2391 case DW_OP_reg18:
2392 return "DW_OP_reg18";
2393 case DW_OP_reg19:
2394 return "DW_OP_reg19";
2395 case DW_OP_reg20:
2396 return "DW_OP_reg20";
2397 case DW_OP_reg21:
2398 return "DW_OP_reg21";
2399 case DW_OP_reg22:
2400 return "DW_OP_reg22";
2401 case DW_OP_reg23:
2402 return "DW_OP_reg23";
2403 case DW_OP_reg24:
2404 return "DW_OP_reg24";
2405 case DW_OP_reg25:
2406 return "DW_OP_reg25";
2407 case DW_OP_reg26:
2408 return "DW_OP_reg26";
2409 case DW_OP_reg27:
2410 return "DW_OP_reg27";
2411 case DW_OP_reg28:
2412 return "DW_OP_reg28";
2413 case DW_OP_reg29:
2414 return "DW_OP_reg29";
2415 case DW_OP_reg30:
2416 return "DW_OP_reg30";
2417 case DW_OP_reg31:
2418 return "DW_OP_reg31";
2419 case DW_OP_breg0:
2420 return "DW_OP_breg0";
2421 case DW_OP_breg1:
2422 return "DW_OP_breg1";
2423 case DW_OP_breg2:
2424 return "DW_OP_breg2";
2425 case DW_OP_breg3:
2426 return "DW_OP_breg3";
2427 case DW_OP_breg4:
2428 return "DW_OP_breg4";
2429 case DW_OP_breg5:
2430 return "DW_OP_breg5";
2431 case DW_OP_breg6:
2432 return "DW_OP_breg6";
2433 case DW_OP_breg7:
2434 return "DW_OP_breg7";
2435 case DW_OP_breg8:
2436 return "DW_OP_breg8";
2437 case DW_OP_breg9:
2438 return "DW_OP_breg9";
2439 case DW_OP_breg10:
2440 return "DW_OP_breg10";
2441 case DW_OP_breg11:
2442 return "DW_OP_breg11";
2443 case DW_OP_breg12:
2444 return "DW_OP_breg12";
2445 case DW_OP_breg13:
2446 return "DW_OP_breg13";
2447 case DW_OP_breg14:
2448 return "DW_OP_breg14";
2449 case DW_OP_breg15:
2450 return "DW_OP_breg15";
2451 case DW_OP_breg16:
2452 return "DW_OP_breg16";
2453 case DW_OP_breg17:
2454 return "DW_OP_breg17";
2455 case DW_OP_breg18:
2456 return "DW_OP_breg18";
2457 case DW_OP_breg19:
2458 return "DW_OP_breg19";
2459 case DW_OP_breg20:
2460 return "DW_OP_breg20";
2461 case DW_OP_breg21:
2462 return "DW_OP_breg21";
2463 case DW_OP_breg22:
2464 return "DW_OP_breg22";
2465 case DW_OP_breg23:
2466 return "DW_OP_breg23";
2467 case DW_OP_breg24:
2468 return "DW_OP_breg24";
2469 case DW_OP_breg25:
2470 return "DW_OP_breg25";
2471 case DW_OP_breg26:
2472 return "DW_OP_breg26";
2473 case DW_OP_breg27:
2474 return "DW_OP_breg27";
2475 case DW_OP_breg28:
2476 return "DW_OP_breg28";
2477 case DW_OP_breg29:
2478 return "DW_OP_breg29";
2479 case DW_OP_breg30:
2480 return "DW_OP_breg30";
2481 case DW_OP_breg31:
2482 return "DW_OP_breg31";
2483 case DW_OP_regx:
2484 return "DW_OP_regx";
2485 case DW_OP_fbreg:
2486 return "DW_OP_fbreg";
2487 case DW_OP_bregx:
2488 return "DW_OP_bregx";
2489 case DW_OP_piece:
2490 return "DW_OP_piece";
2491 case DW_OP_deref_size:
2492 return "DW_OP_deref_size";
2493 case DW_OP_xderef_size:
2494 return "DW_OP_xderef_size";
2495 case DW_OP_nop:
2496 return "DW_OP_nop";
2497 default:
2498 return "OP_<unknown>";
2502 /* Return a pointer to a newly allocated location description. Location
2503 descriptions are simple expression terms that can be strung
2504 together to form more complicated location (address) descriptions. */
2506 static inline dw_loc_descr_ref
2507 new_loc_descr (op, oprnd1, oprnd2)
2508 register enum dwarf_location_atom op;
2509 register unsigned long oprnd1;
2510 register unsigned long oprnd2;
2512 /* Use xcalloc here so we clear out all of the long_long constant in
2513 the union. */
2514 register dw_loc_descr_ref descr
2515 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2517 descr->dw_loc_opc = op;
2518 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2519 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2520 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2521 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2523 return descr;
2526 /* Add a location description term to a location description expression. */
2528 static inline void
2529 add_loc_descr (list_head, descr)
2530 register dw_loc_descr_ref *list_head;
2531 register dw_loc_descr_ref descr;
2533 register dw_loc_descr_ref *d;
2535 /* Find the end of the chain. */
2536 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2539 *d = descr;
2542 /* Return the size of a location descriptor. */
2544 static unsigned long
2545 size_of_loc_descr (loc)
2546 register dw_loc_descr_ref loc;
2548 register unsigned long size = 1;
2550 switch (loc->dw_loc_opc)
2552 case DW_OP_addr:
2553 size += DWARF2_ADDR_SIZE;
2554 break;
2555 case DW_OP_const1u:
2556 case DW_OP_const1s:
2557 size += 1;
2558 break;
2559 case DW_OP_const2u:
2560 case DW_OP_const2s:
2561 size += 2;
2562 break;
2563 case DW_OP_const4u:
2564 case DW_OP_const4s:
2565 size += 4;
2566 break;
2567 case DW_OP_const8u:
2568 case DW_OP_const8s:
2569 size += 8;
2570 break;
2571 case DW_OP_constu:
2572 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2573 break;
2574 case DW_OP_consts:
2575 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2576 break;
2577 case DW_OP_pick:
2578 size += 1;
2579 break;
2580 case DW_OP_plus_uconst:
2581 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2582 break;
2583 case DW_OP_skip:
2584 case DW_OP_bra:
2585 size += 2;
2586 break;
2587 case DW_OP_breg0:
2588 case DW_OP_breg1:
2589 case DW_OP_breg2:
2590 case DW_OP_breg3:
2591 case DW_OP_breg4:
2592 case DW_OP_breg5:
2593 case DW_OP_breg6:
2594 case DW_OP_breg7:
2595 case DW_OP_breg8:
2596 case DW_OP_breg9:
2597 case DW_OP_breg10:
2598 case DW_OP_breg11:
2599 case DW_OP_breg12:
2600 case DW_OP_breg13:
2601 case DW_OP_breg14:
2602 case DW_OP_breg15:
2603 case DW_OP_breg16:
2604 case DW_OP_breg17:
2605 case DW_OP_breg18:
2606 case DW_OP_breg19:
2607 case DW_OP_breg20:
2608 case DW_OP_breg21:
2609 case DW_OP_breg22:
2610 case DW_OP_breg23:
2611 case DW_OP_breg24:
2612 case DW_OP_breg25:
2613 case DW_OP_breg26:
2614 case DW_OP_breg27:
2615 case DW_OP_breg28:
2616 case DW_OP_breg29:
2617 case DW_OP_breg30:
2618 case DW_OP_breg31:
2619 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2620 break;
2621 case DW_OP_regx:
2622 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2623 break;
2624 case DW_OP_fbreg:
2625 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2626 break;
2627 case DW_OP_bregx:
2628 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2629 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2630 break;
2631 case DW_OP_piece:
2632 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2633 break;
2634 case DW_OP_deref_size:
2635 case DW_OP_xderef_size:
2636 size += 1;
2637 break;
2638 default:
2639 break;
2642 return size;
2645 /* Return the size of a series of location descriptors. */
2647 static unsigned long
2648 size_of_locs (loc)
2649 register dw_loc_descr_ref loc;
2651 register unsigned long size = 0;
2653 for (; loc != NULL; loc = loc->dw_loc_next)
2655 loc->dw_loc_addr = size;
2656 size += size_of_loc_descr (loc);
2659 return size;
2662 /* Output location description stack opcode's operands (if any). */
2664 static void
2665 output_loc_operands (loc)
2666 register dw_loc_descr_ref loc;
2668 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2669 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2671 switch (loc->dw_loc_opc)
2673 #ifdef DWARF2_DEBUGGING_INFO
2674 case DW_OP_addr:
2675 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2676 break;
2677 case DW_OP_const2u:
2678 case DW_OP_const2s:
2679 dw2_asm_output_data (2, val1->v.val_int, NULL);
2680 break;
2681 case DW_OP_const4u:
2682 case DW_OP_const4s:
2683 dw2_asm_output_data (4, val1->v.val_int, NULL);
2684 break;
2685 case DW_OP_const8u:
2686 case DW_OP_const8s:
2687 if (HOST_BITS_PER_LONG < 64)
2688 abort ();
2689 dw2_asm_output_data (8, val1->v.val_int, NULL);
2690 break;
2691 case DW_OP_skip:
2692 case DW_OP_bra:
2694 int offset;
2696 if (val1->val_class == dw_val_class_loc)
2697 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2698 else
2699 abort ();
2701 dw2_asm_output_data (2, offset, NULL);
2703 break;
2704 #else
2705 case DW_OP_addr:
2706 case DW_OP_const2u:
2707 case DW_OP_const2s:
2708 case DW_OP_const4u:
2709 case DW_OP_const4s:
2710 case DW_OP_const8u:
2711 case DW_OP_const8s:
2712 case DW_OP_skip:
2713 case DW_OP_bra:
2714 /* We currently don't make any attempt to make sure these are
2715 aligned properly like we do for the main unwind info, so
2716 don't support emitting things larger than a byte if we're
2717 only doing unwinding. */
2718 abort ();
2719 #endif
2720 case DW_OP_const1u:
2721 case DW_OP_const1s:
2722 dw2_asm_output_data (1, val1->v.val_int, NULL);
2723 break;
2724 case DW_OP_constu:
2725 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2726 break;
2727 case DW_OP_consts:
2728 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2729 break;
2730 case DW_OP_pick:
2731 dw2_asm_output_data (1, val1->v.val_int, NULL);
2732 break;
2733 case DW_OP_plus_uconst:
2734 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2735 break;
2736 case DW_OP_breg0:
2737 case DW_OP_breg1:
2738 case DW_OP_breg2:
2739 case DW_OP_breg3:
2740 case DW_OP_breg4:
2741 case DW_OP_breg5:
2742 case DW_OP_breg6:
2743 case DW_OP_breg7:
2744 case DW_OP_breg8:
2745 case DW_OP_breg9:
2746 case DW_OP_breg10:
2747 case DW_OP_breg11:
2748 case DW_OP_breg12:
2749 case DW_OP_breg13:
2750 case DW_OP_breg14:
2751 case DW_OP_breg15:
2752 case DW_OP_breg16:
2753 case DW_OP_breg17:
2754 case DW_OP_breg18:
2755 case DW_OP_breg19:
2756 case DW_OP_breg20:
2757 case DW_OP_breg21:
2758 case DW_OP_breg22:
2759 case DW_OP_breg23:
2760 case DW_OP_breg24:
2761 case DW_OP_breg25:
2762 case DW_OP_breg26:
2763 case DW_OP_breg27:
2764 case DW_OP_breg28:
2765 case DW_OP_breg29:
2766 case DW_OP_breg30:
2767 case DW_OP_breg31:
2768 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2769 break;
2770 case DW_OP_regx:
2771 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2772 break;
2773 case DW_OP_fbreg:
2774 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2775 break;
2776 case DW_OP_bregx:
2777 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2778 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2779 break;
2780 case DW_OP_piece:
2781 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2782 break;
2783 case DW_OP_deref_size:
2784 case DW_OP_xderef_size:
2785 dw2_asm_output_data (1, val1->v.val_int, NULL);
2786 break;
2787 default:
2788 /* Other codes have no operands. */
2789 break;
2793 /* Output a sequence of location operations. */
2795 static void
2796 output_loc_sequence (loc)
2797 dw_loc_descr_ref loc;
2799 for (; loc != NULL; loc = loc->dw_loc_next)
2801 /* Output the opcode. */
2802 dw2_asm_output_data (1, loc->dw_loc_opc,
2803 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2805 /* Output the operand(s) (if any). */
2806 output_loc_operands (loc);
2810 /* This routine will generate the correct assembly data for a location
2811 description based on a cfi entry with a complex address. */
2813 static void
2814 output_cfa_loc (cfi)
2815 dw_cfi_ref cfi;
2817 dw_loc_descr_ref loc;
2818 unsigned long size;
2820 /* Output the size of the block. */
2821 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2822 size = size_of_locs (loc);
2823 dw2_asm_output_data_uleb128 (size, NULL);
2825 /* Now output the operations themselves. */
2826 output_loc_sequence (loc);
2829 /* This function builds a dwarf location descriptor seqeunce from
2830 a dw_cfa_location. */
2832 static struct dw_loc_descr_struct *
2833 build_cfa_loc (cfa)
2834 dw_cfa_location *cfa;
2836 struct dw_loc_descr_struct *head, *tmp;
2838 if (cfa->indirect == 0)
2839 abort ();
2841 if (cfa->base_offset)
2843 if (cfa->reg <= 31)
2844 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2845 else
2846 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2848 else if (cfa->reg <= 31)
2849 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2850 else
2851 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2852 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2853 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2854 add_loc_descr (&head, tmp);
2855 if (cfa->offset != 0)
2857 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2858 add_loc_descr (&head, tmp);
2860 return head;
2863 /* This function fills in aa dw_cfa_location structure from a
2864 dwarf location descriptor sequence. */
2866 static void
2867 get_cfa_from_loc_descr (cfa, loc)
2868 dw_cfa_location *cfa;
2869 struct dw_loc_descr_struct *loc;
2871 struct dw_loc_descr_struct *ptr;
2872 cfa->offset = 0;
2873 cfa->base_offset = 0;
2874 cfa->indirect = 0;
2875 cfa->reg = -1;
2877 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2879 enum dwarf_location_atom op = ptr->dw_loc_opc;
2880 switch (op)
2882 case DW_OP_reg0:
2883 case DW_OP_reg1:
2884 case DW_OP_reg2:
2885 case DW_OP_reg3:
2886 case DW_OP_reg4:
2887 case DW_OP_reg5:
2888 case DW_OP_reg6:
2889 case DW_OP_reg7:
2890 case DW_OP_reg8:
2891 case DW_OP_reg9:
2892 case DW_OP_reg10:
2893 case DW_OP_reg11:
2894 case DW_OP_reg12:
2895 case DW_OP_reg13:
2896 case DW_OP_reg14:
2897 case DW_OP_reg15:
2898 case DW_OP_reg16:
2899 case DW_OP_reg17:
2900 case DW_OP_reg18:
2901 case DW_OP_reg19:
2902 case DW_OP_reg20:
2903 case DW_OP_reg21:
2904 case DW_OP_reg22:
2905 case DW_OP_reg23:
2906 case DW_OP_reg24:
2907 case DW_OP_reg25:
2908 case DW_OP_reg26:
2909 case DW_OP_reg27:
2910 case DW_OP_reg28:
2911 case DW_OP_reg29:
2912 case DW_OP_reg30:
2913 case DW_OP_reg31:
2914 cfa->reg = op - DW_OP_reg0;
2915 break;
2916 case DW_OP_regx:
2917 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2918 break;
2919 case DW_OP_breg0:
2920 case DW_OP_breg1:
2921 case DW_OP_breg2:
2922 case DW_OP_breg3:
2923 case DW_OP_breg4:
2924 case DW_OP_breg5:
2925 case DW_OP_breg6:
2926 case DW_OP_breg7:
2927 case DW_OP_breg8:
2928 case DW_OP_breg9:
2929 case DW_OP_breg10:
2930 case DW_OP_breg11:
2931 case DW_OP_breg12:
2932 case DW_OP_breg13:
2933 case DW_OP_breg14:
2934 case DW_OP_breg15:
2935 case DW_OP_breg16:
2936 case DW_OP_breg17:
2937 case DW_OP_breg18:
2938 case DW_OP_breg19:
2939 case DW_OP_breg20:
2940 case DW_OP_breg21:
2941 case DW_OP_breg22:
2942 case DW_OP_breg23:
2943 case DW_OP_breg24:
2944 case DW_OP_breg25:
2945 case DW_OP_breg26:
2946 case DW_OP_breg27:
2947 case DW_OP_breg28:
2948 case DW_OP_breg29:
2949 case DW_OP_breg30:
2950 case DW_OP_breg31:
2951 cfa->reg = op - DW_OP_breg0;
2952 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2953 break;
2954 case DW_OP_bregx:
2955 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2956 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2957 break;
2958 case DW_OP_deref:
2959 cfa->indirect = 1;
2960 break;
2961 case DW_OP_plus_uconst:
2962 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2963 break;
2964 default:
2965 internal_error ("DW_LOC_OP %s not implememnted\n",
2966 dwarf_stack_op_name (ptr->dw_loc_opc));
2970 #endif /* .debug_frame support */
2972 /* And now, the support for symbolic debugging information. */
2973 #ifdef DWARF2_DEBUGGING_INFO
2975 /* NOTE: In the comments in this file, many references are made to
2976 "Debugging Information Entries". This term is abbreviated as `DIE'
2977 throughout the remainder of this file. */
2979 /* An internal representation of the DWARF output is built, and then
2980 walked to generate the DWARF debugging info. The walk of the internal
2981 representation is done after the entire program has been compiled.
2982 The types below are used to describe the internal representation. */
2984 /* Various DIE's use offsets relative to the beginning of the
2985 .debug_info section to refer to each other. */
2987 typedef long int dw_offset;
2989 /* Define typedefs here to avoid circular dependencies. */
2991 typedef struct dw_attr_struct *dw_attr_ref;
2992 typedef struct dw_line_info_struct *dw_line_info_ref;
2993 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
2994 typedef struct pubname_struct *pubname_ref;
2995 typedef dw_die_ref *arange_ref;
2997 /* Each entry in the line_info_table maintains the file and
2998 line number associated with the label generated for that
2999 entry. The label gives the PC value associated with
3000 the line number entry. */
3002 typedef struct dw_line_info_struct
3004 unsigned long dw_file_num;
3005 unsigned long dw_line_num;
3007 dw_line_info_entry;
3009 /* Line information for functions in separate sections; each one gets its
3010 own sequence. */
3011 typedef struct dw_separate_line_info_struct
3013 unsigned long dw_file_num;
3014 unsigned long dw_line_num;
3015 unsigned long function;
3017 dw_separate_line_info_entry;
3019 /* Each DIE attribute has a field specifying the attribute kind,
3020 a link to the next attribute in the chain, and an attribute value.
3021 Attributes are typically linked below the DIE they modify. */
3023 typedef struct dw_attr_struct
3025 enum dwarf_attribute dw_attr;
3026 dw_attr_ref dw_attr_next;
3027 dw_val_node dw_attr_val;
3029 dw_attr_node;
3031 /* The Debugging Information Entry (DIE) structure */
3033 typedef struct die_struct
3035 enum dwarf_tag die_tag;
3036 char *die_symbol;
3037 dw_attr_ref die_attr;
3038 dw_die_ref die_parent;
3039 dw_die_ref die_child;
3040 dw_die_ref die_sib;
3041 dw_offset die_offset;
3042 unsigned long die_abbrev;
3043 int die_mark;
3045 die_node;
3047 /* The pubname structure */
3049 typedef struct pubname_struct
3051 dw_die_ref die;
3052 char *name;
3054 pubname_entry;
3056 /* The limbo die list structure. */
3057 typedef struct limbo_die_struct
3059 dw_die_ref die;
3060 struct limbo_die_struct *next;
3062 limbo_die_node;
3064 /* How to start an assembler comment. */
3065 #ifndef ASM_COMMENT_START
3066 #define ASM_COMMENT_START ";#"
3067 #endif
3069 /* Define a macro which returns non-zero for a TYPE_DECL which was
3070 implicitly generated for a tagged type.
3072 Note that unlike the gcc front end (which generates a NULL named
3073 TYPE_DECL node for each complete tagged type, each array type, and
3074 each function type node created) the g++ front end generates a
3075 _named_ TYPE_DECL node for each tagged type node created.
3076 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3077 generate a DW_TAG_typedef DIE for them. */
3079 #define TYPE_DECL_IS_STUB(decl) \
3080 (DECL_NAME (decl) == NULL_TREE \
3081 || (DECL_ARTIFICIAL (decl) \
3082 && is_tagged_type (TREE_TYPE (decl)) \
3083 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3084 /* This is necessary for stub decls that \
3085 appear in nested inline functions. */ \
3086 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3087 && (decl_ultimate_origin (decl) \
3088 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3090 /* Information concerning the compilation unit's programming
3091 language, and compiler version. */
3093 extern int flag_traditional;
3095 /* Fixed size portion of the DWARF compilation unit header. */
3096 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3098 /* Fixed size portion of debugging line information prolog. */
3099 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3101 /* Fixed size portion of public names info. */
3102 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3104 /* Fixed size portion of the address range info. */
3105 #define DWARF_ARANGES_HEADER_SIZE \
3106 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3107 - DWARF_OFFSET_SIZE)
3109 /* Size of padding portion in the address range info. It must be
3110 aligned to twice the pointer size. */
3111 #define DWARF_ARANGES_PAD_SIZE \
3112 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3113 - (2 * DWARF_OFFSET_SIZE + 4))
3115 /* Use assembler line directives if available. */
3116 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3117 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3118 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3119 #else
3120 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3121 #endif
3122 #endif
3124 /* Define the architecture-dependent minimum instruction length (in bytes).
3125 In this implementation of DWARF, this field is used for information
3126 purposes only. Since GCC generates assembly language, we have
3127 no a priori knowledge of how many instruction bytes are generated
3128 for each source line, and therefore can use only the DW_LNE_set_address
3129 and DW_LNS_fixed_advance_pc line information commands. */
3131 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3132 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3133 #endif
3135 /* Minimum line offset in a special line info. opcode.
3136 This value was chosen to give a reasonable range of values. */
3137 #define DWARF_LINE_BASE -10
3139 /* First special line opcde - leave room for the standard opcodes. */
3140 #define DWARF_LINE_OPCODE_BASE 10
3142 /* Range of line offsets in a special line info. opcode. */
3143 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3145 /* Flag that indicates the initial value of the is_stmt_start flag.
3146 In the present implementation, we do not mark any lines as
3147 the beginning of a source statement, because that information
3148 is not made available by the GCC front-end. */
3149 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3151 /* This location is used by calc_die_sizes() to keep track
3152 the offset of each DIE within the .debug_info section. */
3153 static unsigned long next_die_offset;
3155 /* Record the root of the DIE's built for the current compilation unit. */
3156 static dw_die_ref comp_unit_die;
3158 /* A list of DIEs with a NULL parent waiting to be relocated. */
3159 static limbo_die_node *limbo_die_list = 0;
3161 /* Structure used by lookup_filename to manage sets of filenames. */
3162 struct file_table
3164 char **table;
3165 unsigned allocated;
3166 unsigned in_use;
3167 unsigned last_lookup_index;
3170 /* Size (in elements) of increments by which we may expand the filename
3171 table. */
3172 #define FILE_TABLE_INCREMENT 64
3174 /* Filenames referenced by this compilation unit. */
3175 static struct file_table file_table;
3177 /* Local pointer to the name of the main input file. Initialized in
3178 dwarf2out_init. */
3179 static const char *primary_filename;
3181 /* A pointer to the base of a table of references to DIE's that describe
3182 declarations. The table is indexed by DECL_UID() which is a unique
3183 number identifying each decl. */
3184 static dw_die_ref *decl_die_table;
3186 /* Number of elements currently allocated for the decl_die_table. */
3187 static unsigned decl_die_table_allocated;
3189 /* Number of elements in decl_die_table currently in use. */
3190 static unsigned decl_die_table_in_use;
3192 /* Size (in elements) of increments by which we may expand the
3193 decl_die_table. */
3194 #define DECL_DIE_TABLE_INCREMENT 256
3196 /* A pointer to the base of a table of references to declaration
3197 scopes. This table is a display which tracks the nesting
3198 of declaration scopes at the current scope and containing
3199 scopes. This table is used to find the proper place to
3200 define type declaration DIE's. */
3201 varray_type decl_scope_table;
3203 /* A pointer to the base of a list of references to DIE's that
3204 are uniquely identified by their tag, presence/absence of
3205 children DIE's, and list of attribute/value pairs. */
3206 static dw_die_ref *abbrev_die_table;
3208 /* Number of elements currently allocated for abbrev_die_table. */
3209 static unsigned abbrev_die_table_allocated;
3211 /* Number of elements in type_die_table currently in use. */
3212 static unsigned abbrev_die_table_in_use;
3214 /* Size (in elements) of increments by which we may expand the
3215 abbrev_die_table. */
3216 #define ABBREV_DIE_TABLE_INCREMENT 256
3218 /* A pointer to the base of a table that contains line information
3219 for each source code line in .text in the compilation unit. */
3220 static dw_line_info_ref line_info_table;
3222 /* Number of elements currently allocated for line_info_table. */
3223 static unsigned line_info_table_allocated;
3225 /* Number of elements in separate_line_info_table currently in use. */
3226 static unsigned separate_line_info_table_in_use;
3228 /* A pointer to the base of a table that contains line information
3229 for each source code line outside of .text in the compilation unit. */
3230 static dw_separate_line_info_ref separate_line_info_table;
3232 /* Number of elements currently allocated for separate_line_info_table. */
3233 static unsigned separate_line_info_table_allocated;
3235 /* Number of elements in line_info_table currently in use. */
3236 static unsigned line_info_table_in_use;
3238 /* Size (in elements) of increments by which we may expand the
3239 line_info_table. */
3240 #define LINE_INFO_TABLE_INCREMENT 1024
3242 /* A pointer to the base of a table that contains a list of publicly
3243 accessible names. */
3244 static pubname_ref pubname_table;
3246 /* Number of elements currently allocated for pubname_table. */
3247 static unsigned pubname_table_allocated;
3249 /* Number of elements in pubname_table currently in use. */
3250 static unsigned pubname_table_in_use;
3252 /* Size (in elements) of increments by which we may expand the
3253 pubname_table. */
3254 #define PUBNAME_TABLE_INCREMENT 64
3256 /* A pointer to the base of a table that contains a list of publicly
3257 accessible names. */
3258 static arange_ref arange_table;
3260 /* Number of elements currently allocated for arange_table. */
3261 static unsigned arange_table_allocated;
3263 /* Number of elements in arange_table currently in use. */
3264 static unsigned arange_table_in_use;
3266 /* Size (in elements) of increments by which we may expand the
3267 arange_table. */
3268 #define ARANGE_TABLE_INCREMENT 64
3270 /* A pointer to the base of a list of incomplete types which might be
3271 completed at some later time. incomplete_types_list needs to be a VARRAY
3272 because we want to tell the garbage collector about it. If we don't tell
3273 the garbage collector about it, we can garbage collect live data.
3274 Bug 4215.*/
3275 varray_type incomplete_types;
3277 /* Record whether the function being analyzed contains inlined functions. */
3278 static int current_function_has_inlines;
3279 #if 0 && defined (MIPS_DEBUGGING_INFO)
3280 static int comp_unit_has_inlines;
3281 #endif
3283 /* Array of RTXes referenced by the debugging information, which therefore
3284 must be kept around forever. We do this rather than perform GC on
3285 the dwarf info because almost all of the dwarf info lives forever, and
3286 it's easier to support non-GC frontends this way. */
3287 static varray_type used_rtx_varray;
3289 /* Forward declarations for functions defined in this file. */
3291 static int is_pseudo_reg PARAMS ((rtx));
3292 static tree type_main_variant PARAMS ((tree));
3293 static int is_tagged_type PARAMS ((tree));
3294 static const char *dwarf_tag_name PARAMS ((unsigned));
3295 static const char *dwarf_attr_name PARAMS ((unsigned));
3296 static const char *dwarf_form_name PARAMS ((unsigned));
3297 #if 0
3298 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3299 #endif
3300 static tree decl_ultimate_origin PARAMS ((tree));
3301 static tree block_ultimate_origin PARAMS ((tree));
3302 static tree decl_class_context PARAMS ((tree));
3303 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3304 static void add_AT_flag PARAMS ((dw_die_ref,
3305 enum dwarf_attribute,
3306 unsigned));
3307 static void add_AT_int PARAMS ((dw_die_ref,
3308 enum dwarf_attribute, long));
3309 static void add_AT_unsigned PARAMS ((dw_die_ref,
3310 enum dwarf_attribute,
3311 unsigned long));
3312 static void add_AT_long_long PARAMS ((dw_die_ref,
3313 enum dwarf_attribute,
3314 unsigned long,
3315 unsigned long));
3316 static void add_AT_float PARAMS ((dw_die_ref,
3317 enum dwarf_attribute,
3318 unsigned, long *));
3319 static void add_AT_string PARAMS ((dw_die_ref,
3320 enum dwarf_attribute,
3321 const char *));
3322 static void add_AT_die_ref PARAMS ((dw_die_ref,
3323 enum dwarf_attribute,
3324 dw_die_ref));
3325 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3326 enum dwarf_attribute,
3327 unsigned));
3328 static void add_AT_loc PARAMS ((dw_die_ref,
3329 enum dwarf_attribute,
3330 dw_loc_descr_ref));
3331 static void add_AT_addr PARAMS ((dw_die_ref,
3332 enum dwarf_attribute,
3333 rtx));
3334 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3335 enum dwarf_attribute,
3336 const char *));
3337 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3338 enum dwarf_attribute,
3339 const char *));
3340 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3341 enum dwarf_attribute));
3342 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3343 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3344 static const char *get_AT_string PARAMS ((dw_die_ref,
3345 enum dwarf_attribute));
3346 static int get_AT_flag PARAMS ((dw_die_ref,
3347 enum dwarf_attribute));
3348 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3349 enum dwarf_attribute));
3350 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3351 enum dwarf_attribute));
3352 static int is_c_family PARAMS ((void));
3353 static int is_java PARAMS ((void));
3354 static int is_fortran PARAMS ((void));
3355 static void remove_AT PARAMS ((dw_die_ref,
3356 enum dwarf_attribute));
3357 static void remove_children PARAMS ((dw_die_ref));
3358 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3359 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3360 static dw_die_ref lookup_type_die PARAMS ((tree));
3361 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3362 static dw_die_ref lookup_decl_die PARAMS ((tree));
3363 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3364 static void print_spaces PARAMS ((FILE *));
3365 static void print_die PARAMS ((dw_die_ref, FILE *));
3366 static void print_dwarf_line_table PARAMS ((FILE *));
3367 static void reverse_die_lists PARAMS ((dw_die_ref));
3368 static void reverse_all_dies PARAMS ((dw_die_ref));
3369 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3370 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3371 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3372 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3373 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3374 static void compute_section_prefix PARAMS ((dw_die_ref));
3375 static int is_type_die PARAMS ((dw_die_ref));
3376 static int is_comdat_die PARAMS ((dw_die_ref));
3377 static int is_symbol_die PARAMS ((dw_die_ref));
3378 static char *gen_internal_sym PARAMS ((void));
3379 static void assign_symbol_names PARAMS ((dw_die_ref));
3380 static void break_out_includes PARAMS ((dw_die_ref));
3381 static void add_sibling_attributes PARAMS ((dw_die_ref));
3382 static void build_abbrev_table PARAMS ((dw_die_ref));
3383 static unsigned long size_of_string PARAMS ((const char *));
3384 static int constant_size PARAMS ((long unsigned));
3385 static unsigned long size_of_die PARAMS ((dw_die_ref));
3386 static void calc_die_sizes PARAMS ((dw_die_ref));
3387 static void mark_dies PARAMS ((dw_die_ref));
3388 static void unmark_dies PARAMS ((dw_die_ref));
3389 static unsigned long size_of_pubnames PARAMS ((void));
3390 static unsigned long size_of_aranges PARAMS ((void));
3391 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3392 static void output_value_format PARAMS ((dw_attr_ref));
3393 static void output_abbrev_section PARAMS ((void));
3394 static void output_die_symbol PARAMS ((dw_die_ref));
3395 static void output_die PARAMS ((dw_die_ref));
3396 static void output_compilation_unit_header PARAMS ((void));
3397 static void output_comp_unit PARAMS ((dw_die_ref));
3398 static const char *dwarf2_name PARAMS ((tree, int));
3399 static void add_pubname PARAMS ((tree, dw_die_ref));
3400 static void output_pubnames PARAMS ((void));
3401 static void add_arange PARAMS ((tree, dw_die_ref));
3402 static void output_aranges PARAMS ((void));
3403 static void output_line_info PARAMS ((void));
3404 static void output_file_names PARAMS ((void));
3405 static dw_die_ref base_type_die PARAMS ((tree));
3406 static tree root_type PARAMS ((tree));
3407 static int is_base_type PARAMS ((tree));
3408 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3409 static int type_is_enum PARAMS ((tree));
3410 static unsigned int reg_number PARAMS ((rtx));
3411 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3412 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3413 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3414 static int is_based_loc PARAMS ((rtx));
3415 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3416 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3417 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3418 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3419 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3420 static tree field_type PARAMS ((tree));
3421 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3422 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3423 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3424 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3425 static void add_AT_location_description PARAMS ((dw_die_ref,
3426 enum dwarf_attribute, rtx));
3427 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3428 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3429 static rtx rtl_for_decl_location PARAMS ((tree));
3430 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3431 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3432 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3433 static void add_bound_info PARAMS ((dw_die_ref,
3434 enum dwarf_attribute, tree));
3435 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3436 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3437 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3438 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3439 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3440 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3441 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3442 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3443 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3444 static void push_decl_scope PARAMS ((tree));
3445 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3446 static void pop_decl_scope PARAMS ((void));
3447 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3448 dw_die_ref));
3449 static const char *type_tag PARAMS ((tree));
3450 static tree member_declared_type PARAMS ((tree));
3451 #if 0
3452 static const char *decl_start_label PARAMS ((tree));
3453 #endif
3454 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3455 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3456 #if 0
3457 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3458 #endif
3459 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3460 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3461 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3462 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3463 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3464 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3465 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3466 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3467 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3468 static void gen_label_die PARAMS ((tree, dw_die_ref));
3469 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3470 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3471 static void gen_field_die PARAMS ((tree, dw_die_ref));
3472 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3473 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3474 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3475 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3476 static void gen_member_die PARAMS ((tree, dw_die_ref));
3477 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3478 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3479 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3480 static void gen_type_die PARAMS ((tree, dw_die_ref));
3481 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3482 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3483 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3484 static int is_redundant_typedef PARAMS ((tree));
3485 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3486 static unsigned lookup_filename PARAMS ((const char *));
3487 static void init_file_table PARAMS ((void));
3488 static void add_incomplete_type PARAMS ((tree));
3489 static void retry_incomplete_types PARAMS ((void));
3490 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3491 static rtx save_rtx PARAMS ((rtx));
3492 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3493 static int file_info_cmp PARAMS ((const void *, const void *));
3495 /* Section names used to hold DWARF debugging information. */
3496 #ifndef DEBUG_INFO_SECTION
3497 #define DEBUG_INFO_SECTION ".debug_info"
3498 #endif
3499 #ifndef ABBREV_SECTION
3500 #define ABBREV_SECTION ".debug_abbrev"
3501 #endif
3502 #ifndef ARANGES_SECTION
3503 #define ARANGES_SECTION ".debug_aranges"
3504 #endif
3505 #ifndef DW_MACINFO_SECTION
3506 #define DW_MACINFO_SECTION ".debug_macinfo"
3507 #endif
3508 #ifndef DEBUG_LINE_SECTION
3509 #define DEBUG_LINE_SECTION ".debug_line"
3510 #endif
3511 #ifndef LOC_SECTION
3512 #define LOC_SECTION ".debug_loc"
3513 #endif
3514 #ifndef PUBNAMES_SECTION
3515 #define PUBNAMES_SECTION ".debug_pubnames"
3516 #endif
3517 #ifndef STR_SECTION
3518 #define STR_SECTION ".debug_str"
3519 #endif
3521 /* Standard ELF section names for compiled code and data. */
3522 #ifndef TEXT_SECTION
3523 #define TEXT_SECTION ".text"
3524 #endif
3525 #ifndef DATA_SECTION
3526 #define DATA_SECTION ".data"
3527 #endif
3528 #ifndef BSS_SECTION
3529 #define BSS_SECTION ".bss"
3530 #endif
3532 /* Labels we insert at beginning sections we can reference instead of
3533 the section names themselves. */
3535 #ifndef TEXT_SECTION_LABEL
3536 #define TEXT_SECTION_LABEL "Ltext"
3537 #endif
3538 #ifndef DEBUG_LINE_SECTION_LABEL
3539 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3540 #endif
3541 #ifndef DEBUG_INFO_SECTION_LABEL
3542 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3543 #endif
3544 #ifndef ABBREV_SECTION_LABEL
3545 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3546 #endif
3548 /* Definitions of defaults for formats and names of various special
3549 (artificial) labels which may be generated within this file (when the -g
3550 options is used and DWARF_DEBUGGING_INFO is in effect.
3551 If necessary, these may be overridden from within the tm.h file, but
3552 typically, overriding these defaults is unnecessary. */
3554 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3555 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3556 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3557 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3558 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3560 #ifndef TEXT_END_LABEL
3561 #define TEXT_END_LABEL "Letext"
3562 #endif
3563 #ifndef DATA_END_LABEL
3564 #define DATA_END_LABEL "Ledata"
3565 #endif
3566 #ifndef BSS_END_LABEL
3567 #define BSS_END_LABEL "Lebss"
3568 #endif
3569 #ifndef BLOCK_BEGIN_LABEL
3570 #define BLOCK_BEGIN_LABEL "LBB"
3571 #endif
3572 #ifndef BLOCK_END_LABEL
3573 #define BLOCK_END_LABEL "LBE"
3574 #endif
3575 #ifndef BODY_BEGIN_LABEL
3576 #define BODY_BEGIN_LABEL "Lbb"
3577 #endif
3578 #ifndef BODY_END_LABEL
3579 #define BODY_END_LABEL "Lbe"
3580 #endif
3581 #ifndef LINE_CODE_LABEL
3582 #define LINE_CODE_LABEL "LM"
3583 #endif
3584 #ifndef SEPARATE_LINE_CODE_LABEL
3585 #define SEPARATE_LINE_CODE_LABEL "LSM"
3586 #endif
3588 /* We allow a language front-end to designate a function that is to be
3589 called to "demangle" any name before it it put into a DIE. */
3591 static const char *(*demangle_name_func) PARAMS ((const char *));
3593 void
3594 dwarf2out_set_demangle_name_func (func)
3595 const char *(*func) PARAMS ((const char *));
3597 demangle_name_func = func;
3600 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3601 that means adding it to used_rtx_varray. If not, that means making
3602 a copy on the permanent_obstack. */
3604 static rtx
3605 save_rtx (orig)
3606 register rtx orig;
3608 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3610 return orig;
3613 /* Test if rtl node points to a pseudo register. */
3615 static inline int
3616 is_pseudo_reg (rtl)
3617 register rtx rtl;
3619 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3620 || (GET_CODE (rtl) == SUBREG
3621 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3624 /* Return a reference to a type, with its const and volatile qualifiers
3625 removed. */
3627 static inline tree
3628 type_main_variant (type)
3629 register tree type;
3631 type = TYPE_MAIN_VARIANT (type);
3633 /* There really should be only one main variant among any group of variants
3634 of a given type (and all of the MAIN_VARIANT values for all members of
3635 the group should point to that one type) but sometimes the C front-end
3636 messes this up for array types, so we work around that bug here. */
3638 if (TREE_CODE (type) == ARRAY_TYPE)
3639 while (type != TYPE_MAIN_VARIANT (type))
3640 type = TYPE_MAIN_VARIANT (type);
3642 return type;
3645 /* Return non-zero if the given type node represents a tagged type. */
3647 static inline int
3648 is_tagged_type (type)
3649 register tree type;
3651 register enum tree_code code = TREE_CODE (type);
3653 return (code == RECORD_TYPE || code == UNION_TYPE
3654 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3657 /* Convert a DIE tag into its string name. */
3659 static const char *
3660 dwarf_tag_name (tag)
3661 register unsigned tag;
3663 switch (tag)
3665 case DW_TAG_padding:
3666 return "DW_TAG_padding";
3667 case DW_TAG_array_type:
3668 return "DW_TAG_array_type";
3669 case DW_TAG_class_type:
3670 return "DW_TAG_class_type";
3671 case DW_TAG_entry_point:
3672 return "DW_TAG_entry_point";
3673 case DW_TAG_enumeration_type:
3674 return "DW_TAG_enumeration_type";
3675 case DW_TAG_formal_parameter:
3676 return "DW_TAG_formal_parameter";
3677 case DW_TAG_imported_declaration:
3678 return "DW_TAG_imported_declaration";
3679 case DW_TAG_label:
3680 return "DW_TAG_label";
3681 case DW_TAG_lexical_block:
3682 return "DW_TAG_lexical_block";
3683 case DW_TAG_member:
3684 return "DW_TAG_member";
3685 case DW_TAG_pointer_type:
3686 return "DW_TAG_pointer_type";
3687 case DW_TAG_reference_type:
3688 return "DW_TAG_reference_type";
3689 case DW_TAG_compile_unit:
3690 return "DW_TAG_compile_unit";
3691 case DW_TAG_string_type:
3692 return "DW_TAG_string_type";
3693 case DW_TAG_structure_type:
3694 return "DW_TAG_structure_type";
3695 case DW_TAG_subroutine_type:
3696 return "DW_TAG_subroutine_type";
3697 case DW_TAG_typedef:
3698 return "DW_TAG_typedef";
3699 case DW_TAG_union_type:
3700 return "DW_TAG_union_type";
3701 case DW_TAG_unspecified_parameters:
3702 return "DW_TAG_unspecified_parameters";
3703 case DW_TAG_variant:
3704 return "DW_TAG_variant";
3705 case DW_TAG_common_block:
3706 return "DW_TAG_common_block";
3707 case DW_TAG_common_inclusion:
3708 return "DW_TAG_common_inclusion";
3709 case DW_TAG_inheritance:
3710 return "DW_TAG_inheritance";
3711 case DW_TAG_inlined_subroutine:
3712 return "DW_TAG_inlined_subroutine";
3713 case DW_TAG_module:
3714 return "DW_TAG_module";
3715 case DW_TAG_ptr_to_member_type:
3716 return "DW_TAG_ptr_to_member_type";
3717 case DW_TAG_set_type:
3718 return "DW_TAG_set_type";
3719 case DW_TAG_subrange_type:
3720 return "DW_TAG_subrange_type";
3721 case DW_TAG_with_stmt:
3722 return "DW_TAG_with_stmt";
3723 case DW_TAG_access_declaration:
3724 return "DW_TAG_access_declaration";
3725 case DW_TAG_base_type:
3726 return "DW_TAG_base_type";
3727 case DW_TAG_catch_block:
3728 return "DW_TAG_catch_block";
3729 case DW_TAG_const_type:
3730 return "DW_TAG_const_type";
3731 case DW_TAG_constant:
3732 return "DW_TAG_constant";
3733 case DW_TAG_enumerator:
3734 return "DW_TAG_enumerator";
3735 case DW_TAG_file_type:
3736 return "DW_TAG_file_type";
3737 case DW_TAG_friend:
3738 return "DW_TAG_friend";
3739 case DW_TAG_namelist:
3740 return "DW_TAG_namelist";
3741 case DW_TAG_namelist_item:
3742 return "DW_TAG_namelist_item";
3743 case DW_TAG_packed_type:
3744 return "DW_TAG_packed_type";
3745 case DW_TAG_subprogram:
3746 return "DW_TAG_subprogram";
3747 case DW_TAG_template_type_param:
3748 return "DW_TAG_template_type_param";
3749 case DW_TAG_template_value_param:
3750 return "DW_TAG_template_value_param";
3751 case DW_TAG_thrown_type:
3752 return "DW_TAG_thrown_type";
3753 case DW_TAG_try_block:
3754 return "DW_TAG_try_block";
3755 case DW_TAG_variant_part:
3756 return "DW_TAG_variant_part";
3757 case DW_TAG_variable:
3758 return "DW_TAG_variable";
3759 case DW_TAG_volatile_type:
3760 return "DW_TAG_volatile_type";
3761 case DW_TAG_MIPS_loop:
3762 return "DW_TAG_MIPS_loop";
3763 case DW_TAG_format_label:
3764 return "DW_TAG_format_label";
3765 case DW_TAG_function_template:
3766 return "DW_TAG_function_template";
3767 case DW_TAG_class_template:
3768 return "DW_TAG_class_template";
3769 case DW_TAG_GNU_BINCL:
3770 return "DW_TAG_GNU_BINCL";
3771 case DW_TAG_GNU_EINCL:
3772 return "DW_TAG_GNU_EINCL";
3773 default:
3774 return "DW_TAG_<unknown>";
3778 /* Convert a DWARF attribute code into its string name. */
3780 static const char *
3781 dwarf_attr_name (attr)
3782 register unsigned attr;
3784 switch (attr)
3786 case DW_AT_sibling:
3787 return "DW_AT_sibling";
3788 case DW_AT_location:
3789 return "DW_AT_location";
3790 case DW_AT_name:
3791 return "DW_AT_name";
3792 case DW_AT_ordering:
3793 return "DW_AT_ordering";
3794 case DW_AT_subscr_data:
3795 return "DW_AT_subscr_data";
3796 case DW_AT_byte_size:
3797 return "DW_AT_byte_size";
3798 case DW_AT_bit_offset:
3799 return "DW_AT_bit_offset";
3800 case DW_AT_bit_size:
3801 return "DW_AT_bit_size";
3802 case DW_AT_element_list:
3803 return "DW_AT_element_list";
3804 case DW_AT_stmt_list:
3805 return "DW_AT_stmt_list";
3806 case DW_AT_low_pc:
3807 return "DW_AT_low_pc";
3808 case DW_AT_high_pc:
3809 return "DW_AT_high_pc";
3810 case DW_AT_language:
3811 return "DW_AT_language";
3812 case DW_AT_member:
3813 return "DW_AT_member";
3814 case DW_AT_discr:
3815 return "DW_AT_discr";
3816 case DW_AT_discr_value:
3817 return "DW_AT_discr_value";
3818 case DW_AT_visibility:
3819 return "DW_AT_visibility";
3820 case DW_AT_import:
3821 return "DW_AT_import";
3822 case DW_AT_string_length:
3823 return "DW_AT_string_length";
3824 case DW_AT_common_reference:
3825 return "DW_AT_common_reference";
3826 case DW_AT_comp_dir:
3827 return "DW_AT_comp_dir";
3828 case DW_AT_const_value:
3829 return "DW_AT_const_value";
3830 case DW_AT_containing_type:
3831 return "DW_AT_containing_type";
3832 case DW_AT_default_value:
3833 return "DW_AT_default_value";
3834 case DW_AT_inline:
3835 return "DW_AT_inline";
3836 case DW_AT_is_optional:
3837 return "DW_AT_is_optional";
3838 case DW_AT_lower_bound:
3839 return "DW_AT_lower_bound";
3840 case DW_AT_producer:
3841 return "DW_AT_producer";
3842 case DW_AT_prototyped:
3843 return "DW_AT_prototyped";
3844 case DW_AT_return_addr:
3845 return "DW_AT_return_addr";
3846 case DW_AT_start_scope:
3847 return "DW_AT_start_scope";
3848 case DW_AT_stride_size:
3849 return "DW_AT_stride_size";
3850 case DW_AT_upper_bound:
3851 return "DW_AT_upper_bound";
3852 case DW_AT_abstract_origin:
3853 return "DW_AT_abstract_origin";
3854 case DW_AT_accessibility:
3855 return "DW_AT_accessibility";
3856 case DW_AT_address_class:
3857 return "DW_AT_address_class";
3858 case DW_AT_artificial:
3859 return "DW_AT_artificial";
3860 case DW_AT_base_types:
3861 return "DW_AT_base_types";
3862 case DW_AT_calling_convention:
3863 return "DW_AT_calling_convention";
3864 case DW_AT_count:
3865 return "DW_AT_count";
3866 case DW_AT_data_member_location:
3867 return "DW_AT_data_member_location";
3868 case DW_AT_decl_column:
3869 return "DW_AT_decl_column";
3870 case DW_AT_decl_file:
3871 return "DW_AT_decl_file";
3872 case DW_AT_decl_line:
3873 return "DW_AT_decl_line";
3874 case DW_AT_declaration:
3875 return "DW_AT_declaration";
3876 case DW_AT_discr_list:
3877 return "DW_AT_discr_list";
3878 case DW_AT_encoding:
3879 return "DW_AT_encoding";
3880 case DW_AT_external:
3881 return "DW_AT_external";
3882 case DW_AT_frame_base:
3883 return "DW_AT_frame_base";
3884 case DW_AT_friend:
3885 return "DW_AT_friend";
3886 case DW_AT_identifier_case:
3887 return "DW_AT_identifier_case";
3888 case DW_AT_macro_info:
3889 return "DW_AT_macro_info";
3890 case DW_AT_namelist_items:
3891 return "DW_AT_namelist_items";
3892 case DW_AT_priority:
3893 return "DW_AT_priority";
3894 case DW_AT_segment:
3895 return "DW_AT_segment";
3896 case DW_AT_specification:
3897 return "DW_AT_specification";
3898 case DW_AT_static_link:
3899 return "DW_AT_static_link";
3900 case DW_AT_type:
3901 return "DW_AT_type";
3902 case DW_AT_use_location:
3903 return "DW_AT_use_location";
3904 case DW_AT_variable_parameter:
3905 return "DW_AT_variable_parameter";
3906 case DW_AT_virtuality:
3907 return "DW_AT_virtuality";
3908 case DW_AT_vtable_elem_location:
3909 return "DW_AT_vtable_elem_location";
3911 case DW_AT_MIPS_fde:
3912 return "DW_AT_MIPS_fde";
3913 case DW_AT_MIPS_loop_begin:
3914 return "DW_AT_MIPS_loop_begin";
3915 case DW_AT_MIPS_tail_loop_begin:
3916 return "DW_AT_MIPS_tail_loop_begin";
3917 case DW_AT_MIPS_epilog_begin:
3918 return "DW_AT_MIPS_epilog_begin";
3919 case DW_AT_MIPS_loop_unroll_factor:
3920 return "DW_AT_MIPS_loop_unroll_factor";
3921 case DW_AT_MIPS_software_pipeline_depth:
3922 return "DW_AT_MIPS_software_pipeline_depth";
3923 case DW_AT_MIPS_linkage_name:
3924 return "DW_AT_MIPS_linkage_name";
3925 case DW_AT_MIPS_stride:
3926 return "DW_AT_MIPS_stride";
3927 case DW_AT_MIPS_abstract_name:
3928 return "DW_AT_MIPS_abstract_name";
3929 case DW_AT_MIPS_clone_origin:
3930 return "DW_AT_MIPS_clone_origin";
3931 case DW_AT_MIPS_has_inlines:
3932 return "DW_AT_MIPS_has_inlines";
3934 case DW_AT_sf_names:
3935 return "DW_AT_sf_names";
3936 case DW_AT_src_info:
3937 return "DW_AT_src_info";
3938 case DW_AT_mac_info:
3939 return "DW_AT_mac_info";
3940 case DW_AT_src_coords:
3941 return "DW_AT_src_coords";
3942 case DW_AT_body_begin:
3943 return "DW_AT_body_begin";
3944 case DW_AT_body_end:
3945 return "DW_AT_body_end";
3946 default:
3947 return "DW_AT_<unknown>";
3951 /* Convert a DWARF value form code into its string name. */
3953 static const char *
3954 dwarf_form_name (form)
3955 register unsigned form;
3957 switch (form)
3959 case DW_FORM_addr:
3960 return "DW_FORM_addr";
3961 case DW_FORM_block2:
3962 return "DW_FORM_block2";
3963 case DW_FORM_block4:
3964 return "DW_FORM_block4";
3965 case DW_FORM_data2:
3966 return "DW_FORM_data2";
3967 case DW_FORM_data4:
3968 return "DW_FORM_data4";
3969 case DW_FORM_data8:
3970 return "DW_FORM_data8";
3971 case DW_FORM_string:
3972 return "DW_FORM_string";
3973 case DW_FORM_block:
3974 return "DW_FORM_block";
3975 case DW_FORM_block1:
3976 return "DW_FORM_block1";
3977 case DW_FORM_data1:
3978 return "DW_FORM_data1";
3979 case DW_FORM_flag:
3980 return "DW_FORM_flag";
3981 case DW_FORM_sdata:
3982 return "DW_FORM_sdata";
3983 case DW_FORM_strp:
3984 return "DW_FORM_strp";
3985 case DW_FORM_udata:
3986 return "DW_FORM_udata";
3987 case DW_FORM_ref_addr:
3988 return "DW_FORM_ref_addr";
3989 case DW_FORM_ref1:
3990 return "DW_FORM_ref1";
3991 case DW_FORM_ref2:
3992 return "DW_FORM_ref2";
3993 case DW_FORM_ref4:
3994 return "DW_FORM_ref4";
3995 case DW_FORM_ref8:
3996 return "DW_FORM_ref8";
3997 case DW_FORM_ref_udata:
3998 return "DW_FORM_ref_udata";
3999 case DW_FORM_indirect:
4000 return "DW_FORM_indirect";
4001 default:
4002 return "DW_FORM_<unknown>";
4006 /* Convert a DWARF type code into its string name. */
4008 #if 0
4009 static const char *
4010 dwarf_type_encoding_name (enc)
4011 register unsigned enc;
4013 switch (enc)
4015 case DW_ATE_address:
4016 return "DW_ATE_address";
4017 case DW_ATE_boolean:
4018 return "DW_ATE_boolean";
4019 case DW_ATE_complex_float:
4020 return "DW_ATE_complex_float";
4021 case DW_ATE_float:
4022 return "DW_ATE_float";
4023 case DW_ATE_signed:
4024 return "DW_ATE_signed";
4025 case DW_ATE_signed_char:
4026 return "DW_ATE_signed_char";
4027 case DW_ATE_unsigned:
4028 return "DW_ATE_unsigned";
4029 case DW_ATE_unsigned_char:
4030 return "DW_ATE_unsigned_char";
4031 default:
4032 return "DW_ATE_<unknown>";
4035 #endif
4037 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4038 instance of an inlined instance of a decl which is local to an inline
4039 function, so we have to trace all of the way back through the origin chain
4040 to find out what sort of node actually served as the original seed for the
4041 given block. */
4043 static tree
4044 decl_ultimate_origin (decl)
4045 register tree decl;
4047 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4048 nodes in the function to point to themselves; ignore that if
4049 we're trying to output the abstract instance of this function. */
4050 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4051 return NULL_TREE;
4053 #ifdef ENABLE_CHECKING
4054 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4055 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4056 most distant ancestor, this should never happen. */
4057 abort ();
4058 #endif
4060 return DECL_ABSTRACT_ORIGIN (decl);
4063 /* Determine the "ultimate origin" of a block. The block may be an inlined
4064 instance of an inlined instance of a block which is local to an inline
4065 function, so we have to trace all of the way back through the origin chain
4066 to find out what sort of node actually served as the original seed for the
4067 given block. */
4069 static tree
4070 block_ultimate_origin (block)
4071 register tree block;
4073 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4075 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4076 nodes in the function to point to themselves; ignore that if
4077 we're trying to output the abstract instance of this function. */
4078 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4079 return NULL_TREE;
4081 if (immediate_origin == NULL_TREE)
4082 return NULL_TREE;
4083 else
4085 register tree ret_val;
4086 register tree lookahead = immediate_origin;
4090 ret_val = lookahead;
4091 lookahead = (TREE_CODE (ret_val) == BLOCK)
4092 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4093 : NULL;
4095 while (lookahead != NULL && lookahead != ret_val);
4097 return ret_val;
4101 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4102 of a virtual function may refer to a base class, so we check the 'this'
4103 parameter. */
4105 static tree
4106 decl_class_context (decl)
4107 tree decl;
4109 tree context = NULL_TREE;
4111 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4112 context = DECL_CONTEXT (decl);
4113 else
4114 context = TYPE_MAIN_VARIANT
4115 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4117 if (context && !TYPE_P (context))
4118 context = NULL_TREE;
4120 return context;
4123 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4124 addition order, and correct that in reverse_all_dies. */
4126 static inline void
4127 add_dwarf_attr (die, attr)
4128 register dw_die_ref die;
4129 register dw_attr_ref attr;
4131 if (die != NULL && attr != NULL)
4133 attr->dw_attr_next = die->die_attr;
4134 die->die_attr = attr;
4138 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4139 static inline dw_val_class
4140 AT_class (a)
4141 dw_attr_ref a;
4143 return a->dw_attr_val.val_class;
4146 /* Add a flag value attribute to a DIE. */
4148 static inline void
4149 add_AT_flag (die, attr_kind, flag)
4150 register dw_die_ref die;
4151 register enum dwarf_attribute attr_kind;
4152 register unsigned flag;
4154 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4156 attr->dw_attr_next = NULL;
4157 attr->dw_attr = attr_kind;
4158 attr->dw_attr_val.val_class = dw_val_class_flag;
4159 attr->dw_attr_val.v.val_flag = flag;
4160 add_dwarf_attr (die, attr);
4163 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4164 static inline unsigned
4165 AT_flag (a)
4166 register dw_attr_ref a;
4168 if (a && AT_class (a) == dw_val_class_flag)
4169 return a->dw_attr_val.v.val_flag;
4171 abort ();
4174 /* Add a signed integer attribute value to a DIE. */
4176 static inline void
4177 add_AT_int (die, attr_kind, int_val)
4178 register dw_die_ref die;
4179 register enum dwarf_attribute attr_kind;
4180 register long int int_val;
4182 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4184 attr->dw_attr_next = NULL;
4185 attr->dw_attr = attr_kind;
4186 attr->dw_attr_val.val_class = dw_val_class_const;
4187 attr->dw_attr_val.v.val_int = int_val;
4188 add_dwarf_attr (die, attr);
4191 static inline long int AT_int PARAMS ((dw_attr_ref));
4192 static inline long int
4193 AT_int (a)
4194 register dw_attr_ref a;
4196 if (a && AT_class (a) == dw_val_class_const)
4197 return a->dw_attr_val.v.val_int;
4199 abort ();
4202 /* Add an unsigned integer attribute value to a DIE. */
4204 static inline void
4205 add_AT_unsigned (die, attr_kind, unsigned_val)
4206 register dw_die_ref die;
4207 register enum dwarf_attribute attr_kind;
4208 register unsigned long unsigned_val;
4210 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4212 attr->dw_attr_next = NULL;
4213 attr->dw_attr = attr_kind;
4214 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4215 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4216 add_dwarf_attr (die, attr);
4219 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4220 static inline unsigned long
4221 AT_unsigned (a)
4222 register dw_attr_ref a;
4224 if (a && AT_class (a) == dw_val_class_unsigned_const)
4225 return a->dw_attr_val.v.val_unsigned;
4227 abort ();
4230 /* Add an unsigned double integer attribute value to a DIE. */
4232 static inline void
4233 add_AT_long_long (die, attr_kind, val_hi, val_low)
4234 register dw_die_ref die;
4235 register enum dwarf_attribute attr_kind;
4236 register unsigned long val_hi;
4237 register unsigned long val_low;
4239 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4241 attr->dw_attr_next = NULL;
4242 attr->dw_attr = attr_kind;
4243 attr->dw_attr_val.val_class = dw_val_class_long_long;
4244 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4245 attr->dw_attr_val.v.val_long_long.low = val_low;
4246 add_dwarf_attr (die, attr);
4249 /* Add a floating point attribute value to a DIE and return it. */
4251 static inline void
4252 add_AT_float (die, attr_kind, length, array)
4253 register dw_die_ref die;
4254 register enum dwarf_attribute attr_kind;
4255 register unsigned length;
4256 register long *array;
4258 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4260 attr->dw_attr_next = NULL;
4261 attr->dw_attr = attr_kind;
4262 attr->dw_attr_val.val_class = dw_val_class_float;
4263 attr->dw_attr_val.v.val_float.length = length;
4264 attr->dw_attr_val.v.val_float.array = array;
4265 add_dwarf_attr (die, attr);
4268 /* Add a string attribute value to a DIE. */
4270 static inline void
4271 add_AT_string (die, attr_kind, str)
4272 register dw_die_ref die;
4273 register enum dwarf_attribute attr_kind;
4274 register const char *str;
4276 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4278 attr->dw_attr_next = NULL;
4279 attr->dw_attr = attr_kind;
4280 attr->dw_attr_val.val_class = dw_val_class_str;
4281 attr->dw_attr_val.v.val_str = xstrdup (str);
4282 add_dwarf_attr (die, attr);
4285 static inline const char *AT_string PARAMS ((dw_attr_ref));
4286 static inline const char *
4287 AT_string (a)
4288 register dw_attr_ref a;
4290 if (a && AT_class (a) == dw_val_class_str)
4291 return a->dw_attr_val.v.val_str;
4293 abort ();
4296 /* Add a DIE reference attribute value to a DIE. */
4298 static inline void
4299 add_AT_die_ref (die, attr_kind, targ_die)
4300 register dw_die_ref die;
4301 register enum dwarf_attribute attr_kind;
4302 register dw_die_ref targ_die;
4304 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4306 attr->dw_attr_next = NULL;
4307 attr->dw_attr = attr_kind;
4308 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4309 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4310 attr->dw_attr_val.v.val_die_ref.external = 0;
4311 add_dwarf_attr (die, attr);
4314 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4315 static inline dw_die_ref
4316 AT_ref (a)
4317 register dw_attr_ref a;
4319 if (a && AT_class (a) == dw_val_class_die_ref)
4320 return a->dw_attr_val.v.val_die_ref.die;
4322 abort ();
4325 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4326 static inline int
4327 AT_ref_external (a)
4328 register dw_attr_ref a;
4330 if (a && AT_class (a) == dw_val_class_die_ref)
4331 return a->dw_attr_val.v.val_die_ref.external;
4333 return 0;
4336 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4337 static inline void
4338 set_AT_ref_external (a, i)
4339 register dw_attr_ref a;
4340 int i;
4342 if (a && AT_class (a) == dw_val_class_die_ref)
4343 a->dw_attr_val.v.val_die_ref.external = i;
4344 else
4345 abort ();
4348 /* Add an FDE reference attribute value to a DIE. */
4350 static inline void
4351 add_AT_fde_ref (die, attr_kind, targ_fde)
4352 register dw_die_ref die;
4353 register enum dwarf_attribute attr_kind;
4354 register unsigned targ_fde;
4356 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4358 attr->dw_attr_next = NULL;
4359 attr->dw_attr = attr_kind;
4360 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4361 attr->dw_attr_val.v.val_fde_index = targ_fde;
4362 add_dwarf_attr (die, attr);
4365 /* Add a location description attribute value to a DIE. */
4367 static inline void
4368 add_AT_loc (die, attr_kind, loc)
4369 register dw_die_ref die;
4370 register enum dwarf_attribute attr_kind;
4371 register dw_loc_descr_ref loc;
4373 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4375 attr->dw_attr_next = NULL;
4376 attr->dw_attr = attr_kind;
4377 attr->dw_attr_val.val_class = dw_val_class_loc;
4378 attr->dw_attr_val.v.val_loc = loc;
4379 add_dwarf_attr (die, attr);
4382 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4383 static inline dw_loc_descr_ref
4384 AT_loc (a)
4385 register dw_attr_ref a;
4387 if (a && AT_class (a) == dw_val_class_loc)
4388 return a->dw_attr_val.v.val_loc;
4390 abort ();
4393 /* Add an address constant attribute value to a DIE. */
4395 static inline void
4396 add_AT_addr (die, attr_kind, addr)
4397 register dw_die_ref die;
4398 register enum dwarf_attribute attr_kind;
4399 rtx addr;
4401 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4403 attr->dw_attr_next = NULL;
4404 attr->dw_attr = attr_kind;
4405 attr->dw_attr_val.val_class = dw_val_class_addr;
4406 attr->dw_attr_val.v.val_addr = addr;
4407 add_dwarf_attr (die, attr);
4410 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4411 static inline rtx
4412 AT_addr (a)
4413 register dw_attr_ref a;
4415 if (a && AT_class (a) == dw_val_class_addr)
4416 return a->dw_attr_val.v.val_addr;
4418 abort ();
4421 /* Add a label identifier attribute value to a DIE. */
4423 static inline void
4424 add_AT_lbl_id (die, attr_kind, lbl_id)
4425 register dw_die_ref die;
4426 register enum dwarf_attribute attr_kind;
4427 register const char *lbl_id;
4429 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4431 attr->dw_attr_next = NULL;
4432 attr->dw_attr = attr_kind;
4433 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4434 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4435 add_dwarf_attr (die, attr);
4438 /* Add a section offset attribute value to a DIE. */
4440 static inline void
4441 add_AT_lbl_offset (die, attr_kind, label)
4442 register dw_die_ref die;
4443 register enum dwarf_attribute attr_kind;
4444 register const char *label;
4446 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4448 attr->dw_attr_next = NULL;
4449 attr->dw_attr = attr_kind;
4450 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4451 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4452 add_dwarf_attr (die, attr);
4455 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4456 static inline const char *
4457 AT_lbl (a)
4458 register dw_attr_ref a;
4460 if (a && (AT_class (a) == dw_val_class_lbl_id
4461 || AT_class (a) == dw_val_class_lbl_offset))
4462 return a->dw_attr_val.v.val_lbl_id;
4464 abort ();
4467 /* Get the attribute of type attr_kind. */
4469 static inline dw_attr_ref
4470 get_AT (die, attr_kind)
4471 register dw_die_ref die;
4472 register enum dwarf_attribute attr_kind;
4474 register dw_attr_ref a;
4475 register dw_die_ref spec = NULL;
4477 if (die != NULL)
4479 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4481 if (a->dw_attr == attr_kind)
4482 return a;
4484 if (a->dw_attr == DW_AT_specification
4485 || a->dw_attr == DW_AT_abstract_origin)
4486 spec = AT_ref (a);
4489 if (spec)
4490 return get_AT (spec, attr_kind);
4493 return NULL;
4496 /* Return the "low pc" attribute value, typically associated with
4497 a subprogram DIE. Return null if the "low pc" attribute is
4498 either not prsent, or if it cannot be represented as an
4499 assembler label identifier. */
4501 static inline const char *
4502 get_AT_low_pc (die)
4503 register dw_die_ref die;
4505 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4506 return a ? AT_lbl (a) : NULL;
4509 /* Return the "high pc" attribute value, typically associated with
4510 a subprogram DIE. Return null if the "high pc" attribute is
4511 either not prsent, or if it cannot be represented as an
4512 assembler label identifier. */
4514 static inline const char *
4515 get_AT_hi_pc (die)
4516 register dw_die_ref die;
4518 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4519 return a ? AT_lbl (a) : NULL;
4522 /* Return the value of the string attribute designated by ATTR_KIND, or
4523 NULL if it is not present. */
4525 static inline const char *
4526 get_AT_string (die, attr_kind)
4527 register dw_die_ref die;
4528 register enum dwarf_attribute attr_kind;
4530 register dw_attr_ref a = get_AT (die, attr_kind);
4531 return a ? AT_string (a) : NULL;
4534 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4535 if it is not present. */
4537 static inline int
4538 get_AT_flag (die, attr_kind)
4539 register dw_die_ref die;
4540 register enum dwarf_attribute attr_kind;
4542 register dw_attr_ref a = get_AT (die, attr_kind);
4543 return a ? AT_flag (a) : 0;
4546 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4547 if it is not present. */
4549 static inline unsigned
4550 get_AT_unsigned (die, attr_kind)
4551 register dw_die_ref die;
4552 register enum dwarf_attribute attr_kind;
4554 register dw_attr_ref a = get_AT (die, attr_kind);
4555 return a ? AT_unsigned (a) : 0;
4558 static inline dw_die_ref
4559 get_AT_ref (die, attr_kind)
4560 dw_die_ref die;
4561 register enum dwarf_attribute attr_kind;
4563 register dw_attr_ref a = get_AT (die, attr_kind);
4564 return a ? AT_ref (a) : NULL;
4567 static inline int
4568 is_c_family ()
4570 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4572 return (lang == DW_LANG_C || lang == DW_LANG_C89
4573 || lang == DW_LANG_C_plus_plus);
4576 static inline int
4577 is_fortran ()
4579 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4581 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4584 static inline int
4585 is_java ()
4587 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4589 return (lang == DW_LANG_Java);
4592 /* Free up the memory used by A. */
4594 static inline void free_AT PARAMS ((dw_attr_ref));
4595 static inline void
4596 free_AT (a)
4597 dw_attr_ref a;
4599 switch (AT_class (a))
4601 case dw_val_class_str:
4602 case dw_val_class_lbl_id:
4603 case dw_val_class_lbl_offset:
4604 free (a->dw_attr_val.v.val_str);
4605 break;
4607 case dw_val_class_float:
4608 free (a->dw_attr_val.v.val_float.array);
4609 break;
4611 default:
4612 break;
4615 free (a);
4618 /* Remove the specified attribute if present. */
4620 static void
4621 remove_AT (die, attr_kind)
4622 register dw_die_ref die;
4623 register enum dwarf_attribute attr_kind;
4625 register dw_attr_ref *p;
4626 register dw_attr_ref removed = NULL;
4628 if (die != NULL)
4630 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4631 if ((*p)->dw_attr == attr_kind)
4633 removed = *p;
4634 *p = (*p)->dw_attr_next;
4635 break;
4638 if (removed != 0)
4639 free_AT (removed);
4643 /* Free up the memory used by DIE. */
4645 static inline void free_die PARAMS ((dw_die_ref));
4646 static inline void
4647 free_die (die)
4648 dw_die_ref die;
4650 remove_children (die);
4651 free (die);
4654 /* Discard the children of this DIE. */
4656 static void
4657 remove_children (die)
4658 register dw_die_ref die;
4660 register dw_die_ref child_die = die->die_child;
4662 die->die_child = NULL;
4664 while (child_die != NULL)
4666 register dw_die_ref tmp_die = child_die;
4667 register dw_attr_ref a;
4669 child_die = child_die->die_sib;
4671 for (a = tmp_die->die_attr; a != NULL;)
4673 register dw_attr_ref tmp_a = a;
4675 a = a->dw_attr_next;
4676 free_AT (tmp_a);
4679 free_die (tmp_die);
4683 /* Add a child DIE below its parent. We build the lists up in reverse
4684 addition order, and correct that in reverse_all_dies. */
4686 static inline void
4687 add_child_die (die, child_die)
4688 register dw_die_ref die;
4689 register dw_die_ref child_die;
4691 if (die != NULL && child_die != NULL)
4693 if (die == child_die)
4694 abort ();
4695 child_die->die_parent = die;
4696 child_die->die_sib = die->die_child;
4697 die->die_child = child_die;
4701 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4702 is the specification, to the front of PARENT's list of children. */
4704 static void
4705 splice_child_die (parent, child)
4706 dw_die_ref parent, child;
4708 dw_die_ref *p;
4710 /* We want the declaration DIE from inside the class, not the
4711 specification DIE at toplevel. */
4712 if (child->die_parent != parent)
4714 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4715 if (tmp)
4716 child = tmp;
4719 if (child->die_parent != parent
4720 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4721 abort ();
4723 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4724 if (*p == child)
4726 *p = child->die_sib;
4727 break;
4730 child->die_sib = parent->die_child;
4731 parent->die_child = child;
4734 /* Return a pointer to a newly created DIE node. */
4736 static inline dw_die_ref
4737 new_die (tag_value, parent_die)
4738 register enum dwarf_tag tag_value;
4739 register dw_die_ref parent_die;
4741 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4743 die->die_tag = tag_value;
4745 if (parent_die != NULL)
4746 add_child_die (parent_die, die);
4747 else
4749 limbo_die_node *limbo_node;
4751 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4752 limbo_node->die = die;
4753 limbo_node->next = limbo_die_list;
4754 limbo_die_list = limbo_node;
4757 return die;
4760 /* Return the DIE associated with the given type specifier. */
4762 static inline dw_die_ref
4763 lookup_type_die (type)
4764 register tree type;
4766 if (TREE_CODE (type) == VECTOR_TYPE)
4767 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4768 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4771 /* Equate a DIE to a given type specifier. */
4773 static inline void
4774 equate_type_number_to_die (type, type_die)
4775 register tree type;
4776 register dw_die_ref type_die;
4778 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4781 /* Return the DIE associated with a given declaration. */
4783 static inline dw_die_ref
4784 lookup_decl_die (decl)
4785 register tree decl;
4787 register unsigned decl_id = DECL_UID (decl);
4789 return (decl_id < decl_die_table_in_use
4790 ? decl_die_table[decl_id] : NULL);
4793 /* Equate a DIE to a particular declaration. */
4795 static void
4796 equate_decl_number_to_die (decl, decl_die)
4797 register tree decl;
4798 register dw_die_ref decl_die;
4800 register unsigned decl_id = DECL_UID (decl);
4801 register unsigned num_allocated;
4803 if (decl_id >= decl_die_table_allocated)
4805 num_allocated
4806 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4807 / DECL_DIE_TABLE_INCREMENT)
4808 * DECL_DIE_TABLE_INCREMENT;
4810 decl_die_table
4811 = (dw_die_ref *) xrealloc (decl_die_table,
4812 sizeof (dw_die_ref) * num_allocated);
4814 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4815 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4816 decl_die_table_allocated = num_allocated;
4819 if (decl_id >= decl_die_table_in_use)
4820 decl_die_table_in_use = (decl_id + 1);
4822 decl_die_table[decl_id] = decl_die;
4825 /* Keep track of the number of spaces used to indent the
4826 output of the debugging routines that print the structure of
4827 the DIE internal representation. */
4828 static int print_indent;
4830 /* Indent the line the number of spaces given by print_indent. */
4832 static inline void
4833 print_spaces (outfile)
4834 FILE *outfile;
4836 fprintf (outfile, "%*s", print_indent, "");
4839 /* Print the information associated with a given DIE, and its children.
4840 This routine is a debugging aid only. */
4842 static void
4843 print_die (die, outfile)
4844 dw_die_ref die;
4845 FILE *outfile;
4847 register dw_attr_ref a;
4848 register dw_die_ref c;
4850 print_spaces (outfile);
4851 fprintf (outfile, "DIE %4lu: %s\n",
4852 die->die_offset, dwarf_tag_name (die->die_tag));
4853 print_spaces (outfile);
4854 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4855 fprintf (outfile, " offset: %lu\n", die->die_offset);
4857 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4859 print_spaces (outfile);
4860 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4862 switch (AT_class (a))
4864 case dw_val_class_addr:
4865 fprintf (outfile, "address");
4866 break;
4867 case dw_val_class_loc:
4868 fprintf (outfile, "location descriptor");
4869 break;
4870 case dw_val_class_const:
4871 fprintf (outfile, "%ld", AT_int (a));
4872 break;
4873 case dw_val_class_unsigned_const:
4874 fprintf (outfile, "%lu", AT_unsigned (a));
4875 break;
4876 case dw_val_class_long_long:
4877 fprintf (outfile, "constant (%lu,%lu)",
4878 a->dw_attr_val.v.val_long_long.hi,
4879 a->dw_attr_val.v.val_long_long.low);
4880 break;
4881 case dw_val_class_float:
4882 fprintf (outfile, "floating-point constant");
4883 break;
4884 case dw_val_class_flag:
4885 fprintf (outfile, "%u", AT_flag (a));
4886 break;
4887 case dw_val_class_die_ref:
4888 if (AT_ref (a) != NULL)
4890 if (AT_ref (a)->die_symbol)
4891 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
4892 else
4893 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4895 else
4896 fprintf (outfile, "die -> <null>");
4897 break;
4898 case dw_val_class_lbl_id:
4899 case dw_val_class_lbl_offset:
4900 fprintf (outfile, "label: %s", AT_lbl (a));
4901 break;
4902 case dw_val_class_str:
4903 if (AT_string (a) != NULL)
4904 fprintf (outfile, "\"%s\"", AT_string (a));
4905 else
4906 fprintf (outfile, "<null>");
4907 break;
4908 default:
4909 break;
4912 fprintf (outfile, "\n");
4915 if (die->die_child != NULL)
4917 print_indent += 4;
4918 for (c = die->die_child; c != NULL; c = c->die_sib)
4919 print_die (c, outfile);
4921 print_indent -= 4;
4923 if (print_indent == 0)
4924 fprintf (outfile, "\n");
4927 /* Print the contents of the source code line number correspondence table.
4928 This routine is a debugging aid only. */
4930 static void
4931 print_dwarf_line_table (outfile)
4932 FILE *outfile;
4934 register unsigned i;
4935 register dw_line_info_ref line_info;
4937 fprintf (outfile, "\n\nDWARF source line information\n");
4938 for (i = 1; i < line_info_table_in_use; ++i)
4940 line_info = &line_info_table[i];
4941 fprintf (outfile, "%5d: ", i);
4942 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
4943 fprintf (outfile, "%6ld", line_info->dw_line_num);
4944 fprintf (outfile, "\n");
4947 fprintf (outfile, "\n\n");
4950 /* Print the information collected for a given DIE. */
4952 void
4953 debug_dwarf_die (die)
4954 dw_die_ref die;
4956 print_die (die, stderr);
4959 /* Print all DWARF information collected for the compilation unit.
4960 This routine is a debugging aid only. */
4962 void
4963 debug_dwarf ()
4965 print_indent = 0;
4966 print_die (comp_unit_die, stderr);
4967 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4968 print_dwarf_line_table (stderr);
4971 /* We build up the lists of children and attributes by pushing new ones
4972 onto the beginning of the list. Reverse the lists for DIE so that
4973 they are in order of addition. */
4975 static void
4976 reverse_die_lists (die)
4977 register dw_die_ref die;
4979 register dw_die_ref c, cp, cn;
4980 register dw_attr_ref a, ap, an;
4982 for (a = die->die_attr, ap = 0; a; a = an)
4984 an = a->dw_attr_next;
4985 a->dw_attr_next = ap;
4986 ap = a;
4988 die->die_attr = ap;
4990 for (c = die->die_child, cp = 0; c; c = cn)
4992 cn = c->die_sib;
4993 c->die_sib = cp;
4994 cp = c;
4996 die->die_child = cp;
4999 /* reverse_die_lists only reverses the single die you pass it. Since
5000 we used to reverse all dies in add_sibling_attributes, which runs
5001 through all the dies, it would reverse all the dies. Now, however,
5002 since we don't call reverse_die_lists in add_sibling_attributes, we
5003 need a routine to recursively reverse all the dies. This is that
5004 routine. */
5006 static void
5007 reverse_all_dies (die)
5008 register dw_die_ref die;
5010 register dw_die_ref c;
5012 reverse_die_lists (die);
5014 for (c = die->die_child; c; c = c->die_sib)
5015 reverse_all_dies (c);
5018 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5019 the CU for the enclosing include file, if any. BINCL_DIE is the
5020 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5021 include file. */
5023 static dw_die_ref
5024 push_new_compile_unit (old_unit, bincl_die)
5025 dw_die_ref old_unit, bincl_die;
5027 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5028 dw_die_ref new_unit = gen_compile_unit_die (filename);
5029 new_unit->die_sib = old_unit;
5030 return new_unit;
5033 /* Close an include-file CU and reopen the enclosing one. */
5035 static dw_die_ref
5036 pop_compile_unit (old_unit)
5037 dw_die_ref old_unit;
5039 dw_die_ref new_unit = old_unit->die_sib;
5040 old_unit->die_sib = NULL;
5041 return new_unit;
5044 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5045 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5047 /* Calculate the checksum of a location expression. */
5049 static inline void
5050 loc_checksum (loc, ctx)
5051 dw_loc_descr_ref loc;
5052 struct md5_ctx *ctx;
5054 PROCESS (loc->dw_loc_opc);
5055 PROCESS (loc->dw_loc_oprnd1);
5056 PROCESS (loc->dw_loc_oprnd2);
5059 /* Calculate the checksum of an attribute. */
5061 static void
5062 attr_checksum (at, ctx)
5063 dw_attr_ref at;
5064 struct md5_ctx *ctx;
5066 dw_loc_descr_ref loc;
5067 rtx r;
5069 PROCESS (at->dw_attr);
5071 /* We don't care about differences in file numbering. */
5072 if (at->dw_attr == DW_AT_decl_file
5073 /* Or that this was compiled with a different compiler snapshot; if
5074 the output is the same, that's what matters. */
5075 || at->dw_attr == DW_AT_producer)
5076 return;
5078 switch (AT_class (at))
5080 case dw_val_class_const:
5081 PROCESS (at->dw_attr_val.v.val_int);
5082 break;
5083 case dw_val_class_unsigned_const:
5084 PROCESS (at->dw_attr_val.v.val_unsigned);
5085 break;
5086 case dw_val_class_long_long:
5087 PROCESS (at->dw_attr_val.v.val_long_long);
5088 break;
5089 case dw_val_class_float:
5090 PROCESS (at->dw_attr_val.v.val_float);
5091 break;
5092 case dw_val_class_flag:
5093 PROCESS (at->dw_attr_val.v.val_flag);
5094 break;
5096 case dw_val_class_str:
5097 PROCESS_STRING (AT_string (at));
5098 break;
5099 case dw_val_class_addr:
5100 r = AT_addr (at);
5101 switch (GET_CODE (r))
5103 case SYMBOL_REF:
5104 PROCESS_STRING (XSTR (r, 0));
5105 break;
5107 default:
5108 abort ();
5110 break;
5112 case dw_val_class_loc:
5113 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5114 loc_checksum (loc, ctx);
5115 break;
5117 case dw_val_class_die_ref:
5118 if (AT_ref (at)->die_offset)
5119 PROCESS (AT_ref (at)->die_offset);
5120 /* FIXME else use target die name or something. */
5122 case dw_val_class_fde_ref:
5123 case dw_val_class_lbl_id:
5124 case dw_val_class_lbl_offset:
5126 default:
5127 break;
5131 /* Calculate the checksum of a DIE. */
5133 static void
5134 die_checksum (die, ctx)
5135 dw_die_ref die;
5136 struct md5_ctx *ctx;
5138 dw_die_ref c;
5139 dw_attr_ref a;
5141 PROCESS (die->die_tag);
5143 for (a = die->die_attr; a; a = a->dw_attr_next)
5144 attr_checksum (a, ctx);
5146 for (c = die->die_child; c; c = c->die_sib)
5147 die_checksum (c, ctx);
5150 #undef PROCESS
5151 #undef PROCESS_STRING
5153 /* The prefix to attach to symbols on DIEs in the current comdat debug
5154 info section. */
5155 static char *comdat_symbol_id;
5157 /* The index of the current symbol within the current comdat CU. */
5158 static unsigned int comdat_symbol_number;
5160 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5161 children, and set comdat_symbol_id accordingly. */
5163 static void
5164 compute_section_prefix (unit_die)
5165 dw_die_ref unit_die;
5167 char *p, *name;
5168 int i;
5169 unsigned char checksum[16];
5170 struct md5_ctx ctx;
5172 md5_init_ctx (&ctx);
5173 die_checksum (unit_die, &ctx);
5174 md5_finish_ctx (&ctx, checksum);
5176 p = lbasename (get_AT_string (unit_die, DW_AT_name));
5177 name = (char *) alloca (strlen (p) + 64);
5178 sprintf (name, "%s.", p);
5180 clean_symbol_name (name);
5182 p = name + strlen (name);
5183 for (i = 0; i < 4; ++i)
5185 sprintf (p, "%.2x", checksum[i]);
5186 p += 2;
5189 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5190 comdat_symbol_number = 0;
5193 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5195 static int
5196 is_type_die (die)
5197 dw_die_ref die;
5199 switch (die->die_tag)
5201 case DW_TAG_array_type:
5202 case DW_TAG_class_type:
5203 case DW_TAG_enumeration_type:
5204 case DW_TAG_pointer_type:
5205 case DW_TAG_reference_type:
5206 case DW_TAG_string_type:
5207 case DW_TAG_structure_type:
5208 case DW_TAG_subroutine_type:
5209 case DW_TAG_union_type:
5210 case DW_TAG_ptr_to_member_type:
5211 case DW_TAG_set_type:
5212 case DW_TAG_subrange_type:
5213 case DW_TAG_base_type:
5214 case DW_TAG_const_type:
5215 case DW_TAG_file_type:
5216 case DW_TAG_packed_type:
5217 case DW_TAG_volatile_type:
5218 return 1;
5219 default:
5220 return 0;
5224 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5225 Basically, we want to choose the bits that are likely to be shared between
5226 compilations (types) and leave out the bits that are specific to individual
5227 compilations (functions). */
5229 static int
5230 is_comdat_die (c)
5231 dw_die_ref c;
5233 #if 1
5234 /* I think we want to leave base types and __vtbl_ptr_type in the
5235 main CU, as we do for stabs. The advantage is a greater
5236 likelihood of sharing between objects that don't include headers
5237 in the same order (and therefore would put the base types in a
5238 different comdat). jason 8/28/00 */
5239 if (c->die_tag == DW_TAG_base_type)
5240 return 0;
5242 if (c->die_tag == DW_TAG_pointer_type
5243 || c->die_tag == DW_TAG_reference_type
5244 || c->die_tag == DW_TAG_const_type
5245 || c->die_tag == DW_TAG_volatile_type)
5247 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5248 return t ? is_comdat_die (t) : 0;
5250 #endif
5252 return is_type_die (c);
5255 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5256 compilation unit. */
5258 static int
5259 is_symbol_die (c)
5260 dw_die_ref c;
5262 if (is_type_die (c))
5263 return 1;
5264 if (get_AT (c, DW_AT_declaration)
5265 && ! get_AT (c, DW_AT_specification))
5266 return 1;
5267 return 0;
5270 static char *
5271 gen_internal_sym ()
5273 char buf[256];
5274 static int label_num;
5275 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5276 return xstrdup (buf);
5279 /* Assign symbols to all worthy DIEs under DIE. */
5281 static void
5282 assign_symbol_names (die)
5283 register dw_die_ref die;
5285 register dw_die_ref c;
5287 if (is_symbol_die (die))
5289 if (comdat_symbol_id)
5291 char *p = alloca (strlen (comdat_symbol_id) + 64);
5292 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5293 comdat_symbol_id, comdat_symbol_number++);
5294 die->die_symbol = xstrdup (p);
5296 else
5297 die->die_symbol = gen_internal_sym ();
5300 for (c = die->die_child; c != NULL; c = c->die_sib)
5301 assign_symbol_names (c);
5304 /* Traverse the DIE (which is always comp_unit_die), and set up
5305 additional compilation units for each of the include files we see
5306 bracketed by BINCL/EINCL. */
5308 static void
5309 break_out_includes (die)
5310 register dw_die_ref die;
5312 dw_die_ref *ptr;
5313 register dw_die_ref unit = NULL;
5314 limbo_die_node *node;
5316 for (ptr = &(die->die_child); *ptr; )
5318 register dw_die_ref c = *ptr;
5320 if (c->die_tag == DW_TAG_GNU_BINCL
5321 || c->die_tag == DW_TAG_GNU_EINCL
5322 || (unit && is_comdat_die (c)))
5324 /* This DIE is for a secondary CU; remove it from the main one. */
5325 *ptr = c->die_sib;
5327 if (c->die_tag == DW_TAG_GNU_BINCL)
5329 unit = push_new_compile_unit (unit, c);
5330 free_die (c);
5332 else if (c->die_tag == DW_TAG_GNU_EINCL)
5334 unit = pop_compile_unit (unit);
5335 free_die (c);
5337 else
5338 add_child_die (unit, c);
5340 else
5342 /* Leave this DIE in the main CU. */
5343 ptr = &(c->die_sib);
5344 continue;
5348 #if 0
5349 /* We can only use this in debugging, since the frontend doesn't check
5350 to make sure that we leave every include file we enter. */
5351 if (unit != NULL)
5352 abort ();
5353 #endif
5355 assign_symbol_names (die);
5356 for (node = limbo_die_list; node; node = node->next)
5358 compute_section_prefix (node->die);
5359 assign_symbol_names (node->die);
5363 /* Traverse the DIE and add a sibling attribute if it may have the
5364 effect of speeding up access to siblings. To save some space,
5365 avoid generating sibling attributes for DIE's without children. */
5367 static void
5368 add_sibling_attributes (die)
5369 register dw_die_ref die;
5371 register dw_die_ref c;
5373 if (die->die_tag != DW_TAG_compile_unit
5374 && die->die_sib && die->die_child != NULL)
5375 /* Add the sibling link to the front of the attribute list. */
5376 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5378 for (c = die->die_child; c != NULL; c = c->die_sib)
5379 add_sibling_attributes (c);
5382 /* The format of each DIE (and its attribute value pairs)
5383 is encoded in an abbreviation table. This routine builds the
5384 abbreviation table and assigns a unique abbreviation id for
5385 each abbreviation entry. The children of each die are visited
5386 recursively. */
5388 static void
5389 build_abbrev_table (die)
5390 register dw_die_ref die;
5392 register unsigned long abbrev_id;
5393 register unsigned long n_alloc;
5394 register dw_die_ref c;
5395 register dw_attr_ref d_attr, a_attr;
5397 /* Scan the DIE references, and mark as external any that refer to
5398 DIEs from other CUs (i.e. those which are not marked). */
5399 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5401 if (AT_class (d_attr) == dw_val_class_die_ref
5402 && AT_ref (d_attr)->die_mark == 0)
5404 if (AT_ref (d_attr)->die_symbol == 0)
5405 abort ();
5406 set_AT_ref_external (d_attr, 1);
5410 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5412 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5414 if (abbrev->die_tag == die->die_tag)
5416 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5418 a_attr = abbrev->die_attr;
5419 d_attr = die->die_attr;
5421 while (a_attr != NULL && d_attr != NULL)
5423 if ((a_attr->dw_attr != d_attr->dw_attr)
5424 || (value_format (a_attr) != value_format (d_attr)))
5425 break;
5427 a_attr = a_attr->dw_attr_next;
5428 d_attr = d_attr->dw_attr_next;
5431 if (a_attr == NULL && d_attr == NULL)
5432 break;
5437 if (abbrev_id >= abbrev_die_table_in_use)
5439 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5441 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5442 abbrev_die_table
5443 = (dw_die_ref *) xrealloc (abbrev_die_table,
5444 sizeof (dw_die_ref) * n_alloc);
5446 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5447 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5448 abbrev_die_table_allocated = n_alloc;
5451 ++abbrev_die_table_in_use;
5452 abbrev_die_table[abbrev_id] = die;
5455 die->die_abbrev = abbrev_id;
5456 for (c = die->die_child; c != NULL; c = c->die_sib)
5457 build_abbrev_table (c);
5460 /* Return the size of a string, including the null byte.
5462 This used to treat backslashes as escapes, and hence they were not included
5463 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5464 which treats a backslash as a backslash, escaping it if necessary, and hence
5465 we must include them in the count. */
5467 static unsigned long
5468 size_of_string (str)
5469 register const char *str;
5471 return strlen (str) + 1;
5474 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5476 static int
5477 constant_size (value)
5478 long unsigned value;
5480 int log;
5482 if (value == 0)
5483 log = 0;
5484 else
5485 log = floor_log2 (value);
5487 log = log / 8;
5488 log = 1 << (floor_log2 (log) + 1);
5490 return log;
5493 /* Return the size of a DIE, as it is represented in the
5494 .debug_info section. */
5496 static unsigned long
5497 size_of_die (die)
5498 register dw_die_ref die;
5500 register unsigned long size = 0;
5501 register dw_attr_ref a;
5503 size += size_of_uleb128 (die->die_abbrev);
5504 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5506 switch (AT_class (a))
5508 case dw_val_class_addr:
5509 size += DWARF2_ADDR_SIZE;
5510 break;
5511 case dw_val_class_loc:
5513 register unsigned long lsize = size_of_locs (AT_loc (a));
5515 /* Block length. */
5516 size += constant_size (lsize);
5517 size += lsize;
5519 break;
5520 case dw_val_class_const:
5521 size += size_of_sleb128 (AT_int (a));
5522 break;
5523 case dw_val_class_unsigned_const:
5524 size += constant_size (AT_unsigned (a));
5525 break;
5526 case dw_val_class_long_long:
5527 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5528 break;
5529 case dw_val_class_float:
5530 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5531 break;
5532 case dw_val_class_flag:
5533 size += 1;
5534 break;
5535 case dw_val_class_die_ref:
5536 size += DWARF_OFFSET_SIZE;
5537 break;
5538 case dw_val_class_fde_ref:
5539 size += DWARF_OFFSET_SIZE;
5540 break;
5541 case dw_val_class_lbl_id:
5542 size += DWARF2_ADDR_SIZE;
5543 break;
5544 case dw_val_class_lbl_offset:
5545 size += DWARF_OFFSET_SIZE;
5546 break;
5547 case dw_val_class_str:
5548 size += size_of_string (AT_string (a));
5549 break;
5550 default:
5551 abort ();
5555 return size;
5558 /* Size the debugging information associated with a given DIE.
5559 Visits the DIE's children recursively. Updates the global
5560 variable next_die_offset, on each time through. Uses the
5561 current value of next_die_offset to update the die_offset
5562 field in each DIE. */
5564 static void
5565 calc_die_sizes (die)
5566 dw_die_ref die;
5568 register dw_die_ref c;
5569 die->die_offset = next_die_offset;
5570 next_die_offset += size_of_die (die);
5572 for (c = die->die_child; c != NULL; c = c->die_sib)
5573 calc_die_sizes (c);
5575 if (die->die_child != NULL)
5576 /* Count the null byte used to terminate sibling lists. */
5577 next_die_offset += 1;
5580 /* Set the marks for a die and its children. We do this so
5581 that we know whether or not a reference needs to use FORM_ref_addr; only
5582 DIEs in the same CU will be marked. We used to clear out the offset
5583 and use that as the flag, but ran into ordering problems. */
5585 static void
5586 mark_dies (die)
5587 dw_die_ref die;
5589 register dw_die_ref c;
5590 die->die_mark = 1;
5591 for (c = die->die_child; c; c = c->die_sib)
5592 mark_dies (c);
5595 /* Clear the marks for a die and its children. */
5597 static void
5598 unmark_dies (die)
5599 dw_die_ref die;
5601 register dw_die_ref c;
5602 die->die_mark = 0;
5603 for (c = die->die_child; c; c = c->die_sib)
5604 unmark_dies (c);
5607 /* Return the size of the .debug_pubnames table generated for the
5608 compilation unit. */
5610 static unsigned long
5611 size_of_pubnames ()
5613 register unsigned long size;
5614 register unsigned i;
5616 size = DWARF_PUBNAMES_HEADER_SIZE;
5617 for (i = 0; i < pubname_table_in_use; ++i)
5619 register pubname_ref p = &pubname_table[i];
5620 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5623 size += DWARF_OFFSET_SIZE;
5624 return size;
5627 /* Return the size of the information in the .debug_aranges section. */
5629 static unsigned long
5630 size_of_aranges ()
5632 register unsigned long size;
5634 size = DWARF_ARANGES_HEADER_SIZE;
5636 /* Count the address/length pair for this compilation unit. */
5637 size += 2 * DWARF2_ADDR_SIZE;
5638 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5640 /* Count the two zero words used to terminated the address range table. */
5641 size += 2 * DWARF2_ADDR_SIZE;
5642 return size;
5645 /* Select the encoding of an attribute value. */
5647 static enum dwarf_form
5648 value_format (a)
5649 dw_attr_ref a;
5651 switch (a->dw_attr_val.val_class)
5653 case dw_val_class_addr:
5654 return DW_FORM_addr;
5655 case dw_val_class_loc:
5656 switch (constant_size (size_of_locs (AT_loc (a))))
5658 case 1:
5659 return DW_FORM_block1;
5660 case 2:
5661 return DW_FORM_block2;
5662 default:
5663 abort ();
5665 case dw_val_class_const:
5666 return DW_FORM_sdata;
5667 case dw_val_class_unsigned_const:
5668 switch (constant_size (AT_unsigned (a)))
5670 case 1:
5671 return DW_FORM_data1;
5672 case 2:
5673 return DW_FORM_data2;
5674 case 4:
5675 return DW_FORM_data4;
5676 case 8:
5677 return DW_FORM_data8;
5678 default:
5679 abort ();
5681 case dw_val_class_long_long:
5682 return DW_FORM_block1;
5683 case dw_val_class_float:
5684 return DW_FORM_block1;
5685 case dw_val_class_flag:
5686 return DW_FORM_flag;
5687 case dw_val_class_die_ref:
5688 if (AT_ref_external (a))
5689 return DW_FORM_ref_addr;
5690 else
5691 return DW_FORM_ref;
5692 case dw_val_class_fde_ref:
5693 return DW_FORM_data;
5694 case dw_val_class_lbl_id:
5695 return DW_FORM_addr;
5696 case dw_val_class_lbl_offset:
5697 return DW_FORM_data;
5698 case dw_val_class_str:
5699 return DW_FORM_string;
5700 default:
5701 abort ();
5705 /* Output the encoding of an attribute value. */
5707 static void
5708 output_value_format (a)
5709 dw_attr_ref a;
5711 enum dwarf_form form = value_format (a);
5712 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
5715 /* Output the .debug_abbrev section which defines the DIE abbreviation
5716 table. */
5718 static void
5719 output_abbrev_section ()
5721 unsigned long abbrev_id;
5723 dw_attr_ref a_attr;
5724 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5726 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5728 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
5730 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
5731 dwarf_tag_name (abbrev->die_tag));
5733 if (abbrev->die_child != NULL)
5734 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
5735 else
5736 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
5738 for (a_attr = abbrev->die_attr; a_attr != NULL;
5739 a_attr = a_attr->dw_attr_next)
5741 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
5742 dwarf_attr_name (a_attr->dw_attr));
5743 output_value_format (a_attr);
5746 dw2_asm_output_data (1, 0, NULL);
5747 dw2_asm_output_data (1, 0, NULL);
5750 /* Terminate the table. */
5751 dw2_asm_output_data (1, 0, NULL);
5754 /* Output a symbol we can use to refer to this DIE from another CU. */
5756 static inline void
5757 output_die_symbol (die)
5758 register dw_die_ref die;
5760 char *sym = die->die_symbol;
5762 if (sym == 0)
5763 return;
5765 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5766 /* We make these global, not weak; if the target doesn't support
5767 .linkonce, it doesn't support combining the sections, so debugging
5768 will break. */
5769 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5770 ASM_OUTPUT_LABEL (asm_out_file, sym);
5773 /* Output the DIE and its attributes. Called recursively to generate
5774 the definitions of each child DIE. */
5776 static void
5777 output_die (die)
5778 register dw_die_ref die;
5780 register dw_attr_ref a;
5781 register dw_die_ref c;
5782 register unsigned long size;
5784 /* If someone in another CU might refer to us, set up a symbol for
5785 them to point to. */
5786 if (die->die_symbol)
5787 output_die_symbol (die);
5789 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
5790 die->die_offset, dwarf_tag_name (die->die_tag));
5792 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5794 const char *name = dwarf_attr_name (a->dw_attr);
5796 switch (AT_class (a))
5798 case dw_val_class_addr:
5799 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
5800 break;
5802 case dw_val_class_loc:
5803 size = size_of_locs (AT_loc (a));
5805 /* Output the block length for this list of location operations. */
5806 dw2_asm_output_data (constant_size (size), size, "%s", name);
5808 output_loc_sequence (AT_loc (a));
5809 break;
5811 case dw_val_class_const:
5812 /* ??? It would be slightly more efficient to use a scheme like is
5813 used for unsigned constants below, but gdb 4.x does not sign
5814 extend. Gdb 5.x does sign extend. */
5815 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
5816 break;
5818 case dw_val_class_unsigned_const:
5819 dw2_asm_output_data (constant_size (AT_unsigned (a)),
5820 AT_unsigned (a), "%s", name);
5821 break;
5823 case dw_val_class_long_long:
5825 unsigned HOST_WIDE_INT first, second;
5827 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5828 "%s", name);
5830 if (WORDS_BIG_ENDIAN)
5832 first = a->dw_attr_val.v.val_long_long.hi;
5833 second = a->dw_attr_val.v.val_long_long.low;
5835 else
5837 first = a->dw_attr_val.v.val_long_long.low;
5838 second = a->dw_attr_val.v.val_long_long.hi;
5840 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5841 first, "long long constant");
5842 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5843 second, NULL);
5845 break;
5847 case dw_val_class_float:
5849 register unsigned int i;
5851 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
5852 "%s", name);
5854 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5855 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
5856 "fp constant word %u", i);
5857 break;
5860 case dw_val_class_flag:
5861 dw2_asm_output_data (1, AT_flag (a), "%s", name);
5862 break;
5864 case dw_val_class_die_ref:
5865 if (AT_ref_external (a))
5867 char *sym = AT_ref (a)->die_symbol;
5868 if (sym == 0)
5869 abort ();
5870 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
5872 else if (AT_ref (a)->die_offset == 0)
5873 abort ();
5874 else
5875 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
5876 "%s", name);
5877 break;
5879 case dw_val_class_fde_ref:
5881 char l1[20];
5882 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
5883 a->dw_attr_val.v.val_fde_index * 2);
5884 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
5886 break;
5888 case dw_val_class_lbl_id:
5889 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
5890 break;
5892 case dw_val_class_lbl_offset:
5893 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
5894 break;
5896 case dw_val_class_str:
5897 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
5898 break;
5900 default:
5901 abort ();
5905 for (c = die->die_child; c != NULL; c = c->die_sib)
5906 output_die (c);
5908 if (die->die_child != NULL)
5910 /* Add null byte to terminate sibling list. */
5911 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
5912 die->die_offset);
5916 /* Output the compilation unit that appears at the beginning of the
5917 .debug_info section, and precedes the DIE descriptions. */
5919 static void
5920 output_compilation_unit_header ()
5922 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
5923 "Length of Compilation Unit Info");
5925 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
5927 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
5928 "Offset Into Abbrev. Section");
5930 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
5933 /* Output the compilation unit DIE and its children. */
5935 static void
5936 output_comp_unit (die)
5937 dw_die_ref die;
5939 const char *secname;
5941 /* Even if there are no children of this DIE, we must output the
5942 information about the compilation unit. Otherwise, on an empty
5943 translation unit, we will generate a present, but empty,
5944 .debug_info section. IRIX 6.5 `nm' will then complain when
5945 examining the file.
5947 Mark all the DIEs in this CU so we know which get local refs. */
5948 mark_dies (die);
5950 build_abbrev_table (die);
5952 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
5953 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
5954 calc_die_sizes (die);
5956 if (die->die_symbol)
5958 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
5959 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
5960 secname = tmp;
5961 die->die_symbol = NULL;
5963 else
5964 secname = (const char *) DEBUG_INFO_SECTION;
5966 /* Output debugging information. */
5967 ASM_OUTPUT_SECTION (asm_out_file, secname);
5968 output_compilation_unit_header ();
5969 output_die (die);
5971 /* Leave the marks on the main CU, so we can check them in
5972 output_pubnames. */
5973 if (die->die_symbol)
5974 unmark_dies (die);
5977 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5978 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5979 argument list, and maybe the scope. */
5981 static const char *
5982 dwarf2_name (decl, scope)
5983 tree decl;
5984 int scope;
5986 return (*decl_printable_name) (decl, scope ? 1 : 0);
5989 /* Add a new entry to .debug_pubnames if appropriate. */
5991 static void
5992 add_pubname (decl, die)
5993 tree decl;
5994 dw_die_ref die;
5996 pubname_ref p;
5998 if (! TREE_PUBLIC (decl))
5999 return;
6001 if (pubname_table_in_use == pubname_table_allocated)
6003 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6004 pubname_table = (pubname_ref) xrealloc
6005 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6008 p = &pubname_table[pubname_table_in_use++];
6009 p->die = die;
6011 p->name = xstrdup (dwarf2_name (decl, 1));
6014 /* Output the public names table used to speed up access to externally
6015 visible names. For now, only generate entries for externally
6016 visible procedures. */
6018 static void
6019 output_pubnames ()
6021 register unsigned i;
6022 register unsigned long pubnames_length = size_of_pubnames ();
6024 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6025 "Length of Public Names Info");
6027 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6029 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6030 "Offset of Compilation Unit Info");
6032 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6033 "Compilation Unit Length");
6035 for (i = 0; i < pubname_table_in_use; ++i)
6037 register pubname_ref pub = &pubname_table[i];
6039 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6040 if (pub->die->die_mark == 0)
6041 abort ();
6043 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6044 "DIE offset");
6046 dw2_asm_output_nstring (pub->name, -1, "external name");
6049 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6052 /* Add a new entry to .debug_aranges if appropriate. */
6054 static void
6055 add_arange (decl, die)
6056 tree decl;
6057 dw_die_ref die;
6059 if (! DECL_SECTION_NAME (decl))
6060 return;
6062 if (arange_table_in_use == arange_table_allocated)
6064 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6065 arange_table
6066 = (arange_ref) xrealloc (arange_table,
6067 arange_table_allocated * sizeof (dw_die_ref));
6070 arange_table[arange_table_in_use++] = die;
6073 /* Output the information that goes into the .debug_aranges table.
6074 Namely, define the beginning and ending address range of the
6075 text section generated for this compilation unit. */
6077 static void
6078 output_aranges ()
6080 register unsigned i;
6081 register unsigned long aranges_length = size_of_aranges ();
6083 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6084 "Length of Address Ranges Info");
6086 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6088 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6089 "Offset of Compilation Unit Info");
6091 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6093 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6095 /* We need to align to twice the pointer size here. */
6096 if (DWARF_ARANGES_PAD_SIZE)
6098 /* Pad using a 2 byte words so that padding is correct for any
6099 pointer size. */
6100 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6101 2 * DWARF2_ADDR_SIZE);
6102 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6103 dw2_asm_output_data (2, 0, NULL);
6106 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6107 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6108 text_section_label, "Length");
6110 for (i = 0; i < arange_table_in_use; ++i)
6112 dw_die_ref die = arange_table[i];
6114 /* We shouldn't see aranges for DIEs outside of the main CU. */
6115 if (die->die_mark == 0)
6116 abort ();
6118 if (die->die_tag == DW_TAG_subprogram)
6120 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6121 "Address");
6122 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6123 get_AT_low_pc (die), "Length");
6125 else
6127 /* A static variable; extract the symbol from DW_AT_location.
6128 Note that this code isn't currently hit, as we only emit
6129 aranges for functions (jason 9/23/99). */
6131 dw_attr_ref a = get_AT (die, DW_AT_location);
6132 dw_loc_descr_ref loc;
6133 if (! a || AT_class (a) != dw_val_class_loc)
6134 abort ();
6136 loc = AT_loc (a);
6137 if (loc->dw_loc_opc != DW_OP_addr)
6138 abort ();
6140 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6141 loc->dw_loc_oprnd1.v.val_addr, "Address");
6142 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6143 get_AT_unsigned (die, DW_AT_byte_size),
6144 "Length");
6148 /* Output the terminator words. */
6149 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6150 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6154 /* Data structure containing information about input files. */
6155 struct file_info
6157 char *path; /* Complete file name. */
6158 char *fname; /* File name part. */
6159 int length; /* Length of entire string. */
6160 int file_idx; /* Index in input file table. */
6161 int dir_idx; /* Index in directory table. */
6164 /* Data structure containing information about directories with source
6165 files. */
6166 struct dir_info
6168 char *path; /* Path including directory name. */
6169 int length; /* Path length. */
6170 int prefix; /* Index of directory entry which is a prefix. */
6171 int count; /* Number of files in this directory. */
6172 int dir_idx; /* Index of directory used as base. */
6173 int used; /* Used in the end? */
6176 /* Callback function for file_info comparison. We sort by looking at
6177 the directories in the path. */
6178 static int
6179 file_info_cmp (p1, p2)
6180 const void *p1;
6181 const void *p2;
6183 const struct file_info *s1 = p1;
6184 const struct file_info *s2 = p2;
6185 unsigned char *cp1;
6186 unsigned char *cp2;
6188 /* Take care of file names without directories. */
6189 if (s1->path == s1->fname)
6190 return -1;
6191 else if (s2->path == s2->fname)
6192 return 1;
6194 cp1 = (unsigned char *) s1->path;
6195 cp2 = (unsigned char *) s2->path;
6197 while (1)
6199 ++cp1;
6200 ++cp2;
6201 /* Reached the end of the first path? */
6202 if (cp1 == (unsigned char *) s1->fname)
6203 /* It doesn't really matter in which order files from the
6204 same directory are sorted in. Therefore don't test for
6205 the second path reaching the end. */
6206 return -1;
6207 else if (cp2 == (unsigned char *) s2->fname)
6208 return 1;
6210 /* Character of current path component the same? */
6211 if (*cp1 != *cp2)
6212 return *cp1 - *cp2;
6216 /* Output the directory table and the file name table. We try to minimize
6217 the total amount of memory needed. A heuristic is used to avoid large
6218 slowdowns with many input files. */
6219 static void
6220 output_file_names ()
6222 struct file_info *files;
6223 struct dir_info *dirs;
6224 int *saved;
6225 int *savehere;
6226 int *backmap;
6227 int ndirs;
6228 int idx_offset;
6229 int i;
6230 int idx;
6232 /* Allocate the various arrays we need. */
6233 files = (struct file_info *) alloca (file_table.in_use
6234 * sizeof (struct file_info));
6235 dirs = (struct dir_info *) alloca (file_table.in_use
6236 * sizeof (struct dir_info));
6238 /* Sort the file names. */
6239 for (i = 1; i < (int) file_table.in_use; ++i)
6241 char *f;
6243 /* Skip all leading "./". */
6244 f = file_table.table[i];
6245 while (f[0] == '.' && f[1] == '/')
6246 f += 2;
6248 /* Create a new array entry. */
6249 files[i].path = f;
6250 files[i].length = strlen (f);
6251 files[i].file_idx = i;
6253 /* Search for the file name part. */
6254 f = strrchr (f, '/');
6255 files[i].fname = f == NULL ? files[i].path : f + 1;
6257 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6259 /* Find all the different directories used. */
6260 dirs[0].path = files[1].path;
6261 dirs[0].length = files[1].fname - files[1].path;
6262 dirs[0].prefix = -1;
6263 dirs[0].count = 1;
6264 dirs[0].dir_idx = 0;
6265 dirs[0].used = 0;
6266 files[1].dir_idx = 0;
6267 ndirs = 1;
6269 for (i = 2; i < (int) file_table.in_use; ++i)
6270 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6271 && memcmp (dirs[ndirs - 1].path, files[i].path,
6272 dirs[ndirs - 1].length) == 0)
6274 /* Same directory as last entry. */
6275 files[i].dir_idx = ndirs - 1;
6276 ++dirs[ndirs - 1].count;
6278 else
6280 int j;
6282 /* This is a new directory. */
6283 dirs[ndirs].path = files[i].path;
6284 dirs[ndirs].length = files[i].fname - files[i].path;
6285 dirs[ndirs].count = 1;
6286 dirs[ndirs].dir_idx = ndirs;
6287 dirs[ndirs].used = 0;
6288 files[i].dir_idx = ndirs;
6290 /* Search for a prefix. */
6291 dirs[ndirs].prefix = -1;
6292 for (j = 0; j < ndirs; ++j)
6293 if (dirs[j].length < dirs[ndirs].length
6294 && dirs[j].length > 1
6295 && (dirs[ndirs].prefix == -1
6296 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6297 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6298 dirs[ndirs].prefix = j;
6300 ++ndirs;
6303 /* Now to the actual work. We have to find a subset of the
6304 directories which allow expressing the file name using references
6305 to the directory table with the least amount of characters. We
6306 do not do an exhaustive search where we would have to check out
6307 every combination of every single possible prefix. Instead we
6308 use a heuristic which provides nearly optimal results in most
6309 cases and never is much off. */
6310 saved = (int *) alloca (ndirs * sizeof (int));
6311 savehere = (int *) alloca (ndirs * sizeof (int));
6313 memset (saved, '\0', ndirs * sizeof (saved[0]));
6314 for (i = 0; i < ndirs; ++i)
6316 int j;
6317 int total;
6319 /* We can always save some space for the current directory. But
6320 this does not mean it will be enough to justify adding the
6321 directory. */
6322 savehere[i] = dirs[i].length;
6323 total = (savehere[i] - saved[i]) * dirs[i].count;
6325 for (j = i + 1; j < ndirs; ++j)
6327 savehere[j] = 0;
6329 if (saved[j] < dirs[i].length)
6331 /* Determine whether the dirs[i] path is a prefix of the
6332 dirs[j] path. */
6333 int k;
6335 k = dirs[j].prefix;
6336 while (k != -1 && k != i)
6337 k = dirs[k].prefix;
6339 if (k == i)
6341 /* Yes it is. We can possibly safe some memory but
6342 writing the filenames in dirs[j] relative to
6343 dirs[i]. */
6344 savehere[j] = dirs[i].length;
6345 total += (savehere[j] - saved[j]) * dirs[j].count;
6350 /* Check whether we can safe enough to justify adding the dirs[i]
6351 directory. */
6352 if (total > dirs[i].length + 1)
6354 /* It's worthwhile adding. */
6355 for (j = i; j < ndirs; ++j)
6356 if (savehere[j] > 0)
6358 /* Remember how much we saved for this directory so far. */
6359 saved[j] = savehere[j];
6361 /* Remember the prefix directory. */
6362 dirs[j].dir_idx = i;
6367 /* We have to emit them in the order they appear in the file_table
6368 array since the index is used in the debug info generation. To
6369 do this efficiently we generate a back-mapping of the indices
6370 first. */
6371 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6372 for (i = 1; i < (int) file_table.in_use; ++i)
6374 backmap[files[i].file_idx] = i;
6375 /* Mark this directory as used. */
6376 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6379 /* That was it. We are ready to emit the information. First the
6380 directory name table. Here we have to make sure that the first
6381 actually emitted directory name has the index one. Zero is
6382 reserved for the current working directory. Make sure we do not
6383 confuse these indices with the one for the constructed table
6384 (even though most of the time they are identical). */
6385 idx = 1;
6386 idx_offset = dirs[0].length > 0 ? 1 : 0;
6387 for (i = 1 - idx_offset; i < ndirs; ++i)
6388 if (dirs[i].used != 0)
6390 dirs[i].used = idx++;
6391 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6392 "Directory Entry: 0x%x", dirs[i].used);
6394 dw2_asm_output_data (1, 0, "End directory table");
6396 /* Correct the index for the current working directory entry if it
6397 exists. */
6398 if (idx_offset == 0)
6399 dirs[0].used = 0;
6401 /* Now write all the file names. */
6402 for (i = 1; i < (int) file_table.in_use; ++i)
6404 int file_idx = backmap[i];
6405 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6407 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6408 "File Entry: 0x%x", i);
6410 /* Include directory index. */
6411 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6413 /* Modification time. */
6414 dw2_asm_output_data_uleb128 (0, NULL);
6416 /* File length in bytes. */
6417 dw2_asm_output_data_uleb128 (0, NULL);
6419 dw2_asm_output_data (1, 0, "End file name table");
6423 /* Output the source line number correspondence information. This
6424 information goes into the .debug_line section. */
6426 static void
6427 output_line_info ()
6429 char l1[20], l2[20], p1[20], p2[20];
6430 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6431 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6432 register unsigned opc;
6433 register unsigned n_op_args;
6434 register unsigned long lt_index;
6435 register unsigned long current_line;
6436 register long line_offset;
6437 register long line_delta;
6438 register unsigned long current_file;
6439 register unsigned long function;
6441 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6442 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6443 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6444 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6446 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6447 "Length of Source Line Info");
6448 ASM_OUTPUT_LABEL (asm_out_file, l1);
6450 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6452 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6453 ASM_OUTPUT_LABEL (asm_out_file, p1);
6455 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6456 "Minimum Instruction Length");
6458 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6459 "Default is_stmt_start flag");
6461 dw2_asm_output_data (1, DWARF_LINE_BASE,
6462 "Line Base Value (Special Opcodes)");
6464 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6465 "Line Range Value (Special Opcodes)");
6467 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6468 "Special Opcode Base");
6470 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6472 switch (opc)
6474 case DW_LNS_advance_pc:
6475 case DW_LNS_advance_line:
6476 case DW_LNS_set_file:
6477 case DW_LNS_set_column:
6478 case DW_LNS_fixed_advance_pc:
6479 n_op_args = 1;
6480 break;
6481 default:
6482 n_op_args = 0;
6483 break;
6486 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6487 opc, n_op_args);
6490 /* Write out the information about the files we use. */
6491 output_file_names ();
6492 ASM_OUTPUT_LABEL (asm_out_file, p2);
6494 /* We used to set the address register to the first location in the text
6495 section here, but that didn't accomplish anything since we already
6496 have a line note for the opening brace of the first function. */
6498 /* Generate the line number to PC correspondence table, encoded as
6499 a series of state machine operations. */
6500 current_file = 1;
6501 current_line = 1;
6502 strcpy (prev_line_label, text_section_label);
6503 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6505 register dw_line_info_ref line_info = &line_info_table[lt_index];
6507 #if 0
6508 /* Disable this optimization for now; GDB wants to see two line notes
6509 at the beginning of a function so it can find the end of the
6510 prologue. */
6512 /* Don't emit anything for redundant notes. Just updating the
6513 address doesn't accomplish anything, because we already assume
6514 that anything after the last address is this line. */
6515 if (line_info->dw_line_num == current_line
6516 && line_info->dw_file_num == current_file)
6517 continue;
6518 #endif
6520 /* Emit debug info for the address of the current line.
6522 Unfortunately, we have little choice here currently, and must always
6523 use the most general form. Gcc does not know the address delta
6524 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
6525 attributes which will give an upper bound on the address range. We
6526 could perhaps use length attributes to determine when it is safe to
6527 use DW_LNS_fixed_advance_pc. */
6529 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6530 if (0)
6532 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6533 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6534 "DW_LNS_fixed_advance_pc");
6535 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6537 else
6539 /* This can handle any delta. This takes
6540 4+DWARF2_ADDR_SIZE bytes. */
6541 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6542 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6543 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6544 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6546 strcpy (prev_line_label, line_label);
6548 /* Emit debug info for the source file of the current line, if
6549 different from the previous line. */
6550 if (line_info->dw_file_num != current_file)
6552 current_file = line_info->dw_file_num;
6553 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6554 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6555 file_table.table[current_file]);
6558 /* Emit debug info for the current line number, choosing the encoding
6559 that uses the least amount of space. */
6560 if (line_info->dw_line_num != current_line)
6562 line_offset = line_info->dw_line_num - current_line;
6563 line_delta = line_offset - DWARF_LINE_BASE;
6564 current_line = line_info->dw_line_num;
6565 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6567 /* This can handle deltas from -10 to 234, using the current
6568 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6569 takes 1 byte. */
6570 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6571 "line %lu", current_line);
6573 else
6575 /* This can handle any delta. This takes at least 4 bytes,
6576 depending on the value being encoded. */
6577 dw2_asm_output_data (1, DW_LNS_advance_line,
6578 "advance to line %lu", current_line);
6579 dw2_asm_output_data_sleb128 (line_offset, NULL);
6580 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6583 else
6585 /* We still need to start a new row, so output a copy insn. */
6586 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6590 /* Emit debug info for the address of the end of the function. */
6591 if (0)
6593 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6594 "DW_LNS_fixed_advance_pc");
6595 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
6597 else
6599 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6600 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6601 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6602 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
6605 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6606 dw2_asm_output_data_uleb128 (1, NULL);
6607 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6609 function = 0;
6610 current_file = 1;
6611 current_line = 1;
6612 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6614 register dw_separate_line_info_ref line_info
6615 = &separate_line_info_table[lt_index];
6617 #if 0
6618 /* Don't emit anything for redundant notes. */
6619 if (line_info->dw_line_num == current_line
6620 && line_info->dw_file_num == current_file
6621 && line_info->function == function)
6622 goto cont;
6623 #endif
6625 /* Emit debug info for the address of the current line. If this is
6626 a new function, or the first line of a function, then we need
6627 to handle it differently. */
6628 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6629 lt_index);
6630 if (function != line_info->function)
6632 function = line_info->function;
6634 /* Set the address register to the first line in the function */
6635 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6636 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6637 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6638 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6640 else
6642 /* ??? See the DW_LNS_advance_pc comment above. */
6643 if (0)
6645 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6646 "DW_LNS_fixed_advance_pc");
6647 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6649 else
6651 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6652 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6653 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6654 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6657 strcpy (prev_line_label, line_label);
6659 /* Emit debug info for the source file of the current line, if
6660 different from the previous line. */
6661 if (line_info->dw_file_num != current_file)
6663 current_file = line_info->dw_file_num;
6664 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6665 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6666 file_table.table[current_file]);
6669 /* Emit debug info for the current line number, choosing the encoding
6670 that uses the least amount of space. */
6671 if (line_info->dw_line_num != current_line)
6673 line_offset = line_info->dw_line_num - current_line;
6674 line_delta = line_offset - DWARF_LINE_BASE;
6675 current_line = line_info->dw_line_num;
6676 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6677 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6678 "line %lu", current_line);
6679 else
6681 dw2_asm_output_data (1, DW_LNS_advance_line,
6682 "advance to line %lu", current_line);
6683 dw2_asm_output_data_sleb128 (line_offset, NULL);
6684 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6687 else
6688 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6690 #if 0
6691 cont:
6692 #endif
6693 ++lt_index;
6695 /* If we're done with a function, end its sequence. */
6696 if (lt_index == separate_line_info_table_in_use
6697 || separate_line_info_table[lt_index].function != function)
6699 current_file = 1;
6700 current_line = 1;
6702 /* Emit debug info for the address of the end of the function. */
6703 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6704 if (0)
6706 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6707 "DW_LNS_fixed_advance_pc");
6708 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6710 else
6712 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6713 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6714 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6715 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6718 /* Output the marker for the end of this sequence. */
6719 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6720 dw2_asm_output_data_uleb128 (1, NULL);
6721 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6725 /* Output the marker for the end of the line number info. */
6726 ASM_OUTPUT_LABEL (asm_out_file, l2);
6729 /* Given a pointer to a tree node for some base type, return a pointer to
6730 a DIE that describes the given type.
6732 This routine must only be called for GCC type nodes that correspond to
6733 Dwarf base (fundamental) types. */
6735 static dw_die_ref
6736 base_type_die (type)
6737 register tree type;
6739 register dw_die_ref base_type_result;
6740 register const char *type_name;
6741 register enum dwarf_type encoding;
6742 register tree name = TYPE_NAME (type);
6744 if (TREE_CODE (type) == ERROR_MARK
6745 || TREE_CODE (type) == VOID_TYPE)
6746 return 0;
6748 if (name)
6750 if (TREE_CODE (name) == TYPE_DECL)
6751 name = DECL_NAME (name);
6753 type_name = IDENTIFIER_POINTER (name);
6755 else
6756 type_name = "__unknown__";
6758 switch (TREE_CODE (type))
6760 case INTEGER_TYPE:
6761 /* Carefully distinguish the C character types, without messing
6762 up if the language is not C. Note that we check only for the names
6763 that contain spaces; other names might occur by coincidence in other
6764 languages. */
6765 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6766 && (type == char_type_node
6767 || ! strcmp (type_name, "signed char")
6768 || ! strcmp (type_name, "unsigned char"))))
6770 if (TREE_UNSIGNED (type))
6771 encoding = DW_ATE_unsigned;
6772 else
6773 encoding = DW_ATE_signed;
6774 break;
6776 /* else fall through. */
6778 case CHAR_TYPE:
6779 /* GNU Pascal/Ada CHAR type. Not used in C. */
6780 if (TREE_UNSIGNED (type))
6781 encoding = DW_ATE_unsigned_char;
6782 else
6783 encoding = DW_ATE_signed_char;
6784 break;
6786 case REAL_TYPE:
6787 encoding = DW_ATE_float;
6788 break;
6790 /* Dwarf2 doesn't know anything about complex ints, so use
6791 a user defined type for it. */
6792 case COMPLEX_TYPE:
6793 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6794 encoding = DW_ATE_complex_float;
6795 else
6796 encoding = DW_ATE_lo_user;
6797 break;
6799 case BOOLEAN_TYPE:
6800 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6801 encoding = DW_ATE_boolean;
6802 break;
6804 default:
6805 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6808 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6809 if (demangle_name_func)
6810 type_name = (*demangle_name_func) (type_name);
6812 add_AT_string (base_type_result, DW_AT_name, type_name);
6813 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6814 int_size_in_bytes (type));
6815 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6817 return base_type_result;
6820 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6821 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6822 a given type is generally the same as the given type, except that if the
6823 given type is a pointer or reference type, then the root type of the given
6824 type is the root type of the "basis" type for the pointer or reference
6825 type. (This definition of the "root" type is recursive.) Also, the root
6826 type of a `const' qualified type or a `volatile' qualified type is the
6827 root type of the given type without the qualifiers. */
6829 static tree
6830 root_type (type)
6831 register tree type;
6833 if (TREE_CODE (type) == ERROR_MARK)
6834 return error_mark_node;
6836 switch (TREE_CODE (type))
6838 case ERROR_MARK:
6839 return error_mark_node;
6841 case POINTER_TYPE:
6842 case REFERENCE_TYPE:
6843 return type_main_variant (root_type (TREE_TYPE (type)));
6845 default:
6846 return type_main_variant (type);
6850 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6851 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6853 static inline int
6854 is_base_type (type)
6855 register tree type;
6857 switch (TREE_CODE (type))
6859 case ERROR_MARK:
6860 case VOID_TYPE:
6861 case INTEGER_TYPE:
6862 case REAL_TYPE:
6863 case COMPLEX_TYPE:
6864 case BOOLEAN_TYPE:
6865 case CHAR_TYPE:
6866 return 1;
6868 case SET_TYPE:
6869 case ARRAY_TYPE:
6870 case RECORD_TYPE:
6871 case UNION_TYPE:
6872 case QUAL_UNION_TYPE:
6873 case ENUMERAL_TYPE:
6874 case FUNCTION_TYPE:
6875 case METHOD_TYPE:
6876 case POINTER_TYPE:
6877 case REFERENCE_TYPE:
6878 case FILE_TYPE:
6879 case OFFSET_TYPE:
6880 case LANG_TYPE:
6881 case VECTOR_TYPE:
6882 return 0;
6884 default:
6885 abort ();
6888 return 0;
6891 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6892 entry that chains various modifiers in front of the given type. */
6894 static dw_die_ref
6895 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6896 register tree type;
6897 register int is_const_type;
6898 register int is_volatile_type;
6899 register dw_die_ref context_die;
6901 register enum tree_code code = TREE_CODE (type);
6902 register dw_die_ref mod_type_die = NULL;
6903 register dw_die_ref sub_die = NULL;
6904 register tree item_type = NULL;
6906 if (code != ERROR_MARK)
6908 tree qualified_type;
6910 /* See if we already have the appropriately qualified variant of
6911 this type. */
6912 qualified_type
6913 = get_qualified_type (type,
6914 ((is_const_type ? TYPE_QUAL_CONST : 0)
6915 | (is_volatile_type
6916 ? TYPE_QUAL_VOLATILE : 0)));
6917 /* If we do, then we can just use its DIE, if it exists. */
6918 if (qualified_type)
6920 mod_type_die = lookup_type_die (qualified_type);
6921 if (mod_type_die)
6922 return mod_type_die;
6925 /* Handle C typedef types. */
6926 if (qualified_type && TYPE_NAME (qualified_type)
6927 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
6928 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
6930 tree type_name = TYPE_NAME (qualified_type);
6931 tree dtype = TREE_TYPE (type_name);
6932 if (qualified_type == dtype)
6934 /* For a named type, use the typedef. */
6935 gen_type_die (qualified_type, context_die);
6936 mod_type_die = lookup_type_die (qualified_type);
6939 else if (is_const_type < TYPE_READONLY (dtype)
6940 || is_volatile_type < TYPE_VOLATILE (dtype))
6941 /* cv-unqualified version of named type. Just use the unnamed
6942 type to which it refers. */
6943 mod_type_die
6944 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
6945 is_const_type, is_volatile_type,
6946 context_die);
6947 /* Else cv-qualified version of named type; fall through. */
6950 if (mod_type_die)
6951 /* OK. */
6953 else if (is_const_type)
6955 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6956 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6958 else if (is_volatile_type)
6960 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6961 sub_die = modified_type_die (type, 0, 0, context_die);
6963 else if (code == POINTER_TYPE)
6965 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6966 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6967 #if 0
6968 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6969 #endif
6970 item_type = TREE_TYPE (type);
6972 else if (code == REFERENCE_TYPE)
6974 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6975 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6976 #if 0
6977 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6978 #endif
6979 item_type = TREE_TYPE (type);
6981 else if (is_base_type (type))
6982 mod_type_die = base_type_die (type);
6983 else
6985 gen_type_die (type, context_die);
6987 /* We have to get the type_main_variant here (and pass that to the
6988 `lookup_type_die' routine) because the ..._TYPE node we have
6989 might simply be a *copy* of some original type node (where the
6990 copy was created to help us keep track of typedef names) and
6991 that copy might have a different TYPE_UID from the original
6992 ..._TYPE node. */
6993 mod_type_die = lookup_type_die (type_main_variant (type));
6994 if (mod_type_die == NULL)
6995 abort ();
6998 /* We want to equate the qualified type to the die below. */
6999 if (qualified_type)
7000 type = qualified_type;
7003 equate_type_number_to_die (type, mod_type_die);
7004 if (item_type)
7005 /* We must do this after the equate_type_number_to_die call, in case
7006 this is a recursive type. This ensures that the modified_type_die
7007 recursion will terminate even if the type is recursive. Recursive
7008 types are possible in Ada. */
7009 sub_die = modified_type_die (item_type,
7010 TYPE_READONLY (item_type),
7011 TYPE_VOLATILE (item_type),
7012 context_die);
7014 if (sub_die != NULL)
7015 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7017 return mod_type_die;
7020 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7021 an enumerated type. */
7023 static inline int
7024 type_is_enum (type)
7025 register tree type;
7027 return TREE_CODE (type) == ENUMERAL_TYPE;
7030 /* Return the register number described by a given RTL node. */
7032 static unsigned int
7033 reg_number (rtl)
7034 register rtx rtl;
7036 register unsigned regno = REGNO (rtl);
7038 if (regno >= FIRST_PSEUDO_REGISTER)
7040 warning ("internal regno botch: regno = %d\n", regno);
7041 regno = 0;
7044 regno = DBX_REGISTER_NUMBER (regno);
7045 return regno;
7048 /* Return a location descriptor that designates a machine register. */
7050 static dw_loc_descr_ref
7051 reg_loc_descriptor (rtl)
7052 register rtx rtl;
7054 register dw_loc_descr_ref loc_result = NULL;
7055 register unsigned reg = reg_number (rtl);
7057 if (reg <= 31)
7058 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7059 else
7060 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7062 return loc_result;
7065 /* Return a location descriptor that designates a constant. */
7067 static dw_loc_descr_ref
7068 int_loc_descriptor (i)
7069 HOST_WIDE_INT i;
7071 enum dwarf_location_atom op;
7073 /* Pick the smallest representation of a constant, rather than just
7074 defaulting to the LEB encoding. */
7075 if (i >= 0)
7077 if (i <= 31)
7078 op = DW_OP_lit0 + i;
7079 else if (i <= 0xff)
7080 op = DW_OP_const1u;
7081 else if (i <= 0xffff)
7082 op = DW_OP_const2u;
7083 else if (HOST_BITS_PER_WIDE_INT == 32
7084 || i <= 0xffffffff)
7085 op = DW_OP_const4u;
7086 else
7087 op = DW_OP_constu;
7089 else
7091 if (i >= -0x80)
7092 op = DW_OP_const1s;
7093 else if (i >= -0x8000)
7094 op = DW_OP_const2s;
7095 else if (HOST_BITS_PER_WIDE_INT == 32
7096 || i >= -0x80000000)
7097 op = DW_OP_const4s;
7098 else
7099 op = DW_OP_consts;
7102 return new_loc_descr (op, i, 0);
7105 /* Return a location descriptor that designates a base+offset location. */
7107 static dw_loc_descr_ref
7108 based_loc_descr (reg, offset)
7109 unsigned reg;
7110 long int offset;
7112 register dw_loc_descr_ref loc_result;
7113 /* For the "frame base", we use the frame pointer or stack pointer
7114 registers, since the RTL for local variables is relative to one of
7115 them. */
7116 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7117 ? HARD_FRAME_POINTER_REGNUM
7118 : STACK_POINTER_REGNUM);
7120 if (reg == fp_reg)
7121 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7122 else if (reg <= 31)
7123 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7124 else
7125 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7127 return loc_result;
7130 /* Return true if this RTL expression describes a base+offset calculation. */
7132 static inline int
7133 is_based_loc (rtl)
7134 register rtx rtl;
7136 return (GET_CODE (rtl) == PLUS
7137 && ((GET_CODE (XEXP (rtl, 0)) == REG
7138 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7141 /* The following routine converts the RTL for a variable or parameter
7142 (resident in memory) into an equivalent Dwarf representation of a
7143 mechanism for getting the address of that same variable onto the top of a
7144 hypothetical "address evaluation" stack.
7146 When creating memory location descriptors, we are effectively transforming
7147 the RTL for a memory-resident object into its Dwarf postfix expression
7148 equivalent. This routine recursively descends an RTL tree, turning
7149 it into Dwarf postfix code as it goes.
7151 MODE is the mode of the memory reference, needed to handle some
7152 autoincrement addressing modes. */
7154 static dw_loc_descr_ref
7155 mem_loc_descriptor (rtl, mode)
7156 register rtx rtl;
7157 enum machine_mode mode;
7159 dw_loc_descr_ref mem_loc_result = NULL;
7160 /* Note that for a dynamically sized array, the location we will generate a
7161 description of here will be the lowest numbered location which is
7162 actually within the array. That's *not* necessarily the same as the
7163 zeroth element of the array. */
7165 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7166 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7167 #endif
7169 switch (GET_CODE (rtl))
7171 case POST_INC:
7172 case POST_DEC:
7173 case POST_MODIFY:
7174 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7175 just fall into the SUBREG code. */
7177 /* Fall through. */
7179 case SUBREG:
7180 /* The case of a subreg may arise when we have a local (register)
7181 variable or a formal (register) parameter which doesn't quite fill
7182 up an entire register. For now, just assume that it is
7183 legitimate to make the Dwarf info refer to the whole register which
7184 contains the given subreg. */
7185 rtl = SUBREG_REG (rtl);
7187 /* Fall through. */
7189 case REG:
7190 /* Whenever a register number forms a part of the description of the
7191 method for calculating the (dynamic) address of a memory resident
7192 object, DWARF rules require the register number be referred to as
7193 a "base register". This distinction is not based in any way upon
7194 what category of register the hardware believes the given register
7195 belongs to. This is strictly DWARF terminology we're dealing with
7196 here. Note that in cases where the location of a memory-resident
7197 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7198 OP_CONST (0)) the actual DWARF location descriptor that we generate
7199 may just be OP_BASEREG (basereg). This may look deceptively like
7200 the object in question was allocated to a register (rather than in
7201 memory) so DWARF consumers need to be aware of the subtle
7202 distinction between OP_REG and OP_BASEREG. */
7203 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7204 break;
7206 case MEM:
7207 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7208 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7209 break;
7211 case LABEL_REF:
7212 /* Some ports can transform a symbol ref into a label ref, because
7213 the symbol ref is too far away and has to be dumped into a constant
7214 pool. */
7215 case CONST:
7216 case SYMBOL_REF:
7217 /* Alternatively, the symbol in the constant pool can be referenced
7218 by a different symbol. */
7219 if (GET_CODE (rtl) == SYMBOL_REF
7220 && CONSTANT_POOL_ADDRESS_P (rtl))
7222 rtx tmp = get_pool_constant (rtl);
7223 /* Doesn't work for floating point constants. */
7224 if (! (GET_CODE (tmp) == CONST_DOUBLE && GET_MODE (tmp) != VOIDmode))
7225 rtl = tmp;
7229 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7230 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7231 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7232 break;
7234 case PRE_MODIFY:
7235 /* Extract the PLUS expression nested inside and fall into
7236 PLUS code below. */
7237 rtl = XEXP (rtl, 1);
7238 goto plus;
7240 case PRE_INC:
7241 case PRE_DEC:
7242 /* Turn these into a PLUS expression and fall into the PLUS code
7243 below. */
7244 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7245 GEN_INT (GET_CODE (rtl) == PRE_INC
7246 ? GET_MODE_UNIT_SIZE (mode)
7247 : -GET_MODE_UNIT_SIZE (mode)));
7249 /* Fall through. */
7251 case PLUS:
7252 plus:
7253 if (is_based_loc (rtl))
7254 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7255 INTVAL (XEXP (rtl, 1)));
7256 else
7258 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7260 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7261 && INTVAL (XEXP (rtl, 1)) >= 0)
7263 add_loc_descr (&mem_loc_result,
7264 new_loc_descr (DW_OP_plus_uconst,
7265 INTVAL (XEXP (rtl, 1)), 0));
7267 else
7269 add_loc_descr (&mem_loc_result,
7270 mem_loc_descriptor (XEXP (rtl, 1), mode));
7271 add_loc_descr (&mem_loc_result,
7272 new_loc_descr (DW_OP_plus, 0, 0));
7275 break;
7277 case MULT:
7278 /* If a pseudo-reg is optimized away, it is possible for it to
7279 be replaced with a MEM containing a multiply. */
7280 add_loc_descr (&mem_loc_result,
7281 mem_loc_descriptor (XEXP (rtl, 0), mode));
7282 add_loc_descr (&mem_loc_result,
7283 mem_loc_descriptor (XEXP (rtl, 1), mode));
7284 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7285 break;
7287 case CONST_INT:
7288 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7289 break;
7291 default:
7292 abort ();
7295 return mem_loc_result;
7298 /* Return a descriptor that describes the concatenation of two locations.
7299 This is typically a complex variable. */
7301 static dw_loc_descr_ref
7302 concat_loc_descriptor (x0, x1)
7303 register rtx x0, x1;
7305 dw_loc_descr_ref cc_loc_result = NULL;
7307 if (!is_pseudo_reg (x0)
7308 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7309 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7310 add_loc_descr (&cc_loc_result,
7311 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7313 if (!is_pseudo_reg (x1)
7314 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7315 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7316 add_loc_descr (&cc_loc_result,
7317 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7319 return cc_loc_result;
7322 /* Output a proper Dwarf location descriptor for a variable or parameter
7323 which is either allocated in a register or in a memory location. For a
7324 register, we just generate an OP_REG and the register number. For a
7325 memory location we provide a Dwarf postfix expression describing how to
7326 generate the (dynamic) address of the object onto the address stack. */
7328 static dw_loc_descr_ref
7329 loc_descriptor (rtl)
7330 register rtx rtl;
7332 dw_loc_descr_ref loc_result = NULL;
7333 switch (GET_CODE (rtl))
7335 case SUBREG:
7336 /* The case of a subreg may arise when we have a local (register)
7337 variable or a formal (register) parameter which doesn't quite fill
7338 up an entire register. For now, just assume that it is
7339 legitimate to make the Dwarf info refer to the whole register which
7340 contains the given subreg. */
7341 rtl = SUBREG_REG (rtl);
7343 /* Fall through. */
7345 case REG:
7346 loc_result = reg_loc_descriptor (rtl);
7347 break;
7349 case MEM:
7350 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7351 break;
7353 case CONCAT:
7354 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7355 break;
7357 default:
7358 abort ();
7361 return loc_result;
7364 /* Similar, but generate the descriptor from trees instead of rtl.
7365 This comes up particularly with variable length arrays. */
7367 static dw_loc_descr_ref
7368 loc_descriptor_from_tree (loc, addressp)
7369 tree loc;
7370 int addressp;
7372 dw_loc_descr_ref ret = NULL;
7373 int indirect_size = 0;
7374 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7375 enum dwarf_location_atom op;
7377 /* ??? Most of the time we do not take proper care for sign/zero
7378 extending the values properly. Hopefully this won't be a real
7379 problem... */
7381 switch (TREE_CODE (loc))
7383 case ERROR_MARK:
7384 break;
7386 case WITH_RECORD_EXPR:
7387 /* This case involves extracting fields from an object to determine the
7388 position of other fields. We don't try to encode this here. The
7389 only user of this is Ada, which encodes the needed information using
7390 the names of types. */
7391 return ret;
7393 case VAR_DECL:
7394 case PARM_DECL:
7396 rtx rtl = rtl_for_decl_location (loc);
7397 enum machine_mode mode = DECL_MODE (loc);
7399 if (rtl == NULL_RTX)
7400 break;
7401 else if (CONSTANT_P (rtl))
7403 ret = new_loc_descr (DW_OP_addr, 0, 0);
7404 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7405 ret->dw_loc_oprnd1.v.val_addr = rtl;
7406 indirect_size = GET_MODE_SIZE (mode);
7408 else
7410 if (GET_CODE (rtl) == MEM)
7412 indirect_size = GET_MODE_SIZE (mode);
7413 rtl = XEXP (rtl, 0);
7415 ret = mem_loc_descriptor (rtl, mode);
7418 break;
7420 case INDIRECT_REF:
7421 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7422 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7423 break;
7425 case NOP_EXPR:
7426 case CONVERT_EXPR:
7427 case NON_LVALUE_EXPR:
7428 case SAVE_EXPR:
7429 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7431 case COMPONENT_REF:
7432 case BIT_FIELD_REF:
7433 case ARRAY_REF:
7435 tree obj, offset;
7436 HOST_WIDE_INT bitsize, bitpos, bytepos;
7437 enum machine_mode mode;
7438 int volatilep;
7439 unsigned int alignment;
7441 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7442 &unsignedp, &volatilep, &alignment);
7443 ret = loc_descriptor_from_tree (obj, 1);
7445 if (offset != NULL_TREE)
7447 /* Variable offset. */
7448 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7449 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7452 if (addressp)
7454 /* We cannot address anything not on a unit boundary. */
7455 if (bitpos % BITS_PER_UNIT != 0)
7456 abort ();
7458 else
7460 if (bitpos % BITS_PER_UNIT != 0
7461 || bitsize % BITS_PER_UNIT != 0)
7463 /* ??? We could handle this by loading and shifting etc.
7464 Wait until someone needs it before expending the effort. */
7465 abort ();
7468 indirect_size = bitsize / BITS_PER_UNIT;
7471 bytepos = bitpos / BITS_PER_UNIT;
7472 if (bytepos > 0)
7473 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7474 else if (bytepos < 0)
7476 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7477 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7479 break;
7482 case INTEGER_CST:
7483 if (host_integerp (loc, 0))
7484 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7485 break;
7487 case BIT_AND_EXPR:
7488 op = DW_OP_and;
7489 goto do_binop;
7490 case BIT_XOR_EXPR:
7491 op = DW_OP_xor;
7492 goto do_binop;
7493 case BIT_IOR_EXPR:
7494 op = DW_OP_or;
7495 goto do_binop;
7496 case TRUNC_DIV_EXPR:
7497 op = DW_OP_div;
7498 goto do_binop;
7499 case MINUS_EXPR:
7500 op = DW_OP_minus;
7501 goto do_binop;
7502 case TRUNC_MOD_EXPR:
7503 op = DW_OP_mod;
7504 goto do_binop;
7505 case MULT_EXPR:
7506 op = DW_OP_mul;
7507 goto do_binop;
7508 case LSHIFT_EXPR:
7509 op = DW_OP_shl;
7510 goto do_binop;
7511 case RSHIFT_EXPR:
7512 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7513 goto do_binop;
7514 case PLUS_EXPR:
7515 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7516 && host_integerp (TREE_OPERAND (loc, 1), 0))
7518 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7519 add_loc_descr (&ret,
7520 new_loc_descr (DW_OP_plus_uconst,
7521 tree_low_cst (TREE_OPERAND (loc, 1),
7523 0));
7524 break;
7526 op = DW_OP_plus;
7527 goto do_binop;
7528 case LE_EXPR:
7529 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7530 break;
7531 op = DW_OP_le;
7532 goto do_binop;
7533 case GE_EXPR:
7534 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7535 break;
7536 op = DW_OP_ge;
7537 goto do_binop;
7538 case LT_EXPR:
7539 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7540 break;
7541 op = DW_OP_lt;
7542 goto do_binop;
7543 case GT_EXPR:
7544 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7545 break;
7546 op = DW_OP_gt;
7547 goto do_binop;
7548 case EQ_EXPR:
7549 op = DW_OP_eq;
7550 goto do_binop;
7551 case NE_EXPR:
7552 op = DW_OP_ne;
7553 goto do_binop;
7555 do_binop:
7556 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7557 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7558 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7559 break;
7561 case BIT_NOT_EXPR:
7562 op = DW_OP_not;
7563 goto do_unop;
7564 case ABS_EXPR:
7565 op = DW_OP_abs;
7566 goto do_unop;
7567 case NEGATE_EXPR:
7568 op = DW_OP_neg;
7569 goto do_unop;
7571 do_unop:
7572 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7573 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7574 break;
7576 case MAX_EXPR:
7577 loc = build (COND_EXPR, TREE_TYPE (loc),
7578 build (LT_EXPR, integer_type_node,
7579 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
7580 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
7581 /* FALLTHRU */
7583 case COND_EXPR:
7585 dw_loc_descr_ref bra_node, jump_node, tmp;
7587 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7588 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
7589 add_loc_descr (&ret, bra_node);
7591 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
7592 add_loc_descr (&ret, tmp);
7593 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
7594 add_loc_descr (&ret, jump_node);
7596 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
7597 add_loc_descr (&ret, tmp);
7598 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7599 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
7601 /* ??? Need a node to point the skip at. Use a nop. */
7602 tmp = new_loc_descr (DW_OP_nop, 0, 0);
7603 add_loc_descr (&ret, tmp);
7604 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7605 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
7607 break;
7609 default:
7610 abort ();
7613 /* If we can't fill the request for an address, die. */
7614 if (addressp && indirect_size == 0)
7615 abort ();
7617 /* If we've got an address and don't want one, dereference. */
7618 if (!addressp && indirect_size > 0)
7620 if (indirect_size > DWARF2_ADDR_SIZE)
7621 abort ();
7622 if (indirect_size == DWARF2_ADDR_SIZE)
7623 op = DW_OP_deref;
7624 else
7625 op = DW_OP_deref_size;
7626 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
7629 return ret;
7632 /* Given a value, round it up to the lowest multiple of `boundary'
7633 which is not less than the value itself. */
7635 static inline HOST_WIDE_INT
7636 ceiling (value, boundary)
7637 HOST_WIDE_INT value;
7638 unsigned int boundary;
7640 return (((value + boundary - 1) / boundary) * boundary);
7643 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7644 pointer to the declared type for the relevant field variable, or return
7645 `integer_type_node' if the given node turns out to be an
7646 ERROR_MARK node. */
7648 static inline tree
7649 field_type (decl)
7650 register tree decl;
7652 register tree type;
7654 if (TREE_CODE (decl) == ERROR_MARK)
7655 return integer_type_node;
7657 type = DECL_BIT_FIELD_TYPE (decl);
7658 if (type == NULL_TREE)
7659 type = TREE_TYPE (decl);
7661 return type;
7664 /* Given a pointer to a tree node, return the alignment in bits for
7665 it, or else return BITS_PER_WORD if the node actually turns out to
7666 be an ERROR_MARK node. */
7668 static inline unsigned
7669 simple_type_align_in_bits (type)
7670 register tree type;
7672 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7675 static inline unsigned
7676 simple_decl_align_in_bits (decl)
7677 register tree decl;
7679 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
7682 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7683 node, return the size in bits for the type if it is a constant, or else
7684 return the alignment for the type if the type's size is not constant, or
7685 else return BITS_PER_WORD if the type actually turns out to be an
7686 ERROR_MARK node. */
7688 static inline unsigned HOST_WIDE_INT
7689 simple_type_size_in_bits (type)
7690 register tree type;
7692 tree type_size_tree;
7694 if (TREE_CODE (type) == ERROR_MARK)
7695 return BITS_PER_WORD;
7696 type_size_tree = TYPE_SIZE (type);
7698 if (type_size_tree == NULL_TREE)
7699 return 0;
7700 if (! host_integerp (type_size_tree, 1))
7701 return TYPE_ALIGN (type);
7702 return tree_low_cst (type_size_tree, 1);
7705 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7706 return the byte offset of the lowest addressed byte of the "containing
7707 object" for the given FIELD_DECL, or return 0 if we are unable to
7708 determine what that offset is, either because the argument turns out to
7709 be a pointer to an ERROR_MARK node, or because the offset is actually
7710 variable. (We can't handle the latter case just yet). */
7712 static HOST_WIDE_INT
7713 field_byte_offset (decl)
7714 register tree decl;
7716 unsigned int type_align_in_bits;
7717 unsigned int decl_align_in_bits;
7718 unsigned HOST_WIDE_INT type_size_in_bits;
7719 HOST_WIDE_INT object_offset_in_bits;
7720 HOST_WIDE_INT object_offset_in_bytes;
7721 tree type;
7722 tree field_size_tree;
7723 HOST_WIDE_INT bitpos_int;
7724 HOST_WIDE_INT deepest_bitpos;
7725 unsigned HOST_WIDE_INT field_size_in_bits;
7727 if (TREE_CODE (decl) == ERROR_MARK)
7728 return 0;
7730 if (TREE_CODE (decl) != FIELD_DECL)
7731 abort ();
7733 type = field_type (decl);
7734 field_size_tree = DECL_SIZE (decl);
7736 /* The size could be unspecified if there was an error, or for
7737 a flexible array member. */
7738 if (! field_size_tree)
7739 field_size_tree = bitsize_zero_node;
7741 /* We cannot yet cope with fields whose positions are variable, so
7742 for now, when we see such things, we simply return 0. Someday, we may
7743 be able to handle such cases, but it will be damn difficult. */
7744 if (! host_integerp (bit_position (decl), 0))
7745 return 0;
7747 bitpos_int = int_bit_position (decl);
7749 /* If we don't know the size of the field, pretend it's a full word. */
7750 if (host_integerp (field_size_tree, 1))
7751 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7752 else
7753 field_size_in_bits = BITS_PER_WORD;
7755 type_size_in_bits = simple_type_size_in_bits (type);
7756 type_align_in_bits = simple_type_align_in_bits (type);
7757 decl_align_in_bits = simple_decl_align_in_bits (decl);
7759 /* Note that the GCC front-end doesn't make any attempt to keep track of
7760 the starting bit offset (relative to the start of the containing
7761 structure type) of the hypothetical "containing object" for a bit-
7762 field. Thus, when computing the byte offset value for the start of the
7763 "containing object" of a bit-field, we must deduce this information on
7764 our own. This can be rather tricky to do in some cases. For example,
7765 handling the following structure type definition when compiling for an
7766 i386/i486 target (which only aligns long long's to 32-bit boundaries)
7767 can be very tricky:
7769 struct S { int field1; long long field2:31; };
7771 Fortunately, there is a simple rule-of-thumb which can be
7772 used in such cases. When compiling for an i386/i486, GCC will allocate
7773 8 bytes for the structure shown above. It decides to do this based upon
7774 one simple rule for bit-field allocation. Quite simply, GCC allocates
7775 each "containing object" for each bit-field at the first (i.e. lowest
7776 addressed) legitimate alignment boundary (based upon the required
7777 minimum alignment for the declared type of the field) which it can
7778 possibly use, subject to the condition that there is still enough
7779 available space remaining in the containing object (when allocated at
7780 the selected point) to fully accommodate all of the bits of the
7781 bit-field itself. This simple rule makes it obvious why GCC allocates
7782 8 bytes for each object of the structure type shown above. When looking
7783 for a place to allocate the "containing object" for `field2', the
7784 compiler simply tries to allocate a 64-bit "containing object" at each
7785 successive 32-bit boundary (starting at zero) until it finds a place to
7786 allocate that 64- bit field such that at least 31 contiguous (and
7787 previously unallocated) bits remain within that selected 64 bit field.
7788 (As it turns out, for the example above, the compiler finds that it is
7789 OK to allocate the "containing object" 64-bit field at bit-offset zero
7790 within the structure type.) Here we attempt to work backwards from the
7791 limited set of facts we're given, and we try to deduce from those facts,
7792 where GCC must have believed that the containing object started (within
7793 the structure type). The value we deduce is then used (by the callers of
7794 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
7795 for fields (both bit-fields and, in the case of DW_AT_location, regular
7796 fields as well). */
7798 /* Figure out the bit-distance from the start of the structure to the
7799 "deepest" bit of the bit-field. */
7800 deepest_bitpos = bitpos_int + field_size_in_bits;
7802 /* This is the tricky part. Use some fancy footwork to deduce where the
7803 lowest addressed bit of the containing object must be. */
7804 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
7806 /* Round up to type_align by default. This works best for bitfields. */
7807 object_offset_in_bits += type_align_in_bits - 1;
7808 object_offset_in_bits /= type_align_in_bits;
7809 object_offset_in_bits *= type_align_in_bits;
7811 if (object_offset_in_bits > bitpos_int)
7813 /* Sigh, the decl must be packed. */
7814 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
7816 /* Round up to decl_align instead. */
7817 object_offset_in_bits += decl_align_in_bits - 1;
7818 object_offset_in_bits /= decl_align_in_bits;
7819 object_offset_in_bits *= decl_align_in_bits;
7822 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
7824 return object_offset_in_bytes;
7827 /* The following routines define various Dwarf attributes and any data
7828 associated with them. */
7830 /* Add a location description attribute value to a DIE.
7832 This emits location attributes suitable for whole variables and
7833 whole parameters. Note that the location attributes for struct fields are
7834 generated by the routine `data_member_location_attribute' below. */
7836 static void
7837 add_AT_location_description (die, attr_kind, rtl)
7838 dw_die_ref die;
7839 enum dwarf_attribute attr_kind;
7840 register rtx rtl;
7842 /* Handle a special case. If we are about to output a location descriptor
7843 for a variable or parameter which has been optimized out of existence,
7844 don't do that. A variable which has been optimized out
7845 of existence will have a DECL_RTL value which denotes a pseudo-reg.
7846 Currently, in some rare cases, variables can have DECL_RTL values which
7847 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
7848 elsewhere in the compiler. We treat such cases as if the variable(s) in
7849 question had been optimized out of existence. */
7851 if (is_pseudo_reg (rtl)
7852 || (GET_CODE (rtl) == MEM
7853 && is_pseudo_reg (XEXP (rtl, 0)))
7854 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
7855 references the internal argument pointer (a pseudo) in a function
7856 where all references to the internal argument pointer were
7857 eliminated via the optimizers. */
7858 || (GET_CODE (rtl) == MEM
7859 && GET_CODE (XEXP (rtl, 0)) == PLUS
7860 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
7861 || (GET_CODE (rtl) == CONCAT
7862 && is_pseudo_reg (XEXP (rtl, 0))
7863 && is_pseudo_reg (XEXP (rtl, 1))))
7864 return;
7866 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
7869 /* Attach the specialized form of location attribute used for data
7870 members of struct and union types. In the special case of a
7871 FIELD_DECL node which represents a bit-field, the "offset" part
7872 of this special location descriptor must indicate the distance
7873 in bytes from the lowest-addressed byte of the containing struct
7874 or union type to the lowest-addressed byte of the "containing
7875 object" for the bit-field. (See the `field_byte_offset' function
7876 above).. For any given bit-field, the "containing object" is a
7877 hypothetical object (of some integral or enum type) within which
7878 the given bit-field lives. The type of this hypothetical
7879 "containing object" is always the same as the declared type of
7880 the individual bit-field itself (for GCC anyway... the DWARF
7881 spec doesn't actually mandate this). Note that it is the size
7882 (in bytes) of the hypothetical "containing object" which will
7883 be given in the DW_AT_byte_size attribute for this bit-field.
7884 (See the `byte_size_attribute' function below.) It is also used
7885 when calculating the value of the DW_AT_bit_offset attribute.
7886 (See the `bit_offset_attribute' function below). */
7888 static void
7889 add_data_member_location_attribute (die, decl)
7890 register dw_die_ref die;
7891 register tree decl;
7893 register unsigned long offset;
7894 register dw_loc_descr_ref loc_descr;
7895 register enum dwarf_location_atom op;
7897 if (TREE_CODE (decl) == TREE_VEC)
7898 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
7899 else
7900 offset = field_byte_offset (decl);
7902 /* The DWARF2 standard says that we should assume that the structure address
7903 is already on the stack, so we can specify a structure field address
7904 by using DW_OP_plus_uconst. */
7906 #ifdef MIPS_DEBUGGING_INFO
7907 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
7908 correctly. It works only if we leave the offset on the stack. */
7909 op = DW_OP_constu;
7910 #else
7911 op = DW_OP_plus_uconst;
7912 #endif
7914 loc_descr = new_loc_descr (op, offset, 0);
7915 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
7918 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
7919 does not have a "location" either in memory or in a register. These
7920 things can arise in GNU C when a constant is passed as an actual parameter
7921 to an inlined function. They can also arise in C++ where declared
7922 constants do not necessarily get memory "homes". */
7924 static void
7925 add_const_value_attribute (die, rtl)
7926 register dw_die_ref die;
7927 register rtx rtl;
7929 switch (GET_CODE (rtl))
7931 case CONST_INT:
7932 /* Note that a CONST_INT rtx could represent either an integer
7933 or a floating-point constant. A CONST_INT is used whenever
7934 the constant will fit into a single word. In all such
7935 cases, the original mode of the constant value is wiped
7936 out, and the CONST_INT rtx is assigned VOIDmode. */
7938 HOST_WIDE_INT val = INTVAL (rtl);
7940 /* ??? We really should be using HOST_WIDE_INT throughout. */
7941 if (val < 0)
7943 if ((long) val != val)
7944 abort ();
7945 add_AT_int (die, DW_AT_const_value, (long) val);
7947 else
7949 if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
7950 abort ();
7951 add_AT_int (die, DW_AT_const_value, (unsigned long) val);
7954 break;
7956 case CONST_DOUBLE:
7957 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
7958 floating-point constant. A CONST_DOUBLE is used whenever the
7959 constant requires more than one word in order to be adequately
7960 represented. We output CONST_DOUBLEs as blocks. */
7962 register enum machine_mode mode = GET_MODE (rtl);
7964 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
7966 register unsigned length = GET_MODE_SIZE (mode) / 4;
7967 long *array = (long *) xmalloc (sizeof (long) * length);
7968 REAL_VALUE_TYPE rv;
7970 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
7971 switch (mode)
7973 case SFmode:
7974 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
7975 break;
7977 case DFmode:
7978 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
7979 break;
7981 case XFmode:
7982 case TFmode:
7983 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
7984 break;
7986 default:
7987 abort ();
7990 add_AT_float (die, DW_AT_const_value, length, array);
7992 else
7994 /* ??? We really should be using HOST_WIDE_INT throughout. */
7995 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
7996 abort ();
7997 add_AT_long_long (die, DW_AT_const_value,
7998 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8001 break;
8003 case CONST_STRING:
8004 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8005 break;
8007 case SYMBOL_REF:
8008 case LABEL_REF:
8009 case CONST:
8010 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8011 break;
8013 case PLUS:
8014 /* In cases where an inlined instance of an inline function is passed
8015 the address of an `auto' variable (which is local to the caller) we
8016 can get a situation where the DECL_RTL of the artificial local
8017 variable (for the inlining) which acts as a stand-in for the
8018 corresponding formal parameter (of the inline function) will look
8019 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8020 exactly a compile-time constant expression, but it isn't the address
8021 of the (artificial) local variable either. Rather, it represents the
8022 *value* which the artificial local variable always has during its
8023 lifetime. We currently have no way to represent such quasi-constant
8024 values in Dwarf, so for now we just punt and generate nothing. */
8025 break;
8027 default:
8028 /* No other kinds of rtx should be possible here. */
8029 abort ();
8034 /* Returns RTL for DECL indicating the location the debugger should
8035 use to find the value of DECL at runtime. Returns NULL_RTX if
8036 there is no such location, or if a satisfactory location could not
8037 be determined. */
8039 static rtx
8040 rtl_for_decl_location (decl)
8041 tree decl;
8043 register rtx rtl;
8045 /* This function should not be called with an abstract declaration,
8046 since such things have no location. */
8047 if (DECL_ABSTRACT (decl))
8048 abort ();
8050 /* Here we have to decide where we are going to say the parameter "lives"
8051 (as far as the debugger is concerned). We only have a couple of
8052 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8054 DECL_RTL normally indicates where the parameter lives during most of the
8055 activation of the function. If optimization is enabled however, this
8056 could be either NULL or else a pseudo-reg. Both of those cases indicate
8057 that the parameter doesn't really live anywhere (as far as the code
8058 generation parts of GCC are concerned) during most of the function's
8059 activation. That will happen (for example) if the parameter is never
8060 referenced within the function.
8062 We could just generate a location descriptor here for all non-NULL
8063 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8064 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8065 where DECL_RTL is NULL or is a pseudo-reg.
8067 Note however that we can only get away with using DECL_INCOMING_RTL as
8068 a backup substitute for DECL_RTL in certain limited cases. In cases
8069 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8070 we can be sure that the parameter was passed using the same type as it is
8071 declared to have within the function, and that its DECL_INCOMING_RTL
8072 points us to a place where a value of that type is passed.
8074 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8075 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8076 because in these cases DECL_INCOMING_RTL points us to a value of some
8077 type which is *different* from the type of the parameter itself. Thus,
8078 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8079 such cases, the debugger would end up (for example) trying to fetch a
8080 `float' from a place which actually contains the first part of a
8081 `double'. That would lead to really incorrect and confusing
8082 output at debug-time.
8084 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8085 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8086 are a couple of exceptions however. On little-endian machines we can
8087 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8088 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8089 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8090 when (on a little-endian machine) a non-prototyped function has a
8091 parameter declared to be of type `short' or `char'. In such cases,
8092 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8093 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8094 passed `int' value. If the debugger then uses that address to fetch
8095 a `short' or a `char' (on a little-endian machine) the result will be
8096 the correct data, so we allow for such exceptional cases below.
8098 Note that our goal here is to describe the place where the given formal
8099 parameter lives during most of the function's activation (i.e. between
8100 the end of the prologue and the start of the epilogue). We'll do that
8101 as best as we can. Note however that if the given formal parameter is
8102 modified sometime during the execution of the function, then a stack
8103 backtrace (at debug-time) will show the function as having been
8104 called with the *new* value rather than the value which was
8105 originally passed in. This happens rarely enough that it is not
8106 a major problem, but it *is* a problem, and I'd like to fix it.
8108 A future version of dwarf2out.c may generate two additional
8109 attributes for any given DW_TAG_formal_parameter DIE which will
8110 describe the "passed type" and the "passed location" for the
8111 given formal parameter in addition to the attributes we now
8112 generate to indicate the "declared type" and the "active
8113 location" for each parameter. This additional set of attributes
8114 could be used by debuggers for stack backtraces. Separately, note
8115 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8116 NULL also. This happens (for example) for inlined-instances of
8117 inline function formal parameters which are never referenced.
8118 This really shouldn't be happening. All PARM_DECL nodes should
8119 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8120 doesn't currently generate these values for inlined instances of
8121 inline function parameters, so when we see such cases, we are
8122 just out-of-luck for the time being (until integrate.c
8123 gets fixed). */
8125 /* Use DECL_RTL as the "location" unless we find something better. */
8126 rtl = DECL_RTL_IF_SET (decl);
8128 if (TREE_CODE (decl) == PARM_DECL)
8130 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8132 tree declared_type = type_main_variant (TREE_TYPE (decl));
8133 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8135 /* This decl represents a formal parameter which was optimized out.
8136 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8137 all* cases where (rtl == NULL_RTX) just below. */
8138 if (declared_type == passed_type)
8139 rtl = DECL_INCOMING_RTL (decl);
8140 else if (! BYTES_BIG_ENDIAN
8141 && TREE_CODE (declared_type) == INTEGER_TYPE
8142 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8143 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8144 rtl = DECL_INCOMING_RTL (decl);
8147 /* If the parm was passed in registers, but lives on the stack, then
8148 make a big endian correction if the mode of the type of the
8149 parameter is not the same as the mode of the rtl. */
8150 /* ??? This is the same series of checks that are made in dbxout.c before
8151 we reach the big endian correction code there. It isn't clear if all
8152 of these checks are necessary here, but keeping them all is the safe
8153 thing to do. */
8154 else if (GET_CODE (rtl) == MEM
8155 && XEXP (rtl, 0) != const0_rtx
8156 && ! CONSTANT_P (XEXP (rtl, 0))
8157 /* Not passed in memory. */
8158 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8159 /* Not passed by invisible reference. */
8160 && (GET_CODE (XEXP (rtl, 0)) != REG
8161 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8162 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8163 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8164 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8165 #endif
8167 /* Big endian correction check. */
8168 && BYTES_BIG_ENDIAN
8169 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8170 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8171 < UNITS_PER_WORD))
8173 int offset = (UNITS_PER_WORD
8174 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8175 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8176 plus_constant (XEXP (rtl, 0), offset));
8180 if (rtl != NULL_RTX)
8182 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8183 #ifdef LEAF_REG_REMAP
8184 if (current_function_uses_only_leaf_regs)
8185 leaf_renumber_regs_insn (rtl);
8186 #endif
8189 return rtl;
8192 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8193 data attribute for a variable or a parameter. We generate the
8194 DW_AT_const_value attribute only in those cases where the given variable
8195 or parameter does not have a true "location" either in memory or in a
8196 register. This can happen (for example) when a constant is passed as an
8197 actual argument in a call to an inline function. (It's possible that
8198 these things can crop up in other ways also.) Note that one type of
8199 constant value which can be passed into an inlined function is a constant
8200 pointer. This can happen for example if an actual argument in an inlined
8201 function call evaluates to a compile-time constant address. */
8203 static void
8204 add_location_or_const_value_attribute (die, decl)
8205 register dw_die_ref die;
8206 register tree decl;
8208 register rtx rtl;
8210 if (TREE_CODE (decl) == ERROR_MARK)
8211 return;
8213 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8214 abort ();
8216 rtl = rtl_for_decl_location (decl);
8217 if (rtl == NULL_RTX)
8218 return;
8220 switch (GET_CODE (rtl))
8222 case ADDRESSOF:
8223 /* The address of a variable that was optimized away; don't emit
8224 anything. */
8225 break;
8227 case CONST_INT:
8228 case CONST_DOUBLE:
8229 case CONST_STRING:
8230 case SYMBOL_REF:
8231 case LABEL_REF:
8232 case CONST:
8233 case PLUS:
8234 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8235 add_const_value_attribute (die, rtl);
8236 break;
8238 case MEM:
8239 case REG:
8240 case SUBREG:
8241 case CONCAT:
8242 add_AT_location_description (die, DW_AT_location, rtl);
8243 break;
8245 default:
8246 abort ();
8250 /* If we don't have a copy of this variable in memory for some reason (such
8251 as a C++ member constant that doesn't have an out-of-line definition),
8252 we should tell the debugger about the constant value. */
8254 static void
8255 tree_add_const_value_attribute (var_die, decl)
8256 dw_die_ref var_die;
8257 tree decl;
8259 tree init = DECL_INITIAL (decl);
8260 tree type = TREE_TYPE (decl);
8262 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8263 && initializer_constant_valid_p (init, type) == null_pointer_node)
8264 /* OK */;
8265 else
8266 return;
8268 switch (TREE_CODE (type))
8270 case INTEGER_TYPE:
8271 if (host_integerp (init, 0))
8272 add_AT_unsigned (var_die, DW_AT_const_value,
8273 TREE_INT_CST_LOW (init));
8274 else
8275 add_AT_long_long (var_die, DW_AT_const_value,
8276 TREE_INT_CST_HIGH (init),
8277 TREE_INT_CST_LOW (init));
8278 break;
8280 default:;
8284 /* Generate an DW_AT_name attribute given some string value to be included as
8285 the value of the attribute. */
8287 static inline void
8288 add_name_attribute (die, name_string)
8289 register dw_die_ref die;
8290 register const char *name_string;
8292 if (name_string != NULL && *name_string != 0)
8294 if (demangle_name_func)
8295 name_string = (*demangle_name_func) (name_string);
8297 add_AT_string (die, DW_AT_name, name_string);
8301 /* Given a tree node describing an array bound (either lower or upper) output
8302 a representation for that bound. */
8304 static void
8305 add_bound_info (subrange_die, bound_attr, bound)
8306 register dw_die_ref subrange_die;
8307 register enum dwarf_attribute bound_attr;
8308 register tree bound;
8310 /* If this is an Ada unconstrained array type, then don't emit any debug
8311 info because the array bounds are unknown. They are parameterized when
8312 the type is instantiated. */
8313 if (contains_placeholder_p (bound))
8314 return;
8316 switch (TREE_CODE (bound))
8318 case ERROR_MARK:
8319 return;
8321 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8322 case INTEGER_CST:
8323 if (! host_integerp (bound, 0)
8324 || (bound_attr == DW_AT_lower_bound
8325 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8326 || (is_fortran () && integer_onep (bound)))))
8327 /* use the default */
8329 else
8330 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8331 break;
8333 case CONVERT_EXPR:
8334 case NOP_EXPR:
8335 case NON_LVALUE_EXPR:
8336 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8337 break;
8339 case SAVE_EXPR:
8340 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8341 access the upper bound values may be bogus. If they refer to a
8342 register, they may only describe how to get at these values at the
8343 points in the generated code right after they have just been
8344 computed. Worse yet, in the typical case, the upper bound values
8345 will not even *be* computed in the optimized code (though the
8346 number of elements will), so these SAVE_EXPRs are entirely
8347 bogus. In order to compensate for this fact, we check here to see
8348 if optimization is enabled, and if so, we don't add an attribute
8349 for the (unknown and unknowable) upper bound. This should not
8350 cause too much trouble for existing (stupid?) debuggers because
8351 they have to deal with empty upper bounds location descriptions
8352 anyway in order to be able to deal with incomplete array types.
8353 Of course an intelligent debugger (GDB?) should be able to
8354 comprehend that a missing upper bound specification in a array
8355 type used for a storage class `auto' local array variable
8356 indicates that the upper bound is both unknown (at compile- time)
8357 and unknowable (at run-time) due to optimization.
8359 We assume that a MEM rtx is safe because gcc wouldn't put the
8360 value there unless it was going to be used repeatedly in the
8361 function, i.e. for cleanups. */
8362 if (SAVE_EXPR_RTL (bound)
8363 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8365 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8366 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8367 register rtx loc = SAVE_EXPR_RTL (bound);
8369 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8370 it references an outer function's frame. */
8372 if (GET_CODE (loc) == MEM)
8374 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8376 if (XEXP (loc, 0) != new_addr)
8377 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8380 add_AT_flag (decl_die, DW_AT_artificial, 1);
8381 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8382 add_AT_location_description (decl_die, DW_AT_location, loc);
8383 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8386 /* Else leave out the attribute. */
8387 break;
8389 case VAR_DECL:
8390 case PARM_DECL:
8392 dw_die_ref decl_die = lookup_decl_die (bound);
8394 /* ??? Can this happen, or should the variable have been bound
8395 first? Probably it can, since I imagine that we try to create
8396 the types of parameters in the order in which they exist in
8397 the list, and won't have created a forward reference to a
8398 later parameter. */
8399 if (decl_die != NULL)
8400 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8401 break;
8404 default:
8406 /* Otherwise try to create a stack operation procedure to
8407 evaluate the value of the array bound. */
8409 dw_die_ref ctx, decl_die;
8410 dw_loc_descr_ref loc;
8412 /* If the CURRENT_FUNCTION_DECL is abstract, then we cannot
8413 compute the array bound based on the location of the BOUND,
8414 since the BOUND does not really exist. Therefore, we
8415 simply omit the bound information.
8417 Ideally, we would do better, and express the computation in
8418 some other way. */
8419 if (DECL_ABSTRACT (current_function_decl))
8420 break;
8422 loc = loc_descriptor_from_tree (bound, 0);
8423 if (loc == NULL)
8424 break;
8426 ctx = lookup_decl_die (current_function_decl);
8428 decl_die = new_die (DW_TAG_variable, ctx);
8429 add_AT_flag (decl_die, DW_AT_artificial, 1);
8430 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8431 add_AT_loc (decl_die, DW_AT_location, loc);
8433 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8434 break;
8439 /* Note that the block of subscript information for an array type also
8440 includes information about the element type of type given array type. */
8442 static void
8443 add_subscript_info (type_die, type)
8444 register dw_die_ref type_die;
8445 register tree type;
8447 #ifndef MIPS_DEBUGGING_INFO
8448 register unsigned dimension_number;
8449 #endif
8450 register tree lower, upper;
8451 register dw_die_ref subrange_die;
8453 /* The GNU compilers represent multidimensional array types as sequences of
8454 one dimensional array types whose element types are themselves array
8455 types. Here we squish that down, so that each multidimensional array
8456 type gets only one array_type DIE in the Dwarf debugging info. The draft
8457 Dwarf specification say that we are allowed to do this kind of
8458 compression in C (because there is no difference between an array or
8459 arrays and a multidimensional array in C) but for other source languages
8460 (e.g. Ada) we probably shouldn't do this. */
8462 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8463 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8464 We work around this by disabling this feature. See also
8465 gen_array_type_die. */
8466 #ifndef MIPS_DEBUGGING_INFO
8467 for (dimension_number = 0;
8468 TREE_CODE (type) == ARRAY_TYPE;
8469 type = TREE_TYPE (type), dimension_number++)
8471 #endif
8472 register tree domain = TYPE_DOMAIN (type);
8474 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8475 and (in GNU C only) variable bounds. Handle all three forms
8476 here. */
8477 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8478 if (domain)
8480 /* We have an array type with specified bounds. */
8481 lower = TYPE_MIN_VALUE (domain);
8482 upper = TYPE_MAX_VALUE (domain);
8484 /* define the index type. */
8485 if (TREE_TYPE (domain))
8487 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8488 TREE_TYPE field. We can't emit debug info for this
8489 because it is an unnamed integral type. */
8490 if (TREE_CODE (domain) == INTEGER_TYPE
8491 && TYPE_NAME (domain) == NULL_TREE
8492 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8493 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8495 else
8496 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8497 type_die);
8500 /* ??? If upper is NULL, the array has unspecified length,
8501 but it does have a lower bound. This happens with Fortran
8502 dimension arr(N:*)
8503 Since the debugger is definitely going to need to know N
8504 to produce useful results, go ahead and output the lower
8505 bound solo, and hope the debugger can cope. */
8507 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8508 if (upper)
8509 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8511 else
8512 /* We have an array type with an unspecified length. The DWARF-2
8513 spec does not say how to handle this; let's just leave out the
8514 bounds. */
8517 #ifndef MIPS_DEBUGGING_INFO
8519 #endif
8522 static void
8523 add_byte_size_attribute (die, tree_node)
8524 dw_die_ref die;
8525 register tree tree_node;
8527 register unsigned size;
8529 switch (TREE_CODE (tree_node))
8531 case ERROR_MARK:
8532 size = 0;
8533 break;
8534 case ENUMERAL_TYPE:
8535 case RECORD_TYPE:
8536 case UNION_TYPE:
8537 case QUAL_UNION_TYPE:
8538 size = int_size_in_bytes (tree_node);
8539 break;
8540 case FIELD_DECL:
8541 /* For a data member of a struct or union, the DW_AT_byte_size is
8542 generally given as the number of bytes normally allocated for an
8543 object of the *declared* type of the member itself. This is true
8544 even for bit-fields. */
8545 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8546 break;
8547 default:
8548 abort ();
8551 /* Note that `size' might be -1 when we get to this point. If it is, that
8552 indicates that the byte size of the entity in question is variable. We
8553 have no good way of expressing this fact in Dwarf at the present time,
8554 so just let the -1 pass on through. */
8556 add_AT_unsigned (die, DW_AT_byte_size, size);
8559 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8560 which specifies the distance in bits from the highest order bit of the
8561 "containing object" for the bit-field to the highest order bit of the
8562 bit-field itself.
8564 For any given bit-field, the "containing object" is a hypothetical
8565 object (of some integral or enum type) within which the given bit-field
8566 lives. The type of this hypothetical "containing object" is always the
8567 same as the declared type of the individual bit-field itself. The
8568 determination of the exact location of the "containing object" for a
8569 bit-field is rather complicated. It's handled by the
8570 `field_byte_offset' function (above).
8572 Note that it is the size (in bytes) of the hypothetical "containing object"
8573 which will be given in the DW_AT_byte_size attribute for this bit-field.
8574 (See `byte_size_attribute' above). */
8576 static inline void
8577 add_bit_offset_attribute (die, decl)
8578 register dw_die_ref die;
8579 register tree decl;
8581 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8582 tree type = DECL_BIT_FIELD_TYPE (decl);
8583 HOST_WIDE_INT bitpos_int;
8584 HOST_WIDE_INT highest_order_object_bit_offset;
8585 HOST_WIDE_INT highest_order_field_bit_offset;
8586 HOST_WIDE_INT unsigned bit_offset;
8588 /* Must be a field and a bit field. */
8589 if (!type
8590 || TREE_CODE (decl) != FIELD_DECL)
8591 abort ();
8593 /* We can't yet handle bit-fields whose offsets are variable, so if we
8594 encounter such things, just return without generating any attribute
8595 whatsoever. Likewise for variable or too large size. */
8596 if (! host_integerp (bit_position (decl), 0)
8597 || ! host_integerp (DECL_SIZE (decl), 1))
8598 return;
8600 bitpos_int = int_bit_position (decl);
8602 /* Note that the bit offset is always the distance (in bits) from the
8603 highest-order bit of the "containing object" to the highest-order bit of
8604 the bit-field itself. Since the "high-order end" of any object or field
8605 is different on big-endian and little-endian machines, the computation
8606 below must take account of these differences. */
8607 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8608 highest_order_field_bit_offset = bitpos_int;
8610 if (! BYTES_BIG_ENDIAN)
8612 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8613 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8616 bit_offset
8617 = (! BYTES_BIG_ENDIAN
8618 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8619 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8621 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8624 /* For a FIELD_DECL node which represents a bit field, output an attribute
8625 which specifies the length in bits of the given field. */
8627 static inline void
8628 add_bit_size_attribute (die, decl)
8629 register dw_die_ref die;
8630 register tree decl;
8632 /* Must be a field and a bit field. */
8633 if (TREE_CODE (decl) != FIELD_DECL
8634 || ! DECL_BIT_FIELD_TYPE (decl))
8635 abort ();
8637 if (host_integerp (DECL_SIZE (decl), 1))
8638 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8641 /* If the compiled language is ANSI C, then add a 'prototyped'
8642 attribute, if arg types are given for the parameters of a function. */
8644 static inline void
8645 add_prototyped_attribute (die, func_type)
8646 register dw_die_ref die;
8647 register tree func_type;
8649 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8650 && TYPE_ARG_TYPES (func_type) != NULL)
8651 add_AT_flag (die, DW_AT_prototyped, 1);
8654 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8655 by looking in either the type declaration or object declaration
8656 equate table. */
8658 static inline void
8659 add_abstract_origin_attribute (die, origin)
8660 register dw_die_ref die;
8661 register tree origin;
8663 dw_die_ref origin_die = NULL;
8665 if (TREE_CODE (origin) != FUNCTION_DECL)
8667 /* We may have gotten separated from the block for the inlined
8668 function, if we're in an exception handler or some such; make
8669 sure that the abstract function has been written out.
8671 Doing this for nested functions is wrong, however; functions are
8672 distinct units, and our context might not even be inline. */
8673 tree fn = origin;
8674 if (TYPE_P (fn))
8675 fn = TYPE_STUB_DECL (fn);
8676 fn = decl_function_context (fn);
8677 if (fn)
8678 dwarf2out_abstract_function (fn);
8681 if (DECL_P (origin))
8682 origin_die = lookup_decl_die (origin);
8683 else if (TYPE_P (origin))
8684 origin_die = lookup_type_die (origin);
8686 if (origin_die == NULL)
8687 abort ();
8689 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8692 /* We do not currently support the pure_virtual attribute. */
8694 static inline void
8695 add_pure_or_virtual_attribute (die, func_decl)
8696 register dw_die_ref die;
8697 register tree func_decl;
8699 if (DECL_VINDEX (func_decl))
8701 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8703 if (host_integerp (DECL_VINDEX (func_decl), 0))
8704 add_AT_loc (die, DW_AT_vtable_elem_location,
8705 new_loc_descr (DW_OP_constu,
8706 tree_low_cst (DECL_VINDEX (func_decl), 0),
8707 0));
8709 /* GNU extension: Record what type this method came from originally. */
8710 if (debug_info_level > DINFO_LEVEL_TERSE)
8711 add_AT_die_ref (die, DW_AT_containing_type,
8712 lookup_type_die (DECL_CONTEXT (func_decl)));
8716 /* Add source coordinate attributes for the given decl. */
8718 static void
8719 add_src_coords_attributes (die, decl)
8720 register dw_die_ref die;
8721 register tree decl;
8723 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
8725 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8726 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8729 /* Add an DW_AT_name attribute and source coordinate attribute for the
8730 given decl, but only if it actually has a name. */
8732 static void
8733 add_name_and_src_coords_attributes (die, decl)
8734 register dw_die_ref die;
8735 register tree decl;
8737 register tree decl_name;
8739 decl_name = DECL_NAME (decl);
8740 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8742 add_name_attribute (die, dwarf2_name (decl, 0));
8743 if (! DECL_ARTIFICIAL (decl))
8744 add_src_coords_attributes (die, decl);
8746 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8747 && TREE_PUBLIC (decl)
8748 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
8749 && !DECL_ABSTRACT (decl))
8750 add_AT_string (die, DW_AT_MIPS_linkage_name,
8751 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8755 /* Push a new declaration scope. */
8757 static void
8758 push_decl_scope (scope)
8759 tree scope;
8761 VARRAY_PUSH_TREE (decl_scope_table, scope);
8764 /* Pop a declaration scope. */
8765 static inline void
8766 pop_decl_scope ()
8768 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
8769 abort ();
8770 VARRAY_POP (decl_scope_table);
8773 /* Return the DIE for the scope that immediately contains this type.
8774 Non-named types get global scope. Named types nested in other
8775 types get their containing scope if it's open, or global scope
8776 otherwise. All other types (i.e. function-local named types) get
8777 the current active scope. */
8779 static dw_die_ref
8780 scope_die_for (t, context_die)
8781 register tree t;
8782 register dw_die_ref context_die;
8784 register dw_die_ref scope_die = NULL;
8785 register tree containing_scope;
8786 register int i;
8788 /* Non-types always go in the current scope. */
8789 if (! TYPE_P (t))
8790 abort ();
8792 containing_scope = TYPE_CONTEXT (t);
8794 /* Ignore namespaces for the moment. */
8795 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
8796 containing_scope = NULL_TREE;
8798 /* Ignore function type "scopes" from the C frontend. They mean that
8799 a tagged type is local to a parmlist of a function declarator, but
8800 that isn't useful to DWARF. */
8801 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
8802 containing_scope = NULL_TREE;
8804 if (containing_scope == NULL_TREE)
8805 scope_die = comp_unit_die;
8806 else if (TYPE_P (containing_scope))
8808 /* For types, we can just look up the appropriate DIE. But
8809 first we check to see if we're in the middle of emitting it
8810 so we know where the new DIE should go. */
8812 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
8813 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
8814 break;
8816 if (i < 0)
8818 if (debug_info_level > DINFO_LEVEL_TERSE
8819 && !TREE_ASM_WRITTEN (containing_scope))
8820 abort ();
8822 /* If none of the current dies are suitable, we get file scope. */
8823 scope_die = comp_unit_die;
8825 else
8826 scope_die = lookup_type_die (containing_scope);
8828 else
8829 scope_die = context_die;
8831 return scope_die;
8834 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
8836 static inline int local_scope_p PARAMS ((dw_die_ref));
8837 static inline int
8838 local_scope_p (context_die)
8839 dw_die_ref context_die;
8841 for (; context_die; context_die = context_die->die_parent)
8842 if (context_die->die_tag == DW_TAG_inlined_subroutine
8843 || context_die->die_tag == DW_TAG_subprogram)
8844 return 1;
8845 return 0;
8848 /* Returns nonzero iff CONTEXT_DIE is a class. */
8850 static inline int class_scope_p PARAMS ((dw_die_ref));
8851 static inline int
8852 class_scope_p (context_die)
8853 dw_die_ref context_die;
8855 return (context_die
8856 && (context_die->die_tag == DW_TAG_structure_type
8857 || context_die->die_tag == DW_TAG_union_type));
8860 /* Many forms of DIEs require a "type description" attribute. This
8861 routine locates the proper "type descriptor" die for the type given
8862 by 'type', and adds an DW_AT_type attribute below the given die. */
8864 static void
8865 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
8866 register dw_die_ref object_die;
8867 register tree type;
8868 register int decl_const;
8869 register int decl_volatile;
8870 register dw_die_ref context_die;
8872 register enum tree_code code = TREE_CODE (type);
8873 register dw_die_ref type_die = NULL;
8875 /* ??? If this type is an unnamed subrange type of an integral or
8876 floating-point type, use the inner type. This is because we have no
8877 support for unnamed types in base_type_die. This can happen if this is
8878 an Ada subrange type. Correct solution is emit a subrange type die. */
8879 if ((code == INTEGER_TYPE || code == REAL_TYPE)
8880 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
8881 type = TREE_TYPE (type), code = TREE_CODE (type);
8883 if (code == ERROR_MARK)
8884 return;
8886 /* Handle a special case. For functions whose return type is void, we
8887 generate *no* type attribute. (Note that no object may have type
8888 `void', so this only applies to function return types). */
8889 if (code == VOID_TYPE)
8890 return;
8892 type_die = modified_type_die (type,
8893 decl_const || TYPE_READONLY (type),
8894 decl_volatile || TYPE_VOLATILE (type),
8895 context_die);
8896 if (type_die != NULL)
8897 add_AT_die_ref (object_die, DW_AT_type, type_die);
8900 /* Given a tree pointer to a struct, class, union, or enum type node, return
8901 a pointer to the (string) tag name for the given type, or zero if the type
8902 was declared without a tag. */
8904 static const char *
8905 type_tag (type)
8906 register tree type;
8908 register const char *name = 0;
8910 if (TYPE_NAME (type) != 0)
8912 register tree t = 0;
8914 /* Find the IDENTIFIER_NODE for the type name. */
8915 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
8916 t = TYPE_NAME (type);
8918 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
8919 a TYPE_DECL node, regardless of whether or not a `typedef' was
8920 involved. */
8921 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8922 && ! DECL_IGNORED_P (TYPE_NAME (type)))
8923 t = DECL_NAME (TYPE_NAME (type));
8925 /* Now get the name as a string, or invent one. */
8926 if (t != 0)
8927 name = IDENTIFIER_POINTER (t);
8930 return (name == 0 || *name == '\0') ? 0 : name;
8933 /* Return the type associated with a data member, make a special check
8934 for bit field types. */
8936 static inline tree
8937 member_declared_type (member)
8938 register tree member;
8940 return (DECL_BIT_FIELD_TYPE (member)
8941 ? DECL_BIT_FIELD_TYPE (member)
8942 : TREE_TYPE (member));
8945 /* Get the decl's label, as described by its RTL. This may be different
8946 from the DECL_NAME name used in the source file. */
8948 #if 0
8949 static const char *
8950 decl_start_label (decl)
8951 register tree decl;
8953 rtx x;
8954 const char *fnname;
8955 x = DECL_RTL (decl);
8956 if (GET_CODE (x) != MEM)
8957 abort ();
8959 x = XEXP (x, 0);
8960 if (GET_CODE (x) != SYMBOL_REF)
8961 abort ();
8963 fnname = XSTR (x, 0);
8964 return fnname;
8966 #endif
8968 /* These routines generate the internal representation of the DIE's for
8969 the compilation unit. Debugging information is collected by walking
8970 the declaration trees passed in from dwarf2out_decl(). */
8972 static void
8973 gen_array_type_die (type, context_die)
8974 register tree type;
8975 register dw_die_ref context_die;
8977 register dw_die_ref scope_die = scope_die_for (type, context_die);
8978 register dw_die_ref array_die;
8979 register tree element_type;
8981 /* ??? The SGI dwarf reader fails for array of array of enum types unless
8982 the inner array type comes before the outer array type. Thus we must
8983 call gen_type_die before we call new_die. See below also. */
8984 #ifdef MIPS_DEBUGGING_INFO
8985 gen_type_die (TREE_TYPE (type), context_die);
8986 #endif
8988 array_die = new_die (DW_TAG_array_type, scope_die);
8990 #if 0
8991 /* We default the array ordering. SDB will probably do
8992 the right things even if DW_AT_ordering is not present. It's not even
8993 an issue until we start to get into multidimensional arrays anyway. If
8994 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
8995 then we'll have to put the DW_AT_ordering attribute back in. (But if
8996 and when we find out that we need to put these in, we will only do so
8997 for multidimensional arrays. */
8998 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
8999 #endif
9001 #ifdef MIPS_DEBUGGING_INFO
9002 /* The SGI compilers handle arrays of unknown bound by setting
9003 AT_declaration and not emitting any subrange DIEs. */
9004 if (! TYPE_DOMAIN (type))
9005 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9006 else
9007 #endif
9008 add_subscript_info (array_die, type);
9010 add_name_attribute (array_die, type_tag (type));
9011 equate_type_number_to_die (type, array_die);
9013 /* Add representation of the type of the elements of this array type. */
9014 element_type = TREE_TYPE (type);
9016 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9017 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9018 We work around this by disabling this feature. See also
9019 add_subscript_info. */
9020 #ifndef MIPS_DEBUGGING_INFO
9021 while (TREE_CODE (element_type) == ARRAY_TYPE)
9022 element_type = TREE_TYPE (element_type);
9024 gen_type_die (element_type, context_die);
9025 #endif
9027 add_type_attribute (array_die, element_type, 0, 0, context_die);
9030 static void
9031 gen_set_type_die (type, context_die)
9032 register tree type;
9033 register dw_die_ref context_die;
9035 register dw_die_ref type_die
9036 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9038 equate_type_number_to_die (type, type_die);
9039 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9042 #if 0
9043 static void
9044 gen_entry_point_die (decl, context_die)
9045 register tree decl;
9046 register dw_die_ref context_die;
9048 register tree origin = decl_ultimate_origin (decl);
9049 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9050 if (origin != NULL)
9051 add_abstract_origin_attribute (decl_die, origin);
9052 else
9054 add_name_and_src_coords_attributes (decl_die, decl);
9055 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9056 0, 0, context_die);
9059 if (DECL_ABSTRACT (decl))
9060 equate_decl_number_to_die (decl, decl_die);
9061 else
9062 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9064 #endif
9066 /* Remember a type in the incomplete_types_list. */
9067 static void
9068 add_incomplete_type (type)
9069 tree type;
9071 VARRAY_PUSH_TREE (incomplete_types, type);
9074 /* Walk through the list of incomplete types again, trying once more to
9075 emit full debugging info for them. */
9077 static void
9078 retry_incomplete_types ()
9080 int i;
9081 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
9083 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
9087 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9089 static void
9090 gen_inlined_enumeration_type_die (type, context_die)
9091 register tree type;
9092 register dw_die_ref context_die;
9094 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9095 context_die);
9096 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9097 be incomplete and such types are not marked. */
9098 add_abstract_origin_attribute (type_die, type);
9101 /* Generate a DIE to represent an inlined instance of a structure type. */
9103 static void
9104 gen_inlined_structure_type_die (type, context_die)
9105 register tree type;
9106 register dw_die_ref context_die;
9108 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9110 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9111 be incomplete and such types are not marked. */
9112 add_abstract_origin_attribute (type_die, type);
9115 /* Generate a DIE to represent an inlined instance of a union type. */
9117 static void
9118 gen_inlined_union_type_die (type, context_die)
9119 register tree type;
9120 register dw_die_ref context_die;
9122 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9124 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9125 be incomplete and such types are not marked. */
9126 add_abstract_origin_attribute (type_die, type);
9129 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9130 include all of the information about the enumeration values also. Each
9131 enumerated type name/value is listed as a child of the enumerated type
9132 DIE. */
9134 static void
9135 gen_enumeration_type_die (type, context_die)
9136 register tree type;
9137 register dw_die_ref context_die;
9139 register dw_die_ref type_die = lookup_type_die (type);
9141 if (type_die == NULL)
9143 type_die = new_die (DW_TAG_enumeration_type,
9144 scope_die_for (type, context_die));
9145 equate_type_number_to_die (type, type_die);
9146 add_name_attribute (type_die, type_tag (type));
9148 else if (! TYPE_SIZE (type))
9149 return;
9150 else
9151 remove_AT (type_die, DW_AT_declaration);
9153 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9154 given enum type is incomplete, do not generate the DW_AT_byte_size
9155 attribute or the DW_AT_element_list attribute. */
9156 if (TYPE_SIZE (type))
9158 register tree link;
9160 TREE_ASM_WRITTEN (type) = 1;
9161 add_byte_size_attribute (type_die, type);
9162 if (TYPE_STUB_DECL (type) != NULL_TREE)
9163 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9165 /* If the first reference to this type was as the return type of an
9166 inline function, then it may not have a parent. Fix this now. */
9167 if (type_die->die_parent == NULL)
9168 add_child_die (scope_die_for (type, context_die), type_die);
9170 for (link = TYPE_FIELDS (type);
9171 link != NULL; link = TREE_CHAIN (link))
9173 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9175 add_name_attribute (enum_die,
9176 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9178 if (host_integerp (TREE_VALUE (link), 0))
9180 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9181 add_AT_int (enum_die, DW_AT_const_value,
9182 tree_low_cst (TREE_VALUE (link), 0));
9183 else
9184 add_AT_unsigned (enum_die, DW_AT_const_value,
9185 tree_low_cst (TREE_VALUE (link), 0));
9189 else
9190 add_AT_flag (type_die, DW_AT_declaration, 1);
9193 /* Generate a DIE to represent either a real live formal parameter decl or to
9194 represent just the type of some formal parameter position in some function
9195 type.
9197 Note that this routine is a bit unusual because its argument may be a
9198 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9199 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9200 node. If it's the former then this function is being called to output a
9201 DIE to represent a formal parameter object (or some inlining thereof). If
9202 it's the latter, then this function is only being called to output a
9203 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9204 argument type of some subprogram type. */
9206 static dw_die_ref
9207 gen_formal_parameter_die (node, context_die)
9208 register tree node;
9209 register dw_die_ref context_die;
9211 register dw_die_ref parm_die
9212 = new_die (DW_TAG_formal_parameter, context_die);
9213 register tree origin;
9215 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9217 case 'd':
9218 origin = decl_ultimate_origin (node);
9219 if (origin != NULL)
9220 add_abstract_origin_attribute (parm_die, origin);
9221 else
9223 add_name_and_src_coords_attributes (parm_die, node);
9224 add_type_attribute (parm_die, TREE_TYPE (node),
9225 TREE_READONLY (node),
9226 TREE_THIS_VOLATILE (node),
9227 context_die);
9228 if (DECL_ARTIFICIAL (node))
9229 add_AT_flag (parm_die, DW_AT_artificial, 1);
9232 equate_decl_number_to_die (node, parm_die);
9233 if (! DECL_ABSTRACT (node))
9234 add_location_or_const_value_attribute (parm_die, node);
9236 break;
9238 case 't':
9239 /* We were called with some kind of a ..._TYPE node. */
9240 add_type_attribute (parm_die, node, 0, 0, context_die);
9241 break;
9243 default:
9244 abort ();
9247 return parm_die;
9250 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9251 at the end of an (ANSI prototyped) formal parameters list. */
9253 static void
9254 gen_unspecified_parameters_die (decl_or_type, context_die)
9255 register tree decl_or_type ATTRIBUTE_UNUSED;
9256 register dw_die_ref context_die;
9258 new_die (DW_TAG_unspecified_parameters, context_die);
9261 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9262 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9263 parameters as specified in some function type specification (except for
9264 those which appear as part of a function *definition*). */
9266 static void
9267 gen_formal_types_die (function_or_method_type, context_die)
9268 register tree function_or_method_type;
9269 register dw_die_ref context_die;
9271 register tree link;
9272 register tree formal_type = NULL;
9273 register tree first_parm_type;
9274 tree arg;
9276 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9278 arg = DECL_ARGUMENTS (function_or_method_type);
9279 function_or_method_type = TREE_TYPE (function_or_method_type);
9281 else
9282 arg = NULL_TREE;
9284 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9286 /* Make our first pass over the list of formal parameter types and output a
9287 DW_TAG_formal_parameter DIE for each one. */
9288 for (link = first_parm_type; link; )
9290 register dw_die_ref parm_die;
9292 formal_type = TREE_VALUE (link);
9293 if (formal_type == void_type_node)
9294 break;
9296 /* Output a (nameless) DIE to represent the formal parameter itself. */
9297 parm_die = gen_formal_parameter_die (formal_type, context_die);
9298 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9299 && link == first_parm_type)
9300 || (arg && DECL_ARTIFICIAL (arg)))
9301 add_AT_flag (parm_die, DW_AT_artificial, 1);
9303 link = TREE_CHAIN (link);
9304 if (arg)
9305 arg = TREE_CHAIN (arg);
9308 /* If this function type has an ellipsis, add a
9309 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9310 if (formal_type != void_type_node)
9311 gen_unspecified_parameters_die (function_or_method_type, context_die);
9313 /* Make our second (and final) pass over the list of formal parameter types
9314 and output DIEs to represent those types (as necessary). */
9315 for (link = TYPE_ARG_TYPES (function_or_method_type);
9316 link;
9317 link = TREE_CHAIN (link))
9319 formal_type = TREE_VALUE (link);
9320 if (formal_type == void_type_node)
9321 break;
9323 gen_type_die (formal_type, context_die);
9327 /* We want to generate the DIE for TYPE so that we can generate the
9328 die for MEMBER, which has been defined; we will need to refer back
9329 to the member declaration nested within TYPE. If we're trying to
9330 generate minimal debug info for TYPE, processing TYPE won't do the
9331 trick; we need to attach the member declaration by hand. */
9333 static void
9334 gen_type_die_for_member (type, member, context_die)
9335 tree type, member;
9336 dw_die_ref context_die;
9338 gen_type_die (type, context_die);
9340 /* If we're trying to avoid duplicate debug info, we may not have
9341 emitted the member decl for this function. Emit it now. */
9342 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9343 && ! lookup_decl_die (member))
9345 if (decl_ultimate_origin (member))
9346 abort ();
9348 push_decl_scope (type);
9349 if (TREE_CODE (member) == FUNCTION_DECL)
9350 gen_subprogram_die (member, lookup_type_die (type));
9351 else
9352 gen_variable_die (member, lookup_type_die (type));
9353 pop_decl_scope ();
9357 /* Generate the DWARF2 info for the "abstract" instance
9358 of a function which we may later generate inlined and/or
9359 out-of-line instances of. */
9361 void
9362 dwarf2out_abstract_function (decl)
9363 tree decl;
9365 register dw_die_ref old_die;
9366 tree save_fn;
9367 tree context;
9368 int was_abstract = DECL_ABSTRACT (decl);
9370 /* Make sure we have the actual abstract inline, not a clone. */
9371 decl = DECL_ORIGIN (decl);
9373 old_die = lookup_decl_die (decl);
9374 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9375 /* We've already generated the abstract instance. */
9376 return;
9378 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9379 we don't get confused by DECL_ABSTRACT. */
9380 if (debug_info_level > DINFO_LEVEL_TERSE)
9382 context = decl_class_context (decl);
9383 if (context)
9384 gen_type_die_for_member
9385 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9388 /* Pretend we've just finished compiling this function. */
9389 save_fn = current_function_decl;
9390 current_function_decl = decl;
9392 set_decl_abstract_flags (decl, 1);
9393 dwarf2out_decl (decl);
9394 if (! was_abstract)
9395 set_decl_abstract_flags (decl, 0);
9397 current_function_decl = save_fn;
9400 /* Generate a DIE to represent a declared function (either file-scope or
9401 block-local). */
9403 static void
9404 gen_subprogram_die (decl, context_die)
9405 register tree decl;
9406 register dw_die_ref context_die;
9408 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9409 register tree origin = decl_ultimate_origin (decl);
9410 register dw_die_ref subr_die;
9411 register rtx fp_reg;
9412 register tree fn_arg_types;
9413 register tree outer_scope;
9414 register dw_die_ref old_die = lookup_decl_die (decl);
9415 register int declaration = (current_function_decl != decl
9416 || class_scope_p (context_die));
9418 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9419 be true, if we started to generate the abstract instance of an inline,
9420 decided to output its containing class, and proceeded to emit the
9421 declaration of the inline from the member list for the class. In that
9422 case, `declaration' takes priority; we'll get back to the abstract
9423 instance when we're done with the class. */
9425 /* The class-scope declaration DIE must be the primary DIE. */
9426 if (origin && declaration && class_scope_p (context_die))
9428 origin = NULL;
9429 if (old_die)
9430 abort ();
9433 if (origin != NULL)
9435 if (declaration && ! local_scope_p (context_die))
9436 abort ();
9438 /* Fixup die_parent for the abstract instance of a nested
9439 inline function. */
9440 if (old_die && old_die->die_parent == NULL)
9441 add_child_die (context_die, old_die);
9443 subr_die = new_die (DW_TAG_subprogram, context_die);
9444 add_abstract_origin_attribute (subr_die, origin);
9446 else if (old_die)
9448 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9450 if (!get_AT_flag (old_die, DW_AT_declaration)
9451 /* We can have a normal definition following an inline one in the
9452 case of redefinition of GNU C extern inlines.
9453 It seems reasonable to use AT_specification in this case. */
9454 && !get_AT_unsigned (old_die, DW_AT_inline))
9456 /* ??? This can happen if there is a bug in the program, for
9457 instance, if it has duplicate function definitions. Ideally,
9458 we should detect this case and ignore it. For now, if we have
9459 already reported an error, any error at all, then assume that
9460 we got here because of a input error, not a dwarf2 bug. */
9461 if (errorcount)
9462 return;
9463 abort ();
9466 /* If the definition comes from the same place as the declaration,
9467 maybe use the old DIE. We always want the DIE for this function
9468 that has the *_pc attributes to be under comp_unit_die so the
9469 debugger can find it. We also need to do this for abstract
9470 instances of inlines, since the spec requires the out-of-line copy
9471 to have the same parent. For local class methods, this doesn't
9472 apply; we just use the old DIE. */
9473 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9474 && (DECL_ARTIFICIAL (decl)
9475 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9476 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9477 == (unsigned) DECL_SOURCE_LINE (decl)))))
9479 subr_die = old_die;
9481 /* Clear out the declaration attribute and the parm types. */
9482 remove_AT (subr_die, DW_AT_declaration);
9483 remove_children (subr_die);
9485 else
9487 subr_die = new_die (DW_TAG_subprogram, context_die);
9488 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9489 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9490 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9491 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9492 != (unsigned) DECL_SOURCE_LINE (decl))
9493 add_AT_unsigned
9494 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9497 else
9499 subr_die = new_die (DW_TAG_subprogram, context_die);
9501 if (TREE_PUBLIC (decl))
9502 add_AT_flag (subr_die, DW_AT_external, 1);
9504 add_name_and_src_coords_attributes (subr_die, decl);
9505 if (debug_info_level > DINFO_LEVEL_TERSE)
9507 register tree type = TREE_TYPE (decl);
9509 add_prototyped_attribute (subr_die, type);
9510 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9513 add_pure_or_virtual_attribute (subr_die, decl);
9514 if (DECL_ARTIFICIAL (decl))
9515 add_AT_flag (subr_die, DW_AT_artificial, 1);
9516 if (TREE_PROTECTED (decl))
9517 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9518 else if (TREE_PRIVATE (decl))
9519 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9522 if (declaration)
9524 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9526 add_AT_flag (subr_die, DW_AT_declaration, 1);
9528 /* The first time we see a member function, it is in the context of
9529 the class to which it belongs. We make sure of this by emitting
9530 the class first. The next time is the definition, which is
9531 handled above. The two may come from the same source text. */
9532 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9533 equate_decl_number_to_die (decl, subr_die);
9536 else if (DECL_ABSTRACT (decl))
9538 if (DECL_INLINE (decl) && !flag_no_inline)
9540 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9541 inline functions, but not for extern inline functions.
9542 We can't get this completely correct because information
9543 about whether the function was declared inline is not
9544 saved anywhere. */
9545 if (DECL_DEFER_OUTPUT (decl))
9546 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9547 else
9548 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9550 else
9551 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9553 equate_decl_number_to_die (decl, subr_die);
9555 else if (!DECL_EXTERNAL (decl))
9557 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9558 equate_decl_number_to_die (decl, subr_die);
9560 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9561 current_funcdef_number);
9562 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9563 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9564 current_funcdef_number);
9565 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9567 add_pubname (decl, subr_die);
9568 add_arange (decl, subr_die);
9570 #ifdef MIPS_DEBUGGING_INFO
9571 /* Add a reference to the FDE for this routine. */
9572 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9573 #endif
9575 /* Define the "frame base" location for this routine. We use the
9576 frame pointer or stack pointer registers, since the RTL for local
9577 variables is relative to one of them. */
9578 fp_reg
9579 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9580 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9582 #if 0
9583 /* ??? This fails for nested inline functions, because context_display
9584 is not part of the state saved/restored for inline functions. */
9585 if (current_function_needs_context)
9586 add_AT_location_description (subr_die, DW_AT_static_link,
9587 lookup_static_chain (decl));
9588 #endif
9591 /* Now output descriptions of the arguments for this function. This gets
9592 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9593 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9594 `...' at the end of the formal parameter list. In order to find out if
9595 there was a trailing ellipsis or not, we must instead look at the type
9596 associated with the FUNCTION_DECL. This will be a node of type
9597 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9598 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9599 an ellipsis at the end. */
9601 /* In the case where we are describing a mere function declaration, all we
9602 need to do here (and all we *can* do here) is to describe the *types* of
9603 its formal parameters. */
9604 if (debug_info_level <= DINFO_LEVEL_TERSE)
9606 else if (declaration)
9607 gen_formal_types_die (decl, subr_die);
9608 else
9610 /* Generate DIEs to represent all known formal parameters */
9611 register tree arg_decls = DECL_ARGUMENTS (decl);
9612 register tree parm;
9614 /* When generating DIEs, generate the unspecified_parameters DIE
9615 instead if we come across the arg "__builtin_va_alist" */
9616 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9617 if (TREE_CODE (parm) == PARM_DECL)
9619 if (DECL_NAME (parm)
9620 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9621 "__builtin_va_alist"))
9622 gen_unspecified_parameters_die (parm, subr_die);
9623 else
9624 gen_decl_die (parm, subr_die);
9627 /* Decide whether we need a unspecified_parameters DIE at the end.
9628 There are 2 more cases to do this for: 1) the ansi ... declaration -
9629 this is detectable when the end of the arg list is not a
9630 void_type_node 2) an unprototyped function declaration (not a
9631 definition). This just means that we have no info about the
9632 parameters at all. */
9633 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9634 if (fn_arg_types != NULL)
9636 /* this is the prototyped case, check for ... */
9637 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9638 gen_unspecified_parameters_die (decl, subr_die);
9640 else if (DECL_INITIAL (decl) == NULL_TREE)
9641 gen_unspecified_parameters_die (decl, subr_die);
9644 /* Output Dwarf info for all of the stuff within the body of the function
9645 (if it has one - it may be just a declaration). */
9646 outer_scope = DECL_INITIAL (decl);
9648 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9649 node created to represent a function. This outermost BLOCK actually
9650 represents the outermost binding contour for the function, i.e. the
9651 contour in which the function's formal parameters and labels get
9652 declared. Curiously, it appears that the front end doesn't actually
9653 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9654 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9655 list for the function instead.) The BLOCK_VARS list for the
9656 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9657 the function however, and we output DWARF info for those in
9658 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9659 node representing the function's outermost pair of curly braces, and
9660 any blocks used for the base and member initializers of a C++
9661 constructor function. */
9662 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9664 current_function_has_inlines = 0;
9665 decls_for_scope (outer_scope, subr_die, 0);
9667 #if 0 && defined (MIPS_DEBUGGING_INFO)
9668 if (current_function_has_inlines)
9670 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9671 if (! comp_unit_has_inlines)
9673 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9674 comp_unit_has_inlines = 1;
9677 #endif
9681 /* Generate a DIE to represent a declared data object. */
9683 static void
9684 gen_variable_die (decl, context_die)
9685 register tree decl;
9686 register dw_die_ref context_die;
9688 register tree origin = decl_ultimate_origin (decl);
9689 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9691 dw_die_ref old_die = lookup_decl_die (decl);
9692 int declaration = (DECL_EXTERNAL (decl)
9693 || class_scope_p (context_die));
9695 if (origin != NULL)
9696 add_abstract_origin_attribute (var_die, origin);
9697 /* Loop unrolling can create multiple blocks that refer to the same
9698 static variable, so we must test for the DW_AT_declaration flag. */
9699 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9700 copy decls and set the DECL_ABSTRACT flag on them instead of
9701 sharing them. */
9702 else if (old_die && TREE_STATIC (decl)
9703 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9705 /* This is a definition of a C++ class level static. */
9706 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9707 if (DECL_NAME (decl))
9709 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9711 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9712 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9714 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9715 != (unsigned) DECL_SOURCE_LINE (decl))
9717 add_AT_unsigned (var_die, DW_AT_decl_line,
9718 DECL_SOURCE_LINE (decl));
9721 else
9723 add_name_and_src_coords_attributes (var_die, decl);
9724 add_type_attribute (var_die, TREE_TYPE (decl),
9725 TREE_READONLY (decl),
9726 TREE_THIS_VOLATILE (decl), context_die);
9728 if (TREE_PUBLIC (decl))
9729 add_AT_flag (var_die, DW_AT_external, 1);
9731 if (DECL_ARTIFICIAL (decl))
9732 add_AT_flag (var_die, DW_AT_artificial, 1);
9734 if (TREE_PROTECTED (decl))
9735 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9737 else if (TREE_PRIVATE (decl))
9738 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9741 if (declaration)
9742 add_AT_flag (var_die, DW_AT_declaration, 1);
9744 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9745 equate_decl_number_to_die (decl, var_die);
9747 if (! declaration && ! DECL_ABSTRACT (decl))
9749 add_location_or_const_value_attribute (var_die, decl);
9750 add_pubname (decl, var_die);
9752 else
9753 tree_add_const_value_attribute (var_die, decl);
9756 /* Generate a DIE to represent a label identifier. */
9758 static void
9759 gen_label_die (decl, context_die)
9760 register tree decl;
9761 register dw_die_ref context_die;
9763 register tree origin = decl_ultimate_origin (decl);
9764 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
9765 register rtx insn;
9766 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9768 if (origin != NULL)
9769 add_abstract_origin_attribute (lbl_die, origin);
9770 else
9771 add_name_and_src_coords_attributes (lbl_die, decl);
9773 if (DECL_ABSTRACT (decl))
9774 equate_decl_number_to_die (decl, lbl_die);
9775 else
9777 insn = DECL_RTL (decl);
9779 /* Deleted labels are programmer specified labels which have been
9780 eliminated because of various optimisations. We still emit them
9781 here so that it is possible to put breakpoints on them. */
9782 if (GET_CODE (insn) == CODE_LABEL
9783 || ((GET_CODE (insn) == NOTE
9784 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
9786 /* When optimization is enabled (via -O) some parts of the compiler
9787 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
9788 represent source-level labels which were explicitly declared by
9789 the user. This really shouldn't be happening though, so catch
9790 it if it ever does happen. */
9791 if (INSN_DELETED_P (insn))
9792 abort ();
9794 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
9795 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
9800 /* Generate a DIE for a lexical block. */
9802 static void
9803 gen_lexical_block_die (stmt, context_die, depth)
9804 register tree stmt;
9805 register dw_die_ref context_die;
9806 int depth;
9808 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
9809 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9811 if (! BLOCK_ABSTRACT (stmt))
9813 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9814 BLOCK_NUMBER (stmt));
9815 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
9816 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9817 BLOCK_NUMBER (stmt));
9818 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
9821 decls_for_scope (stmt, stmt_die, depth);
9824 /* Generate a DIE for an inlined subprogram. */
9826 static void
9827 gen_inlined_subroutine_die (stmt, context_die, depth)
9828 register tree stmt;
9829 register dw_die_ref context_die;
9830 int depth;
9832 if (! BLOCK_ABSTRACT (stmt))
9834 register dw_die_ref subr_die
9835 = new_die (DW_TAG_inlined_subroutine, context_die);
9836 register tree decl = block_ultimate_origin (stmt);
9837 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9839 /* Emit info for the abstract instance first, if we haven't yet. */
9840 dwarf2out_abstract_function (decl);
9842 add_abstract_origin_attribute (subr_die, decl);
9843 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9844 BLOCK_NUMBER (stmt));
9845 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
9846 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9847 BLOCK_NUMBER (stmt));
9848 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
9849 decls_for_scope (stmt, subr_die, depth);
9850 current_function_has_inlines = 1;
9854 /* Generate a DIE for a field in a record, or structure. */
9856 static void
9857 gen_field_die (decl, context_die)
9858 register tree decl;
9859 register dw_die_ref context_die;
9861 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
9863 add_name_and_src_coords_attributes (decl_die, decl);
9864 add_type_attribute (decl_die, member_declared_type (decl),
9865 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
9866 context_die);
9868 /* If this is a bit field... */
9869 if (DECL_BIT_FIELD_TYPE (decl))
9871 add_byte_size_attribute (decl_die, decl);
9872 add_bit_size_attribute (decl_die, decl);
9873 add_bit_offset_attribute (decl_die, decl);
9876 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
9877 add_data_member_location_attribute (decl_die, decl);
9879 if (DECL_ARTIFICIAL (decl))
9880 add_AT_flag (decl_die, DW_AT_artificial, 1);
9882 if (TREE_PROTECTED (decl))
9883 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
9885 else if (TREE_PRIVATE (decl))
9886 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
9889 #if 0
9890 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9891 Use modified_type_die instead.
9892 We keep this code here just in case these types of DIEs may be needed to
9893 represent certain things in other languages (e.g. Pascal) someday. */
9894 static void
9895 gen_pointer_type_die (type, context_die)
9896 register tree type;
9897 register dw_die_ref context_die;
9899 register dw_die_ref ptr_die
9900 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
9902 equate_type_number_to_die (type, ptr_die);
9903 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9904 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9907 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9908 Use modified_type_die instead.
9909 We keep this code here just in case these types of DIEs may be needed to
9910 represent certain things in other languages (e.g. Pascal) someday. */
9911 static void
9912 gen_reference_type_die (type, context_die)
9913 register tree type;
9914 register dw_die_ref context_die;
9916 register dw_die_ref ref_die
9917 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
9919 equate_type_number_to_die (type, ref_die);
9920 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
9921 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9923 #endif
9925 /* Generate a DIE for a pointer to a member type. */
9926 static void
9927 gen_ptr_to_mbr_type_die (type, context_die)
9928 register tree type;
9929 register dw_die_ref context_die;
9931 register dw_die_ref ptr_die
9932 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
9934 equate_type_number_to_die (type, ptr_die);
9935 add_AT_die_ref (ptr_die, DW_AT_containing_type,
9936 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
9937 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9940 /* Generate the DIE for the compilation unit. */
9942 static dw_die_ref
9943 gen_compile_unit_die (filename)
9944 register const char *filename;
9946 register dw_die_ref die;
9947 char producer[250];
9948 const char *wd = getpwd ();
9949 int language;
9951 die = new_die (DW_TAG_compile_unit, NULL);
9952 add_name_attribute (die, filename);
9954 if (wd != NULL && filename[0] != DIR_SEPARATOR)
9955 add_AT_string (die, DW_AT_comp_dir, wd);
9957 sprintf (producer, "%s %s", language_string, version_string);
9959 #ifdef MIPS_DEBUGGING_INFO
9960 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
9961 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
9962 not appear in the producer string, the debugger reaches the conclusion
9963 that the object file is stripped and has no debugging information.
9964 To get the MIPS/SGI debugger to believe that there is debugging
9965 information in the object file, we add a -g to the producer string. */
9966 if (debug_info_level > DINFO_LEVEL_TERSE)
9967 strcat (producer, " -g");
9968 #endif
9970 add_AT_string (die, DW_AT_producer, producer);
9972 if (strcmp (language_string, "GNU C++") == 0)
9973 language = DW_LANG_C_plus_plus;
9974 else if (strcmp (language_string, "GNU Ada") == 0)
9975 language = DW_LANG_Ada83;
9976 else if (strcmp (language_string, "GNU F77") == 0)
9977 language = DW_LANG_Fortran77;
9978 else if (strcmp (language_string, "GNU Pascal") == 0)
9979 language = DW_LANG_Pascal83;
9980 else if (strcmp (language_string, "GNU Java") == 0)
9981 language = DW_LANG_Java;
9982 else if (flag_traditional)
9983 language = DW_LANG_C;
9984 else
9985 language = DW_LANG_C89;
9987 add_AT_unsigned (die, DW_AT_language, language);
9989 return die;
9992 /* Generate a DIE for a string type. */
9994 static void
9995 gen_string_type_die (type, context_die)
9996 register tree type;
9997 register dw_die_ref context_die;
9999 register dw_die_ref type_die
10000 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10002 equate_type_number_to_die (type, type_die);
10004 /* Fudge the string length attribute for now. */
10006 /* TODO: add string length info.
10007 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10008 bound_representation (upper_bound, 0, 'u'); */
10011 /* Generate the DIE for a base class. */
10013 static void
10014 gen_inheritance_die (binfo, context_die)
10015 register tree binfo;
10016 register dw_die_ref context_die;
10018 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10020 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10021 add_data_member_location_attribute (die, binfo);
10023 if (TREE_VIA_VIRTUAL (binfo))
10024 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10025 if (TREE_VIA_PUBLIC (binfo))
10026 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10027 else if (TREE_VIA_PROTECTED (binfo))
10028 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10031 /* Generate a DIE for a class member. */
10033 static void
10034 gen_member_die (type, context_die)
10035 register tree type;
10036 register dw_die_ref context_die;
10038 register tree member;
10039 dw_die_ref child;
10041 /* If this is not an incomplete type, output descriptions of each of its
10042 members. Note that as we output the DIEs necessary to represent the
10043 members of this record or union type, we will also be trying to output
10044 DIEs to represent the *types* of those members. However the `type'
10045 function (above) will specifically avoid generating type DIEs for member
10046 types *within* the list of member DIEs for this (containing) type execpt
10047 for those types (of members) which are explicitly marked as also being
10048 members of this (containing) type themselves. The g++ front- end can
10049 force any given type to be treated as a member of some other
10050 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10051 to point to the TREE node representing the appropriate (containing)
10052 type. */
10054 /* First output info about the base classes. */
10055 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10057 register tree bases = TYPE_BINFO_BASETYPES (type);
10058 register int n_bases = TREE_VEC_LENGTH (bases);
10059 register int i;
10061 for (i = 0; i < n_bases; i++)
10062 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10065 /* Now output info about the data members and type members. */
10066 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10068 /* If we thought we were generating minimal debug info for TYPE
10069 and then changed our minds, some of the member declarations
10070 may have already been defined. Don't define them again, but
10071 do put them in the right order. */
10073 child = lookup_decl_die (member);
10074 if (child)
10075 splice_child_die (context_die, child);
10076 else
10077 gen_decl_die (member, context_die);
10080 /* Now output info about the function members (if any). */
10081 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10083 /* Don't include clones in the member list. */
10084 if (DECL_ABSTRACT_ORIGIN (member))
10085 continue;
10087 child = lookup_decl_die (member);
10088 if (child)
10089 splice_child_die (context_die, child);
10090 else
10091 gen_decl_die (member, context_die);
10095 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10096 is set, we pretend that the type was never defined, so we only get the
10097 member DIEs needed by later specification DIEs. */
10099 static void
10100 gen_struct_or_union_type_die (type, context_die)
10101 register tree type;
10102 register dw_die_ref context_die;
10104 register dw_die_ref type_die = lookup_type_die (type);
10105 register dw_die_ref scope_die = 0;
10106 register int nested = 0;
10107 int complete = (TYPE_SIZE (type)
10108 && (! TYPE_STUB_DECL (type)
10109 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10111 if (type_die && ! complete)
10112 return;
10114 if (TYPE_CONTEXT (type) != NULL_TREE
10115 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10116 nested = 1;
10118 scope_die = scope_die_for (type, context_die);
10120 if (! type_die || (nested && scope_die == comp_unit_die))
10121 /* First occurrence of type or toplevel definition of nested class. */
10123 register dw_die_ref old_die = type_die;
10125 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10126 ? DW_TAG_structure_type : DW_TAG_union_type,
10127 scope_die);
10128 equate_type_number_to_die (type, type_die);
10129 if (old_die)
10130 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10131 else
10132 add_name_attribute (type_die, type_tag (type));
10134 else
10135 remove_AT (type_die, DW_AT_declaration);
10137 /* If this type has been completed, then give it a byte_size attribute and
10138 then give a list of members. */
10139 if (complete)
10141 /* Prevent infinite recursion in cases where the type of some member of
10142 this type is expressed in terms of this type itself. */
10143 TREE_ASM_WRITTEN (type) = 1;
10144 add_byte_size_attribute (type_die, type);
10145 if (TYPE_STUB_DECL (type) != NULL_TREE)
10146 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10148 /* If the first reference to this type was as the return type of an
10149 inline function, then it may not have a parent. Fix this now. */
10150 if (type_die->die_parent == NULL)
10151 add_child_die (scope_die, type_die);
10153 push_decl_scope (type);
10154 gen_member_die (type, type_die);
10155 pop_decl_scope ();
10157 /* GNU extension: Record what type our vtable lives in. */
10158 if (TYPE_VFIELD (type))
10160 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10162 gen_type_die (vtype, context_die);
10163 add_AT_die_ref (type_die, DW_AT_containing_type,
10164 lookup_type_die (vtype));
10167 else
10169 add_AT_flag (type_die, DW_AT_declaration, 1);
10171 /* We don't need to do this for function-local types. */
10172 if (! decl_function_context (TYPE_STUB_DECL (type)))
10173 add_incomplete_type (type);
10177 /* Generate a DIE for a subroutine _type_. */
10179 static void
10180 gen_subroutine_type_die (type, context_die)
10181 register tree type;
10182 register dw_die_ref context_die;
10184 register tree return_type = TREE_TYPE (type);
10185 register dw_die_ref subr_die
10186 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10188 equate_type_number_to_die (type, subr_die);
10189 add_prototyped_attribute (subr_die, type);
10190 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10191 gen_formal_types_die (type, subr_die);
10194 /* Generate a DIE for a type definition */
10196 static void
10197 gen_typedef_die (decl, context_die)
10198 register tree decl;
10199 register dw_die_ref context_die;
10201 register dw_die_ref type_die;
10202 register tree origin;
10204 if (TREE_ASM_WRITTEN (decl))
10205 return;
10206 TREE_ASM_WRITTEN (decl) = 1;
10208 type_die = new_die (DW_TAG_typedef, context_die);
10209 origin = decl_ultimate_origin (decl);
10210 if (origin != NULL)
10211 add_abstract_origin_attribute (type_die, origin);
10212 else
10214 register tree type;
10215 add_name_and_src_coords_attributes (type_die, decl);
10216 if (DECL_ORIGINAL_TYPE (decl))
10218 type = DECL_ORIGINAL_TYPE (decl);
10220 if (type == TREE_TYPE (decl))
10221 abort ();
10222 else
10223 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10225 else
10226 type = TREE_TYPE (decl);
10227 add_type_attribute (type_die, type, TREE_READONLY (decl),
10228 TREE_THIS_VOLATILE (decl), context_die);
10231 if (DECL_ABSTRACT (decl))
10232 equate_decl_number_to_die (decl, type_die);
10235 /* Generate a type description DIE. */
10237 static void
10238 gen_type_die (type, context_die)
10239 register tree type;
10240 register dw_die_ref context_die;
10242 int need_pop;
10244 if (type == NULL_TREE || type == error_mark_node)
10245 return;
10247 /* We are going to output a DIE to represent the unqualified version of
10248 this type (i.e. without any const or volatile qualifiers) so get the
10249 main variant (i.e. the unqualified version) of this type now. */
10250 type = type_main_variant (type);
10252 if (TREE_ASM_WRITTEN (type))
10253 return;
10255 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10256 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10258 TREE_ASM_WRITTEN (type) = 1;
10259 gen_decl_die (TYPE_NAME (type), context_die);
10260 return;
10263 switch (TREE_CODE (type))
10265 case ERROR_MARK:
10266 break;
10268 case POINTER_TYPE:
10269 case REFERENCE_TYPE:
10270 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10271 ensures that the gen_type_die recursion will terminate even if the
10272 type is recursive. Recursive types are possible in Ada. */
10273 /* ??? We could perhaps do this for all types before the switch
10274 statement. */
10275 TREE_ASM_WRITTEN (type) = 1;
10277 /* For these types, all that is required is that we output a DIE (or a
10278 set of DIEs) to represent the "basis" type. */
10279 gen_type_die (TREE_TYPE (type), context_die);
10280 break;
10282 case OFFSET_TYPE:
10283 /* This code is used for C++ pointer-to-data-member types.
10284 Output a description of the relevant class type. */
10285 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10287 /* Output a description of the type of the object pointed to. */
10288 gen_type_die (TREE_TYPE (type), context_die);
10290 /* Now output a DIE to represent this pointer-to-data-member type
10291 itself. */
10292 gen_ptr_to_mbr_type_die (type, context_die);
10293 break;
10295 case SET_TYPE:
10296 gen_type_die (TYPE_DOMAIN (type), context_die);
10297 gen_set_type_die (type, context_die);
10298 break;
10300 case FILE_TYPE:
10301 gen_type_die (TREE_TYPE (type), context_die);
10302 abort (); /* No way to represent these in Dwarf yet! */
10303 break;
10305 case FUNCTION_TYPE:
10306 /* Force out return type (in case it wasn't forced out already). */
10307 gen_type_die (TREE_TYPE (type), context_die);
10308 gen_subroutine_type_die (type, context_die);
10309 break;
10311 case METHOD_TYPE:
10312 /* Force out return type (in case it wasn't forced out already). */
10313 gen_type_die (TREE_TYPE (type), context_die);
10314 gen_subroutine_type_die (type, context_die);
10315 break;
10317 case ARRAY_TYPE:
10318 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10320 gen_type_die (TREE_TYPE (type), context_die);
10321 gen_string_type_die (type, context_die);
10323 else
10324 gen_array_type_die (type, context_die);
10325 break;
10327 case VECTOR_TYPE:
10328 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10329 break;
10331 case ENUMERAL_TYPE:
10332 case RECORD_TYPE:
10333 case UNION_TYPE:
10334 case QUAL_UNION_TYPE:
10335 /* If this is a nested type whose containing class hasn't been
10336 written out yet, writing it out will cover this one, too.
10337 This does not apply to instantiations of member class templates;
10338 they need to be added to the containing class as they are
10339 generated. FIXME: This hurts the idea of combining type decls
10340 from multiple TUs, since we can't predict what set of template
10341 instantiations we'll get. */
10342 if (TYPE_CONTEXT (type)
10343 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10344 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10346 gen_type_die (TYPE_CONTEXT (type), context_die);
10348 if (TREE_ASM_WRITTEN (type))
10349 return;
10351 /* If that failed, attach ourselves to the stub. */
10352 push_decl_scope (TYPE_CONTEXT (type));
10353 context_die = lookup_type_die (TYPE_CONTEXT (type));
10354 need_pop = 1;
10356 else
10357 need_pop = 0;
10359 if (TREE_CODE (type) == ENUMERAL_TYPE)
10360 gen_enumeration_type_die (type, context_die);
10361 else
10362 gen_struct_or_union_type_die (type, context_die);
10364 if (need_pop)
10365 pop_decl_scope ();
10367 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10368 it up if it is ever completed. gen_*_type_die will set it for us
10369 when appropriate. */
10370 return;
10372 case VOID_TYPE:
10373 case INTEGER_TYPE:
10374 case REAL_TYPE:
10375 case COMPLEX_TYPE:
10376 case BOOLEAN_TYPE:
10377 case CHAR_TYPE:
10378 /* No DIEs needed for fundamental types. */
10379 break;
10381 case LANG_TYPE:
10382 /* No Dwarf representation currently defined. */
10383 break;
10385 default:
10386 abort ();
10389 TREE_ASM_WRITTEN (type) = 1;
10392 /* Generate a DIE for a tagged type instantiation. */
10394 static void
10395 gen_tagged_type_instantiation_die (type, context_die)
10396 register tree type;
10397 register dw_die_ref context_die;
10399 if (type == NULL_TREE || type == error_mark_node)
10400 return;
10402 /* We are going to output a DIE to represent the unqualified version of
10403 this type (i.e. without any const or volatile qualifiers) so make sure
10404 that we have the main variant (i.e. the unqualified version) of this
10405 type now. */
10406 if (type != type_main_variant (type))
10407 abort ();
10409 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10410 an instance of an unresolved type. */
10412 switch (TREE_CODE (type))
10414 case ERROR_MARK:
10415 break;
10417 case ENUMERAL_TYPE:
10418 gen_inlined_enumeration_type_die (type, context_die);
10419 break;
10421 case RECORD_TYPE:
10422 gen_inlined_structure_type_die (type, context_die);
10423 break;
10425 case UNION_TYPE:
10426 case QUAL_UNION_TYPE:
10427 gen_inlined_union_type_die (type, context_die);
10428 break;
10430 default:
10431 abort ();
10435 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10436 things which are local to the given block. */
10438 static void
10439 gen_block_die (stmt, context_die, depth)
10440 register tree stmt;
10441 register dw_die_ref context_die;
10442 int depth;
10444 register int must_output_die = 0;
10445 register tree origin;
10446 register tree decl;
10447 register enum tree_code origin_code;
10449 /* Ignore blocks never really used to make RTL. */
10451 if (stmt == NULL_TREE || !TREE_USED (stmt)
10452 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10453 return;
10455 /* Determine the "ultimate origin" of this block. This block may be an
10456 inlined instance of an inlined instance of inline function, so we have
10457 to trace all of the way back through the origin chain to find out what
10458 sort of node actually served as the original seed for the creation of
10459 the current block. */
10460 origin = block_ultimate_origin (stmt);
10461 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10463 /* Determine if we need to output any Dwarf DIEs at all to represent this
10464 block. */
10465 if (origin_code == FUNCTION_DECL)
10466 /* The outer scopes for inlinings *must* always be represented. We
10467 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10468 must_output_die = 1;
10469 else
10471 /* In the case where the current block represents an inlining of the
10472 "body block" of an inline function, we must *NOT* output any DIE for
10473 this block because we have already output a DIE to represent the
10474 whole inlined function scope and the "body block" of any function
10475 doesn't really represent a different scope according to ANSI C
10476 rules. So we check here to make sure that this block does not
10477 represent a "body block inlining" before trying to set the
10478 `must_output_die' flag. */
10479 if (! is_body_block (origin ? origin : stmt))
10481 /* Determine if this block directly contains any "significant"
10482 local declarations which we will need to output DIEs for. */
10483 if (debug_info_level > DINFO_LEVEL_TERSE)
10484 /* We are not in terse mode so *any* local declaration counts
10485 as being a "significant" one. */
10486 must_output_die = (BLOCK_VARS (stmt) != NULL);
10487 else
10488 /* We are in terse mode, so only local (nested) function
10489 definitions count as "significant" local declarations. */
10490 for (decl = BLOCK_VARS (stmt);
10491 decl != NULL; decl = TREE_CHAIN (decl))
10492 if (TREE_CODE (decl) == FUNCTION_DECL
10493 && DECL_INITIAL (decl))
10495 must_output_die = 1;
10496 break;
10501 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10502 DIE for any block which contains no significant local declarations at
10503 all. Rather, in such cases we just call `decls_for_scope' so that any
10504 needed Dwarf info for any sub-blocks will get properly generated. Note
10505 that in terse mode, our definition of what constitutes a "significant"
10506 local declaration gets restricted to include only inlined function
10507 instances and local (nested) function definitions. */
10508 if (must_output_die)
10510 if (origin_code == FUNCTION_DECL)
10511 gen_inlined_subroutine_die (stmt, context_die, depth);
10512 else
10513 gen_lexical_block_die (stmt, context_die, depth);
10515 else
10516 decls_for_scope (stmt, context_die, depth);
10519 /* Generate all of the decls declared within a given scope and (recursively)
10520 all of its sub-blocks. */
10522 static void
10523 decls_for_scope (stmt, context_die, depth)
10524 register tree stmt;
10525 register dw_die_ref context_die;
10526 int depth;
10528 register tree decl;
10529 register tree subblocks;
10531 /* Ignore blocks never really used to make RTL. */
10532 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10533 return;
10535 /* Output the DIEs to represent all of the data objects and typedefs
10536 declared directly within this block but not within any nested
10537 sub-blocks. Also, nested function and tag DIEs have been
10538 generated with a parent of NULL; fix that up now. */
10539 for (decl = BLOCK_VARS (stmt);
10540 decl != NULL; decl = TREE_CHAIN (decl))
10542 register dw_die_ref die;
10544 if (TREE_CODE (decl) == FUNCTION_DECL)
10545 die = lookup_decl_die (decl);
10546 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10547 die = lookup_type_die (TREE_TYPE (decl));
10548 else
10549 die = NULL;
10551 if (die != NULL && die->die_parent == NULL)
10552 add_child_die (context_die, die);
10553 else
10554 gen_decl_die (decl, context_die);
10557 /* Output the DIEs to represent all sub-blocks (and the items declared
10558 therein) of this block. */
10559 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10560 subblocks != NULL;
10561 subblocks = BLOCK_CHAIN (subblocks))
10562 gen_block_die (subblocks, context_die, depth + 1);
10565 /* Is this a typedef we can avoid emitting? */
10567 static inline int
10568 is_redundant_typedef (decl)
10569 register tree decl;
10571 if (TYPE_DECL_IS_STUB (decl))
10572 return 1;
10574 if (DECL_ARTIFICIAL (decl)
10575 && DECL_CONTEXT (decl)
10576 && is_tagged_type (DECL_CONTEXT (decl))
10577 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10578 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10579 /* Also ignore the artificial member typedef for the class name. */
10580 return 1;
10582 return 0;
10585 /* Generate Dwarf debug information for a decl described by DECL. */
10587 static void
10588 gen_decl_die (decl, context_die)
10589 register tree decl;
10590 register dw_die_ref context_die;
10592 register tree origin;
10594 if (TREE_CODE (decl) == ERROR_MARK)
10595 return;
10597 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10598 if (DECL_IGNORED_P (decl))
10599 return;
10601 switch (TREE_CODE (decl))
10603 case CONST_DECL:
10604 /* The individual enumerators of an enum type get output when we output
10605 the Dwarf representation of the relevant enum type itself. */
10606 break;
10608 case FUNCTION_DECL:
10609 /* Don't output any DIEs to represent mere function declarations,
10610 unless they are class members or explicit block externs. */
10611 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10612 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10613 break;
10615 /* If we're emitting a clone, emit info for the abstract instance. */
10616 if (DECL_ORIGIN (decl) != decl)
10617 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
10618 /* If we're emitting an out-of-line copy of an inline function,
10619 emit info for the abstract instance and set up to refer to it. */
10620 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10621 && ! class_scope_p (context_die)
10622 /* dwarf2out_abstract_function won't emit a die if this is just
10623 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10624 that case, because that works only if we have a die. */
10625 && DECL_INITIAL (decl) != NULL_TREE)
10627 dwarf2out_abstract_function (decl);
10628 set_decl_origin_self (decl);
10630 /* Otherwise we're emitting the primary DIE for this decl. */
10631 else if (debug_info_level > DINFO_LEVEL_TERSE)
10633 /* Before we describe the FUNCTION_DECL itself, make sure that we
10634 have described its return type. */
10635 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10637 /* And its virtual context. */
10638 if (DECL_VINDEX (decl) != NULL_TREE)
10639 gen_type_die (DECL_CONTEXT (decl), context_die);
10641 /* And its containing type. */
10642 origin = decl_class_context (decl);
10643 if (origin != NULL_TREE)
10644 gen_type_die_for_member (origin, decl, context_die);
10647 /* Now output a DIE to represent the function itself. */
10648 gen_subprogram_die (decl, context_die);
10649 break;
10651 case TYPE_DECL:
10652 /* If we are in terse mode, don't generate any DIEs to represent any
10653 actual typedefs. */
10654 if (debug_info_level <= DINFO_LEVEL_TERSE)
10655 break;
10657 /* In the special case of a TYPE_DECL node representing the
10658 declaration of some type tag, if the given TYPE_DECL is marked as
10659 having been instantiated from some other (original) TYPE_DECL node
10660 (e.g. one which was generated within the original definition of an
10661 inline function) we have to generate a special (abbreviated)
10662 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10663 DIE here. */
10664 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10666 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10667 break;
10670 if (is_redundant_typedef (decl))
10671 gen_type_die (TREE_TYPE (decl), context_die);
10672 else
10673 /* Output a DIE to represent the typedef itself. */
10674 gen_typedef_die (decl, context_die);
10675 break;
10677 case LABEL_DECL:
10678 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10679 gen_label_die (decl, context_die);
10680 break;
10682 case VAR_DECL:
10683 /* If we are in terse mode, don't generate any DIEs to represent any
10684 variable declarations or definitions. */
10685 if (debug_info_level <= DINFO_LEVEL_TERSE)
10686 break;
10688 /* Output any DIEs that are needed to specify the type of this data
10689 object. */
10690 gen_type_die (TREE_TYPE (decl), context_die);
10692 /* And its containing type. */
10693 origin = decl_class_context (decl);
10694 if (origin != NULL_TREE)
10695 gen_type_die_for_member (origin, decl, context_die);
10697 /* Now output the DIE to represent the data object itself. This gets
10698 complicated because of the possibility that the VAR_DECL really
10699 represents an inlined instance of a formal parameter for an inline
10700 function. */
10701 origin = decl_ultimate_origin (decl);
10702 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10703 gen_formal_parameter_die (decl, context_die);
10704 else
10705 gen_variable_die (decl, context_die);
10706 break;
10708 case FIELD_DECL:
10709 /* Ignore the nameless fields that are used to skip bits, but
10710 handle C++ anonymous unions. */
10711 if (DECL_NAME (decl) != NULL_TREE
10712 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10714 gen_type_die (member_declared_type (decl), context_die);
10715 gen_field_die (decl, context_die);
10717 break;
10719 case PARM_DECL:
10720 gen_type_die (TREE_TYPE (decl), context_die);
10721 gen_formal_parameter_die (decl, context_die);
10722 break;
10724 case NAMESPACE_DECL:
10725 /* Ignore for now. */
10726 break;
10728 default:
10729 abort ();
10733 /* Add Ada "use" clause information for SGI Workshop debugger. */
10735 void
10736 dwarf2out_add_library_unit_info (filename, context_list)
10737 const char *filename;
10738 const char *context_list;
10740 unsigned int file_index;
10742 if (filename != NULL)
10744 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10745 tree context_list_decl
10746 = build_decl (LABEL_DECL, get_identifier (context_list),
10747 void_type_node);
10749 TREE_PUBLIC (context_list_decl) = TRUE;
10750 add_name_attribute (unit_die, context_list);
10751 file_index = lookup_filename (filename);
10752 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10753 add_pubname (context_list_decl, unit_die);
10757 /* Write the debugging output for DECL. */
10759 void
10760 dwarf2out_decl (decl)
10761 register tree decl;
10763 register dw_die_ref context_die = comp_unit_die;
10765 if (TREE_CODE (decl) == ERROR_MARK)
10766 return;
10768 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10769 if (DECL_IGNORED_P (decl))
10770 return;
10772 switch (TREE_CODE (decl))
10774 case FUNCTION_DECL:
10775 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
10776 builtin function. Explicit programmer-supplied declarations of
10777 these same functions should NOT be ignored however. */
10778 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
10779 return;
10781 /* What we would really like to do here is to filter out all mere
10782 file-scope declarations of file-scope functions which are never
10783 referenced later within this translation unit (and keep all of ones
10784 that *are* referenced later on) but we aren't clairvoyant, so we have
10785 no idea which functions will be referenced in the future (i.e. later
10786 on within the current translation unit). So here we just ignore all
10787 file-scope function declarations which are not also definitions. If
10788 and when the debugger needs to know something about these functions,
10789 it will have to hunt around and find the DWARF information associated
10790 with the definition of the function. Note that we can't just check
10791 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
10792 definitions and which ones represent mere declarations. We have to
10793 check `DECL_INITIAL' instead. That's because the C front-end
10794 supports some weird semantics for "extern inline" function
10795 definitions. These can get inlined within the current translation
10796 unit (an thus, we need to generate DWARF info for their abstract
10797 instances so that the DWARF info for the concrete inlined instances
10798 can have something to refer to) but the compiler never generates any
10799 out-of-lines instances of such things (despite the fact that they
10800 *are* definitions). The important point is that the C front-end
10801 marks these "extern inline" functions as DECL_EXTERNAL, but we need
10802 to generate DWARF for them anyway. Note that the C++ front-end also
10803 plays some similar games for inline function definitions appearing
10804 within include files which also contain
10805 `#pragma interface' pragmas. */
10806 if (DECL_INITIAL (decl) == NULL_TREE)
10807 return;
10809 /* If we're a nested function, initially use a parent of NULL; if we're
10810 a plain function, this will be fixed up in decls_for_scope. If
10811 we're a method, it will be ignored, since we already have a DIE. */
10812 if (decl_function_context (decl))
10813 context_die = NULL;
10815 break;
10817 case VAR_DECL:
10818 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
10819 declaration and if the declaration was never even referenced from
10820 within this entire compilation unit. We suppress these DIEs in
10821 order to save space in the .debug section (by eliminating entries
10822 which are probably useless). Note that we must not suppress
10823 block-local extern declarations (whether used or not) because that
10824 would screw-up the debugger's name lookup mechanism and cause it to
10825 miss things which really ought to be in scope at a given point. */
10826 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
10827 return;
10829 /* If we are in terse mode, don't generate any DIEs to represent any
10830 variable declarations or definitions. */
10831 if (debug_info_level <= DINFO_LEVEL_TERSE)
10832 return;
10833 break;
10835 case TYPE_DECL:
10836 /* Don't emit stubs for types unless they are needed by other DIEs. */
10837 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
10838 return;
10840 /* Don't bother trying to generate any DIEs to represent any of the
10841 normal built-in types for the language we are compiling. */
10842 if (DECL_SOURCE_LINE (decl) == 0)
10844 /* OK, we need to generate one for `bool' so GDB knows what type
10845 comparisons have. */
10846 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
10847 == DW_LANG_C_plus_plus)
10848 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
10849 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
10851 return;
10854 /* If we are in terse mode, don't generate any DIEs for types. */
10855 if (debug_info_level <= DINFO_LEVEL_TERSE)
10856 return;
10858 /* If we're a function-scope tag, initially use a parent of NULL;
10859 this will be fixed up in decls_for_scope. */
10860 if (decl_function_context (decl))
10861 context_die = NULL;
10863 break;
10865 default:
10866 return;
10869 gen_decl_die (decl, context_die);
10872 /* Output a marker (i.e. a label) for the beginning of the generated code for
10873 a lexical block. */
10875 void
10876 dwarf2out_begin_block (blocknum)
10877 register unsigned blocknum;
10879 function_section (current_function_decl);
10880 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
10883 /* Output a marker (i.e. a label) for the end of the generated code for a
10884 lexical block. */
10886 void
10887 dwarf2out_end_block (blocknum)
10888 register unsigned blocknum;
10890 function_section (current_function_decl);
10891 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
10894 /* Returns nonzero if it is appropriate not to emit any debugging
10895 information for BLOCK, because it doesn't contain any instructions.
10897 Don't allow this for blocks with nested functions or local classes
10898 as we would end up with orphans, and in the presence of scheduling
10899 we may end up calling them anyway. */
10902 dwarf2out_ignore_block (block)
10903 tree block;
10905 tree decl;
10906 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
10907 if (TREE_CODE (decl) == FUNCTION_DECL
10908 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
10909 return 0;
10910 return 1;
10913 /* Lookup a filename (in the list of filenames that we know about here in
10914 dwarf2out.c) and return its "index". The index of each (known) filename is
10915 just a unique number which is associated with only that one filename.
10916 We need such numbers for the sake of generating labels
10917 (in the .debug_sfnames section) and references to those
10918 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
10919 If the filename given as an argument is not found in our current list,
10920 add it to the list and assign it the next available unique index number.
10921 In order to speed up searches, we remember the index of the filename
10922 was looked up last. This handles the majority of all searches. */
10924 static unsigned
10925 lookup_filename (file_name)
10926 const char *file_name;
10928 register unsigned i;
10930 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
10931 if (strcmp (file_name, "<internal>") == 0
10932 || strcmp (file_name, "<built-in>") == 0)
10933 return 0;
10935 /* Check to see if the file name that was searched on the previous
10936 call matches this file name. If so, return the index. */
10937 if (file_table.last_lookup_index != 0)
10938 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
10939 return file_table.last_lookup_index;
10941 /* Didn't match the previous lookup, search the table */
10942 for (i = 1; i < file_table.in_use; ++i)
10943 if (strcmp (file_name, file_table.table[i]) == 0)
10945 file_table.last_lookup_index = i;
10946 return i;
10949 /* Prepare to add a new table entry by making sure there is enough space in
10950 the table to do so. If not, expand the current table. */
10951 if (i == file_table.allocated)
10953 file_table.allocated = i + FILE_TABLE_INCREMENT;
10954 file_table.table = (char **)
10955 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
10958 /* Add the new entry to the end of the filename table. */
10959 file_table.table[i] = xstrdup (file_name);
10960 file_table.in_use = i + 1;
10961 file_table.last_lookup_index = i;
10963 if (DWARF2_ASM_LINE_DEBUG_INFO)
10964 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
10966 return i;
10969 static void
10970 init_file_table ()
10972 /* Allocate the initial hunk of the file_table. */
10973 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
10974 file_table.allocated = FILE_TABLE_INCREMENT;
10976 /* Skip the first entry - file numbers begin at 1. */
10977 file_table.in_use = 1;
10978 file_table.last_lookup_index = 0;
10981 /* Output a label to mark the beginning of a source code line entry
10982 and record information relating to this source line, in
10983 'line_info_table' for later output of the .debug_line section. */
10985 void
10986 dwarf2out_line (filename, line)
10987 register const char *filename;
10988 register unsigned line;
10990 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10992 function_section (current_function_decl);
10994 if (DWARF2_ASM_LINE_DEBUG_INFO)
10996 unsigned file_num = lookup_filename (filename);
10998 /* Emit the .loc directive understood by GNU as. */
10999 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11001 /* Indicate that line number info exists. */
11002 ++line_info_table_in_use;
11004 /* Indicate that multiple line number tables exist. */
11005 if (DECL_SECTION_NAME (current_function_decl))
11006 ++separate_line_info_table_in_use;
11008 else if (DECL_SECTION_NAME (current_function_decl))
11010 register dw_separate_line_info_ref line_info;
11011 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11012 separate_line_info_table_in_use);
11013 if (flag_debug_asm)
11014 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11015 filename, line);
11017 /* expand the line info table if necessary */
11018 if (separate_line_info_table_in_use
11019 == separate_line_info_table_allocated)
11021 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11022 separate_line_info_table
11023 = (dw_separate_line_info_ref)
11024 xrealloc (separate_line_info_table,
11025 separate_line_info_table_allocated
11026 * sizeof (dw_separate_line_info_entry));
11029 /* Add the new entry at the end of the line_info_table. */
11030 line_info
11031 = &separate_line_info_table[separate_line_info_table_in_use++];
11032 line_info->dw_file_num = lookup_filename (filename);
11033 line_info->dw_line_num = line;
11034 line_info->function = current_funcdef_number;
11036 else
11038 register dw_line_info_ref line_info;
11040 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11041 line_info_table_in_use);
11042 if (flag_debug_asm)
11043 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11044 filename, line);
11046 /* Expand the line info table if necessary. */
11047 if (line_info_table_in_use == line_info_table_allocated)
11049 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11050 line_info_table
11051 = (dw_line_info_ref)
11052 xrealloc (line_info_table,
11053 (line_info_table_allocated
11054 * sizeof (dw_line_info_entry)));
11057 /* Add the new entry at the end of the line_info_table. */
11058 line_info = &line_info_table[line_info_table_in_use++];
11059 line_info->dw_file_num = lookup_filename (filename);
11060 line_info->dw_line_num = line;
11065 /* Record the beginning of a new source file, for later output
11066 of the .debug_macinfo section. At present, unimplemented. */
11068 void
11069 dwarf2out_start_source_file (filename)
11070 register const char *filename ATTRIBUTE_UNUSED;
11072 if (flag_eliminate_dwarf2_dups)
11074 /* Record the beginning of the file for break_out_includes. */
11075 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11076 add_AT_string (bincl_die, DW_AT_name, filename);
11080 /* Record the end of a source file, for later output
11081 of the .debug_macinfo section. At present, unimplemented. */
11083 void
11084 dwarf2out_end_source_file ()
11086 if (flag_eliminate_dwarf2_dups)
11088 /* Record the end of the file for break_out_includes. */
11089 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11093 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11094 the tail part of the directive line, i.e. the part which is past the
11095 initial whitespace, #, whitespace, directive-name, whitespace part. */
11097 void
11098 dwarf2out_define (lineno, buffer)
11099 register unsigned lineno ATTRIBUTE_UNUSED;
11100 register const char *buffer ATTRIBUTE_UNUSED;
11102 static int initialized = 0;
11103 if (!initialized)
11105 dwarf2out_start_source_file (primary_filename);
11106 initialized = 1;
11110 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11111 the tail part of the directive line, i.e. the part which is past the
11112 initial whitespace, #, whitespace, directive-name, whitespace part. */
11114 void
11115 dwarf2out_undef (lineno, buffer)
11116 register unsigned lineno ATTRIBUTE_UNUSED;
11117 register const char *buffer ATTRIBUTE_UNUSED;
11121 /* Set up for Dwarf output at the start of compilation. */
11123 void
11124 dwarf2out_init (asm_out_file, main_input_filename)
11125 register FILE *asm_out_file;
11126 register const char *main_input_filename;
11128 init_file_table ();
11130 /* Remember the name of the primary input file. */
11131 primary_filename = main_input_filename;
11133 /* Add it to the file table first, under the assumption that we'll
11134 be emitting line number data for it first, which avoids having
11135 to add an initial DW_LNS_set_file. */
11136 lookup_filename (main_input_filename);
11138 /* Allocate the initial hunk of the decl_die_table. */
11139 decl_die_table
11140 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11141 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11142 decl_die_table_in_use = 0;
11144 /* Allocate the initial hunk of the decl_scope_table. */
11145 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
11146 ggc_add_tree_varray_root (&decl_scope_table, 1);
11148 /* Allocate the initial hunk of the abbrev_die_table. */
11149 abbrev_die_table
11150 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11151 sizeof (dw_die_ref));
11152 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11153 /* Zero-th entry is allocated, but unused */
11154 abbrev_die_table_in_use = 1;
11156 /* Allocate the initial hunk of the line_info_table. */
11157 line_info_table
11158 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11159 sizeof (dw_line_info_entry));
11160 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11161 /* Zero-th entry is allocated, but unused */
11162 line_info_table_in_use = 1;
11164 /* Generate the initial DIE for the .debug section. Note that the (string)
11165 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11166 will (typically) be a relative pathname and that this pathname should be
11167 taken as being relative to the directory from which the compiler was
11168 invoked when the given (base) source file was compiled. */
11169 comp_unit_die = gen_compile_unit_die (main_input_filename);
11171 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
11172 ggc_add_tree_varray_root (&incomplete_types, 1);
11174 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11175 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11177 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11178 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
11179 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11180 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11181 else
11182 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11183 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11184 DEBUG_INFO_SECTION_LABEL, 0);
11185 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11186 DEBUG_LINE_SECTION_LABEL, 0);
11188 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11189 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11190 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11192 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11193 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11195 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11196 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11197 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11198 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11201 /* Output stuff that dwarf requires at the end of every file,
11202 and generate the DWARF-2 debugging info. */
11204 void
11205 dwarf2out_finish ()
11207 limbo_die_node *node, *next_node;
11208 dw_die_ref die;
11210 /* Traverse the limbo die list, and add parent/child links. The only
11211 dies without parents that should be here are concrete instances of
11212 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11213 For concrete instances, we can get the parent die from the abstract
11214 instance. */
11215 for (node = limbo_die_list; node; node = next_node)
11217 next_node = node->next;
11218 die = node->die;
11220 if (die->die_parent == NULL)
11222 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11223 if (origin)
11224 add_child_die (origin->die_parent, die);
11225 else if (die == comp_unit_die)
11227 else
11228 abort ();
11230 free (node);
11232 limbo_die_list = NULL;
11234 /* Walk through the list of incomplete types again, trying once more to
11235 emit full debugging info for them. */
11236 retry_incomplete_types ();
11238 /* We need to reverse all the dies before break_out_includes, or
11239 we'll see the end of an include file before the beginning. */
11240 reverse_all_dies (comp_unit_die);
11242 /* Generate separate CUs for each of the include files we've seen.
11243 They will go into limbo_die_list. */
11244 if (flag_eliminate_dwarf2_dups)
11245 break_out_includes (comp_unit_die);
11247 /* Traverse the DIE's and add add sibling attributes to those DIE's
11248 that have children. */
11249 add_sibling_attributes (comp_unit_die);
11250 for (node = limbo_die_list; node; node = node->next)
11251 add_sibling_attributes (node->die);
11253 /* Output a terminator label for the .text section. */
11254 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11255 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11257 #if 0
11258 /* Output a terminator label for the .data section. */
11259 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11260 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11262 /* Output a terminator label for the .bss section. */
11263 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11264 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11265 #endif
11267 /* Output the source line correspondence table. We must do this
11268 even if there is no line information. Otherwise, on an empty
11269 translation unit, we will generate a present, but empty,
11270 .debug_info section. IRIX 6.5 `nm' will then complain when
11271 examining the file. */
11272 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11274 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11275 output_line_info ();
11278 /* We can only use the low/high_pc attributes if all of the code was
11279 in .text. */
11280 if (separate_line_info_table_in_use == 0)
11282 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11283 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11286 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11287 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11288 debug_line_section_label);
11290 #if 0 /* unimplemented */
11291 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11292 add_AT_unsigned (die, DW_AT_macro_info, 0);
11293 #endif
11295 /* Output all of the compilation units. We put the main one last so that
11296 the offsets are available to output_pubnames. */
11297 for (node = limbo_die_list; node; node = node->next)
11298 output_comp_unit (node->die);
11299 output_comp_unit (comp_unit_die);
11301 /* Output the abbreviation table. */
11302 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11303 output_abbrev_section ();
11305 if (pubname_table_in_use)
11307 /* Output public names table. */
11308 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11309 output_pubnames ();
11312 /* We only put functions in the arange table, so don't write it out if
11313 we don't have any. */
11314 if (fde_table_in_use)
11316 /* Output the address range information. */
11317 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11318 output_aranges ();
11321 /* At this point, we've switched sections like mad, but we've done
11322 so behind the back of varasm.c. Unfortunately, used
11323 named_section to switch sections doesn't work either; GAS 2.9.5
11324 is not pleased by:
11326 .section debug_aranges,"a",@progbits
11328 on i686-pc-linux-gnu.
11330 By calling force_data_section, we get varasm.c synched back up
11331 with reality. That makes subsequent calls to text_section and
11332 such make sense. */
11333 force_data_section ();
11335 #endif /* DWARF2_DEBUGGING_INFO */