Commit | Line | Data |
---|---|---|
ed3ef339 DE |
1 | /* Scheme interface to values. |
2 | ||
e2882c85 | 3 | Copyright (C) 2008-2018 Free Software Foundation, Inc. |
ed3ef339 DE |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | /* See README file in this directory for implementation notes, coding | |
21 | conventions, et.al. */ | |
22 | ||
23 | #include "defs.h" | |
24 | #include "arch-utils.h" | |
25 | #include "charset.h" | |
26 | #include "cp-abi.h" | |
14ad9311 | 27 | #include "target-float.h" |
ed3ef339 DE |
28 | #include "infcall.h" |
29 | #include "symtab.h" /* Needed by language.h. */ | |
30 | #include "language.h" | |
31 | #include "valprint.h" | |
32 | #include "value.h" | |
33 | #include "guile-internal.h" | |
34 | ||
35 | /* The <gdb:value> smob. */ | |
36 | ||
37 | typedef struct _value_smob | |
38 | { | |
39 | /* This always appears first. */ | |
40 | gdb_smob base; | |
41 | ||
42 | /* Doubly linked list of values in values_in_scheme. | |
43 | IWBN to use a chained_gdb_smob instead, which is doable, it just requires | |
44 | a bit more casting than normal. */ | |
45 | struct _value_smob *next; | |
46 | struct _value_smob *prev; | |
47 | ||
48 | struct value *value; | |
49 | ||
50 | /* These are cached here to avoid making multiple copies of them. | |
51 | Plus computing the dynamic_type can be a bit expensive. | |
52 | We use #f to indicate that the value doesn't exist (e.g. value doesn't | |
53 | have an address), so we need another value to indicate that we haven't | |
54 | computed the value yet. For this we use SCM_UNDEFINED. */ | |
55 | SCM address; | |
56 | SCM type; | |
57 | SCM dynamic_type; | |
58 | } value_smob; | |
59 | ||
60 | static const char value_smob_name[] = "gdb:value"; | |
61 | ||
62 | /* The tag Guile knows the value smob by. */ | |
63 | static scm_t_bits value_smob_tag; | |
64 | ||
65 | /* List of all values which are currently exposed to Scheme. It is | |
66 | maintained so that when an objfile is discarded, preserve_values | |
67 | can copy the values' types if needed. */ | |
68 | static value_smob *values_in_scheme; | |
69 | ||
70 | /* Keywords used by Scheme procedures in this file. */ | |
71 | static SCM type_keyword; | |
72 | static SCM encoding_keyword; | |
73 | static SCM errors_keyword; | |
74 | static SCM length_keyword; | |
75 | ||
76 | /* Possible #:errors values. */ | |
77 | static SCM error_symbol; | |
78 | static SCM escape_symbol; | |
79 | static SCM substitute_symbol; | |
80 | \f | |
81 | /* Administrivia for value smobs. */ | |
82 | ||
83 | /* Iterate over all the <gdb:value> objects, calling preserve_one_value on | |
84 | each. | |
85 | This is the extension_language_ops.preserve_values "method". */ | |
86 | ||
87 | void | |
88 | gdbscm_preserve_values (const struct extension_language_defn *extlang, | |
89 | struct objfile *objfile, htab_t copied_types) | |
90 | { | |
91 | value_smob *iter; | |
92 | ||
93 | for (iter = values_in_scheme; iter; iter = iter->next) | |
94 | preserve_one_value (iter->value, objfile, copied_types); | |
95 | } | |
96 | ||
97 | /* Helper to add a value_smob to the global list. */ | |
98 | ||
99 | static void | |
100 | vlscm_remember_scheme_value (value_smob *v_smob) | |
101 | { | |
102 | v_smob->next = values_in_scheme; | |
103 | if (v_smob->next) | |
104 | v_smob->next->prev = v_smob; | |
105 | v_smob->prev = NULL; | |
106 | values_in_scheme = v_smob; | |
107 | } | |
108 | ||
109 | /* Helper to remove a value_smob from the global list. */ | |
110 | ||
111 | static void | |
112 | vlscm_forget_value_smob (value_smob *v_smob) | |
113 | { | |
114 | /* Remove SELF from the global list. */ | |
115 | if (v_smob->prev) | |
116 | v_smob->prev->next = v_smob->next; | |
117 | else | |
118 | { | |
119 | gdb_assert (values_in_scheme == v_smob); | |
120 | values_in_scheme = v_smob->next; | |
121 | } | |
122 | if (v_smob->next) | |
123 | v_smob->next->prev = v_smob->prev; | |
124 | } | |
125 | ||
ed3ef339 DE |
126 | /* The smob "free" function for <gdb:value>. */ |
127 | ||
128 | static size_t | |
129 | vlscm_free_value_smob (SCM self) | |
130 | { | |
131 | value_smob *v_smob = (value_smob *) SCM_SMOB_DATA (self); | |
132 | ||
133 | vlscm_forget_value_smob (v_smob); | |
22bc8444 | 134 | value_decref (v_smob->value); |
ed3ef339 DE |
135 | |
136 | return 0; | |
137 | } | |
138 | ||
139 | /* The smob "print" function for <gdb:value>. */ | |
140 | ||
141 | static int | |
142 | vlscm_print_value_smob (SCM self, SCM port, scm_print_state *pstate) | |
143 | { | |
144 | value_smob *v_smob = (value_smob *) SCM_SMOB_DATA (self); | |
ed3ef339 | 145 | struct value_print_options opts; |
ed3ef339 DE |
146 | |
147 | if (pstate->writingp) | |
148 | gdbscm_printf (port, "#<%s ", value_smob_name); | |
149 | ||
150 | get_user_print_options (&opts); | |
151 | opts.deref_ref = 0; | |
152 | ||
153 | /* pstate->writingp = zero if invoked by display/~A, and nonzero if | |
154 | invoked by write/~S. What to do here may need to evolve. | |
155 | IWBN if we could pass an argument to format that would we could use | |
156 | instead of writingp. */ | |
157 | opts.raw = !!pstate->writingp; | |
158 | ||
492d29ea | 159 | TRY |
ed3ef339 | 160 | { |
d7e74731 | 161 | string_file stb; |
ed3ef339 | 162 | |
d7e74731 PA |
163 | common_val_print (v_smob->value, &stb, 0, &opts, current_language); |
164 | scm_puts (stb.c_str (), port); | |
ed3ef339 | 165 | } |
492d29ea PA |
166 | CATCH (except, RETURN_MASK_ALL) |
167 | { | |
168 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
169 | } | |
170 | END_CATCH | |
ed3ef339 | 171 | |
ed3ef339 DE |
172 | if (pstate->writingp) |
173 | scm_puts (">", port); | |
174 | ||
175 | scm_remember_upto_here_1 (self); | |
176 | ||
177 | /* Non-zero means success. */ | |
178 | return 1; | |
179 | } | |
180 | ||
181 | /* The smob "equalp" function for <gdb:value>. */ | |
182 | ||
183 | static SCM | |
184 | vlscm_equal_p_value_smob (SCM v1, SCM v2) | |
185 | { | |
186 | const value_smob *v1_smob = (value_smob *) SCM_SMOB_DATA (v1); | |
187 | const value_smob *v2_smob = (value_smob *) SCM_SMOB_DATA (v2); | |
188 | int result = 0; | |
ed3ef339 | 189 | |
492d29ea | 190 | TRY |
ed3ef339 DE |
191 | { |
192 | result = value_equal (v1_smob->value, v2_smob->value); | |
193 | } | |
492d29ea PA |
194 | CATCH (except, RETURN_MASK_ALL) |
195 | { | |
196 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
197 | } | |
198 | END_CATCH | |
ed3ef339 DE |
199 | |
200 | return scm_from_bool (result); | |
201 | } | |
202 | ||
203 | /* Low level routine to create a <gdb:value> object. */ | |
204 | ||
205 | static SCM | |
206 | vlscm_make_value_smob (void) | |
207 | { | |
208 | value_smob *v_smob = (value_smob *) | |
209 | scm_gc_malloc (sizeof (value_smob), value_smob_name); | |
210 | SCM v_scm; | |
211 | ||
212 | /* These must be filled in by the caller. */ | |
213 | v_smob->value = NULL; | |
214 | v_smob->prev = NULL; | |
215 | v_smob->next = NULL; | |
216 | ||
217 | /* These are lazily computed. */ | |
218 | v_smob->address = SCM_UNDEFINED; | |
219 | v_smob->type = SCM_UNDEFINED; | |
220 | v_smob->dynamic_type = SCM_UNDEFINED; | |
221 | ||
222 | v_scm = scm_new_smob (value_smob_tag, (scm_t_bits) v_smob); | |
223 | gdbscm_init_gsmob (&v_smob->base); | |
224 | ||
225 | return v_scm; | |
226 | } | |
227 | ||
228 | /* Return non-zero if SCM is a <gdb:value> object. */ | |
229 | ||
230 | int | |
231 | vlscm_is_value (SCM scm) | |
232 | { | |
233 | return SCM_SMOB_PREDICATE (value_smob_tag, scm); | |
234 | } | |
235 | ||
236 | /* (value? object) -> boolean */ | |
237 | ||
238 | static SCM | |
239 | gdbscm_value_p (SCM scm) | |
240 | { | |
241 | return scm_from_bool (vlscm_is_value (scm)); | |
242 | } | |
243 | ||
244 | /* Create a new <gdb:value> object that encapsulates VALUE. | |
245 | The value is released from the all_values chain so its lifetime is not | |
246 | bound to the execution of a command. */ | |
247 | ||
248 | SCM | |
249 | vlscm_scm_from_value (struct value *value) | |
250 | { | |
251 | /* N.B. It's important to not cause any side-effects until we know the | |
252 | conversion worked. */ | |
253 | SCM v_scm = vlscm_make_value_smob (); | |
254 | value_smob *v_smob = (value_smob *) SCM_SMOB_DATA (v_scm); | |
255 | ||
22bc8444 | 256 | v_smob->value = release_value (value).release (); |
ed3ef339 DE |
257 | vlscm_remember_scheme_value (v_smob); |
258 | ||
259 | return v_scm; | |
260 | } | |
261 | ||
262 | /* Returns the <gdb:value> object in SELF. | |
263 | Throws an exception if SELF is not a <gdb:value> object. */ | |
264 | ||
265 | static SCM | |
266 | vlscm_get_value_arg_unsafe (SCM self, int arg_pos, const char *func_name) | |
267 | { | |
268 | SCM_ASSERT_TYPE (vlscm_is_value (self), self, arg_pos, func_name, | |
269 | value_smob_name); | |
270 | ||
271 | return self; | |
272 | } | |
273 | ||
274 | /* Returns a pointer to the value smob of SELF. | |
275 | Throws an exception if SELF is not a <gdb:value> object. */ | |
276 | ||
277 | static value_smob * | |
278 | vlscm_get_value_smob_arg_unsafe (SCM self, int arg_pos, const char *func_name) | |
279 | { | |
280 | SCM v_scm = vlscm_get_value_arg_unsafe (self, arg_pos, func_name); | |
281 | value_smob *v_smob = (value_smob *) SCM_SMOB_DATA (v_scm); | |
282 | ||
283 | return v_smob; | |
284 | } | |
285 | ||
286 | /* Return the value field of V_SCM, an object of type <gdb:value>. | |
287 | This exists so that we don't have to export the struct's contents. */ | |
288 | ||
289 | struct value * | |
290 | vlscm_scm_to_value (SCM v_scm) | |
291 | { | |
292 | value_smob *v_smob; | |
293 | ||
294 | gdb_assert (vlscm_is_value (v_scm)); | |
295 | v_smob = (value_smob *) SCM_SMOB_DATA (v_scm); | |
296 | return v_smob->value; | |
297 | } | |
298 | \f | |
299 | /* Value methods. */ | |
300 | ||
301 | /* (make-value x [#:type type]) -> <gdb:value> */ | |
302 | ||
303 | static SCM | |
304 | gdbscm_make_value (SCM x, SCM rest) | |
305 | { | |
306 | struct gdbarch *gdbarch = get_current_arch (); | |
307 | const struct language_defn *language = current_language; | |
308 | const SCM keywords[] = { type_keyword, SCM_BOOL_F }; | |
309 | int type_arg_pos = -1; | |
310 | SCM type_scm = SCM_UNDEFINED; | |
311 | SCM except_scm, result; | |
312 | type_smob *t_smob; | |
313 | struct type *type = NULL; | |
314 | struct value *value; | |
315 | struct cleanup *cleanups; | |
316 | ||
317 | gdbscm_parse_function_args (FUNC_NAME, SCM_ARG2, keywords, "#O", rest, | |
318 | &type_arg_pos, &type_scm); | |
319 | ||
320 | if (type_arg_pos > 0) | |
321 | { | |
322 | t_smob = tyscm_get_type_smob_arg_unsafe (type_scm, type_arg_pos, | |
323 | FUNC_NAME); | |
324 | type = tyscm_type_smob_type (t_smob); | |
325 | } | |
326 | ||
327 | cleanups = make_cleanup_value_free_to_mark (value_mark ()); | |
328 | ||
329 | value = vlscm_convert_typed_value_from_scheme (FUNC_NAME, SCM_ARG1, x, | |
330 | type_arg_pos, type_scm, type, | |
331 | &except_scm, | |
332 | gdbarch, language); | |
333 | if (value == NULL) | |
334 | { | |
335 | do_cleanups (cleanups); | |
336 | gdbscm_throw (except_scm); | |
337 | } | |
338 | ||
339 | result = vlscm_scm_from_value (value); | |
340 | ||
341 | do_cleanups (cleanups); | |
342 | ||
343 | if (gdbscm_is_exception (result)) | |
344 | gdbscm_throw (result); | |
345 | return result; | |
346 | } | |
347 | ||
348 | /* (make-lazy-value <gdb:type> address) -> <gdb:value> */ | |
349 | ||
350 | static SCM | |
351 | gdbscm_make_lazy_value (SCM type_scm, SCM address_scm) | |
352 | { | |
353 | type_smob *t_smob; | |
354 | struct type *type; | |
355 | ULONGEST address; | |
356 | struct value *value = NULL; | |
357 | SCM result; | |
358 | struct cleanup *cleanups; | |
ed3ef339 DE |
359 | |
360 | t_smob = tyscm_get_type_smob_arg_unsafe (type_scm, SCM_ARG1, FUNC_NAME); | |
361 | type = tyscm_type_smob_type (t_smob); | |
362 | ||
363 | gdbscm_parse_function_args (FUNC_NAME, SCM_ARG2, NULL, "U", | |
364 | address_scm, &address); | |
365 | ||
366 | cleanups = make_cleanup_value_free_to_mark (value_mark ()); | |
367 | ||
368 | /* There's no (current) need to wrap this in a TRY_CATCH, but for consistency | |
369 | and future-proofing we do. */ | |
492d29ea | 370 | TRY |
ed3ef339 DE |
371 | { |
372 | value = value_from_contents_and_address (type, NULL, address); | |
373 | } | |
492d29ea PA |
374 | CATCH (except, RETURN_MASK_ALL) |
375 | { | |
376 | GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS (except, cleanups); | |
377 | } | |
378 | END_CATCH | |
ed3ef339 DE |
379 | |
380 | result = vlscm_scm_from_value (value); | |
381 | ||
382 | do_cleanups (cleanups); | |
383 | ||
384 | if (gdbscm_is_exception (result)) | |
385 | gdbscm_throw (result); | |
386 | return result; | |
387 | } | |
388 | ||
389 | /* (value-optimized-out? <gdb:value>) -> boolean */ | |
390 | ||
391 | static SCM | |
392 | gdbscm_value_optimized_out_p (SCM self) | |
393 | { | |
394 | value_smob *v_smob | |
395 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
396 | struct value *value = v_smob->value; | |
397 | int opt = 0; | |
ed3ef339 | 398 | |
492d29ea | 399 | TRY |
ed3ef339 DE |
400 | { |
401 | opt = value_optimized_out (value); | |
402 | } | |
492d29ea PA |
403 | CATCH (except, RETURN_MASK_ALL) |
404 | { | |
405 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
406 | } | |
407 | END_CATCH | |
ed3ef339 DE |
408 | |
409 | return scm_from_bool (opt); | |
410 | } | |
411 | ||
412 | /* (value-address <gdb:value>) -> integer | |
413 | Returns #f if the value doesn't have one. */ | |
414 | ||
415 | static SCM | |
416 | gdbscm_value_address (SCM self) | |
417 | { | |
418 | value_smob *v_smob | |
419 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
420 | struct value *value = v_smob->value; | |
421 | ||
422 | if (SCM_UNBNDP (v_smob->address)) | |
423 | { | |
ed3ef339 DE |
424 | struct cleanup *cleanup |
425 | = make_cleanup_value_free_to_mark (value_mark ()); | |
432ae719 | 426 | SCM address = SCM_BOOL_F; |
ed3ef339 | 427 | |
492d29ea | 428 | TRY |
ed3ef339 | 429 | { |
432ae719 | 430 | address = vlscm_scm_from_value (value_addr (value)); |
ed3ef339 | 431 | } |
492d29ea PA |
432 | CATCH (except, RETURN_MASK_ALL) |
433 | { | |
492d29ea PA |
434 | } |
435 | END_CATCH | |
436 | ||
ed3ef339 DE |
437 | do_cleanups (cleanup); |
438 | ||
439 | if (gdbscm_is_exception (address)) | |
440 | gdbscm_throw (address); | |
441 | ||
442 | v_smob->address = address; | |
443 | } | |
444 | ||
445 | return v_smob->address; | |
446 | } | |
447 | ||
448 | /* (value-dereference <gdb:value>) -> <gdb:value> | |
449 | Given a value of a pointer type, apply the C unary * operator to it. */ | |
450 | ||
451 | static SCM | |
452 | gdbscm_value_dereference (SCM self) | |
453 | { | |
454 | value_smob *v_smob | |
455 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
456 | struct value *value = v_smob->value; | |
457 | SCM result; | |
458 | struct value *res_val = NULL; | |
459 | struct cleanup *cleanups; | |
ed3ef339 DE |
460 | |
461 | cleanups = make_cleanup_value_free_to_mark (value_mark ()); | |
462 | ||
492d29ea | 463 | TRY |
ed3ef339 DE |
464 | { |
465 | res_val = value_ind (value); | |
466 | } | |
492d29ea PA |
467 | CATCH (except, RETURN_MASK_ALL) |
468 | { | |
469 | GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS (except, cleanups); | |
470 | } | |
471 | END_CATCH | |
ed3ef339 DE |
472 | |
473 | result = vlscm_scm_from_value (res_val); | |
474 | ||
475 | do_cleanups (cleanups); | |
476 | ||
477 | if (gdbscm_is_exception (result)) | |
478 | gdbscm_throw (result); | |
479 | ||
480 | return result; | |
481 | } | |
482 | ||
483 | /* (value-referenced-value <gdb:value>) -> <gdb:value> | |
484 | Given a value of a reference type, return the value referenced. | |
485 | The difference between this function and gdbscm_value_dereference is that | |
486 | the latter applies * unary operator to a value, which need not always | |
487 | result in the value referenced. | |
488 | For example, for a value which is a reference to an 'int' pointer ('int *'), | |
489 | gdbscm_value_dereference will result in a value of type 'int' while | |
490 | gdbscm_value_referenced_value will result in a value of type 'int *'. */ | |
491 | ||
492 | static SCM | |
493 | gdbscm_value_referenced_value (SCM self) | |
494 | { | |
495 | value_smob *v_smob | |
496 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
497 | struct value *value = v_smob->value; | |
498 | SCM result; | |
499 | struct value *res_val = NULL; | |
500 | struct cleanup *cleanups; | |
ed3ef339 DE |
501 | |
502 | cleanups = make_cleanup_value_free_to_mark (value_mark ()); | |
503 | ||
492d29ea | 504 | TRY |
ed3ef339 DE |
505 | { |
506 | switch (TYPE_CODE (check_typedef (value_type (value)))) | |
507 | { | |
508 | case TYPE_CODE_PTR: | |
509 | res_val = value_ind (value); | |
510 | break; | |
511 | case TYPE_CODE_REF: | |
512 | res_val = coerce_ref (value); | |
513 | break; | |
514 | default: | |
515 | error (_("Trying to get the referenced value from a value which is" | |
516 | " neither a pointer nor a reference")); | |
517 | } | |
518 | } | |
492d29ea PA |
519 | CATCH (except, RETURN_MASK_ALL) |
520 | { | |
521 | GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS (except, cleanups); | |
522 | } | |
523 | END_CATCH | |
ed3ef339 DE |
524 | |
525 | result = vlscm_scm_from_value (res_val); | |
526 | ||
527 | do_cleanups (cleanups); | |
528 | ||
529 | if (gdbscm_is_exception (result)) | |
530 | gdbscm_throw (result); | |
531 | ||
532 | return result; | |
533 | } | |
534 | ||
535 | /* (value-type <gdb:value>) -> <gdb:type> */ | |
536 | ||
537 | static SCM | |
538 | gdbscm_value_type (SCM self) | |
539 | { | |
540 | value_smob *v_smob | |
541 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
542 | struct value *value = v_smob->value; | |
543 | ||
544 | if (SCM_UNBNDP (v_smob->type)) | |
545 | v_smob->type = tyscm_scm_from_type (value_type (value)); | |
546 | ||
547 | return v_smob->type; | |
548 | } | |
549 | ||
550 | /* (value-dynamic-type <gdb:value>) -> <gdb:type> */ | |
551 | ||
552 | static SCM | |
553 | gdbscm_value_dynamic_type (SCM self) | |
554 | { | |
555 | value_smob *v_smob | |
556 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
557 | struct value *value = v_smob->value; | |
558 | struct type *type = NULL; | |
ed3ef339 | 559 | |
1390d0ef | 560 | if (! SCM_UNBNDP (v_smob->dynamic_type)) |
ed3ef339 DE |
561 | return v_smob->dynamic_type; |
562 | ||
492d29ea | 563 | TRY |
ed3ef339 DE |
564 | { |
565 | struct cleanup *cleanup | |
566 | = make_cleanup_value_free_to_mark (value_mark ()); | |
567 | ||
568 | type = value_type (value); | |
f168693b | 569 | type = check_typedef (type); |
ed3ef339 DE |
570 | |
571 | if (((TYPE_CODE (type) == TYPE_CODE_PTR) | |
572 | || (TYPE_CODE (type) == TYPE_CODE_REF)) | |
4753d33b | 573 | && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT)) |
ed3ef339 DE |
574 | { |
575 | struct value *target; | |
576 | int was_pointer = TYPE_CODE (type) == TYPE_CODE_PTR; | |
577 | ||
0be03e84 DE |
578 | if (was_pointer) |
579 | target = value_ind (value); | |
580 | else | |
581 | target = coerce_ref (value); | |
ed3ef339 DE |
582 | type = value_rtti_type (target, NULL, NULL, NULL); |
583 | ||
584 | if (type) | |
585 | { | |
586 | if (was_pointer) | |
587 | type = lookup_pointer_type (type); | |
588 | else | |
3b224330 | 589 | type = lookup_lvalue_reference_type (type); |
ed3ef339 DE |
590 | } |
591 | } | |
4753d33b | 592 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT) |
ed3ef339 DE |
593 | type = value_rtti_type (value, NULL, NULL, NULL); |
594 | else | |
595 | { | |
596 | /* Re-use object's static type. */ | |
597 | type = NULL; | |
598 | } | |
599 | ||
600 | do_cleanups (cleanup); | |
601 | } | |
492d29ea PA |
602 | CATCH (except, RETURN_MASK_ALL) |
603 | { | |
604 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
605 | } | |
606 | END_CATCH | |
ed3ef339 DE |
607 | |
608 | if (type == NULL) | |
609 | v_smob->dynamic_type = gdbscm_value_type (self); | |
610 | else | |
611 | v_smob->dynamic_type = tyscm_scm_from_type (type); | |
612 | ||
613 | return v_smob->dynamic_type; | |
614 | } | |
615 | ||
616 | /* A helper function that implements the various cast operators. */ | |
617 | ||
618 | static SCM | |
619 | vlscm_do_cast (SCM self, SCM type_scm, enum exp_opcode op, | |
620 | const char *func_name) | |
621 | { | |
622 | value_smob *v_smob | |
623 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
624 | struct value *value = v_smob->value; | |
625 | type_smob *t_smob | |
626 | = tyscm_get_type_smob_arg_unsafe (type_scm, SCM_ARG2, FUNC_NAME); | |
627 | struct type *type = tyscm_type_smob_type (t_smob); | |
628 | SCM result; | |
629 | struct value *res_val = NULL; | |
630 | struct cleanup *cleanups; | |
ed3ef339 DE |
631 | |
632 | cleanups = make_cleanup_value_free_to_mark (value_mark ()); | |
633 | ||
492d29ea | 634 | TRY |
ed3ef339 DE |
635 | { |
636 | if (op == UNOP_DYNAMIC_CAST) | |
637 | res_val = value_dynamic_cast (type, value); | |
638 | else if (op == UNOP_REINTERPRET_CAST) | |
639 | res_val = value_reinterpret_cast (type, value); | |
640 | else | |
641 | { | |
642 | gdb_assert (op == UNOP_CAST); | |
643 | res_val = value_cast (type, value); | |
644 | } | |
645 | } | |
492d29ea PA |
646 | CATCH (except, RETURN_MASK_ALL) |
647 | { | |
648 | GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS (except, cleanups); | |
649 | } | |
650 | END_CATCH | |
ed3ef339 DE |
651 | |
652 | gdb_assert (res_val != NULL); | |
653 | result = vlscm_scm_from_value (res_val); | |
654 | ||
655 | do_cleanups (cleanups); | |
656 | ||
657 | if (gdbscm_is_exception (result)) | |
658 | gdbscm_throw (result); | |
659 | ||
660 | return result; | |
661 | } | |
662 | ||
663 | /* (value-cast <gdb:value> <gdb:type>) -> <gdb:value> */ | |
664 | ||
665 | static SCM | |
666 | gdbscm_value_cast (SCM self, SCM new_type) | |
667 | { | |
668 | return vlscm_do_cast (self, new_type, UNOP_CAST, FUNC_NAME); | |
669 | } | |
670 | ||
671 | /* (value-dynamic-cast <gdb:value> <gdb:type>) -> <gdb:value> */ | |
672 | ||
673 | static SCM | |
674 | gdbscm_value_dynamic_cast (SCM self, SCM new_type) | |
675 | { | |
676 | return vlscm_do_cast (self, new_type, UNOP_DYNAMIC_CAST, FUNC_NAME); | |
677 | } | |
678 | ||
679 | /* (value-reinterpret-cast <gdb:value> <gdb:type>) -> <gdb:value> */ | |
680 | ||
681 | static SCM | |
682 | gdbscm_value_reinterpret_cast (SCM self, SCM new_type) | |
683 | { | |
684 | return vlscm_do_cast (self, new_type, UNOP_REINTERPRET_CAST, FUNC_NAME); | |
685 | } | |
686 | ||
687 | /* (value-field <gdb:value> string) -> <gdb:value> | |
688 | Given string name of an element inside structure, return its <gdb:value> | |
689 | object. */ | |
690 | ||
691 | static SCM | |
692 | gdbscm_value_field (SCM self, SCM field_scm) | |
693 | { | |
694 | value_smob *v_smob | |
695 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
696 | struct value *value = v_smob->value; | |
697 | char *field = NULL; | |
698 | struct value *res_val = NULL; | |
699 | SCM result; | |
700 | struct cleanup *cleanups; | |
ed3ef339 DE |
701 | |
702 | SCM_ASSERT_TYPE (scm_is_string (field_scm), field_scm, SCM_ARG2, FUNC_NAME, | |
703 | _("string")); | |
704 | ||
705 | cleanups = make_cleanup_value_free_to_mark (value_mark ()); | |
706 | ||
707 | field = gdbscm_scm_to_c_string (field_scm); | |
708 | make_cleanup (xfree, field); | |
709 | ||
492d29ea | 710 | TRY |
ed3ef339 DE |
711 | { |
712 | struct value *tmp = value; | |
713 | ||
5996220c DE |
714 | res_val = value_struct_elt (&tmp, NULL, field, NULL, |
715 | "struct/class/union"); | |
ed3ef339 | 716 | } |
492d29ea PA |
717 | CATCH (except, RETURN_MASK_ALL) |
718 | { | |
719 | GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS (except, cleanups); | |
720 | } | |
721 | END_CATCH | |
ed3ef339 DE |
722 | |
723 | gdb_assert (res_val != NULL); | |
724 | result = vlscm_scm_from_value (res_val); | |
725 | ||
726 | do_cleanups (cleanups); | |
727 | ||
728 | if (gdbscm_is_exception (result)) | |
729 | gdbscm_throw (result); | |
730 | ||
731 | return result; | |
732 | } | |
733 | ||
734 | /* (value-subscript <gdb:value> integer|<gdb:value>) -> <gdb:value> | |
735 | Return the specified value in an array. */ | |
736 | ||
737 | static SCM | |
738 | gdbscm_value_subscript (SCM self, SCM index_scm) | |
739 | { | |
740 | value_smob *v_smob | |
741 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
742 | struct value *value = v_smob->value; | |
743 | struct value *index = NULL; | |
744 | struct value *res_val = NULL; | |
745 | struct type *type = value_type (value); | |
746 | struct gdbarch *gdbarch; | |
747 | SCM result, except_scm; | |
748 | struct cleanup *cleanups; | |
ed3ef339 DE |
749 | |
750 | /* The sequencing here, as everywhere else, is important. | |
751 | We can't have existing cleanups when a Scheme exception is thrown. */ | |
752 | ||
753 | SCM_ASSERT (type != NULL, self, SCM_ARG2, FUNC_NAME); | |
754 | gdbarch = get_type_arch (type); | |
755 | ||
756 | cleanups = make_cleanup_value_free_to_mark (value_mark ()); | |
757 | ||
758 | index = vlscm_convert_value_from_scheme (FUNC_NAME, SCM_ARG2, index_scm, | |
759 | &except_scm, | |
760 | gdbarch, current_language); | |
761 | if (index == NULL) | |
762 | { | |
763 | do_cleanups (cleanups); | |
764 | gdbscm_throw (except_scm); | |
765 | } | |
766 | ||
492d29ea | 767 | TRY |
ed3ef339 DE |
768 | { |
769 | struct value *tmp = value; | |
770 | ||
771 | /* Assume we are attempting an array access, and let the value code | |
772 | throw an exception if the index has an invalid type. | |
773 | Check the value's type is something that can be accessed via | |
774 | a subscript. */ | |
775 | tmp = coerce_ref (tmp); | |
776 | type = check_typedef (value_type (tmp)); | |
777 | if (TYPE_CODE (type) != TYPE_CODE_ARRAY | |
778 | && TYPE_CODE (type) != TYPE_CODE_PTR) | |
779 | error (_("Cannot subscript requested type")); | |
780 | ||
781 | res_val = value_subscript (tmp, value_as_long (index)); | |
782 | } | |
492d29ea PA |
783 | CATCH (except, RETURN_MASK_ALL) |
784 | { | |
785 | GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS (except, cleanups); | |
786 | } | |
787 | END_CATCH | |
ed3ef339 DE |
788 | |
789 | gdb_assert (res_val != NULL); | |
790 | result = vlscm_scm_from_value (res_val); | |
791 | ||
792 | do_cleanups (cleanups); | |
793 | ||
794 | if (gdbscm_is_exception (result)) | |
795 | gdbscm_throw (result); | |
796 | ||
797 | return result; | |
798 | } | |
799 | ||
800 | /* (value-call <gdb:value> arg-list) -> <gdb:value> | |
801 | Perform an inferior function call on the value. */ | |
802 | ||
803 | static SCM | |
804 | gdbscm_value_call (SCM self, SCM args) | |
805 | { | |
806 | value_smob *v_smob | |
807 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
808 | struct value *function = v_smob->value; | |
809 | struct value *mark = value_mark (); | |
810 | struct type *ftype = NULL; | |
811 | long args_count; | |
812 | struct value **vargs = NULL; | |
813 | SCM result = SCM_BOOL_F; | |
ed3ef339 | 814 | |
492d29ea | 815 | TRY |
ed3ef339 DE |
816 | { |
817 | ftype = check_typedef (value_type (function)); | |
818 | } | |
492d29ea PA |
819 | CATCH (except, RETURN_MASK_ALL) |
820 | { | |
821 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
822 | } | |
823 | END_CATCH | |
ed3ef339 DE |
824 | |
825 | SCM_ASSERT_TYPE (TYPE_CODE (ftype) == TYPE_CODE_FUNC, self, | |
826 | SCM_ARG1, FUNC_NAME, | |
827 | _("function (value of TYPE_CODE_FUNC)")); | |
828 | ||
829 | SCM_ASSERT_TYPE (gdbscm_is_true (scm_list_p (args)), args, | |
830 | SCM_ARG2, FUNC_NAME, _("list")); | |
831 | ||
832 | args_count = scm_ilength (args); | |
833 | if (args_count > 0) | |
834 | { | |
835 | struct gdbarch *gdbarch = get_current_arch (); | |
836 | const struct language_defn *language = current_language; | |
837 | SCM except_scm; | |
838 | long i; | |
839 | ||
8d749320 | 840 | vargs = XALLOCAVEC (struct value *, args_count); |
ed3ef339 DE |
841 | for (i = 0; i < args_count; i++) |
842 | { | |
843 | SCM arg = scm_car (args); | |
844 | ||
845 | vargs[i] = vlscm_convert_value_from_scheme (FUNC_NAME, | |
846 | GDBSCM_ARG_NONE, arg, | |
847 | &except_scm, | |
848 | gdbarch, language); | |
849 | if (vargs[i] == NULL) | |
850 | gdbscm_throw (except_scm); | |
851 | ||
852 | args = scm_cdr (args); | |
853 | } | |
854 | gdb_assert (gdbscm_is_true (scm_null_p (args))); | |
855 | } | |
856 | ||
492d29ea | 857 | TRY |
ed3ef339 DE |
858 | { |
859 | struct cleanup *cleanup = make_cleanup_value_free_to_mark (mark); | |
860 | struct value *return_value; | |
861 | ||
7022349d | 862 | return_value = call_function_by_hand (function, NULL, args_count, vargs); |
ed3ef339 DE |
863 | result = vlscm_scm_from_value (return_value); |
864 | do_cleanups (cleanup); | |
865 | } | |
492d29ea PA |
866 | CATCH (except, RETURN_MASK_ALL) |
867 | { | |
868 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
869 | } | |
870 | END_CATCH | |
ed3ef339 DE |
871 | |
872 | if (gdbscm_is_exception (result)) | |
873 | gdbscm_throw (result); | |
874 | ||
875 | return result; | |
876 | } | |
877 | ||
878 | /* (value->bytevector <gdb:value>) -> bytevector */ | |
879 | ||
880 | static SCM | |
881 | gdbscm_value_to_bytevector (SCM self) | |
882 | { | |
883 | value_smob *v_smob | |
884 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
885 | struct value *value = v_smob->value; | |
886 | struct type *type; | |
887 | size_t length = 0; | |
888 | const gdb_byte *contents = NULL; | |
889 | SCM bv; | |
ed3ef339 DE |
890 | |
891 | type = value_type (value); | |
892 | ||
492d29ea | 893 | TRY |
ed3ef339 | 894 | { |
f168693b | 895 | type = check_typedef (type); |
ed3ef339 DE |
896 | length = TYPE_LENGTH (type); |
897 | contents = value_contents (value); | |
898 | } | |
492d29ea PA |
899 | CATCH (except, RETURN_MASK_ALL) |
900 | { | |
901 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
902 | } | |
903 | END_CATCH | |
ed3ef339 DE |
904 | |
905 | bv = scm_c_make_bytevector (length); | |
906 | memcpy (SCM_BYTEVECTOR_CONTENTS (bv), contents, length); | |
907 | ||
908 | return bv; | |
909 | } | |
910 | ||
911 | /* Helper function to determine if a type is "int-like". */ | |
912 | ||
913 | static int | |
914 | is_intlike (struct type *type, int ptr_ok) | |
915 | { | |
916 | return (TYPE_CODE (type) == TYPE_CODE_INT | |
917 | || TYPE_CODE (type) == TYPE_CODE_ENUM | |
918 | || TYPE_CODE (type) == TYPE_CODE_BOOL | |
919 | || TYPE_CODE (type) == TYPE_CODE_CHAR | |
920 | || (ptr_ok && TYPE_CODE (type) == TYPE_CODE_PTR)); | |
921 | } | |
922 | ||
923 | /* (value->bool <gdb:value>) -> boolean | |
924 | Throws an error if the value is not integer-like. */ | |
925 | ||
926 | static SCM | |
927 | gdbscm_value_to_bool (SCM self) | |
928 | { | |
929 | value_smob *v_smob | |
930 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
931 | struct value *value = v_smob->value; | |
932 | struct type *type; | |
933 | LONGEST l = 0; | |
ed3ef339 DE |
934 | |
935 | type = value_type (value); | |
936 | ||
492d29ea | 937 | TRY |
ed3ef339 | 938 | { |
f168693b | 939 | type = check_typedef (type); |
ed3ef339 | 940 | } |
492d29ea PA |
941 | CATCH (except, RETURN_MASK_ALL) |
942 | { | |
943 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
944 | } | |
945 | END_CATCH | |
ed3ef339 DE |
946 | |
947 | SCM_ASSERT_TYPE (is_intlike (type, 1), self, SCM_ARG1, FUNC_NAME, | |
948 | _("integer-like gdb value")); | |
949 | ||
492d29ea | 950 | TRY |
ed3ef339 DE |
951 | { |
952 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
953 | l = value_as_address (value); | |
954 | else | |
955 | l = value_as_long (value); | |
956 | } | |
492d29ea PA |
957 | CATCH (except, RETURN_MASK_ALL) |
958 | { | |
959 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
960 | } | |
961 | END_CATCH | |
ed3ef339 DE |
962 | |
963 | return scm_from_bool (l != 0); | |
964 | } | |
965 | ||
966 | /* (value->integer <gdb:value>) -> integer | |
967 | Throws an error if the value is not integer-like. */ | |
968 | ||
969 | static SCM | |
970 | gdbscm_value_to_integer (SCM self) | |
971 | { | |
972 | value_smob *v_smob | |
973 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
974 | struct value *value = v_smob->value; | |
975 | struct type *type; | |
976 | LONGEST l = 0; | |
ed3ef339 DE |
977 | |
978 | type = value_type (value); | |
979 | ||
492d29ea | 980 | TRY |
ed3ef339 | 981 | { |
f168693b | 982 | type = check_typedef (type); |
ed3ef339 | 983 | } |
492d29ea PA |
984 | CATCH (except, RETURN_MASK_ALL) |
985 | { | |
986 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
987 | } | |
988 | END_CATCH | |
ed3ef339 DE |
989 | |
990 | SCM_ASSERT_TYPE (is_intlike (type, 1), self, SCM_ARG1, FUNC_NAME, | |
991 | _("integer-like gdb value")); | |
992 | ||
492d29ea | 993 | TRY |
ed3ef339 DE |
994 | { |
995 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
996 | l = value_as_address (value); | |
997 | else | |
998 | l = value_as_long (value); | |
999 | } | |
492d29ea PA |
1000 | CATCH (except, RETURN_MASK_ALL) |
1001 | { | |
1002 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
1003 | } | |
1004 | END_CATCH | |
ed3ef339 DE |
1005 | |
1006 | if (TYPE_UNSIGNED (type)) | |
1007 | return gdbscm_scm_from_ulongest (l); | |
1008 | else | |
1009 | return gdbscm_scm_from_longest (l); | |
1010 | } | |
1011 | ||
1012 | /* (value->real <gdb:value>) -> real | |
1013 | Throws an error if the value is not a number. */ | |
1014 | ||
1015 | static SCM | |
1016 | gdbscm_value_to_real (SCM self) | |
1017 | { | |
1018 | value_smob *v_smob | |
1019 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
1020 | struct value *value = v_smob->value; | |
1021 | struct type *type; | |
14ad9311 UW |
1022 | double d = 0; |
1023 | struct value *check = nullptr; | |
ed3ef339 DE |
1024 | |
1025 | type = value_type (value); | |
1026 | ||
492d29ea | 1027 | TRY |
ed3ef339 | 1028 | { |
f168693b | 1029 | type = check_typedef (type); |
ed3ef339 | 1030 | } |
492d29ea PA |
1031 | CATCH (except, RETURN_MASK_ALL) |
1032 | { | |
1033 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
1034 | } | |
1035 | END_CATCH | |
ed3ef339 DE |
1036 | |
1037 | SCM_ASSERT_TYPE (is_intlike (type, 0) || TYPE_CODE (type) == TYPE_CODE_FLT, | |
1038 | self, SCM_ARG1, FUNC_NAME, _("number")); | |
1039 | ||
492d29ea | 1040 | TRY |
ed3ef339 | 1041 | { |
14ad9311 UW |
1042 | if (is_floating_value (value)) |
1043 | { | |
1044 | d = target_float_to_host_double (value_contents (value), type); | |
1045 | check = allocate_value (type); | |
1046 | target_float_from_host_double (value_contents_raw (check), type, d); | |
1047 | } | |
1048 | else if (TYPE_UNSIGNED (type)) | |
1049 | { | |
1050 | d = (ULONGEST) value_as_long (value); | |
1051 | check = value_from_ulongest (type, (ULONGEST) d); | |
1052 | } | |
1053 | else | |
1054 | { | |
1055 | d = value_as_long (value); | |
1056 | check = value_from_longest (type, (LONGEST) d); | |
1057 | } | |
ed3ef339 | 1058 | } |
492d29ea PA |
1059 | CATCH (except, RETURN_MASK_ALL) |
1060 | { | |
1061 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
1062 | } | |
1063 | END_CATCH | |
ed3ef339 DE |
1064 | |
1065 | /* TODO: Is there a better way to check if the value fits? */ | |
14ad9311 | 1066 | if (!value_equal (value, check)) |
ed3ef339 DE |
1067 | gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self, |
1068 | _("number can't be converted to a double")); | |
1069 | ||
1070 | return scm_from_double (d); | |
1071 | } | |
1072 | ||
1073 | /* (value->string <gdb:value> | |
1074 | [#:encoding encoding] | |
1075 | [#:errors #f | 'error | 'substitute] | |
1076 | [#:length length]) | |
1077 | -> string | |
1078 | Return Unicode string with value's contents, which must be a string. | |
1079 | ||
1080 | If ENCODING is not given, the string is assumed to be encoded in | |
1081 | the target's charset. | |
1082 | ||
1083 | ERRORS is one of #f, 'error or 'substitute. | |
d2929fdc DE |
1084 | An error setting of #f means use the default, which is Guile's |
1085 | %default-port-conversion-strategy when using Guile >= 2.0.6, or 'error if | |
1086 | using an earlier version of Guile. Earlier versions do not properly | |
1087 | support obtaining the default port conversion strategy. | |
1088 | If the default is not one of 'error or 'substitute, 'substitute is used. | |
ed3ef339 DE |
1089 | An error setting of "error" causes an exception to be thrown if there's |
1090 | a decoding error. An error setting of "substitute" causes invalid | |
1091 | characters to be replaced with "?". | |
1092 | ||
1093 | If LENGTH is provided, only fetch string to the length provided. | |
1094 | LENGTH must be a Scheme integer, it can't be a <gdb:value> integer. */ | |
1095 | ||
1096 | static SCM | |
1097 | gdbscm_value_to_string (SCM self, SCM rest) | |
1098 | { | |
1099 | value_smob *v_smob | |
1100 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
1101 | struct value *value = v_smob->value; | |
1102 | const SCM keywords[] = { | |
1103 | encoding_keyword, errors_keyword, length_keyword, SCM_BOOL_F | |
1104 | }; | |
1105 | int encoding_arg_pos = -1, errors_arg_pos = -1, length_arg_pos = -1; | |
1106 | char *encoding = NULL; | |
1107 | SCM errors = SCM_BOOL_F; | |
1108 | int length = -1; | |
1109 | gdb_byte *buffer = NULL; | |
1110 | const char *la_encoding = NULL; | |
1111 | struct type *char_type = NULL; | |
1112 | SCM result; | |
1113 | struct cleanup *cleanups; | |
ed3ef339 DE |
1114 | |
1115 | /* The sequencing here, as everywhere else, is important. | |
1116 | We can't have existing cleanups when a Scheme exception is thrown. */ | |
1117 | ||
1118 | gdbscm_parse_function_args (FUNC_NAME, SCM_ARG2, keywords, "#sOi", rest, | |
1119 | &encoding_arg_pos, &encoding, | |
1120 | &errors_arg_pos, &errors, | |
1121 | &length_arg_pos, &length); | |
1122 | ||
1123 | cleanups = make_cleanup (xfree, encoding); | |
1124 | ||
1125 | if (errors_arg_pos > 0 | |
1126 | && errors != SCM_BOOL_F | |
1127 | && !scm_is_eq (errors, error_symbol) | |
1128 | && !scm_is_eq (errors, substitute_symbol)) | |
1129 | { | |
1130 | SCM excp | |
1131 | = gdbscm_make_out_of_range_error (FUNC_NAME, errors_arg_pos, errors, | |
1132 | _("invalid error kind")); | |
1133 | ||
1134 | do_cleanups (cleanups); | |
1135 | gdbscm_throw (excp); | |
1136 | } | |
1137 | if (errors == SCM_BOOL_F) | |
d2929fdc DE |
1138 | { |
1139 | /* N.B. scm_port_conversion_strategy in Guile versions prior to 2.0.6 | |
1140 | will throw a Scheme error when passed #f. */ | |
1141 | if (gdbscm_guile_version_is_at_least (2, 0, 6)) | |
1142 | errors = scm_port_conversion_strategy (SCM_BOOL_F); | |
1143 | else | |
1144 | errors = error_symbol; | |
1145 | } | |
ed3ef339 DE |
1146 | /* We don't assume anything about the result of scm_port_conversion_strategy. |
1147 | From this point on, if errors is not 'errors, use 'substitute. */ | |
1148 | ||
492d29ea | 1149 | TRY |
ed3ef339 DE |
1150 | { |
1151 | LA_GET_STRING (value, &buffer, &length, &char_type, &la_encoding); | |
1152 | } | |
492d29ea PA |
1153 | CATCH (except, RETURN_MASK_ALL) |
1154 | { | |
1155 | GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS (except, cleanups); | |
1156 | } | |
1157 | END_CATCH | |
ed3ef339 DE |
1158 | |
1159 | /* If errors is "error" scm_from_stringn may throw a Scheme exception. | |
1160 | Make sure we don't leak. This is done via scm_dynwind_begin, et.al. */ | |
1161 | discard_cleanups (cleanups); | |
1162 | ||
c6486df5 | 1163 | scm_dynwind_begin ((scm_t_dynwind_flags) 0); |
ed3ef339 DE |
1164 | |
1165 | gdbscm_dynwind_xfree (encoding); | |
1166 | gdbscm_dynwind_xfree (buffer); | |
1167 | ||
1168 | result = scm_from_stringn ((const char *) buffer, | |
1169 | length * TYPE_LENGTH (char_type), | |
1170 | (encoding != NULL && *encoding != '\0' | |
1171 | ? encoding | |
1172 | : la_encoding), | |
1173 | scm_is_eq (errors, error_symbol) | |
1174 | ? SCM_FAILED_CONVERSION_ERROR | |
1175 | : SCM_FAILED_CONVERSION_QUESTION_MARK); | |
1176 | ||
1177 | scm_dynwind_end (); | |
1178 | ||
1179 | return result; | |
1180 | } | |
1181 | ||
1182 | /* (value->lazy-string <gdb:value> [#:encoding encoding] [#:length length]) | |
1183 | -> <gdb:lazy-string> | |
1184 | Return a Scheme object representing a lazy_string_object type. | |
1185 | A lazy string is a pointer to a string with an optional encoding and length. | |
1186 | If ENCODING is not given, the target's charset is used. | |
a7c0469f DE |
1187 | If LENGTH is provided then the length parameter is set to LENGTH. |
1188 | Otherwise if the value is an array of known length then the array's length | |
1189 | is used. Otherwise the length will be set to -1 (meaning first null of | |
1190 | appropriate with). | |
ed3ef339 DE |
1191 | LENGTH must be a Scheme integer, it can't be a <gdb:value> integer. */ |
1192 | ||
1193 | static SCM | |
1194 | gdbscm_value_to_lazy_string (SCM self, SCM rest) | |
1195 | { | |
1196 | value_smob *v_smob | |
1197 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
1198 | struct value *value = v_smob->value; | |
1199 | const SCM keywords[] = { encoding_keyword, length_keyword, SCM_BOOL_F }; | |
1200 | int encoding_arg_pos = -1, length_arg_pos = -1; | |
1201 | char *encoding = NULL; | |
1202 | int length = -1; | |
1203 | SCM result = SCM_BOOL_F; /* -Wall */ | |
1204 | struct cleanup *cleanups; | |
492d29ea | 1205 | struct gdb_exception except = exception_none; |
ed3ef339 DE |
1206 | |
1207 | /* The sequencing here, as everywhere else, is important. | |
1208 | We can't have existing cleanups when a Scheme exception is thrown. */ | |
1209 | ||
1210 | gdbscm_parse_function_args (FUNC_NAME, SCM_ARG2, keywords, "#si", rest, | |
1211 | &encoding_arg_pos, &encoding, | |
1212 | &length_arg_pos, &length); | |
1213 | ||
a7c0469f DE |
1214 | if (length < -1) |
1215 | { | |
1216 | gdbscm_out_of_range_error (FUNC_NAME, length_arg_pos, | |
1217 | scm_from_int (length), | |
1218 | _("invalid length")); | |
1219 | } | |
1220 | ||
ed3ef339 DE |
1221 | cleanups = make_cleanup (xfree, encoding); |
1222 | ||
492d29ea | 1223 | TRY |
ed3ef339 DE |
1224 | { |
1225 | struct cleanup *inner_cleanup | |
1226 | = make_cleanup_value_free_to_mark (value_mark ()); | |
a7c0469f DE |
1227 | struct type *type, *realtype; |
1228 | CORE_ADDR addr; | |
ed3ef339 | 1229 | |
a7c0469f DE |
1230 | type = value_type (value); |
1231 | realtype = check_typedef (type); | |
1232 | ||
1233 | switch (TYPE_CODE (realtype)) | |
1234 | { | |
1235 | case TYPE_CODE_ARRAY: | |
1236 | { | |
1237 | LONGEST array_length = -1; | |
1238 | LONGEST low_bound, high_bound; | |
1239 | ||
1240 | /* PR 20786: There's no way to specify an array of length zero. | |
1241 | Record a length of [0,-1] which is how Ada does it. Anything | |
1242 | we do is broken, but this one possible solution. */ | |
1243 | if (get_array_bounds (realtype, &low_bound, &high_bound)) | |
1244 | array_length = high_bound - low_bound + 1; | |
1245 | if (length == -1) | |
1246 | length = array_length; | |
1247 | else if (array_length == -1) | |
1248 | { | |
1249 | type = lookup_array_range_type (TYPE_TARGET_TYPE (realtype), | |
1250 | 0, length - 1); | |
1251 | } | |
1252 | else if (length != array_length) | |
1253 | { | |
1254 | /* We need to create a new array type with the | |
1255 | specified length. */ | |
1256 | if (length > array_length) | |
1257 | error (_("length is larger than array size")); | |
1258 | type = lookup_array_range_type (TYPE_TARGET_TYPE (type), | |
1259 | low_bound, | |
1260 | low_bound + length - 1); | |
1261 | } | |
1262 | addr = value_address (value); | |
1263 | break; | |
1264 | } | |
1265 | case TYPE_CODE_PTR: | |
1266 | /* If a length is specified we defer creating an array of the | |
1267 | specified width until we need to. */ | |
1268 | addr = value_as_address (value); | |
1269 | break; | |
1270 | default: | |
1271 | /* Should flag an error here. PR 20769. */ | |
1272 | addr = value_address (value); | |
1273 | break; | |
1274 | } | |
ed3ef339 | 1275 | |
a7c0469f | 1276 | result = lsscm_make_lazy_string (addr, length, encoding, type); |
ed3ef339 DE |
1277 | |
1278 | do_cleanups (inner_cleanup); | |
1279 | } | |
492d29ea PA |
1280 | CATCH (ex, RETURN_MASK_ALL) |
1281 | { | |
1282 | except = ex; | |
1283 | } | |
1284 | END_CATCH | |
1285 | ||
ed3ef339 DE |
1286 | do_cleanups (cleanups); |
1287 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
1288 | ||
1289 | if (gdbscm_is_exception (result)) | |
1290 | gdbscm_throw (result); | |
1291 | ||
1292 | return result; | |
1293 | } | |
1294 | ||
1295 | /* (value-lazy? <gdb:value>) -> boolean */ | |
1296 | ||
1297 | static SCM | |
1298 | gdbscm_value_lazy_p (SCM self) | |
1299 | { | |
1300 | value_smob *v_smob | |
1301 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
1302 | struct value *value = v_smob->value; | |
1303 | ||
1304 | return scm_from_bool (value_lazy (value)); | |
1305 | } | |
1306 | ||
1307 | /* (value-fetch-lazy! <gdb:value>) -> unspecified */ | |
1308 | ||
1309 | static SCM | |
1310 | gdbscm_value_fetch_lazy_x (SCM self) | |
1311 | { | |
1312 | value_smob *v_smob | |
1313 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
1314 | struct value *value = v_smob->value; | |
ed3ef339 | 1315 | |
492d29ea | 1316 | TRY |
ed3ef339 DE |
1317 | { |
1318 | if (value_lazy (value)) | |
1319 | value_fetch_lazy (value); | |
1320 | } | |
492d29ea PA |
1321 | CATCH (except, RETURN_MASK_ALL) |
1322 | { | |
1323 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
1324 | } | |
1325 | END_CATCH | |
ed3ef339 DE |
1326 | |
1327 | return SCM_UNSPECIFIED; | |
1328 | } | |
1329 | ||
1330 | /* (value-print <gdb:value>) -> string */ | |
1331 | ||
1332 | static SCM | |
1333 | gdbscm_value_print (SCM self) | |
1334 | { | |
1335 | value_smob *v_smob | |
1336 | = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); | |
1337 | struct value *value = v_smob->value; | |
1338 | struct value_print_options opts; | |
ed3ef339 DE |
1339 | |
1340 | get_user_print_options (&opts); | |
1341 | opts.deref_ref = 0; | |
1342 | ||
d7e74731 PA |
1343 | string_file stb; |
1344 | ||
492d29ea | 1345 | TRY |
ed3ef339 | 1346 | { |
d7e74731 | 1347 | common_val_print (value, &stb, 0, &opts, current_language); |
ed3ef339 | 1348 | } |
492d29ea PA |
1349 | CATCH (except, RETURN_MASK_ALL) |
1350 | { | |
1351 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
1352 | } | |
1353 | END_CATCH | |
ed3ef339 DE |
1354 | |
1355 | /* Use SCM_FAILED_CONVERSION_QUESTION_MARK to ensure this doesn't | |
1356 | throw an error if the encoding fails. | |
1357 | IWBN to use scm_take_locale_string here, but we'd have to temporarily | |
1358 | override the default port conversion handler because contrary to | |
1359 | documentation it doesn't necessarily free the input string. */ | |
d7e74731 PA |
1360 | return scm_from_stringn (stb.c_str (), stb.size (), host_charset (), |
1361 | SCM_FAILED_CONVERSION_QUESTION_MARK); | |
ed3ef339 DE |
1362 | } |
1363 | \f | |
1364 | /* (parse-and-eval string) -> <gdb:value> | |
1365 | Parse a string and evaluate the string as an expression. */ | |
1366 | ||
1367 | static SCM | |
1368 | gdbscm_parse_and_eval (SCM expr_scm) | |
1369 | { | |
1370 | char *expr_str; | |
1371 | struct value *res_val = NULL; | |
1372 | SCM result; | |
1373 | struct cleanup *cleanups; | |
ed3ef339 DE |
1374 | |
1375 | /* The sequencing here, as everywhere else, is important. | |
1376 | We can't have existing cleanups when a Scheme exception is thrown. */ | |
1377 | ||
1378 | gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, NULL, "s", | |
1379 | expr_scm, &expr_str); | |
1380 | ||
1381 | cleanups = make_cleanup_value_free_to_mark (value_mark ()); | |
1382 | make_cleanup (xfree, expr_str); | |
1383 | ||
492d29ea | 1384 | TRY |
ed3ef339 DE |
1385 | { |
1386 | res_val = parse_and_eval (expr_str); | |
1387 | } | |
492d29ea PA |
1388 | CATCH (except, RETURN_MASK_ALL) |
1389 | { | |
1390 | GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS (except, cleanups); | |
1391 | } | |
1392 | END_CATCH | |
ed3ef339 DE |
1393 | |
1394 | gdb_assert (res_val != NULL); | |
1395 | result = vlscm_scm_from_value (res_val); | |
1396 | ||
1397 | do_cleanups (cleanups); | |
1398 | ||
1399 | if (gdbscm_is_exception (result)) | |
1400 | gdbscm_throw (result); | |
1401 | ||
1402 | return result; | |
1403 | } | |
1404 | ||
1405 | /* (history-ref integer) -> <gdb:value> | |
1406 | Return the specified value from GDB's value history. */ | |
1407 | ||
1408 | static SCM | |
1409 | gdbscm_history_ref (SCM index) | |
1410 | { | |
1411 | int i; | |
1412 | struct value *res_val = NULL; /* Initialize to appease gcc warning. */ | |
ed3ef339 DE |
1413 | |
1414 | gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, NULL, "i", index, &i); | |
1415 | ||
492d29ea | 1416 | TRY |
ed3ef339 DE |
1417 | { |
1418 | res_val = access_value_history (i); | |
1419 | } | |
492d29ea PA |
1420 | CATCH (except, RETURN_MASK_ALL) |
1421 | { | |
1422 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
1423 | } | |
1424 | END_CATCH | |
ed3ef339 DE |
1425 | |
1426 | return vlscm_scm_from_value (res_val); | |
1427 | } | |
7a5a839f LC |
1428 | |
1429 | /* (history-append! <gdb:value>) -> index | |
1430 | Append VALUE to GDB's value history. Return its index in the history. */ | |
1431 | ||
1432 | static SCM | |
1433 | gdbscm_history_append_x (SCM value) | |
1434 | { | |
1435 | int res_index = -1; | |
1436 | struct value *v; | |
fb934770 | 1437 | value_smob *v_smob; |
7a5a839f | 1438 | |
fb934770 LC |
1439 | v_smob = vlscm_get_value_smob_arg_unsafe (value, SCM_ARG1, FUNC_NAME); |
1440 | v = v_smob->value; | |
7a5a839f | 1441 | |
492d29ea | 1442 | TRY |
7a5a839f LC |
1443 | { |
1444 | res_index = record_latest_value (v); | |
1445 | } | |
492d29ea PA |
1446 | CATCH (except, RETURN_MASK_ALL) |
1447 | { | |
1448 | GDBSCM_HANDLE_GDB_EXCEPTION (except); | |
1449 | } | |
1450 | END_CATCH | |
7a5a839f LC |
1451 | |
1452 | return scm_from_int (res_index); | |
1453 | } | |
ed3ef339 DE |
1454 | \f |
1455 | /* Initialize the Scheme value code. */ | |
1456 | ||
1457 | static const scheme_function value_functions[] = | |
1458 | { | |
72e02483 | 1459 | { "value?", 1, 0, 0, as_a_scm_t_subr (gdbscm_value_p), |
ed3ef339 DE |
1460 | "\ |
1461 | Return #t if the object is a <gdb:value> object." }, | |
1462 | ||
72e02483 | 1463 | { "make-value", 1, 0, 1, as_a_scm_t_subr (gdbscm_make_value), |
ed3ef339 DE |
1464 | "\ |
1465 | Create a <gdb:value> representing object.\n\ | |
1466 | Typically this is used to convert numbers and strings to\n\ | |
1467 | <gdb:value> objects.\n\ | |
1468 | \n\ | |
1469 | Arguments: object [#:type <gdb:type>]" }, | |
1470 | ||
72e02483 PA |
1471 | { "value-optimized-out?", 1, 0, 0, |
1472 | as_a_scm_t_subr (gdbscm_value_optimized_out_p), | |
ed3ef339 DE |
1473 | "\ |
1474 | Return #t if the value has been optimizd out." }, | |
1475 | ||
72e02483 | 1476 | { "value-address", 1, 0, 0, as_a_scm_t_subr (gdbscm_value_address), |
ed3ef339 DE |
1477 | "\ |
1478 | Return the address of the value." }, | |
1479 | ||
72e02483 | 1480 | { "value-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_value_type), |
ed3ef339 DE |
1481 | "\ |
1482 | Return the type of the value." }, | |
1483 | ||
72e02483 | 1484 | { "value-dynamic-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_value_dynamic_type), |
ed3ef339 DE |
1485 | "\ |
1486 | Return the dynamic type of the value." }, | |
1487 | ||
72e02483 | 1488 | { "value-cast", 2, 0, 0, as_a_scm_t_subr (gdbscm_value_cast), |
ed3ef339 DE |
1489 | "\ |
1490 | Cast the value to the supplied type.\n\ | |
1491 | \n\ | |
1492 | Arguments: <gdb:value> <gdb:type>" }, | |
1493 | ||
72e02483 | 1494 | { "value-dynamic-cast", 2, 0, 0, as_a_scm_t_subr (gdbscm_value_dynamic_cast), |
ed3ef339 DE |
1495 | "\ |
1496 | Cast the value to the supplied type, as if by the C++\n\ | |
1497 | dynamic_cast operator.\n\ | |
1498 | \n\ | |
1499 | Arguments: <gdb:value> <gdb:type>" }, | |
1500 | ||
72e02483 PA |
1501 | { "value-reinterpret-cast", 2, 0, 0, |
1502 | as_a_scm_t_subr (gdbscm_value_reinterpret_cast), | |
ed3ef339 DE |
1503 | "\ |
1504 | Cast the value to the supplied type, as if by the C++\n\ | |
1505 | reinterpret_cast operator.\n\ | |
1506 | \n\ | |
1507 | Arguments: <gdb:value> <gdb:type>" }, | |
1508 | ||
72e02483 | 1509 | { "value-dereference", 1, 0, 0, as_a_scm_t_subr (gdbscm_value_dereference), |
ed3ef339 DE |
1510 | "\ |
1511 | Return the result of applying the C unary * operator to the value." }, | |
1512 | ||
72e02483 PA |
1513 | { "value-referenced-value", 1, 0, 0, |
1514 | as_a_scm_t_subr (gdbscm_value_referenced_value), | |
ed3ef339 DE |
1515 | "\ |
1516 | Given a value of a reference type, return the value referenced.\n\ | |
1517 | The difference between this function and value-dereference is that\n\ | |
1518 | the latter applies * unary operator to a value, which need not always\n\ | |
1519 | result in the value referenced.\n\ | |
1520 | For example, for a value which is a reference to an 'int' pointer ('int *'),\n\ | |
1521 | value-dereference will result in a value of type 'int' while\n\ | |
1522 | value-referenced-value will result in a value of type 'int *'." }, | |
1523 | ||
72e02483 | 1524 | { "value-field", 2, 0, 0, as_a_scm_t_subr (gdbscm_value_field), |
ed3ef339 DE |
1525 | "\ |
1526 | Return the specified field of the value.\n\ | |
1527 | \n\ | |
1528 | Arguments: <gdb:value> string" }, | |
1529 | ||
72e02483 | 1530 | { "value-subscript", 2, 0, 0, as_a_scm_t_subr (gdbscm_value_subscript), |
ed3ef339 DE |
1531 | "\ |
1532 | Return the value of the array at the specified index.\n\ | |
1533 | \n\ | |
1534 | Arguments: <gdb:value> integer" }, | |
1535 | ||
72e02483 | 1536 | { "value-call", 2, 0, 0, as_a_scm_t_subr (gdbscm_value_call), |
ed3ef339 DE |
1537 | "\ |
1538 | Perform an inferior function call taking the value as a pointer to the\n\ | |
1539 | function to call.\n\ | |
1540 | Each element of the argument list must be a <gdb:value> object or an object\n\ | |
1541 | that can be converted to one.\n\ | |
1542 | The result is the value returned by the function.\n\ | |
1543 | \n\ | |
1544 | Arguments: <gdb:value> arg-list" }, | |
1545 | ||
72e02483 | 1546 | { "value->bool", 1, 0, 0, as_a_scm_t_subr (gdbscm_value_to_bool), |
ed3ef339 DE |
1547 | "\ |
1548 | Return the Scheme boolean representing the GDB value.\n\ | |
1549 | The value must be \"integer like\". Pointers are ok." }, | |
1550 | ||
72e02483 | 1551 | { "value->integer", 1, 0, 0, as_a_scm_t_subr (gdbscm_value_to_integer), |
ed3ef339 DE |
1552 | "\ |
1553 | Return the Scheme integer representing the GDB value.\n\ | |
1554 | The value must be \"integer like\". Pointers are ok." }, | |
1555 | ||
72e02483 | 1556 | { "value->real", 1, 0, 0, as_a_scm_t_subr (gdbscm_value_to_real), |
ed3ef339 DE |
1557 | "\ |
1558 | Return the Scheme real number representing the GDB value.\n\ | |
1559 | The value must be a number." }, | |
1560 | ||
72e02483 | 1561 | { "value->bytevector", 1, 0, 0, as_a_scm_t_subr (gdbscm_value_to_bytevector), |
ed3ef339 DE |
1562 | "\ |
1563 | Return a Scheme bytevector with the raw contents of the GDB value.\n\ | |
1564 | No transformation, endian or otherwise, is performed." }, | |
1565 | ||
72e02483 | 1566 | { "value->string", 1, 0, 1, as_a_scm_t_subr (gdbscm_value_to_string), |
ed3ef339 DE |
1567 | "\ |
1568 | Return the Unicode string of the value's contents.\n\ | |
1569 | If ENCODING is not given, the string is assumed to be encoded in\n\ | |
1570 | the target's charset.\n\ | |
1571 | An error setting \"error\" causes an exception to be thrown if there's\n\ | |
1572 | a decoding error. An error setting of \"substitute\" causes invalid\n\ | |
1573 | characters to be replaced with \"?\". The default is \"error\".\n\ | |
1574 | If LENGTH is provided, only fetch string to the length provided.\n\ | |
1575 | \n\ | |
1576 | Arguments: <gdb:value>\n\ | |
1577 | [#:encoding encoding] [#:errors \"error\"|\"substitute\"]\n\ | |
1578 | [#:length length]" }, | |
1579 | ||
72e02483 PA |
1580 | { "value->lazy-string", 1, 0, 1, |
1581 | as_a_scm_t_subr (gdbscm_value_to_lazy_string), | |
ed3ef339 DE |
1582 | "\ |
1583 | Return a Scheme object representing a lazily fetched Unicode string\n\ | |
1584 | of the value's contents.\n\ | |
1585 | If ENCODING is not given, the string is assumed to be encoded in\n\ | |
1586 | the target's charset.\n\ | |
1587 | If LENGTH is provided, only fetch string to the length provided.\n\ | |
1588 | \n\ | |
1589 | Arguments: <gdb:value> [#:encoding encoding] [#:length length]" }, | |
1590 | ||
72e02483 | 1591 | { "value-lazy?", 1, 0, 0, as_a_scm_t_subr (gdbscm_value_lazy_p), |
ed3ef339 DE |
1592 | "\ |
1593 | Return #t if the value is lazy (not fetched yet from the inferior).\n\ | |
1594 | A lazy value is fetched when needed, or when the value-fetch-lazy! function\n\ | |
1595 | is called." }, | |
1596 | ||
72e02483 | 1597 | { "make-lazy-value", 2, 0, 0, as_a_scm_t_subr (gdbscm_make_lazy_value), |
ed3ef339 DE |
1598 | "\ |
1599 | Create a <gdb:value> that will be lazily fetched from the target.\n\ | |
1600 | \n\ | |
1601 | Arguments: <gdb:type> address" }, | |
1602 | ||
72e02483 | 1603 | { "value-fetch-lazy!", 1, 0, 0, as_a_scm_t_subr (gdbscm_value_fetch_lazy_x), |
ed3ef339 DE |
1604 | "\ |
1605 | Fetch the value from the inferior, if it was lazy.\n\ | |
1606 | The result is \"unspecified\"." }, | |
1607 | ||
72e02483 | 1608 | { "value-print", 1, 0, 0, as_a_scm_t_subr (gdbscm_value_print), |
ed3ef339 DE |
1609 | "\ |
1610 | Return the string representation (print form) of the value." }, | |
1611 | ||
72e02483 | 1612 | { "parse-and-eval", 1, 0, 0, as_a_scm_t_subr (gdbscm_parse_and_eval), |
ed3ef339 DE |
1613 | "\ |
1614 | Evaluates string in gdb and returns the result as a <gdb:value> object." }, | |
1615 | ||
72e02483 | 1616 | { "history-ref", 1, 0, 0, as_a_scm_t_subr (gdbscm_history_ref), |
ed3ef339 DE |
1617 | "\ |
1618 | Return the specified value from GDB's value history." }, | |
1619 | ||
72e02483 | 1620 | { "history-append!", 1, 0, 0, as_a_scm_t_subr (gdbscm_history_append_x), |
7a5a839f LC |
1621 | "\ |
1622 | Append the specified value onto GDB's value history." }, | |
1623 | ||
ed3ef339 DE |
1624 | END_FUNCTIONS |
1625 | }; | |
1626 | ||
1627 | void | |
1628 | gdbscm_initialize_values (void) | |
1629 | { | |
1630 | value_smob_tag = gdbscm_make_smob_type (value_smob_name, | |
1631 | sizeof (value_smob)); | |
ed3ef339 DE |
1632 | scm_set_smob_free (value_smob_tag, vlscm_free_value_smob); |
1633 | scm_set_smob_print (value_smob_tag, vlscm_print_value_smob); | |
1634 | scm_set_smob_equalp (value_smob_tag, vlscm_equal_p_value_smob); | |
1635 | ||
1636 | gdbscm_define_functions (value_functions, 1); | |
1637 | ||
1638 | type_keyword = scm_from_latin1_keyword ("type"); | |
1639 | encoding_keyword = scm_from_latin1_keyword ("encoding"); | |
1640 | errors_keyword = scm_from_latin1_keyword ("errors"); | |
1641 | length_keyword = scm_from_latin1_keyword ("length"); | |
1642 | ||
1643 | error_symbol = scm_from_latin1_symbol ("error"); | |
1644 | escape_symbol = scm_from_latin1_symbol ("escape"); | |
1645 | substitute_symbol = scm_from_latin1_symbol ("substitute"); | |
1646 | } |