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