Update gcc-50 to SVN version 222321 (gcc-5-branch)
[dragonfly.git] / contrib / gcc-5.0 / gcc / dwarf2out.c
CommitLineData
dda118e3
JM
1/* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2015 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
6
7This file is part of GCC.
8
9GCC is free software; you can redistribute it and/or modify it under
10the terms of the GNU General Public License as published by the Free
11Software Foundation; either version 3, or (at your option) any later
12version.
13
14GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17for more details.
18
19You should have received a copy of the GNU General Public License
20along with GCC; see the file COPYING3. If not see
21<http://www.gnu.org/licenses/>. */
22
23/* TODO: Emit .debug_line header even when there are no functions, since
24 the file numbers are used by .debug_info. Alternately, leave
25 out locations for types and decls.
26 Avoid talking about ctors and op= for PODs.
27 Factor out common prologue sequences into multiple CIEs. */
28
29/* The first part of this file deals with the DWARF 2 frame unwind
30 information, which is also used by the GCC efficient exception handling
31 mechanism. The second part, controlled only by an #ifdef
32 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
33 information. */
34
35/* DWARF2 Abbreviation Glossary:
36
37 CFA = Canonical Frame Address
38 a fixed address on the stack which identifies a call frame.
39 We define it to be the value of SP just before the call insn.
40 The CFA register and offset, which may change during the course
41 of the function, are used to calculate its value at runtime.
42
43 CFI = Call Frame Instruction
44 an instruction for the DWARF2 abstract machine
45
46 CIE = Common Information Entry
47 information describing information common to one or more FDEs
48
49 DIE = Debugging Information Entry
50
51 FDE = Frame Description Entry
52 information describing the stack call frame, in particular,
53 how to restore registers
54
55 DW_CFA_... = DWARF2 CFA call frame instruction
56 DW_TAG_... = DWARF2 DIE tag */
57
58#include "config.h"
59#include "system.h"
60#include "coretypes.h"
61#include "tm.h"
62#include "rtl.h"
63#include "hash-set.h"
64#include "machmode.h"
65#include "vec.h"
66#include "double-int.h"
67#include "input.h"
68#include "alias.h"
69#include "symtab.h"
70#include "wide-int.h"
71#include "inchash.h"
72#include "real.h"
73#include "tree.h"
74#include "fold-const.h"
75#include "stringpool.h"
76#include "stor-layout.h"
77#include "varasm.h"
78#include "hashtab.h"
79#include "hard-reg-set.h"
80#include "function.h"
81#include "emit-rtl.h"
82#include "hash-table.h"
83#include "version.h"
84#include "flags.h"
85#include "regs.h"
86#include "rtlhash.h"
87#include "insn-config.h"
88#include "reload.h"
89#include "output.h"
90#include "statistics.h"
91#include "fixed-value.h"
92#include "expmed.h"
93#include "dojump.h"
94#include "explow.h"
95#include "calls.h"
96#include "stmt.h"
97#include "expr.h"
98#include "except.h"
99#include "dwarf2.h"
100#include "dwarf2out.h"
101#include "dwarf2asm.h"
102#include "toplev.h"
103#include "md5.h"
104#include "tm_p.h"
105#include "diagnostic.h"
106#include "tree-pretty-print.h"
107#include "debug.h"
108#include "target.h"
109#include "common/common-target.h"
110#include "langhooks.h"
111#include "hash-map.h"
112#include "is-a.h"
113#include "plugin-api.h"
114#include "ipa-ref.h"
115#include "cgraph.h"
116#include "ira.h"
117#include "lra.h"
118#include "dumpfile.h"
119#include "opts.h"
120#include "tree-dfa.h"
121#include "gdb/gdb-index.h"
122#include "rtl-iter.h"
123
124static void dwarf2out_source_line (unsigned int, const char *, int, bool);
125static rtx_insn *last_var_location_insn;
126static rtx_insn *cached_next_real_insn;
127static void dwarf2out_decl (tree);
128
129#ifdef VMS_DEBUGGING_INFO
130int vms_file_stats_name (const char *, long long *, long *, char *, int *);
131
132/* Define this macro to be a nonzero value if the directory specifications
133 which are output in the debug info should end with a separator. */
134#define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
135/* Define this macro to evaluate to a nonzero value if GCC should refrain
136 from generating indirect strings in DWARF2 debug information, for instance
137 if your target is stuck with an old version of GDB that is unable to
138 process them properly or uses VMS Debug. */
139#define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
140#else
141#define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
142#define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
143#endif
144
145/* ??? Poison these here until it can be done generically. They've been
146 totally replaced in this file; make sure it stays that way. */
147#undef DWARF2_UNWIND_INFO
148#undef DWARF2_FRAME_INFO
149#if (GCC_VERSION >= 3000)
150 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
151#endif
152
153/* The size of the target's pointer type. */
154#ifndef PTR_SIZE
155#define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
156#endif
157
158/* Array of RTXes referenced by the debugging information, which therefore
159 must be kept around forever. */
160static GTY(()) vec<rtx, va_gc> *used_rtx_array;
161
162/* A pointer to the base of a list of incomplete types which might be
163 completed at some later time. incomplete_types_list needs to be a
164 vec<tree, va_gc> *because we want to tell the garbage collector about
165 it. */
166static GTY(()) vec<tree, va_gc> *incomplete_types;
167
168/* A pointer to the base of a table of references to declaration
169 scopes. This table is a display which tracks the nesting
170 of declaration scopes at the current scope and containing
171 scopes. This table is used to find the proper place to
172 define type declaration DIE's. */
173static GTY(()) vec<tree, va_gc> *decl_scope_table;
174
175/* Pointers to various DWARF2 sections. */
176static GTY(()) section *debug_info_section;
177static GTY(()) section *debug_skeleton_info_section;
178static GTY(()) section *debug_abbrev_section;
179static GTY(()) section *debug_skeleton_abbrev_section;
180static GTY(()) section *debug_aranges_section;
181static GTY(()) section *debug_addr_section;
182static GTY(()) section *debug_macinfo_section;
183static GTY(()) section *debug_line_section;
184static GTY(()) section *debug_skeleton_line_section;
185static GTY(()) section *debug_loc_section;
186static GTY(()) section *debug_pubnames_section;
187static GTY(()) section *debug_pubtypes_section;
188static GTY(()) section *debug_str_section;
189static GTY(()) section *debug_str_dwo_section;
190static GTY(()) section *debug_str_offsets_section;
191static GTY(()) section *debug_ranges_section;
192static GTY(()) section *debug_frame_section;
193
194/* Maximum size (in bytes) of an artificially generated label. */
195#define MAX_ARTIFICIAL_LABEL_BYTES 30
196
197/* According to the (draft) DWARF 3 specification, the initial length
198 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
199 bytes are 0xffffffff, followed by the length stored in the next 8
200 bytes.
201
202 However, the SGI/MIPS ABI uses an initial length which is equal to
203 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
204
205#ifndef DWARF_INITIAL_LENGTH_SIZE
206#define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
207#endif
208
209/* Round SIZE up to the nearest BOUNDARY. */
210#define DWARF_ROUND(SIZE,BOUNDARY) \
211 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
212
213/* CIE identifier. */
214#if HOST_BITS_PER_WIDE_INT >= 64
215#define DWARF_CIE_ID \
216 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
217#else
218#define DWARF_CIE_ID DW_CIE_ID
219#endif
220
221
222/* A vector for a table that contains frame description
223 information for each routine. */
224#define NOT_INDEXED (-1U)
225#define NO_INDEX_ASSIGNED (-2U)
226
227static GTY(()) vec<dw_fde_ref, va_gc> *fde_vec;
228
229struct GTY((for_user)) indirect_string_node {
230 const char *str;
231 unsigned int refcount;
232 enum dwarf_form form;
233 char *label;
234 unsigned int index;
235};
236
237struct indirect_string_hasher : ggc_hasher<indirect_string_node *>
238{
239 typedef const char *compare_type;
240
241 static hashval_t hash (indirect_string_node *);
242 static bool equal (indirect_string_node *, const char *);
243};
244
245static GTY (()) hash_table<indirect_string_hasher> *debug_str_hash;
246
247/* With split_debug_info, both the comp_dir and dwo_name go in the
248 main object file, rather than the dwo, similar to the force_direct
249 parameter elsewhere but with additional complications:
250
251 1) The string is needed in both the main object file and the dwo.
252 That is, the comp_dir and dwo_name will appear in both places.
253
254 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
255 DW_FORM_GNU_str_index.
256
257 3) GCC chooses the form to use late, depending on the size and
258 reference count.
259
260 Rather than forcing the all debug string handling functions and
261 callers to deal with these complications, simply use a separate,
262 special-cased string table for any attribute that should go in the
263 main object file. This limits the complexity to just the places
264 that need it. */
265
266static GTY (()) hash_table<indirect_string_hasher> *skeleton_debug_str_hash;
267
268static GTY(()) int dw2_string_counter;
269
270/* True if the compilation unit places functions in more than one section. */
271static GTY(()) bool have_multiple_function_sections = false;
272
273/* Whether the default text and cold text sections have been used at all. */
274
275static GTY(()) bool text_section_used = false;
276static GTY(()) bool cold_text_section_used = false;
277
278/* The default cold text section. */
279static GTY(()) section *cold_text_section;
280
281/* The DIE for C++14 'auto' in a function return type. */
282static GTY(()) dw_die_ref auto_die;
283
284/* The DIE for C++14 'decltype(auto)' in a function return type. */
285static GTY(()) dw_die_ref decltype_auto_die;
286
287/* Forward declarations for functions defined in this file. */
288
289static char *stripattributes (const char *);
290static void output_call_frame_info (int);
291static void dwarf2out_note_section_used (void);
292
293/* Personality decl of current unit. Used only when assembler does not support
294 personality CFI. */
295static GTY(()) rtx current_unit_personality;
296
297/* Data and reference forms for relocatable data. */
298#define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
299#define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
300
301#ifndef DEBUG_FRAME_SECTION
302#define DEBUG_FRAME_SECTION ".debug_frame"
303#endif
304
305#ifndef FUNC_BEGIN_LABEL
306#define FUNC_BEGIN_LABEL "LFB"
307#endif
308
309#ifndef FUNC_END_LABEL
310#define FUNC_END_LABEL "LFE"
311#endif
312
313#ifndef PROLOGUE_END_LABEL
314#define PROLOGUE_END_LABEL "LPE"
315#endif
316
317#ifndef EPILOGUE_BEGIN_LABEL
318#define EPILOGUE_BEGIN_LABEL "LEB"
319#endif
320
321#ifndef FRAME_BEGIN_LABEL
322#define FRAME_BEGIN_LABEL "Lframe"
323#endif
324#define CIE_AFTER_SIZE_LABEL "LSCIE"
325#define CIE_END_LABEL "LECIE"
326#define FDE_LABEL "LSFDE"
327#define FDE_AFTER_SIZE_LABEL "LASFDE"
328#define FDE_END_LABEL "LEFDE"
329#define LINE_NUMBER_BEGIN_LABEL "LSLT"
330#define LINE_NUMBER_END_LABEL "LELT"
331#define LN_PROLOG_AS_LABEL "LASLTP"
332#define LN_PROLOG_END_LABEL "LELTP"
333#define DIE_LABEL_PREFIX "DW"
334\f
335/* Match the base name of a file to the base name of a compilation unit. */
336
337static int
338matches_main_base (const char *path)
339{
340 /* Cache the last query. */
341 static const char *last_path = NULL;
342 static int last_match = 0;
343 if (path != last_path)
344 {
345 const char *base;
346 int length = base_of_path (path, &base);
347 last_path = path;
348 last_match = (length == main_input_baselength
349 && memcmp (base, main_input_basename, length) == 0);
350 }
351 return last_match;
352}
353
354#ifdef DEBUG_DEBUG_STRUCT
355
356static int
357dump_struct_debug (tree type, enum debug_info_usage usage,
358 enum debug_struct_file criterion, int generic,
359 int matches, int result)
360{
361 /* Find the type name. */
362 tree type_decl = TYPE_STUB_DECL (type);
363 tree t = type_decl;
364 const char *name = 0;
365 if (TREE_CODE (t) == TYPE_DECL)
366 t = DECL_NAME (t);
367 if (t)
368 name = IDENTIFIER_POINTER (t);
369
370 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
371 criterion,
372 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
373 matches ? "bas" : "hdr",
374 generic ? "gen" : "ord",
375 usage == DINFO_USAGE_DFN ? ";" :
376 usage == DINFO_USAGE_DIR_USE ? "." : "*",
377 result,
378 (void*) type_decl, name);
379 return result;
380}
381#define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
382 dump_struct_debug (type, usage, criterion, generic, matches, result)
383
384#else
385
386#define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
387 (result)
388
389#endif
390
391/* Get the number of HOST_WIDE_INTs needed to represent the precision
392 of the number. */
393
394static unsigned int
395get_full_len (const wide_int &op)
396{
397 return ((op.get_precision () + HOST_BITS_PER_WIDE_INT - 1)
398 / HOST_BITS_PER_WIDE_INT);
399}
400
401static bool
402should_emit_struct_debug (tree type, enum debug_info_usage usage)
403{
404 enum debug_struct_file criterion;
405 tree type_decl;
406 bool generic = lang_hooks.types.generic_p (type);
407
408 if (generic)
409 criterion = debug_struct_generic[usage];
410 else
411 criterion = debug_struct_ordinary[usage];
412
413 if (criterion == DINFO_STRUCT_FILE_NONE)
414 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
415 if (criterion == DINFO_STRUCT_FILE_ANY)
416 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
417
418 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
419
420 if (type_decl != NULL)
421 {
422 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
423 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
424
425 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
426 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
427 }
428
429 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
430}
431\f
432/* Return a pointer to a copy of the section string name S with all
433 attributes stripped off, and an asterisk prepended (for assemble_name). */
434
435static inline char *
436stripattributes (const char *s)
437{
438 char *stripped = XNEWVEC (char, strlen (s) + 2);
439 char *p = stripped;
440
441 *p++ = '*';
442
443 while (*s && *s != ',')
444 *p++ = *s++;
445
446 *p = '\0';
447 return stripped;
448}
449
450/* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
451 switch to the data section instead, and write out a synthetic start label
452 for collect2 the first time around. */
453
454static void
455switch_to_eh_frame_section (bool back)
456{
457 tree label;
458
459#ifdef EH_FRAME_SECTION_NAME
460 if (eh_frame_section == 0)
461 {
462 int flags;
463
464 if (EH_TABLES_CAN_BE_READ_ONLY)
465 {
466 int fde_encoding;
467 int per_encoding;
468 int lsda_encoding;
469
470 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
471 /*global=*/0);
472 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
473 /*global=*/1);
474 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
475 /*global=*/0);
476 flags = ((! flag_pic
477 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
478 && (fde_encoding & 0x70) != DW_EH_PE_aligned
479 && (per_encoding & 0x70) != DW_EH_PE_absptr
480 && (per_encoding & 0x70) != DW_EH_PE_aligned
481 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
482 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
483 ? 0 : SECTION_WRITE);
484 }
485 else
486 flags = SECTION_WRITE;
487 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
488 }
489#endif /* EH_FRAME_SECTION_NAME */
490
491 if (eh_frame_section)
492 switch_to_section (eh_frame_section);
493 else
494 {
495 /* We have no special eh_frame section. Put the information in
496 the data section and emit special labels to guide collect2. */
497 switch_to_section (data_section);
498
499 if (!back)
500 {
501 label = get_file_function_name ("F");
502 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
503 targetm.asm_out.globalize_label (asm_out_file,
504 IDENTIFIER_POINTER (label));
505 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
506 }
507 }
508}
509
510/* Switch [BACK] to the eh or debug frame table section, depending on
511 FOR_EH. */
512
513static void
514switch_to_frame_table_section (int for_eh, bool back)
515{
516 if (for_eh)
517 switch_to_eh_frame_section (back);
518 else
519 {
520 if (!debug_frame_section)
521 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
522 SECTION_DEBUG, NULL);
523 switch_to_section (debug_frame_section);
524 }
525}
526
527/* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
528
529enum dw_cfi_oprnd_type
530dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
531{
532 switch (cfi)
533 {
534 case DW_CFA_nop:
535 case DW_CFA_GNU_window_save:
536 case DW_CFA_remember_state:
537 case DW_CFA_restore_state:
538 return dw_cfi_oprnd_unused;
539
540 case DW_CFA_set_loc:
541 case DW_CFA_advance_loc1:
542 case DW_CFA_advance_loc2:
543 case DW_CFA_advance_loc4:
544 case DW_CFA_MIPS_advance_loc8:
545 return dw_cfi_oprnd_addr;
546
547 case DW_CFA_offset:
548 case DW_CFA_offset_extended:
549 case DW_CFA_def_cfa:
550 case DW_CFA_offset_extended_sf:
551 case DW_CFA_def_cfa_sf:
552 case DW_CFA_restore:
553 case DW_CFA_restore_extended:
554 case DW_CFA_undefined:
555 case DW_CFA_same_value:
556 case DW_CFA_def_cfa_register:
557 case DW_CFA_register:
558 case DW_CFA_expression:
559 return dw_cfi_oprnd_reg_num;
560
561 case DW_CFA_def_cfa_offset:
562 case DW_CFA_GNU_args_size:
563 case DW_CFA_def_cfa_offset_sf:
564 return dw_cfi_oprnd_offset;
565
566 case DW_CFA_def_cfa_expression:
567 return dw_cfi_oprnd_loc;
568
569 default:
570 gcc_unreachable ();
571 }
572}
573
574/* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
575
576enum dw_cfi_oprnd_type
577dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
578{
579 switch (cfi)
580 {
581 case DW_CFA_def_cfa:
582 case DW_CFA_def_cfa_sf:
583 case DW_CFA_offset:
584 case DW_CFA_offset_extended_sf:
585 case DW_CFA_offset_extended:
586 return dw_cfi_oprnd_offset;
587
588 case DW_CFA_register:
589 return dw_cfi_oprnd_reg_num;
590
591 case DW_CFA_expression:
592 return dw_cfi_oprnd_loc;
593
594 default:
595 return dw_cfi_oprnd_unused;
596 }
597}
598
599/* Output one FDE. */
600
601static void
602output_fde (dw_fde_ref fde, bool for_eh, bool second,
603 char *section_start_label, int fde_encoding, char *augmentation,
604 bool any_lsda_needed, int lsda_encoding)
605{
606 const char *begin, *end;
607 static unsigned int j;
608 char l1[20], l2[20];
609
610 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
611 /* empty */ 0);
612 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
613 for_eh + j);
614 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
615 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
616 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
617 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
618 " indicating 64-bit DWARF extension");
619 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
620 "FDE Length");
621 ASM_OUTPUT_LABEL (asm_out_file, l1);
622
623 if (for_eh)
624 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
625 else
626 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
627 debug_frame_section, "FDE CIE offset");
628
629 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
630 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
631
632 if (for_eh)
633 {
634 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
635 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
636 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
637 "FDE initial location");
638 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
639 end, begin, "FDE address range");
640 }
641 else
642 {
643 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
644 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
645 }
646
647 if (augmentation[0])
648 {
649 if (any_lsda_needed)
650 {
651 int size = size_of_encoded_value (lsda_encoding);
652
653 if (lsda_encoding == DW_EH_PE_aligned)
654 {
655 int offset = ( 4 /* Length */
656 + 4 /* CIE offset */
657 + 2 * size_of_encoded_value (fde_encoding)
658 + 1 /* Augmentation size */ );
659 int pad = -offset & (PTR_SIZE - 1);
660
661 size += pad;
662 gcc_assert (size_of_uleb128 (size) == 1);
663 }
664
665 dw2_asm_output_data_uleb128 (size, "Augmentation size");
666
667 if (fde->uses_eh_lsda)
668 {
669 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
670 fde->funcdef_number);
671 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
672 gen_rtx_SYMBOL_REF (Pmode, l1),
673 false,
674 "Language Specific Data Area");
675 }
676 else
677 {
678 if (lsda_encoding == DW_EH_PE_aligned)
679 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
680 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
681 "Language Specific Data Area (none)");
682 }
683 }
684 else
685 dw2_asm_output_data_uleb128 (0, "Augmentation size");
686 }
687
688 /* Loop through the Call Frame Instructions associated with this FDE. */
689 fde->dw_fde_current_label = begin;
690 {
691 size_t from, until, i;
692
693 from = 0;
694 until = vec_safe_length (fde->dw_fde_cfi);
695
696 if (fde->dw_fde_second_begin == NULL)
697 ;
698 else if (!second)
699 until = fde->dw_fde_switch_cfi_index;
700 else
701 from = fde->dw_fde_switch_cfi_index;
702
703 for (i = from; i < until; i++)
704 output_cfi ((*fde->dw_fde_cfi)[i], fde, for_eh);
705 }
706
707 /* If we are to emit a ref/link from function bodies to their frame tables,
708 do it now. This is typically performed to make sure that tables
709 associated with functions are dragged with them and not discarded in
710 garbage collecting links. We need to do this on a per function basis to
711 cope with -ffunction-sections. */
712
713#ifdef ASM_OUTPUT_DWARF_TABLE_REF
714 /* Switch to the function section, emit the ref to the tables, and
715 switch *back* into the table section. */
716 switch_to_section (function_section (fde->decl));
717 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
718 switch_to_frame_table_section (for_eh, true);
719#endif
720
721 /* Pad the FDE out to an address sized boundary. */
722 ASM_OUTPUT_ALIGN (asm_out_file,
723 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
724 ASM_OUTPUT_LABEL (asm_out_file, l2);
725
726 j += 2;
727}
728
729/* Return true if frame description entry FDE is needed for EH. */
730
731static bool
732fde_needed_for_eh_p (dw_fde_ref fde)
733{
734 if (flag_asynchronous_unwind_tables)
735 return true;
736
737 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
738 return true;
739
740 if (fde->uses_eh_lsda)
741 return true;
742
743 /* If exceptions are enabled, we have collected nothrow info. */
744 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
745 return false;
746
747 return true;
748}
749
750/* Output the call frame information used to record information
751 that relates to calculating the frame pointer, and records the
752 location of saved registers. */
753
754static void
755output_call_frame_info (int for_eh)
756{
757 unsigned int i;
758 dw_fde_ref fde;
759 dw_cfi_ref cfi;
760 char l1[20], l2[20], section_start_label[20];
761 bool any_lsda_needed = false;
762 char augmentation[6];
763 int augmentation_size;
764 int fde_encoding = DW_EH_PE_absptr;
765 int per_encoding = DW_EH_PE_absptr;
766 int lsda_encoding = DW_EH_PE_absptr;
767 int return_reg;
768 rtx personality = NULL;
769 int dw_cie_version;
770
771 /* Don't emit a CIE if there won't be any FDEs. */
772 if (!fde_vec)
773 return;
774
775 /* Nothing to do if the assembler's doing it all. */
776 if (dwarf2out_do_cfi_asm ())
777 return;
778
779 /* If we don't have any functions we'll want to unwind out of, don't emit
780 any EH unwind information. If we make FDEs linkonce, we may have to
781 emit an empty label for an FDE that wouldn't otherwise be emitted. We
782 want to avoid having an FDE kept around when the function it refers to
783 is discarded. Example where this matters: a primary function template
784 in C++ requires EH information, an explicit specialization doesn't. */
785 if (for_eh)
786 {
787 bool any_eh_needed = false;
788
789 FOR_EACH_VEC_ELT (*fde_vec, i, fde)
790 {
791 if (fde->uses_eh_lsda)
792 any_eh_needed = any_lsda_needed = true;
793 else if (fde_needed_for_eh_p (fde))
794 any_eh_needed = true;
795 else if (TARGET_USES_WEAK_UNWIND_INFO)
796 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, 1, 1);
797 }
798
799 if (!any_eh_needed)
800 return;
801 }
802
803 /* We're going to be generating comments, so turn on app. */
804 if (flag_debug_asm)
805 app_enable ();
806
807 /* Switch to the proper frame section, first time. */
808 switch_to_frame_table_section (for_eh, false);
809
810 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
811 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
812
813 /* Output the CIE. */
814 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
815 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
816 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
817 dw2_asm_output_data (4, 0xffffffff,
818 "Initial length escape value indicating 64-bit DWARF extension");
819 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
820 "Length of Common Information Entry");
821 ASM_OUTPUT_LABEL (asm_out_file, l1);
822
823 /* Now that the CIE pointer is PC-relative for EH,
824 use 0 to identify the CIE. */
825 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
826 (for_eh ? 0 : DWARF_CIE_ID),
827 "CIE Identifier Tag");
828
829 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
830 use CIE version 1, unless that would produce incorrect results
831 due to overflowing the return register column. */
832 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
833 dw_cie_version = 1;
834 if (return_reg >= 256 || dwarf_version > 2)
835 dw_cie_version = 3;
836 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
837
838 augmentation[0] = 0;
839 augmentation_size = 0;
840
841 personality = current_unit_personality;
842 if (for_eh)
843 {
844 char *p;
845
846 /* Augmentation:
847 z Indicates that a uleb128 is present to size the
848 augmentation section.
849 L Indicates the encoding (and thus presence) of
850 an LSDA pointer in the FDE augmentation.
851 R Indicates a non-default pointer encoding for
852 FDE code pointers.
853 P Indicates the presence of an encoding + language
854 personality routine in the CIE augmentation. */
855
856 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
857 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
858 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
859
860 p = augmentation + 1;
861 if (personality)
862 {
863 *p++ = 'P';
864 augmentation_size += 1 + size_of_encoded_value (per_encoding);
865 assemble_external_libcall (personality);
866 }
867 if (any_lsda_needed)
868 {
869 *p++ = 'L';
870 augmentation_size += 1;
871 }
872 if (fde_encoding != DW_EH_PE_absptr)
873 {
874 *p++ = 'R';
875 augmentation_size += 1;
876 }
877 if (p > augmentation + 1)
878 {
879 augmentation[0] = 'z';
880 *p = '\0';
881 }
882
883 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
884 if (personality && per_encoding == DW_EH_PE_aligned)
885 {
886 int offset = ( 4 /* Length */
887 + 4 /* CIE Id */
888 + 1 /* CIE version */
889 + strlen (augmentation) + 1 /* Augmentation */
890 + size_of_uleb128 (1) /* Code alignment */
891 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
892 + 1 /* RA column */
893 + 1 /* Augmentation size */
894 + 1 /* Personality encoding */ );
895 int pad = -offset & (PTR_SIZE - 1);
896
897 augmentation_size += pad;
898
899 /* Augmentations should be small, so there's scarce need to
900 iterate for a solution. Die if we exceed one uleb128 byte. */
901 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
902 }
903 }
904
905 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
906 if (dw_cie_version >= 4)
907 {
908 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
909 dw2_asm_output_data (1, 0, "CIE Segment Size");
910 }
911 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
912 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
913 "CIE Data Alignment Factor");
914
915 if (dw_cie_version == 1)
916 dw2_asm_output_data (1, return_reg, "CIE RA Column");
917 else
918 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
919
920 if (augmentation[0])
921 {
922 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
923 if (personality)
924 {
925 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
926 eh_data_format_name (per_encoding));
927 dw2_asm_output_encoded_addr_rtx (per_encoding,
928 personality,
929 true, NULL);
930 }
931
932 if (any_lsda_needed)
933 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
934 eh_data_format_name (lsda_encoding));
935
936 if (fde_encoding != DW_EH_PE_absptr)
937 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
938 eh_data_format_name (fde_encoding));
939 }
940
941 FOR_EACH_VEC_ELT (*cie_cfi_vec, i, cfi)
942 output_cfi (cfi, NULL, for_eh);
943
944 /* Pad the CIE out to an address sized boundary. */
945 ASM_OUTPUT_ALIGN (asm_out_file,
946 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
947 ASM_OUTPUT_LABEL (asm_out_file, l2);
948
949 /* Loop through all of the FDE's. */
950 FOR_EACH_VEC_ELT (*fde_vec, i, fde)
951 {
952 unsigned int k;
953
954 /* Don't emit EH unwind info for leaf functions that don't need it. */
955 if (for_eh && !fde_needed_for_eh_p (fde))
956 continue;
957
958 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
959 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
960 augmentation, any_lsda_needed, lsda_encoding);
961 }
962
963 if (for_eh && targetm.terminate_dw2_eh_frame_info)
964 dw2_asm_output_data (4, 0, "End of Table");
965
966 /* Turn off app to make assembly quicker. */
967 if (flag_debug_asm)
968 app_disable ();
969}
970
971/* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
972
973static void
974dwarf2out_do_cfi_startproc (bool second)
975{
976 int enc;
977 rtx ref;
978 rtx personality = get_personality_function (current_function_decl);
979
980 fprintf (asm_out_file, "\t.cfi_startproc\n");
981
982 if (personality)
983 {
984 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
985 ref = personality;
986
987 /* ??? The GAS support isn't entirely consistent. We have to
988 handle indirect support ourselves, but PC-relative is done
989 in the assembler. Further, the assembler can't handle any
990 of the weirder relocation types. */
991 if (enc & DW_EH_PE_indirect)
992 ref = dw2_force_const_mem (ref, true);
993
994 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
995 output_addr_const (asm_out_file, ref);
996 fputc ('\n', asm_out_file);
997 }
998
999 if (crtl->uses_eh_lsda)
1000 {
1001 char lab[20];
1002
1003 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1004 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
1005 current_function_funcdef_no);
1006 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
1007 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
1008
1009 if (enc & DW_EH_PE_indirect)
1010 ref = dw2_force_const_mem (ref, true);
1011
1012 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
1013 output_addr_const (asm_out_file, ref);
1014 fputc ('\n', asm_out_file);
1015 }
1016}
1017
1018/* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1019 this allocation may be done before pass_final. */
1020
1021dw_fde_ref
1022dwarf2out_alloc_current_fde (void)
1023{
1024 dw_fde_ref fde;
1025
1026 fde = ggc_cleared_alloc<dw_fde_node> ();
1027 fde->decl = current_function_decl;
1028 fde->funcdef_number = current_function_funcdef_no;
1029 fde->fde_index = vec_safe_length (fde_vec);
1030 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
1031 fde->uses_eh_lsda = crtl->uses_eh_lsda;
1032 fde->nothrow = crtl->nothrow;
1033 fde->drap_reg = INVALID_REGNUM;
1034 fde->vdrap_reg = INVALID_REGNUM;
1035
1036 /* Record the FDE associated with this function. */
1037 cfun->fde = fde;
1038 vec_safe_push (fde_vec, fde);
1039
1040 return fde;
1041}
1042
1043/* Output a marker (i.e. a label) for the beginning of a function, before
1044 the prologue. */
1045
1046void
1047dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
1048 const char *file ATTRIBUTE_UNUSED)
1049{
1050 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1051 char * dup_label;
1052 dw_fde_ref fde;
1053 section *fnsec;
1054 bool do_frame;
1055
1056 current_function_func_begin_label = NULL;
1057
1058 do_frame = dwarf2out_do_frame ();
1059
1060 /* ??? current_function_func_begin_label is also used by except.c for
1061 call-site information. We must emit this label if it might be used. */
1062 if (!do_frame
1063 && (!flag_exceptions
1064 || targetm_common.except_unwind_info (&global_options) == UI_SJLJ))
1065 return;
1066
1067 fnsec = function_section (current_function_decl);
1068 switch_to_section (fnsec);
1069 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1070 current_function_funcdef_no);
1071 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
1072 current_function_funcdef_no);
1073 dup_label = xstrdup (label);
1074 current_function_func_begin_label = dup_label;
1075
1076 /* We can elide the fde allocation if we're not emitting debug info. */
1077 if (!do_frame)
1078 return;
1079
1080 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1081 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1082 would include pass_dwarf2_frame. If we've not created the FDE yet,
1083 do so now. */
1084 fde = cfun->fde;
1085 if (fde == NULL)
1086 fde = dwarf2out_alloc_current_fde ();
1087
1088 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1089 fde->dw_fde_begin = dup_label;
1090 fde->dw_fde_current_label = dup_label;
1091 fde->in_std_section = (fnsec == text_section
1092 || (cold_text_section && fnsec == cold_text_section));
1093
1094 /* We only want to output line number information for the genuine dwarf2
1095 prologue case, not the eh frame case. */
1096#ifdef DWARF2_DEBUGGING_INFO
1097 if (file)
1098 dwarf2out_source_line (line, file, 0, true);
1099#endif
1100
1101 if (dwarf2out_do_cfi_asm ())
1102 dwarf2out_do_cfi_startproc (false);
1103 else
1104 {
1105 rtx personality = get_personality_function (current_function_decl);
1106 if (!current_unit_personality)
1107 current_unit_personality = personality;
1108
1109 /* We cannot keep a current personality per function as without CFI
1110 asm, at the point where we emit the CFI data, there is no current
1111 function anymore. */
1112 if (personality && current_unit_personality != personality)
1113 sorry ("multiple EH personalities are supported only with assemblers "
1114 "supporting .cfi_personality directive");
1115 }
1116}
1117
1118/* Output a marker (i.e. a label) for the end of the generated code
1119 for a function prologue. This gets called *after* the prologue code has
1120 been generated. */
1121
1122void
1123dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
1124 const char *file ATTRIBUTE_UNUSED)
1125{
1126 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1127
1128 /* Output a label to mark the endpoint of the code generated for this
1129 function. */
1130 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
1131 current_function_funcdef_no);
1132 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
1133 current_function_funcdef_no);
1134 cfun->fde->dw_fde_vms_end_prologue = xstrdup (label);
1135}
1136
1137/* Output a marker (i.e. a label) for the beginning of the generated code
1138 for a function epilogue. This gets called *before* the prologue code has
1139 been generated. */
1140
1141void
1142dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1143 const char *file ATTRIBUTE_UNUSED)
1144{
1145 dw_fde_ref fde = cfun->fde;
1146 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1147
1148 if (fde->dw_fde_vms_begin_epilogue)
1149 return;
1150
1151 /* Output a label to mark the endpoint of the code generated for this
1152 function. */
1153 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
1154 current_function_funcdef_no);
1155 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
1156 current_function_funcdef_no);
1157 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
1158}
1159
1160/* Output a marker (i.e. a label) for the absolute end of the generated code
1161 for a function definition. This gets called *after* the epilogue code has
1162 been generated. */
1163
1164void
1165dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1166 const char *file ATTRIBUTE_UNUSED)
1167{
1168 dw_fde_ref fde;
1169 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1170
1171 last_var_location_insn = NULL;
1172 cached_next_real_insn = NULL;
1173
1174 if (dwarf2out_do_cfi_asm ())
1175 fprintf (asm_out_file, "\t.cfi_endproc\n");
1176
1177 /* Output a label to mark the endpoint of the code generated for this
1178 function. */
1179 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1180 current_function_funcdef_no);
1181 ASM_OUTPUT_LABEL (asm_out_file, label);
1182 fde = cfun->fde;
1183 gcc_assert (fde != NULL);
1184 if (fde->dw_fde_second_begin == NULL)
1185 fde->dw_fde_end = xstrdup (label);
1186}
1187
1188void
1189dwarf2out_frame_finish (void)
1190{
1191 /* Output call frame information. */
1192 if (targetm.debug_unwind_info () == UI_DWARF2)
1193 output_call_frame_info (0);
1194
1195 /* Output another copy for the unwinder. */
1196 if ((flag_unwind_tables || flag_exceptions)
1197 && targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
1198 output_call_frame_info (1);
1199}
1200
1201/* Note that the current function section is being used for code. */
1202
1203static void
1204dwarf2out_note_section_used (void)
1205{
1206 section *sec = current_function_section ();
1207 if (sec == text_section)
1208 text_section_used = true;
1209 else if (sec == cold_text_section)
1210 cold_text_section_used = true;
1211}
1212
1213static void var_location_switch_text_section (void);
1214static void set_cur_line_info_table (section *);
1215
1216void
1217dwarf2out_switch_text_section (void)
1218{
1219 section *sect;
1220 dw_fde_ref fde = cfun->fde;
1221
1222 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
1223
1224 if (!in_cold_section_p)
1225 {
1226 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
1227 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
1228 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
1229 }
1230 else
1231 {
1232 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
1233 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
1234 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
1235 }
1236 have_multiple_function_sections = true;
1237
1238 /* There is no need to mark used sections when not debugging. */
1239 if (cold_text_section != NULL)
1240 dwarf2out_note_section_used ();
1241
1242 if (dwarf2out_do_cfi_asm ())
1243 fprintf (asm_out_file, "\t.cfi_endproc\n");
1244
1245 /* Now do the real section switch. */
1246 sect = current_function_section ();
1247 switch_to_section (sect);
1248
1249 fde->second_in_std_section
1250 = (sect == text_section
1251 || (cold_text_section && sect == cold_text_section));
1252
1253 if (dwarf2out_do_cfi_asm ())
1254 dwarf2out_do_cfi_startproc (true);
1255
1256 var_location_switch_text_section ();
1257
1258 if (cold_text_section != NULL)
1259 set_cur_line_info_table (sect);
1260}
1261\f
1262/* And now, the subset of the debugging information support code necessary
1263 for emitting location expressions. */
1264
1265/* Data about a single source file. */
1266struct GTY((for_user)) dwarf_file_data {
1267 const char * filename;
1268 int emitted_number;
1269};
1270
1271typedef struct GTY(()) deferred_locations_struct
1272{
1273 tree variable;
1274 dw_die_ref die;
1275} deferred_locations;
1276
1277
1278static GTY(()) vec<deferred_locations, va_gc> *deferred_locations_list;
1279
1280
1281/* Describe an entry into the .debug_addr section. */
1282
1283enum ate_kind {
1284 ate_kind_rtx,
1285 ate_kind_rtx_dtprel,
1286 ate_kind_label
1287};
1288
1289typedef struct GTY((for_user)) addr_table_entry_struct {
1290 enum ate_kind kind;
1291 unsigned int refcount;
1292 unsigned int index;
1293 union addr_table_entry_struct_union
1294 {
1295 rtx GTY ((tag ("0"))) rtl;
1296 char * GTY ((tag ("1"))) label;
1297 }
1298 GTY ((desc ("%1.kind"))) addr;
1299}
1300addr_table_entry;
1301
1302/* Location lists are ranges + location descriptions for that range,
1303 so you can track variables that are in different places over
1304 their entire life. */
1305typedef struct GTY(()) dw_loc_list_struct {
1306 dw_loc_list_ref dw_loc_next;
1307 const char *begin; /* Label and addr_entry for start of range */
1308 addr_table_entry *begin_entry;
1309 const char *end; /* Label for end of range */
1310 char *ll_symbol; /* Label for beginning of location list.
1311 Only on head of list */
1312 const char *section; /* Section this loclist is relative to */
1313 dw_loc_descr_ref expr;
1314 hashval_t hash;
1315 /* True if all addresses in this and subsequent lists are known to be
1316 resolved. */
1317 bool resolved_addr;
1318 /* True if this list has been replaced by dw_loc_next. */
1319 bool replaced;
1320 bool emitted;
1321 /* True if the range should be emitted even if begin and end
1322 are the same. */
1323 bool force;
1324} dw_loc_list_node;
1325
1326static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
1327
1328/* Convert a DWARF stack opcode into its string name. */
1329
1330static const char *
1331dwarf_stack_op_name (unsigned int op)
1332{
1333 const char *name = get_DW_OP_name (op);
1334
1335 if (name != NULL)
1336 return name;
1337
1338 return "OP_<unknown>";
1339}
1340
1341/* Return a pointer to a newly allocated location description. Location
1342 descriptions are simple expression terms that can be strung
1343 together to form more complicated location (address) descriptions. */
1344
1345static inline dw_loc_descr_ref
1346new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
1347 unsigned HOST_WIDE_INT oprnd2)
1348{
1349 dw_loc_descr_ref descr = ggc_cleared_alloc<dw_loc_descr_node> ();
1350
1351 descr->dw_loc_opc = op;
1352 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
1353 descr->dw_loc_oprnd1.val_entry = NULL;
1354 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
1355 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
1356 descr->dw_loc_oprnd2.val_entry = NULL;
1357 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
1358
1359 return descr;
1360}
1361
1362/* Return a pointer to a newly allocated location description for
1363 REG and OFFSET. */
1364
1365static inline dw_loc_descr_ref
1366new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
1367{
1368 if (reg <= 31)
1369 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
1370 offset, 0);
1371 else
1372 return new_loc_descr (DW_OP_bregx, reg, offset);
1373}
1374
1375/* Add a location description term to a location description expression. */
1376
1377static inline void
1378add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
1379{
1380 dw_loc_descr_ref *d;
1381
1382 /* Find the end of the chain. */
1383 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
1384 ;
1385
1386 *d = descr;
1387}
1388
1389/* Compare two location operands for exact equality. */
1390
1391static bool
1392dw_val_equal_p (dw_val_node *a, dw_val_node *b)
1393{
1394 if (a->val_class != b->val_class)
1395 return false;
1396 switch (a->val_class)
1397 {
1398 case dw_val_class_none:
1399 return true;
1400 case dw_val_class_addr:
1401 return rtx_equal_p (a->v.val_addr, b->v.val_addr);
1402
1403 case dw_val_class_offset:
1404 case dw_val_class_unsigned_const:
1405 case dw_val_class_const:
1406 case dw_val_class_range_list:
1407 case dw_val_class_lineptr:
1408 case dw_val_class_macptr:
1409 /* These are all HOST_WIDE_INT, signed or unsigned. */
1410 return a->v.val_unsigned == b->v.val_unsigned;
1411
1412 case dw_val_class_loc:
1413 return a->v.val_loc == b->v.val_loc;
1414 case dw_val_class_loc_list:
1415 return a->v.val_loc_list == b->v.val_loc_list;
1416 case dw_val_class_die_ref:
1417 return a->v.val_die_ref.die == b->v.val_die_ref.die;
1418 case dw_val_class_fde_ref:
1419 return a->v.val_fde_index == b->v.val_fde_index;
1420 case dw_val_class_lbl_id:
1421 case dw_val_class_high_pc:
1422 return strcmp (a->v.val_lbl_id, b->v.val_lbl_id) == 0;
1423 case dw_val_class_str:
1424 return a->v.val_str == b->v.val_str;
1425 case dw_val_class_flag:
1426 return a->v.val_flag == b->v.val_flag;
1427 case dw_val_class_file:
1428 return a->v.val_file == b->v.val_file;
1429 case dw_val_class_decl_ref:
1430 return a->v.val_decl_ref == b->v.val_decl_ref;
1431
1432 case dw_val_class_const_double:
1433 return (a->v.val_double.high == b->v.val_double.high
1434 && a->v.val_double.low == b->v.val_double.low);
1435
1436 case dw_val_class_wide_int:
1437 return *a->v.val_wide == *b->v.val_wide;
1438
1439 case dw_val_class_vec:
1440 {
1441 size_t a_len = a->v.val_vec.elt_size * a->v.val_vec.length;
1442 size_t b_len = b->v.val_vec.elt_size * b->v.val_vec.length;
1443
1444 return (a_len == b_len
1445 && !memcmp (a->v.val_vec.array, b->v.val_vec.array, a_len));
1446 }
1447
1448 case dw_val_class_data8:
1449 return memcmp (a->v.val_data8, b->v.val_data8, 8) == 0;
1450
1451 case dw_val_class_vms_delta:
1452 return (!strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1)
1453 && !strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1));
1454 }
1455 gcc_unreachable ();
1456}
1457
1458/* Compare two location atoms for exact equality. */
1459
1460static bool
1461loc_descr_equal_p_1 (dw_loc_descr_ref a, dw_loc_descr_ref b)
1462{
1463 if (a->dw_loc_opc != b->dw_loc_opc)
1464 return false;
1465
1466 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1467 address size, but since we always allocate cleared storage it
1468 should be zero for other types of locations. */
1469 if (a->dtprel != b->dtprel)
1470 return false;
1471
1472 return (dw_val_equal_p (&a->dw_loc_oprnd1, &b->dw_loc_oprnd1)
1473 && dw_val_equal_p (&a->dw_loc_oprnd2, &b->dw_loc_oprnd2));
1474}
1475
1476/* Compare two complete location expressions for exact equality. */
1477
1478bool
1479loc_descr_equal_p (dw_loc_descr_ref a, dw_loc_descr_ref b)
1480{
1481 while (1)
1482 {
1483 if (a == b)
1484 return true;
1485 if (a == NULL || b == NULL)
1486 return false;
1487 if (!loc_descr_equal_p_1 (a, b))
1488 return false;
1489
1490 a = a->dw_loc_next;
1491 b = b->dw_loc_next;
1492 }
1493}
1494
1495
1496/* Add a constant OFFSET to a location expression. */
1497
1498static void
1499loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
1500{
1501 dw_loc_descr_ref loc;
1502 HOST_WIDE_INT *p;
1503
1504 gcc_assert (*list_head != NULL);
1505
1506 if (!offset)
1507 return;
1508
1509 /* Find the end of the chain. */
1510 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
1511 ;
1512
1513 p = NULL;
1514 if (loc->dw_loc_opc == DW_OP_fbreg
1515 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
1516 p = &loc->dw_loc_oprnd1.v.val_int;
1517 else if (loc->dw_loc_opc == DW_OP_bregx)
1518 p = &loc->dw_loc_oprnd2.v.val_int;
1519
1520 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1521 offset. Don't optimize if an signed integer overflow would happen. */
1522 if (p != NULL
1523 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
1524 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
1525 *p += offset;
1526
1527 else if (offset > 0)
1528 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
1529
1530 else
1531 {
1532 loc->dw_loc_next = int_loc_descriptor (-offset);
1533 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
1534 }
1535}
1536
1537/* Add a constant OFFSET to a location list. */
1538
1539static void
1540loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
1541{
1542 dw_loc_list_ref d;
1543 for (d = list_head; d != NULL; d = d->dw_loc_next)
1544 loc_descr_plus_const (&d->expr, offset);
1545}
1546
1547#define DWARF_REF_SIZE \
1548 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1549
1550static unsigned long int get_base_type_offset (dw_die_ref);
1551
1552/* Return the size of a location descriptor. */
1553
1554static unsigned long
1555size_of_loc_descr (dw_loc_descr_ref loc)
1556{
1557 unsigned long size = 1;
1558
1559 switch (loc->dw_loc_opc)
1560 {
1561 case DW_OP_addr:
1562 size += DWARF2_ADDR_SIZE;
1563 break;
1564 case DW_OP_GNU_addr_index:
1565 case DW_OP_GNU_const_index:
1566 gcc_assert (loc->dw_loc_oprnd1.val_entry->index != NO_INDEX_ASSIGNED);
1567 size += size_of_uleb128 (loc->dw_loc_oprnd1.val_entry->index);
1568 break;
1569 case DW_OP_const1u:
1570 case DW_OP_const1s:
1571 size += 1;
1572 break;
1573 case DW_OP_const2u:
1574 case DW_OP_const2s:
1575 size += 2;
1576 break;
1577 case DW_OP_const4u:
1578 case DW_OP_const4s:
1579 size += 4;
1580 break;
1581 case DW_OP_const8u:
1582 case DW_OP_const8s:
1583 size += 8;
1584 break;
1585 case DW_OP_constu:
1586 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1587 break;
1588 case DW_OP_consts:
1589 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1590 break;
1591 case DW_OP_pick:
1592 size += 1;
1593 break;
1594 case DW_OP_plus_uconst:
1595 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1596 break;
1597 case DW_OP_skip:
1598 case DW_OP_bra:
1599 size += 2;
1600 break;
1601 case DW_OP_breg0:
1602 case DW_OP_breg1:
1603 case DW_OP_breg2:
1604 case DW_OP_breg3:
1605 case DW_OP_breg4:
1606 case DW_OP_breg5:
1607 case DW_OP_breg6:
1608 case DW_OP_breg7:
1609 case DW_OP_breg8:
1610 case DW_OP_breg9:
1611 case DW_OP_breg10:
1612 case DW_OP_breg11:
1613 case DW_OP_breg12:
1614 case DW_OP_breg13:
1615 case DW_OP_breg14:
1616 case DW_OP_breg15:
1617 case DW_OP_breg16:
1618 case DW_OP_breg17:
1619 case DW_OP_breg18:
1620 case DW_OP_breg19:
1621 case DW_OP_breg20:
1622 case DW_OP_breg21:
1623 case DW_OP_breg22:
1624 case DW_OP_breg23:
1625 case DW_OP_breg24:
1626 case DW_OP_breg25:
1627 case DW_OP_breg26:
1628 case DW_OP_breg27:
1629 case DW_OP_breg28:
1630 case DW_OP_breg29:
1631 case DW_OP_breg30:
1632 case DW_OP_breg31:
1633 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1634 break;
1635 case DW_OP_regx:
1636 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1637 break;
1638 case DW_OP_fbreg:
1639 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1640 break;
1641 case DW_OP_bregx:
1642 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1643 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1644 break;
1645 case DW_OP_piece:
1646 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1647 break;
1648 case DW_OP_bit_piece:
1649 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1650 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
1651 break;
1652 case DW_OP_deref_size:
1653 case DW_OP_xderef_size:
1654 size += 1;
1655 break;
1656 case DW_OP_call2:
1657 size += 2;
1658 break;
1659 case DW_OP_call4:
1660 size += 4;
1661 break;
1662 case DW_OP_call_ref:
1663 size += DWARF_REF_SIZE;
1664 break;
1665 case DW_OP_implicit_value:
1666 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1667 + loc->dw_loc_oprnd1.v.val_unsigned;
1668 break;
1669 case DW_OP_GNU_implicit_pointer:
1670 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1671 break;
1672 case DW_OP_GNU_entry_value:
1673 {
1674 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
1675 size += size_of_uleb128 (op_size) + op_size;
1676 break;
1677 }
1678 case DW_OP_GNU_const_type:
1679 {
1680 unsigned long o
1681 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1682 size += size_of_uleb128 (o) + 1;
1683 switch (loc->dw_loc_oprnd2.val_class)
1684 {
1685 case dw_val_class_vec:
1686 size += loc->dw_loc_oprnd2.v.val_vec.length
1687 * loc->dw_loc_oprnd2.v.val_vec.elt_size;
1688 break;
1689 case dw_val_class_const:
1690 size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
1691 break;
1692 case dw_val_class_const_double:
1693 size += HOST_BITS_PER_DOUBLE_INT / BITS_PER_UNIT;
1694 break;
1695 case dw_val_class_wide_int:
1696 size += (get_full_len (*loc->dw_loc_oprnd2.v.val_wide)
1697 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
1698 break;
1699 default:
1700 gcc_unreachable ();
1701 }
1702 break;
1703 }
1704 case DW_OP_GNU_regval_type:
1705 {
1706 unsigned long o
1707 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1708 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1709 + size_of_uleb128 (o);
1710 }
1711 break;
1712 case DW_OP_GNU_deref_type:
1713 {
1714 unsigned long o
1715 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1716 size += 1 + size_of_uleb128 (o);
1717 }
1718 break;
1719 case DW_OP_GNU_convert:
1720 case DW_OP_GNU_reinterpret:
1721 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
1722 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1723 else
1724 {
1725 unsigned long o
1726 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1727 size += size_of_uleb128 (o);
1728 }
1729 break;
1730 case DW_OP_GNU_parameter_ref:
1731 size += 4;
1732 break;
1733 default:
1734 break;
1735 }
1736
1737 return size;
1738}
1739
1740/* Return the size of a series of location descriptors. */
1741
1742unsigned long
1743size_of_locs (dw_loc_descr_ref loc)
1744{
1745 dw_loc_descr_ref l;
1746 unsigned long size;
1747
1748 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1749 field, to avoid writing to a PCH file. */
1750 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
1751 {
1752 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
1753 break;
1754 size += size_of_loc_descr (l);
1755 }
1756 if (! l)
1757 return size;
1758
1759 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
1760 {
1761 l->dw_loc_addr = size;
1762 size += size_of_loc_descr (l);
1763 }
1764
1765 return size;
1766}
1767
1768static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
1769static void get_ref_die_offset_label (char *, dw_die_ref);
1770static unsigned long int get_ref_die_offset (dw_die_ref);
1771
1772/* Output location description stack opcode's operands (if any).
1773 The for_eh_or_skip parameter controls whether register numbers are
1774 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1775 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1776 info). This should be suppressed for the cases that have not been converted
1777 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1778
1779static void
1780output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
1781{
1782 dw_val_ref val1 = &loc->dw_loc_oprnd1;
1783 dw_val_ref val2 = &loc->dw_loc_oprnd2;
1784
1785 switch (loc->dw_loc_opc)
1786 {
1787#ifdef DWARF2_DEBUGGING_INFO
1788 case DW_OP_const2u:
1789 case DW_OP_const2s:
1790 dw2_asm_output_data (2, val1->v.val_int, NULL);
1791 break;
1792 case DW_OP_const4u:
1793 if (loc->dtprel)
1794 {
1795 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
1796 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
1797 val1->v.val_addr);
1798 fputc ('\n', asm_out_file);
1799 break;
1800 }
1801 /* FALLTHRU */
1802 case DW_OP_const4s:
1803 dw2_asm_output_data (4, val1->v.val_int, NULL);
1804 break;
1805 case DW_OP_const8u:
1806 if (loc->dtprel)
1807 {
1808 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
1809 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
1810 val1->v.val_addr);
1811 fputc ('\n', asm_out_file);
1812 break;
1813 }
1814 /* FALLTHRU */
1815 case DW_OP_const8s:
1816 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
1817 dw2_asm_output_data (8, val1->v.val_int, NULL);
1818 break;
1819 case DW_OP_skip:
1820 case DW_OP_bra:
1821 {
1822 int offset;
1823
1824 gcc_assert (val1->val_class == dw_val_class_loc);
1825 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
1826
1827 dw2_asm_output_data (2, offset, NULL);
1828 }
1829 break;
1830 case DW_OP_implicit_value:
1831 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1832 switch (val2->val_class)
1833 {
1834 case dw_val_class_const:
1835 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
1836 break;
1837 case dw_val_class_vec:
1838 {
1839 unsigned int elt_size = val2->v.val_vec.elt_size;
1840 unsigned int len = val2->v.val_vec.length;
1841 unsigned int i;
1842 unsigned char *p;
1843
1844 if (elt_size > sizeof (HOST_WIDE_INT))
1845 {
1846 elt_size /= 2;
1847 len *= 2;
1848 }
1849 for (i = 0, p = val2->v.val_vec.array;
1850 i < len;
1851 i++, p += elt_size)
1852 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
1853 "fp or vector constant word %u", i);
1854 }
1855 break;
1856 case dw_val_class_const_double:
1857 {
1858 unsigned HOST_WIDE_INT first, second;
1859
1860 if (WORDS_BIG_ENDIAN)
1861 {
1862 first = val2->v.val_double.high;
1863 second = val2->v.val_double.low;
1864 }
1865 else
1866 {
1867 first = val2->v.val_double.low;
1868 second = val2->v.val_double.high;
1869 }
1870 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
1871 first, NULL);
1872 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
1873 second, NULL);
1874 }
1875 break;
1876 case dw_val_class_wide_int:
1877 {
1878 int i;
1879 int len = get_full_len (*val2->v.val_wide);
1880 if (WORDS_BIG_ENDIAN)
1881 for (i = len - 1; i >= 0; --i)
1882 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
1883 val2->v.val_wide->elt (i), NULL);
1884 else
1885 for (i = 0; i < len; ++i)
1886 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
1887 val2->v.val_wide->elt (i), NULL);
1888 }
1889 break;
1890 case dw_val_class_addr:
1891 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
1892 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
1893 break;
1894 default:
1895 gcc_unreachable ();
1896 }
1897 break;
1898#else
1899 case DW_OP_const2u:
1900 case DW_OP_const2s:
1901 case DW_OP_const4u:
1902 case DW_OP_const4s:
1903 case DW_OP_const8u:
1904 case DW_OP_const8s:
1905 case DW_OP_skip:
1906 case DW_OP_bra:
1907 case DW_OP_implicit_value:
1908 /* We currently don't make any attempt to make sure these are
1909 aligned properly like we do for the main unwind info, so
1910 don't support emitting things larger than a byte if we're
1911 only doing unwinding. */
1912 gcc_unreachable ();
1913#endif
1914 case DW_OP_const1u:
1915 case DW_OP_const1s:
1916 dw2_asm_output_data (1, val1->v.val_int, NULL);
1917 break;
1918 case DW_OP_constu:
1919 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1920 break;
1921 case DW_OP_consts:
1922 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
1923 break;
1924 case DW_OP_pick:
1925 dw2_asm_output_data (1, val1->v.val_int, NULL);
1926 break;
1927 case DW_OP_plus_uconst:
1928 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1929 break;
1930 case DW_OP_breg0:
1931 case DW_OP_breg1:
1932 case DW_OP_breg2:
1933 case DW_OP_breg3:
1934 case DW_OP_breg4:
1935 case DW_OP_breg5:
1936 case DW_OP_breg6:
1937 case DW_OP_breg7:
1938 case DW_OP_breg8:
1939 case DW_OP_breg9:
1940 case DW_OP_breg10:
1941 case DW_OP_breg11:
1942 case DW_OP_breg12:
1943 case DW_OP_breg13:
1944 case DW_OP_breg14:
1945 case DW_OP_breg15:
1946 case DW_OP_breg16:
1947 case DW_OP_breg17:
1948 case DW_OP_breg18:
1949 case DW_OP_breg19:
1950 case DW_OP_breg20:
1951 case DW_OP_breg21:
1952 case DW_OP_breg22:
1953 case DW_OP_breg23:
1954 case DW_OP_breg24:
1955 case DW_OP_breg25:
1956 case DW_OP_breg26:
1957 case DW_OP_breg27:
1958 case DW_OP_breg28:
1959 case DW_OP_breg29:
1960 case DW_OP_breg30:
1961 case DW_OP_breg31:
1962 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
1963 break;
1964 case DW_OP_regx:
1965 {
1966 unsigned r = val1->v.val_unsigned;
1967 if (for_eh_or_skip >= 0)
1968 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
1969 gcc_assert (size_of_uleb128 (r)
1970 == size_of_uleb128 (val1->v.val_unsigned));
1971 dw2_asm_output_data_uleb128 (r, NULL);
1972 }
1973 break;
1974 case DW_OP_fbreg:
1975 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
1976 break;
1977 case DW_OP_bregx:
1978 {
1979 unsigned r = val1->v.val_unsigned;
1980 if (for_eh_or_skip >= 0)
1981 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
1982 gcc_assert (size_of_uleb128 (r)
1983 == size_of_uleb128 (val1->v.val_unsigned));
1984 dw2_asm_output_data_uleb128 (r, NULL);
1985 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
1986 }
1987 break;
1988 case DW_OP_piece:
1989 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1990 break;
1991 case DW_OP_bit_piece:
1992 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1993 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
1994 break;
1995 case DW_OP_deref_size:
1996 case DW_OP_xderef_size:
1997 dw2_asm_output_data (1, val1->v.val_int, NULL);
1998 break;
1999
2000 case DW_OP_addr:
2001 if (loc->dtprel)
2002 {
2003 if (targetm.asm_out.output_dwarf_dtprel)
2004 {
2005 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
2006 DWARF2_ADDR_SIZE,
2007 val1->v.val_addr);
2008 fputc ('\n', asm_out_file);
2009 }
2010 else
2011 gcc_unreachable ();
2012 }
2013 else
2014 {
2015#ifdef DWARF2_DEBUGGING_INFO
2016 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2017#else
2018 gcc_unreachable ();
2019#endif
2020 }
2021 break;
2022
2023 case DW_OP_GNU_addr_index:
2024 case DW_OP_GNU_const_index:
2025 gcc_assert (loc->dw_loc_oprnd1.val_entry->index != NO_INDEX_ASSIGNED);
2026 dw2_asm_output_data_uleb128 (loc->dw_loc_oprnd1.val_entry->index,
2027 "(index into .debug_addr)");
2028 break;
2029
2030 case DW_OP_GNU_implicit_pointer:
2031 {
2032 char label[MAX_ARTIFICIAL_LABEL_BYTES
2033 + HOST_BITS_PER_WIDE_INT / 2 + 2];
2034 gcc_assert (val1->val_class == dw_val_class_die_ref);
2035 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
2036 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
2037 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2038 }
2039 break;
2040
2041 case DW_OP_GNU_entry_value:
2042 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
2043 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
2044 break;
2045
2046 case DW_OP_GNU_const_type:
2047 {
2048 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
2049 gcc_assert (o);
2050 dw2_asm_output_data_uleb128 (o, NULL);
2051 switch (val2->val_class)
2052 {
2053 case dw_val_class_const:
2054 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2055 dw2_asm_output_data (1, l, NULL);
2056 dw2_asm_output_data (l, val2->v.val_int, NULL);
2057 break;
2058 case dw_val_class_vec:
2059 {
2060 unsigned int elt_size = val2->v.val_vec.elt_size;
2061 unsigned int len = val2->v.val_vec.length;
2062 unsigned int i;
2063 unsigned char *p;
2064
2065 l = len * elt_size;
2066 dw2_asm_output_data (1, l, NULL);
2067 if (elt_size > sizeof (HOST_WIDE_INT))
2068 {
2069 elt_size /= 2;
2070 len *= 2;
2071 }
2072 for (i = 0, p = val2->v.val_vec.array;
2073 i < len;
2074 i++, p += elt_size)
2075 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2076 "fp or vector constant word %u", i);
2077 }
2078 break;
2079 case dw_val_class_const_double:
2080 {
2081 unsigned HOST_WIDE_INT first, second;
2082 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2083
2084 dw2_asm_output_data (1, 2 * l, NULL);
2085 if (WORDS_BIG_ENDIAN)
2086 {
2087 first = val2->v.val_double.high;
2088 second = val2->v.val_double.low;
2089 }
2090 else
2091 {
2092 first = val2->v.val_double.low;
2093 second = val2->v.val_double.high;
2094 }
2095 dw2_asm_output_data (l, first, NULL);
2096 dw2_asm_output_data (l, second, NULL);
2097 }
2098 break;
2099 case dw_val_class_wide_int:
2100 {
2101 int i;
2102 int len = get_full_len (*val2->v.val_wide);
2103 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2104
2105 dw2_asm_output_data (1, len * l, NULL);
2106 if (WORDS_BIG_ENDIAN)
2107 for (i = len - 1; i >= 0; --i)
2108 dw2_asm_output_data (l, val2->v.val_wide->elt (i), NULL);
2109 else
2110 for (i = 0; i < len; ++i)
2111 dw2_asm_output_data (l, val2->v.val_wide->elt (i), NULL);
2112 }
2113 break;
2114 default:
2115 gcc_unreachable ();
2116 }
2117 }
2118 break;
2119 case DW_OP_GNU_regval_type:
2120 {
2121 unsigned r = val1->v.val_unsigned;
2122 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2123 gcc_assert (o);
2124 if (for_eh_or_skip >= 0)
2125 {
2126 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2127 gcc_assert (size_of_uleb128 (r)
2128 == size_of_uleb128 (val1->v.val_unsigned));
2129 }
2130 dw2_asm_output_data_uleb128 (r, NULL);
2131 dw2_asm_output_data_uleb128 (o, NULL);
2132 }
2133 break;
2134 case DW_OP_GNU_deref_type:
2135 {
2136 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2137 gcc_assert (o);
2138 dw2_asm_output_data (1, val1->v.val_int, NULL);
2139 dw2_asm_output_data_uleb128 (o, NULL);
2140 }
2141 break;
2142 case DW_OP_GNU_convert:
2143 case DW_OP_GNU_reinterpret:
2144 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2145 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2146 else
2147 {
2148 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
2149 gcc_assert (o);
2150 dw2_asm_output_data_uleb128 (o, NULL);
2151 }
2152 break;
2153
2154 case DW_OP_GNU_parameter_ref:
2155 {
2156 unsigned long o;
2157 gcc_assert (val1->val_class == dw_val_class_die_ref);
2158 o = get_ref_die_offset (val1->v.val_die_ref.die);
2159 dw2_asm_output_data (4, o, NULL);
2160 }
2161 break;
2162
2163 default:
2164 /* Other codes have no operands. */
2165 break;
2166 }
2167}
2168
2169/* Output a sequence of location operations.
2170 The for_eh_or_skip parameter controls whether register numbers are
2171 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2172 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2173 info). This should be suppressed for the cases that have not been converted
2174 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2175
2176void
2177output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
2178{
2179 for (; loc != NULL; loc = loc->dw_loc_next)
2180 {
2181 enum dwarf_location_atom opc = loc->dw_loc_opc;
2182 /* Output the opcode. */
2183 if (for_eh_or_skip >= 0
2184 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2185 {
2186 unsigned r = (opc - DW_OP_breg0);
2187 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2188 gcc_assert (r <= 31);
2189 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2190 }
2191 else if (for_eh_or_skip >= 0
2192 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2193 {
2194 unsigned r = (opc - DW_OP_reg0);
2195 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2196 gcc_assert (r <= 31);
2197 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2198 }
2199
2200 dw2_asm_output_data (1, opc,
2201 "%s", dwarf_stack_op_name (opc));
2202
2203 /* Output the operand(s) (if any). */
2204 output_loc_operands (loc, for_eh_or_skip);
2205 }
2206}
2207
2208/* Output location description stack opcode's operands (if any).
2209 The output is single bytes on a line, suitable for .cfi_escape. */
2210
2211static void
2212output_loc_operands_raw (dw_loc_descr_ref loc)
2213{
2214 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2215 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2216
2217 switch (loc->dw_loc_opc)
2218 {
2219 case DW_OP_addr:
2220 case DW_OP_GNU_addr_index:
2221 case DW_OP_GNU_const_index:
2222 case DW_OP_implicit_value:
2223 /* We cannot output addresses in .cfi_escape, only bytes. */
2224 gcc_unreachable ();
2225
2226 case DW_OP_const1u:
2227 case DW_OP_const1s:
2228 case DW_OP_pick:
2229 case DW_OP_deref_size:
2230 case DW_OP_xderef_size:
2231 fputc (',', asm_out_file);
2232 dw2_asm_output_data_raw (1, val1->v.val_int);
2233 break;
2234
2235 case DW_OP_const2u:
2236 case DW_OP_const2s:
2237 fputc (',', asm_out_file);
2238 dw2_asm_output_data_raw (2, val1->v.val_int);
2239 break;
2240
2241 case DW_OP_const4u:
2242 case DW_OP_const4s:
2243 fputc (',', asm_out_file);
2244 dw2_asm_output_data_raw (4, val1->v.val_int);
2245 break;
2246
2247 case DW_OP_const8u:
2248 case DW_OP_const8s:
2249 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2250 fputc (',', asm_out_file);
2251 dw2_asm_output_data_raw (8, val1->v.val_int);
2252 break;
2253
2254 case DW_OP_skip:
2255 case DW_OP_bra:
2256 {
2257 int offset;
2258
2259 gcc_assert (val1->val_class == dw_val_class_loc);
2260 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2261
2262 fputc (',', asm_out_file);
2263 dw2_asm_output_data_raw (2, offset);
2264 }
2265 break;
2266
2267 case DW_OP_regx:
2268 {
2269 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2270 gcc_assert (size_of_uleb128 (r)
2271 == size_of_uleb128 (val1->v.val_unsigned));
2272 fputc (',', asm_out_file);
2273 dw2_asm_output_data_uleb128_raw (r);
2274 }
2275 break;
2276
2277 case DW_OP_constu:
2278 case DW_OP_plus_uconst:
2279 case DW_OP_piece:
2280 fputc (',', asm_out_file);
2281 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2282 break;
2283
2284 case DW_OP_bit_piece:
2285 fputc (',', asm_out_file);
2286 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2287 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
2288 break;
2289
2290 case DW_OP_consts:
2291 case DW_OP_breg0:
2292 case DW_OP_breg1:
2293 case DW_OP_breg2:
2294 case DW_OP_breg3:
2295 case DW_OP_breg4:
2296 case DW_OP_breg5:
2297 case DW_OP_breg6:
2298 case DW_OP_breg7:
2299 case DW_OP_breg8:
2300 case DW_OP_breg9:
2301 case DW_OP_breg10:
2302 case DW_OP_breg11:
2303 case DW_OP_breg12:
2304 case DW_OP_breg13:
2305 case DW_OP_breg14:
2306 case DW_OP_breg15:
2307 case DW_OP_breg16:
2308 case DW_OP_breg17:
2309 case DW_OP_breg18:
2310 case DW_OP_breg19:
2311 case DW_OP_breg20:
2312 case DW_OP_breg21:
2313 case DW_OP_breg22:
2314 case DW_OP_breg23:
2315 case DW_OP_breg24:
2316 case DW_OP_breg25:
2317 case DW_OP_breg26:
2318 case DW_OP_breg27:
2319 case DW_OP_breg28:
2320 case DW_OP_breg29:
2321 case DW_OP_breg30:
2322 case DW_OP_breg31:
2323 case DW_OP_fbreg:
2324 fputc (',', asm_out_file);
2325 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
2326 break;
2327
2328 case DW_OP_bregx:
2329 {
2330 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2331 gcc_assert (size_of_uleb128 (r)
2332 == size_of_uleb128 (val1->v.val_unsigned));
2333 fputc (',', asm_out_file);
2334 dw2_asm_output_data_uleb128_raw (r);
2335 fputc (',', asm_out_file);
2336 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
2337 }
2338 break;
2339
2340 case DW_OP_GNU_implicit_pointer:
2341 case DW_OP_GNU_entry_value:
2342 case DW_OP_GNU_const_type:
2343 case DW_OP_GNU_regval_type:
2344 case DW_OP_GNU_deref_type:
2345 case DW_OP_GNU_convert:
2346 case DW_OP_GNU_reinterpret:
2347 case DW_OP_GNU_parameter_ref:
2348 gcc_unreachable ();
2349 break;
2350
2351 default:
2352 /* Other codes have no operands. */
2353 break;
2354 }
2355}
2356
2357void
2358output_loc_sequence_raw (dw_loc_descr_ref loc)
2359{
2360 while (1)
2361 {
2362 enum dwarf_location_atom opc = loc->dw_loc_opc;
2363 /* Output the opcode. */
2364 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2365 {
2366 unsigned r = (opc - DW_OP_breg0);
2367 r = DWARF2_FRAME_REG_OUT (r, 1);
2368 gcc_assert (r <= 31);
2369 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2370 }
2371 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2372 {
2373 unsigned r = (opc - DW_OP_reg0);
2374 r = DWARF2_FRAME_REG_OUT (r, 1);
2375 gcc_assert (r <= 31);
2376 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2377 }
2378 /* Output the opcode. */
2379 fprintf (asm_out_file, "%#x", opc);
2380 output_loc_operands_raw (loc);
2381
2382 if (!loc->dw_loc_next)
2383 break;
2384 loc = loc->dw_loc_next;
2385
2386 fputc (',', asm_out_file);
2387 }
2388}
2389
2390/* This function builds a dwarf location descriptor sequence from a
2391 dw_cfa_location, adding the given OFFSET to the result of the
2392 expression. */
2393
2394struct dw_loc_descr_node *
2395build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
2396{
2397 struct dw_loc_descr_node *head, *tmp;
2398
2399 offset += cfa->offset;
2400
2401 if (cfa->indirect)
2402 {
2403 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
2404 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2405 head->dw_loc_oprnd1.val_entry = NULL;
2406 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2407 add_loc_descr (&head, tmp);
2408 if (offset != 0)
2409 {
2410 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
2411 add_loc_descr (&head, tmp);
2412 }
2413 }
2414 else
2415 head = new_reg_loc_descr (cfa->reg, offset);
2416
2417 return head;
2418}
2419
2420/* This function builds a dwarf location descriptor sequence for
2421 the address at OFFSET from the CFA when stack is aligned to
2422 ALIGNMENT byte. */
2423
2424struct dw_loc_descr_node *
2425build_cfa_aligned_loc (dw_cfa_location *cfa,
2426 HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
2427{
2428 struct dw_loc_descr_node *head;
2429 unsigned int dwarf_fp
2430 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
2431
2432 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2433 if (cfa->reg == HARD_FRAME_POINTER_REGNUM && cfa->indirect == 0)
2434 {
2435 head = new_reg_loc_descr (dwarf_fp, 0);
2436 add_loc_descr (&head, int_loc_descriptor (alignment));
2437 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
2438 loc_descr_plus_const (&head, offset);
2439 }
2440 else
2441 head = new_reg_loc_descr (dwarf_fp, offset);
2442 return head;
2443}
2444\f
2445/* And now, the support for symbolic debugging information. */
2446
2447/* .debug_str support. */
2448
2449static void dwarf2out_init (const char *);
2450static void dwarf2out_finish (const char *);
2451static void dwarf2out_assembly_start (void);
2452static void dwarf2out_define (unsigned int, const char *);
2453static void dwarf2out_undef (unsigned int, const char *);
2454static void dwarf2out_start_source_file (unsigned, const char *);
2455static void dwarf2out_end_source_file (unsigned);
2456static void dwarf2out_function_decl (tree);
2457static void dwarf2out_begin_block (unsigned, unsigned);
2458static void dwarf2out_end_block (unsigned, unsigned);
2459static bool dwarf2out_ignore_block (const_tree);
2460static void dwarf2out_global_decl (tree);
2461static void dwarf2out_type_decl (tree, int);
2462static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
2463static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
2464 dw_die_ref);
2465static void dwarf2out_abstract_function (tree);
2466static void dwarf2out_var_location (rtx_insn *);
2467static void dwarf2out_begin_function (tree);
2468static void dwarf2out_end_function (unsigned int);
2469static void dwarf2out_set_name (tree, tree);
2470
2471/* The debug hooks structure. */
2472
2473const struct gcc_debug_hooks dwarf2_debug_hooks =
2474{
2475 dwarf2out_init,
2476 dwarf2out_finish,
2477 dwarf2out_assembly_start,
2478 dwarf2out_define,
2479 dwarf2out_undef,
2480 dwarf2out_start_source_file,
2481 dwarf2out_end_source_file,
2482 dwarf2out_begin_block,
2483 dwarf2out_end_block,
2484 dwarf2out_ignore_block,
2485 dwarf2out_source_line,
2486 dwarf2out_begin_prologue,
2487#if VMS_DEBUGGING_INFO
2488 dwarf2out_vms_end_prologue,
2489 dwarf2out_vms_begin_epilogue,
2490#else
2491 debug_nothing_int_charstar,
2492 debug_nothing_int_charstar,
2493#endif
2494 dwarf2out_end_epilogue,
2495 dwarf2out_begin_function,
2496 dwarf2out_end_function, /* end_function */
2497 dwarf2out_function_decl, /* function_decl */
2498 dwarf2out_global_decl,
2499 dwarf2out_type_decl, /* type_decl */
2500 dwarf2out_imported_module_or_decl,
2501 debug_nothing_tree, /* deferred_inline_function */
2502 /* The DWARF 2 backend tries to reduce debugging bloat by not
2503 emitting the abstract description of inline functions until
2504 something tries to reference them. */
2505 dwarf2out_abstract_function, /* outlining_inline_function */
2506 debug_nothing_rtx_code_label, /* label */
2507 debug_nothing_int, /* handle_pch */
2508 dwarf2out_var_location,
2509 dwarf2out_switch_text_section,
2510 dwarf2out_set_name,
2511 1, /* start_end_main_source_file */
2512 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
2513};
2514\f
2515/* NOTE: In the comments in this file, many references are made to
2516 "Debugging Information Entries". This term is abbreviated as `DIE'
2517 throughout the remainder of this file. */
2518
2519/* An internal representation of the DWARF output is built, and then
2520 walked to generate the DWARF debugging info. The walk of the internal
2521 representation is done after the entire program has been compiled.
2522 The types below are used to describe the internal representation. */
2523
2524/* Whether to put type DIEs into their own section .debug_types instead
2525 of making them part of the .debug_info section. Only supported for
2526 Dwarf V4 or higher and the user didn't disable them through
2527 -fno-debug-types-section. It is more efficient to put them in a
2528 separate comdat sections since the linker will then be able to
2529 remove duplicates. But not all tools support .debug_types sections
2530 yet. */
2531
2532#define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2533
2534/* Various DIE's use offsets relative to the beginning of the
2535 .debug_info section to refer to each other. */
2536
2537typedef long int dw_offset;
2538
2539/* Define typedefs here to avoid circular dependencies. */
2540
2541typedef struct dw_attr_struct *dw_attr_ref;
2542typedef struct dw_line_info_struct *dw_line_info_ref;
2543typedef struct pubname_struct *pubname_ref;
2544typedef struct dw_ranges_struct *dw_ranges_ref;
2545typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
2546typedef struct comdat_type_struct *comdat_type_node_ref;
2547
2548/* The entries in the line_info table more-or-less mirror the opcodes
2549 that are used in the real dwarf line table. Arrays of these entries
2550 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2551 supported. */
2552
2553enum dw_line_info_opcode {
2554 /* Emit DW_LNE_set_address; the operand is the label index. */
2555 LI_set_address,
2556
2557 /* Emit a row to the matrix with the given line. This may be done
2558 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2559 special opcodes. */
2560 LI_set_line,
2561
2562 /* Emit a DW_LNS_set_file. */
2563 LI_set_file,
2564
2565 /* Emit a DW_LNS_set_column. */
2566 LI_set_column,
2567
2568 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2569 LI_negate_stmt,
2570
2571 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2572 LI_set_prologue_end,
2573 LI_set_epilogue_begin,
2574
2575 /* Emit a DW_LNE_set_discriminator. */
2576 LI_set_discriminator
2577};
2578
2579typedef struct GTY(()) dw_line_info_struct {
2580 enum dw_line_info_opcode opcode;
2581 unsigned int val;
2582} dw_line_info_entry;
2583
2584
2585typedef struct GTY(()) dw_line_info_table_struct {
2586 /* The label that marks the end of this section. */
2587 const char *end_label;
2588
2589 /* The values for the last row of the matrix, as collected in the table.
2590 These are used to minimize the changes to the next row. */
2591 unsigned int file_num;
2592 unsigned int line_num;
2593 unsigned int column_num;
2594 int discrim_num;
2595 bool is_stmt;
2596 bool in_use;
2597
2598 vec<dw_line_info_entry, va_gc> *entries;
2599} dw_line_info_table;
2600
2601typedef dw_line_info_table *dw_line_info_table_p;
2602
2603
2604/* Each DIE attribute has a field specifying the attribute kind,
2605 a link to the next attribute in the chain, and an attribute value.
2606 Attributes are typically linked below the DIE they modify. */
2607
2608typedef struct GTY(()) dw_attr_struct {
2609 enum dwarf_attribute dw_attr;
2610 dw_val_node dw_attr_val;
2611}
2612dw_attr_node;
2613
2614
2615/* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2616 The children of each node form a circular list linked by
2617 die_sib. die_child points to the node *before* the "first" child node. */
2618
2619typedef struct GTY((chain_circular ("%h.die_sib"), for_user)) die_struct {
2620 union die_symbol_or_type_node
2621 {
2622 const char * GTY ((tag ("0"))) die_symbol;
2623 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
2624 }
2625 GTY ((desc ("%0.comdat_type_p"))) die_id;
2626 vec<dw_attr_node, va_gc> *die_attr;
2627 dw_die_ref die_parent;
2628 dw_die_ref die_child;
2629 dw_die_ref die_sib;
2630 dw_die_ref die_definition; /* ref from a specification to its definition */
2631 dw_offset die_offset;
2632 unsigned long die_abbrev;
2633 int die_mark;
2634 unsigned int decl_id;
2635 enum dwarf_tag die_tag;
2636 /* Die is used and must not be pruned as unused. */
2637 BOOL_BITFIELD die_perennial_p : 1;
2638 BOOL_BITFIELD comdat_type_p : 1; /* DIE has a type signature */
2639 /* Lots of spare bits. */
2640}
2641die_node;
2642
2643/* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2644#define FOR_EACH_CHILD(die, c, expr) do { \
2645 c = die->die_child; \
2646 if (c) do { \
2647 c = c->die_sib; \
2648 expr; \
2649 } while (c != die->die_child); \
2650} while (0)
2651
2652/* The pubname structure */
2653
2654typedef struct GTY(()) pubname_struct {
2655 dw_die_ref die;
2656 const char *name;
2657}
2658pubname_entry;
2659
2660
2661struct GTY(()) dw_ranges_struct {
2662 /* If this is positive, it's a block number, otherwise it's a
2663 bitwise-negated index into dw_ranges_by_label. */
2664 int num;
2665};
2666
2667/* A structure to hold a macinfo entry. */
2668
2669typedef struct GTY(()) macinfo_struct {
2670 unsigned char code;
2671 unsigned HOST_WIDE_INT lineno;
2672 const char *info;
2673}
2674macinfo_entry;
2675
2676
2677struct GTY(()) dw_ranges_by_label_struct {
2678 const char *begin;
2679 const char *end;
2680};
2681
2682/* The comdat type node structure. */
2683typedef struct GTY(()) comdat_type_struct
2684{
2685 dw_die_ref root_die;
2686 dw_die_ref type_die;
2687 dw_die_ref skeleton_die;
2688 char signature[DWARF_TYPE_SIGNATURE_SIZE];
2689 struct comdat_type_struct *next;
2690}
2691comdat_type_node;
2692
2693/* The limbo die list structure. */
2694typedef struct GTY(()) limbo_die_struct {
2695 dw_die_ref die;
2696 tree created_for;
2697 struct limbo_die_struct *next;
2698}
2699limbo_die_node;
2700
2701typedef struct skeleton_chain_struct
2702{
2703 dw_die_ref old_die;
2704 dw_die_ref new_die;
2705 struct skeleton_chain_struct *parent;
2706}
2707skeleton_chain_node;
2708
2709/* Define a macro which returns nonzero for a TYPE_DECL which was
2710 implicitly generated for a type.
2711
2712 Note that, unlike the C front-end (which generates a NULL named
2713 TYPE_DECL node for each complete tagged type, each array type,
2714 and each function type node created) the C++ front-end generates
2715 a _named_ TYPE_DECL node for each tagged type node created.
2716 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2717 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2718 front-end, but for each type, tagged or not. */
2719
2720#define TYPE_DECL_IS_STUB(decl) \
2721 (DECL_NAME (decl) == NULL_TREE \
2722 || (DECL_ARTIFICIAL (decl) \
2723 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2724 /* This is necessary for stub decls that \
2725 appear in nested inline functions. */ \
2726 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2727 && (decl_ultimate_origin (decl) \
2728 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2729
2730/* Information concerning the compilation unit's programming
2731 language, and compiler version. */
2732
2733/* Fixed size portion of the DWARF compilation unit header. */
2734#define DWARF_COMPILE_UNIT_HEADER_SIZE \
2735 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2736
2737/* Fixed size portion of the DWARF comdat type unit header. */
2738#define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2739 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2740 + DWARF_OFFSET_SIZE)
2741
2742/* Fixed size portion of public names info. */
2743#define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2744
2745/* Fixed size portion of the address range info. */
2746#define DWARF_ARANGES_HEADER_SIZE \
2747 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2748 DWARF2_ADDR_SIZE * 2) \
2749 - DWARF_INITIAL_LENGTH_SIZE)
2750
2751/* Size of padding portion in the address range info. It must be
2752 aligned to twice the pointer size. */
2753#define DWARF_ARANGES_PAD_SIZE \
2754 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2755 DWARF2_ADDR_SIZE * 2) \
2756 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2757
2758/* Use assembler line directives if available. */
2759#ifndef DWARF2_ASM_LINE_DEBUG_INFO
2760#ifdef HAVE_AS_DWARF2_DEBUG_LINE
2761#define DWARF2_ASM_LINE_DEBUG_INFO 1
2762#else
2763#define DWARF2_ASM_LINE_DEBUG_INFO 0
2764#endif
2765#endif
2766
2767/* Minimum line offset in a special line info. opcode.
2768 This value was chosen to give a reasonable range of values. */
2769#define DWARF_LINE_BASE -10
2770
2771/* First special line opcode - leave room for the standard opcodes. */
2772#define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2773
2774/* Range of line offsets in a special line info. opcode. */
2775#define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2776
2777/* Flag that indicates the initial value of the is_stmt_start flag.
2778 In the present implementation, we do not mark any lines as
2779 the beginning of a source statement, because that information
2780 is not made available by the GCC front-end. */
2781#define DWARF_LINE_DEFAULT_IS_STMT_START 1
2782
2783/* Maximum number of operations per instruction bundle. */
2784#ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2785#define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2786#endif
2787
2788/* This location is used by calc_die_sizes() to keep track
2789 the offset of each DIE within the .debug_info section. */
2790static unsigned long next_die_offset;
2791
2792/* Record the root of the DIE's built for the current compilation unit. */
2793static GTY(()) dw_die_ref single_comp_unit_die;
2794
2795/* A list of type DIEs that have been separated into comdat sections. */
2796static GTY(()) comdat_type_node *comdat_type_list;
2797
2798/* A list of DIEs with a NULL parent waiting to be relocated. */
2799static GTY(()) limbo_die_node *limbo_die_list;
2800
2801/* A list of DIEs for which we may have to generate
2802 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2803static GTY(()) limbo_die_node *deferred_asm_name;
2804
2805struct dwarf_file_hasher : ggc_hasher<dwarf_file_data *>
2806{
2807 typedef const char *compare_type;
2808
2809 static hashval_t hash (dwarf_file_data *);
2810 static bool equal (dwarf_file_data *, const char *);
2811};
2812
2813/* Filenames referenced by this compilation unit. */
2814static GTY(()) hash_table<dwarf_file_hasher> *file_table;
2815
2816struct decl_die_hasher : ggc_hasher<die_node *>
2817{
2818 typedef tree compare_type;
2819
2820 static hashval_t hash (die_node *);
2821 static bool equal (die_node *, tree);
2822};
2823/* A hash table of references to DIE's that describe declarations.
2824 The key is a DECL_UID() which is a unique number identifying each decl. */
2825static GTY (()) hash_table<decl_die_hasher> *decl_die_table;
2826
2827struct block_die_hasher : ggc_hasher<die_struct *>
2828{
2829 static hashval_t hash (die_struct *);
2830 static bool equal (die_struct *, die_struct *);
2831};
2832
2833/* A hash table of references to DIE's that describe COMMON blocks.
2834 The key is DECL_UID() ^ die_parent. */
2835static GTY (()) hash_table<block_die_hasher> *common_block_die_table;
2836
2837typedef struct GTY(()) die_arg_entry_struct {
2838 dw_die_ref die;
2839 tree arg;
2840} die_arg_entry;
2841
2842
2843/* Node of the variable location list. */
2844struct GTY ((chain_next ("%h.next"))) var_loc_node {
2845 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2846 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2847 in mode of the EXPR_LIST node and first EXPR_LIST operand
2848 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2849 location or NULL for padding. For larger bitsizes,
2850 mode is 0 and first operand is a CONCAT with bitsize
2851 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2852 NULL as second operand. */
2853 rtx GTY (()) loc;
2854 const char * GTY (()) label;
2855 struct var_loc_node * GTY (()) next;
2856};
2857
2858/* Variable location list. */
2859struct GTY ((for_user)) var_loc_list_def {
2860 struct var_loc_node * GTY (()) first;
2861
2862 /* Pointer to the last but one or last element of the
2863 chained list. If the list is empty, both first and
2864 last are NULL, if the list contains just one node
2865 or the last node certainly is not redundant, it points
2866 to the last node, otherwise points to the last but one.
2867 Do not mark it for GC because it is marked through the chain. */
2868 struct var_loc_node * GTY ((skip ("%h"))) last;
2869
2870 /* Pointer to the last element before section switch,
2871 if NULL, either sections weren't switched or first
2872 is after section switch. */
2873 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
2874
2875 /* DECL_UID of the variable decl. */
2876 unsigned int decl_id;
2877};
2878typedef struct var_loc_list_def var_loc_list;
2879
2880/* Call argument location list. */
2881struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
2882 rtx GTY (()) call_arg_loc_note;
2883 const char * GTY (()) label;
2884 tree GTY (()) block;
2885 bool tail_call_p;
2886 rtx GTY (()) symbol_ref;
2887 struct call_arg_loc_node * GTY (()) next;
2888};
2889
2890
2891struct decl_loc_hasher : ggc_hasher<var_loc_list *>
2892{
2893 typedef const_tree compare_type;
2894
2895 static hashval_t hash (var_loc_list *);
2896 static bool equal (var_loc_list *, const_tree);
2897};
2898
2899/* Table of decl location linked lists. */
2900static GTY (()) hash_table<decl_loc_hasher> *decl_loc_table;
2901
2902/* Head and tail of call_arg_loc chain. */
2903static GTY (()) struct call_arg_loc_node *call_arg_locations;
2904static struct call_arg_loc_node *call_arg_loc_last;
2905
2906/* Number of call sites in the current function. */
2907static int call_site_count = -1;
2908/* Number of tail call sites in the current function. */
2909static int tail_call_site_count = -1;
2910
2911/* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2912 DIEs. */
2913static vec<dw_die_ref> block_map;
2914
2915/* A cached location list. */
2916struct GTY ((for_user)) cached_dw_loc_list_def {
2917 /* The DECL_UID of the decl that this entry describes. */
2918 unsigned int decl_id;
2919
2920 /* The cached location list. */
2921 dw_loc_list_ref loc_list;
2922};
2923typedef struct cached_dw_loc_list_def cached_dw_loc_list;
2924
2925struct dw_loc_list_hasher : ggc_hasher<cached_dw_loc_list *>
2926{
2927
2928 typedef const_tree compare_type;
2929
2930 static hashval_t hash (cached_dw_loc_list *);
2931 static bool equal (cached_dw_loc_list *, const_tree);
2932};
2933
2934/* Table of cached location lists. */
2935static GTY (()) hash_table<dw_loc_list_hasher> *cached_dw_loc_list_table;
2936
2937/* A pointer to the base of a list of references to DIE's that
2938 are uniquely identified by their tag, presence/absence of
2939 children DIE's, and list of attribute/value pairs. */
2940static GTY((length ("abbrev_die_table_allocated")))
2941 dw_die_ref *abbrev_die_table;
2942
2943/* Number of elements currently allocated for abbrev_die_table. */
2944static GTY(()) unsigned abbrev_die_table_allocated;
2945
2946/* Number of elements in type_die_table currently in use. */
2947static GTY(()) unsigned abbrev_die_table_in_use;
2948
2949/* Size (in elements) of increments by which we may expand the
2950 abbrev_die_table. */
2951#define ABBREV_DIE_TABLE_INCREMENT 256
2952
2953/* A global counter for generating labels for line number data. */
2954static unsigned int line_info_label_num;
2955
2956/* The current table to which we should emit line number information
2957 for the current function. This will be set up at the beginning of
2958 assembly for the function. */
2959static dw_line_info_table *cur_line_info_table;
2960
2961/* The two default tables of line number info. */
2962static GTY(()) dw_line_info_table *text_section_line_info;
2963static GTY(()) dw_line_info_table *cold_text_section_line_info;
2964
2965/* The set of all non-default tables of line number info. */
2966static GTY(()) vec<dw_line_info_table_p, va_gc> *separate_line_info;
2967
2968/* A flag to tell pubnames/types export if there is an info section to
2969 refer to. */
2970static bool info_section_emitted;
2971
2972/* A pointer to the base of a table that contains a list of publicly
2973 accessible names. */
2974static GTY (()) vec<pubname_entry, va_gc> *pubname_table;
2975
2976/* A pointer to the base of a table that contains a list of publicly
2977 accessible types. */
2978static GTY (()) vec<pubname_entry, va_gc> *pubtype_table;
2979
2980/* A pointer to the base of a table that contains a list of macro
2981 defines/undefines (and file start/end markers). */
2982static GTY (()) vec<macinfo_entry, va_gc> *macinfo_table;
2983
2984/* True if .debug_macinfo or .debug_macros section is going to be
2985 emitted. */
2986#define have_macinfo \
2987 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2988 && !macinfo_table->is_empty ())
2989
2990/* Array of dies for which we should generate .debug_ranges info. */
2991static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
2992
2993/* Number of elements currently allocated for ranges_table. */
2994static GTY(()) unsigned ranges_table_allocated;
2995
2996/* Number of elements in ranges_table currently in use. */
2997static GTY(()) unsigned ranges_table_in_use;
2998
2999/* Array of pairs of labels referenced in ranges_table. */
3000static GTY ((length ("ranges_by_label_allocated")))
3001 dw_ranges_by_label_ref ranges_by_label;
3002
3003/* Number of elements currently allocated for ranges_by_label. */
3004static GTY(()) unsigned ranges_by_label_allocated;
3005
3006/* Number of elements in ranges_by_label currently in use. */
3007static GTY(()) unsigned ranges_by_label_in_use;
3008
3009/* Size (in elements) of increments by which we may expand the
3010 ranges_table. */
3011#define RANGES_TABLE_INCREMENT 64
3012
3013/* Whether we have location lists that need outputting */
3014static GTY(()) bool have_location_lists;
3015
3016/* Unique label counter. */
3017static GTY(()) unsigned int loclabel_num;
3018
3019/* Unique label counter for point-of-call tables. */
3020static GTY(()) unsigned int poc_label_num;
3021
3022/* The last file entry emitted by maybe_emit_file(). */
3023static GTY(()) struct dwarf_file_data * last_emitted_file;
3024
3025/* Number of internal labels generated by gen_internal_sym(). */
3026static GTY(()) int label_num;
3027
3028/* Cached result of previous call to lookup_filename. */
3029static GTY(()) struct dwarf_file_data * file_table_last_lookup;
3030
3031static GTY(()) vec<die_arg_entry, va_gc> *tmpl_value_parm_die_table;
3032
3033/* Instances of generic types for which we need to generate debug
3034 info that describe their generic parameters and arguments. That
3035 generation needs to happen once all types are properly laid out so
3036 we do it at the end of compilation. */
3037static GTY(()) vec<tree, va_gc> *generic_type_instances;
3038
3039/* Offset from the "steady-state frame pointer" to the frame base,
3040 within the current function. */
3041static HOST_WIDE_INT frame_pointer_fb_offset;
3042static bool frame_pointer_fb_offset_valid;
3043
3044static vec<dw_die_ref> base_types;
3045
3046/* Flags to represent a set of attribute classes for attributes that represent
3047 a scalar value (bounds, pointers, ...). */
3048enum dw_scalar_form
3049{
3050 dw_scalar_form_constant = 0x01,
3051 dw_scalar_form_exprloc = 0x02,
3052 dw_scalar_form_reference = 0x04
3053};
3054
3055/* Forward declarations for functions defined in this file. */
3056
3057static int is_pseudo_reg (const_rtx);
3058static tree type_main_variant (tree);
3059static int is_tagged_type (const_tree);
3060static const char *dwarf_tag_name (unsigned);
3061static const char *dwarf_attr_name (unsigned);
3062static const char *dwarf_form_name (unsigned);
3063static tree decl_ultimate_origin (const_tree);
3064static tree decl_class_context (tree);
3065static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3066static inline enum dw_val_class AT_class (dw_attr_ref);
3067static inline unsigned int AT_index (dw_attr_ref);
3068static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3069static inline unsigned AT_flag (dw_attr_ref);
3070static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3071static inline HOST_WIDE_INT AT_int (dw_attr_ref);
3072static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3073static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
3074static void add_AT_double (dw_die_ref, enum dwarf_attribute,
3075 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
3076static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3077 unsigned int, unsigned char *);
3078static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
3079static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3080static inline const char *AT_string (dw_attr_ref);
3081static enum dwarf_form AT_string_form (dw_attr_ref);
3082static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3083static void add_AT_specification (dw_die_ref, dw_die_ref);
3084static inline dw_die_ref AT_ref (dw_attr_ref);
3085static inline int AT_ref_external (dw_attr_ref);
3086static inline void set_AT_ref_external (dw_attr_ref, int);
3087static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3088static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3089static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3090static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3091 dw_loc_list_ref);
3092static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3093static addr_table_entry *add_addr_table_entry (void *, enum ate_kind);
3094static void remove_addr_table_entry (addr_table_entry *);
3095static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx, bool);
3096static inline rtx AT_addr (dw_attr_ref);
3097static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3098static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
3099static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
3100static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3101 unsigned HOST_WIDE_INT);
3102static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3103 unsigned long, bool);
3104static inline const char *AT_lbl (dw_attr_ref);
3105static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3106static const char *get_AT_low_pc (dw_die_ref);
3107static const char *get_AT_hi_pc (dw_die_ref);
3108static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3109static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3110static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3111static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3112static bool is_cxx (void);
3113static bool is_fortran (void);
3114static bool is_ada (void);
3115static void remove_AT (dw_die_ref, enum dwarf_attribute);
3116static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3117static void add_child_die (dw_die_ref, dw_die_ref);
3118static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3119static dw_die_ref lookup_type_die (tree);
3120static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
3121static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
3122static void equate_type_number_to_die (tree, dw_die_ref);
3123static dw_die_ref lookup_decl_die (tree);
3124static var_loc_list *lookup_decl_loc (const_tree);
3125static void equate_decl_number_to_die (tree, dw_die_ref);
3126static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
3127static void print_spaces (FILE *);
3128static void print_die (dw_die_ref, FILE *);
3129static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3130static dw_die_ref pop_compile_unit (dw_die_ref);
3131static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3132static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3133static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3134static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
3135static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
3136static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
3137static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
3138 struct md5_ctx *, int *);
3139struct checksum_attributes;
3140static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
3141static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
3142static void checksum_die_context (dw_die_ref, struct md5_ctx *);
3143static void generate_type_signature (dw_die_ref, comdat_type_node *);
3144static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3145static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
3146static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3147static int same_die_p (dw_die_ref, dw_die_ref, int *);
3148static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3149static void compute_section_prefix (dw_die_ref);
3150static int is_type_die (dw_die_ref);
3151static int is_comdat_die (dw_die_ref);
3152static int is_symbol_die (dw_die_ref);
3153static inline bool is_template_instantiation (dw_die_ref);
3154static void assign_symbol_names (dw_die_ref);
3155static void break_out_includes (dw_die_ref);
3156static int is_declaration_die (dw_die_ref);
3157static int should_move_die_to_comdat (dw_die_ref);
3158static dw_die_ref clone_as_declaration (dw_die_ref);
3159static dw_die_ref clone_die (dw_die_ref);
3160static dw_die_ref clone_tree (dw_die_ref);
3161static dw_die_ref copy_declaration_context (dw_die_ref, dw_die_ref);
3162static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
3163static void generate_skeleton_bottom_up (skeleton_chain_node *);
3164static dw_die_ref generate_skeleton (dw_die_ref);
3165static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
3166 dw_die_ref,
3167 dw_die_ref);
3168static void break_out_comdat_types (dw_die_ref);
3169static void copy_decls_for_unworthy_types (dw_die_ref);
3170
3171static void add_sibling_attributes (dw_die_ref);
3172static void output_location_lists (dw_die_ref);
3173static int constant_size (unsigned HOST_WIDE_INT);
3174static unsigned long size_of_die (dw_die_ref);
3175static void calc_die_sizes (dw_die_ref);
3176static void calc_base_type_die_sizes (void);
3177static void mark_dies (dw_die_ref);
3178static void unmark_dies (dw_die_ref);
3179static void unmark_all_dies (dw_die_ref);
3180static unsigned long size_of_pubnames (vec<pubname_entry, va_gc> *);
3181static unsigned long size_of_aranges (void);
3182static enum dwarf_form value_format (dw_attr_ref);
3183static void output_value_format (dw_attr_ref);
3184static void output_abbrev_section (void);
3185static void output_die_abbrevs (unsigned long, dw_die_ref);
3186static void output_die_symbol (dw_die_ref);
3187static void output_die (dw_die_ref);
3188static void output_compilation_unit_header (void);
3189static void output_comp_unit (dw_die_ref, int);
3190static void output_comdat_type_unit (comdat_type_node *);
3191static const char *dwarf2_name (tree, int);
3192static void add_pubname (tree, dw_die_ref);
3193static void add_enumerator_pubname (const char *, dw_die_ref);
3194static void add_pubname_string (const char *, dw_die_ref);
3195static void add_pubtype (tree, dw_die_ref);
3196static void output_pubnames (vec<pubname_entry, va_gc> *);
3197static void output_aranges (unsigned long);
3198static unsigned int add_ranges_num (int);
3199static unsigned int add_ranges (const_tree);
3200static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
3201 bool *, bool);
3202static void output_ranges (void);
3203static dw_line_info_table *new_line_info_table (void);
3204static void output_line_info (bool);
3205static void output_file_names (void);
3206static dw_die_ref base_type_die (tree);
3207static int is_base_type (tree);
3208static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
3209static int decl_quals (const_tree);
3210static dw_die_ref modified_type_die (tree, int, dw_die_ref);
3211static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
3212static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
3213static int type_is_enum (const_tree);
3214static unsigned int dbx_reg_number (const_rtx);
3215static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
3216static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
3217static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
3218 enum var_init_status);
3219static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
3220 enum var_init_status);
3221static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
3222 enum var_init_status);
3223static int is_based_loc (const_rtx);
3224static bool resolve_one_addr (rtx *);
3225static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
3226 enum var_init_status);
3227static dw_loc_descr_ref loc_descriptor (rtx, machine_mode mode,
3228 enum var_init_status);
3229struct loc_descr_context;
3230static dw_loc_list_ref loc_list_from_tree (tree, int,
3231 const struct loc_descr_context *);
3232static dw_loc_descr_ref loc_descriptor_from_tree (tree, int,
3233 const struct loc_descr_context *);
3234static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3235static tree field_type (const_tree);
3236static unsigned int simple_type_align_in_bits (const_tree);
3237static unsigned int simple_decl_align_in_bits (const_tree);
3238static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
3239static HOST_WIDE_INT field_byte_offset (const_tree);
3240static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3241 dw_loc_list_ref);
3242static void add_data_member_location_attribute (dw_die_ref, tree);
3243static bool add_const_value_attribute (dw_die_ref, rtx);
3244static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3245static void insert_wide_int (const wide_int &, unsigned char *, int);
3246static void insert_float (const_rtx, unsigned char *);
3247static rtx rtl_for_decl_location (tree);
3248static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
3249 enum dwarf_attribute);
3250static bool tree_add_const_value_attribute (dw_die_ref, tree);
3251static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
3252static void add_name_attribute (dw_die_ref, const char *);
3253static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
3254static void add_comp_dir_attribute (dw_die_ref);
3255static void add_scalar_info (dw_die_ref, enum dwarf_attribute, tree, int,
3256 const struct loc_descr_context *);
3257static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree,
3258 const struct loc_descr_context *);
3259static void add_subscript_info (dw_die_ref, tree, bool);
3260static void add_byte_size_attribute (dw_die_ref, tree);
3261static void add_bit_offset_attribute (dw_die_ref, tree);
3262static void add_bit_size_attribute (dw_die_ref, tree);
3263static void add_prototyped_attribute (dw_die_ref, tree);
3264static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
3265static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3266static void add_src_coords_attributes (dw_die_ref, tree);
3267static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3268static void push_decl_scope (tree);
3269static void pop_decl_scope (void);
3270static dw_die_ref scope_die_for (tree, dw_die_ref);
3271static inline int local_scope_p (dw_die_ref);
3272static inline int class_scope_p (dw_die_ref);
3273static inline int class_or_namespace_scope_p (dw_die_ref);
3274static void add_type_attribute (dw_die_ref, tree, int, dw_die_ref);
3275static void add_calling_convention_attribute (dw_die_ref, tree);
3276static const char *type_tag (const_tree);
3277static tree member_declared_type (const_tree);
3278#if 0
3279static const char *decl_start_label (tree);
3280#endif
3281static void gen_array_type_die (tree, dw_die_ref);
3282static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
3283#if 0
3284static void gen_entry_point_die (tree, dw_die_ref);
3285#endif
3286static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
3287static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
3288static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
3289static void gen_unspecified_parameters_die (tree, dw_die_ref);
3290static void gen_formal_types_die (tree, dw_die_ref);
3291static void gen_subprogram_die (tree, dw_die_ref);
3292static void gen_variable_die (tree, tree, dw_die_ref);
3293static void gen_const_die (tree, dw_die_ref);
3294static void gen_label_die (tree, dw_die_ref);
3295static void gen_lexical_block_die (tree, dw_die_ref);
3296static void gen_inlined_subroutine_die (tree, dw_die_ref);
3297static void gen_field_die (tree, dw_die_ref);
3298static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3299static dw_die_ref gen_compile_unit_die (const char *);
3300static void gen_inheritance_die (tree, tree, dw_die_ref);
3301static void gen_member_die (tree, dw_die_ref);
3302static void gen_struct_or_union_type_die (tree, dw_die_ref,
3303 enum debug_info_usage);
3304static void gen_subroutine_type_die (tree, dw_die_ref);
3305static void gen_typedef_die (tree, dw_die_ref);
3306static void gen_type_die (tree, dw_die_ref);
3307static void gen_block_die (tree, dw_die_ref);
3308static void decls_for_scope (tree, dw_die_ref);
3309static inline int is_redundant_typedef (const_tree);
3310static bool is_naming_typedef_decl (const_tree);
3311static inline dw_die_ref get_context_die (tree);
3312static void gen_namespace_die (tree, dw_die_ref);
3313static dw_die_ref gen_namelist_decl (tree, dw_die_ref, tree);
3314static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
3315static dw_die_ref force_decl_die (tree);
3316static dw_die_ref force_type_die (tree);
3317static dw_die_ref setup_namespace_context (tree, dw_die_ref);
3318static dw_die_ref declare_in_namespace (tree, dw_die_ref);
3319static struct dwarf_file_data * lookup_filename (const char *);
3320static void retry_incomplete_types (void);
3321static void gen_type_die_for_member (tree, tree, dw_die_ref);
3322static void gen_generic_params_dies (tree);
3323static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
3324static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
3325static void splice_child_die (dw_die_ref, dw_die_ref);
3326static int file_info_cmp (const void *, const void *);
3327static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
3328 const char *, const char *);
3329static void output_loc_list (dw_loc_list_ref);
3330static char *gen_internal_sym (const char *);
3331static bool want_pubnames (void);
3332
3333static void prune_unmark_dies (dw_die_ref);
3334static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
3335static void prune_unused_types_mark (dw_die_ref, int);
3336static void prune_unused_types_walk (dw_die_ref);
3337static void prune_unused_types_walk_attribs (dw_die_ref);
3338static void prune_unused_types_prune (dw_die_ref);
3339static void prune_unused_types (void);
3340static int maybe_emit_file (struct dwarf_file_data *fd);
3341static inline const char *AT_vms_delta1 (dw_attr_ref);
3342static inline const char *AT_vms_delta2 (dw_attr_ref);
3343static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
3344 const char *, const char *);
3345static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
3346static void gen_remaining_tmpl_value_param_die_attribute (void);
3347static bool generic_type_p (tree);
3348static void schedule_generic_params_dies_gen (tree t);
3349static void gen_scheduled_generic_parms_dies (void);
3350
3351static const char *comp_dir_string (void);
3352
3353static void hash_loc_operands (dw_loc_descr_ref, inchash::hash &);
3354
3355/* enum for tracking thread-local variables whose address is really an offset
3356 relative to the TLS pointer, which will need link-time relocation, but will
3357 not need relocation by the DWARF consumer. */
3358
3359enum dtprel_bool
3360{
3361 dtprel_false = 0,
3362 dtprel_true = 1
3363};
3364
3365/* Return the operator to use for an address of a variable. For dtprel_true, we
3366 use DW_OP_const*. For regular variables, which need both link-time
3367 relocation and consumer-level relocation (e.g., to account for shared objects
3368 loaded at a random address), we use DW_OP_addr*. */
3369
3370static inline enum dwarf_location_atom
3371dw_addr_op (enum dtprel_bool dtprel)
3372{
3373 if (dtprel == dtprel_true)
3374 return (dwarf_split_debug_info ? DW_OP_GNU_const_index
3375 : (DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u));
3376 else
3377 return dwarf_split_debug_info ? DW_OP_GNU_addr_index : DW_OP_addr;
3378}
3379
3380/* Return a pointer to a newly allocated address location description. If
3381 dwarf_split_debug_info is true, then record the address with the appropriate
3382 relocation. */
3383static inline dw_loc_descr_ref
3384new_addr_loc_descr (rtx addr, enum dtprel_bool dtprel)
3385{
3386 dw_loc_descr_ref ref = new_loc_descr (dw_addr_op (dtprel), 0, 0);
3387
3388 ref->dw_loc_oprnd1.val_class = dw_val_class_addr;
3389 ref->dw_loc_oprnd1.v.val_addr = addr;
3390 ref->dtprel = dtprel;
3391 if (dwarf_split_debug_info)
3392 ref->dw_loc_oprnd1.val_entry
3393 = add_addr_table_entry (addr,
3394 dtprel ? ate_kind_rtx_dtprel : ate_kind_rtx);
3395 else
3396 ref->dw_loc_oprnd1.val_entry = NULL;
3397
3398 return ref;
3399}
3400
3401/* Section names used to hold DWARF debugging information. */
3402
3403#ifndef DEBUG_INFO_SECTION
3404#define DEBUG_INFO_SECTION ".debug_info"
3405#endif
3406#ifndef DEBUG_DWO_INFO_SECTION
3407#define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3408#endif
3409#ifndef DEBUG_ABBREV_SECTION
3410#define DEBUG_ABBREV_SECTION ".debug_abbrev"
3411#endif
3412#ifndef DEBUG_DWO_ABBREV_SECTION
3413#define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3414#endif
3415#ifndef DEBUG_ARANGES_SECTION
3416#define DEBUG_ARANGES_SECTION ".debug_aranges"
3417#endif
3418#ifndef DEBUG_ADDR_SECTION
3419#define DEBUG_ADDR_SECTION ".debug_addr"
3420#endif
3421#ifndef DEBUG_NORM_MACINFO_SECTION
3422#define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3423#endif
3424#ifndef DEBUG_DWO_MACINFO_SECTION
3425#define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3426#endif
3427#ifndef DEBUG_MACINFO_SECTION
3428#define DEBUG_MACINFO_SECTION \
3429 (!dwarf_split_debug_info \
3430 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3431#endif
3432#ifndef DEBUG_NORM_MACRO_SECTION
3433#define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3434#endif
3435#ifndef DEBUG_DWO_MACRO_SECTION
3436#define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3437#endif
3438#ifndef DEBUG_MACRO_SECTION
3439#define DEBUG_MACRO_SECTION \
3440 (!dwarf_split_debug_info \
3441 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3442#endif
3443#ifndef DEBUG_LINE_SECTION
3444#define DEBUG_LINE_SECTION ".debug_line"
3445#endif
3446#ifndef DEBUG_DWO_LINE_SECTION
3447#define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3448#endif
3449#ifndef DEBUG_LOC_SECTION
3450#define DEBUG_LOC_SECTION ".debug_loc"
3451#endif
3452#ifndef DEBUG_DWO_LOC_SECTION
3453#define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3454#endif
3455#ifndef DEBUG_PUBNAMES_SECTION
3456#define DEBUG_PUBNAMES_SECTION \
3457 ((debug_generate_pub_sections == 2) \
3458 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3459#endif
3460#ifndef DEBUG_PUBTYPES_SECTION
3461#define DEBUG_PUBTYPES_SECTION \
3462 ((debug_generate_pub_sections == 2) \
3463 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3464#endif
3465#define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3466#define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3467#ifndef DEBUG_STR_OFFSETS_SECTION
3468#define DEBUG_STR_OFFSETS_SECTION \
3469 (!dwarf_split_debug_info \
3470 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3471#endif
3472#ifndef DEBUG_STR_DWO_SECTION
3473#define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3474#endif
3475#ifndef DEBUG_STR_SECTION
3476#define DEBUG_STR_SECTION ".debug_str"
3477#endif
3478#ifndef DEBUG_RANGES_SECTION
3479#define DEBUG_RANGES_SECTION ".debug_ranges"
3480#endif
3481
3482/* Standard ELF section names for compiled code and data. */
3483#ifndef TEXT_SECTION_NAME
3484#define TEXT_SECTION_NAME ".text"
3485#endif
3486
3487/* Section flags for .debug_macinfo/.debug_macro section. */
3488#define DEBUG_MACRO_SECTION_FLAGS \
3489 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3490
3491/* Section flags for .debug_str section. */
3492#define DEBUG_STR_SECTION_FLAGS \
3493 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3494 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3495 : SECTION_DEBUG)
3496
3497/* Section flags for .debug_str.dwo section. */
3498#define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3499
3500/* Labels we insert at beginning sections we can reference instead of
3501 the section names themselves. */
3502
3503#ifndef TEXT_SECTION_LABEL
3504#define TEXT_SECTION_LABEL "Ltext"
3505#endif
3506#ifndef COLD_TEXT_SECTION_LABEL
3507#define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3508#endif
3509#ifndef DEBUG_LINE_SECTION_LABEL
3510#define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3511#endif
3512#ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3513#define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3514#endif
3515#ifndef DEBUG_INFO_SECTION_LABEL
3516#define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3517#endif
3518#ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3519#define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3520#endif
3521#ifndef DEBUG_ABBREV_SECTION_LABEL
3522#define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3523#endif
3524#ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3525#define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3526#endif
3527#ifndef DEBUG_ADDR_SECTION_LABEL
3528#define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3529#endif
3530#ifndef DEBUG_LOC_SECTION_LABEL
3531#define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3532#endif
3533#ifndef DEBUG_RANGES_SECTION_LABEL
3534#define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3535#endif
3536#ifndef DEBUG_MACINFO_SECTION_LABEL
3537#define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3538#endif
3539#ifndef DEBUG_MACRO_SECTION_LABEL
3540#define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3541#endif
3542#define SKELETON_COMP_DIE_ABBREV 1
3543#define SKELETON_TYPE_DIE_ABBREV 2
3544
3545/* Definitions of defaults for formats and names of various special
3546 (artificial) labels which may be generated within this file (when the -g
3547 options is used and DWARF2_DEBUGGING_INFO is in effect.
3548 If necessary, these may be overridden from within the tm.h file, but
3549 typically, overriding these defaults is unnecessary. */
3550
3551static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3552static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3553static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3554static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3555static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3556static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3557static char debug_skeleton_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3558static char debug_skeleton_abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3559static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3560static char debug_addr_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3561static char debug_skeleton_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3562static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3563static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3564static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3565
3566#ifndef TEXT_END_LABEL
3567#define TEXT_END_LABEL "Letext"
3568#endif
3569#ifndef COLD_END_LABEL
3570#define COLD_END_LABEL "Letext_cold"
3571#endif
3572#ifndef BLOCK_BEGIN_LABEL
3573#define BLOCK_BEGIN_LABEL "LBB"
3574#endif
3575#ifndef BLOCK_END_LABEL
3576#define BLOCK_END_LABEL "LBE"
3577#endif
3578#ifndef LINE_CODE_LABEL
3579#define LINE_CODE_LABEL "LM"
3580#endif
3581
3582\f
3583/* Return the root of the DIE's built for the current compilation unit. */
3584static dw_die_ref
3585comp_unit_die (void)
3586{
3587 if (!single_comp_unit_die)
3588 single_comp_unit_die = gen_compile_unit_die (NULL);
3589 return single_comp_unit_die;
3590}
3591
3592/* We allow a language front-end to designate a function that is to be
3593 called to "demangle" any name before it is put into a DIE. */
3594
3595static const char *(*demangle_name_func) (const char *);
3596
3597void
3598dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
3599{
3600 demangle_name_func = func;
3601}
3602
3603/* Test if rtl node points to a pseudo register. */
3604
3605static inline int
3606is_pseudo_reg (const_rtx rtl)
3607{
3608 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3609 || (GET_CODE (rtl) == SUBREG
3610 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3611}
3612
3613/* Return a reference to a type, with its const and volatile qualifiers
3614 removed. */
3615
3616static inline tree
3617type_main_variant (tree type)
3618{
3619 type = TYPE_MAIN_VARIANT (type);
3620
3621 /* ??? There really should be only one main variant among any group of
3622 variants of a given type (and all of the MAIN_VARIANT values for all
3623 members of the group should point to that one type) but sometimes the C
3624 front-end messes this up for array types, so we work around that bug
3625 here. */
3626 if (TREE_CODE (type) == ARRAY_TYPE)
3627 while (type != TYPE_MAIN_VARIANT (type))
3628 type = TYPE_MAIN_VARIANT (type);
3629
3630 return type;
3631}
3632
3633/* Return nonzero if the given type node represents a tagged type. */
3634
3635static inline int
3636is_tagged_type (const_tree type)
3637{
3638 enum tree_code code = TREE_CODE (type);
3639
3640 return (code == RECORD_TYPE || code == UNION_TYPE
3641 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3642}
3643
3644/* Set label to debug_info_section_label + die_offset of a DIE reference. */
3645
3646static void
3647get_ref_die_offset_label (char *label, dw_die_ref ref)
3648{
3649 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
3650}
3651
3652/* Return die_offset of a DIE reference to a base type. */
3653
3654static unsigned long int
3655get_base_type_offset (dw_die_ref ref)
3656{
3657 if (ref->die_offset)
3658 return ref->die_offset;
3659 if (comp_unit_die ()->die_abbrev)
3660 {
3661 calc_base_type_die_sizes ();
3662 gcc_assert (ref->die_offset);
3663 }
3664 return ref->die_offset;
3665}
3666
3667/* Return die_offset of a DIE reference other than base type. */
3668
3669static unsigned long int
3670get_ref_die_offset (dw_die_ref ref)
3671{
3672 gcc_assert (ref->die_offset);
3673 return ref->die_offset;
3674}
3675
3676/* Convert a DIE tag into its string name. */
3677
3678static const char *
3679dwarf_tag_name (unsigned int tag)
3680{
3681 const char *name = get_DW_TAG_name (tag);
3682
3683 if (name != NULL)
3684 return name;
3685
3686 return "DW_TAG_<unknown>";
3687}
3688
3689/* Convert a DWARF attribute code into its string name. */
3690
3691static const char *
3692dwarf_attr_name (unsigned int attr)
3693{
3694 const char *name;
3695
3696 switch (attr)
3697 {
3698#if VMS_DEBUGGING_INFO
3699 case DW_AT_HP_prologue:
3700 return "DW_AT_HP_prologue";
3701#else
3702 case DW_AT_MIPS_loop_unroll_factor:
3703 return "DW_AT_MIPS_loop_unroll_factor";
3704#endif
3705
3706#if VMS_DEBUGGING_INFO
3707 case DW_AT_HP_epilogue:
3708 return "DW_AT_HP_epilogue";
3709#else
3710 case DW_AT_MIPS_stride:
3711 return "DW_AT_MIPS_stride";
3712#endif
3713 }
3714
3715 name = get_DW_AT_name (attr);
3716
3717 if (name != NULL)
3718 return name;
3719
3720 return "DW_AT_<unknown>";
3721}
3722
3723/* Convert a DWARF value form code into its string name. */
3724
3725static const char *
3726dwarf_form_name (unsigned int form)
3727{
3728 const char *name = get_DW_FORM_name (form);
3729
3730 if (name != NULL)
3731 return name;
3732
3733 return "DW_FORM_<unknown>";
3734}
3735\f
3736/* Determine the "ultimate origin" of a decl. The decl may be an inlined
3737 instance of an inlined instance of a decl which is local to an inline
3738 function, so we have to trace all of the way back through the origin chain
3739 to find out what sort of node actually served as the original seed for the
3740 given block. */
3741
3742static tree
3743decl_ultimate_origin (const_tree decl)
3744{
3745 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
3746 return NULL_TREE;
3747
3748 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
3749 we're trying to output the abstract instance of this function. */
3750 if (DECL_ABSTRACT_P (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
3751 return NULL_TREE;
3752
3753 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3754 most distant ancestor, this should never happen. */
3755 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
3756
3757 return DECL_ABSTRACT_ORIGIN (decl);
3758}
3759
3760/* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3761 of a virtual function may refer to a base class, so we check the 'this'
3762 parameter. */
3763
3764static tree
3765decl_class_context (tree decl)
3766{
3767 tree context = NULL_TREE;
3768
3769 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3770 context = DECL_CONTEXT (decl);
3771 else
3772 context = TYPE_MAIN_VARIANT
3773 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3774
3775 if (context && !TYPE_P (context))
3776 context = NULL_TREE;
3777
3778 return context;
3779}
3780\f
3781/* Add an attribute/value pair to a DIE. */
3782
3783static inline void
3784add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
3785{
3786 /* Maybe this should be an assert? */
3787 if (die == NULL)
3788 return;
3789
3790 vec_safe_reserve (die->die_attr, 1);
3791 vec_safe_push (die->die_attr, *attr);
3792}
3793
3794static inline enum dw_val_class
3795AT_class (dw_attr_ref a)
3796{
3797 return a->dw_attr_val.val_class;
3798}
3799
3800/* Return the index for any attribute that will be referenced with a
3801 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3802 are stored in dw_attr_val.v.val_str for reference counting
3803 pruning. */
3804
3805static inline unsigned int
3806AT_index (dw_attr_ref a)
3807{
3808 if (AT_class (a) == dw_val_class_str)
3809 return a->dw_attr_val.v.val_str->index;
3810 else if (a->dw_attr_val.val_entry != NULL)
3811 return a->dw_attr_val.val_entry->index;
3812 return NOT_INDEXED;
3813}
3814
3815/* Add a flag value attribute to a DIE. */
3816
3817static inline void
3818add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
3819{
3820 dw_attr_node attr;
3821
3822 attr.dw_attr = attr_kind;
3823 attr.dw_attr_val.val_class = dw_val_class_flag;
3824 attr.dw_attr_val.val_entry = NULL;
3825 attr.dw_attr_val.v.val_flag = flag;
3826 add_dwarf_attr (die, &attr);
3827}
3828
3829static inline unsigned
3830AT_flag (dw_attr_ref a)
3831{
3832 gcc_assert (a && AT_class (a) == dw_val_class_flag);
3833 return a->dw_attr_val.v.val_flag;
3834}
3835
3836/* Add a signed integer attribute value to a DIE. */
3837
3838static inline void
3839add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
3840{
3841 dw_attr_node attr;
3842
3843 attr.dw_attr = attr_kind;
3844 attr.dw_attr_val.val_class = dw_val_class_const;
3845 attr.dw_attr_val.val_entry = NULL;
3846 attr.dw_attr_val.v.val_int = int_val;
3847 add_dwarf_attr (die, &attr);
3848}
3849
3850static inline HOST_WIDE_INT
3851AT_int (dw_attr_ref a)
3852{
3853 gcc_assert (a && AT_class (a) == dw_val_class_const);
3854 return a->dw_attr_val.v.val_int;
3855}
3856
3857/* Add an unsigned integer attribute value to a DIE. */
3858
3859static inline void
3860add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
3861 unsigned HOST_WIDE_INT unsigned_val)
3862{
3863 dw_attr_node attr;
3864
3865 attr.dw_attr = attr_kind;
3866 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
3867 attr.dw_attr_val.val_entry = NULL;
3868 attr.dw_attr_val.v.val_unsigned = unsigned_val;
3869 add_dwarf_attr (die, &attr);
3870}
3871
3872static inline unsigned HOST_WIDE_INT
3873AT_unsigned (dw_attr_ref a)
3874{
3875 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
3876 return a->dw_attr_val.v.val_unsigned;
3877}
3878
3879/* Add an unsigned wide integer attribute value to a DIE. */
3880
3881static inline void
3882add_AT_wide (dw_die_ref die, enum dwarf_attribute attr_kind,
3883 const wide_int& w)
3884{
3885 dw_attr_node attr;
3886
3887 attr.dw_attr = attr_kind;
3888 attr.dw_attr_val.val_class = dw_val_class_wide_int;
3d987775 3889 attr.dw_attr_val.val_entry = NULL;
dda118e3
JM
3890 attr.dw_attr_val.v.val_wide = ggc_alloc<wide_int> ();
3891 *attr.dw_attr_val.v.val_wide = w;
3892 add_dwarf_attr (die, &attr);
3893}
3894
3895/* Add an unsigned double integer attribute value to a DIE. */
3896
3897static inline void
3898add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
3899 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
3900{
3901 dw_attr_node attr;
3902
3903 attr.dw_attr = attr_kind;
3904 attr.dw_attr_val.val_class = dw_val_class_const_double;
3905 attr.dw_attr_val.val_entry = NULL;
3906 attr.dw_attr_val.v.val_double.high = high;
3907