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