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