]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/dwarf2/loc.h
Make dwarf2_compile_expr_to_ax static
[thirdparty/binutils-gdb.git] / gdb / dwarf2 / loc.h
1 /* DWARF 2 location expression support for GDB.
2
3 Copyright (C) 2003-2020 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #if !defined (DWARF2LOC_H)
21 #define DWARF2LOC_H
22
23 #include "dwarf2/expr.h"
24
25 struct symbol_computed_ops;
26 struct objfile;
27 struct dwarf2_per_cu_data;
28 struct dwarf2_loclist_baton;
29 struct agent_expr;
30 struct axs_value;
31
32 /* This header is private to the DWARF-2 reader. It is shared between
33 dwarf2read.c and dwarf2loc.c. */
34
35 /* `set debug entry-values' setting. */
36 extern unsigned int entry_values_debug;
37
38 /* Find a particular location expression from a location list. */
39 const gdb_byte *dwarf2_find_location_expression
40 (struct dwarf2_loclist_baton *baton,
41 size_t *locexpr_length,
42 CORE_ADDR pc);
43
44 struct dwarf2_locexpr_baton dwarf2_fetch_die_loc_sect_off
45 (sect_offset offset_in_cu, struct dwarf2_per_cu_data *per_cu,
46 CORE_ADDR (*get_frame_pc) (void *baton),
47 void *baton, bool resolve_abstract_p = false);
48
49 struct dwarf2_locexpr_baton dwarf2_fetch_die_loc_cu_off
50 (cu_offset offset_in_cu, struct dwarf2_per_cu_data *per_cu,
51 CORE_ADDR (*get_frame_pc) (void *baton),
52 void *baton);
53
54 extern const gdb_byte *dwarf2_fetch_constant_bytes (sect_offset,
55 struct dwarf2_per_cu_data *,
56 struct obstack *,
57 LONGEST *);
58
59 struct type *dwarf2_fetch_die_type_sect_off (sect_offset,
60 struct dwarf2_per_cu_data *);
61
62 struct type *dwarf2_get_die_type (cu_offset die_offset,
63 struct dwarf2_per_cu_data *per_cu);
64
65 /* Find the frame base information for FRAMEFUNC at PC. START is an
66 out parameter which is set to point to the DWARF expression to
67 compute. LENGTH is an out parameter which is set to the length of
68 the DWARF expression. This throws an exception on error or if an
69 expression is not found; the returned length will never be
70 zero. */
71
72 extern void func_get_frame_base_dwarf_block (struct symbol *framefunc,
73 CORE_ADDR pc,
74 const gdb_byte **start,
75 size_t *length);
76
77 /* Evaluate a location description, starting at DATA and with length
78 SIZE, to find the current location of variable of TYPE in the context
79 of FRAME. */
80
81 struct value *dwarf2_evaluate_loc_desc (struct type *type,
82 struct frame_info *frame,
83 const gdb_byte *data,
84 size_t size,
85 struct dwarf2_per_cu_data *per_cu);
86
87 /* A chain of addresses that might be needed to resolve a dynamic
88 property. */
89
90 struct property_addr_info
91 {
92 /* The type of the object whose dynamic properties, if any, are
93 being resolved. */
94 struct type *type;
95
96 /* If not NULL, a buffer containing the object's value. */
97 const gdb_byte *valaddr;
98
99 /* The address of that object. */
100 CORE_ADDR addr;
101
102 /* If not NULL, a pointer to the info for the object containing
103 the object described by this node. */
104 struct property_addr_info *next;
105 };
106
107 /* Converts a dynamic property into a static one. FRAME is the frame in which
108 the property is evaluated; if NULL, the selected frame (if any) is used
109 instead.
110
111 ADDR_STACK is the stack of addresses that might be needed to evaluate the
112 property. When evaluating a property that is not related to a type, it can
113 be NULL.
114
115 Returns true if PROP could be converted and the static value is passed
116 back into VALUE, otherwise returns false. */
117
118 bool dwarf2_evaluate_property (const struct dynamic_prop *prop,
119 struct frame_info *frame,
120 struct property_addr_info *addr_stack,
121 CORE_ADDR *value);
122
123 /* A helper for the compiler interface that compiles a single dynamic
124 property to C code.
125
126 STREAM is where the C code is to be written.
127 RESULT_NAME is the name of the generated variable.
128 GDBARCH is the architecture to use.
129 REGISTERS_USED is a bit-vector that is filled to note which
130 registers are required by the generated expression.
131 PROP is the property for which code is generated.
132 ADDRESS is the address at which the property is considered to be
133 evaluated.
134 SYM the originating symbol, used for error reporting. */
135
136 void dwarf2_compile_property_to_c (string_file *stream,
137 const char *result_name,
138 struct gdbarch *gdbarch,
139 unsigned char *registers_used,
140 const struct dynamic_prop *prop,
141 CORE_ADDR address,
142 struct symbol *sym);
143
144 CORE_ADDR dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu,
145 unsigned int addr_index);
146
147 /* The symbol location baton types used by the DWARF-2 reader (i.e.
148 SYMBOL_LOCATION_BATON for a LOC_COMPUTED symbol). "struct
149 dwarf2_locexpr_baton" is for a symbol with a single location
150 expression; "struct dwarf2_loclist_baton" is for a symbol with a
151 location list. */
152
153 struct dwarf2_locexpr_baton
154 {
155 /* Pointer to the start of the location expression. Valid only if SIZE is
156 not zero. */
157 const gdb_byte *data;
158
159 /* Length of the location expression. For optimized out expressions it is
160 zero. */
161 size_t size;
162
163 /* When true this location expression is a reference and actually
164 describes the address at which the value of the attribute can be
165 found. When false the expression provides the value of the attribute
166 directly. */
167 bool is_reference;
168
169 /* The compilation unit containing the symbol whose location
170 we're computing. */
171 struct dwarf2_per_cu_data *per_cu;
172 };
173
174 struct dwarf2_loclist_baton
175 {
176 /* The initial base address for the location list, based on the compilation
177 unit. */
178 CORE_ADDR base_address;
179
180 /* Pointer to the start of the location list. */
181 const gdb_byte *data;
182
183 /* Length of the location list. */
184 size_t size;
185
186 /* The compilation unit containing the symbol whose location
187 we're computing. */
188 struct dwarf2_per_cu_data *per_cu;
189
190 /* Non-zero if the location list lives in .debug_loc.dwo.
191 The format of entries in this section are different. */
192 unsigned char from_dwo;
193 };
194
195 /* The baton used when a dynamic property is an offset to a parent
196 type. This can be used, for instance, then the bound of an array
197 inside a record is determined by the value of another field inside
198 that record. */
199
200 struct dwarf2_offset_baton
201 {
202 /* The offset from the parent type where the value of the property
203 is stored. In the example provided above, this would be the offset
204 of the field being used as the array bound. */
205 LONGEST offset;
206
207 /* The type of the object whose property is dynamic. In the example
208 provided above, this would the array's index type. */
209 struct type *type;
210 };
211
212 /* A dynamic property is either expressed as a single location expression
213 or a location list. If the property is an indirection, pointing to
214 another die, keep track of the targeted type in PROPERTY_TYPE.
215 Alternatively, if the property location gives the property value
216 directly then it will have PROPERTY_TYPE. */
217
218 struct dwarf2_property_baton
219 {
220 /* If the property is an indirection, we need to evaluate the location
221 in the context of the type PROPERTY_TYPE. If the property is supplied
222 by value then it will be of PROPERTY_TYPE. This field should never be
223 NULL. */
224 struct type *property_type;
225 union
226 {
227 /* Location expression either evaluated in the context of
228 PROPERTY_TYPE, or a value of type PROPERTY_TYPE. */
229 struct dwarf2_locexpr_baton locexpr;
230
231 /* Location list to be evaluated in the context of PROPERTY_TYPE. */
232 struct dwarf2_loclist_baton loclist;
233
234 /* The location is an offset to PROPERTY_TYPE. */
235 struct dwarf2_offset_baton offset_info;
236 };
237 };
238
239 extern const struct symbol_computed_ops dwarf2_locexpr_funcs;
240 extern const struct symbol_computed_ops dwarf2_loclist_funcs;
241
242 extern const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs;
243 extern const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs;
244
245 /* Determined tail calls for constructing virtual tail call frames. */
246
247 struct call_site_chain
248 {
249 /* Initially CALLERS == CALLEES == LENGTH. For partially ambiguous result
250 CALLERS + CALLEES < LENGTH. */
251 int callers, callees, length;
252
253 /* Variably sized array with LENGTH elements. Later [0..CALLERS-1] contain
254 top (GDB "prev") sites and [LENGTH-CALLEES..LENGTH-1] contain bottom
255 (GDB "next") sites. One is interested primarily in the PC field. */
256 struct call_site *call_site[1];
257 };
258
259 struct call_site_stuff;
260 extern gdb::unique_xmalloc_ptr<call_site_chain> call_site_find_chain
261 (struct gdbarch *gdbarch, CORE_ADDR caller_pc, CORE_ADDR callee_pc);
262
263 /* A helper function to convert a DWARF register to an arch register.
264 ARCH is the architecture.
265 DWARF_REG is the register.
266 If DWARF_REG is bad then a complaint is issued and -1 is returned.
267 Note: Some targets get this wrong. */
268
269 extern int dwarf_reg_to_regnum (struct gdbarch *arch, int dwarf_reg);
270
271 /* A wrapper on dwarf_reg_to_regnum to throw an exception if the
272 DWARF register cannot be translated to an architecture register.
273 This takes a ULONGEST instead of an int because some callers actually have
274 a ULONGEST. Negative values passed as ints will still be flagged as
275 invalid. */
276
277 extern int dwarf_reg_to_regnum_or_error (struct gdbarch *arch,
278 ULONGEST dwarf_reg);
279
280 #endif /* dwarf2loc.h */