2001-04-09 Andrew MacLeod <amacleod@redhat.com>
[official-gcc.git] / gcc / dwarf2out.c
blob6f04c753c260c9bc2de8d1a5894378d32df91349
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 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
97 /* How to start an assembler comment. */
98 #ifndef ASM_COMMENT_START
99 #define ASM_COMMENT_START ";#"
100 #endif
102 typedef struct dw_cfi_struct *dw_cfi_ref;
103 typedef struct dw_fde_struct *dw_fde_ref;
104 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
106 /* Call frames are described using a sequence of Call Frame
107 Information instructions. The register number, offset
108 and address fields are provided as possible operands;
109 their use is selected by the opcode field. */
111 typedef union dw_cfi_oprnd_struct
113 unsigned long dw_cfi_reg_num;
114 long int dw_cfi_offset;
115 const char *dw_cfi_addr;
116 struct dw_loc_descr_struct *dw_cfi_loc;
118 dw_cfi_oprnd;
120 typedef struct dw_cfi_struct
122 dw_cfi_ref dw_cfi_next;
123 enum dwarf_call_frame_info dw_cfi_opc;
124 dw_cfi_oprnd dw_cfi_oprnd1;
125 dw_cfi_oprnd dw_cfi_oprnd2;
127 dw_cfi_node;
129 /* This is how we define the location of the CFA. We use to handle it
130 as REG + OFFSET all the time, but now it can be more complex.
131 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
132 Instead of passing around REG and OFFSET, we pass a copy
133 of this structure. */
134 typedef struct cfa_loc
136 unsigned long reg;
137 long offset;
138 long base_offset;
139 int indirect; /* 1 if CFA is accessed via a dereference. */
140 } dw_cfa_location;
142 /* All call frame descriptions (FDE's) in the GCC generated DWARF
143 refer to a single Common Information Entry (CIE), defined at
144 the beginning of the .debug_frame section. This used of a single
145 CIE obviates the need to keep track of multiple CIE's
146 in the DWARF generation routines below. */
148 typedef struct dw_fde_struct
150 const char *dw_fde_begin;
151 const char *dw_fde_current_label;
152 const char *dw_fde_end;
153 dw_cfi_ref dw_fde_cfi;
154 unsigned funcdef_number;
155 unsigned nothrow : 1;
156 unsigned uses_eh_lsda : 1;
158 dw_fde_node;
160 /* Maximum size (in bytes) of an artificially generated label. */
161 #define MAX_ARTIFICIAL_LABEL_BYTES 30
163 /* The size of the target's pointer type. */
164 #ifndef PTR_SIZE
165 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
166 #endif
168 /* The size of addresses as they appear in the Dwarf 2 data.
169 Some architectures use word addresses to refer to code locations,
170 but Dwarf 2 info always uses byte addresses. On such machines,
171 Dwarf 2 addresses need to be larger than the architecture's
172 pointers. */
173 #ifndef DWARF2_ADDR_SIZE
174 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
175 #endif
177 /* The size in bytes of a DWARF field indicating an offset or length
178 relative to a debug info section, specified to be 4 bytes in the
179 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
180 as PTR_SIZE. */
182 #ifndef DWARF_OFFSET_SIZE
183 #define DWARF_OFFSET_SIZE 4
184 #endif
186 #define DWARF_VERSION 2
188 /* Round SIZE up to the nearest BOUNDARY. */
189 #define DWARF_ROUND(SIZE,BOUNDARY) \
190 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
192 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
193 #ifndef DWARF_CIE_DATA_ALIGNMENT
194 #ifdef STACK_GROWS_DOWNWARD
195 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
196 #else
197 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
198 #endif
199 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
201 /* A pointer to the base of a table that contains frame description
202 information for each routine. */
203 static dw_fde_ref fde_table;
205 /* Number of elements currently allocated for fde_table. */
206 static unsigned fde_table_allocated;
208 /* Number of elements in fde_table currently in use. */
209 static unsigned fde_table_in_use;
211 /* Size (in elements) of increments by which we may expand the
212 fde_table. */
213 #define FDE_TABLE_INCREMENT 256
215 /* A list of call frame insns for the CIE. */
216 static dw_cfi_ref cie_cfi_head;
218 /* The number of the current function definition for which debugging
219 information is being generated. These numbers range from 1 up to the
220 maximum number of function definitions contained within the current
221 compilation unit. These numbers are used to create unique label id's
222 unique to each function definition. */
223 unsigned current_funcdef_number = 0;
225 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
226 attribute that accelerates the lookup of the FDE associated
227 with the subprogram. This variable holds the table index of the FDE
228 associated with the current function (body) definition. */
229 static unsigned current_funcdef_fde;
231 /* Forward declarations for functions defined in this file. */
233 static char *stripattributes PARAMS ((const char *));
234 static const char *dwarf_cfi_name PARAMS ((unsigned));
235 static dw_cfi_ref new_cfi PARAMS ((void));
236 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
237 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
238 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
239 static void lookup_cfa PARAMS ((dw_cfa_location *));
240 static void reg_save PARAMS ((const char *, unsigned,
241 unsigned, long));
242 static void initial_return_save PARAMS ((rtx));
243 static long stack_adjust_offset PARAMS ((rtx));
244 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
245 static void output_call_frame_info PARAMS ((int));
246 static void dwarf2out_stack_adjust PARAMS ((rtx));
247 static void queue_reg_save PARAMS ((const char *, rtx, long));
248 static void flush_queued_reg_saves PARAMS ((void));
249 static bool clobbers_queued_reg_save PARAMS ((rtx));
250 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
252 /* Support for complex CFA locations. */
253 static void output_cfa_loc PARAMS ((dw_cfi_ref));
254 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
255 struct dw_loc_descr_struct *));
256 static struct dw_loc_descr_struct *build_cfa_loc
257 PARAMS ((dw_cfa_location *));
258 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
260 /* How to start an assembler comment. */
261 #ifndef ASM_COMMENT_START
262 #define ASM_COMMENT_START ";#"
263 #endif
265 /* Data and reference forms for relocatable data. */
266 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
267 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
269 /* Pseudo-op for defining a new section. */
270 #ifndef SECTION_ASM_OP
271 #define SECTION_ASM_OP "\t.section\t"
272 #endif
274 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
275 print the SECTION_ASM_OP and the section name. The default here works for
276 almost all svr4 assemblers, except for the sparc, where the section name
277 must be enclosed in double quotes. (See sparcv4.h). */
278 #ifndef SECTION_FORMAT
279 #ifdef PUSHSECTION_FORMAT
280 #define SECTION_FORMAT PUSHSECTION_FORMAT
281 #else
282 #define SECTION_FORMAT "%s%s\n"
283 #endif
284 #endif
286 #ifndef FRAME_SECTION
287 #define FRAME_SECTION ".debug_frame"
288 #endif
290 #ifndef FUNC_BEGIN_LABEL
291 #define FUNC_BEGIN_LABEL "LFB"
292 #endif
293 #ifndef FUNC_END_LABEL
294 #define FUNC_END_LABEL "LFE"
295 #endif
296 #define CIE_AFTER_SIZE_LABEL "LSCIE"
297 #define CIE_END_LABEL "LECIE"
298 #define CIE_LENGTH_LABEL "LLCIE"
299 #define FDE_LABEL "LSFDE"
300 #define FDE_AFTER_SIZE_LABEL "LASFDE"
301 #define FDE_END_LABEL "LEFDE"
302 #define FDE_LENGTH_LABEL "LLFDE"
303 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
304 #define LINE_NUMBER_END_LABEL "LELT"
305 #define LN_PROLOG_AS_LABEL "LASLTP"
306 #define LN_PROLOG_END_LABEL "LELTP"
307 #define DIE_LABEL_PREFIX "DW"
309 /* Definitions of defaults for various types of primitive assembly language
310 output operations. These may be overridden from within the tm.h file,
311 but typically, that is unnecessary. */
313 #ifndef ASM_OUTPUT_SECTION
314 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
315 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
316 #endif
318 #ifdef SET_ASM_OP
319 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
320 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
321 do { \
322 fprintf (FILE, "%s", SET_ASM_OP); \
323 assemble_name (FILE, SY); \
324 fputc (',', FILE); \
325 assemble_name (FILE, HI); \
326 fputc ('-', FILE); \
327 assemble_name (FILE, LO); \
328 } while (0)
329 #endif
330 #endif /* SET_ASM_OP */
332 /* The DWARF 2 CFA column which tracks the return address. Normally this
333 is the column for PC, or the first column after all of the hard
334 registers. */
335 #ifndef DWARF_FRAME_RETURN_COLUMN
336 #ifdef PC_REGNUM
337 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
338 #else
339 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
340 #endif
341 #endif
343 /* The mapping from gcc register number to DWARF 2 CFA column number. By
344 default, we just provide columns for all registers. */
345 #ifndef DWARF_FRAME_REGNUM
346 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
347 #endif
349 /* Hook used by __throw. */
352 expand_builtin_dwarf_fp_regnum ()
354 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
357 /* The offset from the incoming value of %sp to the top of the stack frame
358 for the current function. */
359 #ifndef INCOMING_FRAME_SP_OFFSET
360 #define INCOMING_FRAME_SP_OFFSET 0
361 #endif
363 /* Return a pointer to a copy of the section string name S with all
364 attributes stripped off, and an asterisk prepended (for assemble_name). */
366 static inline char *
367 stripattributes (s)
368 const char *s;
370 char *stripped = xmalloc (strlen (s) + 2);
371 char *p = stripped;
373 *p++ = '*';
375 while (*s && *s != ',')
376 *p++ = *s++;
378 *p = '\0';
379 return stripped;
382 /* Generate code to initialize the register size table. */
384 void
385 expand_builtin_init_dwarf_reg_sizes (address)
386 tree address;
388 int i;
389 enum machine_mode mode = TYPE_MODE (char_type_node);
390 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
391 rtx mem = gen_rtx_MEM (mode, addr);
393 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
395 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
396 int size = GET_MODE_SIZE (reg_raw_mode[i]);
398 if (offset < 0)
399 continue;
401 emit_move_insn (change_address (mem, mode,
402 plus_constant (addr, offset)),
403 GEN_INT (size));
407 /* Convert a DWARF call frame info. operation to its string name */
409 static const char *
410 dwarf_cfi_name (cfi_opc)
411 register unsigned cfi_opc;
413 switch (cfi_opc)
415 case DW_CFA_advance_loc:
416 return "DW_CFA_advance_loc";
417 case DW_CFA_offset:
418 return "DW_CFA_offset";
419 case DW_CFA_restore:
420 return "DW_CFA_restore";
421 case DW_CFA_nop:
422 return "DW_CFA_nop";
423 case DW_CFA_set_loc:
424 return "DW_CFA_set_loc";
425 case DW_CFA_advance_loc1:
426 return "DW_CFA_advance_loc1";
427 case DW_CFA_advance_loc2:
428 return "DW_CFA_advance_loc2";
429 case DW_CFA_advance_loc4:
430 return "DW_CFA_advance_loc4";
431 case DW_CFA_offset_extended:
432 return "DW_CFA_offset_extended";
433 case DW_CFA_restore_extended:
434 return "DW_CFA_restore_extended";
435 case DW_CFA_undefined:
436 return "DW_CFA_undefined";
437 case DW_CFA_same_value:
438 return "DW_CFA_same_value";
439 case DW_CFA_register:
440 return "DW_CFA_register";
441 case DW_CFA_remember_state:
442 return "DW_CFA_remember_state";
443 case DW_CFA_restore_state:
444 return "DW_CFA_restore_state";
445 case DW_CFA_def_cfa:
446 return "DW_CFA_def_cfa";
447 case DW_CFA_def_cfa_register:
448 return "DW_CFA_def_cfa_register";
449 case DW_CFA_def_cfa_offset:
450 return "DW_CFA_def_cfa_offset";
451 case DW_CFA_def_cfa_expression:
452 return "DW_CFA_def_cfa_expression";
454 /* SGI/MIPS specific */
455 case DW_CFA_MIPS_advance_loc8:
456 return "DW_CFA_MIPS_advance_loc8";
458 /* GNU extensions */
459 case DW_CFA_GNU_window_save:
460 return "DW_CFA_GNU_window_save";
461 case DW_CFA_GNU_args_size:
462 return "DW_CFA_GNU_args_size";
463 case DW_CFA_GNU_negative_offset_extended:
464 return "DW_CFA_GNU_negative_offset_extended";
466 default:
467 return "DW_CFA_<unknown>";
471 /* Return a pointer to a newly allocated Call Frame Instruction. */
473 static inline dw_cfi_ref
474 new_cfi ()
476 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
478 cfi->dw_cfi_next = NULL;
479 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
480 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
482 return cfi;
485 /* Add a Call Frame Instruction to list of instructions. */
487 static inline void
488 add_cfi (list_head, cfi)
489 register dw_cfi_ref *list_head;
490 register dw_cfi_ref cfi;
492 register dw_cfi_ref *p;
494 /* Find the end of the chain. */
495 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
498 *p = cfi;
501 /* Generate a new label for the CFI info to refer to. */
503 char *
504 dwarf2out_cfi_label ()
506 static char label[20];
507 static unsigned long label_num = 0;
509 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
510 ASM_OUTPUT_LABEL (asm_out_file, label);
512 return label;
515 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
516 or to the CIE if LABEL is NULL. */
518 static void
519 add_fde_cfi (label, cfi)
520 register const char *label;
521 register dw_cfi_ref cfi;
523 if (label)
525 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
527 if (*label == 0)
528 label = dwarf2out_cfi_label ();
530 if (fde->dw_fde_current_label == NULL
531 || strcmp (label, fde->dw_fde_current_label) != 0)
533 register dw_cfi_ref xcfi;
535 fde->dw_fde_current_label = label = xstrdup (label);
537 /* Set the location counter to the new label. */
538 xcfi = new_cfi ();
539 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
540 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
541 add_cfi (&fde->dw_fde_cfi, xcfi);
544 add_cfi (&fde->dw_fde_cfi, cfi);
547 else
548 add_cfi (&cie_cfi_head, cfi);
551 /* Subroutine of lookup_cfa. */
553 static inline void
554 lookup_cfa_1 (cfi, loc)
555 register dw_cfi_ref cfi;
556 register dw_cfa_location *loc;
558 switch (cfi->dw_cfi_opc)
560 case DW_CFA_def_cfa_offset:
561 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
562 break;
563 case DW_CFA_def_cfa_register:
564 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
565 break;
566 case DW_CFA_def_cfa:
567 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
568 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
569 break;
570 case DW_CFA_def_cfa_expression:
571 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
572 break;
573 default:
574 break;
578 /* Find the previous value for the CFA. */
580 static void
581 lookup_cfa (loc)
582 register dw_cfa_location *loc;
584 register dw_cfi_ref cfi;
586 loc->reg = (unsigned long) -1;
587 loc->offset = 0;
588 loc->indirect = 0;
589 loc->base_offset = 0;
591 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
592 lookup_cfa_1 (cfi, loc);
594 if (fde_table_in_use)
596 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
597 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
598 lookup_cfa_1 (cfi, loc);
602 /* The current rule for calculating the DWARF2 canonical frame address. */
603 static dw_cfa_location cfa;
605 /* The register used for saving registers to the stack, and its offset
606 from the CFA. */
607 static dw_cfa_location cfa_store;
609 /* The running total of the size of arguments pushed onto the stack. */
610 static long args_size;
612 /* The last args_size we actually output. */
613 static long old_args_size;
615 /* Entry point to update the canonical frame address (CFA).
616 LABEL is passed to add_fde_cfi. The value of CFA is now to be
617 calculated from REG+OFFSET. */
619 void
620 dwarf2out_def_cfa (label, reg, offset)
621 register const char *label;
622 unsigned reg;
623 long offset;
625 dw_cfa_location loc;
626 loc.indirect = 0;
627 loc.base_offset = 0;
628 loc.reg = reg;
629 loc.offset = offset;
630 def_cfa_1 (label, &loc);
633 /* This routine does the actual work. The CFA is now calculated from
634 the dw_cfa_location structure. */
635 static void
636 def_cfa_1 (label, loc_p)
637 register const char *label;
638 dw_cfa_location *loc_p;
640 register dw_cfi_ref cfi;
641 dw_cfa_location old_cfa, loc;
643 cfa = *loc_p;
644 loc = *loc_p;
646 if (cfa_store.reg == loc.reg && loc.indirect == 0)
647 cfa_store.offset = loc.offset;
649 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
650 lookup_cfa (&old_cfa);
652 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
653 loc.indirect == old_cfa.indirect)
655 if (loc.indirect == 0
656 || loc.base_offset == old_cfa.base_offset)
657 /* Nothing changed so no need to issue any call frame
658 instructions. */
659 return;
662 cfi = new_cfi ();
664 if (loc.reg == old_cfa.reg && !loc.indirect)
666 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
667 indicating the CFA register did not change but the offset
668 did. */
669 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
670 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
673 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
674 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
675 && !loc.indirect)
677 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
678 indicating the CFA register has changed to <register> but the
679 offset has not changed. */
680 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
681 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
683 #endif
685 else if (loc.indirect == 0)
687 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
688 indicating the CFA register has changed to <register> with
689 the specified offset. */
690 cfi->dw_cfi_opc = DW_CFA_def_cfa;
691 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
692 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
694 else
696 /* Construct a DW_CFA_def_cfa_expression instruction to
697 calculate the CFA using a full location expression since no
698 register-offset pair is available. */
699 struct dw_loc_descr_struct *loc_list;
700 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
701 loc_list = build_cfa_loc (&loc);
702 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
705 add_fde_cfi (label, cfi);
708 /* Add the CFI for saving a register. REG is the CFA column number.
709 LABEL is passed to add_fde_cfi.
710 If SREG is -1, the register is saved at OFFSET from the CFA;
711 otherwise it is saved in SREG. */
713 static void
714 reg_save (label, reg, sreg, offset)
715 register const char *label;
716 register unsigned reg;
717 register unsigned sreg;
718 register long offset;
720 register dw_cfi_ref cfi = new_cfi ();
722 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
724 /* The following comparison is correct. -1 is used to indicate that
725 the value isn't a register number. */
726 if (sreg == (unsigned int) -1)
728 if (reg & ~0x3f)
729 /* The register number won't fit in 6 bits, so we have to use
730 the long form. */
731 cfi->dw_cfi_opc = DW_CFA_offset_extended;
732 else
733 cfi->dw_cfi_opc = DW_CFA_offset;
735 #ifdef ENABLE_CHECKING
737 /* If we get an offset that is not a multiple of
738 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
739 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
740 description. */
741 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
743 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
744 abort ();
746 #endif
747 offset /= DWARF_CIE_DATA_ALIGNMENT;
748 if (offset < 0)
750 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
751 offset = -offset;
753 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
755 else if (sreg == reg)
756 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
757 return;
758 else
760 cfi->dw_cfi_opc = DW_CFA_register;
761 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
764 add_fde_cfi (label, cfi);
767 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
768 This CFI tells the unwinder that it needs to restore the window registers
769 from the previous frame's window save area.
771 ??? Perhaps we should note in the CIE where windows are saved (instead of
772 assuming 0(cfa)) and what registers are in the window. */
774 void
775 dwarf2out_window_save (label)
776 register const char *label;
778 register dw_cfi_ref cfi = new_cfi ();
779 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
780 add_fde_cfi (label, cfi);
783 /* Add a CFI to update the running total of the size of arguments
784 pushed onto the stack. */
786 void
787 dwarf2out_args_size (label, size)
788 const char *label;
789 long size;
791 register dw_cfi_ref cfi;
793 if (size == old_args_size)
794 return;
795 old_args_size = size;
797 cfi = new_cfi ();
798 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
799 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
800 add_fde_cfi (label, cfi);
803 /* Entry point for saving a register to the stack. REG is the GCC register
804 number. LABEL and OFFSET are passed to reg_save. */
806 void
807 dwarf2out_reg_save (label, reg, offset)
808 register const char *label;
809 register unsigned reg;
810 register long offset;
812 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
815 /* Entry point for saving the return address in the stack.
816 LABEL and OFFSET are passed to reg_save. */
818 void
819 dwarf2out_return_save (label, offset)
820 register const char *label;
821 register long offset;
823 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
826 /* Entry point for saving the return address in a register.
827 LABEL and SREG are passed to reg_save. */
829 void
830 dwarf2out_return_reg (label, sreg)
831 register const char *label;
832 register unsigned sreg;
834 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
837 /* Record the initial position of the return address. RTL is
838 INCOMING_RETURN_ADDR_RTX. */
840 static void
841 initial_return_save (rtl)
842 register rtx rtl;
844 unsigned int reg = (unsigned int) -1;
845 long offset = 0;
847 switch (GET_CODE (rtl))
849 case REG:
850 /* RA is in a register. */
851 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
852 break;
853 case MEM:
854 /* RA is on the stack. */
855 rtl = XEXP (rtl, 0);
856 switch (GET_CODE (rtl))
858 case REG:
859 if (REGNO (rtl) != STACK_POINTER_REGNUM)
860 abort ();
861 offset = 0;
862 break;
863 case PLUS:
864 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
865 abort ();
866 offset = INTVAL (XEXP (rtl, 1));
867 break;
868 case MINUS:
869 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
870 abort ();
871 offset = -INTVAL (XEXP (rtl, 1));
872 break;
873 default:
874 abort ();
876 break;
877 case PLUS:
878 /* The return address is at some offset from any value we can
879 actually load. For instance, on the SPARC it is in %i7+8. Just
880 ignore the offset for now; it doesn't matter for unwinding frames. */
881 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
882 abort ();
883 initial_return_save (XEXP (rtl, 0));
884 return;
885 default:
886 abort ();
889 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
892 /* Given a SET, calculate the amount of stack adjustment it
893 contains. */
895 static long
896 stack_adjust_offset (pattern)
897 rtx pattern;
899 rtx src = SET_SRC (pattern);
900 rtx dest = SET_DEST (pattern);
901 long offset = 0;
902 enum rtx_code code;
904 if (dest == stack_pointer_rtx)
906 /* (set (reg sp) (plus (reg sp) (const_int))) */
907 code = GET_CODE (src);
908 if (! (code == PLUS || code == MINUS)
909 || XEXP (src, 0) != stack_pointer_rtx
910 || GET_CODE (XEXP (src, 1)) != CONST_INT)
911 return 0;
913 offset = INTVAL (XEXP (src, 1));
915 else if (GET_CODE (dest) == MEM)
917 /* (set (mem (pre_dec (reg sp))) (foo)) */
918 src = XEXP (dest, 0);
919 code = GET_CODE (src);
921 if (! (code == PRE_DEC || code == PRE_INC
922 || code == PRE_MODIFY)
923 || XEXP (src, 0) != stack_pointer_rtx)
924 return 0;
926 if (code == PRE_MODIFY)
928 rtx val = XEXP (XEXP (src, 1), 1);
929 /* We handle only adjustments by constant amount. */
930 if (GET_CODE (XEXP (src, 1)) != PLUS ||
931 GET_CODE (val) != CONST_INT)
932 abort();
933 offset = -INTVAL (val);
935 else offset = GET_MODE_SIZE (GET_MODE (dest));
937 else
938 return 0;
940 if (code == PLUS || code == PRE_INC)
941 offset = -offset;
943 return offset;
946 /* Check INSN to see if it looks like a push or a stack adjustment, and
947 make a note of it if it does. EH uses this information to find out how
948 much extra space it needs to pop off the stack. */
950 static void
951 dwarf2out_stack_adjust (insn)
952 rtx insn;
954 long offset;
955 const char *label;
957 if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN)
959 /* Extract the size of the args from the CALL rtx itself. */
961 insn = PATTERN (insn);
962 if (GET_CODE (insn) == PARALLEL)
963 insn = XVECEXP (insn, 0, 0);
964 if (GET_CODE (insn) == SET)
965 insn = SET_SRC (insn);
966 if (GET_CODE (insn) != CALL)
967 abort ();
968 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
969 return;
972 /* If only calls can throw, and we have a frame pointer,
973 save up adjustments until we see the CALL_INSN. */
974 else if (! flag_non_call_exceptions
975 && cfa.reg != STACK_POINTER_REGNUM)
976 return;
978 if (GET_CODE (insn) == BARRIER)
980 /* When we see a BARRIER, we know to reset args_size to 0. Usually
981 the compiler will have already emitted a stack adjustment, but
982 doesn't bother for calls to noreturn functions. */
983 #ifdef STACK_GROWS_DOWNWARD
984 offset = -args_size;
985 #else
986 offset = args_size;
987 #endif
989 else if (GET_CODE (PATTERN (insn)) == SET)
991 offset = stack_adjust_offset (PATTERN (insn));
993 else if (GET_CODE (PATTERN (insn)) == PARALLEL
994 || GET_CODE (PATTERN (insn)) == SEQUENCE)
996 /* There may be stack adjustments inside compound insns. Search
997 for them. */
998 int j;
1000 offset = 0;
1001 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1003 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1004 if (GET_CODE (pattern) == SET)
1005 offset += stack_adjust_offset (pattern);
1008 else
1009 return;
1011 if (offset == 0)
1012 return;
1014 if (cfa.reg == STACK_POINTER_REGNUM)
1015 cfa.offset += offset;
1017 #ifndef STACK_GROWS_DOWNWARD
1018 offset = -offset;
1019 #endif
1020 args_size += offset;
1021 if (args_size < 0)
1022 args_size = 0;
1024 label = dwarf2out_cfi_label ();
1025 def_cfa_1 (label, &cfa);
1026 dwarf2out_args_size (label, args_size);
1029 /* We delay emitting a register save until either (a) we reach the end
1030 of the prologue or (b) the register is clobbered. This clusters
1031 register saves so that there are fewer pc advances. */
1033 struct queued_reg_save
1035 struct queued_reg_save *next;
1036 rtx reg;
1037 long cfa_offset;
1040 static struct queued_reg_save *queued_reg_saves;
1041 static const char *last_reg_save_label;
1043 static void
1044 queue_reg_save (label, reg, offset)
1045 const char *label;
1046 rtx reg;
1047 long offset;
1049 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1051 q->next = queued_reg_saves;
1052 q->reg = reg;
1053 q->cfa_offset = offset;
1054 queued_reg_saves = q;
1056 last_reg_save_label = label;
1059 static void
1060 flush_queued_reg_saves ()
1062 struct queued_reg_save *q, *next;
1064 for (q = queued_reg_saves; q ; q = next)
1066 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1067 next = q->next;
1068 free (q);
1071 queued_reg_saves = NULL;
1072 last_reg_save_label = NULL;
1075 static bool
1076 clobbers_queued_reg_save (insn)
1077 rtx insn;
1079 struct queued_reg_save *q;
1081 for (q = queued_reg_saves; q ; q = q->next)
1082 if (modified_in_p (q->reg, insn))
1083 return true;
1085 return false;
1089 /* A temporary register holding an integral value used in adjusting SP
1090 or setting up the store_reg. The "offset" field holds the integer
1091 value, not an offset. */
1092 static dw_cfa_location cfa_temp;
1094 /* Record call frame debugging information for an expression EXPR,
1095 which either sets SP or FP (adjusting how we calculate the frame
1096 address) or saves a register to the stack. LABEL indicates the
1097 address of EXPR.
1099 This function encodes a state machine mapping rtxes to actions on
1100 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1101 users need not read the source code.
1103 The High-Level Picture
1105 Changes in the register we use to calculate the CFA: Currently we
1106 assume that if you copy the CFA register into another register, we
1107 should take the other one as the new CFA register; this seems to
1108 work pretty well. If it's wrong for some target, it's simple
1109 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1111 Changes in the register we use for saving registers to the stack:
1112 This is usually SP, but not always. Again, we deduce that if you
1113 copy SP into another register (and SP is not the CFA register),
1114 then the new register is the one we will be using for register
1115 saves. This also seems to work.
1117 Register saves: There's not much guesswork about this one; if
1118 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1119 register save, and the register used to calculate the destination
1120 had better be the one we think we're using for this purpose.
1122 Except: If the register being saved is the CFA register, and the
1123 offset is non-zero, we are saving the CFA, so we assume we have to
1124 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1125 the intent is to save the value of SP from the previous frame.
1127 Invariants / Summaries of Rules
1129 cfa current rule for calculating the CFA. It usually
1130 consists of a register and an offset.
1131 cfa_store register used by prologue code to save things to the stack
1132 cfa_store.offset is the offset from the value of
1133 cfa_store.reg to the actual CFA
1134 cfa_temp register holding an integral value. cfa_temp.offset
1135 stores the value, which will be used to adjust the
1136 stack pointer. cfa_temp is also used like cfa_store,
1137 to track stores to the stack via fp or a temp reg.
1139 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1140 with cfa.reg as the first operand changes the cfa.reg and its
1141 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1142 cfa_temp.offset.
1144 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1145 expression yielding a constant. This sets cfa_temp.reg
1146 and cfa_temp.offset.
1148 Rule 5: Create a new register cfa_store used to save items to the
1149 stack.
1151 Rules 10-14: Save a register to the stack. Define offset as the
1152 difference of the original location and cfa_store's
1153 location (or cfa_temp's location if cfa_temp is used).
1155 The Rules
1157 "{a,b}" indicates a choice of a xor b.
1158 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1160 Rule 1:
1161 (set <reg1> <reg2>:cfa.reg)
1162 effects: cfa.reg = <reg1>
1163 cfa.offset unchanged
1164 cfa_temp.reg = <reg1>
1165 cfa_temp.offset = cfa.offset
1167 Rule 2:
1168 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1169 effects: cfa.reg = sp if fp used
1170 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1171 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1172 if cfa_store.reg==sp
1174 Rule 3:
1175 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1176 effects: cfa.reg = fp
1177 cfa_offset += +/- <const_int>
1179 Rule 4:
1180 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1181 constraints: <reg1> != fp
1182 <reg1> != sp
1183 effects: cfa.reg = <reg1>
1184 cfa_temp.reg = <reg1>
1185 cfa_temp.offset = cfa.offset
1187 Rule 5:
1188 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1189 constraints: <reg1> != fp
1190 <reg1> != sp
1191 effects: cfa_store.reg = <reg1>
1192 cfa_store.offset = cfa.offset - cfa_temp.offset
1194 Rule 6:
1195 (set <reg> <const_int>)
1196 effects: cfa_temp.reg = <reg>
1197 cfa_temp.offset = <const_int>
1199 Rule 7:
1200 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1201 effects: cfa_temp.reg = <reg1>
1202 cfa_temp.offset |= <const_int>
1204 Rule 8:
1205 (set <reg> (high <exp>))
1206 effects: none
1208 Rule 9:
1209 (set <reg> (lo_sum <exp> <const_int>))
1210 effects: cfa_temp.reg = <reg>
1211 cfa_temp.offset = <const_int>
1213 Rule 10:
1214 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1215 effects: cfa_store.offset -= <const_int>
1216 cfa.offset = cfa_store.offset if cfa.reg == sp
1217 cfa.reg = sp
1218 cfa.base_offset = -cfa_store.offset
1220 Rule 11:
1221 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1222 effects: cfa_store.offset += -/+ mode_size(mem)
1223 cfa.offset = cfa_store.offset if cfa.reg == sp
1224 cfa.reg = sp
1225 cfa.base_offset = -cfa_store.offset
1227 Rule 12:
1228 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>)
1229 effects: cfa.reg = <reg1>
1230 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1232 Rule 13:
1233 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1234 effects: cfa.reg = <reg1>
1235 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1237 Rule 14:
1238 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1239 effects: cfa.reg = <reg1>
1240 cfa.base_offset = -cfa_temp.offset
1241 cfa_temp.offset -= mode_size(mem) */
1243 static void
1244 dwarf2out_frame_debug_expr (expr, label)
1245 rtx expr;
1246 const char *label;
1248 rtx src, dest;
1249 long offset;
1251 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1252 the PARALLEL independently. The first element is always processed if
1253 it is a SET. This is for backward compatibility. Other elements
1254 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1255 flag is set in them. */
1257 if (GET_CODE (expr) == PARALLEL
1258 || GET_CODE (expr) == SEQUENCE)
1260 int par_index;
1261 int limit = XVECLEN (expr, 0);
1263 for (par_index = 0; par_index < limit; par_index++)
1265 rtx x = XVECEXP (expr, 0, par_index);
1267 if (GET_CODE (x) == SET &&
1268 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1269 dwarf2out_frame_debug_expr (x, label);
1271 return;
1274 if (GET_CODE (expr) != SET)
1275 abort ();
1277 src = SET_SRC (expr);
1278 dest = SET_DEST (expr);
1280 switch (GET_CODE (dest))
1282 case REG:
1283 /* Rule 1 */
1284 /* Update the CFA rule wrt SP or FP. Make sure src is
1285 relative to the current CFA register. */
1286 switch (GET_CODE (src))
1288 /* Setting FP from SP. */
1289 case REG:
1290 if (cfa.reg == (unsigned) REGNO (src))
1291 /* OK. */
1293 else
1294 abort ();
1296 /* We used to require that dest be either SP or FP, but the
1297 ARM copies SP to a temporary register, and from there to
1298 FP. So we just rely on the backends to only set
1299 RTX_FRAME_RELATED_P on appropriate insns. */
1300 cfa.reg = REGNO (dest);
1301 cfa_temp.reg = cfa.reg;
1302 cfa_temp.offset = cfa.offset;
1303 break;
1305 case PLUS:
1306 case MINUS:
1307 case LO_SUM:
1308 if (dest == stack_pointer_rtx)
1310 /* Rule 2 */
1311 /* Adjusting SP. */
1312 switch (GET_CODE (XEXP (src, 1)))
1314 case CONST_INT:
1315 offset = INTVAL (XEXP (src, 1));
1316 break;
1317 case REG:
1318 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1319 abort ();
1320 offset = cfa_temp.offset;
1321 break;
1322 default:
1323 abort ();
1326 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1328 /* Restoring SP from FP in the epilogue. */
1329 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1330 abort ();
1331 cfa.reg = STACK_POINTER_REGNUM;
1333 else if (GET_CODE (src) == LO_SUM)
1334 /* Assume we've set the source reg of the LO_SUM from sp. */
1336 else if (XEXP (src, 0) != stack_pointer_rtx)
1337 abort ();
1339 if (GET_CODE (src) != MINUS)
1340 offset = -offset;
1341 if (cfa.reg == STACK_POINTER_REGNUM)
1342 cfa.offset += offset;
1343 if (cfa_store.reg == STACK_POINTER_REGNUM)
1344 cfa_store.offset += offset;
1346 else if (dest == hard_frame_pointer_rtx)
1348 /* Rule 3 */
1349 /* Either setting the FP from an offset of the SP,
1350 or adjusting the FP */
1351 if (! frame_pointer_needed)
1352 abort ();
1354 if (GET_CODE (XEXP (src, 0)) == REG
1355 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1356 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1358 offset = INTVAL (XEXP (src, 1));
1359 if (GET_CODE (src) != MINUS)
1360 offset = -offset;
1361 cfa.offset += offset;
1362 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1364 else
1365 abort ();
1367 else
1369 if (GET_CODE (src) == MINUS)
1370 abort ();
1372 /* Rule 4 */
1373 if (GET_CODE (XEXP (src, 0)) == REG
1374 && REGNO (XEXP (src, 0)) == cfa.reg
1375 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1377 /* Setting a temporary CFA register that will be copied
1378 into the FP later on. */
1379 offset = - INTVAL (XEXP (src, 1));
1380 cfa.offset += offset;
1381 cfa.reg = REGNO (dest);
1382 /* Or used to save regs to the stack. */
1383 cfa_temp.reg = cfa.reg;
1384 cfa_temp.offset = cfa.offset;
1386 /* Rule 5 */
1387 else if (GET_CODE (XEXP (src, 0)) == REG
1388 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1389 && XEXP (src, 1) == stack_pointer_rtx)
1391 /* Setting a scratch register that we will use instead
1392 of SP for saving registers to the stack. */
1393 if (cfa.reg != STACK_POINTER_REGNUM)
1394 abort ();
1395 cfa_store.reg = REGNO (dest);
1396 cfa_store.offset = cfa.offset - cfa_temp.offset;
1398 /* Rule 9 */
1399 else if (GET_CODE (src) == LO_SUM
1400 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1402 cfa_temp.reg = REGNO (dest);
1403 cfa_temp.offset = INTVAL (XEXP (src, 1));
1405 else
1406 abort ();
1408 break;
1410 /* Rule 6 */
1411 case CONST_INT:
1412 cfa_temp.reg = REGNO (dest);
1413 cfa_temp.offset = INTVAL (src);
1414 break;
1416 /* Rule 7 */
1417 case IOR:
1418 if (GET_CODE (XEXP (src, 0)) != REG
1419 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1420 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1421 abort ();
1422 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1423 cfa_temp.reg = REGNO (dest);
1424 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1425 break;
1427 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1428 which will fill in all of the bits. */
1429 /* Rule 8 */
1430 case HIGH:
1431 break;
1433 default:
1434 abort ();
1436 def_cfa_1 (label, &cfa);
1437 break;
1439 case MEM:
1440 if (GET_CODE (src) != REG)
1441 abort ();
1443 /* Saving a register to the stack. Make sure dest is relative to the
1444 CFA register. */
1445 switch (GET_CODE (XEXP (dest, 0)))
1447 /* Rule 10 */
1448 /* With a push. */
1449 case PRE_MODIFY:
1450 /* We can't handle variable size modifications. */
1451 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1452 abort();
1453 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1455 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1456 || cfa_store.reg != STACK_POINTER_REGNUM)
1457 abort ();
1458 cfa_store.offset += offset;
1459 if (cfa.reg == STACK_POINTER_REGNUM)
1460 cfa.offset = cfa_store.offset;
1462 offset = -cfa_store.offset;
1463 break;
1464 /* Rule 11 */
1465 case PRE_INC:
1466 case PRE_DEC:
1467 offset = GET_MODE_SIZE (GET_MODE (dest));
1468 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1469 offset = -offset;
1471 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1472 || cfa_store.reg != STACK_POINTER_REGNUM)
1473 abort ();
1474 cfa_store.offset += offset;
1475 if (cfa.reg == STACK_POINTER_REGNUM)
1476 cfa.offset = cfa_store.offset;
1478 offset = -cfa_store.offset;
1479 break;
1481 /* Rule 12 */
1482 /* With an offset. */
1483 case PLUS:
1484 case MINUS:
1485 case LO_SUM:
1486 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1487 abort ();
1488 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1489 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1490 offset = -offset;
1492 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1493 offset -= cfa_store.offset;
1494 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1495 offset -= cfa_temp.offset;
1496 else
1497 abort ();
1498 break;
1500 /* Rule 13 */
1501 /* Without an offset. */
1502 case REG:
1503 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1504 offset = -cfa_store.offset;
1505 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1506 offset = -cfa_temp.offset;
1507 else
1508 abort ();
1509 break;
1511 /* Rule 14 */
1512 case POST_INC:
1513 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1514 abort ();
1515 offset = -cfa_temp.offset;
1516 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1517 break;
1519 default:
1520 abort ();
1523 if (REGNO (src) != STACK_POINTER_REGNUM
1524 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1525 && (unsigned) REGNO (src) == cfa.reg)
1527 /* We're storing the current CFA reg into the stack. */
1529 if (cfa.offset == 0)
1531 /* If the source register is exactly the CFA, assume
1532 we're saving SP like any other register; this happens
1533 on the ARM. */
1535 def_cfa_1 (label, &cfa);
1536 queue_reg_save (label, stack_pointer_rtx, offset);
1537 break;
1539 else
1541 /* Otherwise, we'll need to look in the stack to
1542 calculate the CFA. */
1544 rtx x = XEXP (dest, 0);
1545 if (GET_CODE (x) != REG)
1546 x = XEXP (x, 0);
1547 if (GET_CODE (x) != REG)
1548 abort ();
1549 cfa.reg = (unsigned) REGNO (x);
1550 cfa.base_offset = offset;
1551 cfa.indirect = 1;
1552 def_cfa_1 (label, &cfa);
1553 break;
1557 def_cfa_1 (label, &cfa);
1558 queue_reg_save (label, src, offset);
1559 break;
1561 default:
1562 abort ();
1566 /* Record call frame debugging information for INSN, which either
1567 sets SP or FP (adjusting how we calculate the frame address) or saves a
1568 register to the stack. If INSN is NULL_RTX, initialize our state. */
1570 void
1571 dwarf2out_frame_debug (insn)
1572 rtx insn;
1574 const char *label;
1575 rtx src;
1577 if (insn == NULL_RTX)
1579 /* Flush any queued register saves. */
1580 flush_queued_reg_saves ();
1582 /* Set up state for generating call frame debug info. */
1583 lookup_cfa (&cfa);
1584 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1585 abort ();
1586 cfa.reg = STACK_POINTER_REGNUM;
1587 cfa_store = cfa;
1588 cfa_temp.reg = -1;
1589 cfa_temp.offset = 0;
1590 return;
1593 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1594 flush_queued_reg_saves ();
1596 if (! RTX_FRAME_RELATED_P (insn))
1598 if (!ACCUMULATE_OUTGOING_ARGS)
1599 dwarf2out_stack_adjust (insn);
1600 return;
1603 label = dwarf2out_cfi_label ();
1605 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1606 if (src)
1607 insn = XEXP (src, 0);
1608 else
1609 insn = PATTERN (insn);
1611 dwarf2out_frame_debug_expr (insn, label);
1614 /* Output a Call Frame Information opcode and its operand(s). */
1616 static void
1617 output_cfi (cfi, fde, for_eh)
1618 register dw_cfi_ref cfi;
1619 register dw_fde_ref fde;
1620 int for_eh;
1622 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1624 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1625 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1626 "DW_CFA_advance_loc 0x%lx",
1627 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1629 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1631 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1632 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1633 "DW_CFA_offset, column 0x%lx",
1634 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1635 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1637 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1639 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1640 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1641 "DW_CFA_restore, column 0x%lx",
1642 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1644 else
1646 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1647 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1649 switch (cfi->dw_cfi_opc)
1651 case DW_CFA_set_loc:
1652 dw2_asm_output_addr ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE),
1653 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1654 break;
1655 case DW_CFA_advance_loc1:
1656 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1657 fde->dw_fde_current_label, NULL);
1658 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1659 break;
1660 case DW_CFA_advance_loc2:
1661 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1662 fde->dw_fde_current_label, NULL);
1663 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1664 break;
1665 case DW_CFA_advance_loc4:
1666 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1667 fde->dw_fde_current_label, NULL);
1668 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1669 break;
1670 case DW_CFA_MIPS_advance_loc8:
1671 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1672 fde->dw_fde_current_label, NULL);
1673 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1674 break;
1675 case DW_CFA_offset_extended:
1676 case DW_CFA_GNU_negative_offset_extended:
1677 case DW_CFA_def_cfa:
1678 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1679 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1680 break;
1681 case DW_CFA_restore_extended:
1682 case DW_CFA_undefined:
1683 case DW_CFA_same_value:
1684 case DW_CFA_def_cfa_register:
1685 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1686 break;
1687 case DW_CFA_register:
1688 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1689 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1690 break;
1691 case DW_CFA_def_cfa_offset:
1692 case DW_CFA_GNU_args_size:
1693 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1694 break;
1695 case DW_CFA_GNU_window_save:
1696 break;
1697 case DW_CFA_def_cfa_expression:
1698 output_cfa_loc (cfi);
1699 break;
1700 default:
1701 break;
1706 /* Output the call frame information used to used to record information
1707 that relates to calculating the frame pointer, and records the
1708 location of saved registers. */
1710 static void
1711 output_call_frame_info (for_eh)
1712 int for_eh;
1714 register unsigned long i;
1715 register dw_fde_ref fde;
1716 register dw_cfi_ref cfi;
1717 char l1[20], l2[20];
1718 int any_lsda_needed = 0;
1719 char augmentation[6];
1721 /* If we don't have any functions we'll want to unwind out of, don't
1722 emit any EH unwind information. */
1723 if (for_eh)
1725 int any_eh_needed = 0;
1726 for (i = 0; i < fde_table_in_use; ++i)
1727 if (fde_table[i].uses_eh_lsda)
1728 any_eh_needed = any_lsda_needed = 1;
1729 else if (! fde_table[i].nothrow)
1730 any_eh_needed = 1;
1732 if (! any_eh_needed)
1733 return;
1736 /* We're going to be generating comments, so turn on app. */
1737 if (flag_debug_asm)
1738 app_enable ();
1740 if (for_eh)
1742 #ifdef EH_FRAME_SECTION
1743 EH_FRAME_SECTION ();
1744 #else
1745 tree label = get_file_function_name ('F');
1747 force_data_section ();
1748 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1749 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1750 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1751 #endif
1752 assemble_label ("__FRAME_BEGIN__");
1754 else
1755 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1757 /* Output the CIE. */
1758 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1759 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1760 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1761 "Length of Common Information Entry");
1762 ASM_OUTPUT_LABEL (asm_out_file, l1);
1764 /* Now that the CIE pointer is PC-relative for EH,
1765 use 0 to identify the CIE. */
1766 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1767 (for_eh ? 0 : DW_CIE_ID),
1768 "CIE Identifier Tag");
1770 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1772 augmentation[0] = 0;
1773 if (for_eh)
1775 /* Augmentation:
1776 z Indicates that a uleb128 is present to size the
1777 augmentation section.
1778 R Indicates a pointer encoding for CIE and FDE pointers.
1779 P Indicates the presence of a language personality
1780 routine in the CIE augmentation and an LSDA in the
1781 FDE augmentation. */
1783 /* ??? Handle pointer encodings. */
1785 if (any_lsda_needed)
1786 strcpy (augmentation, "zP");
1788 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1790 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1792 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1793 "CIE Data Alignment Factor");
1795 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1797 if (augmentation[0])
1799 dw2_asm_output_data_uleb128 (PTR_SIZE, "Augmentation size");
1800 if (eh_personality_libfunc)
1801 dw2_asm_output_addr_rtx (PTR_SIZE, eh_personality_libfunc,
1802 "Personality");
1803 else
1804 dw2_asm_output_data (PTR_SIZE, 0, "Personality (none)");
1807 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1808 output_cfi (cfi, NULL, for_eh);
1810 /* Pad the CIE out to an address sized boundary. */
1811 ASM_OUTPUT_ALIGN (asm_out_file,
1812 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1813 ASM_OUTPUT_LABEL (asm_out_file, l2);
1815 /* Loop through all of the FDE's. */
1816 for (i = 0; i < fde_table_in_use; ++i)
1818 fde = &fde_table[i];
1820 /* Don't emit EH unwind info for leaf functions that don't need it. */
1821 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1822 continue;
1824 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1825 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1826 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1827 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1828 "FDE Length");
1829 ASM_OUTPUT_LABEL (asm_out_file, l1);
1831 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1832 emits a target dependent sized offset when for_eh is not true.
1833 This inconsistency may confuse gdb. The only case where we need a
1834 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1835 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1836 though in order to be compatible with the dwarf_fde struct in frame.c.
1837 If the for_eh case is changed, then the struct in frame.c has
1838 to be adjusted appropriately. */
1839 if (for_eh)
1840 dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset");
1841 else
1842 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
1843 stripattributes (FRAME_SECTION),
1844 "FDE CIE offset");
1846 dw2_asm_output_addr ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE),
1847 fde->dw_fde_begin,
1848 "FDE initial location");
1850 dw2_asm_output_delta ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE),
1851 fde->dw_fde_end,
1852 fde->dw_fde_begin,
1853 "FDE address range");
1855 if (augmentation[0])
1857 dw2_asm_output_data_uleb128 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE),
1858 "Augmentation size");
1860 if (fde->uses_eh_lsda)
1862 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA", fde->funcdef_number);
1863 dw2_asm_output_offset ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE),
1864 l1, "Language Specific Data Area");
1866 else
1867 dw2_asm_output_data ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE),
1868 0, "Language Specific Data Area (none)");
1871 /* Loop through the Call Frame Instructions associated with
1872 this FDE. */
1873 fde->dw_fde_current_label = fde->dw_fde_begin;
1874 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1875 output_cfi (cfi, fde, for_eh);
1877 /* Pad the FDE out to an address sized boundary. */
1878 ASM_OUTPUT_ALIGN (asm_out_file,
1879 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1880 ASM_OUTPUT_LABEL (asm_out_file, l2);
1883 #ifndef EH_FRAME_SECTION
1884 if (for_eh)
1885 dw2_asm_output_data (4, 0, "End of Table");
1886 #endif
1887 #ifdef MIPS_DEBUGGING_INFO
1888 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1889 get a value of 0. Putting .align 0 after the label fixes it. */
1890 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1891 #endif
1893 /* Turn off app to make assembly quicker. */
1894 if (flag_debug_asm)
1895 app_disable ();
1898 /* Output a marker (i.e. a label) for the beginning of a function, before
1899 the prologue. */
1901 void
1902 dwarf2out_begin_prologue ()
1904 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1905 register dw_fde_ref fde;
1907 ++current_funcdef_number;
1909 function_section (current_function_decl);
1910 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1911 current_funcdef_number);
1912 ASM_OUTPUT_LABEL (asm_out_file, label);
1913 current_function_func_begin_label = get_identifier (label);
1915 /* Expand the fde table if necessary. */
1916 if (fde_table_in_use == fde_table_allocated)
1918 fde_table_allocated += FDE_TABLE_INCREMENT;
1919 fde_table
1920 = (dw_fde_ref) xrealloc (fde_table,
1921 fde_table_allocated * sizeof (dw_fde_node));
1924 /* Record the FDE associated with this function. */
1925 current_funcdef_fde = fde_table_in_use;
1927 /* Add the new FDE at the end of the fde_table. */
1928 fde = &fde_table[fde_table_in_use++];
1929 fde->dw_fde_begin = xstrdup (label);
1930 fde->dw_fde_current_label = NULL;
1931 fde->dw_fde_end = NULL;
1932 fde->dw_fde_cfi = NULL;
1933 fde->funcdef_number = current_funcdef_number;
1934 fde->nothrow = current_function_nothrow;
1935 fde->uses_eh_lsda = cfun->uses_eh_lsda;
1937 args_size = old_args_size = 0;
1940 /* Output a marker (i.e. a label) for the absolute end of the generated code
1941 for a function definition. This gets called *after* the epilogue code has
1942 been generated. */
1944 void
1945 dwarf2out_end_epilogue ()
1947 dw_fde_ref fde;
1948 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1950 /* Output a label to mark the endpoint of the code generated for this
1951 function. */
1952 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1953 ASM_OUTPUT_LABEL (asm_out_file, label);
1954 fde = &fde_table[fde_table_in_use - 1];
1955 fde->dw_fde_end = xstrdup (label);
1958 void
1959 dwarf2out_frame_init ()
1961 /* Allocate the initial hunk of the fde_table. */
1962 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
1963 fde_table_allocated = FDE_TABLE_INCREMENT;
1964 fde_table_in_use = 0;
1966 /* Generate the CFA instructions common to all FDE's. Do it now for the
1967 sake of lookup_cfa. */
1969 #ifdef DWARF2_UNWIND_INFO
1970 /* On entry, the Canonical Frame Address is at SP. */
1971 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1972 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1973 #endif
1976 void
1977 dwarf2out_frame_finish ()
1979 /* Output call frame information. */
1980 #ifdef MIPS_DEBUGGING_INFO
1981 if (write_symbols == DWARF2_DEBUG)
1982 output_call_frame_info (0);
1983 if (flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
1984 output_call_frame_info (1);
1985 #else
1986 if (write_symbols == DWARF2_DEBUG
1987 || flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
1988 output_call_frame_info (1);
1989 #endif
1992 /* And now, the subset of the debugging information support code necessary
1993 for emitting location expressions. */
1995 typedef struct dw_val_struct *dw_val_ref;
1996 typedef struct die_struct *dw_die_ref;
1997 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1999 /* Each DIE may have a series of attribute/value pairs. Values
2000 can take on several forms. The forms that are used in this
2001 implementation are listed below. */
2003 typedef enum
2005 dw_val_class_addr,
2006 dw_val_class_loc,
2007 dw_val_class_const,
2008 dw_val_class_unsigned_const,
2009 dw_val_class_long_long,
2010 dw_val_class_float,
2011 dw_val_class_flag,
2012 dw_val_class_die_ref,
2013 dw_val_class_fde_ref,
2014 dw_val_class_lbl_id,
2015 dw_val_class_lbl_offset,
2016 dw_val_class_str
2018 dw_val_class;
2020 /* Describe a double word constant value. */
2021 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2023 typedef struct dw_long_long_struct
2025 unsigned long hi;
2026 unsigned long low;
2028 dw_long_long_const;
2030 /* Describe a floating point constant value. */
2032 typedef struct dw_fp_struct
2034 long *array;
2035 unsigned length;
2037 dw_float_const;
2039 /* The dw_val_node describes an attribute's value, as it is
2040 represented internally. */
2042 typedef struct dw_val_struct
2044 dw_val_class val_class;
2045 union
2047 rtx val_addr;
2048 dw_loc_descr_ref val_loc;
2049 long int val_int;
2050 long unsigned val_unsigned;
2051 dw_long_long_const val_long_long;
2052 dw_float_const val_float;
2053 struct {
2054 dw_die_ref die;
2055 int external;
2056 } val_die_ref;
2057 unsigned val_fde_index;
2058 char *val_str;
2059 char *val_lbl_id;
2060 unsigned char val_flag;
2064 dw_val_node;
2066 /* Locations in memory are described using a sequence of stack machine
2067 operations. */
2069 typedef struct dw_loc_descr_struct
2071 dw_loc_descr_ref dw_loc_next;
2072 enum dwarf_location_atom dw_loc_opc;
2073 dw_val_node dw_loc_oprnd1;
2074 dw_val_node dw_loc_oprnd2;
2075 int dw_loc_addr;
2077 dw_loc_descr_node;
2079 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2080 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2081 unsigned long,
2082 unsigned long));
2083 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2084 dw_loc_descr_ref));
2085 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2086 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2087 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2088 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2090 /* Convert a DWARF stack opcode into its string name. */
2092 static const char *
2093 dwarf_stack_op_name (op)
2094 register unsigned op;
2096 switch (op)
2098 case DW_OP_addr:
2099 return "DW_OP_addr";
2100 case DW_OP_deref:
2101 return "DW_OP_deref";
2102 case DW_OP_const1u:
2103 return "DW_OP_const1u";
2104 case DW_OP_const1s:
2105 return "DW_OP_const1s";
2106 case DW_OP_const2u:
2107 return "DW_OP_const2u";
2108 case DW_OP_const2s:
2109 return "DW_OP_const2s";
2110 case DW_OP_const4u:
2111 return "DW_OP_const4u";
2112 case DW_OP_const4s:
2113 return "DW_OP_const4s";
2114 case DW_OP_const8u:
2115 return "DW_OP_const8u";
2116 case DW_OP_const8s:
2117 return "DW_OP_const8s";
2118 case DW_OP_constu:
2119 return "DW_OP_constu";
2120 case DW_OP_consts:
2121 return "DW_OP_consts";
2122 case DW_OP_dup:
2123 return "DW_OP_dup";
2124 case DW_OP_drop:
2125 return "DW_OP_drop";
2126 case DW_OP_over:
2127 return "DW_OP_over";
2128 case DW_OP_pick:
2129 return "DW_OP_pick";
2130 case DW_OP_swap:
2131 return "DW_OP_swap";
2132 case DW_OP_rot:
2133 return "DW_OP_rot";
2134 case DW_OP_xderef:
2135 return "DW_OP_xderef";
2136 case DW_OP_abs:
2137 return "DW_OP_abs";
2138 case DW_OP_and:
2139 return "DW_OP_and";
2140 case DW_OP_div:
2141 return "DW_OP_div";
2142 case DW_OP_minus:
2143 return "DW_OP_minus";
2144 case DW_OP_mod:
2145 return "DW_OP_mod";
2146 case DW_OP_mul:
2147 return "DW_OP_mul";
2148 case DW_OP_neg:
2149 return "DW_OP_neg";
2150 case DW_OP_not:
2151 return "DW_OP_not";
2152 case DW_OP_or:
2153 return "DW_OP_or";
2154 case DW_OP_plus:
2155 return "DW_OP_plus";
2156 case DW_OP_plus_uconst:
2157 return "DW_OP_plus_uconst";
2158 case DW_OP_shl:
2159 return "DW_OP_shl";
2160 case DW_OP_shr:
2161 return "DW_OP_shr";
2162 case DW_OP_shra:
2163 return "DW_OP_shra";
2164 case DW_OP_xor:
2165 return "DW_OP_xor";
2166 case DW_OP_bra:
2167 return "DW_OP_bra";
2168 case DW_OP_eq:
2169 return "DW_OP_eq";
2170 case DW_OP_ge:
2171 return "DW_OP_ge";
2172 case DW_OP_gt:
2173 return "DW_OP_gt";
2174 case DW_OP_le:
2175 return "DW_OP_le";
2176 case DW_OP_lt:
2177 return "DW_OP_lt";
2178 case DW_OP_ne:
2179 return "DW_OP_ne";
2180 case DW_OP_skip:
2181 return "DW_OP_skip";
2182 case DW_OP_lit0:
2183 return "DW_OP_lit0";
2184 case DW_OP_lit1:
2185 return "DW_OP_lit1";
2186 case DW_OP_lit2:
2187 return "DW_OP_lit2";
2188 case DW_OP_lit3:
2189 return "DW_OP_lit3";
2190 case DW_OP_lit4:
2191 return "DW_OP_lit4";
2192 case DW_OP_lit5:
2193 return "DW_OP_lit5";
2194 case DW_OP_lit6:
2195 return "DW_OP_lit6";
2196 case DW_OP_lit7:
2197 return "DW_OP_lit7";
2198 case DW_OP_lit8:
2199 return "DW_OP_lit8";
2200 case DW_OP_lit9:
2201 return "DW_OP_lit9";
2202 case DW_OP_lit10:
2203 return "DW_OP_lit10";
2204 case DW_OP_lit11:
2205 return "DW_OP_lit11";
2206 case DW_OP_lit12:
2207 return "DW_OP_lit12";
2208 case DW_OP_lit13:
2209 return "DW_OP_lit13";
2210 case DW_OP_lit14:
2211 return "DW_OP_lit14";
2212 case DW_OP_lit15:
2213 return "DW_OP_lit15";
2214 case DW_OP_lit16:
2215 return "DW_OP_lit16";
2216 case DW_OP_lit17:
2217 return "DW_OP_lit17";
2218 case DW_OP_lit18:
2219 return "DW_OP_lit18";
2220 case DW_OP_lit19:
2221 return "DW_OP_lit19";
2222 case DW_OP_lit20:
2223 return "DW_OP_lit20";
2224 case DW_OP_lit21:
2225 return "DW_OP_lit21";
2226 case DW_OP_lit22:
2227 return "DW_OP_lit22";
2228 case DW_OP_lit23:
2229 return "DW_OP_lit23";
2230 case DW_OP_lit24:
2231 return "DW_OP_lit24";
2232 case DW_OP_lit25:
2233 return "DW_OP_lit25";
2234 case DW_OP_lit26:
2235 return "DW_OP_lit26";
2236 case DW_OP_lit27:
2237 return "DW_OP_lit27";
2238 case DW_OP_lit28:
2239 return "DW_OP_lit28";
2240 case DW_OP_lit29:
2241 return "DW_OP_lit29";
2242 case DW_OP_lit30:
2243 return "DW_OP_lit30";
2244 case DW_OP_lit31:
2245 return "DW_OP_lit31";
2246 case DW_OP_reg0:
2247 return "DW_OP_reg0";
2248 case DW_OP_reg1:
2249 return "DW_OP_reg1";
2250 case DW_OP_reg2:
2251 return "DW_OP_reg2";
2252 case DW_OP_reg3:
2253 return "DW_OP_reg3";
2254 case DW_OP_reg4:
2255 return "DW_OP_reg4";
2256 case DW_OP_reg5:
2257 return "DW_OP_reg5";
2258 case DW_OP_reg6:
2259 return "DW_OP_reg6";
2260 case DW_OP_reg7:
2261 return "DW_OP_reg7";
2262 case DW_OP_reg8:
2263 return "DW_OP_reg8";
2264 case DW_OP_reg9:
2265 return "DW_OP_reg9";
2266 case DW_OP_reg10:
2267 return "DW_OP_reg10";
2268 case DW_OP_reg11:
2269 return "DW_OP_reg11";
2270 case DW_OP_reg12:
2271 return "DW_OP_reg12";
2272 case DW_OP_reg13:
2273 return "DW_OP_reg13";
2274 case DW_OP_reg14:
2275 return "DW_OP_reg14";
2276 case DW_OP_reg15:
2277 return "DW_OP_reg15";
2278 case DW_OP_reg16:
2279 return "DW_OP_reg16";
2280 case DW_OP_reg17:
2281 return "DW_OP_reg17";
2282 case DW_OP_reg18:
2283 return "DW_OP_reg18";
2284 case DW_OP_reg19:
2285 return "DW_OP_reg19";
2286 case DW_OP_reg20:
2287 return "DW_OP_reg20";
2288 case DW_OP_reg21:
2289 return "DW_OP_reg21";
2290 case DW_OP_reg22:
2291 return "DW_OP_reg22";
2292 case DW_OP_reg23:
2293 return "DW_OP_reg23";
2294 case DW_OP_reg24:
2295 return "DW_OP_reg24";
2296 case DW_OP_reg25:
2297 return "DW_OP_reg25";
2298 case DW_OP_reg26:
2299 return "DW_OP_reg26";
2300 case DW_OP_reg27:
2301 return "DW_OP_reg27";
2302 case DW_OP_reg28:
2303 return "DW_OP_reg28";
2304 case DW_OP_reg29:
2305 return "DW_OP_reg29";
2306 case DW_OP_reg30:
2307 return "DW_OP_reg30";
2308 case DW_OP_reg31:
2309 return "DW_OP_reg31";
2310 case DW_OP_breg0:
2311 return "DW_OP_breg0";
2312 case DW_OP_breg1:
2313 return "DW_OP_breg1";
2314 case DW_OP_breg2:
2315 return "DW_OP_breg2";
2316 case DW_OP_breg3:
2317 return "DW_OP_breg3";
2318 case DW_OP_breg4:
2319 return "DW_OP_breg4";
2320 case DW_OP_breg5:
2321 return "DW_OP_breg5";
2322 case DW_OP_breg6:
2323 return "DW_OP_breg6";
2324 case DW_OP_breg7:
2325 return "DW_OP_breg7";
2326 case DW_OP_breg8:
2327 return "DW_OP_breg8";
2328 case DW_OP_breg9:
2329 return "DW_OP_breg9";
2330 case DW_OP_breg10:
2331 return "DW_OP_breg10";
2332 case DW_OP_breg11:
2333 return "DW_OP_breg11";
2334 case DW_OP_breg12:
2335 return "DW_OP_breg12";
2336 case DW_OP_breg13:
2337 return "DW_OP_breg13";
2338 case DW_OP_breg14:
2339 return "DW_OP_breg14";
2340 case DW_OP_breg15:
2341 return "DW_OP_breg15";
2342 case DW_OP_breg16:
2343 return "DW_OP_breg16";
2344 case DW_OP_breg17:
2345 return "DW_OP_breg17";
2346 case DW_OP_breg18:
2347 return "DW_OP_breg18";
2348 case DW_OP_breg19:
2349 return "DW_OP_breg19";
2350 case DW_OP_breg20:
2351 return "DW_OP_breg20";
2352 case DW_OP_breg21:
2353 return "DW_OP_breg21";
2354 case DW_OP_breg22:
2355 return "DW_OP_breg22";
2356 case DW_OP_breg23:
2357 return "DW_OP_breg23";
2358 case DW_OP_breg24:
2359 return "DW_OP_breg24";
2360 case DW_OP_breg25:
2361 return "DW_OP_breg25";
2362 case DW_OP_breg26:
2363 return "DW_OP_breg26";
2364 case DW_OP_breg27:
2365 return "DW_OP_breg27";
2366 case DW_OP_breg28:
2367 return "DW_OP_breg28";
2368 case DW_OP_breg29:
2369 return "DW_OP_breg29";
2370 case DW_OP_breg30:
2371 return "DW_OP_breg30";
2372 case DW_OP_breg31:
2373 return "DW_OP_breg31";
2374 case DW_OP_regx:
2375 return "DW_OP_regx";
2376 case DW_OP_fbreg:
2377 return "DW_OP_fbreg";
2378 case DW_OP_bregx:
2379 return "DW_OP_bregx";
2380 case DW_OP_piece:
2381 return "DW_OP_piece";
2382 case DW_OP_deref_size:
2383 return "DW_OP_deref_size";
2384 case DW_OP_xderef_size:
2385 return "DW_OP_xderef_size";
2386 case DW_OP_nop:
2387 return "DW_OP_nop";
2388 default:
2389 return "OP_<unknown>";
2393 /* Return a pointer to a newly allocated location description. Location
2394 descriptions are simple expression terms that can be strung
2395 together to form more complicated location (address) descriptions. */
2397 static inline dw_loc_descr_ref
2398 new_loc_descr (op, oprnd1, oprnd2)
2399 register enum dwarf_location_atom op;
2400 register unsigned long oprnd1;
2401 register unsigned long oprnd2;
2403 /* Use xcalloc here so we clear out all of the long_long constant in
2404 the union. */
2405 register dw_loc_descr_ref descr
2406 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2408 descr->dw_loc_opc = op;
2409 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2410 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2411 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2412 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2414 return descr;
2417 /* Add a location description term to a location description expression. */
2419 static inline void
2420 add_loc_descr (list_head, descr)
2421 register dw_loc_descr_ref *list_head;
2422 register dw_loc_descr_ref descr;
2424 register dw_loc_descr_ref *d;
2426 /* Find the end of the chain. */
2427 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2430 *d = descr;
2433 /* Return the size of a location descriptor. */
2435 static unsigned long
2436 size_of_loc_descr (loc)
2437 register dw_loc_descr_ref loc;
2439 register unsigned long size = 1;
2441 switch (loc->dw_loc_opc)
2443 case DW_OP_addr:
2444 size += DWARF2_ADDR_SIZE;
2445 break;
2446 case DW_OP_const1u:
2447 case DW_OP_const1s:
2448 size += 1;
2449 break;
2450 case DW_OP_const2u:
2451 case DW_OP_const2s:
2452 size += 2;
2453 break;
2454 case DW_OP_const4u:
2455 case DW_OP_const4s:
2456 size += 4;
2457 break;
2458 case DW_OP_const8u:
2459 case DW_OP_const8s:
2460 size += 8;
2461 break;
2462 case DW_OP_constu:
2463 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2464 break;
2465 case DW_OP_consts:
2466 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2467 break;
2468 case DW_OP_pick:
2469 size += 1;
2470 break;
2471 case DW_OP_plus_uconst:
2472 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2473 break;
2474 case DW_OP_skip:
2475 case DW_OP_bra:
2476 size += 2;
2477 break;
2478 case DW_OP_breg0:
2479 case DW_OP_breg1:
2480 case DW_OP_breg2:
2481 case DW_OP_breg3:
2482 case DW_OP_breg4:
2483 case DW_OP_breg5:
2484 case DW_OP_breg6:
2485 case DW_OP_breg7:
2486 case DW_OP_breg8:
2487 case DW_OP_breg9:
2488 case DW_OP_breg10:
2489 case DW_OP_breg11:
2490 case DW_OP_breg12:
2491 case DW_OP_breg13:
2492 case DW_OP_breg14:
2493 case DW_OP_breg15:
2494 case DW_OP_breg16:
2495 case DW_OP_breg17:
2496 case DW_OP_breg18:
2497 case DW_OP_breg19:
2498 case DW_OP_breg20:
2499 case DW_OP_breg21:
2500 case DW_OP_breg22:
2501 case DW_OP_breg23:
2502 case DW_OP_breg24:
2503 case DW_OP_breg25:
2504 case DW_OP_breg26:
2505 case DW_OP_breg27:
2506 case DW_OP_breg28:
2507 case DW_OP_breg29:
2508 case DW_OP_breg30:
2509 case DW_OP_breg31:
2510 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2511 break;
2512 case DW_OP_regx:
2513 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2514 break;
2515 case DW_OP_fbreg:
2516 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2517 break;
2518 case DW_OP_bregx:
2519 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2520 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2521 break;
2522 case DW_OP_piece:
2523 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2524 break;
2525 case DW_OP_deref_size:
2526 case DW_OP_xderef_size:
2527 size += 1;
2528 break;
2529 default:
2530 break;
2533 return size;
2536 /* Return the size of a series of location descriptors. */
2538 static unsigned long
2539 size_of_locs (loc)
2540 register dw_loc_descr_ref loc;
2542 register unsigned long size = 0;
2544 for (; loc != NULL; loc = loc->dw_loc_next)
2546 loc->dw_loc_addr = size;
2547 size += size_of_loc_descr (loc);
2550 return size;
2553 /* Output location description stack opcode's operands (if any). */
2555 static void
2556 output_loc_operands (loc)
2557 register dw_loc_descr_ref loc;
2559 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2560 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2562 switch (loc->dw_loc_opc)
2564 #ifdef DWARF2_DEBUGGING_INFO
2565 case DW_OP_addr:
2566 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2567 break;
2568 case DW_OP_const2u:
2569 case DW_OP_const2s:
2570 dw2_asm_output_data (2, val1->v.val_int, NULL);
2571 break;
2572 case DW_OP_const4u:
2573 case DW_OP_const4s:
2574 dw2_asm_output_data (4, val1->v.val_int, NULL);
2575 break;
2576 case DW_OP_const8u:
2577 case DW_OP_const8s:
2578 if (HOST_BITS_PER_LONG < 64)
2579 abort ();
2580 dw2_asm_output_data (8, val1->v.val_int, NULL);
2581 break;
2582 case DW_OP_skip:
2583 case DW_OP_bra:
2585 int offset;
2587 if (val1->val_class == dw_val_class_loc)
2588 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2589 else
2590 abort ();
2592 dw2_asm_output_data (2, offset, NULL);
2594 break;
2595 #else
2596 case DW_OP_addr:
2597 case DW_OP_const2u:
2598 case DW_OP_const2s:
2599 case DW_OP_const4u:
2600 case DW_OP_const4s:
2601 case DW_OP_const8u:
2602 case DW_OP_const8s:
2603 case DW_OP_skip:
2604 case DW_OP_bra:
2605 /* We currently don't make any attempt to make sure these are
2606 aligned properly like we do for the main unwind info, so
2607 don't support emitting things larger than a byte if we're
2608 only doing unwinding. */
2609 abort ();
2610 #endif
2611 case DW_OP_const1u:
2612 case DW_OP_const1s:
2613 dw2_asm_output_data (1, val1->v.val_int, NULL);
2614 break;
2615 case DW_OP_constu:
2616 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2617 break;
2618 case DW_OP_consts:
2619 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2620 break;
2621 case DW_OP_pick:
2622 dw2_asm_output_data (1, val1->v.val_int, NULL);
2623 break;
2624 case DW_OP_plus_uconst:
2625 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2626 break;
2627 case DW_OP_breg0:
2628 case DW_OP_breg1:
2629 case DW_OP_breg2:
2630 case DW_OP_breg3:
2631 case DW_OP_breg4:
2632 case DW_OP_breg5:
2633 case DW_OP_breg6:
2634 case DW_OP_breg7:
2635 case DW_OP_breg8:
2636 case DW_OP_breg9:
2637 case DW_OP_breg10:
2638 case DW_OP_breg11:
2639 case DW_OP_breg12:
2640 case DW_OP_breg13:
2641 case DW_OP_breg14:
2642 case DW_OP_breg15:
2643 case DW_OP_breg16:
2644 case DW_OP_breg17:
2645 case DW_OP_breg18:
2646 case DW_OP_breg19:
2647 case DW_OP_breg20:
2648 case DW_OP_breg21:
2649 case DW_OP_breg22:
2650 case DW_OP_breg23:
2651 case DW_OP_breg24:
2652 case DW_OP_breg25:
2653 case DW_OP_breg26:
2654 case DW_OP_breg27:
2655 case DW_OP_breg28:
2656 case DW_OP_breg29:
2657 case DW_OP_breg30:
2658 case DW_OP_breg31:
2659 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2660 break;
2661 case DW_OP_regx:
2662 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2663 break;
2664 case DW_OP_fbreg:
2665 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2666 break;
2667 case DW_OP_bregx:
2668 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2669 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2670 break;
2671 case DW_OP_piece:
2672 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2673 break;
2674 case DW_OP_deref_size:
2675 case DW_OP_xderef_size:
2676 dw2_asm_output_data (1, val1->v.val_int, NULL);
2677 break;
2678 default:
2679 /* Other codes have no operands. */
2680 break;
2684 /* Output a sequence of location operations. */
2686 static void
2687 output_loc_sequence (loc)
2688 dw_loc_descr_ref loc;
2690 for (; loc != NULL; loc = loc->dw_loc_next)
2692 /* Output the opcode. */
2693 dw2_asm_output_data (1, loc->dw_loc_opc,
2694 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2696 /* Output the operand(s) (if any). */
2697 output_loc_operands (loc);
2701 /* This routine will generate the correct assembly data for a location
2702 description based on a cfi entry with a complex address. */
2704 static void
2705 output_cfa_loc (cfi)
2706 dw_cfi_ref cfi;
2708 dw_loc_descr_ref loc;
2709 unsigned long size;
2711 /* Output the size of the block. */
2712 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2713 size = size_of_locs (loc);
2714 dw2_asm_output_data_uleb128 (size, NULL);
2716 /* Now output the operations themselves. */
2717 output_loc_sequence (loc);
2720 /* This function builds a dwarf location descriptor seqeunce from
2721 a dw_cfa_location. */
2723 static struct dw_loc_descr_struct *
2724 build_cfa_loc (cfa)
2725 dw_cfa_location *cfa;
2727 struct dw_loc_descr_struct *head, *tmp;
2729 if (cfa->indirect == 0)
2730 abort ();
2732 if (cfa->base_offset)
2734 if (cfa->reg <= 31)
2735 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2736 else
2737 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2739 else if (cfa->reg <= 31)
2740 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2741 else
2742 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2743 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2744 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2745 add_loc_descr (&head, tmp);
2746 if (cfa->offset != 0)
2748 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2749 add_loc_descr (&head, tmp);
2751 return head;
2754 /* This function fills in aa dw_cfa_location structure from a
2755 dwarf location descriptor sequence. */
2757 static void
2758 get_cfa_from_loc_descr (cfa, loc)
2759 dw_cfa_location *cfa;
2760 struct dw_loc_descr_struct *loc;
2762 struct dw_loc_descr_struct *ptr;
2763 cfa->offset = 0;
2764 cfa->base_offset = 0;
2765 cfa->indirect = 0;
2766 cfa->reg = -1;
2768 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2770 enum dwarf_location_atom op = ptr->dw_loc_opc;
2771 switch (op)
2773 case DW_OP_reg0:
2774 case DW_OP_reg1:
2775 case DW_OP_reg2:
2776 case DW_OP_reg3:
2777 case DW_OP_reg4:
2778 case DW_OP_reg5:
2779 case DW_OP_reg6:
2780 case DW_OP_reg7:
2781 case DW_OP_reg8:
2782 case DW_OP_reg9:
2783 case DW_OP_reg10:
2784 case DW_OP_reg11:
2785 case DW_OP_reg12:
2786 case DW_OP_reg13:
2787 case DW_OP_reg14:
2788 case DW_OP_reg15:
2789 case DW_OP_reg16:
2790 case DW_OP_reg17:
2791 case DW_OP_reg18:
2792 case DW_OP_reg19:
2793 case DW_OP_reg20:
2794 case DW_OP_reg21:
2795 case DW_OP_reg22:
2796 case DW_OP_reg23:
2797 case DW_OP_reg24:
2798 case DW_OP_reg25:
2799 case DW_OP_reg26:
2800 case DW_OP_reg27:
2801 case DW_OP_reg28:
2802 case DW_OP_reg29:
2803 case DW_OP_reg30:
2804 case DW_OP_reg31:
2805 cfa->reg = op - DW_OP_reg0;
2806 break;
2807 case DW_OP_regx:
2808 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2809 break;
2810 case DW_OP_breg0:
2811 case DW_OP_breg1:
2812 case DW_OP_breg2:
2813 case DW_OP_breg3:
2814 case DW_OP_breg4:
2815 case DW_OP_breg5:
2816 case DW_OP_breg6:
2817 case DW_OP_breg7:
2818 case DW_OP_breg8:
2819 case DW_OP_breg9:
2820 case DW_OP_breg10:
2821 case DW_OP_breg11:
2822 case DW_OP_breg12:
2823 case DW_OP_breg13:
2824 case DW_OP_breg14:
2825 case DW_OP_breg15:
2826 case DW_OP_breg16:
2827 case DW_OP_breg17:
2828 case DW_OP_breg18:
2829 case DW_OP_breg19:
2830 case DW_OP_breg20:
2831 case DW_OP_breg21:
2832 case DW_OP_breg22:
2833 case DW_OP_breg23:
2834 case DW_OP_breg24:
2835 case DW_OP_breg25:
2836 case DW_OP_breg26:
2837 case DW_OP_breg27:
2838 case DW_OP_breg28:
2839 case DW_OP_breg29:
2840 case DW_OP_breg30:
2841 case DW_OP_breg31:
2842 cfa->reg = op - DW_OP_breg0;
2843 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2844 break;
2845 case DW_OP_bregx:
2846 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2847 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2848 break;
2849 case DW_OP_deref:
2850 cfa->indirect = 1;
2851 break;
2852 case DW_OP_plus_uconst:
2853 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2854 break;
2855 default:
2856 internal_error ("DW_LOC_OP %s not implememnted\n",
2857 dwarf_stack_op_name (ptr->dw_loc_opc));
2861 #endif /* .debug_frame support */
2863 /* And now, the support for symbolic debugging information. */
2864 #ifdef DWARF2_DEBUGGING_INFO
2866 /* NOTE: In the comments in this file, many references are made to
2867 "Debugging Information Entries". This term is abbreviated as `DIE'
2868 throughout the remainder of this file. */
2870 /* An internal representation of the DWARF output is built, and then
2871 walked to generate the DWARF debugging info. The walk of the internal
2872 representation is done after the entire program has been compiled.
2873 The types below are used to describe the internal representation. */
2875 /* Various DIE's use offsets relative to the beginning of the
2876 .debug_info section to refer to each other. */
2878 typedef long int dw_offset;
2880 /* Define typedefs here to avoid circular dependencies. */
2882 typedef struct dw_attr_struct *dw_attr_ref;
2883 typedef struct dw_line_info_struct *dw_line_info_ref;
2884 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
2885 typedef struct pubname_struct *pubname_ref;
2886 typedef dw_die_ref *arange_ref;
2888 /* Each entry in the line_info_table maintains the file and
2889 line number associated with the label generated for that
2890 entry. The label gives the PC value associated with
2891 the line number entry. */
2893 typedef struct dw_line_info_struct
2895 unsigned long dw_file_num;
2896 unsigned long dw_line_num;
2898 dw_line_info_entry;
2900 /* Line information for functions in separate sections; each one gets its
2901 own sequence. */
2902 typedef struct dw_separate_line_info_struct
2904 unsigned long dw_file_num;
2905 unsigned long dw_line_num;
2906 unsigned long function;
2908 dw_separate_line_info_entry;
2910 /* Each DIE attribute has a field specifying the attribute kind,
2911 a link to the next attribute in the chain, and an attribute value.
2912 Attributes are typically linked below the DIE they modify. */
2914 typedef struct dw_attr_struct
2916 enum dwarf_attribute dw_attr;
2917 dw_attr_ref dw_attr_next;
2918 dw_val_node dw_attr_val;
2920 dw_attr_node;
2922 /* The Debugging Information Entry (DIE) structure */
2924 typedef struct die_struct
2926 enum dwarf_tag die_tag;
2927 char *die_symbol;
2928 dw_attr_ref die_attr;
2929 dw_die_ref die_parent;
2930 dw_die_ref die_child;
2931 dw_die_ref die_sib;
2932 dw_offset die_offset;
2933 unsigned long die_abbrev;
2934 int die_mark;
2936 die_node;
2938 /* The pubname structure */
2940 typedef struct pubname_struct
2942 dw_die_ref die;
2943 char *name;
2945 pubname_entry;
2947 /* The limbo die list structure. */
2948 typedef struct limbo_die_struct
2950 dw_die_ref die;
2951 struct limbo_die_struct *next;
2953 limbo_die_node;
2955 /* How to start an assembler comment. */
2956 #ifndef ASM_COMMENT_START
2957 #define ASM_COMMENT_START ";#"
2958 #endif
2960 /* Define a macro which returns non-zero for a TYPE_DECL which was
2961 implicitly generated for a tagged type.
2963 Note that unlike the gcc front end (which generates a NULL named
2964 TYPE_DECL node for each complete tagged type, each array type, and
2965 each function type node created) the g++ front end generates a
2966 _named_ TYPE_DECL node for each tagged type node created.
2967 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2968 generate a DW_TAG_typedef DIE for them. */
2970 #define TYPE_DECL_IS_STUB(decl) \
2971 (DECL_NAME (decl) == NULL_TREE \
2972 || (DECL_ARTIFICIAL (decl) \
2973 && is_tagged_type (TREE_TYPE (decl)) \
2974 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2975 /* This is necessary for stub decls that \
2976 appear in nested inline functions. */ \
2977 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2978 && (decl_ultimate_origin (decl) \
2979 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2981 /* Information concerning the compilation unit's programming
2982 language, and compiler version. */
2984 extern int flag_traditional;
2986 /* Fixed size portion of the DWARF compilation unit header. */
2987 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2989 /* Fixed size portion of debugging line information prolog. */
2990 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2992 /* Fixed size portion of public names info. */
2993 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2995 /* Fixed size portion of the address range info. */
2996 #define DWARF_ARANGES_HEADER_SIZE \
2997 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
2998 - DWARF_OFFSET_SIZE)
3000 /* Size of padding portion in the address range info. It must be
3001 aligned to twice the pointer size. */
3002 #define DWARF_ARANGES_PAD_SIZE \
3003 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3004 - (2 * DWARF_OFFSET_SIZE + 4))
3006 /* Use assembler line directives if available. */
3007 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3008 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3009 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3010 #else
3011 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3012 #endif
3013 #endif
3015 /* Define the architecture-dependent minimum instruction length (in bytes).
3016 In this implementation of DWARF, this field is used for information
3017 purposes only. Since GCC generates assembly language, we have
3018 no a priori knowledge of how many instruction bytes are generated
3019 for each source line, and therefore can use only the DW_LNE_set_address
3020 and DW_LNS_fixed_advance_pc line information commands. */
3022 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3023 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3024 #endif
3026 /* Minimum line offset in a special line info. opcode.
3027 This value was chosen to give a reasonable range of values. */
3028 #define DWARF_LINE_BASE -10
3030 /* First special line opcde - leave room for the standard opcodes. */
3031 #define DWARF_LINE_OPCODE_BASE 10
3033 /* Range of line offsets in a special line info. opcode. */
3034 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3036 /* Flag that indicates the initial value of the is_stmt_start flag.
3037 In the present implementation, we do not mark any lines as
3038 the beginning of a source statement, because that information
3039 is not made available by the GCC front-end. */
3040 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3042 /* This location is used by calc_die_sizes() to keep track
3043 the offset of each DIE within the .debug_info section. */
3044 static unsigned long next_die_offset;
3046 /* Record the root of the DIE's built for the current compilation unit. */
3047 static dw_die_ref comp_unit_die;
3049 /* A list of DIEs with a NULL parent waiting to be relocated. */
3050 static limbo_die_node *limbo_die_list = 0;
3052 /* Structure used by lookup_filename to manage sets of filenames. */
3053 struct file_table
3055 char **table;
3056 unsigned allocated;
3057 unsigned in_use;
3058 unsigned last_lookup_index;
3061 /* Size (in elements) of increments by which we may expand the filename
3062 table. */
3063 #define FILE_TABLE_INCREMENT 64
3065 /* Filenames referenced by this compilation unit. */
3066 static struct file_table file_table;
3068 /* Local pointer to the name of the main input file. Initialized in
3069 dwarf2out_init. */
3070 static const char *primary_filename;
3072 /* A pointer to the base of a table of references to DIE's that describe
3073 declarations. The table is indexed by DECL_UID() which is a unique
3074 number identifying each decl. */
3075 static dw_die_ref *decl_die_table;
3077 /* Number of elements currently allocated for the decl_die_table. */
3078 static unsigned decl_die_table_allocated;
3080 /* Number of elements in decl_die_table currently in use. */
3081 static unsigned decl_die_table_in_use;
3083 /* Size (in elements) of increments by which we may expand the
3084 decl_die_table. */
3085 #define DECL_DIE_TABLE_INCREMENT 256
3087 /* A pointer to the base of a table of references to declaration
3088 scopes. This table is a display which tracks the nesting
3089 of declaration scopes at the current scope and containing
3090 scopes. This table is used to find the proper place to
3091 define type declaration DIE's. */
3092 static tree *decl_scope_table;
3094 /* Number of elements currently allocated for the decl_scope_table. */
3095 static int decl_scope_table_allocated;
3097 /* Current level of nesting of declaration scopes. */
3098 static int decl_scope_depth;
3100 /* Size (in elements) of increments by which we may expand the
3101 decl_scope_table. */
3102 #define DECL_SCOPE_TABLE_INCREMENT 64
3104 /* A pointer to the base of a list of references to DIE's that
3105 are uniquely identified by their tag, presence/absence of
3106 children DIE's, and list of attribute/value pairs. */
3107 static dw_die_ref *abbrev_die_table;
3109 /* Number of elements currently allocated for abbrev_die_table. */
3110 static unsigned abbrev_die_table_allocated;
3112 /* Number of elements in type_die_table currently in use. */
3113 static unsigned abbrev_die_table_in_use;
3115 /* Size (in elements) of increments by which we may expand the
3116 abbrev_die_table. */
3117 #define ABBREV_DIE_TABLE_INCREMENT 256
3119 /* A pointer to the base of a table that contains line information
3120 for each source code line in .text in the compilation unit. */
3121 static dw_line_info_ref line_info_table;
3123 /* Number of elements currently allocated for line_info_table. */
3124 static unsigned line_info_table_allocated;
3126 /* Number of elements in separate_line_info_table currently in use. */
3127 static unsigned separate_line_info_table_in_use;
3129 /* A pointer to the base of a table that contains line information
3130 for each source code line outside of .text in the compilation unit. */
3131 static dw_separate_line_info_ref separate_line_info_table;
3133 /* Number of elements currently allocated for separate_line_info_table. */
3134 static unsigned separate_line_info_table_allocated;
3136 /* Number of elements in line_info_table currently in use. */
3137 static unsigned line_info_table_in_use;
3139 /* Size (in elements) of increments by which we may expand the
3140 line_info_table. */
3141 #define LINE_INFO_TABLE_INCREMENT 1024
3143 /* A pointer to the base of a table that contains a list of publicly
3144 accessible names. */
3145 static pubname_ref pubname_table;
3147 /* Number of elements currently allocated for pubname_table. */
3148 static unsigned pubname_table_allocated;
3150 /* Number of elements in pubname_table currently in use. */
3151 static unsigned pubname_table_in_use;
3153 /* Size (in elements) of increments by which we may expand the
3154 pubname_table. */
3155 #define PUBNAME_TABLE_INCREMENT 64
3157 /* A pointer to the base of a table that contains a list of publicly
3158 accessible names. */
3159 static arange_ref arange_table;
3161 /* Number of elements currently allocated for arange_table. */
3162 static unsigned arange_table_allocated;
3164 /* Number of elements in arange_table currently in use. */
3165 static unsigned arange_table_in_use;
3167 /* Size (in elements) of increments by which we may expand the
3168 arange_table. */
3169 #define ARANGE_TABLE_INCREMENT 64
3171 /* A pointer to the base of a list of incomplete types which might be
3172 completed at some later time. */
3174 static tree *incomplete_types_list;
3176 /* Number of elements currently allocated for the incomplete_types_list. */
3177 static unsigned incomplete_types_allocated;
3179 /* Number of elements of incomplete_types_list currently in use. */
3180 static unsigned incomplete_types;
3182 /* Size (in elements) of increments by which we may expand the incomplete
3183 types list. Actually, a single hunk of space of this size should
3184 be enough for most typical programs. */
3185 #define INCOMPLETE_TYPES_INCREMENT 64
3187 /* Record whether the function being analyzed contains inlined functions. */
3188 static int current_function_has_inlines;
3189 #if 0 && defined (MIPS_DEBUGGING_INFO)
3190 static int comp_unit_has_inlines;
3191 #endif
3193 /* Array of RTXes referenced by the debugging information, which therefore
3194 must be kept around forever. We do this rather than perform GC on
3195 the dwarf info because almost all of the dwarf info lives forever, and
3196 it's easier to support non-GC frontends this way. */
3197 static varray_type used_rtx_varray;
3199 /* Forward declarations for functions defined in this file. */
3201 static int is_pseudo_reg PARAMS ((rtx));
3202 static tree type_main_variant PARAMS ((tree));
3203 static int is_tagged_type PARAMS ((tree));
3204 static const char *dwarf_tag_name PARAMS ((unsigned));
3205 static const char *dwarf_attr_name PARAMS ((unsigned));
3206 static const char *dwarf_form_name PARAMS ((unsigned));
3207 #if 0
3208 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3209 #endif
3210 static tree decl_ultimate_origin PARAMS ((tree));
3211 static tree block_ultimate_origin PARAMS ((tree));
3212 static tree decl_class_context PARAMS ((tree));
3213 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3214 static void add_AT_flag PARAMS ((dw_die_ref,
3215 enum dwarf_attribute,
3216 unsigned));
3217 static void add_AT_int PARAMS ((dw_die_ref,
3218 enum dwarf_attribute, long));
3219 static void add_AT_unsigned PARAMS ((dw_die_ref,
3220 enum dwarf_attribute,
3221 unsigned long));
3222 static void add_AT_long_long PARAMS ((dw_die_ref,
3223 enum dwarf_attribute,
3224 unsigned long,
3225 unsigned long));
3226 static void add_AT_float PARAMS ((dw_die_ref,
3227 enum dwarf_attribute,
3228 unsigned, long *));
3229 static void add_AT_string PARAMS ((dw_die_ref,
3230 enum dwarf_attribute,
3231 const char *));
3232 static void add_AT_die_ref PARAMS ((dw_die_ref,
3233 enum dwarf_attribute,
3234 dw_die_ref));
3235 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3236 enum dwarf_attribute,
3237 unsigned));
3238 static void add_AT_loc PARAMS ((dw_die_ref,
3239 enum dwarf_attribute,
3240 dw_loc_descr_ref));
3241 static void add_AT_addr PARAMS ((dw_die_ref,
3242 enum dwarf_attribute,
3243 rtx));
3244 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3245 enum dwarf_attribute,
3246 const char *));
3247 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3248 enum dwarf_attribute,
3249 const char *));
3250 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3251 enum dwarf_attribute));
3252 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3253 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3254 static const char *get_AT_string PARAMS ((dw_die_ref,
3255 enum dwarf_attribute));
3256 static int get_AT_flag PARAMS ((dw_die_ref,
3257 enum dwarf_attribute));
3258 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3259 enum dwarf_attribute));
3260 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3261 enum dwarf_attribute));
3262 static int is_c_family PARAMS ((void));
3263 static int is_java PARAMS ((void));
3264 static int is_fortran PARAMS ((void));
3265 static void remove_AT PARAMS ((dw_die_ref,
3266 enum dwarf_attribute));
3267 static void remove_children PARAMS ((dw_die_ref));
3268 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3269 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3270 static dw_die_ref lookup_type_die PARAMS ((tree));
3271 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3272 static dw_die_ref lookup_decl_die PARAMS ((tree));
3273 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3274 static void print_spaces PARAMS ((FILE *));
3275 static void print_die PARAMS ((dw_die_ref, FILE *));
3276 static void print_dwarf_line_table PARAMS ((FILE *));
3277 static void reverse_die_lists PARAMS ((dw_die_ref));
3278 static void reverse_all_dies PARAMS ((dw_die_ref));
3279 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3280 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3281 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3282 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3283 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3284 static void compute_section_prefix PARAMS ((dw_die_ref));
3285 static int is_type_die PARAMS ((dw_die_ref));
3286 static int is_comdat_die PARAMS ((dw_die_ref));
3287 static int is_symbol_die PARAMS ((dw_die_ref));
3288 static char *gen_internal_sym PARAMS ((void));
3289 static void assign_symbol_names PARAMS ((dw_die_ref));
3290 static void break_out_includes PARAMS ((dw_die_ref));
3291 static void add_sibling_attributes PARAMS ((dw_die_ref));
3292 static void build_abbrev_table PARAMS ((dw_die_ref));
3293 static unsigned long size_of_string PARAMS ((const char *));
3294 static int constant_size PARAMS ((long unsigned));
3295 static unsigned long size_of_die PARAMS ((dw_die_ref));
3296 static void calc_die_sizes PARAMS ((dw_die_ref));
3297 static void mark_dies PARAMS ((dw_die_ref));
3298 static void unmark_dies PARAMS ((dw_die_ref));
3299 static unsigned long size_of_pubnames PARAMS ((void));
3300 static unsigned long size_of_aranges PARAMS ((void));
3301 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3302 static void output_value_format PARAMS ((dw_attr_ref));
3303 static void output_abbrev_section PARAMS ((void));
3304 static void output_die_symbol PARAMS ((dw_die_ref));
3305 static void output_die PARAMS ((dw_die_ref));
3306 static void output_compilation_unit_header PARAMS ((void));
3307 static void output_comp_unit PARAMS ((dw_die_ref));
3308 static const char *dwarf2_name PARAMS ((tree, int));
3309 static void add_pubname PARAMS ((tree, dw_die_ref));
3310 static void output_pubnames PARAMS ((void));
3311 static void add_arange PARAMS ((tree, dw_die_ref));
3312 static void output_aranges PARAMS ((void));
3313 static void output_line_info PARAMS ((void));
3314 static void output_file_names PARAMS ((void));
3315 static dw_die_ref base_type_die PARAMS ((tree));
3316 static tree root_type PARAMS ((tree));
3317 static int is_base_type PARAMS ((tree));
3318 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3319 static int type_is_enum PARAMS ((tree));
3320 static unsigned int reg_number PARAMS ((rtx));
3321 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3322 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3323 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3324 static int is_based_loc PARAMS ((rtx));
3325 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3326 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3327 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3328 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3329 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3330 static tree field_type PARAMS ((tree));
3331 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3332 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3333 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3334 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3335 static void add_AT_location_description PARAMS ((dw_die_ref,
3336 enum dwarf_attribute, rtx));
3337 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3338 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3339 static rtx rtl_for_decl_location PARAMS ((tree));
3340 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3341 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3342 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3343 static void add_bound_info PARAMS ((dw_die_ref,
3344 enum dwarf_attribute, tree));
3345 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3346 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3347 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3348 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3349 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3350 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3351 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3352 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3353 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3354 static void push_decl_scope PARAMS ((tree));
3355 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3356 static void pop_decl_scope PARAMS ((void));
3357 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3358 dw_die_ref));
3359 static const char *type_tag PARAMS ((tree));
3360 static tree member_declared_type PARAMS ((tree));
3361 #if 0
3362 static const char *decl_start_label PARAMS ((tree));
3363 #endif
3364 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3365 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3366 #if 0
3367 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3368 #endif
3369 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3370 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3371 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3372 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3373 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3374 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3375 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3376 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3377 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3378 static void gen_label_die PARAMS ((tree, dw_die_ref));
3379 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3380 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3381 static void gen_field_die PARAMS ((tree, dw_die_ref));
3382 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3383 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3384 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3385 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3386 static void gen_member_die PARAMS ((tree, dw_die_ref));
3387 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3388 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3389 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3390 static void gen_type_die PARAMS ((tree, dw_die_ref));
3391 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3392 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3393 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3394 static int is_redundant_typedef PARAMS ((tree));
3395 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3396 static unsigned lookup_filename PARAMS ((const char *));
3397 static void init_file_table PARAMS ((void));
3398 static void add_incomplete_type PARAMS ((tree));
3399 static void retry_incomplete_types PARAMS ((void));
3400 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3401 static rtx save_rtx PARAMS ((rtx));
3402 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3403 static int file_info_cmp PARAMS ((const void *, const void *));
3405 /* Section names used to hold DWARF debugging information. */
3406 #ifndef DEBUG_INFO_SECTION
3407 #define DEBUG_INFO_SECTION ".debug_info"
3408 #endif
3409 #ifndef ABBREV_SECTION
3410 #define ABBREV_SECTION ".debug_abbrev"
3411 #endif
3412 #ifndef ARANGES_SECTION
3413 #define ARANGES_SECTION ".debug_aranges"
3414 #endif
3415 #ifndef DW_MACINFO_SECTION
3416 #define DW_MACINFO_SECTION ".debug_macinfo"
3417 #endif
3418 #ifndef DEBUG_LINE_SECTION
3419 #define DEBUG_LINE_SECTION ".debug_line"
3420 #endif
3421 #ifndef LOC_SECTION
3422 #define LOC_SECTION ".debug_loc"
3423 #endif
3424 #ifndef PUBNAMES_SECTION
3425 #define PUBNAMES_SECTION ".debug_pubnames"
3426 #endif
3427 #ifndef STR_SECTION
3428 #define STR_SECTION ".debug_str"
3429 #endif
3431 /* Standard ELF section names for compiled code and data. */
3432 #ifndef TEXT_SECTION
3433 #define TEXT_SECTION ".text"
3434 #endif
3435 #ifndef DATA_SECTION
3436 #define DATA_SECTION ".data"
3437 #endif
3438 #ifndef BSS_SECTION
3439 #define BSS_SECTION ".bss"
3440 #endif
3442 /* Labels we insert at beginning sections we can reference instead of
3443 the section names themselves. */
3445 #ifndef TEXT_SECTION_LABEL
3446 #define TEXT_SECTION_LABEL "Ltext"
3447 #endif
3448 #ifndef DEBUG_LINE_SECTION_LABEL
3449 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3450 #endif
3451 #ifndef DEBUG_INFO_SECTION_LABEL
3452 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3453 #endif
3454 #ifndef ABBREV_SECTION_LABEL
3455 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3456 #endif
3458 /* Definitions of defaults for formats and names of various special
3459 (artificial) labels which may be generated within this file (when the -g
3460 options is used and DWARF_DEBUGGING_INFO is in effect.
3461 If necessary, these may be overridden from within the tm.h file, but
3462 typically, overriding these defaults is unnecessary. */
3464 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3465 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3466 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3467 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3468 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3470 #ifndef TEXT_END_LABEL
3471 #define TEXT_END_LABEL "Letext"
3472 #endif
3473 #ifndef DATA_END_LABEL
3474 #define DATA_END_LABEL "Ledata"
3475 #endif
3476 #ifndef BSS_END_LABEL
3477 #define BSS_END_LABEL "Lebss"
3478 #endif
3479 #ifndef BLOCK_BEGIN_LABEL
3480 #define BLOCK_BEGIN_LABEL "LBB"
3481 #endif
3482 #ifndef BLOCK_END_LABEL
3483 #define BLOCK_END_LABEL "LBE"
3484 #endif
3485 #ifndef BODY_BEGIN_LABEL
3486 #define BODY_BEGIN_LABEL "Lbb"
3487 #endif
3488 #ifndef BODY_END_LABEL
3489 #define BODY_END_LABEL "Lbe"
3490 #endif
3491 #ifndef LINE_CODE_LABEL
3492 #define LINE_CODE_LABEL "LM"
3493 #endif
3494 #ifndef SEPARATE_LINE_CODE_LABEL
3495 #define SEPARATE_LINE_CODE_LABEL "LSM"
3496 #endif
3498 /* We allow a language front-end to designate a function that is to be
3499 called to "demangle" any name before it it put into a DIE. */
3501 static const char *(*demangle_name_func) PARAMS ((const char *));
3503 void
3504 dwarf2out_set_demangle_name_func (func)
3505 const char *(*func) PARAMS ((const char *));
3507 demangle_name_func = func;
3510 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3511 that means adding it to used_rtx_varray. If not, that means making
3512 a copy on the permanent_obstack. */
3514 static rtx
3515 save_rtx (orig)
3516 register rtx orig;
3518 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3520 return orig;
3523 /* Test if rtl node points to a pseudo register. */
3525 static inline int
3526 is_pseudo_reg (rtl)
3527 register rtx rtl;
3529 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3530 || (GET_CODE (rtl) == SUBREG
3531 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3534 /* Return a reference to a type, with its const and volatile qualifiers
3535 removed. */
3537 static inline tree
3538 type_main_variant (type)
3539 register tree type;
3541 type = TYPE_MAIN_VARIANT (type);
3543 /* There really should be only one main variant among any group of variants
3544 of a given type (and all of the MAIN_VARIANT values for all members of
3545 the group should point to that one type) but sometimes the C front-end
3546 messes this up for array types, so we work around that bug here. */
3548 if (TREE_CODE (type) == ARRAY_TYPE)
3549 while (type != TYPE_MAIN_VARIANT (type))
3550 type = TYPE_MAIN_VARIANT (type);
3552 return type;
3555 /* Return non-zero if the given type node represents a tagged type. */
3557 static inline int
3558 is_tagged_type (type)
3559 register tree type;
3561 register enum tree_code code = TREE_CODE (type);
3563 return (code == RECORD_TYPE || code == UNION_TYPE
3564 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3567 /* Convert a DIE tag into its string name. */
3569 static const char *
3570 dwarf_tag_name (tag)
3571 register unsigned tag;
3573 switch (tag)
3575 case DW_TAG_padding:
3576 return "DW_TAG_padding";
3577 case DW_TAG_array_type:
3578 return "DW_TAG_array_type";
3579 case DW_TAG_class_type:
3580 return "DW_TAG_class_type";
3581 case DW_TAG_entry_point:
3582 return "DW_TAG_entry_point";
3583 case DW_TAG_enumeration_type:
3584 return "DW_TAG_enumeration_type";
3585 case DW_TAG_formal_parameter:
3586 return "DW_TAG_formal_parameter";
3587 case DW_TAG_imported_declaration:
3588 return "DW_TAG_imported_declaration";
3589 case DW_TAG_label:
3590 return "DW_TAG_label";
3591 case DW_TAG_lexical_block:
3592 return "DW_TAG_lexical_block";
3593 case DW_TAG_member:
3594 return "DW_TAG_member";
3595 case DW_TAG_pointer_type:
3596 return "DW_TAG_pointer_type";
3597 case DW_TAG_reference_type:
3598 return "DW_TAG_reference_type";
3599 case DW_TAG_compile_unit:
3600 return "DW_TAG_compile_unit";
3601 case DW_TAG_string_type:
3602 return "DW_TAG_string_type";
3603 case DW_TAG_structure_type:
3604 return "DW_TAG_structure_type";
3605 case DW_TAG_subroutine_type:
3606 return "DW_TAG_subroutine_type";
3607 case DW_TAG_typedef:
3608 return "DW_TAG_typedef";
3609 case DW_TAG_union_type:
3610 return "DW_TAG_union_type";
3611 case DW_TAG_unspecified_parameters:
3612 return "DW_TAG_unspecified_parameters";
3613 case DW_TAG_variant:
3614 return "DW_TAG_variant";
3615 case DW_TAG_common_block:
3616 return "DW_TAG_common_block";
3617 case DW_TAG_common_inclusion:
3618 return "DW_TAG_common_inclusion";
3619 case DW_TAG_inheritance:
3620 return "DW_TAG_inheritance";
3621 case DW_TAG_inlined_subroutine:
3622 return "DW_TAG_inlined_subroutine";
3623 case DW_TAG_module:
3624 return "DW_TAG_module";
3625 case DW_TAG_ptr_to_member_type:
3626 return "DW_TAG_ptr_to_member_type";
3627 case DW_TAG_set_type:
3628 return "DW_TAG_set_type";
3629 case DW_TAG_subrange_type:
3630 return "DW_TAG_subrange_type";
3631 case DW_TAG_with_stmt:
3632 return "DW_TAG_with_stmt";
3633 case DW_TAG_access_declaration:
3634 return "DW_TAG_access_declaration";
3635 case DW_TAG_base_type:
3636 return "DW_TAG_base_type";
3637 case DW_TAG_catch_block:
3638 return "DW_TAG_catch_block";
3639 case DW_TAG_const_type:
3640 return "DW_TAG_const_type";
3641 case DW_TAG_constant:
3642 return "DW_TAG_constant";
3643 case DW_TAG_enumerator:
3644 return "DW_TAG_enumerator";
3645 case DW_TAG_file_type:
3646 return "DW_TAG_file_type";
3647 case DW_TAG_friend:
3648 return "DW_TAG_friend";
3649 case DW_TAG_namelist:
3650 return "DW_TAG_namelist";
3651 case DW_TAG_namelist_item:
3652 return "DW_TAG_namelist_item";
3653 case DW_TAG_packed_type:
3654 return "DW_TAG_packed_type";
3655 case DW_TAG_subprogram:
3656 return "DW_TAG_subprogram";
3657 case DW_TAG_template_type_param:
3658 return "DW_TAG_template_type_param";
3659 case DW_TAG_template_value_param:
3660 return "DW_TAG_template_value_param";
3661 case DW_TAG_thrown_type:
3662 return "DW_TAG_thrown_type";
3663 case DW_TAG_try_block:
3664 return "DW_TAG_try_block";
3665 case DW_TAG_variant_part:
3666 return "DW_TAG_variant_part";
3667 case DW_TAG_variable:
3668 return "DW_TAG_variable";
3669 case DW_TAG_volatile_type:
3670 return "DW_TAG_volatile_type";
3671 case DW_TAG_MIPS_loop:
3672 return "DW_TAG_MIPS_loop";
3673 case DW_TAG_format_label:
3674 return "DW_TAG_format_label";
3675 case DW_TAG_function_template:
3676 return "DW_TAG_function_template";
3677 case DW_TAG_class_template:
3678 return "DW_TAG_class_template";
3679 case DW_TAG_GNU_BINCL:
3680 return "DW_TAG_GNU_BINCL";
3681 case DW_TAG_GNU_EINCL:
3682 return "DW_TAG_GNU_EINCL";
3683 default:
3684 return "DW_TAG_<unknown>";
3688 /* Convert a DWARF attribute code into its string name. */
3690 static const char *
3691 dwarf_attr_name (attr)
3692 register unsigned attr;
3694 switch (attr)
3696 case DW_AT_sibling:
3697 return "DW_AT_sibling";
3698 case DW_AT_location:
3699 return "DW_AT_location";
3700 case DW_AT_name:
3701 return "DW_AT_name";
3702 case DW_AT_ordering:
3703 return "DW_AT_ordering";
3704 case DW_AT_subscr_data:
3705 return "DW_AT_subscr_data";
3706 case DW_AT_byte_size:
3707 return "DW_AT_byte_size";
3708 case DW_AT_bit_offset:
3709 return "DW_AT_bit_offset";
3710 case DW_AT_bit_size:
3711 return "DW_AT_bit_size";
3712 case DW_AT_element_list:
3713 return "DW_AT_element_list";
3714 case DW_AT_stmt_list:
3715 return "DW_AT_stmt_list";
3716 case DW_AT_low_pc:
3717 return "DW_AT_low_pc";
3718 case DW_AT_high_pc:
3719 return "DW_AT_high_pc";
3720 case DW_AT_language:
3721 return "DW_AT_language";
3722 case DW_AT_member:
3723 return "DW_AT_member";
3724 case DW_AT_discr:
3725 return "DW_AT_discr";
3726 case DW_AT_discr_value:
3727 return "DW_AT_discr_value";
3728 case DW_AT_visibility:
3729 return "DW_AT_visibility";
3730 case DW_AT_import:
3731 return "DW_AT_import";
3732 case DW_AT_string_length:
3733 return "DW_AT_string_length";
3734 case DW_AT_common_reference:
3735 return "DW_AT_common_reference";
3736 case DW_AT_comp_dir:
3737 return "DW_AT_comp_dir";
3738 case DW_AT_const_value:
3739 return "DW_AT_const_value";
3740 case DW_AT_containing_type:
3741 return "DW_AT_containing_type";
3742 case DW_AT_default_value:
3743 return "DW_AT_default_value";
3744 case DW_AT_inline:
3745 return "DW_AT_inline";
3746 case DW_AT_is_optional:
3747 return "DW_AT_is_optional";
3748 case DW_AT_lower_bound:
3749 return "DW_AT_lower_bound";
3750 case DW_AT_producer:
3751 return "DW_AT_producer";
3752 case DW_AT_prototyped:
3753 return "DW_AT_prototyped";
3754 case DW_AT_return_addr:
3755 return "DW_AT_return_addr";
3756 case DW_AT_start_scope:
3757 return "DW_AT_start_scope";
3758 case DW_AT_stride_size:
3759 return "DW_AT_stride_size";
3760 case DW_AT_upper_bound:
3761 return "DW_AT_upper_bound";
3762 case DW_AT_abstract_origin:
3763 return "DW_AT_abstract_origin";
3764 case DW_AT_accessibility:
3765 return "DW_AT_accessibility";
3766 case DW_AT_address_class:
3767 return "DW_AT_address_class";
3768 case DW_AT_artificial:
3769 return "DW_AT_artificial";
3770 case DW_AT_base_types:
3771 return "DW_AT_base_types";
3772 case DW_AT_calling_convention:
3773 return "DW_AT_calling_convention";
3774 case DW_AT_count:
3775 return "DW_AT_count";
3776 case DW_AT_data_member_location:
3777 return "DW_AT_data_member_location";
3778 case DW_AT_decl_column:
3779 return "DW_AT_decl_column";
3780 case DW_AT_decl_file:
3781 return "DW_AT_decl_file";
3782 case DW_AT_decl_line:
3783 return "DW_AT_decl_line";
3784 case DW_AT_declaration:
3785 return "DW_AT_declaration";
3786 case DW_AT_discr_list:
3787 return "DW_AT_discr_list";
3788 case DW_AT_encoding:
3789 return "DW_AT_encoding";
3790 case DW_AT_external:
3791 return "DW_AT_external";
3792 case DW_AT_frame_base:
3793 return "DW_AT_frame_base";
3794 case DW_AT_friend:
3795 return "DW_AT_friend";
3796 case DW_AT_identifier_case:
3797 return "DW_AT_identifier_case";
3798 case DW_AT_macro_info:
3799 return "DW_AT_macro_info";
3800 case DW_AT_namelist_items:
3801 return "DW_AT_namelist_items";
3802 case DW_AT_priority:
3803 return "DW_AT_priority";
3804 case DW_AT_segment:
3805 return "DW_AT_segment";
3806 case DW_AT_specification:
3807 return "DW_AT_specification";
3808 case DW_AT_static_link:
3809 return "DW_AT_static_link";
3810 case DW_AT_type:
3811 return "DW_AT_type";
3812 case DW_AT_use_location:
3813 return "DW_AT_use_location";
3814 case DW_AT_variable_parameter:
3815 return "DW_AT_variable_parameter";
3816 case DW_AT_virtuality:
3817 return "DW_AT_virtuality";
3818 case DW_AT_vtable_elem_location:
3819 return "DW_AT_vtable_elem_location";
3821 case DW_AT_MIPS_fde:
3822 return "DW_AT_MIPS_fde";
3823 case DW_AT_MIPS_loop_begin:
3824 return "DW_AT_MIPS_loop_begin";
3825 case DW_AT_MIPS_tail_loop_begin:
3826 return "DW_AT_MIPS_tail_loop_begin";
3827 case DW_AT_MIPS_epilog_begin:
3828 return "DW_AT_MIPS_epilog_begin";
3829 case DW_AT_MIPS_loop_unroll_factor:
3830 return "DW_AT_MIPS_loop_unroll_factor";
3831 case DW_AT_MIPS_software_pipeline_depth:
3832 return "DW_AT_MIPS_software_pipeline_depth";
3833 case DW_AT_MIPS_linkage_name:
3834 return "DW_AT_MIPS_linkage_name";
3835 case DW_AT_MIPS_stride:
3836 return "DW_AT_MIPS_stride";
3837 case DW_AT_MIPS_abstract_name:
3838 return "DW_AT_MIPS_abstract_name";
3839 case DW_AT_MIPS_clone_origin:
3840 return "DW_AT_MIPS_clone_origin";
3841 case DW_AT_MIPS_has_inlines:
3842 return "DW_AT_MIPS_has_inlines";
3844 case DW_AT_sf_names:
3845 return "DW_AT_sf_names";
3846 case DW_AT_src_info:
3847 return "DW_AT_src_info";
3848 case DW_AT_mac_info:
3849 return "DW_AT_mac_info";
3850 case DW_AT_src_coords:
3851 return "DW_AT_src_coords";
3852 case DW_AT_body_begin:
3853 return "DW_AT_body_begin";
3854 case DW_AT_body_end:
3855 return "DW_AT_body_end";
3856 default:
3857 return "DW_AT_<unknown>";
3861 /* Convert a DWARF value form code into its string name. */
3863 static const char *
3864 dwarf_form_name (form)
3865 register unsigned form;
3867 switch (form)
3869 case DW_FORM_addr:
3870 return "DW_FORM_addr";
3871 case DW_FORM_block2:
3872 return "DW_FORM_block2";
3873 case DW_FORM_block4:
3874 return "DW_FORM_block4";
3875 case DW_FORM_data2:
3876 return "DW_FORM_data2";
3877 case DW_FORM_data4:
3878 return "DW_FORM_data4";
3879 case DW_FORM_data8:
3880 return "DW_FORM_data8";
3881 case DW_FORM_string:
3882 return "DW_FORM_string";
3883 case DW_FORM_block:
3884 return "DW_FORM_block";
3885 case DW_FORM_block1:
3886 return "DW_FORM_block1";
3887 case DW_FORM_data1:
3888 return "DW_FORM_data1";
3889 case DW_FORM_flag:
3890 return "DW_FORM_flag";
3891 case DW_FORM_sdata:
3892 return "DW_FORM_sdata";
3893 case DW_FORM_strp:
3894 return "DW_FORM_strp";
3895 case DW_FORM_udata:
3896 return "DW_FORM_udata";
3897 case DW_FORM_ref_addr:
3898 return "DW_FORM_ref_addr";
3899 case DW_FORM_ref1:
3900 return "DW_FORM_ref1";
3901 case DW_FORM_ref2:
3902 return "DW_FORM_ref2";
3903 case DW_FORM_ref4:
3904 return "DW_FORM_ref4";
3905 case DW_FORM_ref8:
3906 return "DW_FORM_ref8";
3907 case DW_FORM_ref_udata:
3908 return "DW_FORM_ref_udata";
3909 case DW_FORM_indirect:
3910 return "DW_FORM_indirect";
3911 default:
3912 return "DW_FORM_<unknown>";
3916 /* Convert a DWARF type code into its string name. */
3918 #if 0
3919 static const char *
3920 dwarf_type_encoding_name (enc)
3921 register unsigned enc;
3923 switch (enc)
3925 case DW_ATE_address:
3926 return "DW_ATE_address";
3927 case DW_ATE_boolean:
3928 return "DW_ATE_boolean";
3929 case DW_ATE_complex_float:
3930 return "DW_ATE_complex_float";
3931 case DW_ATE_float:
3932 return "DW_ATE_float";
3933 case DW_ATE_signed:
3934 return "DW_ATE_signed";
3935 case DW_ATE_signed_char:
3936 return "DW_ATE_signed_char";
3937 case DW_ATE_unsigned:
3938 return "DW_ATE_unsigned";
3939 case DW_ATE_unsigned_char:
3940 return "DW_ATE_unsigned_char";
3941 default:
3942 return "DW_ATE_<unknown>";
3945 #endif
3947 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3948 instance of an inlined instance of a decl which is local to an inline
3949 function, so we have to trace all of the way back through the origin chain
3950 to find out what sort of node actually served as the original seed for the
3951 given block. */
3953 static tree
3954 decl_ultimate_origin (decl)
3955 register tree decl;
3957 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3958 nodes in the function to point to themselves; ignore that if
3959 we're trying to output the abstract instance of this function. */
3960 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
3961 return NULL_TREE;
3963 #ifdef ENABLE_CHECKING
3964 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
3965 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3966 most distant ancestor, this should never happen. */
3967 abort ();
3968 #endif
3970 return DECL_ABSTRACT_ORIGIN (decl);
3973 /* Determine the "ultimate origin" of a block. The block may be an inlined
3974 instance of an inlined instance of a block which is local to an inline
3975 function, so we have to trace all of the way back through the origin chain
3976 to find out what sort of node actually served as the original seed for the
3977 given block. */
3979 static tree
3980 block_ultimate_origin (block)
3981 register tree block;
3983 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3985 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
3986 nodes in the function to point to themselves; ignore that if
3987 we're trying to output the abstract instance of this function. */
3988 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
3989 return NULL_TREE;
3991 if (immediate_origin == NULL_TREE)
3992 return NULL_TREE;
3993 else
3995 register tree ret_val;
3996 register tree lookahead = immediate_origin;
4000 ret_val = lookahead;
4001 lookahead = (TREE_CODE (ret_val) == BLOCK)
4002 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4003 : NULL;
4005 while (lookahead != NULL && lookahead != ret_val);
4007 return ret_val;
4011 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4012 of a virtual function may refer to a base class, so we check the 'this'
4013 parameter. */
4015 static tree
4016 decl_class_context (decl)
4017 tree decl;
4019 tree context = NULL_TREE;
4021 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4022 context = DECL_CONTEXT (decl);
4023 else
4024 context = TYPE_MAIN_VARIANT
4025 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4027 if (context && !TYPE_P (context))
4028 context = NULL_TREE;
4030 return context;
4033 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4034 addition order, and correct that in reverse_all_dies. */
4036 static inline void
4037 add_dwarf_attr (die, attr)
4038 register dw_die_ref die;
4039 register dw_attr_ref attr;
4041 if (die != NULL && attr != NULL)
4043 attr->dw_attr_next = die->die_attr;
4044 die->die_attr = attr;
4048 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4049 static inline dw_val_class
4050 AT_class (a)
4051 dw_attr_ref a;
4053 return a->dw_attr_val.val_class;
4056 /* Add a flag value attribute to a DIE. */
4058 static inline void
4059 add_AT_flag (die, attr_kind, flag)
4060 register dw_die_ref die;
4061 register enum dwarf_attribute attr_kind;
4062 register unsigned flag;
4064 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4066 attr->dw_attr_next = NULL;
4067 attr->dw_attr = attr_kind;
4068 attr->dw_attr_val.val_class = dw_val_class_flag;
4069 attr->dw_attr_val.v.val_flag = flag;
4070 add_dwarf_attr (die, attr);
4073 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4074 static inline unsigned
4075 AT_flag (a)
4076 register dw_attr_ref a;
4078 if (a && AT_class (a) == dw_val_class_flag)
4079 return a->dw_attr_val.v.val_flag;
4081 abort ();
4084 /* Add a signed integer attribute value to a DIE. */
4086 static inline void
4087 add_AT_int (die, attr_kind, int_val)
4088 register dw_die_ref die;
4089 register enum dwarf_attribute attr_kind;
4090 register long int int_val;
4092 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4094 attr->dw_attr_next = NULL;
4095 attr->dw_attr = attr_kind;
4096 attr->dw_attr_val.val_class = dw_val_class_const;
4097 attr->dw_attr_val.v.val_int = int_val;
4098 add_dwarf_attr (die, attr);
4101 static inline long int AT_int PARAMS ((dw_attr_ref));
4102 static inline long int
4103 AT_int (a)
4104 register dw_attr_ref a;
4106 if (a && AT_class (a) == dw_val_class_const)
4107 return a->dw_attr_val.v.val_int;
4109 abort ();
4112 /* Add an unsigned integer attribute value to a DIE. */
4114 static inline void
4115 add_AT_unsigned (die, attr_kind, unsigned_val)
4116 register dw_die_ref die;
4117 register enum dwarf_attribute attr_kind;
4118 register unsigned long unsigned_val;
4120 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4122 attr->dw_attr_next = NULL;
4123 attr->dw_attr = attr_kind;
4124 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4125 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4126 add_dwarf_attr (die, attr);
4129 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4130 static inline unsigned long
4131 AT_unsigned (a)
4132 register dw_attr_ref a;
4134 if (a && AT_class (a) == dw_val_class_unsigned_const)
4135 return a->dw_attr_val.v.val_unsigned;
4137 abort ();
4140 /* Add an unsigned double integer attribute value to a DIE. */
4142 static inline void
4143 add_AT_long_long (die, attr_kind, val_hi, val_low)
4144 register dw_die_ref die;
4145 register enum dwarf_attribute attr_kind;
4146 register unsigned long val_hi;
4147 register unsigned long val_low;
4149 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4151 attr->dw_attr_next = NULL;
4152 attr->dw_attr = attr_kind;
4153 attr->dw_attr_val.val_class = dw_val_class_long_long;
4154 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4155 attr->dw_attr_val.v.val_long_long.low = val_low;
4156 add_dwarf_attr (die, attr);
4159 /* Add a floating point attribute value to a DIE and return it. */
4161 static inline void
4162 add_AT_float (die, attr_kind, length, array)
4163 register dw_die_ref die;
4164 register enum dwarf_attribute attr_kind;
4165 register unsigned length;
4166 register long *array;
4168 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4170 attr->dw_attr_next = NULL;
4171 attr->dw_attr = attr_kind;
4172 attr->dw_attr_val.val_class = dw_val_class_float;
4173 attr->dw_attr_val.v.val_float.length = length;
4174 attr->dw_attr_val.v.val_float.array = array;
4175 add_dwarf_attr (die, attr);
4178 /* Add a string attribute value to a DIE. */
4180 static inline void
4181 add_AT_string (die, attr_kind, str)
4182 register dw_die_ref die;
4183 register enum dwarf_attribute attr_kind;
4184 register const char *str;
4186 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4188 attr->dw_attr_next = NULL;
4189 attr->dw_attr = attr_kind;
4190 attr->dw_attr_val.val_class = dw_val_class_str;
4191 attr->dw_attr_val.v.val_str = xstrdup (str);
4192 add_dwarf_attr (die, attr);
4195 static inline const char *AT_string PARAMS ((dw_attr_ref));
4196 static inline const char *
4197 AT_string (a)
4198 register dw_attr_ref a;
4200 if (a && AT_class (a) == dw_val_class_str)
4201 return a->dw_attr_val.v.val_str;
4203 abort ();
4206 /* Add a DIE reference attribute value to a DIE. */
4208 static inline void
4209 add_AT_die_ref (die, attr_kind, targ_die)
4210 register dw_die_ref die;
4211 register enum dwarf_attribute attr_kind;
4212 register dw_die_ref targ_die;
4214 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4216 attr->dw_attr_next = NULL;
4217 attr->dw_attr = attr_kind;
4218 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4219 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4220 attr->dw_attr_val.v.val_die_ref.external = 0;
4221 add_dwarf_attr (die, attr);
4224 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4225 static inline dw_die_ref
4226 AT_ref (a)
4227 register dw_attr_ref a;
4229 if (a && AT_class (a) == dw_val_class_die_ref)
4230 return a->dw_attr_val.v.val_die_ref.die;
4232 abort ();
4235 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4236 static inline int
4237 AT_ref_external (a)
4238 register dw_attr_ref a;
4240 if (a && AT_class (a) == dw_val_class_die_ref)
4241 return a->dw_attr_val.v.val_die_ref.external;
4243 return 0;
4246 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4247 static inline void
4248 set_AT_ref_external (a, i)
4249 register dw_attr_ref a;
4250 int i;
4252 if (a && AT_class (a) == dw_val_class_die_ref)
4253 a->dw_attr_val.v.val_die_ref.external = i;
4254 else
4255 abort ();
4258 /* Add an FDE reference attribute value to a DIE. */
4260 static inline void
4261 add_AT_fde_ref (die, attr_kind, targ_fde)
4262 register dw_die_ref die;
4263 register enum dwarf_attribute attr_kind;
4264 register unsigned targ_fde;
4266 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4268 attr->dw_attr_next = NULL;
4269 attr->dw_attr = attr_kind;
4270 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4271 attr->dw_attr_val.v.val_fde_index = targ_fde;
4272 add_dwarf_attr (die, attr);
4275 /* Add a location description attribute value to a DIE. */
4277 static inline void
4278 add_AT_loc (die, attr_kind, loc)
4279 register dw_die_ref die;
4280 register enum dwarf_attribute attr_kind;
4281 register dw_loc_descr_ref loc;
4283 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4285 attr->dw_attr_next = NULL;
4286 attr->dw_attr = attr_kind;
4287 attr->dw_attr_val.val_class = dw_val_class_loc;
4288 attr->dw_attr_val.v.val_loc = loc;
4289 add_dwarf_attr (die, attr);
4292 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4293 static inline dw_loc_descr_ref
4294 AT_loc (a)
4295 register dw_attr_ref a;
4297 if (a && AT_class (a) == dw_val_class_loc)
4298 return a->dw_attr_val.v.val_loc;
4300 abort ();
4303 /* Add an address constant attribute value to a DIE. */
4305 static inline void
4306 add_AT_addr (die, attr_kind, addr)
4307 register dw_die_ref die;
4308 register enum dwarf_attribute attr_kind;
4309 rtx addr;
4311 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4313 attr->dw_attr_next = NULL;
4314 attr->dw_attr = attr_kind;
4315 attr->dw_attr_val.val_class = dw_val_class_addr;
4316 attr->dw_attr_val.v.val_addr = addr;
4317 add_dwarf_attr (die, attr);
4320 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4321 static inline rtx
4322 AT_addr (a)
4323 register dw_attr_ref a;
4325 if (a && AT_class (a) == dw_val_class_addr)
4326 return a->dw_attr_val.v.val_addr;
4328 abort ();
4331 /* Add a label identifier attribute value to a DIE. */
4333 static inline void
4334 add_AT_lbl_id (die, attr_kind, lbl_id)
4335 register dw_die_ref die;
4336 register enum dwarf_attribute attr_kind;
4337 register const char *lbl_id;
4339 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4341 attr->dw_attr_next = NULL;
4342 attr->dw_attr = attr_kind;
4343 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4344 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4345 add_dwarf_attr (die, attr);
4348 /* Add a section offset attribute value to a DIE. */
4350 static inline void
4351 add_AT_lbl_offset (die, attr_kind, label)
4352 register dw_die_ref die;
4353 register enum dwarf_attribute attr_kind;
4354 register const char *label;
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_lbl_offset;
4361 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4362 add_dwarf_attr (die, attr);
4365 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4366 static inline const char *
4367 AT_lbl (a)
4368 register dw_attr_ref a;
4370 if (a && (AT_class (a) == dw_val_class_lbl_id
4371 || AT_class (a) == dw_val_class_lbl_offset))
4372 return a->dw_attr_val.v.val_lbl_id;
4374 abort ();
4377 /* Get the attribute of type attr_kind. */
4379 static inline dw_attr_ref
4380 get_AT (die, attr_kind)
4381 register dw_die_ref die;
4382 register enum dwarf_attribute attr_kind;
4384 register dw_attr_ref a;
4385 register dw_die_ref spec = NULL;
4387 if (die != NULL)
4389 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4391 if (a->dw_attr == attr_kind)
4392 return a;
4394 if (a->dw_attr == DW_AT_specification
4395 || a->dw_attr == DW_AT_abstract_origin)
4396 spec = AT_ref (a);
4399 if (spec)
4400 return get_AT (spec, attr_kind);
4403 return NULL;
4406 /* Return the "low pc" attribute value, typically associated with
4407 a subprogram DIE. Return null if the "low pc" attribute is
4408 either not prsent, or if it cannot be represented as an
4409 assembler label identifier. */
4411 static inline const char *
4412 get_AT_low_pc (die)
4413 register dw_die_ref die;
4415 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4416 return a ? AT_lbl (a) : NULL;
4419 /* Return the "high pc" attribute value, typically associated with
4420 a subprogram DIE. Return null if the "high pc" attribute is
4421 either not prsent, or if it cannot be represented as an
4422 assembler label identifier. */
4424 static inline const char *
4425 get_AT_hi_pc (die)
4426 register dw_die_ref die;
4428 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4429 return a ? AT_lbl (a) : NULL;
4432 /* Return the value of the string attribute designated by ATTR_KIND, or
4433 NULL if it is not present. */
4435 static inline const char *
4436 get_AT_string (die, attr_kind)
4437 register dw_die_ref die;
4438 register enum dwarf_attribute attr_kind;
4440 register dw_attr_ref a = get_AT (die, attr_kind);
4441 return a ? AT_string (a) : NULL;
4444 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4445 if it is not present. */
4447 static inline int
4448 get_AT_flag (die, attr_kind)
4449 register dw_die_ref die;
4450 register enum dwarf_attribute attr_kind;
4452 register dw_attr_ref a = get_AT (die, attr_kind);
4453 return a ? AT_flag (a) : 0;
4456 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4457 if it is not present. */
4459 static inline unsigned
4460 get_AT_unsigned (die, attr_kind)
4461 register dw_die_ref die;
4462 register enum dwarf_attribute attr_kind;
4464 register dw_attr_ref a = get_AT (die, attr_kind);
4465 return a ? AT_unsigned (a) : 0;
4468 static inline dw_die_ref
4469 get_AT_ref (die, attr_kind)
4470 dw_die_ref die;
4471 register enum dwarf_attribute attr_kind;
4473 register dw_attr_ref a = get_AT (die, attr_kind);
4474 return a ? AT_ref (a) : NULL;
4477 static inline int
4478 is_c_family ()
4480 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4482 return (lang == DW_LANG_C || lang == DW_LANG_C89
4483 || lang == DW_LANG_C_plus_plus);
4486 static inline int
4487 is_fortran ()
4489 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4491 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4494 static inline int
4495 is_java ()
4497 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4499 return (lang == DW_LANG_Java);
4502 /* Free up the memory used by A. */
4504 static inline void free_AT PARAMS ((dw_attr_ref));
4505 static inline void
4506 free_AT (a)
4507 dw_attr_ref a;
4509 switch (AT_class (a))
4511 case dw_val_class_str:
4512 case dw_val_class_lbl_id:
4513 case dw_val_class_lbl_offset:
4514 free (a->dw_attr_val.v.val_str);
4515 break;
4517 case dw_val_class_float:
4518 free (a->dw_attr_val.v.val_float.array);
4519 break;
4521 default:
4522 break;
4525 free (a);
4528 /* Remove the specified attribute if present. */
4530 static void
4531 remove_AT (die, attr_kind)
4532 register dw_die_ref die;
4533 register enum dwarf_attribute attr_kind;
4535 register dw_attr_ref *p;
4536 register dw_attr_ref removed = NULL;
4538 if (die != NULL)
4540 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4541 if ((*p)->dw_attr == attr_kind)
4543 removed = *p;
4544 *p = (*p)->dw_attr_next;
4545 break;
4548 if (removed != 0)
4549 free_AT (removed);
4553 /* Free up the memory used by DIE. */
4555 static inline void free_die PARAMS ((dw_die_ref));
4556 static inline void
4557 free_die (die)
4558 dw_die_ref die;
4560 remove_children (die);
4561 free (die);
4564 /* Discard the children of this DIE. */
4566 static void
4567 remove_children (die)
4568 register dw_die_ref die;
4570 register dw_die_ref child_die = die->die_child;
4572 die->die_child = NULL;
4574 while (child_die != NULL)
4576 register dw_die_ref tmp_die = child_die;
4577 register dw_attr_ref a;
4579 child_die = child_die->die_sib;
4581 for (a = tmp_die->die_attr; a != NULL;)
4583 register dw_attr_ref tmp_a = a;
4585 a = a->dw_attr_next;
4586 free_AT (tmp_a);
4589 free_die (tmp_die);
4593 /* Add a child DIE below its parent. We build the lists up in reverse
4594 addition order, and correct that in reverse_all_dies. */
4596 static inline void
4597 add_child_die (die, child_die)
4598 register dw_die_ref die;
4599 register dw_die_ref child_die;
4601 if (die != NULL && child_die != NULL)
4603 if (die == child_die)
4604 abort ();
4605 child_die->die_parent = die;
4606 child_die->die_sib = die->die_child;
4607 die->die_child = child_die;
4611 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4612 is the specification, to the front of PARENT's list of children. */
4614 static void
4615 splice_child_die (parent, child)
4616 dw_die_ref parent, child;
4618 dw_die_ref *p;
4620 /* We want the declaration DIE from inside the class, not the
4621 specification DIE at toplevel. */
4622 if (child->die_parent != parent)
4624 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4625 if (tmp)
4626 child = tmp;
4629 if (child->die_parent != parent
4630 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4631 abort ();
4633 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4634 if (*p == child)
4636 *p = child->die_sib;
4637 break;
4640 child->die_sib = parent->die_child;
4641 parent->die_child = child;
4644 /* Return a pointer to a newly created DIE node. */
4646 static inline dw_die_ref
4647 new_die (tag_value, parent_die)
4648 register enum dwarf_tag tag_value;
4649 register dw_die_ref parent_die;
4651 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4653 die->die_tag = tag_value;
4655 if (parent_die != NULL)
4656 add_child_die (parent_die, die);
4657 else
4659 limbo_die_node *limbo_node;
4661 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4662 limbo_node->die = die;
4663 limbo_node->next = limbo_die_list;
4664 limbo_die_list = limbo_node;
4667 return die;
4670 /* Return the DIE associated with the given type specifier. */
4672 static inline dw_die_ref
4673 lookup_type_die (type)
4674 register tree type;
4676 if (TREE_CODE (type) == VECTOR_TYPE)
4677 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4678 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4681 /* Equate a DIE to a given type specifier. */
4683 static inline void
4684 equate_type_number_to_die (type, type_die)
4685 register tree type;
4686 register dw_die_ref type_die;
4688 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4691 /* Return the DIE associated with a given declaration. */
4693 static inline dw_die_ref
4694 lookup_decl_die (decl)
4695 register tree decl;
4697 register unsigned decl_id = DECL_UID (decl);
4699 return (decl_id < decl_die_table_in_use
4700 ? decl_die_table[decl_id] : NULL);
4703 /* Equate a DIE to a particular declaration. */
4705 static void
4706 equate_decl_number_to_die (decl, decl_die)
4707 register tree decl;
4708 register dw_die_ref decl_die;
4710 register unsigned decl_id = DECL_UID (decl);
4711 register unsigned num_allocated;
4713 if (decl_id >= decl_die_table_allocated)
4715 num_allocated
4716 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4717 / DECL_DIE_TABLE_INCREMENT)
4718 * DECL_DIE_TABLE_INCREMENT;
4720 decl_die_table
4721 = (dw_die_ref *) xrealloc (decl_die_table,
4722 sizeof (dw_die_ref) * num_allocated);
4724 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4725 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4726 decl_die_table_allocated = num_allocated;
4729 if (decl_id >= decl_die_table_in_use)
4730 decl_die_table_in_use = (decl_id + 1);
4732 decl_die_table[decl_id] = decl_die;
4735 /* Keep track of the number of spaces used to indent the
4736 output of the debugging routines that print the structure of
4737 the DIE internal representation. */
4738 static int print_indent;
4740 /* Indent the line the number of spaces given by print_indent. */
4742 static inline void
4743 print_spaces (outfile)
4744 FILE *outfile;
4746 fprintf (outfile, "%*s", print_indent, "");
4749 /* Print the information associated with a given DIE, and its children.
4750 This routine is a debugging aid only. */
4752 static void
4753 print_die (die, outfile)
4754 dw_die_ref die;
4755 FILE *outfile;
4757 register dw_attr_ref a;
4758 register dw_die_ref c;
4760 print_spaces (outfile);
4761 fprintf (outfile, "DIE %4lu: %s\n",
4762 die->die_offset, dwarf_tag_name (die->die_tag));
4763 print_spaces (outfile);
4764 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4765 fprintf (outfile, " offset: %lu\n", die->die_offset);
4767 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4769 print_spaces (outfile);
4770 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4772 switch (AT_class (a))
4774 case dw_val_class_addr:
4775 fprintf (outfile, "address");
4776 break;
4777 case dw_val_class_loc:
4778 fprintf (outfile, "location descriptor");
4779 break;
4780 case dw_val_class_const:
4781 fprintf (outfile, "%ld", AT_int (a));
4782 break;
4783 case dw_val_class_unsigned_const:
4784 fprintf (outfile, "%lu", AT_unsigned (a));
4785 break;
4786 case dw_val_class_long_long:
4787 fprintf (outfile, "constant (%lu,%lu)",
4788 a->dw_attr_val.v.val_long_long.hi,
4789 a->dw_attr_val.v.val_long_long.low);
4790 break;
4791 case dw_val_class_float:
4792 fprintf (outfile, "floating-point constant");
4793 break;
4794 case dw_val_class_flag:
4795 fprintf (outfile, "%u", AT_flag (a));
4796 break;
4797 case dw_val_class_die_ref:
4798 if (AT_ref (a) != NULL)
4800 if (AT_ref (a)->die_symbol)
4801 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
4802 else
4803 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4805 else
4806 fprintf (outfile, "die -> <null>");
4807 break;
4808 case dw_val_class_lbl_id:
4809 case dw_val_class_lbl_offset:
4810 fprintf (outfile, "label: %s", AT_lbl (a));
4811 break;
4812 case dw_val_class_str:
4813 if (AT_string (a) != NULL)
4814 fprintf (outfile, "\"%s\"", AT_string (a));
4815 else
4816 fprintf (outfile, "<null>");
4817 break;
4818 default:
4819 break;
4822 fprintf (outfile, "\n");
4825 if (die->die_child != NULL)
4827 print_indent += 4;
4828 for (c = die->die_child; c != NULL; c = c->die_sib)
4829 print_die (c, outfile);
4831 print_indent -= 4;
4833 if (print_indent == 0)
4834 fprintf (outfile, "\n");
4837 /* Print the contents of the source code line number correspondence table.
4838 This routine is a debugging aid only. */
4840 static void
4841 print_dwarf_line_table (outfile)
4842 FILE *outfile;
4844 register unsigned i;
4845 register dw_line_info_ref line_info;
4847 fprintf (outfile, "\n\nDWARF source line information\n");
4848 for (i = 1; i < line_info_table_in_use; ++i)
4850 line_info = &line_info_table[i];
4851 fprintf (outfile, "%5d: ", i);
4852 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
4853 fprintf (outfile, "%6ld", line_info->dw_line_num);
4854 fprintf (outfile, "\n");
4857 fprintf (outfile, "\n\n");
4860 /* Print the information collected for a given DIE. */
4862 void
4863 debug_dwarf_die (die)
4864 dw_die_ref die;
4866 print_die (die, stderr);
4869 /* Print all DWARF information collected for the compilation unit.
4870 This routine is a debugging aid only. */
4872 void
4873 debug_dwarf ()
4875 print_indent = 0;
4876 print_die (comp_unit_die, stderr);
4877 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4878 print_dwarf_line_table (stderr);
4881 /* We build up the lists of children and attributes by pushing new ones
4882 onto the beginning of the list. Reverse the lists for DIE so that
4883 they are in order of addition. */
4885 static void
4886 reverse_die_lists (die)
4887 register dw_die_ref die;
4889 register dw_die_ref c, cp, cn;
4890 register dw_attr_ref a, ap, an;
4892 for (a = die->die_attr, ap = 0; a; a = an)
4894 an = a->dw_attr_next;
4895 a->dw_attr_next = ap;
4896 ap = a;
4898 die->die_attr = ap;
4900 for (c = die->die_child, cp = 0; c; c = cn)
4902 cn = c->die_sib;
4903 c->die_sib = cp;
4904 cp = c;
4906 die->die_child = cp;
4909 /* reverse_die_lists only reverses the single die you pass it. Since
4910 we used to reverse all dies in add_sibling_attributes, which runs
4911 through all the dies, it would reverse all the dies. Now, however,
4912 since we don't call reverse_die_lists in add_sibling_attributes, we
4913 need a routine to recursively reverse all the dies. This is that
4914 routine. */
4916 static void
4917 reverse_all_dies (die)
4918 register dw_die_ref die;
4920 register dw_die_ref c;
4922 reverse_die_lists (die);
4924 for (c = die->die_child; c; c = c->die_sib)
4925 reverse_all_dies (c);
4928 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
4929 the CU for the enclosing include file, if any. BINCL_DIE is the
4930 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
4931 include file. */
4933 static dw_die_ref
4934 push_new_compile_unit (old_unit, bincl_die)
4935 dw_die_ref old_unit, bincl_die;
4937 const char *filename = get_AT_string (bincl_die, DW_AT_name);
4938 dw_die_ref new_unit = gen_compile_unit_die (filename);
4939 new_unit->die_sib = old_unit;
4940 return new_unit;
4943 /* Close an include-file CU and reopen the enclosing one. */
4945 static dw_die_ref
4946 pop_compile_unit (old_unit)
4947 dw_die_ref old_unit;
4949 dw_die_ref new_unit = old_unit->die_sib;
4950 old_unit->die_sib = NULL;
4951 return new_unit;
4954 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
4955 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
4957 /* Calculate the checksum of a location expression. */
4959 static inline void
4960 loc_checksum (loc, ctx)
4961 dw_loc_descr_ref loc;
4962 struct md5_ctx *ctx;
4964 PROCESS (loc->dw_loc_opc);
4965 PROCESS (loc->dw_loc_oprnd1);
4966 PROCESS (loc->dw_loc_oprnd2);
4969 /* Calculate the checksum of an attribute. */
4971 static void
4972 attr_checksum (at, ctx)
4973 dw_attr_ref at;
4974 struct md5_ctx *ctx;
4976 dw_loc_descr_ref loc;
4977 rtx r;
4979 PROCESS (at->dw_attr);
4981 /* We don't care about differences in file numbering. */
4982 if (at->dw_attr == DW_AT_decl_file
4983 /* Or that this was compiled with a different compiler snapshot; if
4984 the output is the same, that's what matters. */
4985 || at->dw_attr == DW_AT_producer)
4986 return;
4988 switch (AT_class (at))
4990 case dw_val_class_const:
4991 PROCESS (at->dw_attr_val.v.val_int);
4992 break;
4993 case dw_val_class_unsigned_const:
4994 PROCESS (at->dw_attr_val.v.val_unsigned);
4995 break;
4996 case dw_val_class_long_long:
4997 PROCESS (at->dw_attr_val.v.val_long_long);
4998 break;
4999 case dw_val_class_float:
5000 PROCESS (at->dw_attr_val.v.val_float);
5001 break;
5002 case dw_val_class_flag:
5003 PROCESS (at->dw_attr_val.v.val_flag);
5004 break;
5006 case dw_val_class_str:
5007 PROCESS_STRING (AT_string (at));
5008 break;
5009 case dw_val_class_addr:
5010 r = AT_addr (at);
5011 switch (GET_CODE (r))
5013 case SYMBOL_REF:
5014 PROCESS_STRING (XSTR (r, 0));
5015 break;
5017 default:
5018 abort ();
5020 break;
5022 case dw_val_class_loc:
5023 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5024 loc_checksum (loc, ctx);
5025 break;
5027 case dw_val_class_die_ref:
5028 if (AT_ref (at)->die_offset)
5029 PROCESS (AT_ref (at)->die_offset);
5030 /* FIXME else use target die name or something. */
5032 case dw_val_class_fde_ref:
5033 case dw_val_class_lbl_id:
5034 case dw_val_class_lbl_offset:
5036 default:
5037 break;
5041 /* Calculate the checksum of a DIE. */
5043 static void
5044 die_checksum (die, ctx)
5045 dw_die_ref die;
5046 struct md5_ctx *ctx;
5048 dw_die_ref c;
5049 dw_attr_ref a;
5051 PROCESS (die->die_tag);
5053 for (a = die->die_attr; a; a = a->dw_attr_next)
5054 attr_checksum (a, ctx);
5056 for (c = die->die_child; c; c = c->die_sib)
5057 die_checksum (c, ctx);
5060 #undef PROCESS
5061 #undef PROCESS_STRING
5063 /* The prefix to attach to symbols on DIEs in the current comdat debug
5064 info section. */
5065 static char *comdat_symbol_id;
5067 /* The index of the current symbol within the current comdat CU. */
5068 static unsigned int comdat_symbol_number;
5070 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5071 children, and set comdat_symbol_id accordingly. */
5073 static void
5074 compute_section_prefix (unit_die)
5075 dw_die_ref unit_die;
5077 char *p, *name;
5078 int i;
5079 unsigned char checksum[16];
5080 struct md5_ctx ctx;
5082 md5_init_ctx (&ctx);
5083 die_checksum (unit_die, &ctx);
5084 md5_finish_ctx (&ctx, checksum);
5086 p = lbasename (get_AT_string (unit_die, DW_AT_name));
5087 name = (char *) alloca (strlen (p) + 64);
5088 sprintf (name, "%s.", p);
5090 clean_symbol_name (name);
5092 p = name + strlen (name);
5093 for (i = 0; i < 4; ++i)
5095 sprintf (p, "%.2x", checksum[i]);
5096 p += 2;
5099 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5100 comdat_symbol_number = 0;
5103 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5105 static int
5106 is_type_die (die)
5107 dw_die_ref die;
5109 switch (die->die_tag)
5111 case DW_TAG_array_type:
5112 case DW_TAG_class_type:
5113 case DW_TAG_enumeration_type:
5114 case DW_TAG_pointer_type:
5115 case DW_TAG_reference_type:
5116 case DW_TAG_string_type:
5117 case DW_TAG_structure_type:
5118 case DW_TAG_subroutine_type:
5119 case DW_TAG_union_type:
5120 case DW_TAG_ptr_to_member_type:
5121 case DW_TAG_set_type:
5122 case DW_TAG_subrange_type:
5123 case DW_TAG_base_type:
5124 case DW_TAG_const_type:
5125 case DW_TAG_file_type:
5126 case DW_TAG_packed_type:
5127 case DW_TAG_volatile_type:
5128 return 1;
5129 default:
5130 return 0;
5134 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5135 Basically, we want to choose the bits that are likely to be shared between
5136 compilations (types) and leave out the bits that are specific to individual
5137 compilations (functions). */
5139 static int
5140 is_comdat_die (c)
5141 dw_die_ref c;
5143 #if 1
5144 /* I think we want to leave base types and __vtbl_ptr_type in the
5145 main CU, as we do for stabs. The advantage is a greater
5146 likelihood of sharing between objects that don't include headers
5147 in the same order (and therefore would put the base types in a
5148 different comdat). jason 8/28/00 */
5149 if (c->die_tag == DW_TAG_base_type)
5150 return 0;
5152 if (c->die_tag == DW_TAG_pointer_type
5153 || c->die_tag == DW_TAG_reference_type
5154 || c->die_tag == DW_TAG_const_type
5155 || c->die_tag == DW_TAG_volatile_type)
5157 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5158 return t ? is_comdat_die (t) : 0;
5160 #endif
5162 return is_type_die (c);
5165 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5166 compilation unit. */
5168 static int
5169 is_symbol_die (c)
5170 dw_die_ref c;
5172 if (is_type_die (c))
5173 return 1;
5174 if (get_AT (c, DW_AT_declaration)
5175 && ! get_AT (c, DW_AT_specification))
5176 return 1;
5177 return 0;
5180 static char *
5181 gen_internal_sym ()
5183 char buf[256];
5184 static int label_num;
5185 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5186 return xstrdup (buf);
5189 /* Assign symbols to all worthy DIEs under DIE. */
5191 static void
5192 assign_symbol_names (die)
5193 register dw_die_ref die;
5195 register dw_die_ref c;
5197 if (is_symbol_die (die))
5199 if (comdat_symbol_id)
5201 char *p = alloca (strlen (comdat_symbol_id) + 64);
5202 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5203 comdat_symbol_id, comdat_symbol_number++);
5204 die->die_symbol = xstrdup (p);
5206 else
5207 die->die_symbol = gen_internal_sym ();
5210 for (c = die->die_child; c != NULL; c = c->die_sib)
5211 assign_symbol_names (c);
5214 /* Traverse the DIE (which is always comp_unit_die), and set up
5215 additional compilation units for each of the include files we see
5216 bracketed by BINCL/EINCL. */
5218 static void
5219 break_out_includes (die)
5220 register dw_die_ref die;
5222 dw_die_ref *ptr;
5223 register dw_die_ref unit = NULL;
5224 limbo_die_node *node;
5226 for (ptr = &(die->die_child); *ptr; )
5228 register dw_die_ref c = *ptr;
5230 if (c->die_tag == DW_TAG_GNU_BINCL
5231 || c->die_tag == DW_TAG_GNU_EINCL
5232 || (unit && is_comdat_die (c)))
5234 /* This DIE is for a secondary CU; remove it from the main one. */
5235 *ptr = c->die_sib;
5237 if (c->die_tag == DW_TAG_GNU_BINCL)
5239 unit = push_new_compile_unit (unit, c);
5240 free_die (c);
5242 else if (c->die_tag == DW_TAG_GNU_EINCL)
5244 unit = pop_compile_unit (unit);
5245 free_die (c);
5247 else
5248 add_child_die (unit, c);
5250 else
5252 /* Leave this DIE in the main CU. */
5253 ptr = &(c->die_sib);
5254 continue;
5258 #if 0
5259 /* We can only use this in debugging, since the frontend doesn't check
5260 to make sure that we leave every include file we enter. */
5261 if (unit != NULL)
5262 abort ();
5263 #endif
5265 assign_symbol_names (die);
5266 for (node = limbo_die_list; node; node = node->next)
5268 compute_section_prefix (node->die);
5269 assign_symbol_names (node->die);
5273 /* Traverse the DIE and add a sibling attribute if it may have the
5274 effect of speeding up access to siblings. To save some space,
5275 avoid generating sibling attributes for DIE's without children. */
5277 static void
5278 add_sibling_attributes (die)
5279 register dw_die_ref die;
5281 register dw_die_ref c;
5283 if (die->die_tag != DW_TAG_compile_unit
5284 && die->die_sib && die->die_child != NULL)
5285 /* Add the sibling link to the front of the attribute list. */
5286 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5288 for (c = die->die_child; c != NULL; c = c->die_sib)
5289 add_sibling_attributes (c);
5292 /* The format of each DIE (and its attribute value pairs)
5293 is encoded in an abbreviation table. This routine builds the
5294 abbreviation table and assigns a unique abbreviation id for
5295 each abbreviation entry. The children of each die are visited
5296 recursively. */
5298 static void
5299 build_abbrev_table (die)
5300 register dw_die_ref die;
5302 register unsigned long abbrev_id;
5303 register unsigned long n_alloc;
5304 register dw_die_ref c;
5305 register dw_attr_ref d_attr, a_attr;
5307 /* Scan the DIE references, and mark as external any that refer to
5308 DIEs from other CUs (i.e. those which are not marked). */
5309 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5311 if (AT_class (d_attr) == dw_val_class_die_ref
5312 && AT_ref (d_attr)->die_mark == 0)
5314 if (AT_ref (d_attr)->die_symbol == 0)
5315 abort ();
5316 set_AT_ref_external (d_attr, 1);
5320 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5322 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5324 if (abbrev->die_tag == die->die_tag)
5326 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5328 a_attr = abbrev->die_attr;
5329 d_attr = die->die_attr;
5331 while (a_attr != NULL && d_attr != NULL)
5333 if ((a_attr->dw_attr != d_attr->dw_attr)
5334 || (value_format (a_attr) != value_format (d_attr)))
5335 break;
5337 a_attr = a_attr->dw_attr_next;
5338 d_attr = d_attr->dw_attr_next;
5341 if (a_attr == NULL && d_attr == NULL)
5342 break;
5347 if (abbrev_id >= abbrev_die_table_in_use)
5349 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5351 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5352 abbrev_die_table
5353 = (dw_die_ref *) xrealloc (abbrev_die_table,
5354 sizeof (dw_die_ref) * n_alloc);
5356 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5357 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5358 abbrev_die_table_allocated = n_alloc;
5361 ++abbrev_die_table_in_use;
5362 abbrev_die_table[abbrev_id] = die;
5365 die->die_abbrev = abbrev_id;
5366 for (c = die->die_child; c != NULL; c = c->die_sib)
5367 build_abbrev_table (c);
5370 /* Return the size of a string, including the null byte.
5372 This used to treat backslashes as escapes, and hence they were not included
5373 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5374 which treats a backslash as a backslash, escaping it if necessary, and hence
5375 we must include them in the count. */
5377 static unsigned long
5378 size_of_string (str)
5379 register const char *str;
5381 return strlen (str) + 1;
5384 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5386 static int
5387 constant_size (value)
5388 long unsigned value;
5390 int log;
5392 if (value == 0)
5393 log = 0;
5394 else
5395 log = floor_log2 (value);
5397 log = log / 8;
5398 log = 1 << (floor_log2 (log) + 1);
5400 return log;
5403 /* Return the size of a DIE, as it is represented in the
5404 .debug_info section. */
5406 static unsigned long
5407 size_of_die (die)
5408 register dw_die_ref die;
5410 register unsigned long size = 0;
5411 register dw_attr_ref a;
5413 size += size_of_uleb128 (die->die_abbrev);
5414 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5416 switch (AT_class (a))
5418 case dw_val_class_addr:
5419 size += DWARF2_ADDR_SIZE;
5420 break;
5421 case dw_val_class_loc:
5423 register unsigned long lsize = size_of_locs (AT_loc (a));
5425 /* Block length. */
5426 size += constant_size (lsize);
5427 size += lsize;
5429 break;
5430 case dw_val_class_const:
5431 size += size_of_sleb128 (AT_int (a));
5432 break;
5433 case dw_val_class_unsigned_const:
5434 size += constant_size (AT_unsigned (a));
5435 break;
5436 case dw_val_class_long_long:
5437 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5438 break;
5439 case dw_val_class_float:
5440 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5441 break;
5442 case dw_val_class_flag:
5443 size += 1;
5444 break;
5445 case dw_val_class_die_ref:
5446 size += DWARF_OFFSET_SIZE;
5447 break;
5448 case dw_val_class_fde_ref:
5449 size += DWARF_OFFSET_SIZE;
5450 break;
5451 case dw_val_class_lbl_id:
5452 size += DWARF2_ADDR_SIZE;
5453 break;
5454 case dw_val_class_lbl_offset:
5455 size += DWARF_OFFSET_SIZE;
5456 break;
5457 case dw_val_class_str:
5458 size += size_of_string (AT_string (a));
5459 break;
5460 default:
5461 abort ();
5465 return size;
5468 /* Size the debugging information associated with a given DIE.
5469 Visits the DIE's children recursively. Updates the global
5470 variable next_die_offset, on each time through. Uses the
5471 current value of next_die_offset to update the die_offset
5472 field in each DIE. */
5474 static void
5475 calc_die_sizes (die)
5476 dw_die_ref die;
5478 register dw_die_ref c;
5479 die->die_offset = next_die_offset;
5480 next_die_offset += size_of_die (die);
5482 for (c = die->die_child; c != NULL; c = c->die_sib)
5483 calc_die_sizes (c);
5485 if (die->die_child != NULL)
5486 /* Count the null byte used to terminate sibling lists. */
5487 next_die_offset += 1;
5490 /* Set the marks for a die and its children. We do this so
5491 that we know whether or not a reference needs to use FORM_ref_addr; only
5492 DIEs in the same CU will be marked. We used to clear out the offset
5493 and use that as the flag, but ran into ordering problems. */
5495 static void
5496 mark_dies (die)
5497 dw_die_ref die;
5499 register dw_die_ref c;
5500 die->die_mark = 1;
5501 for (c = die->die_child; c; c = c->die_sib)
5502 mark_dies (c);
5505 /* Clear the marks for a die and its children. */
5507 static void
5508 unmark_dies (die)
5509 dw_die_ref die;
5511 register dw_die_ref c;
5512 die->die_mark = 0;
5513 for (c = die->die_child; c; c = c->die_sib)
5514 unmark_dies (c);
5517 /* Return the size of the .debug_pubnames table generated for the
5518 compilation unit. */
5520 static unsigned long
5521 size_of_pubnames ()
5523 register unsigned long size;
5524 register unsigned i;
5526 size = DWARF_PUBNAMES_HEADER_SIZE;
5527 for (i = 0; i < pubname_table_in_use; ++i)
5529 register pubname_ref p = &pubname_table[i];
5530 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5533 size += DWARF_OFFSET_SIZE;
5534 return size;
5537 /* Return the size of the information in the .debug_aranges section. */
5539 static unsigned long
5540 size_of_aranges ()
5542 register unsigned long size;
5544 size = DWARF_ARANGES_HEADER_SIZE;
5546 /* Count the address/length pair for this compilation unit. */
5547 size += 2 * DWARF2_ADDR_SIZE;
5548 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5550 /* Count the two zero words used to terminated the address range table. */
5551 size += 2 * DWARF2_ADDR_SIZE;
5552 return size;
5555 /* Select the encoding of an attribute value. */
5557 static enum dwarf_form
5558 value_format (a)
5559 dw_attr_ref a;
5561 switch (a->dw_attr_val.val_class)
5563 case dw_val_class_addr:
5564 return DW_FORM_addr;
5565 case dw_val_class_loc:
5566 switch (constant_size (size_of_locs (AT_loc (a))))
5568 case 1:
5569 return DW_FORM_block1;
5570 case 2:
5571 return DW_FORM_block2;
5572 default:
5573 abort ();
5575 case dw_val_class_const:
5576 return DW_FORM_sdata;
5577 case dw_val_class_unsigned_const:
5578 switch (constant_size (AT_unsigned (a)))
5580 case 1:
5581 return DW_FORM_data1;
5582 case 2:
5583 return DW_FORM_data2;
5584 case 4:
5585 return DW_FORM_data4;
5586 case 8:
5587 return DW_FORM_data8;
5588 default:
5589 abort ();
5591 case dw_val_class_long_long:
5592 return DW_FORM_block1;
5593 case dw_val_class_float:
5594 return DW_FORM_block1;
5595 case dw_val_class_flag:
5596 return DW_FORM_flag;
5597 case dw_val_class_die_ref:
5598 if (AT_ref_external (a))
5599 return DW_FORM_ref_addr;
5600 else
5601 return DW_FORM_ref;
5602 case dw_val_class_fde_ref:
5603 return DW_FORM_data;
5604 case dw_val_class_lbl_id:
5605 return DW_FORM_addr;
5606 case dw_val_class_lbl_offset:
5607 return DW_FORM_data;
5608 case dw_val_class_str:
5609 return DW_FORM_string;
5610 default:
5611 abort ();
5615 /* Output the encoding of an attribute value. */
5617 static void
5618 output_value_format (a)
5619 dw_attr_ref a;
5621 enum dwarf_form form = value_format (a);
5622 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
5625 /* Output the .debug_abbrev section which defines the DIE abbreviation
5626 table. */
5628 static void
5629 output_abbrev_section ()
5631 unsigned long abbrev_id;
5633 dw_attr_ref a_attr;
5634 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5636 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5638 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
5640 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
5641 dwarf_tag_name (abbrev->die_tag));
5643 if (abbrev->die_child != NULL)
5644 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
5645 else
5646 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
5648 for (a_attr = abbrev->die_attr; a_attr != NULL;
5649 a_attr = a_attr->dw_attr_next)
5651 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
5652 dwarf_attr_name (a_attr->dw_attr));
5653 output_value_format (a_attr);
5656 dw2_asm_output_data (1, 0, NULL);
5657 dw2_asm_output_data (1, 0, NULL);
5660 /* Terminate the table. */
5661 dw2_asm_output_data (1, 0, NULL);
5664 /* Output a symbol we can use to refer to this DIE from another CU. */
5666 static inline void
5667 output_die_symbol (die)
5668 register dw_die_ref die;
5670 char *sym = die->die_symbol;
5672 if (sym == 0)
5673 return;
5675 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5676 /* We make these global, not weak; if the target doesn't support
5677 .linkonce, it doesn't support combining the sections, so debugging
5678 will break. */
5679 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5680 ASM_OUTPUT_LABEL (asm_out_file, sym);
5683 /* Output the DIE and its attributes. Called recursively to generate
5684 the definitions of each child DIE. */
5686 static void
5687 output_die (die)
5688 register dw_die_ref die;
5690 register dw_attr_ref a;
5691 register dw_die_ref c;
5692 register unsigned long size;
5694 /* If someone in another CU might refer to us, set up a symbol for
5695 them to point to. */
5696 if (die->die_symbol)
5697 output_die_symbol (die);
5699 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
5700 die->die_offset, dwarf_tag_name (die->die_tag));
5702 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5704 const char *name = dwarf_attr_name (a->dw_attr);
5706 switch (AT_class (a))
5708 case dw_val_class_addr:
5709 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
5710 break;
5712 case dw_val_class_loc:
5713 size = size_of_locs (AT_loc (a));
5715 /* Output the block length for this list of location operations. */
5716 dw2_asm_output_data (constant_size (size), size, "%s", name);
5718 output_loc_sequence (AT_loc (a));
5719 break;
5721 case dw_val_class_const:
5722 /* ??? It would be slightly more efficient to use a scheme like is
5723 used for unsigned constants below, but gdb 4.x does not sign
5724 extend. Gdb 5.x does sign extend. */
5725 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
5726 break;
5728 case dw_val_class_unsigned_const:
5729 dw2_asm_output_data (constant_size (AT_unsigned (a)),
5730 AT_unsigned (a), "%s", name);
5731 break;
5733 case dw_val_class_long_long:
5735 unsigned HOST_WIDE_INT first, second;
5737 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5738 "%s", name);
5740 if (WORDS_BIG_ENDIAN)
5742 first = a->dw_attr_val.v.val_long_long.hi;
5743 second = a->dw_attr_val.v.val_long_long.low;
5745 else
5747 first = a->dw_attr_val.v.val_long_long.low;
5748 second = a->dw_attr_val.v.val_long_long.hi;
5750 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5751 first, "long long constant");
5752 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5753 second, NULL);
5755 break;
5757 case dw_val_class_float:
5759 register unsigned int i;
5761 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
5762 "%s", name);
5764 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5765 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
5766 "fp constant word %u", i);
5767 break;
5770 case dw_val_class_flag:
5771 dw2_asm_output_data (1, AT_flag (a), "%s", name);
5772 break;
5774 case dw_val_class_die_ref:
5775 if (AT_ref_external (a))
5777 char *sym = AT_ref (a)->die_symbol;
5778 if (sym == 0)
5779 abort ();
5780 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
5782 else if (AT_ref (a)->die_offset == 0)
5783 abort ();
5784 else
5785 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
5786 "%s", name);
5787 break;
5789 case dw_val_class_fde_ref:
5791 char l1[20];
5792 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
5793 a->dw_attr_val.v.val_fde_index * 2);
5794 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
5796 break;
5798 case dw_val_class_lbl_id:
5799 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
5800 break;
5802 case dw_val_class_lbl_offset:
5803 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
5804 break;
5806 case dw_val_class_str:
5807 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
5808 break;
5810 default:
5811 abort ();
5815 for (c = die->die_child; c != NULL; c = c->die_sib)
5816 output_die (c);
5818 if (die->die_child != NULL)
5820 /* Add null byte to terminate sibling list. */
5821 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
5822 die->die_offset);
5826 /* Output the compilation unit that appears at the beginning of the
5827 .debug_info section, and precedes the DIE descriptions. */
5829 static void
5830 output_compilation_unit_header ()
5832 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
5833 "Length of Compilation Unit Info");
5835 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
5837 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
5838 "Offset Into Abbrev. Section");
5840 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
5843 /* Output the compilation unit DIE and its children. */
5845 static void
5846 output_comp_unit (die)
5847 dw_die_ref die;
5849 const char *secname;
5851 if (die->die_child == 0)
5852 return;
5854 /* Mark all the DIEs in this CU so we know which get local refs. */
5855 mark_dies (die);
5857 build_abbrev_table (die);
5859 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
5860 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
5861 calc_die_sizes (die);
5863 if (die->die_symbol)
5865 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
5866 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
5867 secname = tmp;
5868 die->die_symbol = NULL;
5870 else
5871 secname = (const char *) DEBUG_INFO_SECTION;
5873 /* Output debugging information. */
5874 ASM_OUTPUT_SECTION (asm_out_file, secname);
5875 output_compilation_unit_header ();
5876 output_die (die);
5878 /* Leave the marks on the main CU, so we can check them in
5879 output_pubnames. */
5880 if (die->die_symbol)
5881 unmark_dies (die);
5884 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5885 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5886 argument list, and maybe the scope. */
5888 static const char *
5889 dwarf2_name (decl, scope)
5890 tree decl;
5891 int scope;
5893 return (*decl_printable_name) (decl, scope ? 1 : 0);
5896 /* Add a new entry to .debug_pubnames if appropriate. */
5898 static void
5899 add_pubname (decl, die)
5900 tree decl;
5901 dw_die_ref die;
5903 pubname_ref p;
5905 if (! TREE_PUBLIC (decl))
5906 return;
5908 if (pubname_table_in_use == pubname_table_allocated)
5910 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5911 pubname_table = (pubname_ref) xrealloc
5912 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5915 p = &pubname_table[pubname_table_in_use++];
5916 p->die = die;
5918 p->name = xstrdup (dwarf2_name (decl, 1));
5921 /* Output the public names table used to speed up access to externally
5922 visible names. For now, only generate entries for externally
5923 visible procedures. */
5925 static void
5926 output_pubnames ()
5928 register unsigned i;
5929 register unsigned long pubnames_length = size_of_pubnames ();
5931 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
5932 "Length of Public Names Info");
5934 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
5936 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
5937 "Offset of Compilation Unit Info");
5939 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
5940 "Compilation Unit Length");
5942 for (i = 0; i < pubname_table_in_use; ++i)
5944 register pubname_ref pub = &pubname_table[i];
5946 /* We shouldn't see pubnames for DIEs outside of the main CU. */
5947 if (pub->die->die_mark == 0)
5948 abort ();
5950 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
5951 "DIE offset");
5953 dw2_asm_output_nstring (pub->name, -1, "external name");
5956 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
5959 /* Add a new entry to .debug_aranges if appropriate. */
5961 static void
5962 add_arange (decl, die)
5963 tree decl;
5964 dw_die_ref die;
5966 if (! DECL_SECTION_NAME (decl))
5967 return;
5969 if (arange_table_in_use == arange_table_allocated)
5971 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5972 arange_table
5973 = (arange_ref) xrealloc (arange_table,
5974 arange_table_allocated * sizeof (dw_die_ref));
5977 arange_table[arange_table_in_use++] = die;
5980 /* Output the information that goes into the .debug_aranges table.
5981 Namely, define the beginning and ending address range of the
5982 text section generated for this compilation unit. */
5984 static void
5985 output_aranges ()
5987 register unsigned i;
5988 register unsigned long aranges_length = size_of_aranges ();
5990 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
5991 "Length of Address Ranges Info");
5993 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
5995 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
5996 "Offset of Compilation Unit Info");
5998 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6000 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6002 /* We need to align to twice the pointer size here. */
6003 if (DWARF_ARANGES_PAD_SIZE)
6005 /* Pad using a 2 byte words so that padding is correct for any
6006 pointer size. */
6007 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6008 2 * DWARF2_ADDR_SIZE);
6009 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6010 dw2_asm_output_data (2, 0, NULL);
6013 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6014 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6015 text_section_label, "Length");
6017 for (i = 0; i < arange_table_in_use; ++i)
6019 dw_die_ref die = arange_table[i];
6021 /* We shouldn't see aranges for DIEs outside of the main CU. */
6022 if (die->die_mark == 0)
6023 abort ();
6025 if (die->die_tag == DW_TAG_subprogram)
6027 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6028 "Address");
6029 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6030 get_AT_low_pc (die), "Length");
6032 else
6034 /* A static variable; extract the symbol from DW_AT_location.
6035 Note that this code isn't currently hit, as we only emit
6036 aranges for functions (jason 9/23/99). */
6038 dw_attr_ref a = get_AT (die, DW_AT_location);
6039 dw_loc_descr_ref loc;
6040 if (! a || AT_class (a) != dw_val_class_loc)
6041 abort ();
6043 loc = AT_loc (a);
6044 if (loc->dw_loc_opc != DW_OP_addr)
6045 abort ();
6047 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6048 loc->dw_loc_oprnd1.v.val_addr, "Address");
6049 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6050 get_AT_unsigned (die, DW_AT_byte_size),
6051 "Length");
6055 /* Output the terminator words. */
6056 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6057 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6061 /* Data structure containing information about input files. */
6062 struct file_info
6064 char *path; /* Complete file name. */
6065 char *fname; /* File name part. */
6066 int length; /* Length of entire string. */
6067 int file_idx; /* Index in input file table. */
6068 int dir_idx; /* Index in directory table. */
6071 /* Data structure containing information about directories with source
6072 files. */
6073 struct dir_info
6075 char *path; /* Path including directory name. */
6076 int length; /* Path length. */
6077 int prefix; /* Index of directory entry which is a prefix. */
6078 int count; /* Number of files in this directory. */
6079 int dir_idx; /* Index of directory used as base. */
6080 int used; /* Used in the end? */
6083 /* Callback function for file_info comparison. We sort by looking at
6084 the directories in the path. */
6085 static int
6086 file_info_cmp (p1, p2)
6087 const void *p1;
6088 const void *p2;
6090 const struct file_info *s1 = p1;
6091 const struct file_info *s2 = p2;
6092 unsigned char *cp1;
6093 unsigned char *cp2;
6095 /* Take care of file names without directories. */
6096 if (s1->path == s1->fname)
6097 return -1;
6098 else if (s2->path == s2->fname)
6099 return 1;
6101 cp1 = (unsigned char *) s1->path;
6102 cp2 = (unsigned char *) s2->path;
6104 while (1)
6106 ++cp1;
6107 ++cp2;
6108 /* Reached the end of the first path? */
6109 if (cp1 == (unsigned char *) s1->fname)
6110 /* It doesn't really matter in which order files from the
6111 same directory are sorted in. Therefore don't test for
6112 the second path reaching the end. */
6113 return -1;
6114 else if (cp2 == (unsigned char *) s2->fname)
6115 return 1;
6117 /* Character of current path component the same? */
6118 if (*cp1 != *cp2)
6119 return *cp1 - *cp2;
6123 /* Output the directory table and the file name table. We try to minimize
6124 the total amount of memory needed. A heuristic is used to avoid large
6125 slowdowns with many input files. */
6126 static void
6127 output_file_names ()
6129 struct file_info *files;
6130 struct dir_info *dirs;
6131 int *saved;
6132 int *savehere;
6133 int *backmap;
6134 int ndirs;
6135 int idx_offset;
6136 int i;
6137 int idx;
6139 /* Allocate the various arrays we need. */
6140 files = (struct file_info *) alloca (file_table.in_use
6141 * sizeof (struct file_info));
6142 dirs = (struct dir_info *) alloca (file_table.in_use
6143 * sizeof (struct dir_info));
6145 /* Sort the file names. */
6146 for (i = 1; i < (int) file_table.in_use; ++i)
6148 char *f;
6150 /* Skip all leading "./". */
6151 f = file_table.table[i];
6152 while (f[0] == '.' && f[1] == '/')
6153 f += 2;
6155 /* Create a new array entry. */
6156 files[i].path = f;
6157 files[i].length = strlen (f);
6158 files[i].file_idx = i;
6160 /* Search for the file name part. */
6161 f = strrchr (f, '/');
6162 files[i].fname = f == NULL ? files[i].path : f + 1;
6164 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6166 /* Find all the different directories used. */
6167 dirs[0].path = files[1].path;
6168 dirs[0].length = files[1].fname - files[1].path;
6169 dirs[0].prefix = -1;
6170 dirs[0].count = 1;
6171 dirs[0].dir_idx = 0;
6172 dirs[0].used = 0;
6173 files[1].dir_idx = 0;
6174 ndirs = 1;
6176 for (i = 2; i < (int) file_table.in_use; ++i)
6177 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6178 && memcmp (dirs[ndirs - 1].path, files[i].path,
6179 dirs[ndirs - 1].length) == 0)
6181 /* Same directory as last entry. */
6182 files[i].dir_idx = ndirs - 1;
6183 ++dirs[ndirs - 1].count;
6185 else
6187 int j;
6189 /* This is a new directory. */
6190 dirs[ndirs].path = files[i].path;
6191 dirs[ndirs].length = files[i].fname - files[i].path;
6192 dirs[ndirs].count = 1;
6193 dirs[ndirs].dir_idx = ndirs;
6194 dirs[ndirs].used = 0;
6195 files[i].dir_idx = ndirs;
6197 /* Search for a prefix. */
6198 dirs[ndirs].prefix = -1;
6199 for (j = 0; j < ndirs; ++j)
6200 if (dirs[j].length < dirs[ndirs].length
6201 && dirs[j].length > 1
6202 && (dirs[ndirs].prefix == -1
6203 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6204 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6205 dirs[ndirs].prefix = j;
6207 ++ndirs;
6210 /* Now to the actual work. We have to find a subset of the
6211 directories which allow expressing the file name using references
6212 to the directory table with the least amount of characters. We
6213 do not do an exhaustive search where we would have to check out
6214 every combination of every single possible prefix. Instead we
6215 use a heuristic which provides nearly optimal results in most
6216 cases and never is much off. */
6217 saved = (int *) alloca (ndirs * sizeof (int));
6218 savehere = (int *) alloca (ndirs * sizeof (int));
6220 memset (saved, '\0', ndirs * sizeof (saved[0]));
6221 for (i = 0; i < ndirs; ++i)
6223 int j;
6224 int total;
6226 /* We can always save some space for the current directory. But
6227 this does not mean it will be enough to justify adding the
6228 directory. */
6229 savehere[i] = dirs[i].length;
6230 total = (savehere[i] - saved[i]) * dirs[i].count;
6232 for (j = i + 1; j < ndirs; ++j)
6234 savehere[j] = 0;
6236 if (saved[j] < dirs[i].length)
6238 /* Determine whether the dirs[i] path is a prefix of the
6239 dirs[j] path. */
6240 int k;
6242 k = dirs[j].prefix;
6243 while (k != -1 && k != i)
6244 k = dirs[k].prefix;
6246 if (k == i)
6248 /* Yes it is. We can possibly safe some memory but
6249 writing the filenames in dirs[j] relative to
6250 dirs[i]. */
6251 savehere[j] = dirs[i].length;
6252 total += (savehere[j] - saved[j]) * dirs[j].count;
6257 /* Check whether we can safe enough to justify adding the dirs[i]
6258 directory. */
6259 if (total > dirs[i].length + 1)
6261 /* It's worthwhile adding. */
6262 for (j = i; j < ndirs; ++j)
6263 if (savehere[j] > 0)
6265 /* Remember how much we saved for this directory so far. */
6266 saved[j] = savehere[j];
6268 /* Remember the prefix directory. */
6269 dirs[j].dir_idx = i;
6274 /* We have to emit them in the order they appear in the file_table
6275 array since the index is used in the debug info generation. To
6276 do this efficiently we generate a back-mapping of the indices
6277 first. */
6278 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6279 for (i = 1; i < (int) file_table.in_use; ++i)
6281 backmap[files[i].file_idx] = i;
6282 /* Mark this directory as used. */
6283 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6286 /* That was it. We are ready to emit the information. First the
6287 directory name table. Here we have to make sure that the first
6288 actually emitted directory name has the index one. Zero is
6289 reserved for the current working directory. Make sure we do not
6290 confuse these indices with the one for the constructed table
6291 (even though most of the time they are identical). */
6292 idx = 1;
6293 idx_offset = dirs[0].length > 0 ? 1 : 0;
6294 for (i = 1 - idx_offset; i < ndirs; ++i)
6295 if (dirs[i].used != 0)
6297 dirs[i].used = idx++;
6298 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6299 "Directory Entry: 0x%x", dirs[i].used);
6301 dw2_asm_output_data (1, 0, "End directory table");
6303 /* Correct the index for the current working directory entry if it
6304 exists. */
6305 if (idx_offset == 0)
6306 dirs[0].used = 0;
6308 /* Now write all the file names. */
6309 for (i = 1; i < (int) file_table.in_use; ++i)
6311 int file_idx = backmap[i];
6312 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6314 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6315 "File Entry: 0x%x", i);
6317 /* Include directory index. */
6318 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6320 /* Modification time. */
6321 dw2_asm_output_data_uleb128 (0, NULL);
6323 /* File length in bytes. */
6324 dw2_asm_output_data_uleb128 (0, NULL);
6326 dw2_asm_output_data (1, 0, "End file name table");
6330 /* Output the source line number correspondence information. This
6331 information goes into the .debug_line section. */
6333 static void
6334 output_line_info ()
6336 char l1[20], l2[20], p1[20], p2[20];
6337 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6338 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6339 register unsigned opc;
6340 register unsigned n_op_args;
6341 register unsigned long lt_index;
6342 register unsigned long current_line;
6343 register long line_offset;
6344 register long line_delta;
6345 register unsigned long current_file;
6346 register unsigned long function;
6348 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6349 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6350 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6351 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6353 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6354 "Length of Source Line Info");
6355 ASM_OUTPUT_LABEL (asm_out_file, l1);
6357 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6359 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6360 ASM_OUTPUT_LABEL (asm_out_file, p1);
6362 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6363 "Minimum Instruction Length");
6365 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6366 "Default is_stmt_start flag");
6368 dw2_asm_output_data (1, DWARF_LINE_BASE,
6369 "Line Base Value (Special Opcodes)");
6371 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6372 "Line Range Value (Special Opcodes)");
6374 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6375 "Special Opcode Base");
6377 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6379 switch (opc)
6381 case DW_LNS_advance_pc:
6382 case DW_LNS_advance_line:
6383 case DW_LNS_set_file:
6384 case DW_LNS_set_column:
6385 case DW_LNS_fixed_advance_pc:
6386 n_op_args = 1;
6387 break;
6388 default:
6389 n_op_args = 0;
6390 break;
6393 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6394 opc, n_op_args);
6397 /* Write out the information about the files we use. */
6398 output_file_names ();
6399 ASM_OUTPUT_LABEL (asm_out_file, p2);
6401 /* We used to set the address register to the first location in the text
6402 section here, but that didn't accomplish anything since we already
6403 have a line note for the opening brace of the first function. */
6405 /* Generate the line number to PC correspondence table, encoded as
6406 a series of state machine operations. */
6407 current_file = 1;
6408 current_line = 1;
6409 strcpy (prev_line_label, text_section_label);
6410 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6412 register dw_line_info_ref line_info = &line_info_table[lt_index];
6414 #if 0
6415 /* Disable this optimization for now; GDB wants to see two line notes
6416 at the beginning of a function so it can find the end of the
6417 prologue. */
6419 /* Don't emit anything for redundant notes. Just updating the
6420 address doesn't accomplish anything, because we already assume
6421 that anything after the last address is this line. */
6422 if (line_info->dw_line_num == current_line
6423 && line_info->dw_file_num == current_file)
6424 continue;
6425 #endif
6427 /* Emit debug info for the address of the current line.
6429 Unfortunately, we have little choice here currently, and must always
6430 use the most general form. Gcc does not know the address delta
6431 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
6432 attributes which will give an upper bound on the address range. We
6433 could perhaps use length attributes to determine when it is safe to
6434 use DW_LNS_fixed_advance_pc. */
6436 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6437 if (0)
6439 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6440 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6441 "DW_LNS_fixed_advance_pc");
6442 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6444 else
6446 /* This can handle any delta. This takes
6447 4+DWARF2_ADDR_SIZE bytes. */
6448 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6449 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6450 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6451 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6453 strcpy (prev_line_label, line_label);
6455 /* Emit debug info for the source file of the current line, if
6456 different from the previous line. */
6457 if (line_info->dw_file_num != current_file)
6459 current_file = line_info->dw_file_num;
6460 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6461 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6462 file_table.table[current_file]);
6465 /* Emit debug info for the current line number, choosing the encoding
6466 that uses the least amount of space. */
6467 if (line_info->dw_line_num != current_line)
6469 line_offset = line_info->dw_line_num - current_line;
6470 line_delta = line_offset - DWARF_LINE_BASE;
6471 current_line = line_info->dw_line_num;
6472 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6474 /* This can handle deltas from -10 to 234, using the current
6475 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6476 takes 1 byte. */
6477 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6478 "line %lu", current_line);
6480 else
6482 /* This can handle any delta. This takes at least 4 bytes,
6483 depending on the value being encoded. */
6484 dw2_asm_output_data (1, DW_LNS_advance_line,
6485 "advance to line %lu", current_line);
6486 dw2_asm_output_data_sleb128 (line_offset, NULL);
6487 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6490 else
6492 /* We still need to start a new row, so output a copy insn. */
6493 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6497 /* Emit debug info for the address of the end of the function. */
6498 if (0)
6500 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6501 "DW_LNS_fixed_advance_pc");
6502 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
6504 else
6506 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6507 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6508 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6509 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
6512 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6513 dw2_asm_output_data_uleb128 (1, NULL);
6514 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6516 function = 0;
6517 current_file = 1;
6518 current_line = 1;
6519 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6521 register dw_separate_line_info_ref line_info
6522 = &separate_line_info_table[lt_index];
6524 #if 0
6525 /* Don't emit anything for redundant notes. */
6526 if (line_info->dw_line_num == current_line
6527 && line_info->dw_file_num == current_file
6528 && line_info->function == function)
6529 goto cont;
6530 #endif
6532 /* Emit debug info for the address of the current line. If this is
6533 a new function, or the first line of a function, then we need
6534 to handle it differently. */
6535 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6536 lt_index);
6537 if (function != line_info->function)
6539 function = line_info->function;
6541 /* Set the address register to the first line in the function */
6542 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6543 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6544 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6545 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6547 else
6549 /* ??? See the DW_LNS_advance_pc comment above. */
6550 if (0)
6552 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6553 "DW_LNS_fixed_advance_pc");
6554 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6556 else
6558 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6559 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6560 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6561 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6564 strcpy (prev_line_label, line_label);
6566 /* Emit debug info for the source file of the current line, if
6567 different from the previous line. */
6568 if (line_info->dw_file_num != current_file)
6570 current_file = line_info->dw_file_num;
6571 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6572 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6573 file_table.table[current_file]);
6576 /* Emit debug info for the current line number, choosing the encoding
6577 that uses the least amount of space. */
6578 if (line_info->dw_line_num != current_line)
6580 line_offset = line_info->dw_line_num - current_line;
6581 line_delta = line_offset - DWARF_LINE_BASE;
6582 current_line = line_info->dw_line_num;
6583 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6584 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6585 "line %lu", current_line);
6586 else
6588 dw2_asm_output_data (1, DW_LNS_advance_line,
6589 "advance to line %lu", current_line);
6590 dw2_asm_output_data_sleb128 (line_offset, NULL);
6591 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6594 else
6595 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6597 #if 0
6598 cont:
6599 #endif
6600 ++lt_index;
6602 /* If we're done with a function, end its sequence. */
6603 if (lt_index == separate_line_info_table_in_use
6604 || separate_line_info_table[lt_index].function != function)
6606 current_file = 1;
6607 current_line = 1;
6609 /* Emit debug info for the address of the end of the function. */
6610 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6611 if (0)
6613 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6614 "DW_LNS_fixed_advance_pc");
6615 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6617 else
6619 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6620 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6621 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6622 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6625 /* Output the marker for the end of this sequence. */
6626 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6627 dw2_asm_output_data_uleb128 (1, NULL);
6628 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6632 /* Output the marker for the end of the line number info. */
6633 ASM_OUTPUT_LABEL (asm_out_file, l2);
6636 /* Given a pointer to a tree node for some base type, return a pointer to
6637 a DIE that describes the given type.
6639 This routine must only be called for GCC type nodes that correspond to
6640 Dwarf base (fundamental) types. */
6642 static dw_die_ref
6643 base_type_die (type)
6644 register tree type;
6646 register dw_die_ref base_type_result;
6647 register const char *type_name;
6648 register enum dwarf_type encoding;
6649 register tree name = TYPE_NAME (type);
6651 if (TREE_CODE (type) == ERROR_MARK
6652 || TREE_CODE (type) == VOID_TYPE)
6653 return 0;
6655 if (name)
6657 if (TREE_CODE (name) == TYPE_DECL)
6658 name = DECL_NAME (name);
6660 type_name = IDENTIFIER_POINTER (name);
6662 else
6663 type_name = "__unknown__";
6665 switch (TREE_CODE (type))
6667 case INTEGER_TYPE:
6668 /* Carefully distinguish the C character types, without messing
6669 up if the language is not C. Note that we check only for the names
6670 that contain spaces; other names might occur by coincidence in other
6671 languages. */
6672 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6673 && (type == char_type_node
6674 || ! strcmp (type_name, "signed char")
6675 || ! strcmp (type_name, "unsigned char"))))
6677 if (TREE_UNSIGNED (type))
6678 encoding = DW_ATE_unsigned;
6679 else
6680 encoding = DW_ATE_signed;
6681 break;
6683 /* else fall through. */
6685 case CHAR_TYPE:
6686 /* GNU Pascal/Ada CHAR type. Not used in C. */
6687 if (TREE_UNSIGNED (type))
6688 encoding = DW_ATE_unsigned_char;
6689 else
6690 encoding = DW_ATE_signed_char;
6691 break;
6693 case REAL_TYPE:
6694 encoding = DW_ATE_float;
6695 break;
6697 /* Dwarf2 doesn't know anything about complex ints, so use
6698 a user defined type for it. */
6699 case COMPLEX_TYPE:
6700 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6701 encoding = DW_ATE_complex_float;
6702 else
6703 encoding = DW_ATE_lo_user;
6704 break;
6706 case BOOLEAN_TYPE:
6707 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6708 encoding = DW_ATE_boolean;
6709 break;
6711 default:
6712 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6715 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6716 if (demangle_name_func)
6717 type_name = (*demangle_name_func) (type_name);
6719 add_AT_string (base_type_result, DW_AT_name, type_name);
6720 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6721 int_size_in_bytes (type));
6722 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6724 return base_type_result;
6727 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6728 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6729 a given type is generally the same as the given type, except that if the
6730 given type is a pointer or reference type, then the root type of the given
6731 type is the root type of the "basis" type for the pointer or reference
6732 type. (This definition of the "root" type is recursive.) Also, the root
6733 type of a `const' qualified type or a `volatile' qualified type is the
6734 root type of the given type without the qualifiers. */
6736 static tree
6737 root_type (type)
6738 register tree type;
6740 if (TREE_CODE (type) == ERROR_MARK)
6741 return error_mark_node;
6743 switch (TREE_CODE (type))
6745 case ERROR_MARK:
6746 return error_mark_node;
6748 case POINTER_TYPE:
6749 case REFERENCE_TYPE:
6750 return type_main_variant (root_type (TREE_TYPE (type)));
6752 default:
6753 return type_main_variant (type);
6757 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6758 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6760 static inline int
6761 is_base_type (type)
6762 register tree type;
6764 switch (TREE_CODE (type))
6766 case ERROR_MARK:
6767 case VOID_TYPE:
6768 case INTEGER_TYPE:
6769 case REAL_TYPE:
6770 case COMPLEX_TYPE:
6771 case BOOLEAN_TYPE:
6772 case CHAR_TYPE:
6773 return 1;
6775 case SET_TYPE:
6776 case ARRAY_TYPE:
6777 case RECORD_TYPE:
6778 case UNION_TYPE:
6779 case QUAL_UNION_TYPE:
6780 case ENUMERAL_TYPE:
6781 case FUNCTION_TYPE:
6782 case METHOD_TYPE:
6783 case POINTER_TYPE:
6784 case REFERENCE_TYPE:
6785 case FILE_TYPE:
6786 case OFFSET_TYPE:
6787 case LANG_TYPE:
6788 case VECTOR_TYPE:
6789 return 0;
6791 default:
6792 abort ();
6795 return 0;
6798 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6799 entry that chains various modifiers in front of the given type. */
6801 static dw_die_ref
6802 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6803 register tree type;
6804 register int is_const_type;
6805 register int is_volatile_type;
6806 register dw_die_ref context_die;
6808 register enum tree_code code = TREE_CODE (type);
6809 register dw_die_ref mod_type_die = NULL;
6810 register dw_die_ref sub_die = NULL;
6811 register tree item_type = NULL;
6813 if (code != ERROR_MARK)
6815 type = build_type_variant (type, is_const_type, is_volatile_type);
6817 mod_type_die = lookup_type_die (type);
6818 if (mod_type_die)
6819 return mod_type_die;
6821 /* Handle C typedef types. */
6822 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6823 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6825 tree dtype = TREE_TYPE (TYPE_NAME (type));
6826 if (type == dtype)
6828 /* For a named type, use the typedef. */
6829 gen_type_die (type, context_die);
6830 mod_type_die = lookup_type_die (type);
6833 else if (is_const_type < TYPE_READONLY (dtype)
6834 || is_volatile_type < TYPE_VOLATILE (dtype))
6835 /* cv-unqualified version of named type. Just use the unnamed
6836 type to which it refers. */
6837 mod_type_die
6838 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6839 is_const_type, is_volatile_type,
6840 context_die);
6841 /* Else cv-qualified version of named type; fall through. */
6844 if (mod_type_die)
6845 /* OK. */
6847 else if (is_const_type)
6849 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6850 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6852 else if (is_volatile_type)
6854 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6855 sub_die = modified_type_die (type, 0, 0, context_die);
6857 else if (code == POINTER_TYPE)
6859 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6860 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6861 #if 0
6862 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6863 #endif
6864 item_type = TREE_TYPE (type);
6866 else if (code == REFERENCE_TYPE)
6868 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6869 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6870 #if 0
6871 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6872 #endif
6873 item_type = TREE_TYPE (type);
6875 else if (is_base_type (type))
6876 mod_type_die = base_type_die (type);
6877 else
6879 gen_type_die (type, context_die);
6881 /* We have to get the type_main_variant here (and pass that to the
6882 `lookup_type_die' routine) because the ..._TYPE node we have
6883 might simply be a *copy* of some original type node (where the
6884 copy was created to help us keep track of typedef names) and
6885 that copy might have a different TYPE_UID from the original
6886 ..._TYPE node. */
6887 mod_type_die = lookup_type_die (type_main_variant (type));
6888 if (mod_type_die == NULL)
6889 abort ();
6893 equate_type_number_to_die (type, mod_type_die);
6894 if (item_type)
6895 /* We must do this after the equate_type_number_to_die call, in case
6896 this is a recursive type. This ensures that the modified_type_die
6897 recursion will terminate even if the type is recursive. Recursive
6898 types are possible in Ada. */
6899 sub_die = modified_type_die (item_type,
6900 TYPE_READONLY (item_type),
6901 TYPE_VOLATILE (item_type),
6902 context_die);
6904 if (sub_die != NULL)
6905 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6907 return mod_type_die;
6910 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6911 an enumerated type. */
6913 static inline int
6914 type_is_enum (type)
6915 register tree type;
6917 return TREE_CODE (type) == ENUMERAL_TYPE;
6920 /* Return the register number described by a given RTL node. */
6922 static unsigned int
6923 reg_number (rtl)
6924 register rtx rtl;
6926 register unsigned regno = REGNO (rtl);
6928 if (regno >= FIRST_PSEUDO_REGISTER)
6930 warning ("internal regno botch: regno = %d\n", regno);
6931 regno = 0;
6934 regno = DBX_REGISTER_NUMBER (regno);
6935 return regno;
6938 /* Return a location descriptor that designates a machine register. */
6940 static dw_loc_descr_ref
6941 reg_loc_descriptor (rtl)
6942 register rtx rtl;
6944 register dw_loc_descr_ref loc_result = NULL;
6945 register unsigned reg = reg_number (rtl);
6947 if (reg <= 31)
6948 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6949 else
6950 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6952 return loc_result;
6955 /* Return a location descriptor that designates a constant. */
6957 static dw_loc_descr_ref
6958 int_loc_descriptor (i)
6959 HOST_WIDE_INT i;
6961 enum dwarf_location_atom op;
6963 /* Pick the smallest representation of a constant, rather than just
6964 defaulting to the LEB encoding. */
6965 if (i >= 0)
6967 if (i <= 31)
6968 op = DW_OP_lit0 + i;
6969 else if (i <= 0xff)
6970 op = DW_OP_const1u;
6971 else if (i <= 0xffff)
6972 op = DW_OP_const2u;
6973 else if (HOST_BITS_PER_WIDE_INT == 32
6974 || i <= 0xffffffff)
6975 op = DW_OP_const4u;
6976 else
6977 op = DW_OP_constu;
6979 else
6981 if (i >= -0x80)
6982 op = DW_OP_const1s;
6983 else if (i >= -0x8000)
6984 op = DW_OP_const2s;
6985 else if (HOST_BITS_PER_WIDE_INT == 32
6986 || i >= -0x80000000)
6987 op = DW_OP_const4s;
6988 else
6989 op = DW_OP_consts;
6992 return new_loc_descr (op, i, 0);
6995 /* Return a location descriptor that designates a base+offset location. */
6997 static dw_loc_descr_ref
6998 based_loc_descr (reg, offset)
6999 unsigned reg;
7000 long int offset;
7002 register dw_loc_descr_ref loc_result;
7003 /* For the "frame base", we use the frame pointer or stack pointer
7004 registers, since the RTL for local variables is relative to one of
7005 them. */
7006 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7007 ? HARD_FRAME_POINTER_REGNUM
7008 : STACK_POINTER_REGNUM);
7010 if (reg == fp_reg)
7011 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7012 else if (reg <= 31)
7013 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7014 else
7015 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7017 return loc_result;
7020 /* Return true if this RTL expression describes a base+offset calculation. */
7022 static inline int
7023 is_based_loc (rtl)
7024 register rtx rtl;
7026 return (GET_CODE (rtl) == PLUS
7027 && ((GET_CODE (XEXP (rtl, 0)) == REG
7028 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7031 /* The following routine converts the RTL for a variable or parameter
7032 (resident in memory) into an equivalent Dwarf representation of a
7033 mechanism for getting the address of that same variable onto the top of a
7034 hypothetical "address evaluation" stack.
7036 When creating memory location descriptors, we are effectively transforming
7037 the RTL for a memory-resident object into its Dwarf postfix expression
7038 equivalent. This routine recursively descends an RTL tree, turning
7039 it into Dwarf postfix code as it goes.
7041 MODE is the mode of the memory reference, needed to handle some
7042 autoincrement addressing modes. */
7044 static dw_loc_descr_ref
7045 mem_loc_descriptor (rtl, mode)
7046 register rtx rtl;
7047 enum machine_mode mode;
7049 dw_loc_descr_ref mem_loc_result = NULL;
7050 /* Note that for a dynamically sized array, the location we will generate a
7051 description of here will be the lowest numbered location which is
7052 actually within the array. That's *not* necessarily the same as the
7053 zeroth element of the array. */
7055 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7056 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7057 #endif
7059 switch (GET_CODE (rtl))
7061 case POST_INC:
7062 case POST_DEC:
7063 case POST_MODIFY:
7064 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7065 just fall into the SUBREG code. */
7067 /* Fall through. */
7069 case SUBREG:
7070 /* The case of a subreg may arise when we have a local (register)
7071 variable or a formal (register) parameter which doesn't quite fill
7072 up an entire register. For now, just assume that it is
7073 legitimate to make the Dwarf info refer to the whole register which
7074 contains the given subreg. */
7075 rtl = SUBREG_REG (rtl);
7077 /* Fall through. */
7079 case REG:
7080 /* Whenever a register number forms a part of the description of the
7081 method for calculating the (dynamic) address of a memory resident
7082 object, DWARF rules require the register number be referred to as
7083 a "base register". This distinction is not based in any way upon
7084 what category of register the hardware believes the given register
7085 belongs to. This is strictly DWARF terminology we're dealing with
7086 here. Note that in cases where the location of a memory-resident
7087 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7088 OP_CONST (0)) the actual DWARF location descriptor that we generate
7089 may just be OP_BASEREG (basereg). This may look deceptively like
7090 the object in question was allocated to a register (rather than in
7091 memory) so DWARF consumers need to be aware of the subtle
7092 distinction between OP_REG and OP_BASEREG. */
7093 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7094 break;
7096 case MEM:
7097 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7098 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7099 break;
7101 case LABEL_REF:
7102 /* Some ports can transform a symbol ref into a label ref, because
7103 the symbol ref is too far away and has to be dumped into a constant
7104 pool. */
7105 case CONST:
7106 case SYMBOL_REF:
7107 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7108 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7109 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7110 break;
7112 case PRE_MODIFY:
7113 /* Extract the PLUS expression nested inside and fall into
7114 PLUS code bellow. */
7115 rtl = XEXP (rtl, 1);
7116 goto plus;
7118 case PRE_INC:
7119 case PRE_DEC:
7120 /* Turn these into a PLUS expression and fall into the PLUS code
7121 below. */
7122 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7123 GEN_INT (GET_CODE (rtl) == PRE_INC
7124 ? GET_MODE_UNIT_SIZE (mode)
7125 : -GET_MODE_UNIT_SIZE (mode)));
7127 /* Fall through. */
7129 case PLUS:
7130 plus:
7131 if (is_based_loc (rtl))
7132 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7133 INTVAL (XEXP (rtl, 1)));
7134 else
7136 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7138 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7139 && INTVAL (XEXP (rtl, 1)) >= 0)
7141 add_loc_descr (&mem_loc_result,
7142 new_loc_descr (DW_OP_plus_uconst,
7143 INTVAL (XEXP (rtl, 1)), 0));
7145 else
7147 add_loc_descr (&mem_loc_result,
7148 mem_loc_descriptor (XEXP (rtl, 1), mode));
7149 add_loc_descr (&mem_loc_result,
7150 new_loc_descr (DW_OP_plus, 0, 0));
7153 break;
7155 case MULT:
7156 /* If a pseudo-reg is optimized away, it is possible for it to
7157 be replaced with a MEM containing a multiply. */
7158 add_loc_descr (&mem_loc_result,
7159 mem_loc_descriptor (XEXP (rtl, 0), mode));
7160 add_loc_descr (&mem_loc_result,
7161 mem_loc_descriptor (XEXP (rtl, 1), mode));
7162 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7163 break;
7165 case CONST_INT:
7166 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7167 break;
7169 default:
7170 abort ();
7173 return mem_loc_result;
7176 /* Return a descriptor that describes the concatenation of two locations.
7177 This is typically a complex variable. */
7179 static dw_loc_descr_ref
7180 concat_loc_descriptor (x0, x1)
7181 register rtx x0, x1;
7183 dw_loc_descr_ref cc_loc_result = NULL;
7185 if (!is_pseudo_reg (x0)
7186 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7187 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7188 add_loc_descr (&cc_loc_result,
7189 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7191 if (!is_pseudo_reg (x1)
7192 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7193 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7194 add_loc_descr (&cc_loc_result,
7195 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7197 return cc_loc_result;
7200 /* Output a proper Dwarf location descriptor for a variable or parameter
7201 which is either allocated in a register or in a memory location. For a
7202 register, we just generate an OP_REG and the register number. For a
7203 memory location we provide a Dwarf postfix expression describing how to
7204 generate the (dynamic) address of the object onto the address stack. */
7206 static dw_loc_descr_ref
7207 loc_descriptor (rtl)
7208 register rtx rtl;
7210 dw_loc_descr_ref loc_result = NULL;
7211 switch (GET_CODE (rtl))
7213 case SUBREG:
7214 /* The case of a subreg may arise when we have a local (register)
7215 variable or a formal (register) parameter which doesn't quite fill
7216 up an entire register. For now, just assume that it is
7217 legitimate to make the Dwarf info refer to the whole register which
7218 contains the given subreg. */
7219 rtl = SUBREG_REG (rtl);
7221 /* Fall through. */
7223 case REG:
7224 loc_result = reg_loc_descriptor (rtl);
7225 break;
7227 case MEM:
7228 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7229 break;
7231 case CONCAT:
7232 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7233 break;
7235 default:
7236 abort ();
7239 return loc_result;
7242 /* Similar, but generate the descriptor from trees instead of rtl.
7243 This comes up particularly with variable length arrays. */
7245 static dw_loc_descr_ref
7246 loc_descriptor_from_tree (loc, addressp)
7247 tree loc;
7248 int addressp;
7250 dw_loc_descr_ref ret = NULL;
7251 int indirect_size = 0;
7252 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7253 enum dwarf_location_atom op;
7255 /* ??? Most of the time we do not take proper care for sign/zero
7256 extending the values properly. Hopefully this won't be a real
7257 problem... */
7259 switch (TREE_CODE (loc))
7261 case ERROR_MARK:
7262 break;
7264 case WITH_RECORD_EXPR:
7265 /* This case involves extracting fields from an object to determine the
7266 position of other fields. We don't try to encode this here. The
7267 only user of this is Ada, which encodes the needed information using
7268 the names of types. */
7269 return ret;
7271 case VAR_DECL:
7272 case PARM_DECL:
7274 rtx rtl = rtl_for_decl_location (loc);
7275 enum machine_mode mode = DECL_MODE (loc);
7277 if (rtl == NULL_RTX)
7278 break;
7279 else if (CONSTANT_P (rtl))
7281 ret = new_loc_descr (DW_OP_addr, 0, 0);
7282 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7283 ret->dw_loc_oprnd1.v.val_addr = rtl;
7284 indirect_size = GET_MODE_SIZE (mode);
7286 else
7288 if (GET_CODE (rtl) == MEM)
7290 indirect_size = GET_MODE_SIZE (mode);
7291 rtl = XEXP (rtl, 0);
7293 ret = mem_loc_descriptor (rtl, mode);
7296 break;
7298 case INDIRECT_REF:
7299 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7300 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7301 break;
7303 case NOP_EXPR:
7304 case CONVERT_EXPR:
7305 case NON_LVALUE_EXPR:
7306 case SAVE_EXPR:
7307 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7309 case COMPONENT_REF:
7310 case BIT_FIELD_REF:
7311 case ARRAY_REF:
7313 tree obj, offset;
7314 HOST_WIDE_INT bitsize, bitpos, bytepos;
7315 enum machine_mode mode;
7316 int volatilep;
7317 unsigned int alignment;
7319 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7320 &unsignedp, &volatilep, &alignment);
7321 ret = loc_descriptor_from_tree (obj, 1);
7323 if (offset != NULL_TREE)
7325 /* Variable offset. */
7326 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7327 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7330 if (addressp)
7332 /* We cannot address anything not on a unit boundary. */
7333 if (bitpos % BITS_PER_UNIT != 0)
7334 abort ();
7336 else
7338 if (bitpos % BITS_PER_UNIT != 0
7339 || bitsize % BITS_PER_UNIT != 0)
7341 /* ??? We could handle this by loading and shifting etc.
7342 Wait until someone needs it before expending the effort. */
7343 abort ();
7346 indirect_size = bitsize / BITS_PER_UNIT;
7349 bytepos = bitpos / BITS_PER_UNIT;
7350 if (bytepos > 0)
7351 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7352 else if (bytepos < 0)
7354 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7355 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7357 break;
7360 case INTEGER_CST:
7361 if (host_integerp (loc, 0))
7362 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7363 break;
7365 case BIT_AND_EXPR:
7366 op = DW_OP_and;
7367 goto do_binop;
7368 case BIT_XOR_EXPR:
7369 op = DW_OP_xor;
7370 goto do_binop;
7371 case BIT_IOR_EXPR:
7372 op = DW_OP_or;
7373 goto do_binop;
7374 case TRUNC_DIV_EXPR:
7375 op = DW_OP_div;
7376 goto do_binop;
7377 case MINUS_EXPR:
7378 op = DW_OP_minus;
7379 goto do_binop;
7380 case TRUNC_MOD_EXPR:
7381 op = DW_OP_mod;
7382 goto do_binop;
7383 case MULT_EXPR:
7384 op = DW_OP_mul;
7385 goto do_binop;
7386 case LSHIFT_EXPR:
7387 op = DW_OP_shl;
7388 goto do_binop;
7389 case RSHIFT_EXPR:
7390 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7391 goto do_binop;
7392 case PLUS_EXPR:
7393 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7394 && host_integerp (TREE_OPERAND (loc, 1), 0))
7396 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7397 add_loc_descr (&ret,
7398 new_loc_descr (DW_OP_plus_uconst,
7399 tree_low_cst (TREE_OPERAND (loc, 1),
7401 0));
7402 break;
7404 op = DW_OP_plus;
7405 goto do_binop;
7406 case LE_EXPR:
7407 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7408 break;
7409 op = DW_OP_le;
7410 goto do_binop;
7411 case GE_EXPR:
7412 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7413 break;
7414 op = DW_OP_ge;
7415 goto do_binop;
7416 case LT_EXPR:
7417 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7418 break;
7419 op = DW_OP_lt;
7420 goto do_binop;
7421 case GT_EXPR:
7422 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7423 break;
7424 op = DW_OP_gt;
7425 goto do_binop;
7426 case EQ_EXPR:
7427 op = DW_OP_eq;
7428 goto do_binop;
7429 case NE_EXPR:
7430 op = DW_OP_ne;
7431 goto do_binop;
7433 do_binop:
7434 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7435 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7436 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7437 break;
7439 case BIT_NOT_EXPR:
7440 op = DW_OP_not;
7441 goto do_unop;
7442 case ABS_EXPR:
7443 op = DW_OP_abs;
7444 goto do_unop;
7445 case NEGATE_EXPR:
7446 op = DW_OP_neg;
7447 goto do_unop;
7449 do_unop:
7450 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7451 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7452 break;
7454 case MAX_EXPR:
7455 loc = build (COND_EXPR, TREE_TYPE (loc),
7456 build (LT_EXPR, integer_type_node,
7457 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
7458 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
7459 /* FALLTHRU */
7461 case COND_EXPR:
7463 dw_loc_descr_ref bra_node, jump_node, tmp;
7465 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7466 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
7467 add_loc_descr (&ret, bra_node);
7469 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
7470 add_loc_descr (&ret, tmp);
7471 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
7472 add_loc_descr (&ret, jump_node);
7474 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
7475 add_loc_descr (&ret, tmp);
7476 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7477 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
7479 /* ??? Need a node to point the skip at. Use a nop. */
7480 tmp = new_loc_descr (DW_OP_nop, 0, 0);
7481 add_loc_descr (&ret, tmp);
7482 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7483 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
7485 break;
7487 default:
7488 abort ();
7491 /* If we can't fill the request for an address, die. */
7492 if (addressp && indirect_size == 0)
7493 abort ();
7495 /* If we've got an address and don't want one, dereference. */
7496 if (!addressp && indirect_size > 0)
7498 if (indirect_size > DWARF2_ADDR_SIZE)
7499 abort ();
7500 if (indirect_size == DWARF2_ADDR_SIZE)
7501 op = DW_OP_deref;
7502 else
7503 op = DW_OP_deref_size;
7504 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
7507 return ret;
7510 /* Given a value, round it up to the lowest multiple of `boundary'
7511 which is not less than the value itself. */
7513 static inline HOST_WIDE_INT
7514 ceiling (value, boundary)
7515 HOST_WIDE_INT value;
7516 unsigned int boundary;
7518 return (((value + boundary - 1) / boundary) * boundary);
7521 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7522 pointer to the declared type for the relevant field variable, or return
7523 `integer_type_node' if the given node turns out to be an
7524 ERROR_MARK node. */
7526 static inline tree
7527 field_type (decl)
7528 register tree decl;
7530 register tree type;
7532 if (TREE_CODE (decl) == ERROR_MARK)
7533 return integer_type_node;
7535 type = DECL_BIT_FIELD_TYPE (decl);
7536 if (type == NULL_TREE)
7537 type = TREE_TYPE (decl);
7539 return type;
7542 /* Given a pointer to a tree node, return the alignment in bits for
7543 it, or else return BITS_PER_WORD if the node actually turns out to
7544 be an ERROR_MARK node. */
7546 static inline unsigned
7547 simple_type_align_in_bits (type)
7548 register tree type;
7550 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7553 static inline unsigned
7554 simple_decl_align_in_bits (decl)
7555 register tree decl;
7557 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
7560 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7561 node, return the size in bits for the type if it is a constant, or else
7562 return the alignment for the type if the type's size is not constant, or
7563 else return BITS_PER_WORD if the type actually turns out to be an
7564 ERROR_MARK node. */
7566 static inline unsigned HOST_WIDE_INT
7567 simple_type_size_in_bits (type)
7568 register tree type;
7570 tree type_size_tree;
7572 if (TREE_CODE (type) == ERROR_MARK)
7573 return BITS_PER_WORD;
7574 type_size_tree = TYPE_SIZE (type);
7576 if (type_size_tree == NULL_TREE)
7577 return 0;
7578 if (! host_integerp (type_size_tree, 1))
7579 return TYPE_ALIGN (type);
7580 return tree_low_cst (type_size_tree, 1);
7583 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7584 return the byte offset of the lowest addressed byte of the "containing
7585 object" for the given FIELD_DECL, or return 0 if we are unable to
7586 determine what that offset is, either because the argument turns out to
7587 be a pointer to an ERROR_MARK node, or because the offset is actually
7588 variable. (We can't handle the latter case just yet). */
7590 static HOST_WIDE_INT
7591 field_byte_offset (decl)
7592 register tree decl;
7594 unsigned int type_align_in_bits;
7595 unsigned int decl_align_in_bits;
7596 unsigned HOST_WIDE_INT type_size_in_bits;
7597 HOST_WIDE_INT object_offset_in_bits;
7598 HOST_WIDE_INT object_offset_in_bytes;
7599 tree type;
7600 tree field_size_tree;
7601 HOST_WIDE_INT bitpos_int;
7602 HOST_WIDE_INT deepest_bitpos;
7603 unsigned HOST_WIDE_INT field_size_in_bits;
7605 if (TREE_CODE (decl) == ERROR_MARK)
7606 return 0;
7608 if (TREE_CODE (decl) != FIELD_DECL)
7609 abort ();
7611 type = field_type (decl);
7612 field_size_tree = DECL_SIZE (decl);
7614 /* The size could be unspecified if there was an error, or for
7615 a flexible array member. */
7616 if (! field_size_tree)
7617 field_size_tree = bitsize_zero_node;
7619 /* We cannot yet cope with fields whose positions are variable, so
7620 for now, when we see such things, we simply return 0. Someday, we may
7621 be able to handle such cases, but it will be damn difficult. */
7622 if (! host_integerp (bit_position (decl), 0))
7623 return 0;
7625 bitpos_int = int_bit_position (decl);
7627 /* If we don't know the size of the field, pretend it's a full word. */
7628 if (host_integerp (field_size_tree, 1))
7629 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7630 else
7631 field_size_in_bits = BITS_PER_WORD;
7633 type_size_in_bits = simple_type_size_in_bits (type);
7634 type_align_in_bits = simple_type_align_in_bits (type);
7635 decl_align_in_bits = simple_decl_align_in_bits (decl);
7637 /* Note that the GCC front-end doesn't make any attempt to keep track of
7638 the starting bit offset (relative to the start of the containing
7639 structure type) of the hypothetical "containing object" for a bit-
7640 field. Thus, when computing the byte offset value for the start of the
7641 "containing object" of a bit-field, we must deduce this information on
7642 our own. This can be rather tricky to do in some cases. For example,
7643 handling the following structure type definition when compiling for an
7644 i386/i486 target (which only aligns long long's to 32-bit boundaries)
7645 can be very tricky:
7647 struct S { int field1; long long field2:31; };
7649 Fortunately, there is a simple rule-of-thumb which can be
7650 used in such cases. When compiling for an i386/i486, GCC will allocate
7651 8 bytes for the structure shown above. It decides to do this based upon
7652 one simple rule for bit-field allocation. Quite simply, GCC allocates
7653 each "containing object" for each bit-field at the first (i.e. lowest
7654 addressed) legitimate alignment boundary (based upon the required
7655 minimum alignment for the declared type of the field) which it can
7656 possibly use, subject to the condition that there is still enough
7657 available space remaining in the containing object (when allocated at
7658 the selected point) to fully accommodate all of the bits of the
7659 bit-field itself. This simple rule makes it obvious why GCC allocates
7660 8 bytes for each object of the structure type shown above. When looking
7661 for a place to allocate the "containing object" for `field2', the
7662 compiler simply tries to allocate a 64-bit "containing object" at each
7663 successive 32-bit boundary (starting at zero) until it finds a place to
7664 allocate that 64- bit field such that at least 31 contiguous (and
7665 previously unallocated) bits remain within that selected 64 bit field.
7666 (As it turns out, for the example above, the compiler finds that it is
7667 OK to allocate the "containing object" 64-bit field at bit-offset zero
7668 within the structure type.) Here we attempt to work backwards from the
7669 limited set of facts we're given, and we try to deduce from those facts,
7670 where GCC must have believed that the containing object started (within
7671 the structure type). The value we deduce is then used (by the callers of
7672 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
7673 for fields (both bit-fields and, in the case of DW_AT_location, regular
7674 fields as well). */
7676 /* Figure out the bit-distance from the start of the structure to the
7677 "deepest" bit of the bit-field. */
7678 deepest_bitpos = bitpos_int + field_size_in_bits;
7680 /* This is the tricky part. Use some fancy footwork to deduce where the
7681 lowest addressed bit of the containing object must be. */
7682 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
7684 /* Round up to type_align by default. This works best for bitfields. */
7685 object_offset_in_bits += type_align_in_bits - 1;
7686 object_offset_in_bits /= type_align_in_bits;
7687 object_offset_in_bits *= type_align_in_bits;
7689 if (object_offset_in_bits > bitpos_int)
7691 /* Sigh, the decl must be packed. */
7692 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
7694 /* Round up to decl_align instead. */
7695 object_offset_in_bits += decl_align_in_bits - 1;
7696 object_offset_in_bits /= decl_align_in_bits;
7697 object_offset_in_bits *= decl_align_in_bits;
7700 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
7702 return object_offset_in_bytes;
7705 /* The following routines define various Dwarf attributes and any data
7706 associated with them. */
7708 /* Add a location description attribute value to a DIE.
7710 This emits location attributes suitable for whole variables and
7711 whole parameters. Note that the location attributes for struct fields are
7712 generated by the routine `data_member_location_attribute' below. */
7714 static void
7715 add_AT_location_description (die, attr_kind, rtl)
7716 dw_die_ref die;
7717 enum dwarf_attribute attr_kind;
7718 register rtx rtl;
7720 /* Handle a special case. If we are about to output a location descriptor
7721 for a variable or parameter which has been optimized out of existence,
7722 don't do that. A variable which has been optimized out
7723 of existence will have a DECL_RTL value which denotes a pseudo-reg.
7724 Currently, in some rare cases, variables can have DECL_RTL values which
7725 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
7726 elsewhere in the compiler. We treat such cases as if the variable(s) in
7727 question had been optimized out of existence. */
7729 if (is_pseudo_reg (rtl)
7730 || (GET_CODE (rtl) == MEM
7731 && is_pseudo_reg (XEXP (rtl, 0)))
7732 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
7733 references the internal argument pointer (a pseudo) in a function
7734 where all references to the internal argument pointer were
7735 eliminated via the optimizers. */
7736 || (GET_CODE (rtl) == MEM
7737 && GET_CODE (XEXP (rtl, 0)) == PLUS
7738 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
7739 || (GET_CODE (rtl) == CONCAT
7740 && is_pseudo_reg (XEXP (rtl, 0))
7741 && is_pseudo_reg (XEXP (rtl, 1))))
7742 return;
7744 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
7747 /* Attach the specialized form of location attribute used for data
7748 members of struct and union types. In the special case of a
7749 FIELD_DECL node which represents a bit-field, the "offset" part
7750 of this special location descriptor must indicate the distance
7751 in bytes from the lowest-addressed byte of the containing struct
7752 or union type to the lowest-addressed byte of the "containing
7753 object" for the bit-field. (See the `field_byte_offset' function
7754 above).. For any given bit-field, the "containing object" is a
7755 hypothetical object (of some integral or enum type) within which
7756 the given bit-field lives. The type of this hypothetical
7757 "containing object" is always the same as the declared type of
7758 the individual bit-field itself (for GCC anyway... the DWARF
7759 spec doesn't actually mandate this). Note that it is the size
7760 (in bytes) of the hypothetical "containing object" which will
7761 be given in the DW_AT_byte_size attribute for this bit-field.
7762 (See the `byte_size_attribute' function below.) It is also used
7763 when calculating the value of the DW_AT_bit_offset attribute.
7764 (See the `bit_offset_attribute' function below). */
7766 static void
7767 add_data_member_location_attribute (die, decl)
7768 register dw_die_ref die;
7769 register tree decl;
7771 register unsigned long offset;
7772 register dw_loc_descr_ref loc_descr;
7773 register enum dwarf_location_atom op;
7775 if (TREE_CODE (decl) == TREE_VEC)
7776 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
7777 else
7778 offset = field_byte_offset (decl);
7780 /* The DWARF2 standard says that we should assume that the structure address
7781 is already on the stack, so we can specify a structure field address
7782 by using DW_OP_plus_uconst. */
7784 #ifdef MIPS_DEBUGGING_INFO
7785 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
7786 correctly. It works only if we leave the offset on the stack. */
7787 op = DW_OP_constu;
7788 #else
7789 op = DW_OP_plus_uconst;
7790 #endif
7792 loc_descr = new_loc_descr (op, offset, 0);
7793 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
7796 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
7797 does not have a "location" either in memory or in a register. These
7798 things can arise in GNU C when a constant is passed as an actual parameter
7799 to an inlined function. They can also arise in C++ where declared
7800 constants do not necessarily get memory "homes". */
7802 static void
7803 add_const_value_attribute (die, rtl)
7804 register dw_die_ref die;
7805 register rtx rtl;
7807 switch (GET_CODE (rtl))
7809 case CONST_INT:
7810 /* Note that a CONST_INT rtx could represent either an integer
7811 or a floating-point constant. A CONST_INT is used whenever
7812 the constant will fit into a single word. In all such
7813 cases, the original mode of the constant value is wiped
7814 out, and the CONST_INT rtx is assigned VOIDmode. */
7816 HOST_WIDE_INT val = INTVAL (rtl);
7818 /* ??? We really should be using HOST_WIDE_INT throughout. */
7819 if (val < 0)
7821 if ((long) val != val)
7822 abort ();
7823 add_AT_int (die, DW_AT_const_value, (long) val);
7825 else
7827 if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
7828 abort ();
7829 add_AT_int (die, DW_AT_const_value, (unsigned long) val);
7832 break;
7834 case CONST_DOUBLE:
7835 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
7836 floating-point constant. A CONST_DOUBLE is used whenever the
7837 constant requires more than one word in order to be adequately
7838 represented. We output CONST_DOUBLEs as blocks. */
7840 register enum machine_mode mode = GET_MODE (rtl);
7842 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
7844 register unsigned length = GET_MODE_SIZE (mode) / 4;
7845 long *array = (long *) xmalloc (sizeof (long) * length);
7846 REAL_VALUE_TYPE rv;
7848 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
7849 switch (mode)
7851 case SFmode:
7852 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
7853 break;
7855 case DFmode:
7856 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
7857 break;
7859 case XFmode:
7860 case TFmode:
7861 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
7862 break;
7864 default:
7865 abort ();
7868 add_AT_float (die, DW_AT_const_value, length, array);
7870 else
7872 /* ??? We really should be using HOST_WIDE_INT throughout. */
7873 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
7874 abort ();
7875 add_AT_long_long (die, DW_AT_const_value,
7876 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
7879 break;
7881 case CONST_STRING:
7882 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
7883 break;
7885 case SYMBOL_REF:
7886 case LABEL_REF:
7887 case CONST:
7888 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
7889 break;
7891 case PLUS:
7892 /* In cases where an inlined instance of an inline function is passed
7893 the address of an `auto' variable (which is local to the caller) we
7894 can get a situation where the DECL_RTL of the artificial local
7895 variable (for the inlining) which acts as a stand-in for the
7896 corresponding formal parameter (of the inline function) will look
7897 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
7898 exactly a compile-time constant expression, but it isn't the address
7899 of the (artificial) local variable either. Rather, it represents the
7900 *value* which the artificial local variable always has during its
7901 lifetime. We currently have no way to represent such quasi-constant
7902 values in Dwarf, so for now we just punt and generate nothing. */
7903 break;
7905 default:
7906 /* No other kinds of rtx should be possible here. */
7907 abort ();
7912 static rtx
7913 rtl_for_decl_location (decl)
7914 tree decl;
7916 register rtx rtl;
7918 /* Here we have to decide where we are going to say the parameter "lives"
7919 (as far as the debugger is concerned). We only have a couple of
7920 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
7922 DECL_RTL normally indicates where the parameter lives during most of the
7923 activation of the function. If optimization is enabled however, this
7924 could be either NULL or else a pseudo-reg. Both of those cases indicate
7925 that the parameter doesn't really live anywhere (as far as the code
7926 generation parts of GCC are concerned) during most of the function's
7927 activation. That will happen (for example) if the parameter is never
7928 referenced within the function.
7930 We could just generate a location descriptor here for all non-NULL
7931 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
7932 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
7933 where DECL_RTL is NULL or is a pseudo-reg.
7935 Note however that we can only get away with using DECL_INCOMING_RTL as
7936 a backup substitute for DECL_RTL in certain limited cases. In cases
7937 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
7938 we can be sure that the parameter was passed using the same type as it is
7939 declared to have within the function, and that its DECL_INCOMING_RTL
7940 points us to a place where a value of that type is passed.
7942 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
7943 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
7944 because in these cases DECL_INCOMING_RTL points us to a value of some
7945 type which is *different* from the type of the parameter itself. Thus,
7946 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
7947 such cases, the debugger would end up (for example) trying to fetch a
7948 `float' from a place which actually contains the first part of a
7949 `double'. That would lead to really incorrect and confusing
7950 output at debug-time.
7952 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
7953 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
7954 are a couple of exceptions however. On little-endian machines we can
7955 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
7956 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
7957 an integral type that is smaller than TREE_TYPE (decl). These cases arise
7958 when (on a little-endian machine) a non-prototyped function has a
7959 parameter declared to be of type `short' or `char'. In such cases,
7960 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
7961 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
7962 passed `int' value. If the debugger then uses that address to fetch
7963 a `short' or a `char' (on a little-endian machine) the result will be
7964 the correct data, so we allow for such exceptional cases below.
7966 Note that our goal here is to describe the place where the given formal
7967 parameter lives during most of the function's activation (i.e. between
7968 the end of the prologue and the start of the epilogue). We'll do that
7969 as best as we can. Note however that if the given formal parameter is
7970 modified sometime during the execution of the function, then a stack
7971 backtrace (at debug-time) will show the function as having been
7972 called with the *new* value rather than the value which was
7973 originally passed in. This happens rarely enough that it is not
7974 a major problem, but it *is* a problem, and I'd like to fix it.
7976 A future version of dwarf2out.c may generate two additional
7977 attributes for any given DW_TAG_formal_parameter DIE which will
7978 describe the "passed type" and the "passed location" for the
7979 given formal parameter in addition to the attributes we now
7980 generate to indicate the "declared type" and the "active
7981 location" for each parameter. This additional set of attributes
7982 could be used by debuggers for stack backtraces. Separately, note
7983 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
7984 NULL also. This happens (for example) for inlined-instances of
7985 inline function formal parameters which are never referenced.
7986 This really shouldn't be happening. All PARM_DECL nodes should
7987 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
7988 doesn't currently generate these values for inlined instances of
7989 inline function parameters, so when we see such cases, we are
7990 just out-of-luck for the time being (until integrate.c
7991 gets fixed). */
7993 /* Use DECL_RTL as the "location" unless we find something better. */
7994 rtl = DECL_RTL_IF_SET (decl);
7996 if (TREE_CODE (decl) == PARM_DECL)
7998 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8000 tree declared_type = type_main_variant (TREE_TYPE (decl));
8001 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8003 /* This decl represents a formal parameter which was optimized out.
8004 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8005 all* cases where (rtl == NULL_RTX) just below. */
8006 if (declared_type == passed_type)
8007 rtl = DECL_INCOMING_RTL (decl);
8008 else if (! BYTES_BIG_ENDIAN
8009 && TREE_CODE (declared_type) == INTEGER_TYPE
8010 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8011 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8012 rtl = DECL_INCOMING_RTL (decl);
8015 /* If the parm was passed in registers, but lives on the stack, then
8016 make a big endian correction if the mode of the type of the
8017 parameter is not the same as the mode of the rtl. */
8018 /* ??? This is the same series of checks that are made in dbxout.c before
8019 we reach the big endian correction code there. It isn't clear if all
8020 of these checks are necessary here, but keeping them all is the safe
8021 thing to do. */
8022 else if (GET_CODE (rtl) == MEM
8023 && XEXP (rtl, 0) != const0_rtx
8024 && ! CONSTANT_P (XEXP (rtl, 0))
8025 /* Not passed in memory. */
8026 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8027 /* Not passed by invisible reference. */
8028 && (GET_CODE (XEXP (rtl, 0)) != REG
8029 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8030 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8031 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8032 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8033 #endif
8035 /* Big endian correction check. */
8036 && BYTES_BIG_ENDIAN
8037 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8038 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8039 < UNITS_PER_WORD))
8041 int offset = (UNITS_PER_WORD
8042 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8043 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8044 plus_constant (XEXP (rtl, 0), offset));
8048 if (rtl != NULL_RTX)
8050 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8051 #ifdef LEAF_REG_REMAP
8052 if (current_function_uses_only_leaf_regs)
8053 leaf_renumber_regs_insn (rtl);
8054 #endif
8057 return rtl;
8060 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8061 data attribute for a variable or a parameter. We generate the
8062 DW_AT_const_value attribute only in those cases where the given variable
8063 or parameter does not have a true "location" either in memory or in a
8064 register. This can happen (for example) when a constant is passed as an
8065 actual argument in a call to an inline function. (It's possible that
8066 these things can crop up in other ways also.) Note that one type of
8067 constant value which can be passed into an inlined function is a constant
8068 pointer. This can happen for example if an actual argument in an inlined
8069 function call evaluates to a compile-time constant address. */
8071 static void
8072 add_location_or_const_value_attribute (die, decl)
8073 register dw_die_ref die;
8074 register tree decl;
8076 register rtx rtl;
8078 if (TREE_CODE (decl) == ERROR_MARK)
8079 return;
8081 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8082 abort ();
8084 rtl = rtl_for_decl_location (decl);
8085 if (rtl == NULL_RTX)
8086 return;
8088 switch (GET_CODE (rtl))
8090 case ADDRESSOF:
8091 /* The address of a variable that was optimized away; don't emit
8092 anything. */
8093 break;
8095 case CONST_INT:
8096 case CONST_DOUBLE:
8097 case CONST_STRING:
8098 case SYMBOL_REF:
8099 case LABEL_REF:
8100 case CONST:
8101 case PLUS:
8102 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8103 add_const_value_attribute (die, rtl);
8104 break;
8106 case MEM:
8107 case REG:
8108 case SUBREG:
8109 case CONCAT:
8110 add_AT_location_description (die, DW_AT_location, rtl);
8111 break;
8113 default:
8114 abort ();
8118 /* If we don't have a copy of this variable in memory for some reason (such
8119 as a C++ member constant that doesn't have an out-of-line definition),
8120 we should tell the debugger about the constant value. */
8122 static void
8123 tree_add_const_value_attribute (var_die, decl)
8124 dw_die_ref var_die;
8125 tree decl;
8127 tree init = DECL_INITIAL (decl);
8128 tree type = TREE_TYPE (decl);
8130 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8131 && initializer_constant_valid_p (init, type) == null_pointer_node)
8132 /* OK */;
8133 else
8134 return;
8136 switch (TREE_CODE (type))
8138 case INTEGER_TYPE:
8139 if (host_integerp (init, 0))
8140 add_AT_unsigned (var_die, DW_AT_const_value,
8141 TREE_INT_CST_LOW (init));
8142 else
8143 add_AT_long_long (var_die, DW_AT_const_value,
8144 TREE_INT_CST_HIGH (init),
8145 TREE_INT_CST_LOW (init));
8146 break;
8148 default:;
8152 /* Generate an DW_AT_name attribute given some string value to be included as
8153 the value of the attribute. */
8155 static inline void
8156 add_name_attribute (die, name_string)
8157 register dw_die_ref die;
8158 register const char *name_string;
8160 if (name_string != NULL && *name_string != 0)
8162 if (demangle_name_func)
8163 name_string = (*demangle_name_func) (name_string);
8165 add_AT_string (die, DW_AT_name, name_string);
8169 /* Given a tree node describing an array bound (either lower or upper) output
8170 a representation for that bound. */
8172 static void
8173 add_bound_info (subrange_die, bound_attr, bound)
8174 register dw_die_ref subrange_die;
8175 register enum dwarf_attribute bound_attr;
8176 register tree bound;
8178 /* If this is an Ada unconstrained array type, then don't emit any debug
8179 info because the array bounds are unknown. They are parameterized when
8180 the type is instantiated. */
8181 if (contains_placeholder_p (bound))
8182 return;
8184 switch (TREE_CODE (bound))
8186 case ERROR_MARK:
8187 return;
8189 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8190 case INTEGER_CST:
8191 if (! host_integerp (bound, 0)
8192 || (bound_attr == DW_AT_lower_bound
8193 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8194 || (is_fortran () && integer_onep (bound)))))
8195 /* use the default */
8197 else
8198 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8199 break;
8201 case CONVERT_EXPR:
8202 case NOP_EXPR:
8203 case NON_LVALUE_EXPR:
8204 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8205 break;
8207 case SAVE_EXPR:
8208 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8209 access the upper bound values may be bogus. If they refer to a
8210 register, they may only describe how to get at these values at the
8211 points in the generated code right after they have just been
8212 computed. Worse yet, in the typical case, the upper bound values
8213 will not even *be* computed in the optimized code (though the
8214 number of elements will), so these SAVE_EXPRs are entirely
8215 bogus. In order to compensate for this fact, we check here to see
8216 if optimization is enabled, and if so, we don't add an attribute
8217 for the (unknown and unknowable) upper bound. This should not
8218 cause too much trouble for existing (stupid?) debuggers because
8219 they have to deal with empty upper bounds location descriptions
8220 anyway in order to be able to deal with incomplete array types.
8221 Of course an intelligent debugger (GDB?) should be able to
8222 comprehend that a missing upper bound specification in a array
8223 type used for a storage class `auto' local array variable
8224 indicates that the upper bound is both unknown (at compile- time)
8225 and unknowable (at run-time) due to optimization.
8227 We assume that a MEM rtx is safe because gcc wouldn't put the
8228 value there unless it was going to be used repeatedly in the
8229 function, i.e. for cleanups. */
8230 if (SAVE_EXPR_RTL (bound)
8231 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8233 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8234 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8235 register rtx loc = SAVE_EXPR_RTL (bound);
8237 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8238 it references an outer function's frame. */
8240 if (GET_CODE (loc) == MEM)
8242 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8244 if (XEXP (loc, 0) != new_addr)
8245 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8248 add_AT_flag (decl_die, DW_AT_artificial, 1);
8249 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8250 add_AT_location_description (decl_die, DW_AT_location, loc);
8251 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8254 /* Else leave out the attribute. */
8255 break;
8257 case VAR_DECL:
8258 case PARM_DECL:
8260 dw_die_ref decl_die = lookup_decl_die (bound);
8262 /* ??? Can this happen, or should the variable have been bound
8263 first? Probably it can, since I imagine that we try to create
8264 the types of parameters in the order in which they exist in
8265 the list, and won't have created a forward reference to a
8266 later parameter. */
8267 if (decl_die != NULL)
8268 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8269 break;
8272 default:
8274 /* Otherwise try to create a stack operation procedure to
8275 evaluate the value of the array bound. */
8277 dw_die_ref ctx, decl_die;
8278 dw_loc_descr_ref loc;
8280 loc = loc_descriptor_from_tree (bound, 0);
8281 if (loc == NULL)
8282 break;
8284 ctx = lookup_decl_die (current_function_decl);
8286 decl_die = new_die (DW_TAG_variable, ctx);
8287 add_AT_flag (decl_die, DW_AT_artificial, 1);
8288 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8289 add_AT_loc (decl_die, DW_AT_location, loc);
8291 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8292 break;
8297 /* Note that the block of subscript information for an array type also
8298 includes information about the element type of type given array type. */
8300 static void
8301 add_subscript_info (type_die, type)
8302 register dw_die_ref type_die;
8303 register tree type;
8305 #ifndef MIPS_DEBUGGING_INFO
8306 register unsigned dimension_number;
8307 #endif
8308 register tree lower, upper;
8309 register dw_die_ref subrange_die;
8311 /* The GNU compilers represent multidimensional array types as sequences of
8312 one dimensional array types whose element types are themselves array
8313 types. Here we squish that down, so that each multidimensional array
8314 type gets only one array_type DIE in the Dwarf debugging info. The draft
8315 Dwarf specification say that we are allowed to do this kind of
8316 compression in C (because there is no difference between an array or
8317 arrays and a multidimensional array in C) but for other source languages
8318 (e.g. Ada) we probably shouldn't do this. */
8320 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8321 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8322 We work around this by disabling this feature. See also
8323 gen_array_type_die. */
8324 #ifndef MIPS_DEBUGGING_INFO
8325 for (dimension_number = 0;
8326 TREE_CODE (type) == ARRAY_TYPE;
8327 type = TREE_TYPE (type), dimension_number++)
8329 #endif
8330 register tree domain = TYPE_DOMAIN (type);
8332 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8333 and (in GNU C only) variable bounds. Handle all three forms
8334 here. */
8335 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8336 if (domain)
8338 /* We have an array type with specified bounds. */
8339 lower = TYPE_MIN_VALUE (domain);
8340 upper = TYPE_MAX_VALUE (domain);
8342 /* define the index type. */
8343 if (TREE_TYPE (domain))
8345 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8346 TREE_TYPE field. We can't emit debug info for this
8347 because it is an unnamed integral type. */
8348 if (TREE_CODE (domain) == INTEGER_TYPE
8349 && TYPE_NAME (domain) == NULL_TREE
8350 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8351 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8353 else
8354 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8355 type_die);
8358 /* ??? If upper is NULL, the array has unspecified length,
8359 but it does have a lower bound. This happens with Fortran
8360 dimension arr(N:*)
8361 Since the debugger is definitely going to need to know N
8362 to produce useful results, go ahead and output the lower
8363 bound solo, and hope the debugger can cope. */
8365 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8366 if (upper)
8367 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8369 else
8370 /* We have an array type with an unspecified length. The DWARF-2
8371 spec does not say how to handle this; let's just leave out the
8372 bounds. */
8375 #ifndef MIPS_DEBUGGING_INFO
8377 #endif
8380 static void
8381 add_byte_size_attribute (die, tree_node)
8382 dw_die_ref die;
8383 register tree tree_node;
8385 register unsigned size;
8387 switch (TREE_CODE (tree_node))
8389 case ERROR_MARK:
8390 size = 0;
8391 break;
8392 case ENUMERAL_TYPE:
8393 case RECORD_TYPE:
8394 case UNION_TYPE:
8395 case QUAL_UNION_TYPE:
8396 size = int_size_in_bytes (tree_node);
8397 break;
8398 case FIELD_DECL:
8399 /* For a data member of a struct or union, the DW_AT_byte_size is
8400 generally given as the number of bytes normally allocated for an
8401 object of the *declared* type of the member itself. This is true
8402 even for bit-fields. */
8403 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8404 break;
8405 default:
8406 abort ();
8409 /* Note that `size' might be -1 when we get to this point. If it is, that
8410 indicates that the byte size of the entity in question is variable. We
8411 have no good way of expressing this fact in Dwarf at the present time,
8412 so just let the -1 pass on through. */
8414 add_AT_unsigned (die, DW_AT_byte_size, size);
8417 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8418 which specifies the distance in bits from the highest order bit of the
8419 "containing object" for the bit-field to the highest order bit of the
8420 bit-field itself.
8422 For any given bit-field, the "containing object" is a hypothetical
8423 object (of some integral or enum type) within which the given bit-field
8424 lives. The type of this hypothetical "containing object" is always the
8425 same as the declared type of the individual bit-field itself. The
8426 determination of the exact location of the "containing object" for a
8427 bit-field is rather complicated. It's handled by the
8428 `field_byte_offset' function (above).
8430 Note that it is the size (in bytes) of the hypothetical "containing object"
8431 which will be given in the DW_AT_byte_size attribute for this bit-field.
8432 (See `byte_size_attribute' above). */
8434 static inline void
8435 add_bit_offset_attribute (die, decl)
8436 register dw_die_ref die;
8437 register tree decl;
8439 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8440 tree type = DECL_BIT_FIELD_TYPE (decl);
8441 HOST_WIDE_INT bitpos_int;
8442 HOST_WIDE_INT highest_order_object_bit_offset;
8443 HOST_WIDE_INT highest_order_field_bit_offset;
8444 HOST_WIDE_INT unsigned bit_offset;
8446 /* Must be a field and a bit field. */
8447 if (!type
8448 || TREE_CODE (decl) != FIELD_DECL)
8449 abort ();
8451 /* We can't yet handle bit-fields whose offsets are variable, so if we
8452 encounter such things, just return without generating any attribute
8453 whatsoever. Likewise for variable or too large size. */
8454 if (! host_integerp (bit_position (decl), 0)
8455 || ! host_integerp (DECL_SIZE (decl), 1))
8456 return;
8458 bitpos_int = int_bit_position (decl);
8460 /* Note that the bit offset is always the distance (in bits) from the
8461 highest-order bit of the "containing object" to the highest-order bit of
8462 the bit-field itself. Since the "high-order end" of any object or field
8463 is different on big-endian and little-endian machines, the computation
8464 below must take account of these differences. */
8465 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8466 highest_order_field_bit_offset = bitpos_int;
8468 if (! BYTES_BIG_ENDIAN)
8470 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8471 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8474 bit_offset
8475 = (! BYTES_BIG_ENDIAN
8476 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8477 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8479 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8482 /* For a FIELD_DECL node which represents a bit field, output an attribute
8483 which specifies the length in bits of the given field. */
8485 static inline void
8486 add_bit_size_attribute (die, decl)
8487 register dw_die_ref die;
8488 register tree decl;
8490 /* Must be a field and a bit field. */
8491 if (TREE_CODE (decl) != FIELD_DECL
8492 || ! DECL_BIT_FIELD_TYPE (decl))
8493 abort ();
8495 if (host_integerp (DECL_SIZE (decl), 1))
8496 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8499 /* If the compiled language is ANSI C, then add a 'prototyped'
8500 attribute, if arg types are given for the parameters of a function. */
8502 static inline void
8503 add_prototyped_attribute (die, func_type)
8504 register dw_die_ref die;
8505 register tree func_type;
8507 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8508 && TYPE_ARG_TYPES (func_type) != NULL)
8509 add_AT_flag (die, DW_AT_prototyped, 1);
8512 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8513 by looking in either the type declaration or object declaration
8514 equate table. */
8516 static inline void
8517 add_abstract_origin_attribute (die, origin)
8518 register dw_die_ref die;
8519 register tree origin;
8521 dw_die_ref origin_die = NULL;
8523 if (TREE_CODE (origin) != FUNCTION_DECL)
8525 /* We may have gotten separated from the block for the inlined
8526 function, if we're in an exception handler or some such; make
8527 sure that the abstract function has been written out.
8529 Doing this for nested functions is wrong, however; functions are
8530 distinct units, and our context might not even be inline. */
8531 tree fn = origin;
8532 if (TYPE_P (fn))
8533 fn = TYPE_STUB_DECL (fn);
8534 fn = decl_function_context (fn);
8535 if (fn)
8536 dwarf2out_abstract_function (fn);
8539 if (DECL_P (origin))
8540 origin_die = lookup_decl_die (origin);
8541 else if (TYPE_P (origin))
8542 origin_die = lookup_type_die (origin);
8544 if (origin_die == NULL)
8545 abort ();
8547 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8550 /* We do not currently support the pure_virtual attribute. */
8552 static inline void
8553 add_pure_or_virtual_attribute (die, func_decl)
8554 register dw_die_ref die;
8555 register tree func_decl;
8557 if (DECL_VINDEX (func_decl))
8559 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8561 if (host_integerp (DECL_VINDEX (func_decl), 0))
8562 add_AT_loc (die, DW_AT_vtable_elem_location,
8563 new_loc_descr (DW_OP_constu,
8564 tree_low_cst (DECL_VINDEX (func_decl), 0),
8565 0));
8567 /* GNU extension: Record what type this method came from originally. */
8568 if (debug_info_level > DINFO_LEVEL_TERSE)
8569 add_AT_die_ref (die, DW_AT_containing_type,
8570 lookup_type_die (DECL_CONTEXT (func_decl)));
8574 /* Add source coordinate attributes for the given decl. */
8576 static void
8577 add_src_coords_attributes (die, decl)
8578 register dw_die_ref die;
8579 register tree decl;
8581 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
8583 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8584 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8587 /* Add an DW_AT_name attribute and source coordinate attribute for the
8588 given decl, but only if it actually has a name. */
8590 static void
8591 add_name_and_src_coords_attributes (die, decl)
8592 register dw_die_ref die;
8593 register tree decl;
8595 register tree decl_name;
8597 decl_name = DECL_NAME (decl);
8598 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8600 add_name_attribute (die, dwarf2_name (decl, 0));
8601 if (! DECL_ARTIFICIAL (decl))
8602 add_src_coords_attributes (die, decl);
8604 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8605 && TREE_PUBLIC (decl)
8606 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
8607 && !DECL_ABSTRACT (decl))
8608 add_AT_string (die, DW_AT_MIPS_linkage_name,
8609 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8613 /* Push a new declaration scope. */
8615 static void
8616 push_decl_scope (scope)
8617 tree scope;
8619 /* Make room in the decl_scope_table, if necessary. */
8620 if (decl_scope_table_allocated == decl_scope_depth)
8622 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
8623 decl_scope_table
8624 = (tree *) xrealloc (decl_scope_table,
8625 decl_scope_table_allocated * sizeof (tree));
8628 decl_scope_table[decl_scope_depth] = scope;
8629 decl_scope_depth++;
8632 /* Pop a declaration scope. */
8633 static inline void
8634 pop_decl_scope ()
8636 if (decl_scope_depth <= 0)
8637 abort ();
8638 --decl_scope_depth;
8641 /* Return the DIE for the scope that immediately contains this type.
8642 Non-named types get global scope. Named types nested in other
8643 types get their containing scope if it's open, or global scope
8644 otherwise. All other types (i.e. function-local named types) get
8645 the current active scope. */
8647 static dw_die_ref
8648 scope_die_for (t, context_die)
8649 register tree t;
8650 register dw_die_ref context_die;
8652 register dw_die_ref scope_die = NULL;
8653 register tree containing_scope;
8654 register int i;
8656 /* Non-types always go in the current scope. */
8657 if (! TYPE_P (t))
8658 abort ();
8660 containing_scope = TYPE_CONTEXT (t);
8662 /* Ignore namespaces for the moment. */
8663 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
8664 containing_scope = NULL_TREE;
8666 /* Ignore function type "scopes" from the C frontend. They mean that
8667 a tagged type is local to a parmlist of a function declarator, but
8668 that isn't useful to DWARF. */
8669 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
8670 containing_scope = NULL_TREE;
8672 if (containing_scope == NULL_TREE)
8673 scope_die = comp_unit_die;
8674 else if (TYPE_P (containing_scope))
8676 /* For types, we can just look up the appropriate DIE. But
8677 first we check to see if we're in the middle of emitting it
8678 so we know where the new DIE should go. */
8680 for (i = decl_scope_depth - 1; i >= 0; --i)
8681 if (decl_scope_table[i] == containing_scope)
8682 break;
8684 if (i < 0)
8686 if (debug_info_level > DINFO_LEVEL_TERSE
8687 && !TREE_ASM_WRITTEN (containing_scope))
8688 abort ();
8690 /* If none of the current dies are suitable, we get file scope. */
8691 scope_die = comp_unit_die;
8693 else
8694 scope_die = lookup_type_die (containing_scope);
8696 else
8697 scope_die = context_die;
8699 return scope_die;
8702 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
8704 static inline int local_scope_p PARAMS ((dw_die_ref));
8705 static inline int
8706 local_scope_p (context_die)
8707 dw_die_ref context_die;
8709 for (; context_die; context_die = context_die->die_parent)
8710 if (context_die->die_tag == DW_TAG_inlined_subroutine
8711 || context_die->die_tag == DW_TAG_subprogram)
8712 return 1;
8713 return 0;
8716 /* Returns nonzero iff CONTEXT_DIE is a class. */
8718 static inline int class_scope_p PARAMS ((dw_die_ref));
8719 static inline int
8720 class_scope_p (context_die)
8721 dw_die_ref context_die;
8723 return (context_die
8724 && (context_die->die_tag == DW_TAG_structure_type
8725 || context_die->die_tag == DW_TAG_union_type));
8728 /* Many forms of DIEs require a "type description" attribute. This
8729 routine locates the proper "type descriptor" die for the type given
8730 by 'type', and adds an DW_AT_type attribute below the given die. */
8732 static void
8733 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
8734 register dw_die_ref object_die;
8735 register tree type;
8736 register int decl_const;
8737 register int decl_volatile;
8738 register dw_die_ref context_die;
8740 register enum tree_code code = TREE_CODE (type);
8741 register dw_die_ref type_die = NULL;
8743 /* ??? If this type is an unnamed subrange type of an integral or
8744 floating-point type, use the inner type. This is because we have no
8745 support for unnamed types in base_type_die. This can happen if this is
8746 an Ada subrange type. Correct solution is emit a subrange type die. */
8747 if ((code == INTEGER_TYPE || code == REAL_TYPE)
8748 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
8749 type = TREE_TYPE (type), code = TREE_CODE (type);
8751 if (code == ERROR_MARK)
8752 return;
8754 /* Handle a special case. For functions whose return type is void, we
8755 generate *no* type attribute. (Note that no object may have type
8756 `void', so this only applies to function return types). */
8757 if (code == VOID_TYPE)
8758 return;
8760 type_die = modified_type_die (type,
8761 decl_const || TYPE_READONLY (type),
8762 decl_volatile || TYPE_VOLATILE (type),
8763 context_die);
8764 if (type_die != NULL)
8765 add_AT_die_ref (object_die, DW_AT_type, type_die);
8768 /* Given a tree pointer to a struct, class, union, or enum type node, return
8769 a pointer to the (string) tag name for the given type, or zero if the type
8770 was declared without a tag. */
8772 static const char *
8773 type_tag (type)
8774 register tree type;
8776 register const char *name = 0;
8778 if (TYPE_NAME (type) != 0)
8780 register tree t = 0;
8782 /* Find the IDENTIFIER_NODE for the type name. */
8783 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
8784 t = TYPE_NAME (type);
8786 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
8787 a TYPE_DECL node, regardless of whether or not a `typedef' was
8788 involved. */
8789 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8790 && ! DECL_IGNORED_P (TYPE_NAME (type)))
8791 t = DECL_NAME (TYPE_NAME (type));
8793 /* Now get the name as a string, or invent one. */
8794 if (t != 0)
8795 name = IDENTIFIER_POINTER (t);
8798 return (name == 0 || *name == '\0') ? 0 : name;
8801 /* Return the type associated with a data member, make a special check
8802 for bit field types. */
8804 static inline tree
8805 member_declared_type (member)
8806 register tree member;
8808 return (DECL_BIT_FIELD_TYPE (member)
8809 ? DECL_BIT_FIELD_TYPE (member)
8810 : TREE_TYPE (member));
8813 /* Get the decl's label, as described by its RTL. This may be different
8814 from the DECL_NAME name used in the source file. */
8816 #if 0
8817 static const char *
8818 decl_start_label (decl)
8819 register tree decl;
8821 rtx x;
8822 const char *fnname;
8823 x = DECL_RTL (decl);
8824 if (GET_CODE (x) != MEM)
8825 abort ();
8827 x = XEXP (x, 0);
8828 if (GET_CODE (x) != SYMBOL_REF)
8829 abort ();
8831 fnname = XSTR (x, 0);
8832 return fnname;
8834 #endif
8836 /* These routines generate the internal representation of the DIE's for
8837 the compilation unit. Debugging information is collected by walking
8838 the declaration trees passed in from dwarf2out_decl(). */
8840 static void
8841 gen_array_type_die (type, context_die)
8842 register tree type;
8843 register dw_die_ref context_die;
8845 register dw_die_ref scope_die = scope_die_for (type, context_die);
8846 register dw_die_ref array_die;
8847 register tree element_type;
8849 /* ??? The SGI dwarf reader fails for array of array of enum types unless
8850 the inner array type comes before the outer array type. Thus we must
8851 call gen_type_die before we call new_die. See below also. */
8852 #ifdef MIPS_DEBUGGING_INFO
8853 gen_type_die (TREE_TYPE (type), context_die);
8854 #endif
8856 array_die = new_die (DW_TAG_array_type, scope_die);
8858 #if 0
8859 /* We default the array ordering. SDB will probably do
8860 the right things even if DW_AT_ordering is not present. It's not even
8861 an issue until we start to get into multidimensional arrays anyway. If
8862 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
8863 then we'll have to put the DW_AT_ordering attribute back in. (But if
8864 and when we find out that we need to put these in, we will only do so
8865 for multidimensional arrays. */
8866 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
8867 #endif
8869 #ifdef MIPS_DEBUGGING_INFO
8870 /* The SGI compilers handle arrays of unknown bound by setting
8871 AT_declaration and not emitting any subrange DIEs. */
8872 if (! TYPE_DOMAIN (type))
8873 add_AT_unsigned (array_die, DW_AT_declaration, 1);
8874 else
8875 #endif
8876 add_subscript_info (array_die, type);
8878 add_name_attribute (array_die, type_tag (type));
8879 equate_type_number_to_die (type, array_die);
8881 /* Add representation of the type of the elements of this array type. */
8882 element_type = TREE_TYPE (type);
8884 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8885 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8886 We work around this by disabling this feature. See also
8887 add_subscript_info. */
8888 #ifndef MIPS_DEBUGGING_INFO
8889 while (TREE_CODE (element_type) == ARRAY_TYPE)
8890 element_type = TREE_TYPE (element_type);
8892 gen_type_die (element_type, context_die);
8893 #endif
8895 add_type_attribute (array_die, element_type, 0, 0, context_die);
8898 static void
8899 gen_set_type_die (type, context_die)
8900 register tree type;
8901 register dw_die_ref context_die;
8903 register dw_die_ref type_die
8904 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
8906 equate_type_number_to_die (type, type_die);
8907 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
8910 #if 0
8911 static void
8912 gen_entry_point_die (decl, context_die)
8913 register tree decl;
8914 register dw_die_ref context_die;
8916 register tree origin = decl_ultimate_origin (decl);
8917 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
8918 if (origin != NULL)
8919 add_abstract_origin_attribute (decl_die, origin);
8920 else
8922 add_name_and_src_coords_attributes (decl_die, decl);
8923 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
8924 0, 0, context_die);
8927 if (DECL_ABSTRACT (decl))
8928 equate_decl_number_to_die (decl, decl_die);
8929 else
8930 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
8932 #endif
8934 /* Remember a type in the incomplete_types_list. */
8936 static void
8937 add_incomplete_type (type)
8938 tree type;
8940 if (incomplete_types == incomplete_types_allocated)
8942 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
8943 incomplete_types_list
8944 = (tree *) xrealloc (incomplete_types_list,
8945 sizeof (tree) * incomplete_types_allocated);
8948 incomplete_types_list[incomplete_types++] = type;
8951 /* Walk through the list of incomplete types again, trying once more to
8952 emit full debugging info for them. */
8954 static void
8955 retry_incomplete_types ()
8957 register tree type;
8959 while (incomplete_types)
8961 --incomplete_types;
8962 type = incomplete_types_list[incomplete_types];
8963 gen_type_die (type, comp_unit_die);
8967 /* Generate a DIE to represent an inlined instance of an enumeration type. */
8969 static void
8970 gen_inlined_enumeration_type_die (type, context_die)
8971 register tree type;
8972 register dw_die_ref context_die;
8974 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
8975 context_die);
8976 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8977 be incomplete and such types are not marked. */
8978 add_abstract_origin_attribute (type_die, type);
8981 /* Generate a DIE to represent an inlined instance of a structure type. */
8983 static void
8984 gen_inlined_structure_type_die (type, context_die)
8985 register tree type;
8986 register dw_die_ref context_die;
8988 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
8990 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8991 be incomplete and such types are not marked. */
8992 add_abstract_origin_attribute (type_die, type);
8995 /* Generate a DIE to represent an inlined instance of a union type. */
8997 static void
8998 gen_inlined_union_type_die (type, context_die)
8999 register tree type;
9000 register dw_die_ref context_die;
9002 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9004 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9005 be incomplete and such types are not marked. */
9006 add_abstract_origin_attribute (type_die, type);
9009 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9010 include all of the information about the enumeration values also. Each
9011 enumerated type name/value is listed as a child of the enumerated type
9012 DIE. */
9014 static void
9015 gen_enumeration_type_die (type, context_die)
9016 register tree type;
9017 register dw_die_ref context_die;
9019 register dw_die_ref type_die = lookup_type_die (type);
9021 if (type_die == NULL)
9023 type_die = new_die (DW_TAG_enumeration_type,
9024 scope_die_for (type, context_die));
9025 equate_type_number_to_die (type, type_die);
9026 add_name_attribute (type_die, type_tag (type));
9028 else if (! TYPE_SIZE (type))
9029 return;
9030 else
9031 remove_AT (type_die, DW_AT_declaration);
9033 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9034 given enum type is incomplete, do not generate the DW_AT_byte_size
9035 attribute or the DW_AT_element_list attribute. */
9036 if (TYPE_SIZE (type))
9038 register tree link;
9040 TREE_ASM_WRITTEN (type) = 1;
9041 add_byte_size_attribute (type_die, type);
9042 if (TYPE_STUB_DECL (type) != NULL_TREE)
9043 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9045 /* If the first reference to this type was as the return type of an
9046 inline function, then it may not have a parent. Fix this now. */
9047 if (type_die->die_parent == NULL)
9048 add_child_die (scope_die_for (type, context_die), type_die);
9050 for (link = TYPE_FIELDS (type);
9051 link != NULL; link = TREE_CHAIN (link))
9053 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9055 add_name_attribute (enum_die,
9056 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9058 if (host_integerp (TREE_VALUE (link), 0))
9060 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9061 add_AT_int (enum_die, DW_AT_const_value,
9062 tree_low_cst (TREE_VALUE (link), 0));
9063 else
9064 add_AT_unsigned (enum_die, DW_AT_const_value,
9065 tree_low_cst (TREE_VALUE (link), 0));
9069 else
9070 add_AT_flag (type_die, DW_AT_declaration, 1);
9073 /* Generate a DIE to represent either a real live formal parameter decl or to
9074 represent just the type of some formal parameter position in some function
9075 type.
9077 Note that this routine is a bit unusual because its argument may be a
9078 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9079 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9080 node. If it's the former then this function is being called to output a
9081 DIE to represent a formal parameter object (or some inlining thereof). If
9082 it's the latter, then this function is only being called to output a
9083 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9084 argument type of some subprogram type. */
9086 static dw_die_ref
9087 gen_formal_parameter_die (node, context_die)
9088 register tree node;
9089 register dw_die_ref context_die;
9091 register dw_die_ref parm_die
9092 = new_die (DW_TAG_formal_parameter, context_die);
9093 register tree origin;
9095 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9097 case 'd':
9098 origin = decl_ultimate_origin (node);
9099 if (origin != NULL)
9100 add_abstract_origin_attribute (parm_die, origin);
9101 else
9103 add_name_and_src_coords_attributes (parm_die, node);
9104 add_type_attribute (parm_die, TREE_TYPE (node),
9105 TREE_READONLY (node),
9106 TREE_THIS_VOLATILE (node),
9107 context_die);
9108 if (DECL_ARTIFICIAL (node))
9109 add_AT_flag (parm_die, DW_AT_artificial, 1);
9112 equate_decl_number_to_die (node, parm_die);
9113 if (! DECL_ABSTRACT (node))
9114 add_location_or_const_value_attribute (parm_die, node);
9116 break;
9118 case 't':
9119 /* We were called with some kind of a ..._TYPE node. */
9120 add_type_attribute (parm_die, node, 0, 0, context_die);
9121 break;
9123 default:
9124 abort ();
9127 return parm_die;
9130 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9131 at the end of an (ANSI prototyped) formal parameters list. */
9133 static void
9134 gen_unspecified_parameters_die (decl_or_type, context_die)
9135 register tree decl_or_type ATTRIBUTE_UNUSED;
9136 register dw_die_ref context_die;
9138 new_die (DW_TAG_unspecified_parameters, context_die);
9141 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9142 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9143 parameters as specified in some function type specification (except for
9144 those which appear as part of a function *definition*). */
9146 static void
9147 gen_formal_types_die (function_or_method_type, context_die)
9148 register tree function_or_method_type;
9149 register dw_die_ref context_die;
9151 register tree link;
9152 register tree formal_type = NULL;
9153 register tree first_parm_type;
9154 tree arg;
9156 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9158 arg = DECL_ARGUMENTS (function_or_method_type);
9159 function_or_method_type = TREE_TYPE (function_or_method_type);
9161 else
9162 arg = NULL_TREE;
9164 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9166 /* Make our first pass over the list of formal parameter types and output a
9167 DW_TAG_formal_parameter DIE for each one. */
9168 for (link = first_parm_type; link; )
9170 register dw_die_ref parm_die;
9172 formal_type = TREE_VALUE (link);
9173 if (formal_type == void_type_node)
9174 break;
9176 /* Output a (nameless) DIE to represent the formal parameter itself. */
9177 parm_die = gen_formal_parameter_die (formal_type, context_die);
9178 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9179 && link == first_parm_type)
9180 || (arg && DECL_ARTIFICIAL (arg)))
9181 add_AT_flag (parm_die, DW_AT_artificial, 1);
9183 link = TREE_CHAIN (link);
9184 if (arg)
9185 arg = TREE_CHAIN (arg);
9188 /* If this function type has an ellipsis, add a
9189 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9190 if (formal_type != void_type_node)
9191 gen_unspecified_parameters_die (function_or_method_type, context_die);
9193 /* Make our second (and final) pass over the list of formal parameter types
9194 and output DIEs to represent those types (as necessary). */
9195 for (link = TYPE_ARG_TYPES (function_or_method_type);
9196 link;
9197 link = TREE_CHAIN (link))
9199 formal_type = TREE_VALUE (link);
9200 if (formal_type == void_type_node)
9201 break;
9203 gen_type_die (formal_type, context_die);
9207 /* We want to generate the DIE for TYPE so that we can generate the
9208 die for MEMBER, which has been defined; we will need to refer back
9209 to the member declaration nested within TYPE. If we're trying to
9210 generate minimal debug info for TYPE, processing TYPE won't do the
9211 trick; we need to attach the member declaration by hand. */
9213 static void
9214 gen_type_die_for_member (type, member, context_die)
9215 tree type, member;
9216 dw_die_ref context_die;
9218 gen_type_die (type, context_die);
9220 /* If we're trying to avoid duplicate debug info, we may not have
9221 emitted the member decl for this function. Emit it now. */
9222 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9223 && ! lookup_decl_die (member))
9225 if (decl_ultimate_origin (member))
9226 abort ();
9228 push_decl_scope (type);
9229 if (TREE_CODE (member) == FUNCTION_DECL)
9230 gen_subprogram_die (member, lookup_type_die (type));
9231 else
9232 gen_variable_die (member, lookup_type_die (type));
9233 pop_decl_scope ();
9237 /* Generate the DWARF2 info for the "abstract" instance
9238 of a function which we may later generate inlined and/or
9239 out-of-line instances of. */
9241 void
9242 dwarf2out_abstract_function (decl)
9243 tree decl;
9245 register dw_die_ref old_die;
9246 tree save_fn;
9247 tree context;
9248 int was_abstract = DECL_ABSTRACT (decl);
9250 /* Make sure we have the actual abstract inline, not a clone. */
9251 decl = DECL_ORIGIN (decl);
9253 old_die = lookup_decl_die (decl);
9254 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9255 /* We've already generated the abstract instance. */
9256 return;
9258 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9259 we don't get confused by DECL_ABSTRACT. */
9260 context = decl_class_context (decl);
9261 if (context)
9262 gen_type_die_for_member
9263 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9265 /* Pretend we've just finished compiling this function. */
9266 save_fn = current_function_decl;
9267 current_function_decl = decl;
9269 set_decl_abstract_flags (decl, 1);
9270 dwarf2out_decl (decl);
9271 if (! was_abstract)
9272 set_decl_abstract_flags (decl, 0);
9274 current_function_decl = save_fn;
9277 /* Generate a DIE to represent a declared function (either file-scope or
9278 block-local). */
9280 static void
9281 gen_subprogram_die (decl, context_die)
9282 register tree decl;
9283 register dw_die_ref context_die;
9285 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9286 register tree origin = decl_ultimate_origin (decl);
9287 register dw_die_ref subr_die;
9288 register rtx fp_reg;
9289 register tree fn_arg_types;
9290 register tree outer_scope;
9291 register dw_die_ref old_die = lookup_decl_die (decl);
9292 register int declaration = (current_function_decl != decl
9293 || class_scope_p (context_die));
9295 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9296 be true, if we started to generate the abstract instance of an inline,
9297 decided to output its containing class, and proceeded to emit the
9298 declaration of the inline from the member list for the class. In that
9299 case, `declaration' takes priority; we'll get back to the abstract
9300 instance when we're done with the class. */
9302 /* The class-scope declaration DIE must be the primary DIE. */
9303 if (origin && declaration && class_scope_p (context_die))
9305 origin = NULL;
9306 if (old_die)
9307 abort ();
9310 if (origin != NULL)
9312 if (declaration && ! local_scope_p (context_die))
9313 abort ();
9315 /* Fixup die_parent for the abstract instance of a nested
9316 inline function. */
9317 if (old_die && old_die->die_parent == NULL)
9318 add_child_die (context_die, old_die);
9320 subr_die = new_die (DW_TAG_subprogram, context_die);
9321 add_abstract_origin_attribute (subr_die, origin);
9323 else if (old_die)
9325 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9327 if (!get_AT_flag (old_die, DW_AT_declaration)
9328 /* We can have a normal definition following an inline one in the
9329 case of redefinition of GNU C extern inlines.
9330 It seems reasonable to use AT_specification in this case. */
9331 && !get_AT_unsigned (old_die, DW_AT_inline))
9333 /* ??? This can happen if there is a bug in the program, for
9334 instance, if it has duplicate function definitions. Ideally,
9335 we should detect this case and ignore it. For now, if we have
9336 already reported an error, any error at all, then assume that
9337 we got here because of a input error, not a dwarf2 bug. */
9338 if (errorcount)
9339 return;
9340 abort ();
9343 /* If the definition comes from the same place as the declaration,
9344 maybe use the old DIE. We always want the DIE for this function
9345 that has the *_pc attributes to be under comp_unit_die so the
9346 debugger can find it. We also need to do this for abstract
9347 instances of inlines, since the spec requires the out-of-line copy
9348 to have the same parent. For local class methods, this doesn't
9349 apply; we just use the old DIE. */
9350 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9351 && (DECL_ARTIFICIAL (decl)
9352 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9353 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9354 == (unsigned) DECL_SOURCE_LINE (decl)))))
9356 subr_die = old_die;
9358 /* Clear out the declaration attribute and the parm types. */
9359 remove_AT (subr_die, DW_AT_declaration);
9360 remove_children (subr_die);
9362 else
9364 subr_die = new_die (DW_TAG_subprogram, context_die);
9365 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9366 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9367 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9368 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9369 != (unsigned) DECL_SOURCE_LINE (decl))
9370 add_AT_unsigned
9371 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9374 else
9376 subr_die = new_die (DW_TAG_subprogram, context_die);
9378 if (TREE_PUBLIC (decl))
9379 add_AT_flag (subr_die, DW_AT_external, 1);
9381 add_name_and_src_coords_attributes (subr_die, decl);
9382 if (debug_info_level > DINFO_LEVEL_TERSE)
9384 register tree type = TREE_TYPE (decl);
9386 add_prototyped_attribute (subr_die, type);
9387 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9390 add_pure_or_virtual_attribute (subr_die, decl);
9391 if (DECL_ARTIFICIAL (decl))
9392 add_AT_flag (subr_die, DW_AT_artificial, 1);
9393 if (TREE_PROTECTED (decl))
9394 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9395 else if (TREE_PRIVATE (decl))
9396 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9399 if (declaration)
9401 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9403 add_AT_flag (subr_die, DW_AT_declaration, 1);
9405 /* The first time we see a member function, it is in the context of
9406 the class to which it belongs. We make sure of this by emitting
9407 the class first. The next time is the definition, which is
9408 handled above. The two may come from the same source text. */
9409 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9410 equate_decl_number_to_die (decl, subr_die);
9413 else if (DECL_ABSTRACT (decl))
9415 if (DECL_INLINE (decl) && !flag_no_inline)
9417 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9418 inline functions, but not for extern inline functions.
9419 We can't get this completely correct because information
9420 about whether the function was declared inline is not
9421 saved anywhere. */
9422 if (DECL_DEFER_OUTPUT (decl))
9423 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9424 else
9425 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9427 else
9428 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9430 equate_decl_number_to_die (decl, subr_die);
9432 else if (!DECL_EXTERNAL (decl))
9434 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9435 equate_decl_number_to_die (decl, subr_die);
9437 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9438 current_funcdef_number);
9439 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9440 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9441 current_funcdef_number);
9442 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9444 add_pubname (decl, subr_die);
9445 add_arange (decl, subr_die);
9447 #ifdef MIPS_DEBUGGING_INFO
9448 /* Add a reference to the FDE for this routine. */
9449 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9450 #endif
9452 /* Define the "frame base" location for this routine. We use the
9453 frame pointer or stack pointer registers, since the RTL for local
9454 variables is relative to one of them. */
9455 fp_reg
9456 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9457 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9459 #if 0
9460 /* ??? This fails for nested inline functions, because context_display
9461 is not part of the state saved/restored for inline functions. */
9462 if (current_function_needs_context)
9463 add_AT_location_description (subr_die, DW_AT_static_link,
9464 lookup_static_chain (decl));
9465 #endif
9468 /* Now output descriptions of the arguments for this function. This gets
9469 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9470 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9471 `...' at the end of the formal parameter list. In order to find out if
9472 there was a trailing ellipsis or not, we must instead look at the type
9473 associated with the FUNCTION_DECL. This will be a node of type
9474 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9475 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9476 an ellipsis at the end. */
9478 /* In the case where we are describing a mere function declaration, all we
9479 need to do here (and all we *can* do here) is to describe the *types* of
9480 its formal parameters. */
9481 if (debug_info_level <= DINFO_LEVEL_TERSE)
9483 else if (declaration)
9484 gen_formal_types_die (decl, subr_die);
9485 else
9487 /* Generate DIEs to represent all known formal parameters */
9488 register tree arg_decls = DECL_ARGUMENTS (decl);
9489 register tree parm;
9491 /* When generating DIEs, generate the unspecified_parameters DIE
9492 instead if we come across the arg "__builtin_va_alist" */
9493 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9494 if (TREE_CODE (parm) == PARM_DECL)
9496 if (DECL_NAME (parm)
9497 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9498 "__builtin_va_alist"))
9499 gen_unspecified_parameters_die (parm, subr_die);
9500 else
9501 gen_decl_die (parm, subr_die);
9504 /* Decide whether we need a unspecified_parameters DIE at the end.
9505 There are 2 more cases to do this for: 1) the ansi ... declaration -
9506 this is detectable when the end of the arg list is not a
9507 void_type_node 2) an unprototyped function declaration (not a
9508 definition). This just means that we have no info about the
9509 parameters at all. */
9510 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9511 if (fn_arg_types != NULL)
9513 /* this is the prototyped case, check for ... */
9514 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9515 gen_unspecified_parameters_die (decl, subr_die);
9517 else if (DECL_INITIAL (decl) == NULL_TREE)
9518 gen_unspecified_parameters_die (decl, subr_die);
9521 /* Output Dwarf info for all of the stuff within the body of the function
9522 (if it has one - it may be just a declaration). */
9523 outer_scope = DECL_INITIAL (decl);
9525 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9526 node created to represent a function. This outermost BLOCK actually
9527 represents the outermost binding contour for the function, i.e. the
9528 contour in which the function's formal parameters and labels get
9529 declared. Curiously, it appears that the front end doesn't actually
9530 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9531 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9532 list for the function instead.) The BLOCK_VARS list for the
9533 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9534 the function however, and we output DWARF info for those in
9535 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9536 node representing the function's outermost pair of curly braces, and
9537 any blocks used for the base and member initializers of a C++
9538 constructor function. */
9539 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9541 current_function_has_inlines = 0;
9542 decls_for_scope (outer_scope, subr_die, 0);
9544 #if 0 && defined (MIPS_DEBUGGING_INFO)
9545 if (current_function_has_inlines)
9547 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9548 if (! comp_unit_has_inlines)
9550 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9551 comp_unit_has_inlines = 1;
9554 #endif
9558 /* Generate a DIE to represent a declared data object. */
9560 static void
9561 gen_variable_die (decl, context_die)
9562 register tree decl;
9563 register dw_die_ref context_die;
9565 register tree origin = decl_ultimate_origin (decl);
9566 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9568 dw_die_ref old_die = lookup_decl_die (decl);
9569 int declaration = (DECL_EXTERNAL (decl)
9570 || class_scope_p (context_die));
9572 if (origin != NULL)
9573 add_abstract_origin_attribute (var_die, origin);
9574 /* Loop unrolling can create multiple blocks that refer to the same
9575 static variable, so we must test for the DW_AT_declaration flag. */
9576 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9577 copy decls and set the DECL_ABSTRACT flag on them instead of
9578 sharing them. */
9579 else if (old_die && TREE_STATIC (decl)
9580 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9582 /* This is a definition of a C++ class level static. */
9583 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9584 if (DECL_NAME (decl))
9586 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9588 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9589 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9591 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9592 != (unsigned) DECL_SOURCE_LINE (decl))
9594 add_AT_unsigned (var_die, DW_AT_decl_line,
9595 DECL_SOURCE_LINE (decl));
9598 else
9600 add_name_and_src_coords_attributes (var_die, decl);
9601 add_type_attribute (var_die, TREE_TYPE (decl),
9602 TREE_READONLY (decl),
9603 TREE_THIS_VOLATILE (decl), context_die);
9605 if (TREE_PUBLIC (decl))
9606 add_AT_flag (var_die, DW_AT_external, 1);
9608 if (DECL_ARTIFICIAL (decl))
9609 add_AT_flag (var_die, DW_AT_artificial, 1);
9611 if (TREE_PROTECTED (decl))
9612 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9614 else if (TREE_PRIVATE (decl))
9615 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9618 if (declaration)
9619 add_AT_flag (var_die, DW_AT_declaration, 1);
9621 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9622 equate_decl_number_to_die (decl, var_die);
9624 if (! declaration && ! DECL_ABSTRACT (decl))
9626 add_location_or_const_value_attribute (var_die, decl);
9627 add_pubname (decl, var_die);
9629 else
9630 tree_add_const_value_attribute (var_die, decl);
9633 /* Generate a DIE to represent a label identifier. */
9635 static void
9636 gen_label_die (decl, context_die)
9637 register tree decl;
9638 register dw_die_ref context_die;
9640 register tree origin = decl_ultimate_origin (decl);
9641 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
9642 register rtx insn;
9643 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9645 if (origin != NULL)
9646 add_abstract_origin_attribute (lbl_die, origin);
9647 else
9648 add_name_and_src_coords_attributes (lbl_die, decl);
9650 if (DECL_ABSTRACT (decl))
9651 equate_decl_number_to_die (decl, lbl_die);
9652 else
9654 insn = DECL_RTL (decl);
9656 /* Deleted labels are programmer specified labels which have been
9657 eliminated because of various optimisations. We still emit them
9658 here so that it is possible to put breakpoints on them. */
9659 if (GET_CODE (insn) == CODE_LABEL
9660 || ((GET_CODE (insn) == NOTE
9661 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
9663 /* When optimization is enabled (via -O) some parts of the compiler
9664 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
9665 represent source-level labels which were explicitly declared by
9666 the user. This really shouldn't be happening though, so catch
9667 it if it ever does happen. */
9668 if (INSN_DELETED_P (insn))
9669 abort ();
9671 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
9672 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
9677 /* Generate a DIE for a lexical block. */
9679 static void
9680 gen_lexical_block_die (stmt, context_die, depth)
9681 register tree stmt;
9682 register dw_die_ref context_die;
9683 int depth;
9685 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
9686 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9688 if (! BLOCK_ABSTRACT (stmt))
9690 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9691 BLOCK_NUMBER (stmt));
9692 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
9693 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9694 BLOCK_NUMBER (stmt));
9695 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
9698 decls_for_scope (stmt, stmt_die, depth);
9701 /* Generate a DIE for an inlined subprogram. */
9703 static void
9704 gen_inlined_subroutine_die (stmt, context_die, depth)
9705 register tree stmt;
9706 register dw_die_ref context_die;
9707 int depth;
9709 if (! BLOCK_ABSTRACT (stmt))
9711 register dw_die_ref subr_die
9712 = new_die (DW_TAG_inlined_subroutine, context_die);
9713 register tree decl = block_ultimate_origin (stmt);
9714 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9716 /* Emit info for the abstract instance first, if we haven't yet. */
9717 dwarf2out_abstract_function (decl);
9719 add_abstract_origin_attribute (subr_die, decl);
9720 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9721 BLOCK_NUMBER (stmt));
9722 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
9723 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9724 BLOCK_NUMBER (stmt));
9725 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
9726 decls_for_scope (stmt, subr_die, depth);
9727 current_function_has_inlines = 1;
9731 /* Generate a DIE for a field in a record, or structure. */
9733 static void
9734 gen_field_die (decl, context_die)
9735 register tree decl;
9736 register dw_die_ref context_die;
9738 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
9740 add_name_and_src_coords_attributes (decl_die, decl);
9741 add_type_attribute (decl_die, member_declared_type (decl),
9742 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
9743 context_die);
9745 /* If this is a bit field... */
9746 if (DECL_BIT_FIELD_TYPE (decl))
9748 add_byte_size_attribute (decl_die, decl);
9749 add_bit_size_attribute (decl_die, decl);
9750 add_bit_offset_attribute (decl_die, decl);
9753 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
9754 add_data_member_location_attribute (decl_die, decl);
9756 if (DECL_ARTIFICIAL (decl))
9757 add_AT_flag (decl_die, DW_AT_artificial, 1);
9759 if (TREE_PROTECTED (decl))
9760 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
9762 else if (TREE_PRIVATE (decl))
9763 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
9766 #if 0
9767 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9768 Use modified_type_die instead.
9769 We keep this code here just in case these types of DIEs may be needed to
9770 represent certain things in other languages (e.g. Pascal) someday. */
9771 static void
9772 gen_pointer_type_die (type, context_die)
9773 register tree type;
9774 register dw_die_ref context_die;
9776 register dw_die_ref ptr_die
9777 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
9779 equate_type_number_to_die (type, ptr_die);
9780 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9781 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9784 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9785 Use modified_type_die instead.
9786 We keep this code here just in case these types of DIEs may be needed to
9787 represent certain things in other languages (e.g. Pascal) someday. */
9788 static void
9789 gen_reference_type_die (type, context_die)
9790 register tree type;
9791 register dw_die_ref context_die;
9793 register dw_die_ref ref_die
9794 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
9796 equate_type_number_to_die (type, ref_die);
9797 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
9798 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9800 #endif
9802 /* Generate a DIE for a pointer to a member type. */
9803 static void
9804 gen_ptr_to_mbr_type_die (type, context_die)
9805 register tree type;
9806 register dw_die_ref context_die;
9808 register dw_die_ref ptr_die
9809 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
9811 equate_type_number_to_die (type, ptr_die);
9812 add_AT_die_ref (ptr_die, DW_AT_containing_type,
9813 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
9814 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9817 /* Generate the DIE for the compilation unit. */
9819 static dw_die_ref
9820 gen_compile_unit_die (filename)
9821 register const char *filename;
9823 register dw_die_ref die;
9824 char producer[250];
9825 const char *wd = getpwd ();
9826 int language;
9828 die = new_die (DW_TAG_compile_unit, NULL);
9829 add_name_attribute (die, filename);
9831 if (wd != NULL && filename[0] != DIR_SEPARATOR)
9832 add_AT_string (die, DW_AT_comp_dir, wd);
9834 sprintf (producer, "%s %s", language_string, version_string);
9836 #ifdef MIPS_DEBUGGING_INFO
9837 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
9838 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
9839 not appear in the producer string, the debugger reaches the conclusion
9840 that the object file is stripped and has no debugging information.
9841 To get the MIPS/SGI debugger to believe that there is debugging
9842 information in the object file, we add a -g to the producer string. */
9843 if (debug_info_level > DINFO_LEVEL_TERSE)
9844 strcat (producer, " -g");
9845 #endif
9847 add_AT_string (die, DW_AT_producer, producer);
9849 if (strcmp (language_string, "GNU C++") == 0)
9850 language = DW_LANG_C_plus_plus;
9851 else if (strcmp (language_string, "GNU Ada") == 0)
9852 language = DW_LANG_Ada83;
9853 else if (strcmp (language_string, "GNU F77") == 0)
9854 language = DW_LANG_Fortran77;
9855 else if (strcmp (language_string, "GNU Pascal") == 0)
9856 language = DW_LANG_Pascal83;
9857 else if (strcmp (language_string, "GNU Java") == 0)
9858 language = DW_LANG_Java;
9859 else if (flag_traditional)
9860 language = DW_LANG_C;
9861 else
9862 language = DW_LANG_C89;
9864 add_AT_unsigned (die, DW_AT_language, language);
9866 return die;
9869 /* Generate a DIE for a string type. */
9871 static void
9872 gen_string_type_die (type, context_die)
9873 register tree type;
9874 register dw_die_ref context_die;
9876 register dw_die_ref type_die
9877 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
9879 equate_type_number_to_die (type, type_die);
9881 /* Fudge the string length attribute for now. */
9883 /* TODO: add string length info.
9884 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
9885 bound_representation (upper_bound, 0, 'u'); */
9888 /* Generate the DIE for a base class. */
9890 static void
9891 gen_inheritance_die (binfo, context_die)
9892 register tree binfo;
9893 register dw_die_ref context_die;
9895 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
9897 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
9898 add_data_member_location_attribute (die, binfo);
9900 if (TREE_VIA_VIRTUAL (binfo))
9901 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9902 if (TREE_VIA_PUBLIC (binfo))
9903 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
9904 else if (TREE_VIA_PROTECTED (binfo))
9905 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
9908 /* Generate a DIE for a class member. */
9910 static void
9911 gen_member_die (type, context_die)
9912 register tree type;
9913 register dw_die_ref context_die;
9915 register tree member;
9916 dw_die_ref child;
9918 /* If this is not an incomplete type, output descriptions of each of its
9919 members. Note that as we output the DIEs necessary to represent the
9920 members of this record or union type, we will also be trying to output
9921 DIEs to represent the *types* of those members. However the `type'
9922 function (above) will specifically avoid generating type DIEs for member
9923 types *within* the list of member DIEs for this (containing) type execpt
9924 for those types (of members) which are explicitly marked as also being
9925 members of this (containing) type themselves. The g++ front- end can
9926 force any given type to be treated as a member of some other
9927 (containing) type by setting the TYPE_CONTEXT of the given (member) type
9928 to point to the TREE node representing the appropriate (containing)
9929 type. */
9931 /* First output info about the base classes. */
9932 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
9934 register tree bases = TYPE_BINFO_BASETYPES (type);
9935 register int n_bases = TREE_VEC_LENGTH (bases);
9936 register int i;
9938 for (i = 0; i < n_bases; i++)
9939 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
9942 /* Now output info about the data members and type members. */
9943 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
9945 /* If we thought we were generating minimal debug info for TYPE
9946 and then changed our minds, some of the member declarations
9947 may have already been defined. Don't define them again, but
9948 do put them in the right order. */
9950 child = lookup_decl_die (member);
9951 if (child)
9952 splice_child_die (context_die, child);
9953 else
9954 gen_decl_die (member, context_die);
9957 /* Now output info about the function members (if any). */
9958 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
9960 /* Don't include clones in the member list. */
9961 if (DECL_ABSTRACT_ORIGIN (member))
9962 continue;
9964 child = lookup_decl_die (member);
9965 if (child)
9966 splice_child_die (context_die, child);
9967 else
9968 gen_decl_die (member, context_die);
9972 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
9973 is set, we pretend that the type was never defined, so we only get the
9974 member DIEs needed by later specification DIEs. */
9976 static void
9977 gen_struct_or_union_type_die (type, context_die)
9978 register tree type;
9979 register dw_die_ref context_die;
9981 register dw_die_ref type_die = lookup_type_die (type);
9982 register dw_die_ref scope_die = 0;
9983 register int nested = 0;
9984 int complete = (TYPE_SIZE (type)
9985 && (! TYPE_STUB_DECL (type)
9986 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
9988 if (type_die && ! complete)
9989 return;
9991 if (TYPE_CONTEXT (type) != NULL_TREE
9992 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
9993 nested = 1;
9995 scope_die = scope_die_for (type, context_die);
9997 if (! type_die || (nested && scope_die == comp_unit_die))
9998 /* First occurrence of type or toplevel definition of nested class. */
10000 register dw_die_ref old_die = type_die;
10002 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10003 ? DW_TAG_structure_type : DW_TAG_union_type,
10004 scope_die);
10005 equate_type_number_to_die (type, type_die);
10006 if (old_die)
10007 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10008 else
10009 add_name_attribute (type_die, type_tag (type));
10011 else
10012 remove_AT (type_die, DW_AT_declaration);
10014 /* If this type has been completed, then give it a byte_size attribute and
10015 then give a list of members. */
10016 if (complete)
10018 /* Prevent infinite recursion in cases where the type of some member of
10019 this type is expressed in terms of this type itself. */
10020 TREE_ASM_WRITTEN (type) = 1;
10021 add_byte_size_attribute (type_die, type);
10022 if (TYPE_STUB_DECL (type) != NULL_TREE)
10023 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10025 /* If the first reference to this type was as the return type of an
10026 inline function, then it may not have a parent. Fix this now. */
10027 if (type_die->die_parent == NULL)
10028 add_child_die (scope_die, type_die);
10030 push_decl_scope (type);
10031 gen_member_die (type, type_die);
10032 pop_decl_scope ();
10034 /* GNU extension: Record what type our vtable lives in. */
10035 if (TYPE_VFIELD (type))
10037 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10039 gen_type_die (vtype, context_die);
10040 add_AT_die_ref (type_die, DW_AT_containing_type,
10041 lookup_type_die (vtype));
10044 else
10046 add_AT_flag (type_die, DW_AT_declaration, 1);
10048 /* We don't need to do this for function-local types. */
10049 if (! decl_function_context (TYPE_STUB_DECL (type)))
10050 add_incomplete_type (type);
10054 /* Generate a DIE for a subroutine _type_. */
10056 static void
10057 gen_subroutine_type_die (type, context_die)
10058 register tree type;
10059 register dw_die_ref context_die;
10061 register tree return_type = TREE_TYPE (type);
10062 register dw_die_ref subr_die
10063 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10065 equate_type_number_to_die (type, subr_die);
10066 add_prototyped_attribute (subr_die, type);
10067 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10068 gen_formal_types_die (type, subr_die);
10071 /* Generate a DIE for a type definition */
10073 static void
10074 gen_typedef_die (decl, context_die)
10075 register tree decl;
10076 register dw_die_ref context_die;
10078 register dw_die_ref type_die;
10079 register tree origin;
10081 if (TREE_ASM_WRITTEN (decl))
10082 return;
10083 TREE_ASM_WRITTEN (decl) = 1;
10085 type_die = new_die (DW_TAG_typedef, context_die);
10086 origin = decl_ultimate_origin (decl);
10087 if (origin != NULL)
10088 add_abstract_origin_attribute (type_die, origin);
10089 else
10091 register tree type;
10092 add_name_and_src_coords_attributes (type_die, decl);
10093 if (DECL_ORIGINAL_TYPE (decl))
10095 type = DECL_ORIGINAL_TYPE (decl);
10097 if (type == TREE_TYPE (decl))
10098 abort ();
10099 else
10100 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10102 else
10103 type = TREE_TYPE (decl);
10104 add_type_attribute (type_die, type, TREE_READONLY (decl),
10105 TREE_THIS_VOLATILE (decl), context_die);
10108 if (DECL_ABSTRACT (decl))
10109 equate_decl_number_to_die (decl, type_die);
10112 /* Generate a type description DIE. */
10114 static void
10115 gen_type_die (type, context_die)
10116 register tree type;
10117 register dw_die_ref context_die;
10119 int need_pop;
10121 if (type == NULL_TREE || type == error_mark_node)
10122 return;
10124 /* We are going to output a DIE to represent the unqualified version of
10125 this type (i.e. without any const or volatile qualifiers) so get the
10126 main variant (i.e. the unqualified version) of this type now. */
10127 type = type_main_variant (type);
10129 if (TREE_ASM_WRITTEN (type))
10130 return;
10132 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10133 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10135 TREE_ASM_WRITTEN (type) = 1;
10136 gen_decl_die (TYPE_NAME (type), context_die);
10137 return;
10140 switch (TREE_CODE (type))
10142 case ERROR_MARK:
10143 break;
10145 case POINTER_TYPE:
10146 case REFERENCE_TYPE:
10147 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10148 ensures that the gen_type_die recursion will terminate even if the
10149 type is recursive. Recursive types are possible in Ada. */
10150 /* ??? We could perhaps do this for all types before the switch
10151 statement. */
10152 TREE_ASM_WRITTEN (type) = 1;
10154 /* For these types, all that is required is that we output a DIE (or a
10155 set of DIEs) to represent the "basis" type. */
10156 gen_type_die (TREE_TYPE (type), context_die);
10157 break;
10159 case OFFSET_TYPE:
10160 /* This code is used for C++ pointer-to-data-member types.
10161 Output a description of the relevant class type. */
10162 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10164 /* Output a description of the type of the object pointed to. */
10165 gen_type_die (TREE_TYPE (type), context_die);
10167 /* Now output a DIE to represent this pointer-to-data-member type
10168 itself. */
10169 gen_ptr_to_mbr_type_die (type, context_die);
10170 break;
10172 case SET_TYPE:
10173 gen_type_die (TYPE_DOMAIN (type), context_die);
10174 gen_set_type_die (type, context_die);
10175 break;
10177 case FILE_TYPE:
10178 gen_type_die (TREE_TYPE (type), context_die);
10179 abort (); /* No way to represent these in Dwarf yet! */
10180 break;
10182 case FUNCTION_TYPE:
10183 /* Force out return type (in case it wasn't forced out already). */
10184 gen_type_die (TREE_TYPE (type), context_die);
10185 gen_subroutine_type_die (type, context_die);
10186 break;
10188 case METHOD_TYPE:
10189 /* Force out return type (in case it wasn't forced out already). */
10190 gen_type_die (TREE_TYPE (type), context_die);
10191 gen_subroutine_type_die (type, context_die);
10192 break;
10194 case ARRAY_TYPE:
10195 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10197 gen_type_die (TREE_TYPE (type), context_die);
10198 gen_string_type_die (type, context_die);
10200 else
10201 gen_array_type_die (type, context_die);
10202 break;
10204 case VECTOR_TYPE:
10205 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10206 break;
10208 case ENUMERAL_TYPE:
10209 case RECORD_TYPE:
10210 case UNION_TYPE:
10211 case QUAL_UNION_TYPE:
10212 /* If this is a nested type whose containing class hasn't been
10213 written out yet, writing it out will cover this one, too.
10214 This does not apply to instantiations of member class templates;
10215 they need to be added to the containing class as they are
10216 generated. FIXME: This hurts the idea of combining type decls
10217 from multiple TUs, since we can't predict what set of template
10218 instantiations we'll get. */
10219 if (TYPE_CONTEXT (type)
10220 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10221 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10223 gen_type_die (TYPE_CONTEXT (type), context_die);
10225 if (TREE_ASM_WRITTEN (type))
10226 return;
10228 /* If that failed, attach ourselves to the stub. */
10229 push_decl_scope (TYPE_CONTEXT (type));
10230 context_die = lookup_type_die (TYPE_CONTEXT (type));
10231 need_pop = 1;
10233 else
10234 need_pop = 0;
10236 if (TREE_CODE (type) == ENUMERAL_TYPE)
10237 gen_enumeration_type_die (type, context_die);
10238 else
10239 gen_struct_or_union_type_die (type, context_die);
10241 if (need_pop)
10242 pop_decl_scope ();
10244 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10245 it up if it is ever completed. gen_*_type_die will set it for us
10246 when appropriate. */
10247 return;
10249 case VOID_TYPE:
10250 case INTEGER_TYPE:
10251 case REAL_TYPE:
10252 case COMPLEX_TYPE:
10253 case BOOLEAN_TYPE:
10254 case CHAR_TYPE:
10255 /* No DIEs needed for fundamental types. */
10256 break;
10258 case LANG_TYPE:
10259 /* No Dwarf representation currently defined. */
10260 break;
10262 default:
10263 abort ();
10266 TREE_ASM_WRITTEN (type) = 1;
10269 /* Generate a DIE for a tagged type instantiation. */
10271 static void
10272 gen_tagged_type_instantiation_die (type, context_die)
10273 register tree type;
10274 register dw_die_ref context_die;
10276 if (type == NULL_TREE || type == error_mark_node)
10277 return;
10279 /* We are going to output a DIE to represent the unqualified version of
10280 this type (i.e. without any const or volatile qualifiers) so make sure
10281 that we have the main variant (i.e. the unqualified version) of this
10282 type now. */
10283 if (type != type_main_variant (type))
10284 abort ();
10286 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10287 an instance of an unresolved type. */
10289 switch (TREE_CODE (type))
10291 case ERROR_MARK:
10292 break;
10294 case ENUMERAL_TYPE:
10295 gen_inlined_enumeration_type_die (type, context_die);
10296 break;
10298 case RECORD_TYPE:
10299 gen_inlined_structure_type_die (type, context_die);
10300 break;
10302 case UNION_TYPE:
10303 case QUAL_UNION_TYPE:
10304 gen_inlined_union_type_die (type, context_die);
10305 break;
10307 default:
10308 abort ();
10312 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10313 things which are local to the given block. */
10315 static void
10316 gen_block_die (stmt, context_die, depth)
10317 register tree stmt;
10318 register dw_die_ref context_die;
10319 int depth;
10321 register int must_output_die = 0;
10322 register tree origin;
10323 register tree decl;
10324 register enum tree_code origin_code;
10326 /* Ignore blocks never really used to make RTL. */
10328 if (stmt == NULL_TREE || !TREE_USED (stmt)
10329 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10330 return;
10332 /* Determine the "ultimate origin" of this block. This block may be an
10333 inlined instance of an inlined instance of inline function, so we have
10334 to trace all of the way back through the origin chain to find out what
10335 sort of node actually served as the original seed for the creation of
10336 the current block. */
10337 origin = block_ultimate_origin (stmt);
10338 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10340 /* Determine if we need to output any Dwarf DIEs at all to represent this
10341 block. */
10342 if (origin_code == FUNCTION_DECL)
10343 /* The outer scopes for inlinings *must* always be represented. We
10344 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10345 must_output_die = 1;
10346 else
10348 /* In the case where the current block represents an inlining of the
10349 "body block" of an inline function, we must *NOT* output any DIE for
10350 this block because we have already output a DIE to represent the
10351 whole inlined function scope and the "body block" of any function
10352 doesn't really represent a different scope according to ANSI C
10353 rules. So we check here to make sure that this block does not
10354 represent a "body block inlining" before trying to set the
10355 `must_output_die' flag. */
10356 if (! is_body_block (origin ? origin : stmt))
10358 /* Determine if this block directly contains any "significant"
10359 local declarations which we will need to output DIEs for. */
10360 if (debug_info_level > DINFO_LEVEL_TERSE)
10361 /* We are not in terse mode so *any* local declaration counts
10362 as being a "significant" one. */
10363 must_output_die = (BLOCK_VARS (stmt) != NULL);
10364 else
10365 /* We are in terse mode, so only local (nested) function
10366 definitions count as "significant" local declarations. */
10367 for (decl = BLOCK_VARS (stmt);
10368 decl != NULL; decl = TREE_CHAIN (decl))
10369 if (TREE_CODE (decl) == FUNCTION_DECL
10370 && DECL_INITIAL (decl))
10372 must_output_die = 1;
10373 break;
10378 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10379 DIE for any block which contains no significant local declarations at
10380 all. Rather, in such cases we just call `decls_for_scope' so that any
10381 needed Dwarf info for any sub-blocks will get properly generated. Note
10382 that in terse mode, our definition of what constitutes a "significant"
10383 local declaration gets restricted to include only inlined function
10384 instances and local (nested) function definitions. */
10385 if (must_output_die)
10387 if (origin_code == FUNCTION_DECL)
10388 gen_inlined_subroutine_die (stmt, context_die, depth);
10389 else
10390 gen_lexical_block_die (stmt, context_die, depth);
10392 else
10393 decls_for_scope (stmt, context_die, depth);
10396 /* Generate all of the decls declared within a given scope and (recursively)
10397 all of its sub-blocks. */
10399 static void
10400 decls_for_scope (stmt, context_die, depth)
10401 register tree stmt;
10402 register dw_die_ref context_die;
10403 int depth;
10405 register tree decl;
10406 register tree subblocks;
10408 /* Ignore blocks never really used to make RTL. */
10409 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10410 return;
10412 /* Output the DIEs to represent all of the data objects and typedefs
10413 declared directly within this block but not within any nested
10414 sub-blocks. Also, nested function and tag DIEs have been
10415 generated with a parent of NULL; fix that up now. */
10416 for (decl = BLOCK_VARS (stmt);
10417 decl != NULL; decl = TREE_CHAIN (decl))
10419 register dw_die_ref die;
10421 if (TREE_CODE (decl) == FUNCTION_DECL)
10422 die = lookup_decl_die (decl);
10423 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10424 die = lookup_type_die (TREE_TYPE (decl));
10425 else
10426 die = NULL;
10428 if (die != NULL && die->die_parent == NULL)
10429 add_child_die (context_die, die);
10430 else
10431 gen_decl_die (decl, context_die);
10434 /* Output the DIEs to represent all sub-blocks (and the items declared
10435 therein) of this block. */
10436 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10437 subblocks != NULL;
10438 subblocks = BLOCK_CHAIN (subblocks))
10439 gen_block_die (subblocks, context_die, depth + 1);
10442 /* Is this a typedef we can avoid emitting? */
10444 static inline int
10445 is_redundant_typedef (decl)
10446 register tree decl;
10448 if (TYPE_DECL_IS_STUB (decl))
10449 return 1;
10451 if (DECL_ARTIFICIAL (decl)
10452 && DECL_CONTEXT (decl)
10453 && is_tagged_type (DECL_CONTEXT (decl))
10454 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10455 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10456 /* Also ignore the artificial member typedef for the class name. */
10457 return 1;
10459 return 0;
10462 /* Generate Dwarf debug information for a decl described by DECL. */
10464 static void
10465 gen_decl_die (decl, context_die)
10466 register tree decl;
10467 register dw_die_ref context_die;
10469 register tree origin;
10471 if (TREE_CODE (decl) == ERROR_MARK)
10472 return;
10474 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10475 if (DECL_IGNORED_P (decl))
10476 return;
10478 switch (TREE_CODE (decl))
10480 case CONST_DECL:
10481 /* The individual enumerators of an enum type get output when we output
10482 the Dwarf representation of the relevant enum type itself. */
10483 break;
10485 case FUNCTION_DECL:
10486 /* Don't output any DIEs to represent mere function declarations,
10487 unless they are class members or explicit block externs. */
10488 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10489 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10490 break;
10492 /* If we're emitting a clone, emit info for the abstract instance. */
10493 if (DECL_ORIGIN (decl) != decl)
10494 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
10495 /* If we're emitting an out-of-line copy of an inline function,
10496 emit info for the abstract instance and set up to refer to it. */
10497 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10498 && ! class_scope_p (context_die)
10499 /* dwarf2out_abstract_function won't emit a die if this is just
10500 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10501 that case, because that works only if we have a die. */
10502 && DECL_INITIAL (decl) != NULL_TREE)
10504 dwarf2out_abstract_function (decl);
10505 set_decl_origin_self (decl);
10507 /* Otherwise we're emitting the primary DIE for this decl. */
10508 else if (debug_info_level > DINFO_LEVEL_TERSE)
10510 /* Before we describe the FUNCTION_DECL itself, make sure that we
10511 have described its return type. */
10512 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10514 /* And its virtual context. */
10515 if (DECL_VINDEX (decl) != NULL_TREE)
10516 gen_type_die (DECL_CONTEXT (decl), context_die);
10518 /* And its containing type. */
10519 origin = decl_class_context (decl);
10520 if (origin != NULL_TREE)
10521 gen_type_die_for_member (origin, decl, context_die);
10524 /* Now output a DIE to represent the function itself. */
10525 gen_subprogram_die (decl, context_die);
10526 break;
10528 case TYPE_DECL:
10529 /* If we are in terse mode, don't generate any DIEs to represent any
10530 actual typedefs. */
10531 if (debug_info_level <= DINFO_LEVEL_TERSE)
10532 break;
10534 /* In the special case of a TYPE_DECL node representing the
10535 declaration of some type tag, if the given TYPE_DECL is marked as
10536 having been instantiated from some other (original) TYPE_DECL node
10537 (e.g. one which was generated within the original definition of an
10538 inline function) we have to generate a special (abbreviated)
10539 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10540 DIE here. */
10541 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10543 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10544 break;
10547 if (is_redundant_typedef (decl))
10548 gen_type_die (TREE_TYPE (decl), context_die);
10549 else
10550 /* Output a DIE to represent the typedef itself. */
10551 gen_typedef_die (decl, context_die);
10552 break;
10554 case LABEL_DECL:
10555 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10556 gen_label_die (decl, context_die);
10557 break;
10559 case VAR_DECL:
10560 /* If we are in terse mode, don't generate any DIEs to represent any
10561 variable declarations or definitions. */
10562 if (debug_info_level <= DINFO_LEVEL_TERSE)
10563 break;
10565 /* Output any DIEs that are needed to specify the type of this data
10566 object. */
10567 gen_type_die (TREE_TYPE (decl), context_die);
10569 /* And its containing type. */
10570 origin = decl_class_context (decl);
10571 if (origin != NULL_TREE)
10572 gen_type_die_for_member (origin, decl, context_die);
10574 /* Now output the DIE to represent the data object itself. This gets
10575 complicated because of the possibility that the VAR_DECL really
10576 represents an inlined instance of a formal parameter for an inline
10577 function. */
10578 origin = decl_ultimate_origin (decl);
10579 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10580 gen_formal_parameter_die (decl, context_die);
10581 else
10582 gen_variable_die (decl, context_die);
10583 break;
10585 case FIELD_DECL:
10586 /* Ignore the nameless fields that are used to skip bits, but
10587 handle C++ anonymous unions. */
10588 if (DECL_NAME (decl) != NULL_TREE
10589 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10591 gen_type_die (member_declared_type (decl), context_die);
10592 gen_field_die (decl, context_die);
10594 break;
10596 case PARM_DECL:
10597 gen_type_die (TREE_TYPE (decl), context_die);
10598 gen_formal_parameter_die (decl, context_die);
10599 break;
10601 case NAMESPACE_DECL:
10602 /* Ignore for now. */
10603 break;
10605 default:
10606 abort ();
10610 /* Add Ada "use" clause information for SGI Workshop debugger. */
10612 void
10613 dwarf2out_add_library_unit_info (filename, context_list)
10614 const char *filename;
10615 const char *context_list;
10617 unsigned int file_index;
10619 if (filename != NULL)
10621 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10622 tree context_list_decl
10623 = build_decl (LABEL_DECL, get_identifier (context_list),
10624 void_type_node);
10626 TREE_PUBLIC (context_list_decl) = TRUE;
10627 add_name_attribute (unit_die, context_list);
10628 file_index = lookup_filename (filename);
10629 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10630 add_pubname (context_list_decl, unit_die);
10634 /* Write the debugging output for DECL. */
10636 void
10637 dwarf2out_decl (decl)
10638 register tree decl;
10640 register dw_die_ref context_die = comp_unit_die;
10642 if (TREE_CODE (decl) == ERROR_MARK)
10643 return;
10645 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10646 if (DECL_IGNORED_P (decl))
10647 return;
10649 switch (TREE_CODE (decl))
10651 case FUNCTION_DECL:
10652 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
10653 builtin function. Explicit programmer-supplied declarations of
10654 these same functions should NOT be ignored however. */
10655 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
10656 return;
10658 /* What we would really like to do here is to filter out all mere
10659 file-scope declarations of file-scope functions which are never
10660 referenced later within this translation unit (and keep all of ones
10661 that *are* referenced later on) but we aren't clairvoyant, so we have
10662 no idea which functions will be referenced in the future (i.e. later
10663 on within the current translation unit). So here we just ignore all
10664 file-scope function declarations which are not also definitions. If
10665 and when the debugger needs to know something about these functions,
10666 it will have to hunt around and find the DWARF information associated
10667 with the definition of the function. Note that we can't just check
10668 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
10669 definitions and which ones represent mere declarations. We have to
10670 check `DECL_INITIAL' instead. That's because the C front-end
10671 supports some weird semantics for "extern inline" function
10672 definitions. These can get inlined within the current translation
10673 unit (an thus, we need to generate DWARF info for their abstract
10674 instances so that the DWARF info for the concrete inlined instances
10675 can have something to refer to) but the compiler never generates any
10676 out-of-lines instances of such things (despite the fact that they
10677 *are* definitions). The important point is that the C front-end
10678 marks these "extern inline" functions as DECL_EXTERNAL, but we need
10679 to generate DWARF for them anyway. Note that the C++ front-end also
10680 plays some similar games for inline function definitions appearing
10681 within include files which also contain
10682 `#pragma interface' pragmas. */
10683 if (DECL_INITIAL (decl) == NULL_TREE)
10684 return;
10686 /* If we're a nested function, initially use a parent of NULL; if we're
10687 a plain function, this will be fixed up in decls_for_scope. If
10688 we're a method, it will be ignored, since we already have a DIE. */
10689 if (decl_function_context (decl))
10690 context_die = NULL;
10692 break;
10694 case VAR_DECL:
10695 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
10696 declaration and if the declaration was never even referenced from
10697 within this entire compilation unit. We suppress these DIEs in
10698 order to save space in the .debug section (by eliminating entries
10699 which are probably useless). Note that we must not suppress
10700 block-local extern declarations (whether used or not) because that
10701 would screw-up the debugger's name lookup mechanism and cause it to
10702 miss things which really ought to be in scope at a given point. */
10703 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
10704 return;
10706 /* If we are in terse mode, don't generate any DIEs to represent any
10707 variable declarations or definitions. */
10708 if (debug_info_level <= DINFO_LEVEL_TERSE)
10709 return;
10710 break;
10712 case TYPE_DECL:
10713 /* Don't emit stubs for types unless they are needed by other DIEs. */
10714 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
10715 return;
10717 /* Don't bother trying to generate any DIEs to represent any of the
10718 normal built-in types for the language we are compiling. */
10719 if (DECL_SOURCE_LINE (decl) == 0)
10721 /* OK, we need to generate one for `bool' so GDB knows what type
10722 comparisons have. */
10723 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
10724 == DW_LANG_C_plus_plus)
10725 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
10726 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
10728 return;
10731 /* If we are in terse mode, don't generate any DIEs for types. */
10732 if (debug_info_level <= DINFO_LEVEL_TERSE)
10733 return;
10735 /* If we're a function-scope tag, initially use a parent of NULL;
10736 this will be fixed up in decls_for_scope. */
10737 if (decl_function_context (decl))
10738 context_die = NULL;
10740 break;
10742 default:
10743 return;
10746 gen_decl_die (decl, context_die);
10749 /* Output a marker (i.e. a label) for the beginning of the generated code for
10750 a lexical block. */
10752 void
10753 dwarf2out_begin_block (blocknum)
10754 register unsigned blocknum;
10756 function_section (current_function_decl);
10757 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
10760 /* Output a marker (i.e. a label) for the end of the generated code for a
10761 lexical block. */
10763 void
10764 dwarf2out_end_block (blocknum)
10765 register unsigned blocknum;
10767 function_section (current_function_decl);
10768 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
10771 /* Returns nonzero if it is appropriate not to emit any debugging
10772 information for BLOCK, because it doesn't contain any instructions.
10774 Don't allow this for blocks with nested functions or local classes
10775 as we would end up with orphans, and in the presence of scheduling
10776 we may end up calling them anyway. */
10779 dwarf2out_ignore_block (block)
10780 tree block;
10782 tree decl;
10783 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
10784 if (TREE_CODE (decl) == FUNCTION_DECL
10785 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
10786 return 0;
10787 return 1;
10790 /* Lookup a filename (in the list of filenames that we know about here in
10791 dwarf2out.c) and return its "index". The index of each (known) filename is
10792 just a unique number which is associated with only that one filename.
10793 We need such numbers for the sake of generating labels
10794 (in the .debug_sfnames section) and references to those
10795 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
10796 If the filename given as an argument is not found in our current list,
10797 add it to the list and assign it the next available unique index number.
10798 In order to speed up searches, we remember the index of the filename
10799 was looked up last. This handles the majority of all searches. */
10801 static unsigned
10802 lookup_filename (file_name)
10803 const char *file_name;
10805 register unsigned i;
10807 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
10808 if (strcmp (file_name, "<internal>") == 0
10809 || strcmp (file_name, "<built-in>") == 0)
10810 return 0;
10812 /* Check to see if the file name that was searched on the previous
10813 call matches this file name. If so, return the index. */
10814 if (file_table.last_lookup_index != 0)
10815 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
10816 return file_table.last_lookup_index;
10818 /* Didn't match the previous lookup, search the table */
10819 for (i = 1; i < file_table.in_use; ++i)
10820 if (strcmp (file_name, file_table.table[i]) == 0)
10822 file_table.last_lookup_index = i;
10823 return i;
10826 /* Prepare to add a new table entry by making sure there is enough space in
10827 the table to do so. If not, expand the current table. */
10828 if (i == file_table.allocated)
10830 file_table.allocated = i + FILE_TABLE_INCREMENT;
10831 file_table.table = (char **)
10832 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
10835 /* Add the new entry to the end of the filename table. */
10836 file_table.table[i] = xstrdup (file_name);
10837 file_table.in_use = i + 1;
10838 file_table.last_lookup_index = i;
10840 if (DWARF2_ASM_LINE_DEBUG_INFO)
10841 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
10843 return i;
10846 static void
10847 init_file_table ()
10849 /* Allocate the initial hunk of the file_table. */
10850 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
10851 file_table.allocated = FILE_TABLE_INCREMENT;
10853 /* Skip the first entry - file numbers begin at 1. */
10854 file_table.in_use = 1;
10855 file_table.last_lookup_index = 0;
10858 /* Output a label to mark the beginning of a source code line entry
10859 and record information relating to this source line, in
10860 'line_info_table' for later output of the .debug_line section. */
10862 void
10863 dwarf2out_line (filename, line)
10864 register const char *filename;
10865 register unsigned line;
10867 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10869 function_section (current_function_decl);
10871 if (DWARF2_ASM_LINE_DEBUG_INFO)
10873 unsigned file_num = lookup_filename (filename);
10875 /* Emit the .loc directive understood by GNU as. */
10876 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
10878 /* Indicate that line number info exists. */
10879 ++line_info_table_in_use;
10881 /* Indicate that multiple line number tables exist. */
10882 if (DECL_SECTION_NAME (current_function_decl))
10883 ++separate_line_info_table_in_use;
10885 else if (DECL_SECTION_NAME (current_function_decl))
10887 register dw_separate_line_info_ref line_info;
10888 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
10889 separate_line_info_table_in_use);
10890 if (flag_debug_asm)
10891 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
10892 filename, line);
10894 /* expand the line info table if necessary */
10895 if (separate_line_info_table_in_use
10896 == separate_line_info_table_allocated)
10898 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10899 separate_line_info_table
10900 = (dw_separate_line_info_ref)
10901 xrealloc (separate_line_info_table,
10902 separate_line_info_table_allocated
10903 * sizeof (dw_separate_line_info_entry));
10906 /* Add the new entry at the end of the line_info_table. */
10907 line_info
10908 = &separate_line_info_table[separate_line_info_table_in_use++];
10909 line_info->dw_file_num = lookup_filename (filename);
10910 line_info->dw_line_num = line;
10911 line_info->function = current_funcdef_number;
10913 else
10915 register dw_line_info_ref line_info;
10917 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
10918 line_info_table_in_use);
10919 if (flag_debug_asm)
10920 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
10921 filename, line);
10923 /* Expand the line info table if necessary. */
10924 if (line_info_table_in_use == line_info_table_allocated)
10926 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10927 line_info_table
10928 = (dw_line_info_ref)
10929 xrealloc (line_info_table,
10930 (line_info_table_allocated
10931 * sizeof (dw_line_info_entry)));
10934 /* Add the new entry at the end of the line_info_table. */
10935 line_info = &line_info_table[line_info_table_in_use++];
10936 line_info->dw_file_num = lookup_filename (filename);
10937 line_info->dw_line_num = line;
10942 /* Record the beginning of a new source file, for later output
10943 of the .debug_macinfo section. At present, unimplemented. */
10945 void
10946 dwarf2out_start_source_file (filename)
10947 register const char *filename ATTRIBUTE_UNUSED;
10949 if (flag_eliminate_dwarf2_dups)
10951 /* Record the beginning of the file for break_out_includes. */
10952 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
10953 add_AT_string (bincl_die, DW_AT_name, filename);
10957 /* Record the end of a source file, for later output
10958 of the .debug_macinfo section. At present, unimplemented. */
10960 void
10961 dwarf2out_end_source_file ()
10963 if (flag_eliminate_dwarf2_dups)
10965 /* Record the end of the file for break_out_includes. */
10966 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
10970 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10971 the tail part of the directive line, i.e. the part which is past the
10972 initial whitespace, #, whitespace, directive-name, whitespace part. */
10974 void
10975 dwarf2out_define (lineno, buffer)
10976 register unsigned lineno ATTRIBUTE_UNUSED;
10977 register const char *buffer ATTRIBUTE_UNUSED;
10979 static int initialized = 0;
10980 if (!initialized)
10982 dwarf2out_start_source_file (primary_filename);
10983 initialized = 1;
10987 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10988 the tail part of the directive line, i.e. the part which is past the
10989 initial whitespace, #, whitespace, directive-name, whitespace part. */
10991 void
10992 dwarf2out_undef (lineno, buffer)
10993 register unsigned lineno ATTRIBUTE_UNUSED;
10994 register const char *buffer ATTRIBUTE_UNUSED;
10998 /* Set up for Dwarf output at the start of compilation. */
11000 void
11001 dwarf2out_init (asm_out_file, main_input_filename)
11002 register FILE *asm_out_file;
11003 register const char *main_input_filename;
11005 init_file_table ();
11007 /* Remember the name of the primary input file. */
11008 primary_filename = main_input_filename;
11010 /* Add it to the file table first, under the assumption that we'll
11011 be emitting line number data for it first, which avoids having
11012 to add an initial DW_LNS_set_file. */
11013 lookup_filename (main_input_filename);
11015 /* Allocate the initial hunk of the decl_die_table. */
11016 decl_die_table
11017 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11018 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11019 decl_die_table_in_use = 0;
11021 /* Allocate the initial hunk of the decl_scope_table. */
11022 decl_scope_table
11023 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11024 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11025 decl_scope_depth = 0;
11027 /* Allocate the initial hunk of the abbrev_die_table. */
11028 abbrev_die_table
11029 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11030 sizeof (dw_die_ref));
11031 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11032 /* Zero-th entry is allocated, but unused */
11033 abbrev_die_table_in_use = 1;
11035 /* Allocate the initial hunk of the line_info_table. */
11036 line_info_table
11037 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11038 sizeof (dw_line_info_entry));
11039 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11040 /* Zero-th entry is allocated, but unused */
11041 line_info_table_in_use = 1;
11043 /* Generate the initial DIE for the .debug section. Note that the (string)
11044 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11045 will (typically) be a relative pathname and that this pathname should be
11046 taken as being relative to the directory from which the compiler was
11047 invoked when the given (base) source file was compiled. */
11048 comp_unit_die = gen_compile_unit_die (main_input_filename);
11050 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11051 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11053 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11054 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
11055 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11056 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11057 else
11058 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11059 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11060 DEBUG_INFO_SECTION_LABEL, 0);
11061 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11062 DEBUG_LINE_SECTION_LABEL, 0);
11064 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11065 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11066 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11068 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11069 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11071 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11072 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11073 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11074 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11077 /* Output stuff that dwarf requires at the end of every file,
11078 and generate the DWARF-2 debugging info. */
11080 void
11081 dwarf2out_finish ()
11083 limbo_die_node *node, *next_node;
11084 dw_die_ref die;
11086 /* Traverse the limbo die list, and add parent/child links. The only
11087 dies without parents that should be here are concrete instances of
11088 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11089 For concrete instances, we can get the parent die from the abstract
11090 instance. */
11091 for (node = limbo_die_list; node; node = next_node)
11093 next_node = node->next;
11094 die = node->die;
11096 if (die->die_parent == NULL)
11098 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11099 if (origin)
11100 add_child_die (origin->die_parent, die);
11101 else if (die == comp_unit_die)
11103 else
11104 abort ();
11106 free (node);
11108 limbo_die_list = NULL;
11110 /* Walk through the list of incomplete types again, trying once more to
11111 emit full debugging info for them. */
11112 retry_incomplete_types ();
11114 /* We need to reverse all the dies before break_out_includes, or
11115 we'll see the end of an include file before the beginning. */
11116 reverse_all_dies (comp_unit_die);
11118 /* Generate separate CUs for each of the include files we've seen.
11119 They will go into limbo_die_list. */
11120 if (flag_eliminate_dwarf2_dups)
11121 break_out_includes (comp_unit_die);
11123 /* Traverse the DIE's and add add sibling attributes to those DIE's
11124 that have children. */
11125 add_sibling_attributes (comp_unit_die);
11126 for (node = limbo_die_list; node; node = node->next)
11127 add_sibling_attributes (node->die);
11129 /* Output a terminator label for the .text section. */
11130 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11131 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11133 #if 0
11134 /* Output a terminator label for the .data section. */
11135 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11136 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11138 /* Output a terminator label for the .bss section. */
11139 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11140 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11141 #endif
11143 /* Output the source line correspondence table. */
11144 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
11146 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11148 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11149 output_line_info ();
11152 /* We can only use the low/high_pc attributes if all of the code
11153 was in .text. */
11154 if (separate_line_info_table_in_use == 0)
11156 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11157 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11160 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11161 debug_line_section_label);
11164 #if 0 /* unimplemented */
11165 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11166 add_AT_unsigned (die, DW_AT_macro_info, 0);
11167 #endif
11169 /* Output all of the compilation units. We put the main one last so that
11170 the offsets are available to output_pubnames. */
11171 for (node = limbo_die_list; node; node = node->next)
11172 output_comp_unit (node->die);
11173 output_comp_unit (comp_unit_die);
11175 /* Output the abbreviation table. */
11176 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11177 output_abbrev_section ();
11179 if (pubname_table_in_use)
11181 /* Output public names table. */
11182 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11183 output_pubnames ();
11186 /* We only put functions in the arange table, so don't write it out if
11187 we don't have any. */
11188 if (fde_table_in_use)
11190 /* Output the address range information. */
11191 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11192 output_aranges ();
11195 #endif /* DWARF2_DEBUGGING_INFO */