]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Definitions for values of C expressions, for GDB. |
dea7f9ba | 2 | |
213516ef | 3 | Copyright (C) 1986-2023 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
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. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #if !defined (VALUE_H) | |
21 | #define VALUE_H 1 | |
22 | ||
1df6926e | 23 | #include "frame.h" /* For struct frame_id. */ |
ba18742c | 24 | #include "extension.h" |
268a13a5 | 25 | #include "gdbsupport/gdb_ref_ptr.h" |
b49180ac | 26 | #include "gmp-utils.h" |
dea7f9ba MK |
27 | |
28 | struct block; | |
da3331ec | 29 | struct expression; |
dea7f9ba | 30 | struct regcache; |
da3331ec AC |
31 | struct symbol; |
32 | struct type; | |
dea7f9ba | 33 | struct ui_file; |
d8ca156b | 34 | struct language_defn; |
79a45b7d | 35 | struct value_print_options; |
d16aafd8 | 36 | |
9a0dc9e3 PA |
37 | /* Values can be partially 'optimized out' and/or 'unavailable'. |
38 | These are distinct states and have different string representations | |
39 | and related error strings. | |
40 | ||
41 | 'unavailable' has a specific meaning in this context. It means the | |
42 | value exists in the program (at the machine level), but GDB has no | |
43 | means to get to it. Such a value is normally printed as | |
44 | <unavailable>. Examples of how to end up with an unavailable value | |
45 | would be: | |
46 | ||
47 | - We're inspecting a traceframe, and the memory or registers the | |
48 | debug information says the value lives on haven't been collected. | |
49 | ||
50 | - We're inspecting a core dump, the memory or registers the debug | |
51 | information says the value lives aren't present in the dump | |
52 | (that is, we have a partial/trimmed core dump, or we don't fully | |
53 | understand/handle the core dump's format). | |
54 | ||
55 | - We're doing live debugging, but the debug API has no means to | |
56 | get at where the value lives in the machine, like e.g., ptrace | |
57 | not having access to some register or register set. | |
58 | ||
59 | - Any other similar scenario. | |
60 | ||
61 | OTOH, "optimized out" is about what the compiler decided to generate | |
62 | (or not generate). A chunk of a value that was optimized out does | |
63 | not actually exist in the program. There's no way to get at it | |
64 | short of compiling the program differently. | |
65 | ||
66 | A register that has not been saved in a frame is likewise considered | |
67 | optimized out, except not-saved registers have a different string | |
68 | representation and related error strings. E.g., we'll print them as | |
69 | <not-saved> instead of <optimized out>, as in: | |
70 | ||
71 | (gdb) p/x $rax | |
72 | $1 = <not saved> | |
73 | (gdb) info registers rax | |
74 | rax <not saved> | |
75 | ||
76 | If the debug info describes a variable as being in such a register, | |
77 | we'll still print the variable as <optimized out>. IOW, <not saved> | |
78 | is reserved for inspecting registers at the machine level. | |
79 | ||
80 | When comparing value contents, optimized out chunks, unavailable | |
81 | chunks, and valid contents data are all considered different. See | |
82 | value_contents_eq for more info. | |
83 | */ | |
84 | ||
e4153ae6 CB |
85 | extern bool overload_resolution; |
86 | ||
7cf57bc5 | 87 | /* Defines an [OFFSET, OFFSET + LENGTH) range. */ |
c906108c | 88 | |
7cf57bc5 TT |
89 | struct range |
90 | { | |
91 | /* Lowest offset in the range. */ | |
92 | LONGEST offset; | |
93 | ||
94 | /* Length of the range. */ | |
95 | ULONGEST length; | |
96 | ||
97 | /* Returns true if THIS is strictly less than OTHER, useful for | |
98 | searching. We keep ranges sorted by offset and coalesce | |
99 | overlapping and contiguous ranges, so this just compares the | |
100 | starting offset. */ | |
101 | ||
102 | bool operator< (const range &other) const | |
103 | { | |
104 | return offset < other.offset; | |
105 | } | |
106 | ||
107 | /* Returns true if THIS is equal to OTHER. */ | |
108 | bool operator== (const range &other) const | |
109 | { | |
110 | return offset == other.offset && length == other.length; | |
111 | } | |
112 | }; | |
c906108c | 113 | |
bbfa6f00 | 114 | /* Increase VAL's reference count. */ |
22bc8444 | 115 | |
bbfa6f00 | 116 | extern void value_incref (struct value *val); |
22bc8444 | 117 | |
bbfa6f00 TT |
118 | /* Decrease VAL's reference count. When the reference count drops to |
119 | 0, VAL will be freed. */ | |
22bc8444 TT |
120 | |
121 | extern void value_decref (struct value *val); | |
122 | ||
123 | /* A policy class to interface gdb::ref_ptr with struct value. */ | |
124 | ||
125 | struct value_ref_policy | |
126 | { | |
127 | static void incref (struct value *ptr) | |
128 | { | |
129 | value_incref (ptr); | |
130 | } | |
131 | ||
132 | static void decref (struct value *ptr) | |
133 | { | |
134 | value_decref (ptr); | |
135 | } | |
136 | }; | |
137 | ||
138 | /* A gdb:;ref_ptr pointer to a struct value. */ | |
139 | ||
140 | typedef gdb::ref_ptr<struct value, value_ref_policy> value_ref_ptr; | |
141 | ||
7cf57bc5 TT |
142 | /* Note that the fields in this structure are arranged to save a bit |
143 | of memory. */ | |
144 | ||
145 | struct value | |
146 | { | |
cbe793af TT |
147 | private: |
148 | ||
149 | /* Values can only be created via "static constructors". */ | |
7cf57bc5 TT |
150 | explicit value (struct type *type_) |
151 | : m_modifiable (1), | |
152 | m_lazy (1), | |
153 | m_initialized (1), | |
154 | m_stack (0), | |
155 | m_is_zero (false), | |
156 | m_in_history (false), | |
157 | m_type (type_), | |
158 | m_enclosing_type (type_) | |
159 | { | |
160 | } | |
161 | ||
cbe793af TT |
162 | public: |
163 | ||
164 | /* Allocate a lazy value for type TYPE. Its actual content is | |
165 | "lazily" allocated too: the content field of the return value is | |
166 | NULL; it will be allocated when it is fetched from the target. */ | |
167 | static struct value *allocate_lazy (struct type *type); | |
168 | ||
317c3ed9 TT |
169 | /* Allocate a value and its contents for type TYPE. */ |
170 | static struct value *allocate (struct type *type); | |
171 | ||
b64e2602 TT |
172 | /* Create a computed lvalue, with type TYPE, function pointers |
173 | FUNCS, and closure CLOSURE. */ | |
174 | static struct value *allocate_computed (struct type *type, | |
175 | const struct lval_funcs *funcs, | |
176 | void *closure); | |
177 | ||
b27556e3 TT |
178 | /* Allocate NOT_LVAL value for type TYPE being OPTIMIZED_OUT. */ |
179 | static struct value *allocate_optimized_out (struct type *type); | |
180 | ||
ee7bb294 TT |
181 | /* Create a value of type TYPE that is zero, and return it. */ |
182 | static struct value *zero (struct type *type, enum lval_type lv); | |
183 | ||
7cf57bc5 TT |
184 | ~value (); |
185 | ||
186 | DISABLE_COPY_AND_ASSIGN (value); | |
187 | ||
d0c97917 TT |
188 | /* Type of the value. */ |
189 | struct type *type () const | |
190 | { return m_type; } | |
191 | ||
81ae560c TT |
192 | /* This is being used to change the type of an existing value, that |
193 | code should instead be creating a new value with the changed type | |
194 | (but possibly shared content). */ | |
195 | void deprecated_set_type (struct type *type) | |
196 | { m_type = type; } | |
197 | ||
f9ee742c TT |
198 | /* Return the gdbarch associated with the value. */ |
199 | struct gdbarch *arch () const; | |
200 | ||
f49d5fa2 TT |
201 | /* Only used for bitfields; number of bits contained in them. */ |
202 | LONGEST bitsize () const | |
203 | { return m_bitsize; } | |
204 | ||
205 | void set_bitsize (LONGEST bit) | |
206 | { m_bitsize = bit; } | |
207 | ||
5011c493 TT |
208 | /* Only used for bitfields; position of start of field. For |
209 | little-endian targets, it is the position of the LSB. For | |
210 | big-endian targets, it is the position of the MSB. */ | |
211 | LONGEST bitpos () const | |
212 | { return m_bitpos; } | |
213 | ||
214 | void set_bitpos (LONGEST bit) | |
215 | { m_bitpos = bit; } | |
216 | ||
fac7bdaa TT |
217 | /* Only used for bitfields; the containing value. This allows a |
218 | single read from the target when displaying multiple | |
219 | bitfields. */ | |
220 | value *parent () const | |
221 | { return m_parent.get (); } | |
222 | ||
223 | void set_parent (struct value *parent) | |
224 | { m_parent = value_ref_ptr::new_reference (parent); } | |
225 | ||
76675c4d TT |
226 | /* Describes offset of a value within lval of a structure in bytes. |
227 | If lval == lval_memory, this is an offset to the address. If | |
228 | lval == lval_register, this is a further offset from | |
229 | location.address within the registers structure. Note also the | |
230 | member embedded_offset below. */ | |
231 | LONGEST offset () const | |
232 | { return m_offset; } | |
233 | ||
234 | void set_offset (LONGEST offset) | |
235 | { m_offset = offset; } | |
236 | ||
4b53ca88 TT |
237 | /* The comment from "struct value" reads: ``Is it modifiable? Only |
238 | relevant if lval != not_lval.''. Shouldn't the value instead be | |
239 | not_lval and be done with it? */ | |
240 | int deprecated_modifiable () const | |
241 | { return m_modifiable; } | |
242 | ||
391f8628 TT |
243 | LONGEST pointed_to_offset () const |
244 | { return m_pointed_to_offset; } | |
245 | ||
246 | void set_pointed_to_offset (LONGEST val) | |
247 | { m_pointed_to_offset = val; } | |
248 | ||
249 | LONGEST embedded_offset () const | |
250 | { return m_embedded_offset; } | |
251 | ||
252 | void set_embedded_offset (LONGEST val) | |
253 | { m_embedded_offset = val; } | |
254 | ||
3ee3b270 TT |
255 | /* If zero, contents of this value are in the contents field. If |
256 | nonzero, contents are in inferior. If the lval field is lval_memory, | |
257 | the contents are in inferior memory at location.address plus offset. | |
258 | The lval field may also be lval_register. | |
259 | ||
260 | WARNING: This field is used by the code which handles watchpoints | |
261 | (see breakpoint.c) to decide whether a particular value can be | |
262 | watched by hardware watchpoints. If the lazy flag is set for some | |
263 | member of a value chain, it is assumed that this member of the | |
264 | chain doesn't need to be watched as part of watching the value | |
265 | itself. This is how GDB avoids watching the entire struct or array | |
266 | when the user wants to watch a single struct member or array | |
267 | element. If you ever change the way lazy flag is set and reset, be | |
268 | sure to consider this use as well! */ | |
269 | ||
270 | int lazy () const | |
271 | { return m_lazy; } | |
272 | ||
273 | void set_lazy (int val) | |
274 | { m_lazy = val; } | |
275 | ||
391f8628 | 276 | |
463b870d TT |
277 | /* If a value represents a C++ object, then the `type' field gives the |
278 | object's compile-time type. If the object actually belongs to some | |
279 | class derived from `type', perhaps with other base classes and | |
280 | additional members, then `type' is just a subobject of the real | |
281 | thing, and the full object is probably larger than `type' would | |
282 | suggest. | |
283 | ||
284 | If `type' is a dynamic class (i.e. one with a vtable), then GDB can | |
285 | actually determine the object's run-time type by looking at the | |
286 | run-time type information in the vtable. When this information is | |
287 | available, we may elect to read in the entire object, for several | |
288 | reasons: | |
289 | ||
290 | - When printing the value, the user would probably rather see the | |
291 | full object, not just the limited portion apparent from the | |
292 | compile-time type. | |
293 | ||
294 | - If `type' has virtual base classes, then even printing `type' | |
295 | alone may require reaching outside the `type' portion of the | |
296 | object to wherever the virtual base class has been stored. | |
297 | ||
298 | When we store the entire object, `enclosing_type' is the run-time | |
299 | type -- the complete object -- and `embedded_offset' is the offset | |
300 | of `type' within that larger type, in bytes. The value_contents() | |
301 | macro takes `embedded_offset' into account, so most GDB code | |
302 | continues to see the `type' portion of the value, just as the | |
303 | inferior would. | |
304 | ||
305 | If `type' is a pointer to an object, then `enclosing_type' is a | |
306 | pointer to the object's run-time type, and `pointed_to_offset' is | |
307 | the offset in bytes from the full object to the pointed-to object | |
308 | -- that is, the value `embedded_offset' would have if we followed | |
309 | the pointer and fetched the complete object. (I don't really see | |
310 | the point. Why not just determine the run-time type when you | |
311 | indirect, and avoid the special case? The contents don't matter | |
312 | until you indirect anyway.) | |
313 | ||
314 | If we're not doing anything fancy, `enclosing_type' is equal to | |
315 | `type', and `embedded_offset' is zero, so everything works | |
316 | normally. */ | |
317 | ||
318 | struct type *enclosing_type () const | |
319 | { return m_enclosing_type; } | |
320 | ||
321 | void set_enclosing_type (struct type *new_type); | |
322 | ||
c8580184 TT |
323 | int stack () const |
324 | { return m_stack; } | |
325 | ||
326 | void set_stack (int val) | |
327 | { m_stack = val; } | |
328 | ||
b9f74d54 TT |
329 | /* If this value is lval_computed, return its lval_funcs |
330 | structure. */ | |
331 | const struct lval_funcs *computed_funcs () const; | |
332 | ||
333 | /* If this value is lval_computed, return its closure. The meaning | |
334 | of the returned value depends on the functions this value | |
335 | uses. */ | |
336 | void *computed_closure () const; | |
337 | ||
97044105 TT |
338 | enum lval_type *deprecated_lval_hack () |
339 | { return &m_lval; } | |
340 | ||
341 | enum lval_type lval () const | |
342 | { return m_lval; } | |
343 | ||
8e5b19ad TT |
344 | /* Set or return field indicating whether a variable is initialized or |
345 | not, based on debugging information supplied by the compiler. | |
346 | 1 = initialized; 0 = uninitialized. */ | |
347 | int initialized () const | |
348 | { return m_initialized; } | |
349 | ||
350 | void set_initialized (int value) | |
351 | { m_initialized = value; } | |
352 | ||
9feb2d07 TT |
353 | /* If lval == lval_memory, return the address in the inferior. If |
354 | lval == lval_register, return the byte offset into the registers | |
355 | structure. Otherwise, return 0. The returned address | |
356 | includes the offset, if any. */ | |
357 | CORE_ADDR address () const; | |
358 | ||
359 | /* Like address, except the result does not include value's | |
360 | offset. */ | |
361 | CORE_ADDR raw_address () const; | |
362 | ||
363 | /* Set the address of a value. */ | |
364 | void set_address (CORE_ADDR); | |
365 | ||
f29de665 TT |
366 | struct internalvar **deprecated_internalvar_hack () |
367 | { return &m_location.internalvar; } | |
368 | ||
369 | struct frame_id *deprecated_next_frame_id_hack (); | |
370 | ||
371 | int *deprecated_regnum_hack (); | |
372 | ||
bbe912ba TT |
373 | /* contents() and contents_raw() both return the address of the gdb |
374 | buffer used to hold a copy of the contents of the lval. | |
375 | contents() is used when the contents of the buffer are needed -- | |
376 | it uses fetch_lazy() to load the buffer from the process being | |
377 | debugged if it hasn't already been loaded (contents_writeable() | |
378 | is used when a writeable but fetched buffer is required).. | |
379 | contents_raw() is used when data is being stored into the buffer, | |
380 | or when it is certain that the contents of the buffer are valid. | |
381 | ||
382 | Note: The contents pointer is adjusted by the offset required to | |
383 | get to the real subobject, if the value happens to represent | |
384 | something embedded in a larger run-time object. */ | |
385 | gdb::array_view<gdb_byte> contents_raw (); | |
386 | gdb::array_view<gdb_byte> contents_all_raw (); | |
387 | gdb::array_view<gdb_byte> contents_writeable (); | |
388 | ||
78259c36 TT |
389 | /* Load the actual content of a lazy value. Fetch the data from the |
390 | user's process and clear the lazy flag to indicate that the data in | |
391 | the buffer is valid. | |
392 | ||
393 | If the value is zero-length, we avoid calling read_memory, which | |
394 | would abort. We mark the value as fetched anyway -- all 0 bytes of | |
395 | it. */ | |
396 | void fetch_lazy (); | |
397 | ||
02744ba9 TT |
398 | /* Compare LENGTH bytes of this value's contents starting at OFFSET1 |
399 | with LENGTH bytes of VAL2's contents starting at OFFSET2. | |
400 | ||
401 | Note that "contents" refers to the whole value's contents | |
402 | (value_contents_all), without any embedded offset adjustment. For | |
403 | example, to compare a complete object value with itself, including | |
404 | its enclosing type chunk, you'd do: | |
405 | ||
406 | int len = check_typedef (val->enclosing_type ())->length (); | |
407 | val->contents_eq (0, val, 0, len); | |
408 | ||
409 | Returns true iff the set of available/valid contents match. | |
410 | ||
411 | Optimized-out contents are equal to optimized-out contents, and are | |
412 | not equal to non-optimized-out contents. | |
413 | ||
414 | Unavailable contents are equal to unavailable contents, and are not | |
415 | equal to non-unavailable contents. | |
416 | ||
417 | For example, if 'x's represent an unavailable byte, and 'V' and 'Z' | |
418 | represent different available/valid bytes, in a value with length | |
419 | 16: | |
420 | ||
421 | offset: 0 4 8 12 16 | |
422 | contents: xxxxVVVVxxxxVVZZ | |
423 | ||
424 | then: | |
425 | ||
426 | val->contents_eq(0, val, 8, 6) => true | |
427 | val->contents_eq(0, val, 4, 4) => false | |
428 | val->contents_eq(0, val, 8, 8) => false | |
429 | val->contents_eq(4, val, 12, 2) => true | |
430 | val->contents_eq(4, val, 12, 4) => true | |
431 | val->contents_eq(3, val, 4, 4) => true | |
432 | ||
433 | If 'x's represent an unavailable byte, 'o' represents an optimized | |
434 | out byte, in a value with length 8: | |
435 | ||
436 | offset: 0 4 8 | |
437 | contents: xxxxoooo | |
438 | ||
439 | then: | |
440 | ||
441 | val->contents_eq(0, val, 2, 2) => true | |
442 | val->contents_eq(4, val, 6, 2) => true | |
443 | val->contents_eq(0, val, 4, 4) => true | |
444 | ||
445 | We only know whether a value chunk is unavailable or optimized out | |
446 | if we've tried to read it. As this routine is used by printing | |
447 | routines, which may be printing values in the value history, long | |
448 | after the inferior is gone, it works with const values. Therefore, | |
449 | this routine must not be called with lazy values. */ | |
450 | ||
451 | bool contents_eq (LONGEST offset1, const struct value *val2, LONGEST offset2, | |
452 | LONGEST length) const; | |
453 | ||
454 | /* An overload of contents_eq that compares the entirety of both | |
455 | values. */ | |
456 | bool contents_eq (const struct value *val2) const; | |
457 | ||
d0c97917 | 458 | |
7cf57bc5 TT |
459 | /* Type of value; either not an lval, or one of the various |
460 | different possible kinds of lval. */ | |
461 | enum lval_type m_lval = not_lval; | |
462 | ||
463 | /* Is it modifiable? Only relevant if lval != not_lval. */ | |
464 | unsigned int m_modifiable : 1; | |
465 | ||
466 | /* If zero, contents of this value are in the contents field. If | |
467 | nonzero, contents are in inferior. If the lval field is lval_memory, | |
468 | the contents are in inferior memory at location.address plus offset. | |
469 | The lval field may also be lval_register. | |
470 | ||
471 | WARNING: This field is used by the code which handles watchpoints | |
472 | (see breakpoint.c) to decide whether a particular value can be | |
473 | watched by hardware watchpoints. If the lazy flag is set for | |
474 | some member of a value chain, it is assumed that this member of | |
475 | the chain doesn't need to be watched as part of watching the | |
476 | value itself. This is how GDB avoids watching the entire struct | |
477 | or array when the user wants to watch a single struct member or | |
478 | array element. If you ever change the way lazy flag is set and | |
479 | reset, be sure to consider this use as well! */ | |
480 | unsigned int m_lazy : 1; | |
481 | ||
482 | /* If value is a variable, is it initialized or not. */ | |
483 | unsigned int m_initialized : 1; | |
484 | ||
485 | /* If value is from the stack. If this is set, read_stack will be | |
486 | used instead of read_memory to enable extra caching. */ | |
487 | unsigned int m_stack : 1; | |
488 | ||
ee7bb294 | 489 | /* True if this is a zero value, created by 'value::zero'; false |
7cf57bc5 TT |
490 | otherwise. */ |
491 | bool m_is_zero : 1; | |
492 | ||
493 | /* True if this a value recorded in value history; false otherwise. */ | |
494 | bool m_in_history : 1; | |
495 | ||
496 | /* Location of value (if lval). */ | |
497 | union | |
498 | { | |
499 | /* If lval == lval_memory, this is the address in the inferior */ | |
500 | CORE_ADDR address; | |
501 | ||
502 | /*If lval == lval_register, the value is from a register. */ | |
503 | struct | |
504 | { | |
505 | /* Register number. */ | |
506 | int regnum; | |
507 | /* Frame ID of "next" frame to which a register value is relative. | |
508 | If the register value is found relative to frame F, then the | |
509 | frame id of F->next will be stored in next_frame_id. */ | |
510 | struct frame_id next_frame_id; | |
511 | } reg; | |
512 | ||
513 | /* Pointer to internal variable. */ | |
514 | struct internalvar *internalvar; | |
515 | ||
516 | /* Pointer to xmethod worker. */ | |
517 | struct xmethod_worker *xm_worker; | |
518 | ||
519 | /* If lval == lval_computed, this is a set of function pointers | |
520 | to use to access and describe the value, and a closure pointer | |
521 | for them to use. */ | |
522 | struct | |
523 | { | |
524 | /* Functions to call. */ | |
525 | const struct lval_funcs *funcs; | |
526 | ||
527 | /* Closure for those functions to use. */ | |
528 | void *closure; | |
529 | } computed; | |
530 | } m_location {}; | |
531 | ||
532 | /* Describes offset of a value within lval of a structure in target | |
533 | addressable memory units. Note also the member embedded_offset | |
534 | below. */ | |
535 | LONGEST m_offset = 0; | |
536 | ||
537 | /* Only used for bitfields; number of bits contained in them. */ | |
538 | LONGEST m_bitsize = 0; | |
539 | ||
540 | /* Only used for bitfields; position of start of field. For | |
541 | little-endian targets, it is the position of the LSB. For | |
542 | big-endian targets, it is the position of the MSB. */ | |
543 | LONGEST m_bitpos = 0; | |
544 | ||
545 | /* The number of references to this value. When a value is created, | |
546 | the value chain holds a reference, so REFERENCE_COUNT is 1. If | |
547 | release_value is called, this value is removed from the chain but | |
548 | the caller of release_value now has a reference to this value. | |
549 | The caller must arrange for a call to value_free later. */ | |
550 | int m_reference_count = 1; | |
551 | ||
552 | /* Only used for bitfields; the containing value. This allows a | |
553 | single read from the target when displaying multiple | |
554 | bitfields. */ | |
555 | value_ref_ptr m_parent; | |
556 | ||
557 | /* Type of the value. */ | |
558 | struct type *m_type; | |
559 | ||
560 | /* If a value represents a C++ object, then the `type' field gives | |
561 | the object's compile-time type. If the object actually belongs | |
562 | to some class derived from `type', perhaps with other base | |
563 | classes and additional members, then `type' is just a subobject | |
564 | of the real thing, and the full object is probably larger than | |
565 | `type' would suggest. | |
566 | ||
567 | If `type' is a dynamic class (i.e. one with a vtable), then GDB | |
568 | can actually determine the object's run-time type by looking at | |
569 | the run-time type information in the vtable. When this | |
570 | information is available, we may elect to read in the entire | |
571 | object, for several reasons: | |
572 | ||
573 | - When printing the value, the user would probably rather see the | |
574 | full object, not just the limited portion apparent from the | |
575 | compile-time type. | |
576 | ||
577 | - If `type' has virtual base classes, then even printing `type' | |
578 | alone may require reaching outside the `type' portion of the | |
579 | object to wherever the virtual base class has been stored. | |
580 | ||
581 | When we store the entire object, `enclosing_type' is the run-time | |
582 | type -- the complete object -- and `embedded_offset' is the | |
583 | offset of `type' within that larger type, in target addressable memory | |
584 | units. The value_contents() macro takes `embedded_offset' into account, | |
585 | so most GDB code continues to see the `type' portion of the value, just | |
586 | as the inferior would. | |
587 | ||
588 | If `type' is a pointer to an object, then `enclosing_type' is a | |
589 | pointer to the object's run-time type, and `pointed_to_offset' is | |
590 | the offset in target addressable memory units from the full object | |
591 | to the pointed-to object -- that is, the value `embedded_offset' would | |
592 | have if we followed the pointer and fetched the complete object. | |
593 | (I don't really see the point. Why not just determine the | |
594 | run-time type when you indirect, and avoid the special case? The | |
595 | contents don't matter until you indirect anyway.) | |
596 | ||
597 | If we're not doing anything fancy, `enclosing_type' is equal to | |
598 | `type', and `embedded_offset' is zero, so everything works | |
599 | normally. */ | |
600 | struct type *m_enclosing_type; | |
601 | LONGEST m_embedded_offset = 0; | |
602 | LONGEST m_pointed_to_offset = 0; | |
603 | ||
604 | /* Actual contents of the value. Target byte-order. | |
605 | ||
606 | May be nullptr if the value is lazy or is entirely optimized out. | |
607 | Guaranteed to be non-nullptr otherwise. */ | |
608 | gdb::unique_xmalloc_ptr<gdb_byte> m_contents; | |
609 | ||
610 | /* Unavailable ranges in CONTENTS. We mark unavailable ranges, | |
611 | rather than available, since the common and default case is for a | |
612 | value to be available. This is filled in at value read time. | |
613 | The unavailable ranges are tracked in bits. Note that a contents | |
614 | bit that has been optimized out doesn't really exist in the | |
615 | program, so it can't be marked unavailable either. */ | |
616 | std::vector<range> m_unavailable; | |
617 | ||
618 | /* Likewise, but for optimized out contents (a chunk of the value of | |
619 | a variable that does not actually exist in the program). If LVAL | |
620 | is lval_register, this is a register ($pc, $sp, etc., never a | |
621 | program variable) that has not been saved in the frame. Not | |
622 | saved registers and optimized-out program variables values are | |
623 | treated pretty much the same, except not-saved registers have a | |
624 | different string representation and related error strings. */ | |
625 | std::vector<range> m_optimized_out; | |
626 | ||
627 | /* This is only non-zero for values of TYPE_CODE_ARRAY and if the size of | |
628 | the array in inferior memory is greater than max_value_size. If these | |
629 | conditions are met then, when the value is loaded from the inferior | |
630 | GDB will only load a portion of the array into memory, and | |
631 | limited_length will be set to indicate the length in octets that were | |
632 | loaded from the inferior. */ | |
633 | ULONGEST m_limited_length = 0; | |
317c3ed9 TT |
634 | |
635 | private: | |
636 | ||
637 | /* Allocate a value and its contents for type TYPE. If CHECK_SIZE | |
638 | is true, then apply the usual max-value-size checks. */ | |
639 | static struct value *allocate (struct type *type, bool check_size); | |
78259c36 TT |
640 | |
641 | /* Helper for fetch_lazy when the value is a bitfield. */ | |
642 | void fetch_lazy_bitfield (); | |
643 | ||
644 | /* Helper for fetch_lazy when the value is in memory. */ | |
645 | void fetch_lazy_memory (); | |
646 | ||
647 | /* Helper for fetch_lazy when the value is in a register. */ | |
648 | void fetch_lazy_register (); | |
82ca8f72 TT |
649 | |
650 | /* Try to limit ourselves to only fetching the limited number of | |
651 | elements. However, if this limited number of elements still | |
652 | puts us over max_value_size, then we still refuse it and | |
653 | return failure here, which will ultimately throw an error. */ | |
654 | bool set_limited_array_length (); | |
655 | ||
656 | public: /* Temporary */ | |
657 | ||
658 | /* Allocate the contents of this value if it has not been allocated | |
659 | yet. If CHECK_SIZE is true, then apply the usual max-value-size | |
660 | checks. */ | |
661 | void allocate_contents (bool check_size); | |
02744ba9 TT |
662 | |
663 | private: | |
664 | ||
665 | /* Helper function for value_contents_eq. The only difference is that | |
666 | this function is bit rather than byte based. | |
667 | ||
668 | Compare LENGTH bits of this value's contents starting at OFFSET1 | |
669 | bits with LENGTH bits of VAL2's contents starting at OFFSET2 | |
670 | bits. Return true if the available bits match. */ | |
671 | bool contents_bits_eq (int offset1, const struct value *val2, int offset2, | |
672 | int length) const; | |
7cf57bc5 TT |
673 | }; |
674 | ||
8264ba82 AG |
675 | /* Returns value_type or value_enclosing_type depending on |
676 | value_print_options.objectprint. | |
677 | ||
678 | If RESOLVE_SIMPLE_TYPES is 0 the enclosing type will be resolved | |
679 | only for pointers and references, else it will be returned | |
680 | for all the types (e.g. structures). This option is useful | |
681 | to prevent retrieving enclosing type for the base classes fields. | |
682 | ||
683 | REAL_TYPE_FOUND is used to inform whether the real type was found | |
684 | (or just static type was used). The NULL may be passed if it is not | |
685 | necessary. */ | |
686 | ||
687 | extern struct type *value_actual_type (struct value *value, | |
688 | int resolve_simple_types, | |
689 | int *real_type_found); | |
690 | ||
5f5233d4 PA |
691 | /* For lval_computed values, this structure holds functions used to |
692 | retrieve and set the value (or portions of the value). | |
693 | ||
694 | For each function, 'V' is the 'this' pointer: an lval_funcs | |
695 | function F may always assume that the V it receives is an | |
696 | lval_computed value, and has F in the appropriate slot of its | |
697 | lval_funcs structure. */ | |
698 | ||
699 | struct lval_funcs | |
700 | { | |
701 | /* Fill in VALUE's contents. This is used to "un-lazy" values. If | |
702 | a problem arises in obtaining VALUE's bits, this function should | |
ac71a68c JK |
703 | call 'error'. If it is NULL value_fetch_lazy on "un-lazy" |
704 | non-optimized-out value is an internal error. */ | |
5f5233d4 PA |
705 | void (*read) (struct value *v); |
706 | ||
707 | /* Handle an assignment TOVAL = FROMVAL by writing the value of | |
708 | FROMVAL to TOVAL's location. The contents of TOVAL have not yet | |
709 | been updated. If a problem arises in doing so, this function | |
ac71a68c JK |
710 | should call 'error'. If it is NULL such TOVAL assignment is an error as |
711 | TOVAL is not considered as an lvalue. */ | |
5f5233d4 PA |
712 | void (*write) (struct value *toval, struct value *fromval); |
713 | ||
a519e8ff TT |
714 | /* Return true if any part of V is optimized out, false otherwise. |
715 | This will only be called for lazy values -- if the value has been | |
716 | fetched, then the value's optimized-out bits are consulted | |
717 | instead. */ | |
718 | bool (*is_optimized_out) (struct value *v); | |
719 | ||
8cf6f0b1 TT |
720 | /* If non-NULL, this is used to implement pointer indirection for |
721 | this value. This method may return NULL, in which case value_ind | |
722 | will fall back to ordinary indirection. */ | |
723 | struct value *(*indirect) (struct value *value); | |
724 | ||
a471c594 JK |
725 | /* If non-NULL, this is used to implement reference resolving for |
726 | this value. This method may return NULL, in which case coerce_ref | |
727 | will fall back to ordinary references resolving. */ | |
728 | struct value *(*coerce_ref) (const struct value *value); | |
729 | ||
8cf6f0b1 TT |
730 | /* If non-NULL, this is used to determine whether the indicated bits |
731 | of VALUE are a synthetic pointer. */ | |
732 | int (*check_synthetic_pointer) (const struct value *value, | |
6b850546 | 733 | LONGEST offset, int length); |
8cf6f0b1 | 734 | |
5f5233d4 PA |
735 | /* Return a duplicate of VALUE's closure, for use in a new value. |
736 | This may simply return the same closure, if VALUE's is | |
737 | reference-counted or statically allocated. | |
738 | ||
739 | This may be NULL, in which case VALUE's closure is re-used in the | |
740 | new value. */ | |
0e03807e | 741 | void *(*copy_closure) (const struct value *v); |
5f5233d4 PA |
742 | |
743 | /* Drop VALUE's reference to its closure. Maybe this frees the | |
744 | closure; maybe this decrements a reference count; maybe the | |
745 | closure is statically allocated and this does nothing. | |
746 | ||
747 | This may be NULL, in which case no action is taken to free | |
748 | VALUE's closure. */ | |
749 | void (*free_closure) (struct value *v); | |
750 | }; | |
751 | ||
901461f8 PA |
752 | /* Throw an error complaining that the value has been optimized |
753 | out. */ | |
754 | ||
755 | extern void error_value_optimized_out (void); | |
756 | ||
91294c83 AC |
757 | /* Actual contents of the value. For use of this value; setting it |
758 | uses the stuff above. Not valid if lazy is nonzero. Target | |
759 | byte-order. We force it to be aligned properly for any possible | |
760 | value. Note that a value therefore extends beyond what is | |
761 | declared here. */ | |
762 | ||
50888e42 | 763 | extern gdb::array_view<const gdb_byte> value_contents (struct value *); |
c906108c SS |
764 | |
765 | /* The ALL variants of the above two macros do not adjust the returned | |
dea7f9ba | 766 | pointer by the embedded_offset value. */ |
c5aa993b | 767 | |
50888e42 | 768 | extern gdb::array_view<const gdb_byte> value_contents_all (struct value *); |
c5aa993b | 769 | |
0e03807e TT |
770 | /* Like value_contents_all, but does not require that the returned |
771 | bits be valid. This should only be used in situations where you | |
772 | plan to check the validity manually. */ | |
50888e42 | 773 | extern gdb::array_view<const gdb_byte> value_contents_for_printing (struct value *value); |
0e03807e | 774 | |
de4127a3 PA |
775 | /* Like value_contents_for_printing, but accepts a constant value |
776 | pointer. Unlike value_contents_for_printing however, the pointed | |
777 | value must _not_ be lazy. */ | |
50888e42 | 778 | extern gdb::array_view<const gdb_byte> |
de4127a3 PA |
779 | value_contents_for_printing_const (const struct value *value); |
780 | ||
91294c83 | 781 | /* If nonzero, this is the value of a variable which does not actually |
eca07816 JB |
782 | exist in the program, at least partially. If the value is lazy, |
783 | this may fetch it now. */ | |
feb13ab0 | 784 | extern int value_optimized_out (struct value *value); |
c906108c | 785 | |
9a0dc9e3 PA |
786 | /* Given a value, return true if any of the contents bits starting at |
787 | OFFSET and extending for LENGTH bits is optimized out, false | |
788 | otherwise. */ | |
789 | ||
790 | extern int value_bits_any_optimized_out (const struct value *value, | |
791 | int bit_offset, int bit_length); | |
792 | ||
793 | /* Like value_optimized_out, but return true iff the whole value is | |
794 | optimized out. */ | |
795 | extern int value_entirely_optimized_out (struct value *value); | |
796 | ||
797 | /* Mark VALUE's content bytes starting at OFFSET and extending for | |
798 | LENGTH bytes as optimized out. */ | |
799 | ||
800 | extern void mark_value_bytes_optimized_out (struct value *value, | |
801 | int offset, int length); | |
802 | ||
803 | /* Mark VALUE's content bits starting at OFFSET and extending for | |
804 | LENGTH bits as optimized out. */ | |
eca07816 | 805 | |
9a0dc9e3 | 806 | extern void mark_value_bits_optimized_out (struct value *value, |
6b850546 | 807 | LONGEST offset, LONGEST length); |
0e03807e | 808 | |
74bcbdf3 PA |
809 | /* Set COMPONENT's location as appropriate for a component of WHOLE |
810 | --- regardless of what kind of lvalue WHOLE is. */ | |
811 | extern void set_value_component_location (struct value *component, | |
dda83cd7 | 812 | const struct value *whole); |
74bcbdf3 | 813 | |
13bb5560 AC |
814 | /* While the following fields are per- VALUE .CONTENT .PIECE (i.e., a |
815 | single value might have multiple LVALs), this hacked interface is | |
816 | limited to just the first PIECE. Expect further change. */ | |
91294c83 AC |
817 | /* Type of value; either not an lval, or one of the various different |
818 | possible kinds of lval. */ | |
97044105 | 819 | #define VALUE_LVAL(val) (*((val)->deprecated_lval_hack ())) |
a471c594 | 820 | |
91294c83 | 821 | /* Pointer to internal variable. */ |
f29de665 | 822 | #define VALUE_INTERNALVAR(val) (*((val)->deprecated_internalvar_hack ())) |
91294c83 | 823 | |
41b56feb KB |
824 | /* Frame ID of "next" frame to which a register value is relative. A |
825 | register value is indicated by VALUE_LVAL being set to lval_register. | |
826 | So, if the register value is found relative to frame F, then the | |
827 | frame id of F->next will be stored in VALUE_NEXT_FRAME_ID. */ | |
f29de665 | 828 | #define VALUE_NEXT_FRAME_ID(val) (*((val)->deprecated_next_frame_id_hack ())) |
41b56feb | 829 | |
91294c83 | 830 | /* Register number if the value is from a register. */ |
f29de665 | 831 | #define VALUE_REGNUM(val) (*((val)->deprecated_regnum_hack ())) |
13bb5560 | 832 | |
a471c594 JK |
833 | /* Return value after lval_funcs->coerce_ref (after check_typedef). Return |
834 | NULL if lval_funcs->coerce_ref is not applicable for whatever reason. */ | |
835 | ||
836 | extern struct value *coerce_ref_if_computed (const struct value *arg); | |
837 | ||
dfcee124 AG |
838 | /* Setup a new value type and enclosing value type for dereferenced value VALUE. |
839 | ENC_TYPE is the new enclosing type that should be set. ORIGINAL_TYPE and | |
e79eb02f AB |
840 | ORIGINAL_VAL are the type and value of the original reference or |
841 | pointer. ORIGINAL_VALUE_ADDRESS is the address within VALUE, that is | |
842 | the address that was dereferenced. | |
dfcee124 AG |
843 | |
844 | Note, that VALUE is modified by this function. | |
845 | ||
846 | It is a common implementation for coerce_ref and value_ind. */ | |
847 | ||
848 | extern struct value * readjust_indirect_value_type (struct value *value, | |
849 | struct type *enc_type, | |
4bf7b526 | 850 | const struct type *original_type, |
e79eb02f AB |
851 | struct value *original_val, |
852 | CORE_ADDR original_value_address); | |
dfcee124 | 853 | |
dea7f9ba | 854 | /* Convert a REF to the object referenced. */ |
c906108c | 855 | |
994b9211 | 856 | extern struct value *coerce_ref (struct value *value); |
c906108c SS |
857 | |
858 | /* If ARG is an array, convert it to a pointer. | |
c906108c SS |
859 | If ARG is a function, convert it to a function pointer. |
860 | ||
861 | References are dereferenced. */ | |
862 | ||
994b9211 | 863 | extern struct value *coerce_array (struct value *value); |
c906108c | 864 | |
8cf6f0b1 TT |
865 | /* Given a value, determine whether the bits starting at OFFSET and |
866 | extending for LENGTH bits are a synthetic pointer. */ | |
867 | ||
868 | extern int value_bits_synthetic_pointer (const struct value *value, | |
6b850546 | 869 | LONGEST offset, LONGEST length); |
8cf6f0b1 | 870 | |
4e07d55f PA |
871 | /* Given a value, determine whether the contents bytes starting at |
872 | OFFSET and extending for LENGTH bytes are available. This returns | |
873 | nonzero if all bytes in the given range are available, zero if any | |
874 | byte is unavailable. */ | |
875 | ||
876 | extern int value_bytes_available (const struct value *value, | |
4f82620c | 877 | LONGEST offset, ULONGEST length); |
4e07d55f | 878 | |
bdf22206 AB |
879 | /* Given a value, determine whether the contents bits starting at |
880 | OFFSET and extending for LENGTH bits are available. This returns | |
881 | nonzero if all bits in the given range are available, zero if any | |
882 | bit is unavailable. */ | |
883 | ||
884 | extern int value_bits_available (const struct value *value, | |
4f82620c | 885 | LONGEST offset, ULONGEST length); |
bdf22206 | 886 | |
ec0a52e1 PA |
887 | /* Like value_bytes_available, but return false if any byte in the |
888 | whole object is unavailable. */ | |
889 | extern int value_entirely_available (struct value *value); | |
890 | ||
6211c335 YQ |
891 | /* Like value_entirely_available, but return false if any byte in the |
892 | whole object is available. */ | |
893 | extern int value_entirely_unavailable (struct value *value); | |
894 | ||
4e07d55f PA |
895 | /* Mark VALUE's content bytes starting at OFFSET and extending for |
896 | LENGTH bytes as unavailable. */ | |
897 | ||
898 | extern void mark_value_bytes_unavailable (struct value *value, | |
4f82620c | 899 | LONGEST offset, ULONGEST length); |
c8c1c22f | 900 | |
bdf22206 AB |
901 | /* Mark VALUE's content bits starting at OFFSET and extending for |
902 | LENGTH bits as unavailable. */ | |
903 | ||
904 | extern void mark_value_bits_unavailable (struct value *value, | |
4f82620c | 905 | LONGEST offset, ULONGEST length); |
bdf22206 | 906 | |
3ae385af SM |
907 | /* Read LENGTH addressable memory units starting at MEMADDR into BUFFER, |
908 | which is (or will be copied to) VAL's contents buffer offset by | |
23f945bf AA |
909 | BIT_OFFSET bits. Marks value contents ranges as unavailable if |
910 | the corresponding memory is likewise unavailable. STACK indicates | |
911 | whether the memory is known to be stack memory. */ | |
e6ca34fc | 912 | |
23f945bf | 913 | extern void read_value_memory (struct value *val, LONGEST bit_offset, |
e6ca34fc PA |
914 | int stack, CORE_ADDR memaddr, |
915 | gdb_byte *buffer, size_t length); | |
916 | ||
8954db33 AB |
917 | /* Cast SCALAR_VALUE to the element type of VECTOR_TYPE, then replicate |
918 | into each element of a new vector value with VECTOR_TYPE. */ | |
919 | ||
920 | struct value *value_vector_widen (struct value *scalar_value, | |
921 | struct type *vector_type); | |
922 | ||
c906108c | 923 | \f |
c5aa993b | 924 | |
c906108c SS |
925 | #include "symtab.h" |
926 | #include "gdbtypes.h" | |
927 | #include "expression.h" | |
928 | ||
bd2b40ac | 929 | class frame_info_ptr; |
c906108c | 930 | struct fn_field; |
c906108c | 931 | |
9cb709b6 TT |
932 | extern int print_address_demangle (const struct value_print_options *, |
933 | struct gdbarch *, CORE_ADDR, | |
934 | struct ui_file *, int); | |
c906108c | 935 | |
70100014 UW |
936 | /* Returns true if VAL is of floating-point type. In addition, |
937 | throws an error if the value is an invalid floating-point value. */ | |
938 | extern bool is_floating_value (struct value *val); | |
939 | ||
f23631e4 | 940 | extern LONGEST value_as_long (struct value *val); |
f23631e4 | 941 | extern CORE_ADDR value_as_address (struct value *val); |
c906108c | 942 | |
fc1a4b47 | 943 | extern LONGEST unpack_long (struct type *type, const gdb_byte *valaddr); |
fc1a4b47 | 944 | extern CORE_ADDR unpack_pointer (struct type *type, const gdb_byte *valaddr); |
5467c6c8 | 945 | |
8929e59d | 946 | extern LONGEST unpack_field_as_long (struct type *type, |
fc1a4b47 | 947 | const gdb_byte *valaddr, |
a14ed312 | 948 | int fieldno); |
ef83a141 TT |
949 | |
950 | /* Unpack a bitfield of the specified FIELD_TYPE, from the object at | |
951 | VALADDR, and store the result in *RESULT. | |
952 | The bitfield starts at BITPOS bits and contains BITSIZE bits; if | |
953 | BITSIZE is zero, then the length is taken from FIELD_TYPE. | |
954 | ||
955 | Extracting bits depends on endianness of the machine. Compute the | |
956 | number of least significant bits to discard. For big endian machines, | |
957 | we compute the total number of bits in the anonymous object, subtract | |
958 | off the bit count from the MSB of the object to the MSB of the | |
959 | bitfield, then the size of the bitfield, which leaves the LSB discard | |
960 | count. For little endian machines, the discard count is simply the | |
961 | number of bits from the LSB of the anonymous object to the LSB of the | |
962 | bitfield. | |
963 | ||
964 | If the field is signed, we also do sign extension. */ | |
965 | ||
966 | extern LONGEST unpack_bits_as_long (struct type *field_type, | |
967 | const gdb_byte *valaddr, | |
968 | LONGEST bitpos, LONGEST bitsize); | |
969 | ||
5467c6c8 | 970 | extern int unpack_value_field_as_long (struct type *type, const gdb_byte *valaddr, |
6b850546 | 971 | LONGEST embedded_offset, int fieldno, |
5467c6c8 PA |
972 | const struct value *val, LONGEST *result); |
973 | ||
bb9d5f81 | 974 | extern void unpack_value_bitfield (struct value *dest_val, |
6b850546 DT |
975 | LONGEST bitpos, LONGEST bitsize, |
976 | const gdb_byte *valaddr, | |
977 | LONGEST embedded_offset, | |
bb9d5f81 PP |
978 | const struct value *val); |
979 | ||
5467c6c8 PA |
980 | extern struct value *value_field_bitfield (struct type *type, int fieldno, |
981 | const gdb_byte *valaddr, | |
6b850546 | 982 | LONGEST embedded_offset, |
5467c6c8 | 983 | const struct value *val); |
c906108c | 984 | |
14d06750 DJ |
985 | extern void pack_long (gdb_byte *buf, struct type *type, LONGEST num); |
986 | ||
f23631e4 | 987 | extern struct value *value_from_longest (struct type *type, LONGEST num); |
595939de | 988 | extern struct value *value_from_ulongest (struct type *type, ULONGEST num); |
f23631e4 | 989 | extern struct value *value_from_pointer (struct type *type, CORE_ADDR addr); |
7584bb30 | 990 | extern struct value *value_from_host_double (struct type *type, double d); |
e799154c | 991 | extern struct value *value_from_history_ref (const char *, const char **); |
3fff9862 YQ |
992 | extern struct value *value_from_component (struct value *, struct type *, |
993 | LONGEST); | |
0f71a2f6 | 994 | |
e379f652 TT |
995 | |
996 | /* Create a new value by extracting it from WHOLE. TYPE is the type | |
997 | of the new value. BIT_OFFSET and BIT_LENGTH describe the offset | |
998 | and field width of the value to extract from WHOLE -- BIT_LENGTH | |
999 | may differ from TYPE's length in the case where WHOLE's type is | |
1000 | packed. | |
1001 | ||
1002 | When the value does come from a non-byte-aligned offset or field | |
1003 | width, it will be marked non_lval. */ | |
1004 | ||
1005 | extern struct value *value_from_component_bitsize (struct value *whole, | |
1006 | struct type *type, | |
1007 | LONGEST bit_offset, | |
1008 | LONGEST bit_length); | |
1009 | ||
00a4c844 AC |
1010 | extern struct value *value_at (struct type *type, CORE_ADDR addr); |
1011 | extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr); | |
c906108c | 1012 | |
7f22044a TT |
1013 | /* Like value_at, but ensures that the result is marked not_lval. |
1014 | This can be important if the memory is "volatile". */ | |
1015 | extern struct value *value_at_non_lval (struct type *type, CORE_ADDR addr); | |
1016 | ||
012370f6 TT |
1017 | extern struct value *value_from_contents_and_address_unresolved |
1018 | (struct type *, const gdb_byte *, CORE_ADDR); | |
8acb6b92 TT |
1019 | extern struct value *value_from_contents_and_address (struct type *, |
1020 | const gdb_byte *, | |
1021 | CORE_ADDR); | |
8a9b8146 | 1022 | extern struct value *value_from_contents (struct type *, const gdb_byte *); |
8acb6b92 | 1023 | |
2ed3c037 UW |
1024 | extern struct value *default_value_from_register (struct gdbarch *gdbarch, |
1025 | struct type *type, | |
9acbedc0 | 1026 | int regnum, |
2ed3c037 | 1027 | struct frame_id frame_id); |
9acbedc0 | 1028 | |
b56d6f31 | 1029 | extern void read_frame_register_value (struct value *value, |
bd2b40ac | 1030 | frame_info_ptr frame); |
b56d6f31 | 1031 | |
f23631e4 | 1032 | extern struct value *value_from_register (struct type *type, int regnum, |
bd2b40ac | 1033 | frame_info_ptr frame); |
c906108c | 1034 | |
2ed3c037 | 1035 | extern CORE_ADDR address_from_register (int regnum, |
bd2b40ac | 1036 | frame_info_ptr frame); |
0b2b0195 | 1037 | |
9df2fbc4 PM |
1038 | extern struct value *value_of_variable (struct symbol *var, |
1039 | const struct block *b); | |
c906108c | 1040 | |
270140bd TT |
1041 | extern struct value *address_of_variable (struct symbol *var, |
1042 | const struct block *b); | |
61212c0f | 1043 | |
bd2b40ac | 1044 | extern struct value *value_of_register (int regnum, frame_info_ptr frame); |
c906108c | 1045 | |
bd2b40ac | 1046 | struct value *value_of_register_lazy (frame_info_ptr frame, int regnum); |
9214ee5f | 1047 | |
0b31a4bc TT |
1048 | /* Return the symbol's reading requirement. */ |
1049 | ||
1050 | extern enum symbol_needs_kind symbol_read_needs (struct symbol *); | |
1051 | ||
1052 | /* Return true if the symbol needs a frame. This is a wrapper for | |
1053 | symbol_read_needs that simply checks for SYMBOL_NEEDS_FRAME. */ | |
1054 | ||
a14ed312 | 1055 | extern int symbol_read_needs_frame (struct symbol *); |
c906108c | 1056 | |
f23631e4 | 1057 | extern struct value *read_var_value (struct symbol *var, |
63e43d3a | 1058 | const struct block *var_block, |
bd2b40ac | 1059 | frame_info_ptr frame); |
c906108c | 1060 | |
6b850546 DT |
1061 | extern void value_contents_copy (struct value *dst, LONGEST dst_offset, |
1062 | struct value *src, LONGEST src_offset, | |
1063 | LONGEST length); | |
c906108c | 1064 | |
f23631e4 | 1065 | extern struct value *allocate_repeat_value (struct type *type, int count); |
c906108c | 1066 | |
f23631e4 | 1067 | extern struct value *value_mark (void); |
c906108c | 1068 | |
4bf7b526 | 1069 | extern void value_free_to_mark (const struct value *mark); |
c906108c | 1070 | |
eb115069 TT |
1071 | /* A helper class that uses value_mark at construction time and calls |
1072 | value_free_to_mark in the destructor. This is used to clear out | |
1073 | temporary values created during the lifetime of this object. */ | |
1074 | class scoped_value_mark | |
1075 | { | |
1076 | public: | |
1077 | ||
1078 | scoped_value_mark () | |
1079 | : m_value (value_mark ()) | |
1080 | { | |
1081 | } | |
1082 | ||
1083 | ~scoped_value_mark () | |
1084 | { | |
0cf08227 TT |
1085 | free_to_mark (); |
1086 | } | |
1087 | ||
54f70bc1 TT |
1088 | scoped_value_mark (scoped_value_mark &&other) = default; |
1089 | ||
1090 | DISABLE_COPY_AND_ASSIGN (scoped_value_mark); | |
1091 | ||
0cf08227 TT |
1092 | /* Free the values currently on the value stack. */ |
1093 | void free_to_mark () | |
1094 | { | |
1095 | if (m_value != NULL) | |
1096 | { | |
1097 | value_free_to_mark (m_value); | |
1098 | m_value = NULL; | |
1099 | } | |
eb115069 TT |
1100 | } |
1101 | ||
1102 | private: | |
1103 | ||
1104 | const struct value *m_value; | |
1105 | }; | |
1106 | ||
e3a3797e | 1107 | extern struct value *value_cstring (const char *ptr, ssize_t len, |
3b7538c0 | 1108 | struct type *char_type); |
7cc3f8e2 | 1109 | extern struct value *value_string (const char *ptr, ssize_t len, |
3b7538c0 | 1110 | struct type *char_type); |
c906108c | 1111 | |
f23631e4 | 1112 | extern struct value *value_array (int lowbound, int highbound, |
89f5065b | 1113 | struct value **elemvec); |
c906108c | 1114 | |
f23631e4 | 1115 | extern struct value *value_concat (struct value *arg1, struct value *arg2); |
c906108c | 1116 | |
f23631e4 AC |
1117 | extern struct value *value_binop (struct value *arg1, struct value *arg2, |
1118 | enum exp_opcode op); | |
c906108c | 1119 | |
2497b498 | 1120 | extern struct value *value_ptradd (struct value *arg1, LONGEST arg2); |
89eef114 UW |
1121 | |
1122 | extern LONGEST value_ptrdiff (struct value *arg1, struct value *arg2); | |
c906108c | 1123 | |
00db9531 SM |
1124 | /* Return true if VAL does not live in target memory, but should in order |
1125 | to operate on it. Otherwise return false. */ | |
1126 | ||
1127 | extern bool value_must_coerce_to_target (struct value *arg1); | |
63092375 DJ |
1128 | |
1129 | extern struct value *value_coerce_to_target (struct value *arg1); | |
1130 | ||
f23631e4 | 1131 | extern struct value *value_coerce_array (struct value *arg1); |
c906108c | 1132 | |
f23631e4 | 1133 | extern struct value *value_coerce_function (struct value *arg1); |
c906108c | 1134 | |
f23631e4 | 1135 | extern struct value *value_ind (struct value *arg1); |
c906108c | 1136 | |
f23631e4 | 1137 | extern struct value *value_addr (struct value *arg1); |
c906108c | 1138 | |
a65cfae5 | 1139 | extern struct value *value_ref (struct value *arg1, enum type_code refcode); |
fb933624 | 1140 | |
89f5065b AC |
1141 | extern struct value *value_assign (struct value *toval, |
1142 | struct value *fromval); | |
c906108c | 1143 | |
36e9969c NS |
1144 | extern struct value *value_pos (struct value *arg1); |
1145 | ||
f23631e4 | 1146 | extern struct value *value_neg (struct value *arg1); |
c906108c | 1147 | |
f23631e4 | 1148 | extern struct value *value_complement (struct value *arg1); |
c906108c | 1149 | |
f23631e4 | 1150 | extern struct value *value_struct_elt (struct value **argp, |
158cc4fe | 1151 | gdb::optional<gdb::array_view <value *>> args, |
714f19d5 TT |
1152 | const char *name, int *static_memfuncp, |
1153 | const char *err); | |
c906108c | 1154 | |
b5b08fb4 SC |
1155 | extern struct value *value_struct_elt_bitpos (struct value **argp, |
1156 | int bitpos, | |
1157 | struct type *field_type, | |
1158 | const char *err); | |
1159 | ||
79c2c32d | 1160 | extern struct value *value_aggregate_elt (struct type *curtype, |
c848d642 | 1161 | const char *name, |
072bba3b | 1162 | struct type *expect_type, |
0d5de010 DJ |
1163 | int want_address, |
1164 | enum noside noside); | |
c906108c | 1165 | |
f23631e4 | 1166 | extern struct value *value_static_field (struct type *type, int fieldno); |
c906108c | 1167 | |
4c3376c8 SW |
1168 | enum oload_search_type { NON_METHOD, METHOD, BOTH }; |
1169 | ||
6b1747cd | 1170 | extern int find_overload_match (gdb::array_view<value *> args, |
4c3376c8 | 1171 | const char *name, |
28c64fc2 | 1172 | enum oload_search_type method, |
7f8c9282 | 1173 | struct value **objp, struct symbol *fsym, |
f23631e4 | 1174 | struct value **valp, struct symbol **symp, |
e66d4446 SC |
1175 | int *staticp, const int no_adl, |
1176 | enum noside noside); | |
c906108c | 1177 | |
f23631e4 | 1178 | extern struct value *value_field (struct value *arg1, int fieldno); |
c906108c | 1179 | |
6b850546 | 1180 | extern struct value *value_primitive_field (struct value *arg1, LONGEST offset, |
f23631e4 AC |
1181 | int fieldno, |
1182 | struct type *arg_type); | |
c906108c | 1183 | |
c906108c | 1184 | |
6b850546 | 1185 | extern struct type *value_rtti_indirect_type (struct value *, int *, LONGEST *, |
dfcee124 | 1186 | int *); |
c906108c | 1187 | |
f23631e4 AC |
1188 | extern struct value *value_full_object (struct value *, struct type *, int, |
1189 | int, int); | |
c906108c | 1190 | |
b1af9e97 | 1191 | extern struct value *value_cast_pointers (struct type *, struct value *, int); |
fb933624 | 1192 | |
f23631e4 | 1193 | extern struct value *value_cast (struct type *type, struct value *arg2); |
c906108c | 1194 | |
4e8f195d TT |
1195 | extern struct value *value_reinterpret_cast (struct type *type, |
1196 | struct value *arg); | |
1197 | ||
1198 | extern struct value *value_dynamic_cast (struct type *type, struct value *arg); | |
1199 | ||
18a46dbe | 1200 | extern struct value *value_one (struct type *type); |
301f0ecf | 1201 | |
f23631e4 | 1202 | extern struct value *value_repeat (struct value *arg1, int count); |
c906108c | 1203 | |
2497b498 | 1204 | extern struct value *value_subscript (struct value *array, LONGEST index); |
c906108c | 1205 | |
afc05acb UW |
1206 | extern struct value *value_bitstring_subscript (struct type *type, |
1207 | struct value *bitstring, | |
2497b498 | 1208 | LONGEST index); |
afc05acb | 1209 | |
5fe830e4 AC |
1210 | extern struct value *register_value_being_returned (struct type *valtype, |
1211 | struct regcache *retbuf); | |
c906108c | 1212 | |
fbb06eb1 | 1213 | extern int value_in (struct value *element, struct value *set); |
c906108c | 1214 | |
fc1a4b47 | 1215 | extern int value_bit_index (struct type *type, const gdb_byte *addr, |
c84141d6 | 1216 | int index); |
c906108c | 1217 | |
bbfdfe1c DM |
1218 | extern enum return_value_convention |
1219 | struct_return_convention (struct gdbarch *gdbarch, struct value *function, | |
1220 | struct type *value_type); | |
1221 | ||
d80b854b | 1222 | extern int using_struct_return (struct gdbarch *gdbarch, |
6a3a010b | 1223 | struct value *function, |
c055b101 | 1224 | struct type *value_type); |
c906108c | 1225 | |
efd7ff14 TT |
1226 | /* Evaluate the expression EXP. If set, EXPECT_TYPE is passed to the |
1227 | outermost operation's evaluation. This is ignored by most | |
1228 | operations, but may be used, e.g., to determine the type of an | |
1229 | otherwise untyped symbol. The caller should not assume that the | |
1230 | returned value has this type. */ | |
1231 | ||
1232 | extern struct value *evaluate_expression (struct expression *exp, | |
1233 | struct type *expect_type = nullptr); | |
c906108c | 1234 | |
f23631e4 | 1235 | extern struct value *evaluate_type (struct expression *exp); |
c906108c | 1236 | |
ced9779b JB |
1237 | extern value *evaluate_var_value (enum noside noside, const block *blk, |
1238 | symbol *var); | |
1239 | ||
1240 | extern value *evaluate_var_msym_value (enum noside noside, | |
1241 | struct objfile *objfile, | |
1242 | minimal_symbol *msymbol); | |
1243 | ||
413403fc | 1244 | namespace expr { class operation; }; |
1eaebe02 | 1245 | extern void fetch_subexp_value (struct expression *exp, |
413403fc | 1246 | expr::operation *op, |
0cf6dd15 | 1247 | struct value **valp, struct value **resultp, |
a6535de1 | 1248 | std::vector<value_ref_ptr> *val_chain, |
2e362716 | 1249 | bool preserve_errors); |
0cf6dd15 | 1250 | |
bbc13ae3 | 1251 | extern struct value *parse_and_eval (const char *exp); |
c906108c | 1252 | |
bbc13ae3 | 1253 | extern struct value *parse_to_comma_and_eval (const char **expp); |
c906108c | 1254 | |
f5756acc | 1255 | extern struct type *parse_and_eval_type (const char *p, int length); |
c906108c | 1256 | |
bbc13ae3 | 1257 | extern CORE_ADDR parse_and_eval_address (const char *exp); |
c906108c | 1258 | |
a1b8c4cc | 1259 | extern LONGEST parse_and_eval_long (const char *exp); |
bb518678 | 1260 | |
4066e646 UW |
1261 | extern void unop_promote (const struct language_defn *language, |
1262 | struct gdbarch *gdbarch, | |
1263 | struct value **arg1); | |
1264 | ||
1265 | extern void binop_promote (const struct language_defn *language, | |
1266 | struct gdbarch *gdbarch, | |
1267 | struct value **arg1, struct value **arg2); | |
1268 | ||
f23631e4 | 1269 | extern struct value *access_value_history (int num); |
c906108c | 1270 | |
30a87e90 AB |
1271 | /* Return the number of items in the value history. */ |
1272 | ||
1273 | extern ULONGEST value_history_count (); | |
1274 | ||
78267919 UW |
1275 | extern struct value *value_of_internalvar (struct gdbarch *gdbarch, |
1276 | struct internalvar *var); | |
c906108c | 1277 | |
4fa62494 UW |
1278 | extern int get_internalvar_integer (struct internalvar *var, LONGEST *l); |
1279 | ||
f23631e4 | 1280 | extern void set_internalvar (struct internalvar *var, struct value *val); |
c906108c | 1281 | |
4fa62494 UW |
1282 | extern void set_internalvar_integer (struct internalvar *var, LONGEST l); |
1283 | ||
78267919 UW |
1284 | extern void set_internalvar_string (struct internalvar *var, |
1285 | const char *string); | |
1286 | ||
4fa62494 UW |
1287 | extern void clear_internalvar (struct internalvar *var); |
1288 | ||
a14ed312 | 1289 | extern void set_internalvar_component (struct internalvar *var, |
6b850546 DT |
1290 | LONGEST offset, |
1291 | LONGEST bitpos, LONGEST bitsize, | |
f23631e4 | 1292 | struct value *newvalue); |
c906108c | 1293 | |
bc3b79fd | 1294 | extern struct internalvar *lookup_only_internalvar (const char *name); |
c4a3d09a | 1295 | |
bc3b79fd | 1296 | extern struct internalvar *create_internalvar (const char *name); |
c4a3d09a | 1297 | |
eb3ff9a5 PA |
1298 | extern void complete_internalvar (completion_tracker &tracker, |
1299 | const char *name); | |
d55637df | 1300 | |
22d2b532 SDJ |
1301 | /* An internalvar can be dynamically computed by supplying a vector of |
1302 | function pointers to perform various operations. */ | |
1303 | ||
1304 | struct internalvar_funcs | |
1305 | { | |
1306 | /* Compute the value of the variable. The DATA argument passed to | |
1307 | the function is the same argument that was passed to | |
1308 | `create_internalvar_type_lazy'. */ | |
1309 | ||
1310 | struct value *(*make_value) (struct gdbarch *arch, | |
1311 | struct internalvar *var, | |
1312 | void *data); | |
1313 | ||
1314 | /* Update the agent expression EXPR with bytecode to compute the | |
1315 | value. VALUE is the agent value we are updating. The DATA | |
1316 | argument passed to this function is the same argument that was | |
1317 | passed to `create_internalvar_type_lazy'. If this pointer is | |
1318 | NULL, then the internalvar cannot be compiled to an agent | |
1319 | expression. */ | |
1320 | ||
1321 | void (*compile_to_ax) (struct internalvar *var, | |
1322 | struct agent_expr *expr, | |
1323 | struct axs_value *value, | |
1324 | void *data); | |
22d2b532 SDJ |
1325 | }; |
1326 | ||
73033f12 SDJ |
1327 | extern struct internalvar *create_internalvar_type_lazy (const char *name, |
1328 | const struct internalvar_funcs *funcs, | |
1329 | void *data); | |
22d2b532 SDJ |
1330 | |
1331 | /* Compile an internal variable to an agent expression. VAR is the | |
1332 | variable to compile; EXPR and VALUE are the agent expression we are | |
1333 | updating. This will return 0 if there is no known way to compile | |
1334 | VAR, and 1 if VAR was successfully compiled. It may also throw an | |
1335 | exception on error. */ | |
1336 | ||
1337 | extern int compile_internalvar_to_ax (struct internalvar *var, | |
1338 | struct agent_expr *expr, | |
1339 | struct axs_value *value); | |
4aa995e1 | 1340 | |
bc3b79fd | 1341 | extern struct internalvar *lookup_internalvar (const char *name); |
c906108c | 1342 | |
f23631e4 | 1343 | extern int value_equal (struct value *arg1, struct value *arg2); |
c906108c | 1344 | |
218d2fc6 TJB |
1345 | extern int value_equal_contents (struct value *arg1, struct value *arg2); |
1346 | ||
f23631e4 | 1347 | extern int value_less (struct value *arg1, struct value *arg2); |
c906108c | 1348 | |
7ebaa5f7 TT |
1349 | /* Simulate the C operator ! -- return true if ARG1 contains zero. */ |
1350 | extern bool value_logical_not (struct value *arg1); | |
1351 | ||
1352 | /* Returns true if the value VAL represents a true value. */ | |
1353 | static inline bool | |
1354 | value_true (struct value *val) | |
1355 | { | |
1356 | return !value_logical_not (val); | |
1357 | } | |
c906108c SS |
1358 | |
1359 | /* C++ */ | |
1360 | ||
85bc8cb7 JK |
1361 | extern struct value *value_of_this (const struct language_defn *lang); |
1362 | ||
1363 | extern struct value *value_of_this_silent (const struct language_defn *lang); | |
c906108c | 1364 | |
f23631e4 AC |
1365 | extern struct value *value_x_binop (struct value *arg1, struct value *arg2, |
1366 | enum exp_opcode op, | |
1367 | enum exp_opcode otherop, | |
1368 | enum noside noside); | |
c906108c | 1369 | |
f23631e4 AC |
1370 | extern struct value *value_x_unop (struct value *arg1, enum exp_opcode op, |
1371 | enum noside noside); | |
c906108c | 1372 | |
89f5065b | 1373 | extern struct value *value_fn_field (struct value **arg1p, struct fn_field *f, |
6b850546 | 1374 | int j, struct type *type, LONGEST offset); |
c906108c | 1375 | |
be636754 PA |
1376 | extern int binop_types_user_defined_p (enum exp_opcode op, |
1377 | struct type *type1, | |
1378 | struct type *type2); | |
1379 | ||
f23631e4 AC |
1380 | extern int binop_user_defined_p (enum exp_opcode op, struct value *arg1, |
1381 | struct value *arg2); | |
c906108c | 1382 | |
f23631e4 | 1383 | extern int unop_user_defined_p (enum exp_opcode op, struct value *arg1); |
c906108c | 1384 | |
d8228535 | 1385 | extern int destructor_name_p (const char *name, struct type *type); |
c906108c | 1386 | |
22bc8444 | 1387 | extern value_ref_ptr release_value (struct value *val); |
e848a8a5 | 1388 | |
f23631e4 | 1389 | extern int record_latest_value (struct value *val); |
c906108c | 1390 | |
50810684 | 1391 | extern void modify_field (struct type *type, gdb_byte *addr, |
6b850546 | 1392 | LONGEST fieldval, LONGEST bitpos, LONGEST bitsize); |
c906108c | 1393 | |
0d5cff50 | 1394 | extern void type_print (struct type *type, const char *varstring, |
89f5065b | 1395 | struct ui_file *stream, int show); |
c906108c | 1396 | |
2f408ecb | 1397 | extern std::string type_to_string (struct type *type); |
ae6a3a4c | 1398 | |
fc1a4b47 AC |
1399 | extern gdb_byte *baseclass_addr (struct type *type, int index, |
1400 | gdb_byte *valaddr, | |
8929e59d | 1401 | struct value **valuep, int *errp); |
c906108c | 1402 | |
89f5065b | 1403 | extern void print_longest (struct ui_file *stream, int format, |
d9fcf2fb | 1404 | int use_local, LONGEST val); |
c906108c | 1405 | |
fc1a4b47 | 1406 | extern void print_floating (const gdb_byte *valaddr, struct type *type, |
89f5065b | 1407 | struct ui_file *stream); |
c906108c | 1408 | |
8e069a98 TT |
1409 | extern void value_print (struct value *val, struct ui_file *stream, |
1410 | const struct value_print_options *options); | |
c906108c | 1411 | |
a6535de1 TT |
1412 | /* Release values from the value chain and return them. Values |
1413 | created after MARK are released. If MARK is nullptr, or if MARK is | |
1414 | not found on the value chain, then all values are released. Values | |
1415 | are returned in reverse order of creation; that is, newest | |
1416 | first. */ | |
1417 | ||
1418 | extern std::vector<value_ref_ptr> value_release_to_mark | |
1419 | (const struct value *mark); | |
c906108c | 1420 | |
a1f5dd1b TT |
1421 | extern void common_val_print (struct value *val, |
1422 | struct ui_file *stream, int recurse, | |
1423 | const struct value_print_options *options, | |
1424 | const struct language_defn *language); | |
806048c6 | 1425 | |
09ca9e2e TT |
1426 | extern int val_print_string (struct type *elttype, const char *encoding, |
1427 | CORE_ADDR addr, int len, | |
79a45b7d TT |
1428 | struct ui_file *stream, |
1429 | const struct value_print_options *options); | |
c906108c | 1430 | |
aad95b57 TT |
1431 | extern void print_variable_and_value (const char *name, |
1432 | struct symbol *var, | |
bd2b40ac | 1433 | frame_info_ptr frame, |
aad95b57 TT |
1434 | struct ui_file *stream, |
1435 | int indent); | |
c906108c | 1436 | |
89f5065b AC |
1437 | extern void typedef_print (struct type *type, struct symbol *news, |
1438 | struct ui_file *stream); | |
c906108c | 1439 | |
baf20f76 | 1440 | extern const char *internalvar_name (const struct internalvar *var); |
c906108c | 1441 | |
ae5a43e0 | 1442 | extern void preserve_values (struct objfile *); |
c906108c SS |
1443 | |
1444 | /* From values.c */ | |
1445 | ||
5f8ab46b | 1446 | extern struct value *value_copy (const value *); |
c906108c | 1447 | |
c37f7098 KW |
1448 | extern struct value *value_non_lval (struct value *); |
1449 | ||
6c659fc2 SC |
1450 | extern void value_force_lval (struct value *, CORE_ADDR); |
1451 | ||
4c082a81 SC |
1452 | extern struct value *make_cv_value (int, int, struct value *); |
1453 | ||
4e7a5ef5 TT |
1454 | extern void preserve_one_value (struct value *, struct objfile *, htab_t); |
1455 | ||
c906108c SS |
1456 | /* From valops.c */ |
1457 | ||
f23631e4 | 1458 | extern struct value *varying_to_slice (struct value *); |
c906108c | 1459 | |
f23631e4 | 1460 | extern struct value *value_slice (struct value *, int, int); |
c906108c | 1461 | |
6b4a335b TT |
1462 | /* Create a complex number. The type is the complex type; the values |
1463 | are cast to the underlying scalar type before the complex number is | |
1464 | created. */ | |
1465 | ||
f23631e4 AC |
1466 | extern struct value *value_literal_complex (struct value *, struct value *, |
1467 | struct type *); | |
c906108c | 1468 | |
4c99290d TT |
1469 | /* Return the real part of a complex value. */ |
1470 | ||
1471 | extern struct value *value_real_part (struct value *value); | |
1472 | ||
1473 | /* Return the imaginary part of a complex value. */ | |
1474 | ||
1475 | extern struct value *value_imaginary_part (struct value *value); | |
1476 | ||
3e3b026f UW |
1477 | extern struct value *find_function_in_inferior (const char *, |
1478 | struct objfile **); | |
c906108c | 1479 | |
f23631e4 | 1480 | extern struct value *value_allocate_space_in_inferior (int); |
c906108c | 1481 | |
bc3b79fd TJB |
1482 | /* User function handler. */ |
1483 | ||
d452c4bc UW |
1484 | typedef struct value *(*internal_function_fn) (struct gdbarch *gdbarch, |
1485 | const struct language_defn *language, | |
1486 | void *cookie, | |
bc3b79fd TJB |
1487 | int argc, |
1488 | struct value **argv); | |
1489 | ||
1a6d41c6 TT |
1490 | /* Add a new internal function. NAME is the name of the function; DOC |
1491 | is a documentation string describing the function. HANDLER is | |
1492 | called when the function is invoked. COOKIE is an arbitrary | |
1493 | pointer which is passed to HANDLER and is intended for "user | |
1494 | data". */ | |
1495 | ||
1496 | extern void add_internal_function (const char *name, const char *doc, | |
1497 | internal_function_fn handler, | |
1498 | void *cookie); | |
1499 | ||
1500 | /* This overload takes an allocated documentation string. */ | |
1501 | ||
3ea16160 | 1502 | extern void add_internal_function (gdb::unique_xmalloc_ptr<char> &&name, |
1a6d41c6 TT |
1503 | gdb::unique_xmalloc_ptr<char> &&doc, |
1504 | internal_function_fn handler, | |
1505 | void *cookie); | |
bc3b79fd | 1506 | |
d452c4bc UW |
1507 | struct value *call_internal_function (struct gdbarch *gdbarch, |
1508 | const struct language_defn *language, | |
1509 | struct value *function, | |
bc3b79fd TJB |
1510 | int argc, struct value **argv); |
1511 | ||
91f87213 | 1512 | const char *value_internal_function_name (struct value *); |
bc3b79fd | 1513 | |
ba18742c SM |
1514 | /* Build a value wrapping and representing WORKER. The value takes ownership |
1515 | of the xmethod_worker object. */ | |
1516 | ||
1517 | extern struct value *value_from_xmethod (xmethod_worker_up &&worker); | |
e81e7f5e | 1518 | |
2ce1cdbf | 1519 | extern struct type *result_type_of_xmethod (struct value *method, |
6b1747cd | 1520 | gdb::array_view<value *> argv); |
2ce1cdbf DE |
1521 | |
1522 | extern struct value *call_xmethod (struct value *method, | |
6b1747cd | 1523 | gdb::array_view<value *> argv); |
e81e7f5e | 1524 | |
9d1447e0 SDJ |
1525 | /* Destroy the values currently allocated. This is called when GDB is |
1526 | exiting (e.g., on quit_force). */ | |
1527 | extern void finalize_values (); | |
1528 | ||
b49180ac TT |
1529 | /* Convert VALUE to a gdb_mpq. The caller must ensure that VALUE is |
1530 | of floating-point, fixed-point, or integer type. */ | |
1531 | extern gdb_mpq value_to_gdb_mpq (struct value *value); | |
1532 | ||
a0c07915 AB |
1533 | /* While an instance of this class is live, and array values that are |
1534 | created, that are larger than max_value_size, will be restricted in size | |
1535 | to a particular number of elements. */ | |
1536 | ||
1537 | struct scoped_array_length_limiting | |
1538 | { | |
1539 | /* Limit any large array values to only contain ELEMENTS elements. */ | |
1540 | scoped_array_length_limiting (int elements); | |
1541 | ||
1542 | /* Restore the previous array value limit. */ | |
1543 | ~scoped_array_length_limiting (); | |
1544 | ||
1545 | private: | |
1546 | /* Used to hold the previous array value element limit. */ | |
1547 | gdb::optional<int> m_old_value; | |
1548 | }; | |
1549 | ||
c5aa993b | 1550 | #endif /* !defined (VALUE_H) */ |