GDB (xrefs)
Loading...
Searching...
No Matches
scm-frame.c
Go to the documentation of this file.
1/* Scheme interface to stack frames.
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 "block.h"
25#include "frame.h"
26#include "inferior.h"
27#include "objfiles.h"
28#include "symfile.h"
29#include "symtab.h"
30#include "stack.h"
31#include "user-regs.h"
32#include "value.h"
33#include "guile-internal.h"
34
35/* The <gdb:frame> smob. */
36
38{
39 /* This always appears first. */
41
44
45 /* Frames are tracked by inferior.
46 We need some place to put the eq?-able hash table, and this feels as
47 good a place as any. Frames in one inferior shouldn't be considered
48 equal to frames in a different inferior. The frame becomes invalid if
49 this becomes NULL (the inferior has been deleted from gdb).
50 It's easier to relax restrictions than impose them after the fact.
51 N.B. It is an outstanding question whether a frame survives reruns of
52 the inferior. Intuitively the answer is "No", but currently a frame
53 also survives, e.g., multiple invocations of the same function from
54 the same point. Even different threads can have the same frame, e.g.,
55 if a thread dies and a new thread gets the same stack. */
57
58 /* Marks that the FRAME_ID member actually holds the ID of the frame next
59 to this, and not this frame's ID itself. This is a hack to permit Scheme
60 frame objects which represent invalid frames (i.e., the last frame_info
61 in a corrupt stack). The problem arises from the fact that this code
62 relies on FRAME_ID to uniquely identify a frame, which is not always true
63 for the last "frame" in a corrupt stack (it can have a null ID, or the
64 same ID as the previous frame). Whenever get_prev_frame returns NULL, we
65 record the frame_id of the next frame and set FRAME_ID_IS_NEXT to 1. */
67};
68
69static const char frame_smob_name[] = "gdb:frame";
70
71/* The tag Guile knows the frame smob by. */
72static scm_t_bits frame_smob_tag;
73
74/* Keywords used in argument passing. */
75static SCM block_keyword;
76
77/* This is called when an inferior is about to be freed.
78 Invalidate the frame as further actions on the frame could result
79 in bad data. All access to the frame should be gated by
80 frscm_get_frame_smob_arg_unsafe which will raise an exception on
81 invalid frames. */
83{
84 /* Helper function for frscm_del_inferior_frames to mark the frame
85 as invalid. */
86
87 static int
88 frscm_mark_frame_invalid (void **slot, void *info)
89 {
90 frame_smob *f_smob = (frame_smob *) *slot;
91
92 f_smob->inferior = NULL;
93 return 1;
94 }
95
96 void operator() (htab_t htab)
97 {
98 gdb_assert (htab != nullptr);
99 htab_traverse_noresize (htab, frscm_mark_frame_invalid, NULL);
100 htab_delete (htab);
101 }
102};
103
104static const registry<inferior>::key<htab, frscm_deleter>
106
107/* Administrivia for frame smobs. */
108
109/* Helper function to hash a frame_smob. */
110
111static hashval_t
113{
114 const frame_smob *f_smob = (const frame_smob *) p;
115 const struct frame_id *fid = &f_smob->frame_id;
116 hashval_t hash = htab_hash_pointer (f_smob->inferior);
117
118 if (fid->stack_status == FID_STACK_VALID)
119 hash = iterative_hash (&fid->stack_addr, sizeof (fid->stack_addr), hash);
120 if (fid->code_addr_p)
121 hash = iterative_hash (&fid->code_addr, sizeof (fid->code_addr), hash);
122 if (fid->special_addr_p)
123 hash = iterative_hash (&fid->special_addr, sizeof (fid->special_addr),
124 hash);
125
126 return hash;
127}
128
129/* Helper function to compute equality of frame_smobs. */
130
131static int
132frscm_eq_frame_smob (const void *ap, const void *bp)
133{
134 const frame_smob *a = (const frame_smob *) ap;
135 const frame_smob *b = (const frame_smob *) bp;
136
137 return (a->frame_id == b->frame_id
138 && a->inferior == b->inferior
139 && a->inferior != NULL);
140}
141
142/* Return the frame -> SCM mapping table.
143 It is created if necessary. */
144
145static htab_t
147{
148 htab_t htab = frscm_inferior_data_key.get (inferior);
149
150 if (htab == NULL)
151 {
155 }
156
157 return htab;
158}
159
160/* The smob "free" function for <gdb:frame>. */
161
162static size_t
164{
165 frame_smob *f_smob = (frame_smob *) SCM_SMOB_DATA (self);
166
167 if (f_smob->inferior != NULL)
168 {
169 htab_t htab = frscm_inferior_frame_map (f_smob->inferior);
170
172 }
173
174 /* Not necessary, done to catch bugs. */
175 f_smob->inferior = NULL;
176
177 return 0;
178}
179
180/* The smob "print" function for <gdb:frame>. */
181
182static int
183frscm_print_frame_smob (SCM self, SCM port, scm_print_state *pstate)
184{
185 frame_smob *f_smob = (frame_smob *) SCM_SMOB_DATA (self);
186
187 gdbscm_printf (port, "#<%s %s>",
189 f_smob->frame_id.to_string ().c_str ());
190 scm_remember_upto_here_1 (self);
191
192 /* Non-zero means success. */
193 return 1;
194}
195
196/* Low level routine to create a <gdb:frame> object. */
197
198static SCM
200{
201 frame_smob *f_smob = (frame_smob *)
202 scm_gc_malloc (sizeof (frame_smob), frame_smob_name);
203 SCM f_scm;
204
205 f_smob->frame_id = null_frame_id;
206 f_smob->gdbarch = NULL;
207 f_smob->inferior = NULL;
208 f_smob->frame_id_is_next = 0;
209 f_scm = scm_new_smob (frame_smob_tag, (scm_t_bits) f_smob);
210 gdbscm_init_eqable_gsmob (&f_smob->base, f_scm);
211
212 return f_scm;
213}
214
215/* Return non-zero if SCM is a <gdb:frame> object. */
216
217int
219{
220 return SCM_SMOB_PREDICATE (frame_smob_tag, scm);
221}
222
223/* (frame? object) -> boolean */
224
225static SCM
227{
228 return scm_from_bool (frscm_is_frame (scm));
229}
230
231/* Create a new <gdb:frame> object that encapsulates FRAME.
232 Returns a <gdb:exception> object if there is an error. */
233
234static SCM
236{
237 frame_smob *f_smob, f_smob_for_lookup;
238 SCM f_scm;
239 htab_t htab;
240 eqable_gdb_smob **slot;
242 struct gdbarch *gdbarch = NULL;
243 int frame_id_is_next = 0;
244
245 /* If we've already created a gsmob for this frame, return it.
246 This makes frames eq?-able. */
248 f_smob_for_lookup.frame_id = get_frame_id (frame_info_ptr (frame));
249 f_smob_for_lookup.inferior = inferior;
250 slot = gdbscm_find_eqable_gsmob_ptr_slot (htab, &f_smob_for_lookup.base);
251 if (*slot != NULL)
252 return (*slot)->containing_scm;
253
254 try
255 {
256 frame_info_ptr frame_ptr (frame);
257
258 /* Try to get the previous frame, to determine if this is the last frame
259 in a corrupt stack. If so, we need to store the frame_id of the next
260 frame and not of this one (which is possibly invalid). */
261 if (get_prev_frame (frame_ptr) == NULL
262 && get_frame_unwind_stop_reason (frame_ptr) != UNWIND_NO_REASON
263 && get_next_frame (frame_ptr) != NULL)
264 {
265 frame_id = get_frame_id (get_next_frame (frame_ptr));
266 frame_id_is_next = 1;
267 }
268 else
269 {
270 frame_id = get_frame_id (frame_ptr);
271 frame_id_is_next = 0;
272 }
273 gdbarch = get_frame_arch (frame_ptr);
274 }
275 catch (const gdb_exception &except)
276 {
277 return gdbscm_scm_from_gdb_exception (unpack (except));
278 }
279
280 f_scm = frscm_make_frame_smob ();
281 f_smob = (frame_smob *) SCM_SMOB_DATA (f_scm);
282 f_smob->frame_id = frame_id;
283 f_smob->gdbarch = gdbarch;
284 f_smob->inferior = inferior;
285 f_smob->frame_id_is_next = frame_id_is_next;
286
288
289 return f_scm;
290}
291
292/* Create a new <gdb:frame> object that encapsulates FRAME.
293 A Scheme exception is thrown if there is an error. */
294
295static SCM
297 struct inferior *inferior)
298{
299 SCM f_scm = frscm_scm_from_frame (frame, inferior);
300
301 if (gdbscm_is_exception (f_scm))
302 gdbscm_throw (f_scm);
303
304 return f_scm;
305}
306
307/* Returns the <gdb:frame> object in SELF.
308 Throws an exception if SELF is not a <gdb:frame> object. */
309
310static SCM
311frscm_get_frame_arg_unsafe (SCM self, int arg_pos, const char *func_name)
312{
313 SCM_ASSERT_TYPE (frscm_is_frame (self), self, arg_pos, func_name,
315
316 return self;
317}
318
319/* There is no gdbscm_scm_to_frame function because translating
320 a frame SCM object to a struct frame_info * can throw a GDB error.
321 Thus code working with frames has to handle both Scheme errors (e.g., the
322 object is not a frame) and GDB errors (e.g., the frame lookup failed).
323
324 To help keep things clear we split what would be gdbscm_scm_to_frame
325 into two:
326
327 frscm_get_frame_smob_arg_unsafe
328 - throws a Scheme error if object is not a frame,
329 or if the inferior is gone or is no longer current
330
331 frscm_frame_smob_to_frame
332 - may throw a gdb error if the conversion fails
333 - it's not clear when it will and won't throw a GDB error,
334 but for robustness' sake we assume that whenever we call out to GDB
335 a GDB error may get thrown (and thus the call must be wrapped in a
336 TRY_CATCH) */
337
338/* Returns the frame_smob for the object wrapped by FRAME_SCM.
339 A Scheme error is thrown if FRAME_SCM is not a frame. */
340
342frscm_get_frame_smob_arg_unsafe (SCM self, int arg_pos, const char *func_name)
343{
344 SCM f_scm = frscm_get_frame_arg_unsafe (self, arg_pos, func_name);
345 frame_smob *f_smob = (frame_smob *) SCM_SMOB_DATA (f_scm);
346
347 if (f_smob->inferior == NULL)
348 {
349 gdbscm_invalid_object_error (func_name, arg_pos, self,
350 _("inferior"));
351 }
352 if (f_smob->inferior != current_inferior ())
353 scm_misc_error (func_name, _("inferior has changed"), SCM_EOL);
354
355 return f_smob;
356}
357
358/* Returns the frame_info object wrapped by F_SMOB.
359 If the frame doesn't exist anymore (the frame id doesn't
360 correspond to any frame in the inferior), returns NULL.
361 This function calls GDB routines, so don't assume a GDB error will
362 not be thrown. */
363
364struct frame_info_ptr
366{
367 frame_info_ptr frame = frame_find_by_id (f_smob->frame_id);
368 if (frame == NULL)
369 return NULL;
370
371 if (f_smob->frame_id_is_next)
372 frame = get_prev_frame (frame);
373
374 return frame;
375}
376
377
378/* Frame methods. */
379
380/* (frame-valid? <gdb:frame>) -> bool
381 Returns #t if the frame corresponding to the frame_id of this
382 object still exists in the inferior. */
383
384static SCM
386{
387 frame_smob *f_smob;
388 bool result = false;
389
390 f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
391
393 try
394 {
396 result = frame != nullptr;
397 }
398 catch (const gdb_exception &except)
399 {
400 exc = unpack (except);
401 }
402
404 return scm_from_bool (result);
405}
406
407/* (frame-name <gdb:frame>) -> string
408 Returns the name of the function corresponding to this frame,
409 or #f if there is no function. */
410
411static SCM
413{
414 frame_smob *f_smob;
415 gdb::unique_xmalloc_ptr<char> name;
416 enum language lang = language_minimal;
417 bool found = false;
418 SCM result;
419
420 f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
421
423 try
424 {
426 if (frame != NULL)
427 {
428 found = true;
429 name = find_frame_funname (frame, &lang, NULL);
430 }
431 }
432 catch (const gdb_exception &except)
433 {
434 exc = unpack (except);
435 }
436
438 if (!found)
439 {
440 gdbscm_invalid_object_error (FUNC_NAME, SCM_ARG1, self,
441 _("<gdb:frame>"));
442 }
443
444 if (name != NULL)
445 result = gdbscm_scm_from_c_string (name.get ());
446 else
447 result = SCM_BOOL_F;
448
449 return result;
450}
451
452/* (frame-type <gdb:frame>) -> integer
453 Returns the frame type, namely one of the gdb:*_FRAME constants. */
454
455static SCM
457{
458 frame_smob *f_smob;
460 bool found = false;
461
462 f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
463
465 try
466 {
468 if (frame != NULL)
469 {
470 found = true;
471 type = get_frame_type (frame);
472 }
473 }
474 catch (const gdb_exception &except)
475 {
476 exc = unpack (except);
477 }
478
480 if (!found)
481 {
482 gdbscm_invalid_object_error (FUNC_NAME, SCM_ARG1, self,
483 _("<gdb:frame>"));
484 }
485
486 return scm_from_int (type);
487}
488
489/* (frame-arch <gdb:frame>) -> <gdb:architecture>
490 Returns the frame's architecture as a gdb:architecture object. */
491
492static SCM
494{
495 frame_smob *f_smob;
496 bool found = false;
497
498 f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
499
501 try
502 {
504 found = frame != nullptr;
505 }
506 catch (const gdb_exception &except)
507 {
508 exc = unpack (except);
509 }
510
512 if (!found)
513 {
514 gdbscm_invalid_object_error (FUNC_NAME, SCM_ARG1, self,
515 _("<gdb:frame>"));
516 }
517
518 return arscm_scm_from_arch (f_smob->gdbarch);
519}
520
521/* (frame-unwind-stop-reason <gdb:frame>) -> integer
522 Returns one of the gdb:FRAME_UNWIND_* constants. */
523
524static SCM
526{
527 frame_smob *f_smob;
528 bool found = false;
529 enum unwind_stop_reason stop_reason = UNWIND_NO_REASON;
530
531 f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
532
534 try
535 {
537 if (frame != nullptr)
538 {
539 found = true;
540 stop_reason = get_frame_unwind_stop_reason (frame);
541 }
542 }
543 catch (const gdb_exception &except)
544 {
545 exc = unpack (except);
546 }
547
549 if (!found)
550 {
551 gdbscm_invalid_object_error (FUNC_NAME, SCM_ARG1, self,
552 _("<gdb:frame>"));
553 }
554
555 return scm_from_int (stop_reason);
556}
557
558/* (frame-pc <gdb:frame>) -> integer
559 Returns the frame's resume address. */
560
561static SCM
563{
564 frame_smob *f_smob;
565 CORE_ADDR pc = 0;
566 bool found = false;
567
568 f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
569
571 try
572 {
574 if (frame != NULL)
575 {
576 pc = get_frame_pc (frame);
577 found = true;
578 }
579 }
580 catch (const gdb_exception &except)
581 {
582 exc = unpack (except);
583 }
584
586 if (!found)
587 {
588 gdbscm_invalid_object_error (FUNC_NAME, SCM_ARG1, self,
589 _("<gdb:frame>"));
590 }
591
592 return gdbscm_scm_from_ulongest (pc);
593}
594
595/* (frame-block <gdb:frame>) -> <gdb:block>
596 Returns the frame's code block, or #f if one cannot be found. */
597
598static SCM
600{
601 frame_smob *f_smob;
602 const struct block *block = NULL, *fn_block;
603 bool found = false;
604
605 f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
606
608 try
609 {
611 if (frame != NULL)
612 {
613 found = true;
614 block = get_frame_block (frame, NULL);
615 }
616 }
617 catch (const gdb_exception &except)
618 {
619 exc = unpack (except);
620 }
621
623 if (!found)
624 {
625 gdbscm_invalid_object_error (FUNC_NAME, SCM_ARG1, self,
626 _("<gdb:frame>"));
627 }
628
629 for (fn_block = block;
630 fn_block != NULL && fn_block->function () == NULL;
631 fn_block = fn_block->superblock ())
632 continue;
633
634 if (block == NULL || fn_block == NULL || fn_block->function () == NULL)
635 {
636 scm_misc_error (FUNC_NAME, _("cannot find block for frame"),
637 scm_list_1 (self));
638 }
639
640 if (block != NULL)
641 {
643 (block, fn_block->function ()->objfile ());
644 }
645
646 return SCM_BOOL_F;
647}
648
649/* (frame-function <gdb:frame>) -> <gdb:symbol>
650 Returns the symbol for the function corresponding to this frame,
651 or #f if there isn't one. */
652
653static SCM
655{
656 frame_smob *f_smob;
657 struct symbol *sym = NULL;
658 bool found = false;
659
660 f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
661
663 try
664 {
666 if (frame != NULL)
667 {
668 found = true;
670 }
671 }
672 catch (const gdb_exception &except)
673 {
674 exc = unpack (except);
675 }
676
678 if (!found)
679 {
680 gdbscm_invalid_object_error (FUNC_NAME, SCM_ARG1, self,
681 _("<gdb:frame>"));
682 }
683
684 if (sym != NULL)
685 return syscm_scm_from_symbol (sym);
686
687 return SCM_BOOL_F;
688}
689
690/* (frame-older <gdb:frame>) -> <gdb:frame>
691 Returns the frame immediately older (outer) to this frame,
692 or #f if there isn't one. */
693
694static SCM
696{
697 frame_smob *f_smob;
698 struct frame_info *prev = NULL;
699 bool found = false;
700
701 f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
702
704 try
705 {
707 if (frame != NULL)
708 {
709 found = true;
710 prev = get_prev_frame (frame).get ();
711 }
712 }
713 catch (const gdb_exception &except)
714 {
715 exc = unpack (except);
716 }
717
719 if (!found)
720 {
721 gdbscm_invalid_object_error (FUNC_NAME, SCM_ARG1, self,
722 _("<gdb:frame>"));
723 }
724
725 if (prev != NULL)
726 return frscm_scm_from_frame_unsafe (prev, f_smob->inferior);
727
728 return SCM_BOOL_F;
729}
730
731/* (frame-newer <gdb:frame>) -> <gdb:frame>
732 Returns the frame immediately newer (inner) to this frame,
733 or #f if there isn't one. */
734
735static SCM
737{
738 frame_smob *f_smob;
739 struct frame_info *next = NULL;
740 bool found = false;
741
742 f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
743
745 try
746 {
748 if (frame != NULL)
749 {
750 found = true;
751 next = get_next_frame (frame).get ();
752 }
753 }
754 catch (const gdb_exception &except)
755 {
756 exc = unpack (except);
757 }
758
760 if (!found)
761 {
762 gdbscm_invalid_object_error (FUNC_NAME, SCM_ARG1, self,
763 _("<gdb:frame>"));
764 }
765
766 if (next != NULL)
767 return frscm_scm_from_frame_unsafe (next, f_smob->inferior);
768
769 return SCM_BOOL_F;
770}
771
772/* (frame-sal <gdb:frame>) -> <gdb:sal>
773 Returns the frame's symtab and line. */
774
775static SCM
777{
778 frame_smob *f_smob;
779 struct symtab_and_line sal;
780 bool found = false;
781
782 f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
783
785 try
786 {
788 if (frame != NULL)
789 {
790 found = true;
791 sal = find_frame_sal (frame);
792 }
793 }
794 catch (const gdb_exception &except)
795 {
796 exc = unpack (except);
797 }
798
800 if (!found)
801 {
802 gdbscm_invalid_object_error (FUNC_NAME, SCM_ARG1, self,
803 _("<gdb:frame>"));
804 }
805
806 return stscm_scm_from_sal (sal);
807}
808
809/* (frame-read-register <gdb:frame> string) -> <gdb:value>
810 The register argument must be a string. */
811
812static SCM
813gdbscm_frame_read_register (SCM self, SCM register_scm)
814{
815 char *register_str;
816 struct value *value = NULL;
817 bool found = false;
818 frame_smob *f_smob;
819
820 f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
821 gdbscm_parse_function_args (FUNC_NAME, SCM_ARG2, NULL, "s",
822 register_scm, &register_str);
823
824 gdbscm_gdb_exception except {};
825
826 try
827 {
828 int regnum;
829
831 if (frame)
832 {
833 found = true;
835 register_str,
836 strlen (register_str));
837 if (regnum >= 0)
838 value = value_of_register (regnum, frame);
839 }
840 }
841 catch (const gdb_exception &ex)
842 {
843 except = unpack (ex);
844 }
845
846 xfree (register_str);
848
849 if (!found)
850 {
851 gdbscm_invalid_object_error (FUNC_NAME, SCM_ARG1, self,
852 _("<gdb:frame>"));
853 }
854
855 if (value == NULL)
856 {
857 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG2, register_scm,
858 _("unknown register"));
859 }
860
862}
863
864/* (frame-read-var <gdb:frame> <gdb:symbol>) -> <gdb:value>
865 (frame-read-var <gdb:frame> string [#:block <gdb:block>]) -> <gdb:value>
866 If the optional block argument is provided start the search from that block,
867 otherwise search from the frame's current block (determined by examining
868 the resume address of the frame). The variable argument must be a string
869 or an instance of a <gdb:symbol>. The block argument must be an instance of
870 <gdb:block>. */
871
872static SCM
873gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
874{
875 SCM keywords[] = { block_keyword, SCM_BOOL_F };
876 frame_smob *f_smob;
877 int block_arg_pos = -1;
878 SCM block_scm = SCM_UNDEFINED;
879 struct frame_info *frame = NULL;
880 struct symbol *var = NULL;
881 const struct block *block = NULL;
882 struct value *value = NULL;
883
884 f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
885
887 try
888 {
889 frame = frscm_frame_smob_to_frame (f_smob).get ();
890 }
891 catch (const gdb_exception &except)
892 {
893 exc = unpack (except);
894 }
895
897 if (frame == NULL)
898 {
899 gdbscm_invalid_object_error (FUNC_NAME, SCM_ARG1, self,
900 _("<gdb:frame>"));
901 }
902
903 gdbscm_parse_function_args (FUNC_NAME, SCM_ARG3, keywords, "#O",
904 rest, &block_arg_pos, &block_scm);
905
906 if (syscm_is_symbol (symbol_scm))
907 {
908 var = syscm_get_valid_symbol_arg_unsafe (symbol_scm, SCM_ARG2,
909 FUNC_NAME);
910 SCM_ASSERT (SCM_UNBNDP (block_scm), block_scm, SCM_ARG3, FUNC_NAME);
911 }
912 else if (scm_is_string (symbol_scm))
913 {
914 gdbscm_gdb_exception except {};
915
916 if (! SCM_UNBNDP (block_scm))
917 {
918 SCM except_scm;
919
920 gdb_assert (block_arg_pos > 0);
921 block = bkscm_scm_to_block (block_scm, block_arg_pos, FUNC_NAME,
922 &except_scm);
923 if (block == NULL)
924 gdbscm_throw (except_scm);
925 }
926
927 {
928 gdb::unique_xmalloc_ptr<char> var_name
929 (gdbscm_scm_to_c_string (symbol_scm));
930 /* N.B. Between here and the end of the scope, don't do anything
931 to cause a Scheme exception. */
932
933 try
934 {
935 struct block_symbol lookup_sym;
936
937 if (block == NULL)
938 block = get_frame_block (frame_info_ptr (frame), NULL);
939 lookup_sym = lookup_symbol (var_name.get (), block, VAR_DOMAIN,
940 NULL);
941 var = lookup_sym.symbol;
942 block = lookup_sym.block;
943 }
944 catch (const gdb_exception &ex)
945 {
946 except = unpack (ex);
947 }
948 }
949
951
952 if (var == NULL)
953 gdbscm_out_of_range_error (FUNC_NAME, 0, symbol_scm,
954 _("variable not found"));
955 }
956 else
957 {
958 /* Use SCM_ASSERT_TYPE for more consistent error messages. */
959 SCM_ASSERT_TYPE (0, symbol_scm, SCM_ARG1, FUNC_NAME,
960 _("gdb:symbol or string"));
961 }
962
963 try
964 {
965 value = read_var_value (var, block, frame_info_ptr (frame));
966 }
967 catch (const gdb_exception &except)
968 {
969 exc = unpack (except);
970 }
971
974}
975
976/* (frame-select <gdb:frame>) -> unspecified
977 Select this frame. */
978
979static SCM
981{
982 frame_smob *f_smob;
983 bool found = false;
984
985 f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
986
988 try
989 {
991 if (frame != NULL)
992 {
993 found = true;
994 select_frame (frame);
995 }
996 }
997 catch (const gdb_exception &except)
998 {
999 exc = unpack (except);
1000 }
1001
1003 if (!found)
1004 {
1005 gdbscm_invalid_object_error (FUNC_NAME, SCM_ARG1, self,
1006 _("<gdb:frame>"));
1007 }
1008
1009 return SCM_UNSPECIFIED;
1010}
1011
1012/* (newest-frame) -> <gdb:frame>
1013 Returns the newest frame. */
1014
1015static SCM
1017{
1018 struct frame_info *frame = NULL;
1019
1020 gdbscm_gdb_exception exc {};
1021 try
1022 {
1023 frame = get_current_frame ().get ();
1024 }
1025 catch (const gdb_exception &except)
1026 {
1027 exc = unpack (except);
1028 }
1029
1032}
1033
1034/* (selected-frame) -> <gdb:frame>
1035 Returns the selected frame. */
1036
1037static SCM
1039{
1040 struct frame_info *frame = NULL;
1041
1042 gdbscm_gdb_exception exc {};
1043 try
1044 {
1045 frame = get_selected_frame (_("No frame is currently selected")).get ();
1046 }
1047 catch (const gdb_exception &except)
1048 {
1049 exc = unpack (except);
1050 }
1051
1054}
1055
1056/* (unwind-stop-reason-string integer) -> string
1057 Return a string explaining the unwind stop reason. */
1058
1059static SCM
1061{
1062 int reason;
1063 const char *str;
1064
1065 gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, NULL, "i",
1066 reason_scm, &reason);
1067
1068 if (reason < UNWIND_FIRST || reason > UNWIND_LAST)
1069 scm_out_of_range (FUNC_NAME, reason_scm);
1070
1072 return gdbscm_scm_from_c_string (str);
1073}
1074
1075/* Initialize the Scheme frame support. */
1076
1078{
1079#define ENTRY(X) { #X, X }
1080
1086 ENTRY (ARCH_FRAME),
1088
1089#undef ENTRY
1090
1091#define SET(name, description) \
1092 { "FRAME_" #name, name },
1093#include "unwind_stop_reasons.def"
1094#undef SET
1095
1097};
1098
1100{
1101 { "frame?", 1, 0, 0, as_a_scm_t_subr (gdbscm_frame_p),
1102 "\
1103Return #t if the object is a <gdb:frame> object." },
1104
1105 { "frame-valid?", 1, 0, 0, as_a_scm_t_subr (gdbscm_frame_valid_p),
1106 "\
1107Return #t if the object is a valid <gdb:frame> object.\n\
1108Frames become invalid when the inferior returns to its caller." },
1109
1110 { "frame-name", 1, 0, 0, as_a_scm_t_subr (gdbscm_frame_name),
1111 "\
1112Return the name of the function corresponding to this frame,\n\
1113or #f if there is no function." },
1114
1115 { "frame-arch", 1, 0, 0, as_a_scm_t_subr (gdbscm_frame_arch),
1116 "\
1117Return the frame's architecture as a <gdb:arch> object." },
1118
1119 { "frame-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_frame_type),
1120 "\
1121Return the frame type, namely one of the gdb:*_FRAME constants." },
1122
1123 { "frame-unwind-stop-reason", 1, 0, 0,
1125 "\
1126Return one of the gdb:FRAME_UNWIND_* constants explaining why\n\
1127it's not possible to find frames older than this." },
1128
1129 { "frame-pc", 1, 0, 0, as_a_scm_t_subr (gdbscm_frame_pc),
1130 "\
1131Return the frame's resume address." },
1132
1133 { "frame-block", 1, 0, 0, as_a_scm_t_subr (gdbscm_frame_block),
1134 "\
1135Return the frame's code block, or #f if one cannot be found." },
1136
1137 { "frame-function", 1, 0, 0, as_a_scm_t_subr (gdbscm_frame_function),
1138 "\
1139Return the <gdb:symbol> for the function corresponding to this frame,\n\
1140or #f if there isn't one." },
1141
1142 { "frame-older", 1, 0, 0, as_a_scm_t_subr (gdbscm_frame_older),
1143 "\
1144Return the frame immediately older (outer) to this frame,\n\
1145or #f if there isn't one." },
1146
1147 { "frame-newer", 1, 0, 0, as_a_scm_t_subr (gdbscm_frame_newer),
1148 "\
1149Return the frame immediately newer (inner) to this frame,\n\
1150or #f if there isn't one." },
1151
1152 { "frame-sal", 1, 0, 0, as_a_scm_t_subr (gdbscm_frame_sal),
1153 "\
1154Return the frame's symtab-and-line <gdb:sal> object." },
1155
1156 { "frame-read-var", 2, 0, 1, as_a_scm_t_subr (gdbscm_frame_read_var),
1157 "\
1158Return the value of the symbol in the frame.\n\
1159\n\
1160 Arguments: <gdb:frame> <gdb:symbol>\n\
1161 Or: <gdb:frame> string [#:block <gdb:block>]" },
1162
1163 { "frame-read-register", 2, 0, 0,
1165 "\
1166Return the value of the register in the frame.\n\
1167\n\
1168 Arguments: <gdb:frame> string" },
1169
1170 { "frame-select", 1, 0, 0, as_a_scm_t_subr (gdbscm_frame_select),
1171 "\
1172Select this frame." },
1173
1174 { "newest-frame", 0, 0, 0, as_a_scm_t_subr (gdbscm_newest_frame),
1175 "\
1176Return the newest frame." },
1177
1178 { "selected-frame", 0, 0, 0, as_a_scm_t_subr (gdbscm_selected_frame),
1179 "\
1180Return the selected frame." },
1181
1182 { "unwind-stop-reason-string", 1, 0, 0,
1184 "\
1185Return a string explaining the unwind stop reason.\n\
1186\n\
1187 Arguments: integer (the result of frame-unwind-stop-reason)" },
1188
1190};
1191
1192void
1194{
1197 scm_set_smob_free (frame_smob_tag, frscm_free_frame_smob);
1198 scm_set_smob_print (frame_smob_tag, frscm_print_frame_smob);
1199
1202
1203 block_keyword = scm_from_latin1_keyword ("block");
1204}
int regnum
const char *const name
static struct parser_state * pstate
Definition ada-exp.c:101
void xfree(void *)
struct symbol * find_pc_function(CORE_ADDR pc)
Definition blockframe.c:150
const struct block * get_frame_block(frame_info_ptr frame, CORE_ADDR *addr_in_block)
Definition blockframe.c:55
frame_info * get() const
Definition frame.h:294
void set(unsigned key, void *datum)
Definition registry.h:204
void * get(unsigned key)
Definition registry.h:211
language
Definition defs.h:211
@ language_minimal
Definition defs.h:224
struct value * value_of_register(int regnum, frame_info_ptr frame)
Definition findvar.c:253
struct value * read_var_value(struct symbol *var, const struct block *var_block, frame_info_ptr frame)
Definition findvar.c:739
const struct frame_id null_frame_id
Definition frame.c:688
@ FID_STACK_VALID
Definition frame-id.h:31
frame_info_ptr get_next_frame(frame_info_ptr this_frame)
Definition frame.c:2068
enum unwind_stop_reason get_frame_unwind_stop_reason(frame_info_ptr frame)
Definition frame.c:3166
void select_frame(frame_info_ptr fi)
Definition frame.c:1927
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2712
const char * unwind_stop_reason_to_string(enum unwind_stop_reason reason)
Definition frame.c:3178
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
Definition frame.c:3027
enum frame_type get_frame_type(frame_info_ptr frame)
Definition frame.c:2955
frame_info_ptr get_selected_frame(const char *message)
Definition frame.c:1888
frame_info_ptr frame_find_by_id(struct frame_id id)
Definition frame.c:916
frame_info_ptr get_current_frame(void)
Definition frame.c:1670
CORE_ADDR get_frame_address_in_block(frame_info_ptr this_frame)
Definition frame.c:2742
struct frame_id get_frame_id(frame_info_ptr fi)
Definition frame.c:631
frame_info_ptr get_prev_frame(frame_info_ptr this_frame)
Definition frame.c:2614
symtab_and_line find_frame_sal(frame_info_ptr frame)
Definition frame.c:2821
frame_type
Definition frame.h:184
@ ARCH_FRAME
Definition frame.h:200
@ DUMMY_FRAME
Definition frame.h:190
@ TAILCALL_FRAME
Definition frame.h:195
@ SIGTRAMP_FRAME
Definition frame.h:198
@ NORMAL_FRAME
Definition frame.h:187
@ SENTINEL_FRAME
Definition frame.h:203
@ INLINE_FRAME
Definition frame.h:193
unwind_stop_reason
Definition frame.h:653
void gdbscm_init_eqable_gsmob(eqable_gdb_smob *base, SCM containing_scm)
Definition scm-gsmob.c:162
int syscm_is_symbol(SCM scm)
Definition scm-symbol.c:213
#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
#define END_INTEGER_CONSTANTS
gdbscm_gdb_exception unpack(const gdb_exception &exc)
htab_t gdbscm_create_eqable_gsmob_ptr_map(htab_hash hash_fn, htab_eq eq_fn)
Definition scm-gsmob.c:213
SCM vlscm_scm_from_value(struct value *value)
Definition scm-value.c:252
SCM stscm_scm_from_sal(struct symtab_and_line sal)
Definition scm-symtab.c:444
SCM gdbscm_scm_from_gdb_exception(const gdbscm_gdb_exception &exception)
void gdbscm_invalid_object_error(const char *subr, int arg_pos, SCM bad_value, const char *error) ATTRIBUTE_NORETURN
void gdbscm_out_of_range_error(const char *subr, int arg_pos, SCM bad_value, const char *error) ATTRIBUTE_NORETURN
SCM bkscm_scm_from_block(const struct block *block, struct objfile *objfile)
Definition scm-block.c:238
void gdbscm_clear_eqable_gsmob_ptr_slot(htab_t htab, eqable_gdb_smob *base)
Definition scm-gsmob.c:251
SCM arscm_scm_from_arch(struct gdbarch *gdbarch)
Definition scm-arch.c:115
SCM gdbscm_scm_from_ulongest(ULONGEST l)
Definition scm-utils.c:565
void gdbscm_printf(SCM port, const char *format,...) ATTRIBUTE_PRINTF(2
gdb::unique_xmalloc_ptr< char > gdbscm_scm_to_c_string(SCM string)
Definition scm-string.c:55
struct symbol * syscm_get_valid_symbol_arg_unsafe(SCM self, int arg_pos, const char *func_name)
Definition scm-symbol.c:308
void gdbscm_define_integer_constants(const scheme_integer_constant *, int is_public)
Definition scm-utils.c:63
const struct block * bkscm_scm_to_block(SCM block_scm, int arg_pos, const char *func_name, SCM *excp)
Definition scm-block.c:345
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
eqable_gdb_smob ** gdbscm_find_eqable_gsmob_ptr_slot(htab_t htab, eqable_gdb_smob *base)
Definition scm-gsmob.c:226
#define GDBSCM_HANDLE_GDB_EXCEPTION(exception)
void gdbscm_fill_eqable_gsmob_ptr_slot(eqable_gdb_smob **slot, eqable_gdb_smob *base)
Definition scm-gsmob.c:237
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
SCM syscm_scm_from_symbol(struct symbol *symbol)
Definition scm-symbol.c:230
static scm_t_subr as_a_scm_t_subr(SCM(*func)(void))
#define FUNC_NAME
SCM gdbscm_scm_from_c_string(const char *string)
Definition scm-string.c:45
struct inferior * current_inferior(void)
Definition inferior.c:55
static const scheme_function frame_functions[]
Definition scm-frame.c:1099
static SCM gdbscm_unwind_stop_reason_string(SCM reason_scm)
Definition scm-frame.c:1060
static SCM frscm_scm_from_frame_unsafe(struct frame_info *frame, struct inferior *inferior)
Definition scm-frame.c:296
static SCM gdbscm_frame_p(SCM scm)
Definition scm-frame.c:226
static SCM gdbscm_frame_sal(SCM self)
Definition scm-frame.c:776
struct frame_info_ptr frscm_frame_smob_to_frame(frame_smob *f_smob)
Definition scm-frame.c:365
static SCM frscm_scm_from_frame(struct frame_info *frame, struct inferior *inferior)
Definition scm-frame.c:235
static size_t frscm_free_frame_smob(SCM self)
Definition scm-frame.c:163
static SCM gdbscm_frame_read_var(SCM self, SCM symbol_scm, SCM rest)
Definition scm-frame.c:873
static hashval_t frscm_hash_frame_smob(const void *p)
Definition scm-frame.c:112
static SCM gdbscm_frame_newer(SCM self)
Definition scm-frame.c:736
static scm_t_bits frame_smob_tag
Definition scm-frame.c:72
static int frscm_print_frame_smob(SCM self, SCM port, scm_print_state *pstate)
Definition scm-frame.c:183
static const registry< inferior >::key< htab, frscm_deleter > frscm_inferior_data_key
Definition scm-frame.c:105
static int frscm_eq_frame_smob(const void *ap, const void *bp)
Definition scm-frame.c:132
#define ENTRY(X)
static SCM gdbscm_frame_select(SCM self)
Definition scm-frame.c:980
static SCM gdbscm_frame_unwind_stop_reason(SCM self)
Definition scm-frame.c:525
static SCM block_keyword
Definition scm-frame.c:75
static const scheme_integer_constant frame_integer_constants[]
Definition scm-frame.c:1077
static SCM frscm_make_frame_smob(void)
Definition scm-frame.c:199
static SCM gdbscm_frame_pc(SCM self)
Definition scm-frame.c:562
static SCM gdbscm_frame_function(SCM self)
Definition scm-frame.c:654
static const char frame_smob_name[]
Definition scm-frame.c:69
static SCM gdbscm_selected_frame(void)
Definition scm-frame.c:1038
void gdbscm_initialize_frames(void)
Definition scm-frame.c:1193
static SCM gdbscm_frame_block(SCM self)
Definition scm-frame.c:599
frame_smob * frscm_get_frame_smob_arg_unsafe(SCM self, int arg_pos, const char *func_name)
Definition scm-frame.c:342
int frscm_is_frame(SCM scm)
Definition scm-frame.c:218
static SCM gdbscm_frame_type(SCM self)
Definition scm-frame.c:456
static htab_t frscm_inferior_frame_map(struct inferior *inferior)
Definition scm-frame.c:146
static SCM gdbscm_frame_read_register(SCM self, SCM register_scm)
Definition scm-frame.c:813
static SCM frscm_get_frame_arg_unsafe(SCM self, int arg_pos, const char *func_name)
Definition scm-frame.c:311
static SCM gdbscm_frame_older(SCM self)
Definition scm-frame.c:695
static SCM gdbscm_frame_name(SCM self)
Definition scm-frame.c:412
static SCM gdbscm_frame_valid_p(SCM self)
Definition scm-frame.c:385
static SCM gdbscm_frame_arch(SCM self)
Definition scm-frame.c:493
static SCM gdbscm_newest_frame(void)
Definition scm-frame.c:1016
gdb::unique_xmalloc_ptr< char > find_frame_funname(frame_info_ptr frame, enum language *funlang, struct symbol **funcp)
Definition stack.c:1256
const struct block * block
Definition symtab.h:1537
struct symbol * symbol
Definition symtab.h:1533
Definition block.h:109
symbol * function() const
Definition block.h:127
CORE_ADDR stack_addr
Definition frame-id.h:68
CORE_ADDR code_addr
Definition frame-id.h:83
std::string to_string() const
Definition frame.c:407
unsigned int special_addr_p
Definition frame-id.h:100
unsigned int code_addr_p
Definition frame-id.h:99
__extension__ enum frame_id_stack_status stack_status
Definition frame-id.h:98
CORE_ADDR special_addr
Definition frame-id.h:95
struct frame_info * prev
Definition frame.c:186
struct gdbarch * gdbarch
Definition scm-frame.c:43
int frame_id_is_next
Definition scm-frame.c:66
struct inferior * inferior
Definition scm-frame.c:56
eqable_gdb_smob base
Definition scm-frame.c:40
struct frame_id frame_id
Definition scm-frame.c:42
void operator()(htab_t htab)
Definition scm-frame.c:96
static int frscm_mark_frame_invalid(void **slot, void *info)
Definition scm-frame.c:88
struct objfile * objfile() const
Definition symtab.c:6482
Definition value.h:130
struct block_symbol lookup_symbol(const char *name, const struct block *block, domain_enum domain, struct field_of_this_result *is_a_field_of_this)
Definition symtab.c:1964
@ VAR_DOMAIN
Definition symtab.h:910
int user_reg_map_name_to_regnum(struct gdbarch *gdbarch, const char *name, int len)
Definition user-regs.c:132