1/* dwarf2out.h - Various declarations for functions found in dwarf2out.c
2   Copyright (C) 1998-2020 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3.  If not see
18<http://www.gnu.org/licenses/>.  */
19
20#ifndef GCC_DWARF2OUT_H
21#define GCC_DWARF2OUT_H 1
22
23#include "dwarf2.h"	/* ??? Remove this once only used by dwarf2foo.c.  */
24
25typedef struct die_struct *dw_die_ref;
26typedef const struct die_struct *const_dw_die_ref;
27
28typedef struct dw_val_node *dw_val_ref;
29typedef struct dw_cfi_node *dw_cfi_ref;
30typedef struct dw_loc_descr_node *dw_loc_descr_ref;
31typedef struct dw_loc_list_struct *dw_loc_list_ref;
32typedef struct dw_discr_list_node *dw_discr_list_ref;
33typedef wide_int *wide_int_ptr;
34
35
36/* Call frames are described using a sequence of Call Frame
37   Information instructions.  The register number, offset
38   and address fields are provided as possible operands;
39   their use is selected by the opcode field.  */
40
41enum dw_cfi_oprnd_type {
42  dw_cfi_oprnd_unused,
43  dw_cfi_oprnd_reg_num,
44  dw_cfi_oprnd_offset,
45  dw_cfi_oprnd_addr,
46  dw_cfi_oprnd_loc,
47  dw_cfi_oprnd_cfa_loc
48};
49
50typedef union GTY(()) {
51  unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
52  HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
53  const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
54  struct dw_loc_descr_node * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
55  struct dw_cfa_location * GTY ((tag ("dw_cfi_oprnd_cfa_loc")))
56    dw_cfi_cfa_loc;
57} dw_cfi_oprnd;
58
59struct GTY(()) dw_cfi_node {
60  enum dwarf_call_frame_info dw_cfi_opc;
61  dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
62    dw_cfi_oprnd1;
63  dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
64    dw_cfi_oprnd2;
65};
66
67
68typedef vec<dw_cfi_ref, va_gc> *cfi_vec;
69
70typedef struct dw_fde_node *dw_fde_ref;
71
72/* All call frame descriptions (FDE's) in the GCC generated DWARF
73   refer to a single Common Information Entry (CIE), defined at
74   the beginning of the .debug_frame section.  This use of a single
75   CIE obviates the need to keep track of multiple CIE's
76   in the DWARF generation routines below.  */
77
78struct GTY(()) dw_fde_node {
79  tree decl;
80  const char *dw_fde_begin;
81  const char *dw_fde_current_label;
82  const char *dw_fde_end;
83  const char *dw_fde_vms_end_prologue;
84  const char *dw_fde_vms_begin_epilogue;
85  const char *dw_fde_second_begin;
86  const char *dw_fde_second_end;
87  cfi_vec dw_fde_cfi;
88  int dw_fde_switch_cfi_index; /* Last CFI before switching sections.  */
89  HOST_WIDE_INT stack_realignment;
90
91  unsigned funcdef_number;
92  unsigned fde_index;
93
94  /* Dynamic realign argument pointer register.  */
95  unsigned int drap_reg;
96  /* Virtual dynamic realign argument pointer register.  */
97  unsigned int vdrap_reg;
98  /* These 3 flags are copied from rtl_data in function.h.  */
99  unsigned all_throwers_are_sibcalls : 1;
100  unsigned uses_eh_lsda : 1;
101  unsigned nothrow : 1;
102  /* Whether we did stack realign in this call frame.  */
103  unsigned stack_realign : 1;
104  /* Whether dynamic realign argument pointer register has been saved.  */
105  unsigned drap_reg_saved: 1;
106  /* True iff dw_fde_begin label is in text_section or cold_text_section.  */
107  unsigned in_std_section : 1;
108  /* True iff dw_fde_second_begin label is in text_section or
109     cold_text_section.  */
110  unsigned second_in_std_section : 1;
111  /* True if Rule 18 described in dwarf2cfi.c is in action, i.e. for dynamic
112     stack realignment in between pushing of hard frame pointer to stack
113     and setting hard frame pointer to stack pointer.  The register save for
114     hard frame pointer register should be emitted only on the latter
115     instruction.  */
116  unsigned rule18 : 1;
117};
118
119
120/* This is how we define the location of the CFA. We use to handle it
121   as REG + OFFSET all the time,  but now it can be more complex.
122   It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
123   Instead of passing around REG and OFFSET, we pass a copy
124   of this structure.  */
125struct GTY(()) dw_cfa_location {
126  poly_int64_pod offset;
127  poly_int64_pod base_offset;
128  /* REG is in DWARF_FRAME_REGNUM space, *not* normal REGNO space.  */
129  unsigned int reg;
130  BOOL_BITFIELD indirect : 1;  /* 1 if CFA is accessed via a dereference.  */
131  BOOL_BITFIELD in_use : 1;    /* 1 if a saved cfa is stored here.  */
132};
133
134
135/* Each DIE may have a series of attribute/value pairs.  Values
136   can take on several forms.  The forms that are used in this
137   implementation are listed below.  */
138
139enum dw_val_class
140{
141  dw_val_class_none,
142  dw_val_class_addr,
143  dw_val_class_offset,
144  dw_val_class_loc,
145  dw_val_class_loc_list,
146  dw_val_class_range_list,
147  dw_val_class_const,
148  dw_val_class_unsigned_const,
149  dw_val_class_const_double,
150  dw_val_class_wide_int,
151  dw_val_class_vec,
152  dw_val_class_flag,
153  dw_val_class_die_ref,
154  dw_val_class_fde_ref,
155  dw_val_class_lbl_id,
156  dw_val_class_lineptr,
157  dw_val_class_str,
158  dw_val_class_macptr,
159  dw_val_class_loclistsptr,
160  dw_val_class_file,
161  dw_val_class_data8,
162  dw_val_class_decl_ref,
163  dw_val_class_vms_delta,
164  dw_val_class_high_pc,
165  dw_val_class_discr_value,
166  dw_val_class_discr_list,
167  dw_val_class_const_implicit,
168  dw_val_class_unsigned_const_implicit,
169  dw_val_class_file_implicit,
170  dw_val_class_view_list,
171  dw_val_class_symview
172};
173
174/* Describe a floating point constant value, or a vector constant value.  */
175
176struct GTY(()) dw_vec_const {
177  void * GTY((atomic)) array;
178  unsigned length;
179  unsigned elt_size;
180};
181
182/* Describe a single value that a discriminant can match.
183
184   Discriminants (in the "record variant part" meaning) are scalars.
185   dw_discr_list_ref and dw_discr_value are a mean to describe a set of
186   discriminant values that are matched by a particular variant.
187
188   Discriminants can be signed or unsigned scalars, and can be discriminants
189   values.  Both have to be consistent, though.  */
190
191struct GTY(()) dw_discr_value {
192  int pos; /* Whether the discriminant value is positive (unsigned).  */
193  union
194    {
195      HOST_WIDE_INT GTY ((tag ("0"))) sval;
196      unsigned HOST_WIDE_INT GTY ((tag ("1"))) uval;
197    }
198  GTY ((desc ("%1.pos"))) v;
199};
200
201struct addr_table_entry;
202
203/* The dw_val_node describes an attribute's value, as it is
204   represented internally.  */
205
206struct GTY(()) dw_val_node {
207  enum dw_val_class val_class;
208  struct addr_table_entry * GTY(()) val_entry;
209  union dw_val_struct_union
210    {
211      rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
212      unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
213      dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
214      dw_die_ref GTY ((tag ("dw_val_class_view_list"))) val_view_list;
215      dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
216      HOST_WIDE_INT GTY ((default)) val_int;
217      unsigned HOST_WIDE_INT
218	GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
219      double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
220      wide_int_ptr GTY ((tag ("dw_val_class_wide_int"))) val_wide;
221      dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
222      struct dw_val_die_union
223	{
224	  dw_die_ref die;
225	  int external;
226	} GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
227      unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
228      struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
229      char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
230      unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
231      struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
232      struct dwarf_file_data *
233	GTY ((tag ("dw_val_class_file_implicit"))) val_file_implicit;
234      unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
235      tree GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref;
236      struct dw_val_vms_delta_union
237	{
238	  char * lbl1;
239	  char * lbl2;
240	} GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
241      dw_discr_value GTY ((tag ("dw_val_class_discr_value"))) val_discr_value;
242      dw_discr_list_ref GTY ((tag ("dw_val_class_discr_list"))) val_discr_list;
243      char * GTY ((tag ("dw_val_class_symview"))) val_symbolic_view;
244    }
245  GTY ((desc ("%1.val_class"))) v;
246};
247
248/* Locations in memory are described using a sequence of stack machine
249   operations.  */
250
251struct GTY((chain_next ("%h.dw_loc_next"))) dw_loc_descr_node {
252  dw_loc_descr_ref dw_loc_next;
253  ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
254  /* Used to distinguish DW_OP_addr with a direct symbol relocation
255     from DW_OP_addr with a dtp-relative symbol relocation.  */
256  unsigned int dtprel : 1;
257  /* For DW_OP_pick, DW_OP_dup and DW_OP_over operations: true iff.
258     it targets a DWARF prodecure argument.  In this case, it needs to be
259     relocated according to the current frame offset.  */
260  unsigned int frame_offset_rel : 1;
261  int dw_loc_addr;
262  dw_val_node dw_loc_oprnd1;
263  dw_val_node dw_loc_oprnd2;
264};
265
266/* A variant (inside a record variant part) is selected when the corresponding
267   discriminant matches its set of values (see the comment for dw_discr_value).
268   The following datastructure holds such matching information.  */
269
270struct GTY(()) dw_discr_list_node {
271  dw_discr_list_ref dw_discr_next;
272
273  dw_discr_value dw_discr_lower_bound;
274  dw_discr_value dw_discr_upper_bound;
275  /* This node represents only the value in dw_discr_lower_bound when it's
276     zero.  It represents the range between the two fields (bounds included)
277     otherwise.  */
278  int dw_discr_range;
279};
280
281/* Interface from dwarf2out.c to dwarf2cfi.c.  */
282extern struct dw_loc_descr_node *build_cfa_loc
283  (dw_cfa_location *, poly_int64);
284extern struct dw_loc_descr_node *build_cfa_aligned_loc
285  (dw_cfa_location *, poly_int64, HOST_WIDE_INT);
286extern struct dw_loc_descr_node *mem_loc_descriptor
287  (rtx, machine_mode mode, machine_mode mem_mode,
288   enum var_init_status);
289extern bool loc_descr_equal_p (dw_loc_descr_ref, dw_loc_descr_ref);
290extern dw_fde_ref dwarf2out_alloc_current_fde (void);
291
292extern unsigned long size_of_locs (dw_loc_descr_ref);
293extern void output_loc_sequence (dw_loc_descr_ref, int);
294extern void output_loc_sequence_raw (dw_loc_descr_ref);
295
296/* Interface from dwarf2cfi.c to dwarf2out.c.  */
297extern void lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc,
298			  dw_cfa_location *remember);
299extern bool cfa_equal_p (const dw_cfa_location *, const dw_cfa_location *);
300
301extern void output_cfi (dw_cfi_ref, dw_fde_ref, int);
302
303extern GTY(()) cfi_vec cie_cfi_vec;
304
305/* Interface from dwarf2*.c to the rest of the compiler.  */
306extern enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
307  (enum dwarf_call_frame_info cfi);
308extern enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
309  (enum dwarf_call_frame_info cfi);
310
311extern void output_cfi_directive (FILE *f, struct dw_cfi_node *cfi);
312
313extern void dwarf2out_emit_cfi (dw_cfi_ref cfi);
314
315extern void debug_dwarf (void);
316struct die_struct;
317extern void debug_dwarf_die (struct die_struct *);
318extern void debug_dwarf_loc_descr (dw_loc_descr_ref);
319extern void debug (die_struct &ref);
320extern void debug (die_struct *ptr);
321extern void dwarf2out_set_demangle_name_func (const char *(*) (const char *));
322#ifdef VMS_DEBUGGING_INFO
323extern void dwarf2out_vms_debug_main_pointer (void);
324#endif
325
326enum array_descr_ordering
327{
328  array_descr_ordering_default,
329  array_descr_ordering_row_major,
330  array_descr_ordering_column_major
331};
332
333#define DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN 16
334
335struct array_descr_info
336{
337  int ndimensions;
338  enum array_descr_ordering ordering;
339  tree element_type;
340  tree base_decl;
341  tree data_location;
342  tree allocated;
343  tree associated;
344  tree stride;
345  tree rank;
346  bool stride_in_bits;
347  struct array_descr_dimen
348    {
349      /* GCC uses sizetype for array indices, so lower_bound and upper_bound
350	 will likely be "sizetype" values. However, bounds may have another
351	 type in the original source code.  */
352      tree bounds_type;
353      tree lower_bound;
354      tree upper_bound;
355
356      /* Only Fortran uses more than one dimension for array types.  For other
357	 languages, the stride can be rather specified for the whole array.  */
358      tree stride;
359    } dimen[DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN];
360};
361
362enum fixed_point_scale_factor
363{
364  fixed_point_scale_factor_binary,
365  fixed_point_scale_factor_decimal,
366  fixed_point_scale_factor_arbitrary
367};
368
369struct fixed_point_type_info
370{
371  /* A scale factor is the value one has to multiply with physical data in
372     order to get the fixed point logical data.  The DWARF standard enables one
373     to encode it in three ways.  */
374  enum fixed_point_scale_factor scale_factor_kind;
375  union
376    {
377      /* For binary scale factor, the scale factor is: 2 ** binary.  */
378      int binary;
379      /* For decimal scale factor, the scale factor is: 10 ** binary.  */
380      int decimal;
381      /* For arbitrary scale factor, the scale factor is:
382	 numerator / denominator.  */
383      struct
384	{
385	  unsigned HOST_WIDE_INT numerator;
386	  HOST_WIDE_INT denominator;
387	} arbitrary;
388    } scale_factor;
389};
390
391void dwarf2out_c_finalize (void);
392
393#endif /* GCC_DWARF2OUT_H */
394