value.h 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. /* Definitions for values of C expressions, for GDB.
  2. Copyright (C) 1986-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #if !defined (VALUE_H)
  15. #define VALUE_H 1
  16. #include "frame.h" /* For struct frame_id. */
  17. #include "extension.h"
  18. #include "gdbsupport/gdb_ref_ptr.h"
  19. #include "gmp-utils.h"
  20. struct block;
  21. struct expression;
  22. struct regcache;
  23. struct symbol;
  24. struct type;
  25. struct ui_file;
  26. struct language_defn;
  27. struct value_print_options;
  28. /* Values can be partially 'optimized out' and/or 'unavailable'.
  29. These are distinct states and have different string representations
  30. and related error strings.
  31. 'unavailable' has a specific meaning in this context. It means the
  32. value exists in the program (at the machine level), but GDB has no
  33. means to get to it. Such a value is normally printed as
  34. <unavailable>. Examples of how to end up with an unavailable value
  35. would be:
  36. - We're inspecting a traceframe, and the memory or registers the
  37. debug information says the value lives on haven't been collected.
  38. - We're inspecting a core dump, the memory or registers the debug
  39. information says the value lives aren't present in the dump
  40. (that is, we have a partial/trimmed core dump, or we don't fully
  41. understand/handle the core dump's format).
  42. - We're doing live debugging, but the debug API has no means to
  43. get at where the value lives in the machine, like e.g., ptrace
  44. not having access to some register or register set.
  45. - Any other similar scenario.
  46. OTOH, "optimized out" is about what the compiler decided to generate
  47. (or not generate). A chunk of a value that was optimized out does
  48. not actually exist in the program. There's no way to get at it
  49. short of compiling the program differently.
  50. A register that has not been saved in a frame is likewise considered
  51. optimized out, except not-saved registers have a different string
  52. representation and related error strings. E.g., we'll print them as
  53. <not-saved> instead of <optimized out>, as in:
  54. (gdb) p/x $rax
  55. $1 = <not saved>
  56. (gdb) info registers rax
  57. rax <not saved>
  58. If the debug info describes a variable as being in such a register,
  59. we'll still print the variable as <optimized out>. IOW, <not saved>
  60. is reserved for inspecting registers at the machine level.
  61. When comparing value contents, optimized out chunks, unavailable
  62. chunks, and valid contents data are all considered different. See
  63. value_contents_eq for more info.
  64. */
  65. extern bool overload_resolution;
  66. /* The structure which defines the type of a value. It should never
  67. be possible for a program lval value to survive over a call to the
  68. inferior (i.e. to be put into the history list or an internal
  69. variable). */
  70. struct value;
  71. /* Increase VAL's reference count. */
  72. extern void value_incref (struct value *val);
  73. /* Decrease VAL's reference count. When the reference count drops to
  74. 0, VAL will be freed. */
  75. extern void value_decref (struct value *val);
  76. /* A policy class to interface gdb::ref_ptr with struct value. */
  77. struct value_ref_policy
  78. {
  79. static void incref (struct value *ptr)
  80. {
  81. value_incref (ptr);
  82. }
  83. static void decref (struct value *ptr)
  84. {
  85. value_decref (ptr);
  86. }
  87. };
  88. /* A gdb:;ref_ptr pointer to a struct value. */
  89. typedef gdb::ref_ptr<struct value, value_ref_policy> value_ref_ptr;
  90. /* Values are stored in a chain, so that they can be deleted easily
  91. over calls to the inferior. Values assigned to internal variables,
  92. put into the value history or exposed to Python are taken off this
  93. list. */
  94. struct value *value_next (const struct value *);
  95. /* Type of the value. */
  96. extern struct type *value_type (const struct value *);
  97. /* Return the gdbarch associated with the value. */
  98. extern struct gdbarch *get_value_arch (const struct value *value);
  99. /* This is being used to change the type of an existing value, that
  100. code should instead be creating a new value with the changed type
  101. (but possibly shared content). */
  102. extern void deprecated_set_value_type (struct value *value,
  103. struct type *type);
  104. /* Only used for bitfields; number of bits contained in them. */
  105. extern LONGEST value_bitsize (const struct value *);
  106. extern void set_value_bitsize (struct value *, LONGEST bit);
  107. /* Only used for bitfields; position of start of field. For
  108. little-endian targets, it is the position of the LSB. For
  109. big-endian targets, it is the position of the MSB. */
  110. extern LONGEST value_bitpos (const struct value *);
  111. extern void set_value_bitpos (struct value *, LONGEST bit);
  112. /* Only used for bitfields; the containing value. This allows a
  113. single read from the target when displaying multiple
  114. bitfields. */
  115. struct value *value_parent (const struct value *);
  116. extern void set_value_parent (struct value *value, struct value *parent);
  117. /* Describes offset of a value within lval of a structure in bytes.
  118. If lval == lval_memory, this is an offset to the address. If lval
  119. == lval_register, this is a further offset from location.address
  120. within the registers structure. Note also the member
  121. embedded_offset below. */
  122. extern LONGEST value_offset (const struct value *);
  123. extern void set_value_offset (struct value *, LONGEST offset);
  124. /* The comment from "struct value" reads: ``Is it modifiable? Only
  125. relevant if lval != not_lval.''. Shouldn't the value instead be
  126. not_lval and be done with it? */
  127. extern int deprecated_value_modifiable (const struct value *value);
  128. /* If a value represents a C++ object, then the `type' field gives the
  129. object's compile-time type. If the object actually belongs to some
  130. class derived from `type', perhaps with other base classes and
  131. additional members, then `type' is just a subobject of the real
  132. thing, and the full object is probably larger than `type' would
  133. suggest.
  134. If `type' is a dynamic class (i.e. one with a vtable), then GDB can
  135. actually determine the object's run-time type by looking at the
  136. run-time type information in the vtable. When this information is
  137. available, we may elect to read in the entire object, for several
  138. reasons:
  139. - When printing the value, the user would probably rather see the
  140. full object, not just the limited portion apparent from the
  141. compile-time type.
  142. - If `type' has virtual base classes, then even printing `type'
  143. alone may require reaching outside the `type' portion of the
  144. object to wherever the virtual base class has been stored.
  145. When we store the entire object, `enclosing_type' is the run-time
  146. type -- the complete object -- and `embedded_offset' is the offset
  147. of `type' within that larger type, in bytes. The value_contents()
  148. macro takes `embedded_offset' into account, so most GDB code
  149. continues to see the `type' portion of the value, just as the
  150. inferior would.
  151. If `type' is a pointer to an object, then `enclosing_type' is a
  152. pointer to the object's run-time type, and `pointed_to_offset' is
  153. the offset in bytes from the full object to the pointed-to object
  154. -- that is, the value `embedded_offset' would have if we followed
  155. the pointer and fetched the complete object. (I don't really see
  156. the point. Why not just determine the run-time type when you
  157. indirect, and avoid the special case? The contents don't matter
  158. until you indirect anyway.)
  159. If we're not doing anything fancy, `enclosing_type' is equal to
  160. `type', and `embedded_offset' is zero, so everything works
  161. normally. */
  162. extern struct type *value_enclosing_type (const struct value *);
  163. extern void set_value_enclosing_type (struct value *val,
  164. struct type *new_type);
  165. /* Returns value_type or value_enclosing_type depending on
  166. value_print_options.objectprint.
  167. If RESOLVE_SIMPLE_TYPES is 0 the enclosing type will be resolved
  168. only for pointers and references, else it will be returned
  169. for all the types (e.g. structures). This option is useful
  170. to prevent retrieving enclosing type for the base classes fields.
  171. REAL_TYPE_FOUND is used to inform whether the real type was found
  172. (or just static type was used). The NULL may be passed if it is not
  173. necessary. */
  174. extern struct type *value_actual_type (struct value *value,
  175. int resolve_simple_types,
  176. int *real_type_found);
  177. extern LONGEST value_pointed_to_offset (const struct value *value);
  178. extern void set_value_pointed_to_offset (struct value *value, LONGEST val);
  179. extern LONGEST value_embedded_offset (const struct value *value);
  180. extern void set_value_embedded_offset (struct value *value, LONGEST val);
  181. /* For lval_computed values, this structure holds functions used to
  182. retrieve and set the value (or portions of the value).
  183. For each function, 'V' is the 'this' pointer: an lval_funcs
  184. function F may always assume that the V it receives is an
  185. lval_computed value, and has F in the appropriate slot of its
  186. lval_funcs structure. */
  187. struct lval_funcs
  188. {
  189. /* Fill in VALUE's contents. This is used to "un-lazy" values. If
  190. a problem arises in obtaining VALUE's bits, this function should
  191. call 'error'. If it is NULL value_fetch_lazy on "un-lazy"
  192. non-optimized-out value is an internal error. */
  193. void (*read) (struct value *v);
  194. /* Handle an assignment TOVAL = FROMVAL by writing the value of
  195. FROMVAL to TOVAL's location. The contents of TOVAL have not yet
  196. been updated. If a problem arises in doing so, this function
  197. should call 'error'. If it is NULL such TOVAL assignment is an error as
  198. TOVAL is not considered as an lvalue. */
  199. void (*write) (struct value *toval, struct value *fromval);
  200. /* Return true if any part of V is optimized out, false otherwise.
  201. This will only be called for lazy values -- if the value has been
  202. fetched, then the value's optimized-out bits are consulted
  203. instead. */
  204. bool (*is_optimized_out) (struct value *v);
  205. /* If non-NULL, this is used to implement pointer indirection for
  206. this value. This method may return NULL, in which case value_ind
  207. will fall back to ordinary indirection. */
  208. struct value *(*indirect) (struct value *value);
  209. /* If non-NULL, this is used to implement reference resolving for
  210. this value. This method may return NULL, in which case coerce_ref
  211. will fall back to ordinary references resolving. */
  212. struct value *(*coerce_ref) (const struct value *value);
  213. /* If non-NULL, this is used to determine whether the indicated bits
  214. of VALUE are a synthetic pointer. */
  215. int (*check_synthetic_pointer) (const struct value *value,
  216. LONGEST offset, int length);
  217. /* Return a duplicate of VALUE's closure, for use in a new value.
  218. This may simply return the same closure, if VALUE's is
  219. reference-counted or statically allocated.
  220. This may be NULL, in which case VALUE's closure is re-used in the
  221. new value. */
  222. void *(*copy_closure) (const struct value *v);
  223. /* Drop VALUE's reference to its closure. Maybe this frees the
  224. closure; maybe this decrements a reference count; maybe the
  225. closure is statically allocated and this does nothing.
  226. This may be NULL, in which case no action is taken to free
  227. VALUE's closure. */
  228. void (*free_closure) (struct value *v);
  229. };
  230. /* Create a computed lvalue, with type TYPE, function pointers FUNCS,
  231. and closure CLOSURE. */
  232. extern struct value *allocate_computed_value (struct type *type,
  233. const struct lval_funcs *funcs,
  234. void *closure);
  235. extern struct value *allocate_optimized_out_value (struct type *type);
  236. /* If VALUE is lval_computed, return its lval_funcs structure. */
  237. extern const struct lval_funcs *value_computed_funcs (const struct value *);
  238. /* If VALUE is lval_computed, return its closure. The meaning of the
  239. returned value depends on the functions VALUE uses. */
  240. extern void *value_computed_closure (const struct value *value);
  241. /* If zero, contents of this value are in the contents field. If
  242. nonzero, contents are in inferior. If the lval field is lval_memory,
  243. the contents are in inferior memory at location.address plus offset.
  244. The lval field may also be lval_register.
  245. WARNING: This field is used by the code which handles watchpoints
  246. (see breakpoint.c) to decide whether a particular value can be
  247. watched by hardware watchpoints. If the lazy flag is set for some
  248. member of a value chain, it is assumed that this member of the
  249. chain doesn't need to be watched as part of watching the value
  250. itself. This is how GDB avoids watching the entire struct or array
  251. when the user wants to watch a single struct member or array
  252. element. If you ever change the way lazy flag is set and reset, be
  253. sure to consider this use as well! */
  254. extern int value_lazy (const struct value *);
  255. extern void set_value_lazy (struct value *value, int val);
  256. extern int value_stack (const struct value *);
  257. extern void set_value_stack (struct value *value, int val);
  258. /* Throw an error complaining that the value has been optimized
  259. out. */
  260. extern void error_value_optimized_out (void);
  261. /* value_contents() and value_contents_raw() both return the address
  262. of the gdb buffer used to hold a copy of the contents of the lval.
  263. value_contents() is used when the contents of the buffer are needed
  264. -- it uses value_fetch_lazy() to load the buffer from the process
  265. being debugged if it hasn't already been loaded
  266. (value_contents_writeable() is used when a writeable but fetched
  267. buffer is required).. value_contents_raw() is used when data is
  268. being stored into the buffer, or when it is certain that the
  269. contents of the buffer are valid.
  270. Note: The contents pointer is adjusted by the offset required to
  271. get to the real subobject, if the value happens to represent
  272. something embedded in a larger run-time object. */
  273. extern gdb::array_view<gdb_byte> value_contents_raw (struct value *);
  274. /* Actual contents of the value. For use of this value; setting it
  275. uses the stuff above. Not valid if lazy is nonzero. Target
  276. byte-order. We force it to be aligned properly for any possible
  277. value. Note that a value therefore extends beyond what is
  278. declared here. */
  279. extern gdb::array_view<const gdb_byte> value_contents (struct value *);
  280. extern gdb::array_view<gdb_byte> value_contents_writeable (struct value *);
  281. /* The ALL variants of the above two macros do not adjust the returned
  282. pointer by the embedded_offset value. */
  283. extern gdb::array_view<gdb_byte> value_contents_all_raw (struct value *);
  284. extern gdb::array_view<const gdb_byte> value_contents_all (struct value *);
  285. /* Like value_contents_all, but does not require that the returned
  286. bits be valid. This should only be used in situations where you
  287. plan to check the validity manually. */
  288. extern gdb::array_view<const gdb_byte> value_contents_for_printing (struct value *value);
  289. /* Like value_contents_for_printing, but accepts a constant value
  290. pointer. Unlike value_contents_for_printing however, the pointed
  291. value must _not_ be lazy. */
  292. extern gdb::array_view<const gdb_byte>
  293. value_contents_for_printing_const (const struct value *value);
  294. extern void value_fetch_lazy (struct value *val);
  295. /* If nonzero, this is the value of a variable which does not actually
  296. exist in the program, at least partially. If the value is lazy,
  297. this may fetch it now. */
  298. extern int value_optimized_out (struct value *value);
  299. /* Given a value, return true if any of the contents bits starting at
  300. OFFSET and extending for LENGTH bits is optimized out, false
  301. otherwise. */
  302. extern int value_bits_any_optimized_out (const struct value *value,
  303. int bit_offset, int bit_length);
  304. /* Like value_optimized_out, but return true iff the whole value is
  305. optimized out. */
  306. extern int value_entirely_optimized_out (struct value *value);
  307. /* Mark VALUE's content bytes starting at OFFSET and extending for
  308. LENGTH bytes as optimized out. */
  309. extern void mark_value_bytes_optimized_out (struct value *value,
  310. int offset, int length);
  311. /* Mark VALUE's content bits starting at OFFSET and extending for
  312. LENGTH bits as optimized out. */
  313. extern void mark_value_bits_optimized_out (struct value *value,
  314. LONGEST offset, LONGEST length);
  315. /* Set or return field indicating whether a variable is initialized or
  316. not, based on debugging information supplied by the compiler.
  317. 1 = initialized; 0 = uninitialized. */
  318. extern int value_initialized (const struct value *);
  319. extern void set_value_initialized (struct value *, int);
  320. /* Set COMPONENT's location as appropriate for a component of WHOLE
  321. --- regardless of what kind of lvalue WHOLE is. */
  322. extern void set_value_component_location (struct value *component,
  323. const struct value *whole);
  324. /* While the following fields are per- VALUE .CONTENT .PIECE (i.e., a
  325. single value might have multiple LVALs), this hacked interface is
  326. limited to just the first PIECE. Expect further change. */
  327. /* Type of value; either not an lval, or one of the various different
  328. possible kinds of lval. */
  329. extern enum lval_type *deprecated_value_lval_hack (struct value *);
  330. #define VALUE_LVAL(val) (*deprecated_value_lval_hack (val))
  331. /* Like VALUE_LVAL, except the parameter can be const. */
  332. extern enum lval_type value_lval_const (const struct value *value);
  333. /* If lval == lval_memory, return the address in the inferior. If
  334. lval == lval_register, return the byte offset into the registers
  335. structure. Otherwise, return 0. The returned address
  336. includes the offset, if any. */
  337. extern CORE_ADDR value_address (const struct value *);
  338. /* Like value_address, except the result does not include value's
  339. offset. */
  340. extern CORE_ADDR value_raw_address (const struct value *);
  341. /* Set the address of a value. */
  342. extern void set_value_address (struct value *, CORE_ADDR);
  343. /* Pointer to internal variable. */
  344. extern struct internalvar **deprecated_value_internalvar_hack (struct value *);
  345. #define VALUE_INTERNALVAR(val) (*deprecated_value_internalvar_hack (val))
  346. /* Frame ID of "next" frame to which a register value is relative. A
  347. register value is indicated by VALUE_LVAL being set to lval_register.
  348. So, if the register value is found relative to frame F, then the
  349. frame id of F->next will be stored in VALUE_NEXT_FRAME_ID. */
  350. extern struct frame_id *deprecated_value_next_frame_id_hack (struct value *);
  351. #define VALUE_NEXT_FRAME_ID(val) (*deprecated_value_next_frame_id_hack (val))
  352. /* Register number if the value is from a register. */
  353. extern int *deprecated_value_regnum_hack (struct value *);
  354. #define VALUE_REGNUM(val) (*deprecated_value_regnum_hack (val))
  355. /* Return value after lval_funcs->coerce_ref (after check_typedef). Return
  356. NULL if lval_funcs->coerce_ref is not applicable for whatever reason. */
  357. extern struct value *coerce_ref_if_computed (const struct value *arg);
  358. /* Setup a new value type and enclosing value type for dereferenced value VALUE.
  359. ENC_TYPE is the new enclosing type that should be set. ORIGINAL_TYPE and
  360. ORIGINAL_VAL are the type and value of the original reference or
  361. pointer. ORIGINAL_VALUE_ADDRESS is the address within VALUE, that is
  362. the address that was dereferenced.
  363. Note, that VALUE is modified by this function.
  364. It is a common implementation for coerce_ref and value_ind. */
  365. extern struct value * readjust_indirect_value_type (struct value *value,
  366. struct type *enc_type,
  367. const struct type *original_type,
  368. struct value *original_val,
  369. CORE_ADDR original_value_address);
  370. /* Convert a REF to the object referenced. */
  371. extern struct value *coerce_ref (struct value *value);
  372. /* If ARG is an array, convert it to a pointer.
  373. If ARG is a function, convert it to a function pointer.
  374. References are dereferenced. */
  375. extern struct value *coerce_array (struct value *value);
  376. /* Given a value, determine whether the bits starting at OFFSET and
  377. extending for LENGTH bits are a synthetic pointer. */
  378. extern int value_bits_synthetic_pointer (const struct value *value,
  379. LONGEST offset, LONGEST length);
  380. /* Given a value, determine whether the contents bytes starting at
  381. OFFSET and extending for LENGTH bytes are available. This returns
  382. nonzero if all bytes in the given range are available, zero if any
  383. byte is unavailable. */
  384. extern int value_bytes_available (const struct value *value,
  385. LONGEST offset, LONGEST length);
  386. /* Given a value, determine whether the contents bits starting at
  387. OFFSET and extending for LENGTH bits are available. This returns
  388. nonzero if all bits in the given range are available, zero if any
  389. bit is unavailable. */
  390. extern int value_bits_available (const struct value *value,
  391. LONGEST offset, LONGEST length);
  392. /* Like value_bytes_available, but return false if any byte in the
  393. whole object is unavailable. */
  394. extern int value_entirely_available (struct value *value);
  395. /* Like value_entirely_available, but return false if any byte in the
  396. whole object is available. */
  397. extern int value_entirely_unavailable (struct value *value);
  398. /* Mark VALUE's content bytes starting at OFFSET and extending for
  399. LENGTH bytes as unavailable. */
  400. extern void mark_value_bytes_unavailable (struct value *value,
  401. LONGEST offset, LONGEST length);
  402. /* Mark VALUE's content bits starting at OFFSET and extending for
  403. LENGTH bits as unavailable. */
  404. extern void mark_value_bits_unavailable (struct value *value,
  405. LONGEST offset, LONGEST length);
  406. /* Compare LENGTH bytes of VAL1's contents starting at OFFSET1 with
  407. LENGTH bytes of VAL2's contents starting at OFFSET2.
  408. Note that "contents" refers to the whole value's contents
  409. (value_contents_all), without any embedded offset adjustment. For
  410. example, to compare a complete object value with itself, including
  411. its enclosing type chunk, you'd do:
  412. int len = TYPE_LENGTH (check_typedef (value_enclosing_type (val)));
  413. value_contents_eq (val, 0, val, 0, len);
  414. Returns true iff the set of available/valid contents match.
  415. Optimized-out contents are equal to optimized-out contents, and are
  416. not equal to non-optimized-out contents.
  417. Unavailable contents are equal to unavailable contents, and are not
  418. equal to non-unavailable contents.
  419. For example, if 'x's represent an unavailable byte, and 'V' and 'Z'
  420. represent different available/valid bytes, in a value with length
  421. 16:
  422. offset: 0 4 8 12 16
  423. contents: xxxxVVVVxxxxVVZZ
  424. then:
  425. value_contents_eq(val, 0, val, 8, 6) => true
  426. value_contents_eq(val, 0, val, 4, 4) => false
  427. value_contents_eq(val, 0, val, 8, 8) => false
  428. value_contents_eq(val, 4, val, 12, 2) => true
  429. value_contents_eq(val, 4, val, 12, 4) => true
  430. value_contents_eq(val, 3, val, 4, 4) => true
  431. If 'x's represent an unavailable byte, 'o' represents an optimized
  432. out byte, in a value with length 8:
  433. offset: 0 4 8
  434. contents: xxxxoooo
  435. then:
  436. value_contents_eq(val, 0, val, 2, 2) => true
  437. value_contents_eq(val, 4, val, 6, 2) => true
  438. value_contents_eq(val, 0, val, 4, 4) => true
  439. We only know whether a value chunk is unavailable or optimized out
  440. if we've tried to read it. As this routine is used by printing
  441. routines, which may be printing values in the value history, long
  442. after the inferior is gone, it works with const values. Therefore,
  443. this routine must not be called with lazy values. */
  444. extern bool value_contents_eq (const struct value *val1, LONGEST offset1,
  445. const struct value *val2, LONGEST offset2,
  446. LONGEST length);
  447. /* Read LENGTH addressable memory units starting at MEMADDR into BUFFER,
  448. which is (or will be copied to) VAL's contents buffer offset by
  449. BIT_OFFSET bits. Marks value contents ranges as unavailable if
  450. the corresponding memory is likewise unavailable. STACK indicates
  451. whether the memory is known to be stack memory. */
  452. extern void read_value_memory (struct value *val, LONGEST bit_offset,
  453. int stack, CORE_ADDR memaddr,
  454. gdb_byte *buffer, size_t length);
  455. /* Cast SCALAR_VALUE to the element type of VECTOR_TYPE, then replicate
  456. into each element of a new vector value with VECTOR_TYPE. */
  457. struct value *value_vector_widen (struct value *scalar_value,
  458. struct type *vector_type);
  459. #include "symtab.h"
  460. #include "gdbtypes.h"
  461. #include "expression.h"
  462. struct frame_info;
  463. struct fn_field;
  464. extern int print_address_demangle (const struct value_print_options *,
  465. struct gdbarch *, CORE_ADDR,
  466. struct ui_file *, int);
  467. /* Returns true if VAL is of floating-point type. In addition,
  468. throws an error if the value is an invalid floating-point value. */
  469. extern bool is_floating_value (struct value *val);
  470. extern LONGEST value_as_long (struct value *val);
  471. extern CORE_ADDR value_as_address (struct value *val);
  472. extern LONGEST unpack_long (struct type *type, const gdb_byte *valaddr);
  473. extern CORE_ADDR unpack_pointer (struct type *type, const gdb_byte *valaddr);
  474. extern LONGEST unpack_field_as_long (struct type *type,
  475. const gdb_byte *valaddr,
  476. int fieldno);
  477. /* Unpack a bitfield of the specified FIELD_TYPE, from the object at
  478. VALADDR, and store the result in *RESULT.
  479. The bitfield starts at BITPOS bits and contains BITSIZE bits; if
  480. BITSIZE is zero, then the length is taken from FIELD_TYPE.
  481. Extracting bits depends on endianness of the machine. Compute the
  482. number of least significant bits to discard. For big endian machines,
  483. we compute the total number of bits in the anonymous object, subtract
  484. off the bit count from the MSB of the object to the MSB of the
  485. bitfield, then the size of the bitfield, which leaves the LSB discard
  486. count. For little endian machines, the discard count is simply the
  487. number of bits from the LSB of the anonymous object to the LSB of the
  488. bitfield.
  489. If the field is signed, we also do sign extension. */
  490. extern LONGEST unpack_bits_as_long (struct type *field_type,
  491. const gdb_byte *valaddr,
  492. LONGEST bitpos, LONGEST bitsize);
  493. extern int unpack_value_field_as_long (struct type *type, const gdb_byte *valaddr,
  494. LONGEST embedded_offset, int fieldno,
  495. const struct value *val, LONGEST *result);
  496. extern void unpack_value_bitfield (struct value *dest_val,
  497. LONGEST bitpos, LONGEST bitsize,
  498. const gdb_byte *valaddr,
  499. LONGEST embedded_offset,
  500. const struct value *val);
  501. extern struct value *value_field_bitfield (struct type *type, int fieldno,
  502. const gdb_byte *valaddr,
  503. LONGEST embedded_offset,
  504. const struct value *val);
  505. extern void pack_long (gdb_byte *buf, struct type *type, LONGEST num);
  506. extern struct value *value_from_longest (struct type *type, LONGEST num);
  507. extern struct value *value_from_ulongest (struct type *type, ULONGEST num);
  508. extern struct value *value_from_pointer (struct type *type, CORE_ADDR addr);
  509. extern struct value *value_from_host_double (struct type *type, double d);
  510. extern struct value *value_from_history_ref (const char *, const char **);
  511. extern struct value *value_from_component (struct value *, struct type *,
  512. LONGEST);
  513. extern struct value *value_at (struct type *type, CORE_ADDR addr);
  514. extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
  515. extern struct value *value_from_contents_and_address_unresolved
  516. (struct type *, const gdb_byte *, CORE_ADDR);
  517. extern struct value *value_from_contents_and_address (struct type *,
  518. const gdb_byte *,
  519. CORE_ADDR);
  520. extern struct value *value_from_contents (struct type *, const gdb_byte *);
  521. extern struct value *default_value_from_register (struct gdbarch *gdbarch,
  522. struct type *type,
  523. int regnum,
  524. struct frame_id frame_id);
  525. extern void read_frame_register_value (struct value *value,
  526. struct frame_info *frame);
  527. extern struct value *value_from_register (struct type *type, int regnum,
  528. struct frame_info *frame);
  529. extern CORE_ADDR address_from_register (int regnum,
  530. struct frame_info *frame);
  531. extern struct value *value_of_variable (struct symbol *var,
  532. const struct block *b);
  533. extern struct value *address_of_variable (struct symbol *var,
  534. const struct block *b);
  535. extern struct value *value_of_register (int regnum, struct frame_info *frame);
  536. struct value *value_of_register_lazy (struct frame_info *frame, int regnum);
  537. /* Return the symbol's reading requirement. */
  538. extern enum symbol_needs_kind symbol_read_needs (struct symbol *);
  539. /* Return true if the symbol needs a frame. This is a wrapper for
  540. symbol_read_needs that simply checks for SYMBOL_NEEDS_FRAME. */
  541. extern int symbol_read_needs_frame (struct symbol *);
  542. extern struct value *read_var_value (struct symbol *var,
  543. const struct block *var_block,
  544. struct frame_info *frame);
  545. extern struct value *allocate_value (struct type *type);
  546. extern struct value *allocate_value_lazy (struct type *type);
  547. extern void value_contents_copy (struct value *dst, LONGEST dst_offset,
  548. struct value *src, LONGEST src_offset,
  549. LONGEST length);
  550. extern struct value *allocate_repeat_value (struct type *type, int count);
  551. extern struct value *value_mark (void);
  552. extern void value_free_to_mark (const struct value *mark);
  553. /* A helper class that uses value_mark at construction time and calls
  554. value_free_to_mark in the destructor. This is used to clear out
  555. temporary values created during the lifetime of this object. */
  556. class scoped_value_mark
  557. {
  558. public:
  559. scoped_value_mark ()
  560. : m_value (value_mark ())
  561. {
  562. }
  563. ~scoped_value_mark ()
  564. {
  565. free_to_mark ();
  566. }
  567. scoped_value_mark (scoped_value_mark &&other) = default;
  568. DISABLE_COPY_AND_ASSIGN (scoped_value_mark);
  569. /* Free the values currently on the value stack. */
  570. void free_to_mark ()
  571. {
  572. if (m_value != NULL)
  573. {
  574. value_free_to_mark (m_value);
  575. m_value = NULL;
  576. }
  577. }
  578. private:
  579. const struct value *m_value;
  580. };
  581. extern struct value *value_cstring (const char *ptr, ssize_t len,
  582. struct type *char_type);
  583. extern struct value *value_string (const char *ptr, ssize_t len,
  584. struct type *char_type);
  585. extern struct value *value_array (int lowbound, int highbound,
  586. struct value **elemvec);
  587. extern struct value *value_concat (struct value *arg1, struct value *arg2);
  588. extern struct value *value_binop (struct value *arg1, struct value *arg2,
  589. enum exp_opcode op);
  590. extern struct value *value_ptradd (struct value *arg1, LONGEST arg2);
  591. extern LONGEST value_ptrdiff (struct value *arg1, struct value *arg2);
  592. /* Return true if VAL does not live in target memory, but should in order
  593. to operate on it. Otherwise return false. */
  594. extern bool value_must_coerce_to_target (struct value *arg1);
  595. extern struct value *value_coerce_to_target (struct value *arg1);
  596. extern struct value *value_coerce_array (struct value *arg1);
  597. extern struct value *value_coerce_function (struct value *arg1);
  598. extern struct value *value_ind (struct value *arg1);
  599. extern struct value *value_addr (struct value *arg1);
  600. extern struct value *value_ref (struct value *arg1, enum type_code refcode);
  601. extern struct value *value_assign (struct value *toval,
  602. struct value *fromval);
  603. extern struct value *value_pos (struct value *arg1);
  604. extern struct value *value_neg (struct value *arg1);
  605. extern struct value *value_complement (struct value *arg1);
  606. extern struct value *value_struct_elt (struct value **argp,
  607. gdb::optional<gdb::array_view <value *>> args,
  608. const char *name, int *static_memfuncp,
  609. const char *err);
  610. extern struct value *value_struct_elt_bitpos (struct value **argp,
  611. int bitpos,
  612. struct type *field_type,
  613. const char *err);
  614. extern struct value *value_aggregate_elt (struct type *curtype,
  615. const char *name,
  616. struct type *expect_type,
  617. int want_address,
  618. enum noside noside);
  619. extern struct value *value_static_field (struct type *type, int fieldno);
  620. enum oload_search_type { NON_METHOD, METHOD, BOTH };
  621. extern int find_overload_match (gdb::array_view<value *> args,
  622. const char *name,
  623. enum oload_search_type method,
  624. struct value **objp, struct symbol *fsym,
  625. struct value **valp, struct symbol **symp,
  626. int *staticp, const int no_adl,
  627. enum noside noside);
  628. extern struct value *value_field (struct value *arg1, int fieldno);
  629. extern struct value *value_primitive_field (struct value *arg1, LONGEST offset,
  630. int fieldno,
  631. struct type *arg_type);
  632. extern struct type *value_rtti_indirect_type (struct value *, int *, LONGEST *,
  633. int *);
  634. extern struct value *value_full_object (struct value *, struct type *, int,
  635. int, int);
  636. extern struct value *value_cast_pointers (struct type *, struct value *, int);
  637. extern struct value *value_cast (struct type *type, struct value *arg2);
  638. extern struct value *value_reinterpret_cast (struct type *type,
  639. struct value *arg);
  640. extern struct value *value_dynamic_cast (struct type *type, struct value *arg);
  641. extern struct value *value_zero (struct type *type, enum lval_type lv);
  642. extern struct value *value_one (struct type *type);
  643. extern struct value *value_repeat (struct value *arg1, int count);
  644. extern struct value *value_subscript (struct value *array, LONGEST index);
  645. extern struct value *value_bitstring_subscript (struct type *type,
  646. struct value *bitstring,
  647. LONGEST index);
  648. extern struct value *register_value_being_returned (struct type *valtype,
  649. struct regcache *retbuf);
  650. extern int value_in (struct value *element, struct value *set);
  651. extern int value_bit_index (struct type *type, const gdb_byte *addr,
  652. int index);
  653. extern enum return_value_convention
  654. struct_return_convention (struct gdbarch *gdbarch, struct value *function,
  655. struct type *value_type);
  656. extern int using_struct_return (struct gdbarch *gdbarch,
  657. struct value *function,
  658. struct type *value_type);
  659. /* Evaluate the expression EXP. If set, EXPECT_TYPE is passed to the
  660. outermost operation's evaluation. This is ignored by most
  661. operations, but may be used, e.g., to determine the type of an
  662. otherwise untyped symbol. The caller should not assume that the
  663. returned value has this type. */
  664. extern struct value *evaluate_expression (struct expression *exp,
  665. struct type *expect_type = nullptr);
  666. extern struct value *evaluate_type (struct expression *exp);
  667. extern value *evaluate_var_value (enum noside noside, const block *blk,
  668. symbol *var);
  669. extern value *evaluate_var_msym_value (enum noside noside,
  670. struct objfile *objfile,
  671. minimal_symbol *msymbol);
  672. namespace expr { class operation; };
  673. extern void fetch_subexp_value (struct expression *exp,
  674. expr::operation *op,
  675. struct value **valp, struct value **resultp,
  676. std::vector<value_ref_ptr> *val_chain,
  677. bool preserve_errors);
  678. extern struct value *parse_and_eval (const char *exp);
  679. extern struct value *parse_to_comma_and_eval (const char **expp);
  680. extern struct type *parse_and_eval_type (const char *p, int length);
  681. extern CORE_ADDR parse_and_eval_address (const char *exp);
  682. extern LONGEST parse_and_eval_long (const char *exp);
  683. extern void unop_promote (const struct language_defn *language,
  684. struct gdbarch *gdbarch,
  685. struct value **arg1);
  686. extern void binop_promote (const struct language_defn *language,
  687. struct gdbarch *gdbarch,
  688. struct value **arg1, struct value **arg2);
  689. extern struct value *access_value_history (int num);
  690. /* Return the number of items in the value history. */
  691. extern ULONGEST value_history_count ();
  692. extern struct value *value_of_internalvar (struct gdbarch *gdbarch,
  693. struct internalvar *var);
  694. extern int get_internalvar_integer (struct internalvar *var, LONGEST *l);
  695. extern void set_internalvar (struct internalvar *var, struct value *val);
  696. extern void set_internalvar_integer (struct internalvar *var, LONGEST l);
  697. extern void set_internalvar_string (struct internalvar *var,
  698. const char *string);
  699. extern void clear_internalvar (struct internalvar *var);
  700. extern void set_internalvar_component (struct internalvar *var,
  701. LONGEST offset,
  702. LONGEST bitpos, LONGEST bitsize,
  703. struct value *newvalue);
  704. extern struct internalvar *lookup_only_internalvar (const char *name);
  705. extern struct internalvar *create_internalvar (const char *name);
  706. extern void complete_internalvar (completion_tracker &tracker,
  707. const char *name);
  708. /* An internalvar can be dynamically computed by supplying a vector of
  709. function pointers to perform various operations. */
  710. struct internalvar_funcs
  711. {
  712. /* Compute the value of the variable. The DATA argument passed to
  713. the function is the same argument that was passed to
  714. `create_internalvar_type_lazy'. */
  715. struct value *(*make_value) (struct gdbarch *arch,
  716. struct internalvar *var,
  717. void *data);
  718. /* Update the agent expression EXPR with bytecode to compute the
  719. value. VALUE is the agent value we are updating. The DATA
  720. argument passed to this function is the same argument that was
  721. passed to `create_internalvar_type_lazy'. If this pointer is
  722. NULL, then the internalvar cannot be compiled to an agent
  723. expression. */
  724. void (*compile_to_ax) (struct internalvar *var,
  725. struct agent_expr *expr,
  726. struct axs_value *value,
  727. void *data);
  728. };
  729. extern struct internalvar *create_internalvar_type_lazy (const char *name,
  730. const struct internalvar_funcs *funcs,
  731. void *data);
  732. /* Compile an internal variable to an agent expression. VAR is the
  733. variable to compile; EXPR and VALUE are the agent expression we are
  734. updating. This will return 0 if there is no known way to compile
  735. VAR, and 1 if VAR was successfully compiled. It may also throw an
  736. exception on error. */
  737. extern int compile_internalvar_to_ax (struct internalvar *var,
  738. struct agent_expr *expr,
  739. struct axs_value *value);
  740. extern struct internalvar *lookup_internalvar (const char *name);
  741. extern int value_equal (struct value *arg1, struct value *arg2);
  742. extern int value_equal_contents (struct value *arg1, struct value *arg2);
  743. extern int value_less (struct value *arg1, struct value *arg2);
  744. /* Simulate the C operator ! -- return true if ARG1 contains zero. */
  745. extern bool value_logical_not (struct value *arg1);
  746. /* Returns true if the value VAL represents a true value. */
  747. static inline bool
  748. value_true (struct value *val)
  749. {
  750. return !value_logical_not (val);
  751. }
  752. /* C++ */
  753. extern struct value *value_of_this (const struct language_defn *lang);
  754. extern struct value *value_of_this_silent (const struct language_defn *lang);
  755. extern struct value *value_x_binop (struct value *arg1, struct value *arg2,
  756. enum exp_opcode op,
  757. enum exp_opcode otherop,
  758. enum noside noside);
  759. extern struct value *value_x_unop (struct value *arg1, enum exp_opcode op,
  760. enum noside noside);
  761. extern struct value *value_fn_field (struct value **arg1p, struct fn_field *f,
  762. int j, struct type *type, LONGEST offset);
  763. extern int binop_types_user_defined_p (enum exp_opcode op,
  764. struct type *type1,
  765. struct type *type2);
  766. extern int binop_user_defined_p (enum exp_opcode op, struct value *arg1,
  767. struct value *arg2);
  768. extern int unop_user_defined_p (enum exp_opcode op, struct value *arg1);
  769. extern int destructor_name_p (const char *name, struct type *type);
  770. extern value_ref_ptr release_value (struct value *val);
  771. extern int record_latest_value (struct value *val);
  772. extern void modify_field (struct type *type, gdb_byte *addr,
  773. LONGEST fieldval, LONGEST bitpos, LONGEST bitsize);
  774. extern void type_print (struct type *type, const char *varstring,
  775. struct ui_file *stream, int show);
  776. extern std::string type_to_string (struct type *type);
  777. extern gdb_byte *baseclass_addr (struct type *type, int index,
  778. gdb_byte *valaddr,
  779. struct value **valuep, int *errp);
  780. extern void print_longest (struct ui_file *stream, int format,
  781. int use_local, LONGEST val);
  782. extern void print_floating (const gdb_byte *valaddr, struct type *type,
  783. struct ui_file *stream);
  784. extern void value_print (struct value *val, struct ui_file *stream,
  785. const struct value_print_options *options);
  786. /* Release values from the value chain and return them. Values
  787. created after MARK are released. If MARK is nullptr, or if MARK is
  788. not found on the value chain, then all values are released. Values
  789. are returned in reverse order of creation; that is, newest
  790. first. */
  791. extern std::vector<value_ref_ptr> value_release_to_mark
  792. (const struct value *mark);
  793. extern void common_val_print (struct value *val,
  794. struct ui_file *stream, int recurse,
  795. const struct value_print_options *options,
  796. const struct language_defn *language);
  797. extern int val_print_string (struct type *elttype, const char *encoding,
  798. CORE_ADDR addr, int len,
  799. struct ui_file *stream,
  800. const struct value_print_options *options);
  801. extern void print_variable_and_value (const char *name,
  802. struct symbol *var,
  803. struct frame_info *frame,
  804. struct ui_file *stream,
  805. int indent);
  806. extern void typedef_print (struct type *type, struct symbol *news,
  807. struct ui_file *stream);
  808. extern const char *internalvar_name (const struct internalvar *var);
  809. extern void preserve_values (struct objfile *);
  810. /* From values.c */
  811. extern struct value *value_copy (const value *);
  812. extern struct value *value_non_lval (struct value *);
  813. extern void value_force_lval (struct value *, CORE_ADDR);
  814. extern struct value *make_cv_value (int, int, struct value *);
  815. extern void preserve_one_value (struct value *, struct objfile *, htab_t);
  816. /* From valops.c */
  817. extern struct value *varying_to_slice (struct value *);
  818. extern struct value *value_slice (struct value *, int, int);
  819. /* Create a complex number. The type is the complex type; the values
  820. are cast to the underlying scalar type before the complex number is
  821. created. */
  822. extern struct value *value_literal_complex (struct value *, struct value *,
  823. struct type *);
  824. /* Return the real part of a complex value. */
  825. extern struct value *value_real_part (struct value *value);
  826. /* Return the imaginary part of a complex value. */
  827. extern struct value *value_imaginary_part (struct value *value);
  828. extern struct value *find_function_in_inferior (const char *,
  829. struct objfile **);
  830. extern struct value *value_allocate_space_in_inferior (int);
  831. /* User function handler. */
  832. typedef struct value *(*internal_function_fn) (struct gdbarch *gdbarch,
  833. const struct language_defn *language,
  834. void *cookie,
  835. int argc,
  836. struct value **argv);
  837. /* Add a new internal function. NAME is the name of the function; DOC
  838. is a documentation string describing the function. HANDLER is
  839. called when the function is invoked. COOKIE is an arbitrary
  840. pointer which is passed to HANDLER and is intended for "user
  841. data". */
  842. extern void add_internal_function (const char *name, const char *doc,
  843. internal_function_fn handler,
  844. void *cookie);
  845. /* This overload takes an allocated documentation string. */
  846. extern void add_internal_function (gdb::unique_xmalloc_ptr<char> &&name,
  847. gdb::unique_xmalloc_ptr<char> &&doc,
  848. internal_function_fn handler,
  849. void *cookie);
  850. struct value *call_internal_function (struct gdbarch *gdbarch,
  851. const struct language_defn *language,
  852. struct value *function,
  853. int argc, struct value **argv);
  854. const char *value_internal_function_name (struct value *);
  855. /* Build a value wrapping and representing WORKER. The value takes ownership
  856. of the xmethod_worker object. */
  857. extern struct value *value_from_xmethod (xmethod_worker_up &&worker);
  858. extern struct type *result_type_of_xmethod (struct value *method,
  859. gdb::array_view<value *> argv);
  860. extern struct value *call_xmethod (struct value *method,
  861. gdb::array_view<value *> argv);
  862. /* Destroy the values currently allocated. This is called when GDB is
  863. exiting (e.g., on quit_force). */
  864. extern void finalize_values ();
  865. /* Convert VALUE to a gdb_mpq. The caller must ensure that VALUE is
  866. of floating-point, fixed-point, or integer type. */
  867. extern gdb_mpq value_to_gdb_mpq (struct value *value);
  868. #endif /* !defined (VALUE_H) */