Merge branch 'master' of ssh://crater.dragonflybsd.org/repository/git/dragonfly
[dragonfly.git] / contrib / gcc-3.4 / gcc / dwarf2out.c
CommitLineData
003757ed
MD
1/* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
1c1138ce 3 2003, 2004, 2005 Free Software Foundation, Inc.
003757ed
MD
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).
7
8This file is part of GCC.
9
10GCC is free software; you can redistribute it and/or modify it under
11the terms of the GNU General Public License as published by the Free
12Software Foundation; either version 2, or (at your option) any later
13version.
14
15GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16WARRANTY; without even the implied warranty of MERCHANTABILITY or
17FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18for more details.
19
20You should have received a copy of the GNU General Public License
21along with GCC; see the file COPYING. If not, write to the Free
22Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2302111-1307, USA. */
24
25/* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
30
31/* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
35 information. */
36
37#include "config.h"
38#include "system.h"
39#include "coretypes.h"
40#include "tm.h"
41#include "tree.h"
42#include "flags.h"
43#include "real.h"
44#include "rtl.h"
45#include "hard-reg-set.h"
46#include "regs.h"
47#include "insn-config.h"
48#include "reload.h"
49#include "function.h"
50#include "output.h"
51#include "expr.h"
52#include "libfuncs.h"
53#include "except.h"
54#include "dwarf2.h"
55#include "dwarf2out.h"
56#include "dwarf2asm.h"
57#include "toplev.h"
58#include "varray.h"
59#include "ggc.h"
60#include "md5.h"
61#include "tm_p.h"
62#include "diagnostic.h"
63#include "debug.h"
64#include "target.h"
65#include "langhooks.h"
66#include "hashtab.h"
67#include "cgraph.h"
68
69#ifdef DWARF2_DEBUGGING_INFO
70static void dwarf2out_source_line (unsigned int, const char *);
71#endif
72
73/* DWARF2 Abbreviation Glossary:
74 CFA = Canonical Frame Address
75 a fixed address on the stack which identifies a call frame.
76 We define it to be the value of SP just before the call insn.
77 The CFA register and offset, which may change during the course
78 of the function, are used to calculate its value at runtime.
79 CFI = Call Frame Instruction
80 an instruction for the DWARF2 abstract machine
81 CIE = Common Information Entry
82 information describing information common to one or more FDEs
83 DIE = Debugging Information Entry
84 FDE = Frame Description Entry
85 information describing the stack call frame, in particular,
86 how to restore registers
87
88 DW_CFA_... = DWARF2 CFA call frame instruction
89 DW_TAG_... = DWARF2 DIE tag */
90
91/* Decide whether we want to emit frame unwind information for the current
92 translation unit. */
93
94int
95dwarf2out_do_frame (void)
96{
97 return (write_symbols == DWARF2_DEBUG
98 || write_symbols == VMS_AND_DWARF2_DEBUG
99#ifdef DWARF2_FRAME_INFO
100 || DWARF2_FRAME_INFO
101#endif
102#ifdef DWARF2_UNWIND_INFO
103 || flag_unwind_tables
104 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
105#endif
106 );
107}
108
109/* The size of the target's pointer type. */
110#ifndef PTR_SIZE
111#define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
112#endif
113
114/* Various versions of targetm.eh_frame_section. Note these must appear
115 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro guards. */
116
117/* Version of targetm.eh_frame_section for systems with named sections. */
118void
119named_section_eh_frame_section (void)
120{
121#ifdef EH_FRAME_SECTION_NAME
122#ifdef HAVE_LD_RO_RW_SECTION_MIXING
123 int fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
124 int per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
125 int lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
126 int flags;
127
128 flags = (! flag_pic
129 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
130 && (fde_encoding & 0x70) != DW_EH_PE_aligned
131 && (per_encoding & 0x70) != DW_EH_PE_absptr
132 && (per_encoding & 0x70) != DW_EH_PE_aligned
133 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
134 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
135 ? 0 : SECTION_WRITE;
136 named_section_flags (EH_FRAME_SECTION_NAME, flags);
137#else
138 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
139#endif
140#endif
141}
142
143/* Version of targetm.eh_frame_section for systems using collect2. */
144void
145collect2_eh_frame_section (void)
146{
147 tree label = get_file_function_name ('F');
148
149 data_section ();
150 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
151 (*targetm.asm_out.globalize_label) (asm_out_file, IDENTIFIER_POINTER (label));
152 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
153}
154
155/* Default version of targetm.eh_frame_section. */
156void
157default_eh_frame_section (void)
158{
159#ifdef EH_FRAME_SECTION_NAME
160 named_section_eh_frame_section ();
161#else
162 collect2_eh_frame_section ();
163#endif
164}
165
166/* Array of RTXes referenced by the debugging information, which therefore
167 must be kept around forever. */
168static GTY(()) varray_type used_rtx_varray;
169
170/* A pointer to the base of a list of incomplete types which might be
171 completed at some later time. incomplete_types_list needs to be a VARRAY
172 because we want to tell the garbage collector about it. */
173static GTY(()) varray_type incomplete_types;
174
175/* A pointer to the base of a table of references to declaration
176 scopes. This table is a display which tracks the nesting
177 of declaration scopes at the current scope and containing
178 scopes. This table is used to find the proper place to
179 define type declaration DIE's. */
180static GTY(()) varray_type decl_scope_table;
181
182/* How to start an assembler comment. */
183#ifndef ASM_COMMENT_START
184#define ASM_COMMENT_START ";#"
185#endif
186
187typedef struct dw_cfi_struct *dw_cfi_ref;
188typedef struct dw_fde_struct *dw_fde_ref;
189typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
190
191/* Call frames are described using a sequence of Call Frame
192 Information instructions. The register number, offset
193 and address fields are provided as possible operands;
194 their use is selected by the opcode field. */
195
196enum dw_cfi_oprnd_type {
197 dw_cfi_oprnd_unused,
198 dw_cfi_oprnd_reg_num,
199 dw_cfi_oprnd_offset,
200 dw_cfi_oprnd_addr,
201 dw_cfi_oprnd_loc
202};
203
204typedef union dw_cfi_oprnd_struct GTY(())
205{
206 unsigned long GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
207 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
208 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
209 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
210}
211dw_cfi_oprnd;
212
213typedef struct dw_cfi_struct GTY(())
214{
215 dw_cfi_ref dw_cfi_next;
216 enum dwarf_call_frame_info dw_cfi_opc;
217 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
218 dw_cfi_oprnd1;
219 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
220 dw_cfi_oprnd2;
221}
222dw_cfi_node;
223
224/* This is how we define the location of the CFA. We use to handle it
225 as REG + OFFSET all the time, but now it can be more complex.
226 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
227 Instead of passing around REG and OFFSET, we pass a copy
228 of this structure. */
229typedef struct cfa_loc GTY(())
230{
231 unsigned long reg;
232 HOST_WIDE_INT offset;
233 HOST_WIDE_INT base_offset;
234 int indirect; /* 1 if CFA is accessed via a dereference. */
235} dw_cfa_location;
236
237/* All call frame descriptions (FDE's) in the GCC generated DWARF
238 refer to a single Common Information Entry (CIE), defined at
239 the beginning of the .debug_frame section. This use of a single
240 CIE obviates the need to keep track of multiple CIE's
241 in the DWARF generation routines below. */
242
243typedef struct dw_fde_struct GTY(())
244{
245 const char *dw_fde_begin;
246 const char *dw_fde_current_label;
247 const char *dw_fde_end;
248 dw_cfi_ref dw_fde_cfi;
249 unsigned funcdef_number;
250 unsigned all_throwers_are_sibcalls : 1;
251 unsigned nothrow : 1;
252 unsigned uses_eh_lsda : 1;
253}
254dw_fde_node;
255
256/* Maximum size (in bytes) of an artificially generated label. */
257#define MAX_ARTIFICIAL_LABEL_BYTES 30
258
259/* The size of addresses as they appear in the Dwarf 2 data.
260 Some architectures use word addresses to refer to code locations,
261 but Dwarf 2 info always uses byte addresses. On such machines,
262 Dwarf 2 addresses need to be larger than the architecture's
263 pointers. */
264#ifndef DWARF2_ADDR_SIZE
265#define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
266#endif
267
268/* The size in bytes of a DWARF field indicating an offset or length
269 relative to a debug info section, specified to be 4 bytes in the
270 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
271 as PTR_SIZE. */
272
273#ifndef DWARF_OFFSET_SIZE
274#define DWARF_OFFSET_SIZE 4
275#endif
276
277/* According to the (draft) DWARF 3 specification, the initial length
278 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
279 bytes are 0xffffffff, followed by the length stored in the next 8
280 bytes.
281
282 However, the SGI/MIPS ABI uses an initial length which is equal to
283 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
284
285#ifndef DWARF_INITIAL_LENGTH_SIZE
286#define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
287#endif
288
289#define DWARF_VERSION 2
290
291/* Round SIZE up to the nearest BOUNDARY. */
292#define DWARF_ROUND(SIZE,BOUNDARY) \
293 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
294
295/* Offsets recorded in opcodes are a multiple of this alignment factor. */
296#ifndef DWARF_CIE_DATA_ALIGNMENT
297#ifdef STACK_GROWS_DOWNWARD
298#define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
299#else
300#define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
301#endif
302#endif
303
304/* A pointer to the base of a table that contains frame description
305 information for each routine. */
306static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
307
308/* Number of elements currently allocated for fde_table. */
309static GTY(()) unsigned fde_table_allocated;
310
311/* Number of elements in fde_table currently in use. */
312static GTY(()) unsigned fde_table_in_use;
313
314/* Size (in elements) of increments by which we may expand the
315 fde_table. */
316#define FDE_TABLE_INCREMENT 256
317
318/* A list of call frame insns for the CIE. */
319static GTY(()) dw_cfi_ref cie_cfi_head;
320
321#if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
322/* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
323 attribute that accelerates the lookup of the FDE associated
324 with the subprogram. This variable holds the table index of the FDE
325 associated with the current function (body) definition. */
326static unsigned current_funcdef_fde;
327#endif
328
329struct indirect_string_node GTY(())
330{
331 const char *str;
332 unsigned int refcount;
333 unsigned int form;
334 char *label;
335};
336
337static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
338
339static GTY(()) int dw2_string_counter;
340static GTY(()) unsigned long dwarf2out_cfi_label_num;
341
342#if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
343
344/* Forward declarations for functions defined in this file. */
345
346static char *stripattributes (const char *);
347static const char *dwarf_cfi_name (unsigned);
348static dw_cfi_ref new_cfi (void);
349static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
350static void add_fde_cfi (const char *, dw_cfi_ref);
351static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
352static void lookup_cfa (dw_cfa_location *);
353static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
354static void initial_return_save (rtx);
355static HOST_WIDE_INT stack_adjust_offset (rtx);
356static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
357static void output_call_frame_info (int);
358static void dwarf2out_stack_adjust (rtx);
359static void queue_reg_save (const char *, rtx, HOST_WIDE_INT);
360static void flush_queued_reg_saves (void);
361static bool clobbers_queued_reg_save (rtx);
362static void dwarf2out_frame_debug_expr (rtx, const char *);
363
364/* Support for complex CFA locations. */
365static void output_cfa_loc (dw_cfi_ref);
366static void get_cfa_from_loc_descr (dw_cfa_location *,
367 struct dw_loc_descr_struct *);
368static struct dw_loc_descr_struct *build_cfa_loc
369 (dw_cfa_location *);
370static void def_cfa_1 (const char *, dw_cfa_location *);
371
372/* How to start an assembler comment. */
373#ifndef ASM_COMMENT_START
374#define ASM_COMMENT_START ";#"
375#endif
376
377/* Data and reference forms for relocatable data. */
378#define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
379#define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
380
381#ifndef DEBUG_FRAME_SECTION
382#define DEBUG_FRAME_SECTION ".debug_frame"
383#endif
384
385#ifndef FUNC_BEGIN_LABEL
386#define FUNC_BEGIN_LABEL "LFB"
387#endif
388
389#ifndef FUNC_END_LABEL
390#define FUNC_END_LABEL "LFE"
391#endif
392
393#define FRAME_BEGIN_LABEL "Lframe"
394#define CIE_AFTER_SIZE_LABEL "LSCIE"
395#define CIE_END_LABEL "LECIE"
396#define FDE_LABEL "LSFDE"
397#define FDE_AFTER_SIZE_LABEL "LASFDE"
398#define FDE_END_LABEL "LEFDE"
399#define LINE_NUMBER_BEGIN_LABEL "LSLT"
400#define LINE_NUMBER_END_LABEL "LELT"
401#define LN_PROLOG_AS_LABEL "LASLTP"
402#define LN_PROLOG_END_LABEL "LELTP"
403#define DIE_LABEL_PREFIX "DW"
404
405/* The DWARF 2 CFA column which tracks the return address. Normally this
406 is the column for PC, or the first column after all of the hard
407 registers. */
408#ifndef DWARF_FRAME_RETURN_COLUMN
409#ifdef PC_REGNUM
410#define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
411#else
412#define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
413#endif
414#endif
415
416/* The mapping from gcc register number to DWARF 2 CFA column number. By
417 default, we just provide columns for all registers. */
418#ifndef DWARF_FRAME_REGNUM
419#define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
420#endif
421
422/* The offset from the incoming value of %sp to the top of the stack frame
423 for the current function. */
424#ifndef INCOMING_FRAME_SP_OFFSET
425#define INCOMING_FRAME_SP_OFFSET 0
426#endif
427\f
428/* Hook used by __throw. */
429
430rtx
431expand_builtin_dwarf_sp_column (void)
432{
433 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
434}
435
436/* Return a pointer to a copy of the section string name S with all
437 attributes stripped off, and an asterisk prepended (for assemble_name). */
438
439static inline char *
440stripattributes (const char *s)
441{
442 char *stripped = xmalloc (strlen (s) + 2);
443 char *p = stripped;
444
445 *p++ = '*';
446
447 while (*s && *s != ',')
448 *p++ = *s++;
449
450 *p = '\0';
451 return stripped;
452}
453
454/* Generate code to initialize the register size table. */
455
456void
457expand_builtin_init_dwarf_reg_sizes (tree address)
458{
459 int i;
460 enum machine_mode mode = TYPE_MODE (char_type_node);
461 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
462 rtx mem = gen_rtx_MEM (BLKmode, addr);
463 bool wrote_return_column = false;
464
465 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
466 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
467 {
468 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
469 enum machine_mode save_mode = reg_raw_mode[i];
470 HOST_WIDE_INT size;
471
472 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
473 save_mode = choose_hard_reg_mode (i, 1, true);
474 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
475 {
476 if (save_mode == VOIDmode)
477 continue;
478 wrote_return_column = true;
479 }
480 size = GET_MODE_SIZE (save_mode);
481 if (offset < 0)
482 continue;
483
484 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
485 }
486
487#ifdef DWARF_ALT_FRAME_RETURN_COLUMN
488 if (! wrote_return_column)
489 abort ();
490 i = DWARF_ALT_FRAME_RETURN_COLUMN;
491 wrote_return_column = false;
492#else
493 i = DWARF_FRAME_RETURN_COLUMN;
494#endif
495
496 if (! wrote_return_column)
497 {
498 enum machine_mode save_mode = Pmode;
499 HOST_WIDE_INT offset = i * GET_MODE_SIZE (mode);
500 HOST_WIDE_INT size = GET_MODE_SIZE (save_mode);
501 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
502 }
503}
504
505/* Convert a DWARF call frame info. operation to its string name */
506
507static const char *
508dwarf_cfi_name (unsigned int cfi_opc)
509{
510 switch (cfi_opc)
511 {
512 case DW_CFA_advance_loc:
513 return "DW_CFA_advance_loc";
514 case DW_CFA_offset:
515 return "DW_CFA_offset";
516 case DW_CFA_restore:
517 return "DW_CFA_restore";
518 case DW_CFA_nop:
519 return "DW_CFA_nop";
520 case DW_CFA_set_loc:
521 return "DW_CFA_set_loc";
522 case DW_CFA_advance_loc1:
523 return "DW_CFA_advance_loc1";
524 case DW_CFA_advance_loc2:
525 return "DW_CFA_advance_loc2";
526 case DW_CFA_advance_loc4:
527 return "DW_CFA_advance_loc4";
528 case DW_CFA_offset_extended:
529 return "DW_CFA_offset_extended";
530 case DW_CFA_restore_extended:
531 return "DW_CFA_restore_extended";
532 case DW_CFA_undefined:
533 return "DW_CFA_undefined";
534 case DW_CFA_same_value:
535 return "DW_CFA_same_value";
536 case DW_CFA_register:
537 return "DW_CFA_register";
538 case DW_CFA_remember_state:
539 return "DW_CFA_remember_state";
540 case DW_CFA_restore_state:
541 return "DW_CFA_restore_state";
542 case DW_CFA_def_cfa:
543 return "DW_CFA_def_cfa";
544 case DW_CFA_def_cfa_register:
545 return "DW_CFA_def_cfa_register";
546 case DW_CFA_def_cfa_offset:
547 return "DW_CFA_def_cfa_offset";
548
549 /* DWARF 3 */
550 case DW_CFA_def_cfa_expression:
551 return "DW_CFA_def_cfa_expression";
552 case DW_CFA_expression:
553 return "DW_CFA_expression";
554 case DW_CFA_offset_extended_sf:
555 return "DW_CFA_offset_extended_sf";
556 case DW_CFA_def_cfa_sf:
557 return "DW_CFA_def_cfa_sf";
558 case DW_CFA_def_cfa_offset_sf:
559 return "DW_CFA_def_cfa_offset_sf";
560
561 /* SGI/MIPS specific */
562 case DW_CFA_MIPS_advance_loc8:
563 return "DW_CFA_MIPS_advance_loc8";
564
565 /* GNU extensions */
566 case DW_CFA_GNU_window_save:
567 return "DW_CFA_GNU_window_save";
568 case DW_CFA_GNU_args_size:
569 return "DW_CFA_GNU_args_size";
570 case DW_CFA_GNU_negative_offset_extended:
571 return "DW_CFA_GNU_negative_offset_extended";
572
573 default:
574 return "DW_CFA_<unknown>";
575 }
576}
577
578/* Return a pointer to a newly allocated Call Frame Instruction. */
579
580static inline dw_cfi_ref
581new_cfi (void)
582{
583 dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node));
584
585 cfi->dw_cfi_next = NULL;
586 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
587 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
588
589 return cfi;
590}
591
592/* Add a Call Frame Instruction to list of instructions. */
593
594static inline void
595add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
596{
597 dw_cfi_ref *p;
598
599 /* Find the end of the chain. */
600 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
601 ;
602
603 *p = cfi;
604}
605
606/* Generate a new label for the CFI info to refer to. */
607
608char *
609dwarf2out_cfi_label (void)
610{
611 static char label[20];
612
613 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
614 ASM_OUTPUT_LABEL (asm_out_file, label);
615 return label;
616}
617
618/* Add CFI to the current fde at the PC value indicated by LABEL if specified,
619 or to the CIE if LABEL is NULL. */
620
621static void
622add_fde_cfi (const char *label, dw_cfi_ref cfi)
623{
624 if (label)
625 {
626 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
627
628 if (*label == 0)
629 label = dwarf2out_cfi_label ();
630
631 if (fde->dw_fde_current_label == NULL
632 || strcmp (label, fde->dw_fde_current_label) != 0)
633 {
634 dw_cfi_ref xcfi;
635
636 fde->dw_fde_current_label = label = xstrdup (label);
637
638 /* Set the location counter to the new label. */
639 xcfi = new_cfi ();
640 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
641 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
642 add_cfi (&fde->dw_fde_cfi, xcfi);
643 }
644
645 add_cfi (&fde->dw_fde_cfi, cfi);
646 }
647
648 else
649 add_cfi (&cie_cfi_head, cfi);
650}
651
652/* Subroutine of lookup_cfa. */
653
654static inline void
655lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
656{
657 switch (cfi->dw_cfi_opc)
658 {
659 case DW_CFA_def_cfa_offset:
660 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
661 break;
662 case DW_CFA_def_cfa_register:
663 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
664 break;
665 case DW_CFA_def_cfa:
666 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
667 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
668 break;
669 case DW_CFA_def_cfa_expression:
670 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
671 break;
672 default:
673 break;
674 }
675}
676
677/* Find the previous value for the CFA. */
678
679static void
680lookup_cfa (dw_cfa_location *loc)
681{
682 dw_cfi_ref cfi;
683
684 loc->reg = (unsigned long) -1;
685 loc->offset = 0;
686 loc->indirect = 0;
687 loc->base_offset = 0;
688
689 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
690 lookup_cfa_1 (cfi, loc);
691
692 if (fde_table_in_use)
693 {
694 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
695 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
696 lookup_cfa_1 (cfi, loc);
697 }
698}
699
700/* The current rule for calculating the DWARF2 canonical frame address. */
701static dw_cfa_location cfa;
702
703/* The register used for saving registers to the stack, and its offset
704 from the CFA. */
705static dw_cfa_location cfa_store;
706
707/* The running total of the size of arguments pushed onto the stack. */
708static HOST_WIDE_INT args_size;
709
710/* The last args_size we actually output. */
711static HOST_WIDE_INT old_args_size;
712
713/* Entry point to update the canonical frame address (CFA).
714 LABEL is passed to add_fde_cfi. The value of CFA is now to be
715 calculated from REG+OFFSET. */
716
717void
718dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
719{
720 dw_cfa_location loc;
721 loc.indirect = 0;
722 loc.base_offset = 0;
723 loc.reg = reg;
724 loc.offset = offset;
725 def_cfa_1 (label, &loc);
726}
727
728/* This routine does the actual work. The CFA is now calculated from
729 the dw_cfa_location structure. */
730
731static void
732def_cfa_1 (const char *label, dw_cfa_location *loc_p)
733{
734 dw_cfi_ref cfi;
735 dw_cfa_location old_cfa, loc;
736
737 cfa = *loc_p;
738 loc = *loc_p;
739
740 if (cfa_store.reg == loc.reg && loc.indirect == 0)
741 cfa_store.offset = loc.offset;
742
743 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
744 lookup_cfa (&old_cfa);
745
746 /* If nothing changed, no need to issue any call frame instructions. */
747 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
748 && loc.indirect == old_cfa.indirect
749 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
750 return;
751
752 cfi = new_cfi ();
753
754 if (loc.reg == old_cfa.reg && !loc.indirect)
755 {
756 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
757 indicating the CFA register did not change but the offset
758 did. */
759 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
760 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
761 }
762
763#ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
764 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
765 && !loc.indirect)
766 {
767 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
768 indicating the CFA register has changed to <register> but the
769 offset has not changed. */
770 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
771 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
772 }
773#endif
774
775 else if (loc.indirect == 0)
776 {
777 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
778 indicating the CFA register has changed to <register> with
779 the specified offset. */
780 cfi->dw_cfi_opc = DW_CFA_def_cfa;
781 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
782 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
783 }
784 else
785 {
786 /* Construct a DW_CFA_def_cfa_expression instruction to
787 calculate the CFA using a full location expression since no
788 register-offset pair is available. */
789 struct dw_loc_descr_struct *loc_list;
790
791 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
792 loc_list = build_cfa_loc (&loc);
793 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
794 }
795
796 add_fde_cfi (label, cfi);
797}
798
799/* Add the CFI for saving a register. REG is the CFA column number.
800 LABEL is passed to add_fde_cfi.
801 If SREG is -1, the register is saved at OFFSET from the CFA;
802 otherwise it is saved in SREG. */
803
804static void
805reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
806{
807 dw_cfi_ref cfi = new_cfi ();
808
809 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
810
811 /* The following comparison is correct. -1 is used to indicate that
812 the value isn't a register number. */
813 if (sreg == (unsigned int) -1)
814 {
815 if (reg & ~0x3f)
816 /* The register number won't fit in 6 bits, so we have to use
817 the long form. */
818 cfi->dw_cfi_opc = DW_CFA_offset_extended;
819 else
820 cfi->dw_cfi_opc = DW_CFA_offset;
821
822#ifdef ENABLE_CHECKING
823 {
824 /* If we get an offset that is not a multiple of
825 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
826 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
827 description. */
828 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
829
830 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
831 abort ();
832 }
833#endif
834 offset /= DWARF_CIE_DATA_ALIGNMENT;
835 if (offset < 0)
836 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
837
838 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
839 }
840 else if (sreg == reg)
841 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
842 return;
843 else
844 {
845 cfi->dw_cfi_opc = DW_CFA_register;
846 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
847 }
848
849 add_fde_cfi (label, cfi);
850}
851
852/* Add the CFI for saving a register window. LABEL is passed to reg_save.
853 This CFI tells the unwinder that it needs to restore the window registers
854 from the previous frame's window save area.
855
856 ??? Perhaps we should note in the CIE where windows are saved (instead of
857 assuming 0(cfa)) and what registers are in the window. */
858
859void
860dwarf2out_window_save (const char *label)
861{
862 dw_cfi_ref cfi = new_cfi ();
863
864 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
865 add_fde_cfi (label, cfi);
866}
867
868/* Add a CFI to update the running total of the size of arguments
869 pushed onto the stack. */
870
871void
872dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
873{
874 dw_cfi_ref cfi;
875
876 if (size == old_args_size)
877 return;
878
879 old_args_size = size;
880
881 cfi = new_cfi ();
882 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
883 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
884 add_fde_cfi (label, cfi);
885}
886
887/* Entry point for saving a register to the stack. REG is the GCC register
888 number. LABEL and OFFSET are passed to reg_save. */
889
890void
891dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
892{
893 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
894}
895
896/* Entry point for saving the return address in the stack.
897 LABEL and OFFSET are passed to reg_save. */
898
899void
900dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
901{
902 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
903}
904
905/* Entry point for saving the return address in a register.
906 LABEL and SREG are passed to reg_save. */
907
908void
909dwarf2out_return_reg (const char *label, unsigned int sreg)
910{
911 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
912}
913
914/* Record the initial position of the return address. RTL is
915 INCOMING_RETURN_ADDR_RTX. */
916
917static void
918initial_return_save (rtx rtl)
919{
920 unsigned int reg = (unsigned int) -1;
921 HOST_WIDE_INT offset = 0;
922
923 switch (GET_CODE (rtl))
924 {
925 case REG:
926 /* RA is in a register. */
927 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
928 break;
929
930 case MEM:
931 /* RA is on the stack. */
932 rtl = XEXP (rtl, 0);
933 switch (GET_CODE (rtl))
934 {
935 case REG:
936 if (REGNO (rtl) != STACK_POINTER_REGNUM)
937 abort ();
938 offset = 0;
939 break;
940
941 case PLUS:
942 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
943 abort ();
944 offset = INTVAL (XEXP (rtl, 1));
945 break;
946
947 case MINUS:
948 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
949 abort ();
950 offset = -INTVAL (XEXP (rtl, 1));
951 break;
952
953 default:
954 abort ();
955 }
956
957 break;
958
959 case PLUS:
960 /* The return address is at some offset from any value we can
961 actually load. For instance, on the SPARC it is in %i7+8. Just
962 ignore the offset for now; it doesn't matter for unwinding frames. */
963 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
964 abort ();
965 initial_return_save (XEXP (rtl, 0));
966 return;
967
968 default:
969 abort ();
970 }
971
972 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
973}
974
975/* Given a SET, calculate the amount of stack adjustment it
976 contains. */
977
978static HOST_WIDE_INT
979stack_adjust_offset (rtx pattern)
980{
981 rtx src = SET_SRC (pattern);
982 rtx dest = SET_DEST (pattern);
983 HOST_WIDE_INT offset = 0;
984 enum rtx_code code;
985
986 if (dest == stack_pointer_rtx)
987 {
988 /* (set (reg sp) (plus (reg sp) (const_int))) */
989 code = GET_CODE (src);
990 if (! (code == PLUS || code == MINUS)
991 || XEXP (src, 0) != stack_pointer_rtx
992 || GET_CODE (XEXP (src, 1)) != CONST_INT)
993 return 0;
994
995 offset = INTVAL (XEXP (src, 1));
996 if (code == PLUS)
997 offset = -offset;
998 }
999 else if (GET_CODE (dest) == MEM)
1000 {
1001 /* (set (mem (pre_dec (reg sp))) (foo)) */
1002 src = XEXP (dest, 0);
1003 code = GET_CODE (src);
1004
1005 switch (code)
1006 {
1007 case PRE_MODIFY:
1008 case POST_MODIFY:
1009 if (XEXP (src, 0) == stack_pointer_rtx)
1010 {
1011 rtx val = XEXP (XEXP (src, 1), 1);
1012 /* We handle only adjustments by constant amount. */
1013 if (GET_CODE (XEXP (src, 1)) != PLUS ||
1014 GET_CODE (val) != CONST_INT)
1015 abort ();
1016 offset = -INTVAL (val);
1017 break;
1018 }
1019 return 0;
1020
1021 case PRE_DEC:
1022 case POST_DEC:
1023 if (XEXP (src, 0) == stack_pointer_rtx)
1024 {
1025 offset = GET_MODE_SIZE (GET_MODE (dest));
1026 break;
1027 }
1028 return 0;
1029
1030 case PRE_INC:
1031 case POST_INC:
1032 if (XEXP (src, 0) == stack_pointer_rtx)
1033 {
1034 offset = -GET_MODE_SIZE (GET_MODE (dest));
1035 break;
1036 }
1037 return 0;
1038
1039 default:
1040 return 0;
1041 }
1042 }
1043 else
1044 return 0;
1045
1046 return offset;
1047}
1048
1049/* Check INSN to see if it looks like a push or a stack adjustment, and
1050 make a note of it if it does. EH uses this information to find out how
1051 much extra space it needs to pop off the stack. */
1052
1053static void
1054dwarf2out_stack_adjust (rtx insn)
1055{
1056 HOST_WIDE_INT offset;
1057 const char *label;
1058 int i;
1059
1060 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1061 with this function. Proper support would require all frame-related
1062 insns to be marked, and to be able to handle saving state around
1063 epilogues textually in the middle of the function. */
1064 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1065 return;
1066
1067 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1068 {
1069 /* Extract the size of the args from the CALL rtx itself. */
1070 insn = PATTERN (insn);
1071 if (GET_CODE (insn) == PARALLEL)
1072 insn = XVECEXP (insn, 0, 0);
1073 if (GET_CODE (insn) == SET)
1074 insn = SET_SRC (insn);
1075 if (GET_CODE (insn) != CALL)
1076 abort ();
1077
1078 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1079 return;
1080 }
1081
1082 /* If only calls can throw, and we have a frame pointer,
1083 save up adjustments until we see the CALL_INSN. */
1084 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1085 return;
1086
1087 if (GET_CODE (insn) == BARRIER)
1088 {
1089 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1090 the compiler will have already emitted a stack adjustment, but
1091 doesn't bother for calls to noreturn functions. */
1092#ifdef STACK_GROWS_DOWNWARD
1093 offset = -args_size;
1094#else
1095 offset = args_size;
1096#endif
1097 }
1098 else if (GET_CODE (PATTERN (insn)) == SET)
1099 offset = stack_adjust_offset (PATTERN (insn));
1100 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1101 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1102 {
1103 /* There may be stack adjustments inside compound insns. Search
1104 for them. */
1105 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1106 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1107 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1108 }
1109 else
1110 return;
1111
1112 if (offset == 0)
1113 return;
1114
1115 if (cfa.reg == STACK_POINTER_REGNUM)
1116 cfa.offset += offset;
1117
1118#ifndef STACK_GROWS_DOWNWARD
1119 offset = -offset;
1120#endif
1121
1122 args_size += offset;
1123 if (args_size < 0)
1124 args_size = 0;
1125
1126 label = dwarf2out_cfi_label ();
1127 def_cfa_1 (label, &cfa);
1128 dwarf2out_args_size (label, args_size);
1129}
1130
1131#endif
1132
1133/* We delay emitting a register save until either (a) we reach the end
1134 of the prologue or (b) the register is clobbered. This clusters
1135 register saves so that there are fewer pc advances. */
1136
1137struct queued_reg_save GTY(())
1138{
1139 struct queued_reg_save *next;
1140 rtx reg;
1141 HOST_WIDE_INT cfa_offset;
1142};
1143
1144static GTY(()) struct queued_reg_save *queued_reg_saves;
1145
1146#if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1147static const char *last_reg_save_label;
1148
1149static void
1150queue_reg_save (const char *label, rtx reg, HOST_WIDE_INT offset)
1151{
1152 struct queued_reg_save *q = ggc_alloc (sizeof (*q));
1153
1154 q->next = queued_reg_saves;
1155 q->reg = reg;
1156 q->cfa_offset = offset;
1157 queued_reg_saves = q;
1158
1159 last_reg_save_label = label;
1160}
1161
1162static void
1163flush_queued_reg_saves (void)
1164{
1165 struct queued_reg_save *q, *next;
1166
1167 for (q = queued_reg_saves; q; q = next)
1168 {
1169 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1170 next = q->next;
1171 }
1172
1173 queued_reg_saves = NULL;
1174 last_reg_save_label = NULL;
1175}
1176
1177static bool
1178clobbers_queued_reg_save (rtx insn)
1179{
1180 struct queued_reg_save *q;
1181
1182 for (q = queued_reg_saves; q; q = q->next)
1183 if (modified_in_p (q->reg, insn))
1184 return true;
1185
1186 return false;
1187}
1188
1189
1190/* A temporary register holding an integral value used in adjusting SP
1191 or setting up the store_reg. The "offset" field holds the integer
1192 value, not an offset. */
1193static dw_cfa_location cfa_temp;
1194
1195/* Record call frame debugging information for an expression EXPR,
1196 which either sets SP or FP (adjusting how we calculate the frame
1197 address) or saves a register to the stack. LABEL indicates the
1198 address of EXPR.
1199
1200 This function encodes a state machine mapping rtxes to actions on
1201 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1202 users need not read the source code.
1203
1204 The High-Level Picture
1205
1206 Changes in the register we use to calculate the CFA: Currently we
1207 assume that if you copy the CFA register into another register, we
1208 should take the other one as the new CFA register; this seems to
1209 work pretty well. If it's wrong for some target, it's simple
1210 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1211
1212 Changes in the register we use for saving registers to the stack:
1213 This is usually SP, but not always. Again, we deduce that if you
1214 copy SP into another register (and SP is not the CFA register),
1215 then the new register is the one we will be using for register
1216 saves. This also seems to work.
1217
1218 Register saves: There's not much guesswork about this one; if
1219 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1220 register save, and the register used to calculate the destination
1221 had better be the one we think we're using for this purpose.
1222
1223 Except: If the register being saved is the CFA register, and the
1224 offset is nonzero, we are saving the CFA, so we assume we have to
1225 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1226 the intent is to save the value of SP from the previous frame.
1227
1228 Invariants / Summaries of Rules
1229
1230 cfa current rule for calculating the CFA. It usually
1231 consists of a register and an offset.
1232 cfa_store register used by prologue code to save things to the stack
1233 cfa_store.offset is the offset from the value of
1234 cfa_store.reg to the actual CFA
1235 cfa_temp register holding an integral value. cfa_temp.offset
1236 stores the value, which will be used to adjust the
1237 stack pointer. cfa_temp is also used like cfa_store,
1238 to track stores to the stack via fp or a temp reg.
1239
1240 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1241 with cfa.reg as the first operand changes the cfa.reg and its
1242 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1243 cfa_temp.offset.
1244
1245 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1246 expression yielding a constant. This sets cfa_temp.reg
1247 and cfa_temp.offset.
1248
1249 Rule 5: Create a new register cfa_store used to save items to the
1250 stack.
1251
1252 Rules 10-14: Save a register to the stack. Define offset as the
1253 difference of the original location and cfa_store's
1254 location (or cfa_temp's location if cfa_temp is used).
1255
1256 The Rules
1257
1258 "{a,b}" indicates a choice of a xor b.
1259 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1260
1261 Rule 1:
1262 (set <reg1> <reg2>:cfa.reg)
1263 effects: cfa.reg = <reg1>
1264 cfa.offset unchanged
1265 cfa_temp.reg = <reg1>
1266 cfa_temp.offset = cfa.offset
1267
1268 Rule 2:
1269 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1270 {<const_int>,<reg>:cfa_temp.reg}))
1271 effects: cfa.reg = sp if fp used
1272 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1273 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1274 if cfa_store.reg==sp
1275
1276 Rule 3:
1277 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1278 effects: cfa.reg = fp
1279 cfa_offset += +/- <const_int>
1280
1281 Rule 4:
1282 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1283 constraints: <reg1> != fp
1284 <reg1> != sp
1285 effects: cfa.reg = <reg1>
1286 cfa_temp.reg = <reg1>
1287 cfa_temp.offset = cfa.offset
1288
1289 Rule 5:
1290 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1291 constraints: <reg1> != fp
1292 <reg1> != sp
1293 effects: cfa_store.reg = <reg1>
1294 cfa_store.offset = cfa.offset - cfa_temp.offset
1295
1296 Rule 6:
1297 (set <reg> <const_int>)
1298 effects: cfa_temp.reg = <reg>
1299 cfa_temp.offset = <const_int>
1300
1301 Rule 7:
1302 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1303 effects: cfa_temp.reg = <reg1>
1304 cfa_temp.offset |= <const_int>
1305
1306 Rule 8:
1307 (set <reg> (high <exp>))
1308 effects: none
1309
1310 Rule 9:
1311 (set <reg> (lo_sum <exp> <const_int>))
1312 effects: cfa_temp.reg = <reg>
1313 cfa_temp.offset = <const_int>
1314
1315 Rule 10:
1316 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1317 effects: cfa_store.offset -= <const_int>
1318 cfa.offset = cfa_store.offset if cfa.reg == sp
1319 cfa.reg = sp
1320 cfa.base_offset = -cfa_store.offset
1321
1322 Rule 11:
1323 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1324 effects: cfa_store.offset += -/+ mode_size(mem)
1325 cfa.offset = cfa_store.offset if cfa.reg == sp
1326 cfa.reg = sp
1327 cfa.base_offset = -cfa_store.offset
1328
1329 Rule 12:
1330 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1331
1332 <reg2>)
1333 effects: cfa.reg = <reg1>
1334 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1335
1336 Rule 13:
1337 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1338 effects: cfa.reg = <reg1>
1339 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1340
1341 Rule 14:
1342 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1343 effects: cfa.reg = <reg1>
1344 cfa.base_offset = -cfa_temp.offset
1345 cfa_temp.offset -= mode_size(mem) */
1346
1347static void
1348dwarf2out_frame_debug_expr (rtx expr, const char *label)
1349{
1350 rtx src, dest;
1351 HOST_WIDE_INT offset;
1352
1353 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1354 the PARALLEL independently. The first element is always processed if
1355 it is a SET. This is for backward compatibility. Other elements
1356 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1357 flag is set in them. */
1358 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1359 {
1360 int par_index;
1361 int limit = XVECLEN (expr, 0);
1362
1363 for (par_index = 0; par_index < limit; par_index++)
1364 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1365 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1366 || par_index == 0))
1367 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1368
1369 return;
1370 }
1371
1372 if (GET_CODE (expr) != SET)
1373 abort ();
1374
1375 src = SET_SRC (expr);
1376 dest = SET_DEST (expr);
1377
1378 switch (GET_CODE (dest))
1379 {
1380 case REG:
1381 /* Rule 1 */
1382 /* Update the CFA rule wrt SP or FP. Make sure src is
1383 relative to the current CFA register. */
1384 switch (GET_CODE (src))
1385 {
1386 /* Setting FP from SP. */
1387 case REG:
1388 if (cfa.reg == (unsigned) REGNO (src))
1389 /* OK. */
1390 ;
1391 else
1392 abort ();
1393
1394 /* We used to require that dest be either SP or FP, but the
1395 ARM copies SP to a temporary register, and from there to
1396 FP. So we just rely on the backends to only set
1397 RTX_FRAME_RELATED_P on appropriate insns. */
1398 cfa.reg = REGNO (dest);
1399 cfa_temp.reg = cfa.reg;
1400 cfa_temp.offset = cfa.offset;
1401 break;
1402
1403 case PLUS:
1404 case MINUS:
1405 case LO_SUM:
1406 if (dest == stack_pointer_rtx)
1407 {
1408 /* Rule 2 */
1409 /* Adjusting SP. */
1410 switch (GET_CODE (XEXP (src, 1)))
1411 {
1412 case CONST_INT:
1413 offset = INTVAL (XEXP (src, 1));
1414 break;
1415 case REG:
1416 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1417 abort ();
1418 offset = cfa_temp.offset;
1419 break;
1420 default:
1421 abort ();
1422 }
1423
1424 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1425 {
1426 /* Restoring SP from FP in the epilogue. */
1427 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1428 abort ();
1429 cfa.reg = STACK_POINTER_REGNUM;
1430 }
1431 else if (GET_CODE (src) == LO_SUM)
1432 /* Assume we've set the source reg of the LO_SUM from sp. */
1433 ;
1434 else if (XEXP (src, 0) != stack_pointer_rtx)
1435 abort ();
1436
1437 if (GET_CODE (src) != MINUS)
1438 offset = -offset;
1439 if (cfa.reg == STACK_POINTER_REGNUM)
1440 cfa.offset += offset;
1441 if (cfa_store.reg == STACK_POINTER_REGNUM)
1442 cfa_store.offset += offset;
1443 }
1444 else if (dest == hard_frame_pointer_rtx)
1445 {
1446 /* Rule 3 */
1447 /* Either setting the FP from an offset of the SP,
1448 or adjusting the FP */
1449 if (! frame_pointer_needed)
1450 abort ();
1451
1452 if (GET_CODE (XEXP (src, 0)) == REG
1453 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1454 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1455 {
1456 offset = INTVAL (XEXP (src, 1));
1457 if (GET_CODE (src) != MINUS)
1458 offset = -offset;
1459 cfa.offset += offset;
1460 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1461 }
1462 else
1463 abort ();
1464 }
1465 else
1466 {
1467 if (GET_CODE (src) == MINUS)
1468 abort ();
1469
1470 /* Rule 4 */
1471 if (GET_CODE (XEXP (src, 0)) == REG
1472 && REGNO (XEXP (src, 0)) == cfa.reg
1473 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1474 {
1475 /* Setting a temporary CFA register that will be copied
1476 into the FP later on. */
1477 offset = - INTVAL (XEXP (src, 1));
1478 cfa.offset += offset;
1479 cfa.reg = REGNO (dest);
1480 /* Or used to save regs to the stack. */
1481 cfa_temp.reg = cfa.reg;
1482 cfa_temp.offset = cfa.offset;
1483 }
1484
1485 /* Rule 5 */
1486 else if (GET_CODE (XEXP (src, 0)) == REG
1487 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1488 && XEXP (src, 1) == stack_pointer_rtx)
1489 {
1490 /* Setting a scratch register that we will use instead
1491 of SP for saving registers to the stack. */
1492 if (cfa.reg != STACK_POINTER_REGNUM)
1493 abort ();
1494 cfa_store.reg = REGNO (dest);
1495 cfa_store.offset = cfa.offset - cfa_temp.offset;
1496 }
1497
1498 /* Rule 9 */
1499 else if (GET_CODE (src) == LO_SUM
1500 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1501 {
1502 cfa_temp.reg = REGNO (dest);
1503 cfa_temp.offset = INTVAL (XEXP (src, 1));
1504 }
1505 else
1506 abort ();
1507 }
1508 break;
1509
1510 /* Rule 6 */
1511 case CONST_INT:
1512 cfa_temp.reg = REGNO (dest);
1513 cfa_temp.offset = INTVAL (src);
1514 break;
1515
1516 /* Rule 7 */
1517 case IOR:
1518 if (GET_CODE (XEXP (src, 0)) != REG
1519 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1520 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1521 abort ();
1522
1523 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1524 cfa_temp.reg = REGNO (dest);
1525 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1526 break;
1527
1528 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1529 which will fill in all of the bits. */
1530 /* Rule 8 */
1531 case HIGH:
1532 break;
1533
1534 default:
1535 abort ();
1536 }
1537
1538 def_cfa_1 (label, &cfa);
1539 break;
1540
1541 case MEM:
1542 if (GET_CODE (src) != REG)
1543 abort ();
1544
1545 /* Saving a register to the stack. Make sure dest is relative to the
1546 CFA register. */
1547 switch (GET_CODE (XEXP (dest, 0)))
1548 {
1549 /* Rule 10 */
1550 /* With a push. */
1551 case PRE_MODIFY:
1552 /* We can't handle variable size modifications. */
1553 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1554 abort ();
1555 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1556
1557 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1558 || cfa_store.reg != STACK_POINTER_REGNUM)
1559 abort ();
1560
1561 cfa_store.offset += offset;
1562 if (cfa.reg == STACK_POINTER_REGNUM)
1563 cfa.offset = cfa_store.offset;
1564
1565 offset = -cfa_store.offset;
1566 break;
1567
1568 /* Rule 11 */
1569 case PRE_INC:
1570 case PRE_DEC:
1571 offset = GET_MODE_SIZE (GET_MODE (dest));
1572 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1573 offset = -offset;
1574
1575 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1576 || cfa_store.reg != STACK_POINTER_REGNUM)
1577 abort ();
1578
1579 cfa_store.offset += offset;
1580 if (cfa.reg == STACK_POINTER_REGNUM)
1581 cfa.offset = cfa_store.offset;
1582
1583 offset = -cfa_store.offset;
1584 break;
1585
1586 /* Rule 12 */
1587 /* With an offset. */
1588 case PLUS:
1589 case MINUS:
1590 case LO_SUM:
1591 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1592 abort ();
1593 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1594 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1595 offset = -offset;
1596
1597 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1598 offset -= cfa_store.offset;
1599 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1600 offset -= cfa_temp.offset;
1601 else
1602 abort ();
1603 break;
1604
1605 /* Rule 13 */
1606 /* Without an offset. */
1607 case REG:
1608 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1609 offset = -cfa_store.offset;
1610 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1611 offset = -cfa_temp.offset;
1612 else
1613 abort ();
1614 break;
1615
1616 /* Rule 14 */
1617 case POST_INC:
1618 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1619 abort ();
1620 offset = -cfa_temp.offset;
1621 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1622 break;
1623
1624 default:
1625 abort ();
1626 }
1627
1628 if (REGNO (src) != STACK_POINTER_REGNUM
1629 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1630 && (unsigned) REGNO (src) == cfa.reg)
1631 {
1632 /* We're storing the current CFA reg into the stack. */
1633
1634 if (cfa.offset == 0)
1635 {
1636 /* If the source register is exactly the CFA, assume
1637 we're saving SP like any other register; this happens
1638 on the ARM. */
1639 def_cfa_1 (label, &cfa);
1640 queue_reg_save (label, stack_pointer_rtx, offset);
1641 break;
1642 }
1643 else
1644 {
1645 /* Otherwise, we'll need to look in the stack to
1646 calculate the CFA. */
1647 rtx x = XEXP (dest, 0);
1648
1649 if (GET_CODE (x) != REG)
1650 x = XEXP (x, 0);
1651 if (GET_CODE (x) != REG)
1652 abort ();
1653
1654 cfa.reg = REGNO (x);
1655 cfa.base_offset = offset;
1656 cfa.indirect = 1;
1657 def_cfa_1 (label, &cfa);
1658 break;
1659 }
1660 }
1661
1662 def_cfa_1 (label, &cfa);
1663 queue_reg_save (label, src, offset);
1664 break;
1665
1666 default:
1667 abort ();
1668 }
1669}
1670
1671/* Record call frame debugging information for INSN, which either
1672 sets SP or FP (adjusting how we calculate the frame address) or saves a
1673 register to the stack. If INSN is NULL_RTX, initialize our state. */
1674
1675void
1676dwarf2out_frame_debug (rtx insn)
1677{
1678 const char *label;
1679 rtx src;
1680
1681 if (insn == NULL_RTX)
1682 {
1683 /* Flush any queued register saves. */
1684 flush_queued_reg_saves ();
1685
1686 /* Set up state for generating call frame debug info. */
1687 lookup_cfa (&cfa);
1688 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1689 abort ();
1690
1691 cfa.reg = STACK_POINTER_REGNUM;
1692 cfa_store = cfa;
1693 cfa_temp.reg = -1;
1694 cfa_temp.offset = 0;
1695 return;
1696 }
1697
1698 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1699 flush_queued_reg_saves ();
1700
1701 if (! RTX_FRAME_RELATED_P (insn))
1702 {
1703 if (!ACCUMULATE_OUTGOING_ARGS)
1704 dwarf2out_stack_adjust (insn);
1705
1706 return;
1707 }
1708
1709 label = dwarf2out_cfi_label ();
1710 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1711 if (src)
1712 insn = XEXP (src, 0);
1713 else
1714 insn = PATTERN (insn);
1715
1716 dwarf2out_frame_debug_expr (insn, label);
1717}
1718
1719#endif
1720
1721/* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1722static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1723 (enum dwarf_call_frame_info cfi);
1724
1725static enum dw_cfi_oprnd_type
1726dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1727{
1728 switch (cfi)
1729 {
1730 case DW_CFA_nop:
1731 case DW_CFA_GNU_window_save:
1732 return dw_cfi_oprnd_unused;
1733
1734 case DW_CFA_set_loc:
1735 case DW_CFA_advance_loc1:
1736 case DW_CFA_advance_loc2:
1737 case DW_CFA_advance_loc4:
1738 case DW_CFA_MIPS_advance_loc8:
1739 return dw_cfi_oprnd_addr;
1740
1741 case DW_CFA_offset:
1742 case DW_CFA_offset_extended:
1743 case DW_CFA_def_cfa:
1744 case DW_CFA_offset_extended_sf:
1745 case DW_CFA_def_cfa_sf:
1746 case DW_CFA_restore_extended:
1747 case DW_CFA_undefined:
1748 case DW_CFA_same_value:
1749 case DW_CFA_def_cfa_register:
1750 case DW_CFA_register:
1751 return dw_cfi_oprnd_reg_num;
1752
1753 case DW_CFA_def_cfa_offset:
1754 case DW_CFA_GNU_args_size:
1755 case DW_CFA_def_cfa_offset_sf:
1756 return dw_cfi_oprnd_offset;
1757
1758 case DW_CFA_def_cfa_expression:
1759 case DW_CFA_expression:
1760 return dw_cfi_oprnd_loc;
1761
1762 default:
1763 abort ();
1764 }
1765}
1766
1767/* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1768static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1769 (enum dwarf_call_frame_info cfi);
1770
1771static enum dw_cfi_oprnd_type
1772dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1773{
1774 switch (cfi)
1775 {
1776 case DW_CFA_def_cfa:
1777 case DW_CFA_def_cfa_sf:
1778 case DW_CFA_offset:
1779 case DW_CFA_offset_extended_sf:
1780 case DW_CFA_offset_extended:
1781 return dw_cfi_oprnd_offset;
1782
1783 case DW_CFA_register:
1784 return dw_cfi_oprnd_reg_num;
1785
1786 default:
1787 return dw_cfi_oprnd_unused;
1788 }
1789}
1790
1791#if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1792
1793/* Map register numbers held in the call frame info that gcc has
1794 collected using DWARF_FRAME_REGNUM to those that should be output in
1795 .debug_frame and .eh_frame. */
1796#ifndef DWARF2_FRAME_REG_OUT
1797#define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
1798#endif
1799
1800/* Output a Call Frame Information opcode and its operand(s). */
1801
1802static void
1803output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
1804{
1805 unsigned long r;
1806 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1807 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1808 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1809 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
1810 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1811 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1812 {
1813 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1814 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
1815 "DW_CFA_offset, column 0x%lx", r);
1816 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1817 }
1818 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1819 {
1820 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1821 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
1822 "DW_CFA_restore, column 0x%lx", r);
1823 }
1824 else
1825 {
1826 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1827 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1828
1829 switch (cfi->dw_cfi_opc)
1830 {
1831 case DW_CFA_set_loc:
1832 if (for_eh)
1833 dw2_asm_output_encoded_addr_rtx (
1834 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1835 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1836 NULL);
1837 else
1838 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1839 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1840 break;
1841
1842 case DW_CFA_advance_loc1:
1843 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1844 fde->dw_fde_current_label, NULL);
1845 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1846 break;
1847
1848 case DW_CFA_advance_loc2:
1849 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1850 fde->dw_fde_current_label, NULL);
1851 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1852 break;
1853
1854 case DW_CFA_advance_loc4:
1855 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1856 fde->dw_fde_current_label, NULL);
1857 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1858 break;
1859
1860 case DW_CFA_MIPS_advance_loc8:
1861 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1862 fde->dw_fde_current_label, NULL);
1863 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1864 break;
1865
1866 case DW_CFA_offset_extended:
1867 case DW_CFA_def_cfa:
1868 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1869 dw2_asm_output_data_uleb128 (r, NULL);
1870 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1871 break;
1872
1873 case DW_CFA_offset_extended_sf:
1874 case DW_CFA_def_cfa_sf:
1875 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1876 dw2_asm_output_data_uleb128 (r, NULL);
1877 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1878 break;
1879
1880 case DW_CFA_restore_extended:
1881 case DW_CFA_undefined:
1882 case DW_CFA_same_value:
1883 case DW_CFA_def_cfa_register:
1884 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1885 dw2_asm_output_data_uleb128 (r, NULL);
1886 break;
1887
1888 case DW_CFA_register:
1889 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1890 dw2_asm_output_data_uleb128 (r, NULL);
1891 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
1892 dw2_asm_output_data_uleb128 (r, NULL);
1893 break;
1894
1895 case DW_CFA_def_cfa_offset:
1896 case DW_CFA_GNU_args_size:
1897 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1898 break;
1899
1900 case DW_CFA_def_cfa_offset_sf:
1901 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1902 break;
1903
1904 case DW_CFA_GNU_window_save:
1905 break;
1906
1907 case DW_CFA_def_cfa_expression:
1908 case DW_CFA_expression:
1909 output_cfa_loc (cfi);
1910 break;
1911
1912 case DW_CFA_GNU_negative_offset_extended:
1913 /* Obsoleted by DW_CFA_offset_extended_sf. */
1914 abort ();
1915
1916 default:
1917 break;
1918 }
1919 }
1920}
1921
1922/* Output the call frame information used to record information
1923 that relates to calculating the frame pointer, and records the
1924 location of saved registers. */
1925
1926static void
1927output_call_frame_info (int for_eh)
1928{
1929 unsigned int i;
1930 dw_fde_ref fde;
1931 dw_cfi_ref cfi;
1932 char l1[20], l2[20], section_start_label[20];
1933 bool any_lsda_needed = false;
1934 char augmentation[6];
1935 int augmentation_size;
1936 int fde_encoding = DW_EH_PE_absptr;
1937 int per_encoding = DW_EH_PE_absptr;
1938 int lsda_encoding = DW_EH_PE_absptr;
1939
1940 /* Don't emit a CIE if there won't be any FDEs. */
1941 if (fde_table_in_use == 0)
1942 return;
1943
1944 /* If we don't have any functions we'll want to unwind out of, don't
1945 emit any EH unwind information. Note that if exceptions aren't
1946 enabled, we won't have collected nothrow information, and if we
1947 asked for asynchronous tables, we always want this info. */
1948 if (for_eh)
1949 {
1950 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
1951
1952 for (i = 0; i < fde_table_in_use; i++)
1953 if (fde_table[i].uses_eh_lsda)
1954 any_eh_needed = any_lsda_needed = true;
1955 else if (! fde_table[i].nothrow
1956 && ! fde_table[i].all_throwers_are_sibcalls)
1957 any_eh_needed = true;
1958
1959 if (! any_eh_needed)
1960 return;
1961 }
1962
1963 /* We're going to be generating comments, so turn on app. */
1964 if (flag_debug_asm)
1965 app_enable ();
1966
1967 if (for_eh)
1968 (*targetm.asm_out.eh_frame_section) ();
1969 else
1970 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1971
1972 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1973 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1974
1975 /* Output the CIE. */
1976 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1977 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1978 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1979 "Length of Common Information Entry");
1980 ASM_OUTPUT_LABEL (asm_out_file, l1);
1981
1982 /* Now that the CIE pointer is PC-relative for EH,
1983 use 0 to identify the CIE. */
1984 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1985 (for_eh ? 0 : DW_CIE_ID),
1986 "CIE Identifier Tag");
1987
1988 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1989
1990 augmentation[0] = 0;
1991 augmentation_size = 0;
1992 if (for_eh)
1993 {
1994 char *p;
1995
1996 /* Augmentation:
1997 z Indicates that a uleb128 is present to size the
1998 augmentation section.
1999 L Indicates the encoding (and thus presence) of
2000 an LSDA pointer in the FDE augmentation.
2001 R Indicates a non-default pointer encoding for
2002 FDE code pointers.
2003 P Indicates the presence of an encoding + language
2004 personality routine in the CIE augmentation. */
2005
2006 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2007 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2008 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2009
2010 p = augmentation + 1;
2011 if (eh_personality_libfunc)
2012 {
2013 *p++ = 'P';
2014 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2015 }
2016 if (any_lsda_needed)
2017 {
2018 *p++ = 'L';
2019 augmentation_size += 1;
2020 }
2021 if (fde_encoding != DW_EH_PE_absptr)
2022 {
2023 *p++ = 'R';
2024 augmentation_size += 1;
2025 }
2026 if (p > augmentation + 1)
2027 {
2028 augmentation[0] = 'z';
2029 *p = '\0';
2030 }
2031
2032 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2033 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2034 {
2035 int offset = ( 4 /* Length */
2036 + 4 /* CIE Id */
2037 + 1 /* CIE version */
2038 + strlen (augmentation) + 1 /* Augmentation */
2039 + size_of_uleb128 (1) /* Code alignment */
2040 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2041 + 1 /* RA column */
2042 + 1 /* Augmentation size */
2043 + 1 /* Personality encoding */ );
2044 int pad = -offset & (PTR_SIZE - 1);
2045
2046 augmentation_size += pad;
2047
2048 /* Augmentations should be small, so there's scarce need to
2049 iterate for a solution. Die if we exceed one uleb128 byte. */
2050 if (size_of_uleb128 (augmentation_size) != 1)
2051 abort ();
2052 }
2053 }
2054
2055 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2056 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2057 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2058 "CIE Data Alignment Factor");
2059 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
2060
2061 if (augmentation[0])
2062 {
2063 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2064 if (eh_personality_libfunc)
2065 {
2066 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2067 eh_data_format_name (per_encoding));
2068 dw2_asm_output_encoded_addr_rtx (per_encoding,
2069 eh_personality_libfunc, NULL);
2070 }
2071
2072 if (any_lsda_needed)
2073 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2074 eh_data_format_name (lsda_encoding));
2075
2076 if (fde_encoding != DW_EH_PE_absptr)
2077 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2078 eh_data_format_name (fde_encoding));
2079 }
2080
2081 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2082 output_cfi (cfi, NULL, for_eh);
2083
2084 /* Pad the CIE out to an address sized boundary. */
2085 ASM_OUTPUT_ALIGN (asm_out_file,
2086 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2087 ASM_OUTPUT_LABEL (asm_out_file, l2);
2088
2089 /* Loop through all of the FDE's. */
2090 for (i = 0; i < fde_table_in_use; i++)
2091 {
2092 fde = &fde_table[i];
2093
2094 /* Don't emit EH unwind info for leaf functions that don't need it. */
2095 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2096 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2097 && !fde->uses_eh_lsda)
2098 continue;
2099
2100 (*targetm.asm_out.internal_label) (asm_out_file, FDE_LABEL, for_eh + i * 2);
2101 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2102 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2103 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2104 "FDE Length");
2105 ASM_OUTPUT_LABEL (asm_out_file, l1);
2106
2107 if (for_eh)
2108 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2109 else
2110 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2111 "FDE CIE offset");
2112
2113 if (for_eh)
2114 {
2115 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2116 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
2117 "FDE initial location");
2118 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2119 fde->dw_fde_end, fde->dw_fde_begin,
2120 "FDE address range");
2121 }
2122 else
2123 {
2124 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2125 "FDE initial location");
2126 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2127 fde->dw_fde_end, fde->dw_fde_begin,
2128 "FDE address range");
2129 }
2130
2131 if (augmentation[0])
2132 {
2133 if (any_lsda_needed)
2134 {
2135 int size = size_of_encoded_value (lsda_encoding);
2136
2137 if (lsda_encoding == DW_EH_PE_aligned)
2138 {
2139 int offset = ( 4 /* Length */
2140 + 4 /* CIE offset */
2141 + 2 * size_of_encoded_value (fde_encoding)
2142 + 1 /* Augmentation size */ );
2143 int pad = -offset & (PTR_SIZE - 1);
2144
2145 size += pad;
2146 if (size_of_uleb128 (size) != 1)
2147 abort ();
2148 }
2149
2150 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2151
2152 if (fde->uses_eh_lsda)
2153 {
2154 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2155 fde->funcdef_number);
2156 dw2_asm_output_encoded_addr_rtx (
2157 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2158 "Language Specific Data Area");
2159 }
2160 else
2161 {
2162 if (lsda_encoding == DW_EH_PE_aligned)
2163 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2164 dw2_asm_output_data
2165 (size_of_encoded_value (lsda_encoding), 0,
2166 "Language Specific Data Area (none)");
2167 }
2168 }
2169 else
2170 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2171 }
2172
2173 /* Loop through the Call Frame Instructions associated with
2174 this FDE. */
2175 fde->dw_fde_current_label = fde->dw_fde_begin;
2176 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2177 output_cfi (cfi, fde, for_eh);
2178
2179 /* Pad the FDE out to an address sized boundary. */
2180 ASM_OUTPUT_ALIGN (asm_out_file,
2181 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2182 ASM_OUTPUT_LABEL (asm_out_file, l2);
2183 }
2184
2185 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2186 dw2_asm_output_data (4, 0, "End of Table");
2187#ifdef MIPS_DEBUGGING_INFO
2188 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2189 get a value of 0. Putting .align 0 after the label fixes it. */
2190 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2191#endif
2192
2193 /* Turn off app to make assembly quicker. */
2194 if (flag_debug_asm)
2195 app_disable ();
2196}
2197
2198/* Output a marker (i.e. a label) for the beginning of a function, before
2199 the prologue. */
2200
2201void
2202dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2203 const char *file ATTRIBUTE_UNUSED)
2204{
2205 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2206 dw_fde_ref fde;
2207
2208 current_function_func_begin_label = 0;
2209
2210#ifdef IA64_UNWIND_INFO
2211 /* ??? current_function_func_begin_label is also used by except.c
2212 for call-site information. We must emit this label if it might
2213 be used. */
2214 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2215 && ! dwarf2out_do_frame ())
2216 return;
2217#else
2218 if (! dwarf2out_do_frame ())
2219 return;
2220#endif
2221
2222 function_section (current_function_decl);
2223 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2224 current_function_funcdef_no);
2225 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2226 current_function_funcdef_no);
2227 current_function_func_begin_label = get_identifier (label);
2228
2229#ifdef IA64_UNWIND_INFO
2230 /* We can elide the fde allocation if we're not emitting debug info. */
2231 if (! dwarf2out_do_frame ())
2232 return;
2233#endif
2234
2235 /* Expand the fde table if necessary. */
2236 if (fde_table_in_use == fde_table_allocated)
2237 {
2238 fde_table_allocated += FDE_TABLE_INCREMENT;
2239 fde_table = ggc_realloc (fde_table,
2240 fde_table_allocated * sizeof (dw_fde_node));
2241 memset (fde_table + fde_table_in_use, 0,
2242 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2243 }
2244
2245 /* Record the FDE associated with this function. */
2246 current_funcdef_fde = fde_table_in_use;
2247
2248 /* Add the new FDE at the end of the fde_table. */
2249 fde = &fde_table[fde_table_in_use++];
2250 fde->dw_fde_begin = xstrdup (label);
2251 fde->dw_fde_current_label = NULL;
2252 fde->dw_fde_end = NULL;
2253 fde->dw_fde_cfi = NULL;
2254 fde->funcdef_number = current_function_funcdef_no;
2255 fde->nothrow = current_function_nothrow;
2256 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2257 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2258
2259 args_size = old_args_size = 0;
2260
2261 /* We only want to output line number information for the genuine dwarf2
2262 prologue case, not the eh frame case. */
2263#ifdef DWARF2_DEBUGGING_INFO
2264 if (file)
2265 dwarf2out_source_line (line, file);
2266#endif
2267}
2268
2269/* Output a marker (i.e. a label) for the absolute end of the generated code
2270 for a function definition. This gets called *after* the epilogue code has
2271 been generated. */
2272
2273void
2274dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2275 const char *file ATTRIBUTE_UNUSED)
2276{
2277 dw_fde_ref fde;
2278 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2279
2280 /* Output a label to mark the endpoint of the code generated for this
2281 function. */
2282 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2283 current_function_funcdef_no);
2284 ASM_OUTPUT_LABEL (asm_out_file, label);
2285 fde = &fde_table[fde_table_in_use - 1];
2286 fde->dw_fde_end = xstrdup (label);
2287}
2288
2289void
2290dwarf2out_frame_init (void)
2291{
2292 /* Allocate the initial hunk of the fde_table. */
2293 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2294 fde_table_allocated = FDE_TABLE_INCREMENT;
2295 fde_table_in_use = 0;
2296
2297 /* Generate the CFA instructions common to all FDE's. Do it now for the
2298 sake of lookup_cfa. */
2299
2300#ifdef DWARF2_UNWIND_INFO
2301 /* On entry, the Canonical Frame Address is at SP. */
2302 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2303 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2304#endif
2305}
2306
2307void
2308dwarf2out_frame_finish (void)
2309{
2310 /* Output call frame information. */
2311 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2312 output_call_frame_info (0);
2313
2314 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2315 output_call_frame_info (1);
2316}
2317#endif
2318\f
2319/* And now, the subset of the debugging information support code necessary
2320 for emitting location expressions. */
2321
2322/* We need some way to distinguish DW_OP_addr with a direct symbol
2323 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2324#define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2325
2326
2327typedef struct dw_val_struct *dw_val_ref;
2328typedef struct die_struct *dw_die_ref;
2329typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2330typedef struct dw_loc_list_struct *dw_loc_list_ref;
2331
2332/* Each DIE may have a series of attribute/value pairs. Values
2333 can take on several forms. The forms that are used in this
2334 implementation are listed below. */
2335
2336enum dw_val_class
2337{
2338 dw_val_class_addr,
2339 dw_val_class_offset,
2340 dw_val_class_loc,
2341 dw_val_class_loc_list,
2342 dw_val_class_range_list,
2343 dw_val_class_const,
2344 dw_val_class_unsigned_const,
2345 dw_val_class_long_long,
2346 dw_val_class_vec,
2347 dw_val_class_flag,
2348 dw_val_class_die_ref,
2349 dw_val_class_fde_ref,
2350 dw_val_class_lbl_id,
2351 dw_val_class_lbl_offset,
2352 dw_val_class_str
2353};
2354
2355/* Describe a double word constant value. */
2356/* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2357
2358typedef struct dw_long_long_struct GTY(())
2359{
2360 unsigned long hi;
2361 unsigned long low;
2362}
2363dw_long_long_const;
2364
2365/* Describe a floating point constant value, or a vector constant value. */
2366
2367typedef struct dw_vec_struct GTY(())
2368{
2369 unsigned char * GTY((length ("%h.length"))) array;
2370 unsigned length;
2371 unsigned elt_size;
2372}
2373dw_vec_const;
2374
2375/* The dw_val_node describes an attribute's value, as it is
2376 represented internally. */
2377
2378typedef struct dw_val_struct GTY(())
2379{
2380 enum dw_val_class val_class;
2381 union dw_val_struct_union
2382 {
2383 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2384 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2385 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2386 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2387 HOST_WIDE_INT GTY ((default (""))) val_int;
2388 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2389 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2390 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2391 struct dw_val_die_union
2392 {
2393 dw_die_ref die;
2394 int external;
2395 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2396 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2397 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2398 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2399 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2400 }
2401 GTY ((desc ("%1.val_class"))) v;
2402}
2403dw_val_node;
2404
2405/* Locations in memory are described using a sequence of stack machine
2406 operations. */
2407
2408typedef struct dw_loc_descr_struct GTY(())
2409{
2410 dw_loc_descr_ref dw_loc_next;
2411 enum dwarf_location_atom dw_loc_opc;
2412 dw_val_node dw_loc_oprnd1;
2413 dw_val_node dw_loc_oprnd2;
2414 int dw_loc_addr;
2415}
2416dw_loc_descr_node;
2417
2418/* Location lists are ranges + location descriptions for that range,
2419 so you can track variables that are in different places over
2420 their entire life. */
2421typedef struct dw_loc_list_struct GTY(())
2422{
2423 dw_loc_list_ref dw_loc_next;
2424 const char *begin; /* Label for begin address of range */
2425 const char *end; /* Label for end address of range */
2426 char *ll_symbol; /* Label for beginning of location list.
2427 Only on head of list */
2428 const char *section; /* Section this loclist is relative to */
2429 dw_loc_descr_ref expr;
2430} dw_loc_list_node;
2431
2432#if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2433
2434static const char *dwarf_stack_op_name (unsigned);
2435static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2436 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2437static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2438static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2439static unsigned long size_of_locs (dw_loc_descr_ref);
2440static void output_loc_operands (dw_loc_descr_ref);
2441static void output_loc_sequence (dw_loc_descr_ref);
2442
2443/* Convert a DWARF stack opcode into its string name. */
2444
2445static const char *
2446dwarf_stack_op_name (unsigned int op)
2447{
2448 switch (op)
2449 {
2450 case DW_OP_addr:
2451 case INTERNAL_DW_OP_tls_addr:
2452 return "DW_OP_addr";
2453 case DW_OP_deref:
2454 return "DW_OP_deref";
2455 case DW_OP_const1u:
2456 return "DW_OP_const1u";
2457 case DW_OP_const1s:
2458 return "DW_OP_const1s";
2459 case DW_OP_const2u:
2460 return "DW_OP_const2u";
2461 case DW_OP_const2s:
2462 return "DW_OP_const2s";
2463 case DW_OP_const4u:
2464 return "DW_OP_const4u";
2465 case DW_OP_const4s:
2466 return "DW_OP_const4s";
2467 case DW_OP_const8u:
2468 return "DW_OP_const8u";
2469 case DW_OP_const8s:
2470 return "DW_OP_const8s";
2471 case DW_OP_constu:
2472 return "DW_OP_constu";
2473 case DW_OP_consts:
2474 return "DW_OP_consts";
2475 case DW_OP_dup:
2476 return "DW_OP_dup";
2477 case DW_OP_drop:
2478 return "DW_OP_drop";
2479 case DW_OP_over:
2480 return "DW_OP_over";
2481 case DW_OP_pick:
2482 return "DW_OP_pick";
2483 case DW_OP_swap:
2484 return "DW_OP_swap";
2485 case DW_OP_rot:
2486 return "DW_OP_rot";
2487 case DW_OP_xderef:
2488 return "DW_OP_xderef";
2489 case DW_OP_abs:
2490 return "DW_OP_abs";
2491 case DW_OP_and:
2492 return "DW_OP_and";
2493 case DW_OP_div:
2494 return "DW_OP_div";
2495 case DW_OP_minus:
2496 return "DW_OP_minus";
2497 case DW_OP_mod:
2498 return "DW_OP_mod";
2499 case DW_OP_mul:
2500 return "DW_OP_mul";
2501 case DW_OP_neg:
2502 return "DW_OP_neg";
2503 case DW_OP_not:
2504 return "DW_OP_not";
2505 case DW_OP_or:
2506 return "DW_OP_or";
2507 case DW_OP_plus:
2508 return "DW_OP_plus";
2509 case DW_OP_plus_uconst:
2510 return "DW_OP_plus_uconst";
2511 case DW_OP_shl:
2512 return "DW_OP_shl";
2513 case DW_OP_shr:
2514 return "DW_OP_shr";
2515 case DW_OP_shra:
2516 return "DW_OP_shra";
2517 case DW_OP_xor:
2518 return "DW_OP_xor";
2519 case DW_OP_bra:
2520 return "DW_OP_bra";
2521 case DW_OP_eq:
2522 return "DW_OP_eq";
2523 case DW_OP_ge:
2524 return "DW_OP_ge";
2525 case DW_OP_gt:
2526 return "DW_OP_gt";
2527 case DW_OP_le:
2528 return "DW_OP_le";
2529 case DW_OP_lt:
2530 return "DW_OP_lt";
2531 case DW_OP_ne:
2532 return "DW_OP_ne";
2533 case DW_OP_skip:
2534 return "DW_OP_skip";
2535 case DW_OP_lit0:
2536 return "DW_OP_lit0";
2537 case DW_OP_lit1:
2538 return "DW_OP_lit1";
2539 case DW_OP_lit2:
2540 return "DW_OP_lit2";
2541 case DW_OP_lit3:
2542 return "DW_OP_lit3";
2543 case DW_OP_lit4:
2544 return "DW_OP_lit4";
2545 case DW_OP_lit5:
2546 return "DW_OP_lit5";
2547 case DW_OP_lit6:
2548 return "DW_OP_lit6";
2549 case DW_OP_lit7:
2550 return "DW_OP_lit7";
2551 case DW_OP_lit8:
2552 return "DW_OP_lit8";
2553 case DW_OP_lit9:
2554 return "DW_OP_lit9";
2555 case DW_OP_lit10:
2556 return "DW_OP_lit10";
2557 case DW_OP_lit11:
2558 return "DW_OP_lit11";
2559 case DW_OP_lit12:
2560 return "DW_OP_lit12";
2561 case DW_OP_lit13:
2562 return "DW_OP_lit13";
2563 case DW_OP_lit14:
2564 return "DW_OP_lit14";
2565 case DW_OP_lit15:
2566 return "DW_OP_lit15";
2567 case DW_OP_lit16:
2568 return "DW_OP_lit16";
2569 case DW_OP_lit17:
2570 return "DW_OP_lit17";
2571 case DW_OP_lit18:
2572 return "DW_OP_lit18";
2573 case DW_OP_lit19:
2574 return "DW_OP_lit19";
2575 case DW_OP_lit20:
2576 return "DW_OP_lit20";
2577 case DW_OP_lit21:
2578 return "DW_OP_lit21";
2579 case DW_OP_lit22:
2580 return "DW_OP_lit22";
2581 case DW_OP_lit23:
2582 return "DW_OP_lit23";
2583 case DW_OP_lit24:
2584 return "DW_OP_lit24";
2585 case DW_OP_lit25:
2586 return "DW_OP_lit25";
2587 case DW_OP_lit26:
2588 return "DW_OP_lit26";
2589 case DW_OP_lit27:
2590 return "DW_OP_lit27";
2591 case DW_OP_lit28:
2592 return "DW_OP_lit28";
2593 case DW_OP_lit29:
2594 return "DW_OP_lit29";
2595 case DW_OP_lit30:
2596 return "DW_OP_lit30";
2597 case DW_OP_lit31:
2598 return "DW_OP_lit31";
2599 case DW_OP_reg0:
2600 return "DW_OP_reg0";
2601 case DW_OP_reg1:
2602 return "DW_OP_reg1";
2603 case DW_OP_reg2:
2604 return "DW_OP_reg2";
2605 case DW_OP_reg3:
2606 return "DW_OP_reg3";
2607 case DW_OP_reg4:
2608 return "DW_OP_reg4";
2609 case DW_OP_reg5:
2610 return "DW_OP_reg5";
2611 case DW_OP_reg6:
2612 return "DW_OP_reg6";
2613 case DW_OP_reg7:
2614 return "DW_OP_reg7";
2615 case DW_OP_reg8:
2616 return "DW_OP_reg8";
2617 case DW_OP_reg9:
2618 return "DW_OP_reg9";
2619 case DW_OP_reg10:
2620 return "DW_OP_reg10";
2621 case DW_OP_reg11:
2622 return "DW_OP_reg11";
2623 case DW_OP_reg12:
2624 return "DW_OP_reg12";
2625 case DW_OP_reg13:
2626 return "DW_OP_reg13";
2627 case DW_OP_reg14:
2628 return "DW_OP_reg14";
2629 case DW_OP_reg15:
2630 return "DW_OP_reg15";
2631 case DW_OP_reg16:
2632 return "DW_OP_reg16";
2633 case DW_OP_reg17:
2634 return "DW_OP_reg17";
2635 case DW_OP_reg18:
2636 return "DW_OP_reg18";
2637 case DW_OP_reg19:
2638 return "DW_OP_reg19";
2639 case DW_OP_reg20:
2640 return "DW_OP_reg20";
2641 case DW_OP_reg21:
2642 return "DW_OP_reg21";
2643 case DW_OP_reg22:
2644 return "DW_OP_reg22";
2645 case DW_OP_reg23:
2646 return "DW_OP_reg23";
2647 case DW_OP_reg24:
2648 return "DW_OP_reg24";
2649 case DW_OP_reg25:
2650 return "DW_OP_reg25";
2651 case DW_OP_reg26:
2652 return "DW_OP_reg26";
2653 case DW_OP_reg27:
2654 return "DW_OP_reg27";
2655 case DW_OP_reg28:
2656 return "DW_OP_reg28";
2657 case DW_OP_reg29:
2658 return "DW_OP_reg29";
2659 case DW_OP_reg30:
2660 return "DW_OP_reg30";
2661 case DW_OP_reg31:
2662 return "DW_OP_reg31";
2663 case DW_OP_breg0:
2664 return "DW_OP_breg0";
2665 case DW_OP_breg1:
2666 return "DW_OP_breg1";
2667 case DW_OP_breg2:
2668 return "DW_OP_breg2";
2669 case DW_OP_breg3:
2670 return "DW_OP_breg3";
2671 case DW_OP_breg4:
2672 return "DW_OP_breg4";
2673 case DW_OP_breg5:
2674 return "DW_OP_breg5";
2675 case DW_OP_breg6:
2676 return "DW_OP_breg6";
2677 case DW_OP_breg7:
2678 return "DW_OP_breg7";
2679 case DW_OP_breg8:
2680 return "DW_OP_breg8";
2681 case DW_OP_breg9:
2682 return "DW_OP_breg9";
2683 case DW_OP_breg10:
2684 return "DW_OP_breg10";
2685 case DW_OP_breg11:
2686 return "DW_OP_breg11";
2687 case DW_OP_breg12:
2688 return "DW_OP_breg12";
2689 case DW_OP_breg13:
2690 return "DW_OP_breg13";
2691 case DW_OP_breg14:
2692 return "DW_OP_breg14";
2693 case DW_OP_breg15:
2694 return "DW_OP_breg15";
2695 case DW_OP_breg16:
2696 return "DW_OP_breg16";
2697 case DW_OP_breg17:
2698 return "DW_OP_breg17";
2699 case DW_OP_breg18:
2700 return "DW_OP_breg18";
2701 case DW_OP_breg19:
2702 return "DW_OP_breg19";
2703 case DW_OP_breg20:
2704 return "DW_OP_breg20";
2705 case DW_OP_breg21:
2706 return "DW_OP_breg21";
2707 case DW_OP_breg22:
2708 return "DW_OP_breg22";
2709 case DW_OP_breg23:
2710 return "DW_OP_breg23";
2711 case DW_OP_breg24:
2712 return "DW_OP_breg24";
2713 case DW_OP_breg25:
2714 return "DW_OP_breg25";
2715 case DW_OP_breg26:
2716 return "DW_OP_breg26";
2717 case DW_OP_breg27:
2718 return "DW_OP_breg27";
2719 case DW_OP_breg28:
2720 return "DW_OP_breg28";
2721 case DW_OP_breg29:
2722 return "DW_OP_breg29";
2723 case DW_OP_breg30:
2724 return "DW_OP_breg30";
2725 case DW_OP_breg31:
2726 return "DW_OP_breg31";
2727 case DW_OP_regx:
2728 return "DW_OP_regx";
2729 case DW_OP_fbreg:
2730 return "DW_OP_fbreg";
2731 case DW_OP_bregx:
2732 return "DW_OP_bregx";
2733 case DW_OP_piece:
2734 return "DW_OP_piece";
2735 case DW_OP_deref_size:
2736 return "DW_OP_deref_size";
2737 case DW_OP_xderef_size:
2738 return "DW_OP_xderef_size";
2739 case DW_OP_nop:
2740 return "DW_OP_nop";
2741 case DW_OP_push_object_address:
2742 return "DW_OP_push_object_address";
2743 case DW_OP_call2:
2744 return "DW_OP_call2";
2745 case DW_OP_call4:
2746 return "DW_OP_call4";
2747 case DW_OP_call_ref:
2748 return "DW_OP_call_ref";
2749 case DW_OP_GNU_push_tls_address:
2750 return "DW_OP_GNU_push_tls_address";
2751 default:
2752 return "OP_<unknown>";
2753 }
2754}
2755
2756/* Return a pointer to a newly allocated location description. Location
2757 descriptions are simple expression terms that can be strung
2758 together to form more complicated location (address) descriptions. */
2759
2760static inline dw_loc_descr_ref
2761new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
2762 unsigned HOST_WIDE_INT oprnd2)
2763{
2764 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
2765
2766 descr->dw_loc_opc = op;
2767 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2768 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2769 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2770 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2771
2772 return descr;
2773}
2774
2775
2776/* Add a location description term to a location description expression. */
2777
2778static inline void
2779add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
2780{
2781 dw_loc_descr_ref *d;
2782
2783 /* Find the end of the chain. */
2784 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2785 ;
2786
2787 *d = descr;
2788}
2789
2790/* Return the size of a location descriptor. */
2791
2792static unsigned long
2793size_of_loc_descr (dw_loc_descr_ref loc)
2794{
2795 unsigned long size = 1;
2796
2797 switch (loc->dw_loc_opc)
2798 {
2799 case DW_OP_addr:
2800 case INTERNAL_DW_OP_tls_addr:
2801 size += DWARF2_ADDR_SIZE;
2802 break;
2803 case DW_OP_const1u:
2804 case DW_OP_const1s:
2805 size += 1;
2806 break;
2807 case DW_OP_const2u:
2808 case DW_OP_const2s:
2809 size += 2;
2810 break;
2811 case DW_OP_const4u:
2812 case DW_OP_const4s:
2813 size += 4;
2814 break;
2815 case DW_OP_const8u:
2816 case DW_OP_const8s:
2817 size += 8;
2818 break;
2819 case DW_OP_constu:
2820 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2821 break;
2822 case DW_OP_consts:
2823 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2824 break;
2825 case DW_OP_pick:
2826 size += 1;
2827 break;
2828 case DW_OP_plus_uconst:
2829 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2830 break;
2831 case DW_OP_skip:
2832 case DW_OP_bra:
2833 size += 2;
2834 break;
2835 case DW_OP_breg0:
2836 case DW_OP_breg1:
2837 case DW_OP_breg2:
2838 case DW_OP_breg3:
2839 case DW_OP_breg4:
2840 case DW_OP_breg5:
2841 case DW_OP_breg6:
2842 case DW_OP_breg7:
2843 case DW_OP_breg8:
2844 case DW_OP_breg9:
2845 case DW_OP_breg10:
2846 case DW_OP_breg11:
2847 case DW_OP_breg12:
2848 case DW_OP_breg13:
2849 case DW_OP_breg14:
2850 case DW_OP_breg15:
2851 case DW_OP_breg16:
2852 case DW_OP_breg17:
2853 case DW_OP_breg18:
2854 case DW_OP_breg19:
2855 case DW_OP_breg20:
2856 case DW_OP_breg21:
2857 case DW_OP_breg22:
2858 case DW_OP_breg23:
2859 case DW_OP_breg24:
2860 case DW_OP_breg25:
2861 case DW_OP_breg26:
2862 case DW_OP_breg27:
2863 case DW_OP_breg28:
2864 case DW_OP_breg29:
2865 case DW_OP_breg30:
2866 case DW_OP_breg31:
2867 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2868 break;
2869 case DW_OP_regx:
2870 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2871 break;
2872 case DW_OP_fbreg:
2873 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2874 break;
2875 case DW_OP_bregx:
2876 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2877 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2878 break;
2879 case DW_OP_piece:
2880 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2881 break;
2882 case DW_OP_deref_size:
2883 case DW_OP_xderef_size:
2884 size += 1;
2885 break;
2886 case DW_OP_call2:
2887 size += 2;
2888 break;
2889 case DW_OP_call4:
2890 size += 4;
2891 break;
2892 case DW_OP_call_ref:
2893 size += DWARF2_ADDR_SIZE;
2894 break;
2895 default:
2896 break;
2897 }
2898
2899 return size;
2900}
2901
2902/* Return the size of a series of location descriptors. */
2903
2904static unsigned long
2905size_of_locs (dw_loc_descr_ref loc)
2906{
2907 unsigned long size;
2908
2909 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2910 {
2911 loc->dw_loc_addr = size;
2912 size += size_of_loc_descr (loc);
2913 }
2914
2915 return size;
2916}
2917
2918/* Output location description stack opcode's operands (if any). */
2919
2920static void
2921output_loc_operands (dw_loc_descr_ref loc)
2922{
2923 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2924 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2925
2926 switch (loc->dw_loc_opc)
2927 {
2928#ifdef DWARF2_DEBUGGING_INFO
2929 case DW_OP_addr:
2930 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2931 break;
2932 case DW_OP_const2u:
2933 case DW_OP_const2s:
2934 dw2_asm_output_data (2, val1->v.val_int, NULL);
2935 break;
2936 case DW_OP_const4u:
2937 case DW_OP_const4s:
2938 dw2_asm_output_data (4, val1->v.val_int, NULL);
2939 break;
2940 case DW_OP_const8u:
2941 case DW_OP_const8s:
2942 if (HOST_BITS_PER_LONG < 64)
2943 abort ();
2944 dw2_asm_output_data (8, val1->v.val_int, NULL);
2945 break;
2946 case DW_OP_skip:
2947 case DW_OP_bra:
2948 {
2949 int offset;
2950
2951 if (val1->val_class == dw_val_class_loc)
2952 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2953 else
2954 abort ();
2955
2956 dw2_asm_output_data (2, offset, NULL);
2957 }
2958 break;
2959#else
2960 case DW_OP_addr:
2961 case DW_OP_const2u:
2962 case DW_OP_const2s:
2963 case DW_OP_const4u:
2964 case DW_OP_const4s:
2965 case DW_OP_const8u:
2966 case DW_OP_const8s:
2967 case DW_OP_skip:
2968 case DW_OP_bra:
2969 /* We currently don't make any attempt to make sure these are
2970 aligned properly like we do for the main unwind info, so
2971 don't support emitting things larger than a byte if we're
2972 only doing unwinding. */
2973 abort ();
2974#endif
2975 case DW_OP_const1u:
2976 case DW_OP_const1s:
2977 dw2_asm_output_data (1, val1->v.val_int, NULL);
2978 break;
2979 case DW_OP_constu:
2980 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2981 break;
2982 case DW_OP_consts:
2983 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2984 break;
2985 case DW_OP_pick:
2986 dw2_asm_output_data (1, val1->v.val_int, NULL);
2987 break;
2988 case DW_OP_plus_uconst:
2989 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2990 break;
2991 case DW_OP_breg0:
2992 case DW_OP_breg1:
2993 case DW_OP_breg2:
2994 case DW_OP_breg3:
2995 case DW_OP_breg4:
2996 case DW_OP_breg5:
2997 case DW_OP_breg6:
2998 case DW_OP_breg7:
2999 case DW_OP_breg8:
3000 case DW_OP_breg9:
3001 case DW_OP_breg10:
3002 case DW_OP_breg11:
3003 case DW_OP_breg12:
3004 case DW_OP_breg13:
3005 case DW_OP_breg14:
3006 case DW_OP_breg15:
3007 case DW_OP_breg16:
3008 case DW_OP_breg17:
3009 case DW_OP_breg18:
3010 case DW_OP_breg19:
3011 case DW_OP_breg20:
3012 case DW_OP_breg21:
3013 case DW_OP_breg22:
3014 case DW_OP_breg23:
3015 case DW_OP_breg24:
3016 case DW_OP_breg25:
3017 case DW_OP_breg26:
3018 case DW_OP_breg27:
3019 case DW_OP_breg28:
3020 case DW_OP_breg29:
3021 case DW_OP_breg30:
3022 case DW_OP_breg31:
3023 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3024 break;
3025 case DW_OP_regx:
3026 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3027 break;
3028 case DW_OP_fbreg:
3029 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3030 break;
3031 case DW_OP_bregx:
3032 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3033 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3034 break;
3035 case DW_OP_piece:
3036 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3037 break;
3038 case DW_OP_deref_size:
3039 case DW_OP_xderef_size:
3040 dw2_asm_output_data (1, val1->v.val_int, NULL);
3041 break;
3042
3043 case INTERNAL_DW_OP_tls_addr:
3044#ifdef ASM_OUTPUT_DWARF_DTPREL
3045 ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE,
3046 val1->v.val_addr);
3047 fputc ('\n', asm_out_file);
3048#else
3049 abort ();
3050#endif
3051 break;
3052
3053 default:
3054 /* Other codes have no operands. */
3055 break;
3056 }
3057}
3058
3059/* Output a sequence of location operations. */
3060
3061static void
3062output_loc_sequence (dw_loc_descr_ref loc)
3063{
3064 for (; loc != NULL; loc = loc->dw_loc_next)
3065 {
3066 /* Output the opcode. */
3067 dw2_asm_output_data (1, loc->dw_loc_opc,
3068 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3069
3070 /* Output the operand(s) (if any). */
3071 output_loc_operands (loc);
3072 }
3073}
3074
3075/* This routine will generate the correct assembly data for a location
3076 description based on a cfi entry with a complex address. */
3077
3078static void
3079output_cfa_loc (dw_cfi_ref cfi)
3080{
3081 dw_loc_descr_ref loc;
3082 unsigned long size;
3083
3084 /* Output the size of the block. */
3085 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3086 size = size_of_locs (loc);
3087 dw2_asm_output_data_uleb128 (size, NULL);
3088
3089 /* Now output the operations themselves. */
3090 output_loc_sequence (loc);
3091}
3092
3093/* This function builds a dwarf location descriptor sequence from
3094 a dw_cfa_location. */
3095
3096static struct dw_loc_descr_struct *
3097build_cfa_loc (dw_cfa_location *cfa)
3098{
3099 struct dw_loc_descr_struct *head, *tmp;
3100
3101 if (cfa->indirect == 0)
3102 abort ();
3103
3104 if (cfa->base_offset)
3105 {
3106 if (cfa->reg <= 31)
3107 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3108 else
3109 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3110 }
3111 else if (cfa->reg <= 31)
3112 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3113 else
3114 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3115
3116 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3117 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3118 add_loc_descr (&head, tmp);
3119 if (cfa->offset != 0)
3120 {
3121 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3122 add_loc_descr (&head, tmp);
3123 }
3124
3125 return head;
3126}
3127
3128/* This function fills in aa dw_cfa_location structure from a dwarf location
3129 descriptor sequence. */
3130
3131static void
3132get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3133{
3134 struct dw_loc_descr_struct *ptr;
3135 cfa->offset = 0;
3136 cfa->base_offset = 0;
3137 cfa->indirect = 0;
3138 cfa->reg = -1;
3139
3140 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3141 {
3142 enum dwarf_location_atom op = ptr->dw_loc_opc;
3143
3144 switch (op)
3145 {
3146 case DW_OP_reg0:
3147 case DW_OP_reg1:
3148 case DW_OP_reg2:
3149 case DW_OP_reg3:
3150 case DW_OP_reg4:
3151 case DW_OP_reg5:
3152 case DW_OP_reg6:
3153 case DW_OP_reg7:
3154 case DW_OP_reg8:
3155 case DW_OP_reg9:
3156 case DW_OP_reg10:
3157 case DW_OP_reg11:
3158 case DW_OP_reg12:
3159 case DW_OP_reg13:
3160 case DW_OP_reg14:
3161 case DW_OP_reg15:
3162 case DW_OP_reg16:
3163 case DW_OP_reg17:
3164 case DW_OP_reg18:
3165 case DW_OP_reg19:
3166 case DW_OP_reg20:
3167 case DW_OP_reg21:
3168 case DW_OP_reg22:
3169 case DW_OP_reg23:
3170 case DW_OP_reg24:
3171 case DW_OP_reg25:
3172 case DW_OP_reg26:
3173 case DW_OP_reg27:
3174 case DW_OP_reg28:
3175 case DW_OP_reg29:
3176 case DW_OP_reg30:
3177 case DW_OP_reg31:
3178 cfa->reg = op - DW_OP_reg0;
3179 break;
3180 case DW_OP_regx:
3181 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3182 break;
3183 case DW_OP_breg0:
3184 case DW_OP_breg1:
3185 case DW_OP_breg2:
3186 case DW_OP_breg3:
3187 case DW_OP_breg4:
3188 case DW_OP_breg5:
3189 case DW_OP_breg6:
3190 case DW_OP_breg7:
3191 case DW_OP_breg8:
3192 case DW_OP_breg9:
3193 case DW_OP_breg10:
3194 case DW_OP_breg11:
3195 case DW_OP_breg12:
3196 case DW_OP_breg13:
3197 case DW_OP_breg14:
3198 case DW_OP_breg15:
3199 case DW_OP_breg16:
3200 case DW_OP_breg17:
3201 case DW_OP_breg18:
3202 case DW_OP_breg19:
3203 case DW_OP_breg20:
3204 case DW_OP_breg21:
3205 case DW_OP_breg22:
3206 case DW_OP_breg23:
3207 case DW_OP_breg24:
3208 case DW_OP_breg25:
3209 case DW_OP_breg26:
3210 case DW_OP_breg27:
3211 case DW_OP_breg28:
3212 case DW_OP_breg29:
3213 case DW_OP_breg30:
3214 case DW_OP_breg31:
3215 cfa->reg = op - DW_OP_breg0;
3216 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3217 break;
3218 case DW_OP_bregx:
3219 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3220 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3221 break;
3222 case DW_OP_deref:
3223 cfa->indirect = 1;
3224 break;
3225 case DW_OP_plus_uconst:
3226 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3227 break;
3228 default:
3229 internal_error ("DW_LOC_OP %s not implemented\n",
3230 dwarf_stack_op_name (ptr->dw_loc_opc));
3231 }
3232 }
3233}
3234#endif /* .debug_frame support */
3235\f
3236/* And now, the support for symbolic debugging information. */
3237#ifdef DWARF2_DEBUGGING_INFO
3238
3239/* .debug_str support. */
3240static int output_indirect_string (void **, void *);
3241
3242static void dwarf2out_init (const char *);
3243static void dwarf2out_finish (const char *);
3244static void dwarf2out_define (unsigned int, const char *);
3245static void dwarf2out_undef (unsigned int, const char *);
3246static void dwarf2out_start_source_file (unsigned, const char *);
3247static void dwarf2out_end_source_file (unsigned);
3248static void dwarf2out_begin_block (unsigned, unsigned);
3249static void dwarf2out_end_block (unsigned, unsigned);
3250static bool dwarf2out_ignore_block (tree);
3251static void dwarf2out_global_decl (tree);
3252static void dwarf2out_abstract_function (tree);
3253
3254/* The debug hooks structure. */
3255
3256const struct gcc_debug_hooks dwarf2_debug_hooks =
3257{
3258 dwarf2out_init,
3259 dwarf2out_finish,
3260 dwarf2out_define,
3261 dwarf2out_undef,
3262 dwarf2out_start_source_file,
3263 dwarf2out_end_source_file,
3264 dwarf2out_begin_block,
3265 dwarf2out_end_block,
3266 dwarf2out_ignore_block,
3267 dwarf2out_source_line,
3268 dwarf2out_begin_prologue,
3269 debug_nothing_int_charstar, /* end_prologue */
3270 dwarf2out_end_epilogue,
3271 debug_nothing_tree, /* begin_function */
3272 debug_nothing_int, /* end_function */
3273 dwarf2out_decl, /* function_decl */
3274 dwarf2out_global_decl,
3275 debug_nothing_tree, /* deferred_inline_function */
3276 /* The DWARF 2 backend tries to reduce debugging bloat by not
3277 emitting the abstract description of inline functions until
3278 something tries to reference them. */
3279 dwarf2out_abstract_function, /* outlining_inline_function */
3280 debug_nothing_rtx, /* label */
3281 debug_nothing_int /* handle_pch */
3282};
3283#endif
3284\f
3285/* NOTE: In the comments in this file, many references are made to
3286 "Debugging Information Entries". This term is abbreviated as `DIE'
3287 throughout the remainder of this file. */
3288
3289/* An internal representation of the DWARF output is built, and then
3290 walked to generate the DWARF debugging info. The walk of the internal
3291 representation is done after the entire program has been compiled.
3292 The types below are used to describe the internal representation. */
3293
3294/* Various DIE's use offsets relative to the beginning of the
3295 .debug_info section to refer to each other. */
3296
3297typedef long int dw_offset;
3298
3299/* Define typedefs here to avoid circular dependencies. */
3300
3301typedef struct dw_attr_struct *dw_attr_ref;
3302typedef struct dw_line_info_struct *dw_line_info_ref;
3303typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3304typedef struct pubname_struct *pubname_ref;
3305typedef struct dw_ranges_struct *dw_ranges_ref;
3306
3307/* Each entry in the line_info_table maintains the file and
3308 line number associated with the label generated for that
3309 entry. The label gives the PC value associated with
3310 the line number entry. */
3311
3312typedef struct dw_line_info_struct GTY(())
3313{
3314 unsigned long dw_file_num;
3315 unsigned long dw_line_num;
3316}
3317dw_line_info_entry;
3318
3319/* Line information for functions in separate sections; each one gets its
3320 own sequence. */
3321typedef struct dw_separate_line_info_struct GTY(())
3322{
3323 unsigned long dw_file_num;
3324 unsigned long dw_line_num;
3325 unsigned long function;
3326}
3327dw_separate_line_info_entry;
3328
3329/* Each DIE attribute has a field specifying the attribute kind,
3330 a link to the next attribute in the chain, and an attribute value.
3331 Attributes are typically linked below the DIE they modify. */
3332
3333typedef struct dw_attr_struct GTY(())
3334{
3335 enum dwarf_attribute dw_attr;
3336 dw_attr_ref dw_attr_next;
3337 dw_val_node dw_attr_val;
3338}
3339dw_attr_node;
3340
3341/* The Debugging Information Entry (DIE) structure */
3342
3343typedef struct die_struct GTY(())
3344{
3345 enum dwarf_tag die_tag;
3346 char *die_symbol;
3347 dw_attr_ref die_attr;
3348 dw_die_ref die_parent;
3349 dw_die_ref die_child;
3350 dw_die_ref die_sib;
3351 dw_die_ref die_definition; /* ref from a specification to its definition */
3352 dw_offset die_offset;
3353 unsigned long die_abbrev;
3354 int die_mark;
3355}
3356die_node;
3357
3358/* The pubname structure */
3359
3360typedef struct pubname_struct GTY(())
3361{
3362 dw_die_ref die;
3363 char *name;
3364}
3365pubname_entry;
3366
3367struct dw_ranges_struct GTY(())
3368{
3369 int block_num;
3370};
3371
3372/* The limbo die list structure. */
3373typedef struct limbo_die_struct GTY(())
3374{
3375 dw_die_ref die;
3376 tree created_for;
3377 struct limbo_die_struct *next;
3378}
3379limbo_die_node;
3380
3381/* How to start an assembler comment. */
3382#ifndef ASM_COMMENT_START
3383#define ASM_COMMENT_START ";#"
3384#endif
3385
3386/* Define a macro which returns nonzero for a TYPE_DECL which was
3387 implicitly generated for a tagged type.
3388
3389 Note that unlike the gcc front end (which generates a NULL named
3390 TYPE_DECL node for each complete tagged type, each array type, and
3391 each function type node created) the g++ front end generates a
3392 _named_ TYPE_DECL node for each tagged type node created.
3393 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3394 generate a DW_TAG_typedef DIE for them. */
3395
3396#define TYPE_DECL_IS_STUB(decl) \
3397 (DECL_NAME (decl) == NULL_TREE \
3398 || (DECL_ARTIFICIAL (decl) \
3399 && is_tagged_type (TREE_TYPE (decl)) \
3400 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3401 /* This is necessary for stub decls that \
3402 appear in nested inline functions. */ \
3403 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3404 && (decl_ultimate_origin (decl) \
3405 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3406
3407/* Information concerning the compilation unit's programming
3408 language, and compiler version. */
3409
3410/* Fixed size portion of the DWARF compilation unit header. */
3411#define DWARF_COMPILE_UNIT_HEADER_SIZE \
3412 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3413
3414/* Fixed size portion of public names info. */
3415#define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3416
3417/* Fixed size portion of the address range info. */
3418#define DWARF_ARANGES_HEADER_SIZE \
3419 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3420 DWARF2_ADDR_SIZE * 2) \
3421 - DWARF_INITIAL_LENGTH_SIZE)
3422
3423/* Size of padding portion in the address range info. It must be
3424 aligned to twice the pointer size. */
3425#define DWARF_ARANGES_PAD_SIZE \
3426 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3427 DWARF2_ADDR_SIZE * 2) \
3428 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3429
3430/* Use assembler line directives if available. */
3431#ifndef DWARF2_ASM_LINE_DEBUG_INFO
3432#ifdef HAVE_AS_DWARF2_DEBUG_LINE
3433#define DWARF2_ASM_LINE_DEBUG_INFO 1
3434#else
3435#define DWARF2_ASM_LINE_DEBUG_INFO 0
3436#endif
3437#endif
3438
3439/* Minimum line offset in a special line info. opcode.
3440 This value was chosen to give a reasonable range of values. */
3441#define DWARF_LINE_BASE -10
3442
3443/* First special line opcode - leave room for the standard opcodes. */
3444#define DWARF_LINE_OPCODE_BASE 10
3445
3446/* Range of line offsets in a special line info. opcode. */
3447#define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3448
3449/* Flag that indicates the initial value of the is_stmt_start flag.
3450 In the present implementation, we do not mark any lines as
3451 the beginning of a source statement, because that information
3452 is not made available by the GCC front-end. */
3453#define DWARF_LINE_DEFAULT_IS_STMT_START 1
3454
3455#ifdef DWARF2_DEBUGGING_INFO
3456/* This location is used by calc_die_sizes() to keep track
3457 the offset of each DIE within the .debug_info section. */
3458static unsigned long next_die_offset;
3459#endif
3460
3461/* Record the root of the DIE's built for the current compilation unit. */
3462static GTY(()) dw_die_ref comp_unit_die;
3463
3464/* A list of DIEs with a NULL parent waiting to be relocated. */
3465static GTY(()) limbo_die_node *limbo_die_list;
3466
3467/* Filenames referenced by this compilation unit. */
3468static GTY(()) varray_type file_table;
3469static GTY(()) varray_type file_table_emitted;
3470static GTY(()) size_t file_table_last_lookup_index;
3471
3472/* A pointer to the base of a table of references to DIE's that describe
3473 declarations. The table is indexed by DECL_UID() which is a unique
3474 number identifying each decl. */
3475static GTY((length ("decl_die_table_allocated"))) dw_die_ref *decl_die_table;
3476
3477/* Number of elements currently allocated for the decl_die_table. */
3478static GTY(()) unsigned decl_die_table_allocated;
3479
3480/* Number of elements in decl_die_table currently in use. */
3481static GTY(()) unsigned decl_die_table_in_use;
3482
3483/* Size (in elements) of increments by which we may expand the
3484 decl_die_table. */
3485#define DECL_DIE_TABLE_INCREMENT 256
3486
3487/* A pointer to the base of a list of references to DIE's that
3488 are uniquely identified by their tag, presence/absence of
3489 children DIE's, and list of attribute/value pairs. */
3490static GTY((length ("abbrev_die_table_allocated")))
3491 dw_die_ref *abbrev_die_table;
3492
3493/* Number of elements currently allocated for abbrev_die_table. */
3494static GTY(()) unsigned abbrev_die_table_allocated;
3495
3496/* Number of elements in type_die_table currently in use. */
3497static GTY(()) unsigned abbrev_die_table_in_use;
3498
3499/* Size (in elements) of increments by which we may expand the
3500 abbrev_die_table. */
3501#define ABBREV_DIE_TABLE_INCREMENT 256
3502
3503/* A pointer to the base of a table that contains line information
3504 for each source code line in .text in the compilation unit. */
3505static GTY((length ("line_info_table_allocated")))
3506 dw_line_info_ref line_info_table;
3507
3508/* Number of elements currently allocated for line_info_table. */
3509static GTY(()) unsigned line_info_table_allocated;
3510
3511/* Number of elements in line_info_table currently in use. */
3512static GTY(()) unsigned line_info_table_in_use;
3513
3514/* A pointer to the base of a table that contains line information
3515 for each source code line outside of .text in the compilation unit. */
3516static GTY ((length ("separate_line_info_table_allocated")))
3517 dw_separate_line_info_ref separate_line_info_table;
3518
3519/* Number of elements currently allocated for separate_line_info_table. */
3520static GTY(()) unsigned separate_line_info_table_allocated;
3521
3522/* Number of elements in separate_line_info_table currently in use. */
3523static GTY(()) unsigned separate_line_info_table_in_use;
3524
3525/* Size (in elements) of increments by which we may expand the
3526 line_info_table. */
3527#define LINE_INFO_TABLE_INCREMENT 1024
3528
3529/* A pointer to the base of a table that contains a list of publicly
3530 accessible names. */
3531static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table;
3532
3533/* Number of elements currently allocated for pubname_table. */
3534static GTY(()) unsigned pubname_table_allocated;
3535
3536/* Number of elements in pubname_table currently in use. */
3537static GTY(()) unsigned pubname_table_in_use;
3538
3539/* Size (in elements) of increments by which we may expand the
3540 pubname_table. */
3541#define PUBNAME_TABLE_INCREMENT 64
3542
3543/* Array of dies for which we should generate .debug_arange info. */
3544static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
3545
3546/* Number of elements currently allocated for arange_table. */
3547static GTY(()) unsigned arange_table_allocated;
3548
3549/* Number of elements in arange_table currently in use. */
3550static GTY(()) unsigned arange_table_in_use;
3551
3552/* Size (in elements) of increments by which we may expand the
3553 arange_table. */
3554#define ARANGE_TABLE_INCREMENT 64
3555
3556/* Array of dies for which we should generate .debug_ranges info. */
3557static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3558
3559/* Number of elements currently allocated for ranges_table. */
3560static GTY(()) unsigned ranges_table_allocated;
3561
3562/* Number of elements in ranges_table currently in use. */
3563static GTY(()) unsigned ranges_table_in_use;
3564
3565/* Size (in elements) of increments by which we may expand the
3566 ranges_table. */
3567#define RANGES_TABLE_INCREMENT 64
3568
3569/* Whether we have location lists that need outputting */
3570static GTY(()) unsigned have_location_lists;
3571
3572#ifdef DWARF2_DEBUGGING_INFO
3573/* Record whether the function being analyzed contains inlined functions. */
3574static int current_function_has_inlines;
3575#endif
3576#if 0 && defined (MIPS_DEBUGGING_INFO)
3577static int comp_unit_has_inlines;
3578#endif
3579
3580/* Number of file tables emitted in maybe_emit_file(). */
3581static GTY(()) int emitcount = 0;
3582
3583/* Number of internal labels generated by gen_internal_sym(). */
3584static GTY(()) int label_num;
3585
3586#ifdef DWARF2_DEBUGGING_INFO
3587
3588/* Forward declarations for functions defined in this file. */
3589
3590static int is_pseudo_reg (rtx);
3591static tree type_main_variant (tree);
3592static int is_tagged_type (tree);
3593static const char *dwarf_tag_name (unsigned);
3594static const char *dwarf_attr_name (unsigned);
3595static const char *dwarf_form_name (unsigned);
3596#if 0
3597static const char *dwarf_type_encoding_name (unsigned);
3598#endif
3599static tree decl_ultimate_origin (tree);
3600static tree block_ultimate_origin (tree);
3601static tree decl_class_context (tree);
3602static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3603static inline enum dw_val_class AT_class (dw_attr_ref);
3604static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3605static inline unsigned AT_flag (dw_attr_ref);
3606static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3607static inline HOST_WIDE_INT AT_int (dw_attr_ref);
3608static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3609static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
3610static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
3611 unsigned long);
3612static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3613 unsigned int, unsigned char *);
3614static hashval_t debug_str_do_hash (const void *);
3615static int debug_str_eq (const void *, const void *);
3616static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3617static inline const char *AT_string (dw_attr_ref);
3618static int AT_string_form (dw_attr_ref);
3619static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3620static void add_AT_specification (dw_die_ref, dw_die_ref);
3621static inline dw_die_ref AT_ref (dw_attr_ref);
3622static inline int AT_ref_external (dw_attr_ref);
3623static inline void set_AT_ref_external (dw_attr_ref, int);
3624static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3625static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3626static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3627static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3628 dw_loc_list_ref);
3629static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3630static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3631static inline rtx AT_addr (dw_attr_ref);
3632static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3633static void add_AT_lbl_offset (dw_die_ref, enum dwarf_attribute, const char *);
3634static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3635 unsigned HOST_WIDE_INT);
3636static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3637 unsigned long);
3638static inline const char *AT_lbl (dw_attr_ref);
3639static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3640static const char *get_AT_low_pc (dw_die_ref);
3641static const char *get_AT_hi_pc (dw_die_ref);
3642static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3643static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3644static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3645static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3646static bool is_c_family (void);
3647static bool is_cxx (void);
3648static bool is_java (void);
3649static bool is_fortran (void);
3650static bool is_ada (void);
3651static void remove_AT (dw_die_ref, enum dwarf_attribute);
1c1138ce 3652static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
003757ed
MD
3653static inline void free_die (dw_die_ref);
3654static void remove_children (dw_die_ref);
3655static void add_child_die (dw_die_ref, dw_die_ref);
3656static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3657static dw_die_ref lookup_type_die (tree);
3658static void equate_type_number_to_die (tree, dw_die_ref);
3659static dw_die_ref lookup_decl_die (tree);
3660static void equate_decl_number_to_die (tree, dw_die_ref);
3661static void print_spaces (FILE *);
3662static void print_die (dw_die_ref, FILE *);
3663static void print_dwarf_line_table (FILE *);
3664static void reverse_die_lists (dw_die_ref);
3665static void reverse_all_dies (dw_die_ref);
3666static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3667static dw_die_ref pop_compile_unit (dw_die_ref);
3668static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3669static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3670static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3671static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3672static int same_dw_val_p (dw_val_node *, dw_val_node *, int *);
3673static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3674static int same_die_p (dw_die_ref, dw_die_ref, int *);
3675static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3676static void compute_section_prefix (dw_die_ref);
3677static int is_type_die (dw_die_ref);
3678static int is_comdat_die (dw_die_ref);
3679static int is_symbol_die (dw_die_ref);
3680static void assign_symbol_names (dw_die_ref);
3681static void break_out_includes (dw_die_ref);
3682static hashval_t htab_cu_hash (const void *);
3683static int htab_cu_eq (const void *, const void *);
3684static void htab_cu_del (void *);
3685static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3686static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3687static void add_sibling_attributes (dw_die_ref);
3688static void build_abbrev_table (dw_die_ref);
3689static void output_location_lists (dw_die_ref);
3690static int constant_size (long unsigned);
3691static unsigned long size_of_die (dw_die_ref);
3692static void calc_die_sizes (dw_die_ref);
3693static void mark_dies (dw_die_ref);
3694static void unmark_dies (dw_die_ref);
3695static void unmark_all_dies (dw_die_ref);
3696static unsigned long size_of_pubnames (void);
3697static unsigned long size_of_aranges (void);
3698static enum dwarf_form value_format (dw_attr_ref);
3699static void output_value_format (dw_attr_ref);
3700static void output_abbrev_section (void);
3701static void output_die_symbol (dw_die_ref);
3702static void output_die (dw_die_ref);
3703static void output_compilation_unit_header (void);
3704static void output_comp_unit (dw_die_ref, int);
3705static const char *dwarf2_name (tree, int);
3706static void add_pubname (tree, dw_die_ref);
3707static void output_pubnames (void);
3708static void add_arange (tree, dw_die_ref);
3709static void output_aranges (void);
3710static unsigned int add_ranges (tree);
3711static void output_ranges (void);
3712static void output_line_info (void);
3713static void output_file_names (void);
3714static dw_die_ref base_type_die (tree);
3715static tree root_type (tree);
3716static int is_base_type (tree);
3717static bool is_subrange_type (tree);
3718static dw_die_ref subrange_type_die (tree, dw_die_ref);
3719static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
3720static int type_is_enum (tree);
3721static unsigned int dbx_reg_number (rtx);
3722static dw_loc_descr_ref reg_loc_descriptor (rtx);
3723static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int);
3724static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx);
3725static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3726static dw_loc_descr_ref based_loc_descr (unsigned, HOST_WIDE_INT);
3727static int is_based_loc (rtx);
3728static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode);
3729static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx);
3730static dw_loc_descr_ref loc_descriptor (rtx);
3731static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
3732static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3733static tree field_type (tree);
3734static unsigned int simple_type_align_in_bits (tree);
3735static unsigned int simple_decl_align_in_bits (tree);
3736static unsigned HOST_WIDE_INT simple_type_size_in_bits (tree);
3737static HOST_WIDE_INT field_byte_offset (tree);
3738static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3739 dw_loc_descr_ref);
3740static void add_data_member_location_attribute (dw_die_ref, tree);
3741static void add_const_value_attribute (dw_die_ref, rtx);
3742static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3743static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
3744static void insert_float (rtx, unsigned char *);
3745static rtx rtl_for_decl_location (tree);
3746static void add_location_or_const_value_attribute (dw_die_ref, tree);
3747static void tree_add_const_value_attribute (dw_die_ref, tree);
3748static void add_name_attribute (dw_die_ref, const char *);
3749static void add_comp_dir_attribute (dw_die_ref);
3750static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
3751static void add_subscript_info (dw_die_ref, tree);
3752static void add_byte_size_attribute (dw_die_ref, tree);
3753static void add_bit_offset_attribute (dw_die_ref, tree);
3754static void add_bit_size_attribute (dw_die_ref, tree);
3755static void add_prototyped_attribute (dw_die_ref, tree);
3756static void add_abstract_origin_attribute (dw_die_ref, tree);
3757static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3758static void add_src_coords_attributes (dw_die_ref, tree);
3759static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3760static void push_decl_scope (tree);
3761static void pop_decl_scope (void);
3762static dw_die_ref scope_die_for (tree, dw_die_ref);
3763static inline int local_scope_p (dw_die_ref);
3764static inline int class_or_namespace_scope_p (dw_die_ref);
3765static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
3766static const char *type_tag (tree);
3767static tree member_declared_type (tree);
3768#if 0
3769static const char *decl_start_label (tree);
3770#endif
3771static void gen_array_type_die (tree, dw_die_ref);
3772static void gen_set_type_die (tree, dw_die_ref);
3773#if 0
3774static void gen_entry_point_die (tree, dw_die_ref);
3775#endif
3776static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
3777static void gen_inlined_structure_type_die (tree, dw_die_ref);
3778static void gen_inlined_union_type_die (tree, dw_die_ref);
3779static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
3780static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
3781static void gen_unspecified_parameters_die (tree, dw_die_ref);
3782static void gen_formal_types_die (tree, dw_die_ref);
3783static void gen_subprogram_die (tree, dw_die_ref);
3784static void gen_variable_die (tree, dw_die_ref);
3785static void gen_label_die (tree, dw_die_ref);
3786static void gen_lexical_block_die (tree, dw_die_ref, int);
3787static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
3788static void gen_field_die (tree, dw_die_ref);
3789static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3790static dw_die_ref gen_compile_unit_die (const char *);
3791static void gen_string_type_die (tree, dw_die_ref);
3792static void gen_inheritance_die (tree, tree, dw_die_ref);
3793static void gen_member_die (tree, dw_die_ref);
3794static void gen_struct_or_union_type_die (tree, dw_die_ref);
3795static void gen_subroutine_type_die (tree, dw_die_ref);
3796static void gen_typedef_die (tree, dw_die_ref);
3797static void gen_type_die (tree, dw_die_ref);
3798static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
3799static void gen_block_die (tree, dw_die_ref, int);
3800static void decls_for_scope (tree, dw_die_ref, int);
3801static int is_redundant_typedef (tree);
3802static void gen_namespace_die (tree);
3803static void gen_decl_die (tree, dw_die_ref);
3804static dw_die_ref force_namespace_die (tree);
3805static dw_die_ref setup_namespace_context (tree, dw_die_ref);
3806static void declare_in_namespace (tree, dw_die_ref);
3807static unsigned lookup_filename (const char *);
3808static void init_file_table (void);
3809static void retry_incomplete_types (void);
3810static void gen_type_die_for_member (tree, tree, dw_die_ref);
3811static void splice_child_die (dw_die_ref, dw_die_ref);
3812static int file_info_cmp (const void *, const void *);
3813static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
3814 const char *, const char *, unsigned);
3815static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
3816 const char *, const char *,
3817 const char *);
3818static void output_loc_list (dw_loc_list_ref);
3819static char *gen_internal_sym (const char *);
3820
3821static void prune_unmark_dies (dw_die_ref);
3822static void prune_unused_types_mark (dw_die_ref, int);
3823static void prune_unused_types_walk (dw_die_ref);
3824static void prune_unused_types_walk_attribs (dw_die_ref);
3825static void prune_unused_types_prune (dw_die_ref);
3826static void prune_unused_types (void);
3827static int maybe_emit_file (int);
3828
3829/* Section names used to hold DWARF debugging information. */
3830#ifndef DEBUG_INFO_SECTION
3831#define DEBUG_INFO_SECTION ".debug_info"
3832#endif
3833#ifndef DEBUG_ABBREV_SECTION
3834#define DEBUG_ABBREV_SECTION ".debug_abbrev"
3835#endif
3836#ifndef DEBUG_ARANGES_SECTION
3837#define DEBUG_ARANGES_SECTION ".debug_aranges"
3838#endif
3839#ifndef DEBUG_MACINFO_SECTION
3840#define DEBUG_MACINFO_SECTION ".debug_macinfo"
3841#endif
3842#ifndef DEBUG_LINE_SECTION
3843#define DEBUG_LINE_SECTION ".debug_line"
3844#endif