OSDN Git Service

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