1 /* Scheme interface to stack frames.
3 Copyright (C) 2008-2014 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 /* See README file in this directory for implementation notes, coding
21 conventions, et.al. */
32 #include "guile-internal.h"
34 /* The <gdb:frame> smob.
35 The typedef for this struct is in guile-internal.h. */
39 /* This always appears first. */
42 struct frame_id frame_id
;
43 struct gdbarch
*gdbarch
;
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. */
56 struct inferior
*inferior
;
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. */
69 static const char frame_smob_name
[] = "gdb:frame";
71 /* The tag Guile knows the frame smob by. */
72 static scm_t_bits frame_smob_tag
;
74 /* Keywords used in argument passing. */
75 static SCM block_keyword
;
77 static const struct inferior_data
*frscm_inferior_data_key
;
79 /* Administrivia for frame smobs. */
81 /* Helper function to hash a frame_smob. */
84 frscm_hash_frame_smob (const void *p
)
86 const frame_smob
*f_smob
= p
;
87 const struct frame_id
*fid
= &f_smob
->frame_id
;
88 hashval_t hash
= htab_hash_pointer (f_smob
->inferior
);
90 if (fid
->stack_status
== FID_STACK_VALID
)
91 hash
= iterative_hash (&fid
->stack_addr
, sizeof (fid
->stack_addr
), hash
);
93 hash
= iterative_hash (&fid
->code_addr
, sizeof (fid
->code_addr
), hash
);
94 if (fid
->special_addr_p
)
95 hash
= iterative_hash (&fid
->special_addr
, sizeof (fid
->special_addr
),
101 /* Helper function to compute equality of frame_smobs. */
104 frscm_eq_frame_smob (const void *ap
, const void *bp
)
106 const frame_smob
*a
= ap
;
107 const frame_smob
*b
= bp
;
109 return (frame_id_eq (a
->frame_id
, b
->frame_id
)
110 && a
->inferior
== b
->inferior
111 && a
->inferior
!= NULL
);
114 /* Return the frame -> SCM mapping table.
115 It is created if necessary. */
118 frscm_inferior_frame_map (struct inferior
*inferior
)
120 htab_t htab
= inferior_data (inferior
, frscm_inferior_data_key
);
124 htab
= gdbscm_create_eqable_gsmob_ptr_map (frscm_hash_frame_smob
,
125 frscm_eq_frame_smob
);
126 set_inferior_data (inferior
, frscm_inferior_data_key
, htab
);
132 /* The smob "free" function for <gdb:frame>. */
135 frscm_free_frame_smob (SCM self
)
137 frame_smob
*f_smob
= (frame_smob
*) SCM_SMOB_DATA (self
);
139 if (f_smob
->inferior
!= NULL
)
141 htab_t htab
= frscm_inferior_frame_map (f_smob
->inferior
);
143 gdbscm_clear_eqable_gsmob_ptr_slot (htab
, &f_smob
->base
);
146 /* Not necessary, done to catch bugs. */
147 f_smob
->inferior
= NULL
;
152 /* The smob "print" function for <gdb:frame>. */
155 frscm_print_frame_smob (SCM self
, SCM port
, scm_print_state
*pstate
)
157 frame_smob
*f_smob
= (frame_smob
*) SCM_SMOB_DATA (self
);
158 struct ui_file
*strfile
;
161 gdbscm_printf (port
, "#<%s ", frame_smob_name
);
163 strfile
= mem_fileopen ();
164 fprint_frame_id (strfile
, f_smob
->frame_id
);
165 s
= ui_file_xstrdup (strfile
, NULL
);
166 gdbscm_printf (port
, "%s", s
);
167 ui_file_delete (strfile
);
170 scm_puts (">", port
);
172 scm_remember_upto_here_1 (self
);
174 /* Non-zero means success. */
178 /* Low level routine to create a <gdb:frame> object. */
181 frscm_make_frame_smob (void)
183 frame_smob
*f_smob
= (frame_smob
*)
184 scm_gc_malloc (sizeof (frame_smob
), frame_smob_name
);
187 f_smob
->frame_id
= null_frame_id
;
188 f_smob
->gdbarch
= NULL
;
189 f_smob
->inferior
= NULL
;
190 f_smob
->frame_id_is_next
= 0;
191 f_scm
= scm_new_smob (frame_smob_tag
, (scm_t_bits
) f_smob
);
192 gdbscm_init_eqable_gsmob (&f_smob
->base
, f_scm
);
197 /* Return non-zero if SCM is a <gdb:frame> object. */
200 frscm_is_frame (SCM scm
)
202 return SCM_SMOB_PREDICATE (frame_smob_tag
, scm
);
205 /* (frame? object) -> boolean */
208 gdbscm_frame_p (SCM scm
)
210 return scm_from_bool (frscm_is_frame (scm
));
213 /* Create a new <gdb:frame> object that encapsulates FRAME.
214 Returns a <gdb:exception> object if there is an error. */
217 frscm_scm_from_frame (struct frame_info
*frame
, struct inferior
*inferior
)
219 frame_smob
*f_smob
, f_smob_for_lookup
;
222 eqable_gdb_smob
**slot
;
223 volatile struct gdb_exception except
;
224 struct frame_id frame_id
= null_frame_id
;
225 struct gdbarch
*gdbarch
= NULL
;
226 int frame_id_is_next
= 0;
228 /* If we've already created a gsmob for this frame, return it.
229 This makes frames eq?-able. */
230 htab
= frscm_inferior_frame_map (inferior
);
231 f_smob_for_lookup
.frame_id
= get_frame_id (frame
);
232 f_smob_for_lookup
.inferior
= inferior
;
233 slot
= gdbscm_find_eqable_gsmob_ptr_slot (htab
, &f_smob_for_lookup
.base
);
235 return (*slot
)->containing_scm
;
237 TRY_CATCH (except
, RETURN_MASK_ALL
)
239 /* Try to get the previous frame, to determine if this is the last frame
240 in a corrupt stack. If so, we need to store the frame_id of the next
241 frame and not of this one (which is possibly invalid). */
242 if (get_prev_frame (frame
) == NULL
243 && get_frame_unwind_stop_reason (frame
) != UNWIND_NO_REASON
244 && get_next_frame (frame
) != NULL
)
246 frame_id
= get_frame_id (get_next_frame (frame
));
247 frame_id_is_next
= 1;
251 frame_id
= get_frame_id (frame
);
252 frame_id_is_next
= 0;
254 gdbarch
= get_frame_arch (frame
);
256 if (except
.reason
< 0)
257 return gdbscm_scm_from_gdb_exception (except
);
259 f_scm
= frscm_make_frame_smob ();
260 f_smob
= (frame_smob
*) SCM_SMOB_DATA (f_scm
);
261 f_smob
->frame_id
= frame_id
;
262 f_smob
->gdbarch
= gdbarch
;
263 f_smob
->inferior
= inferior
;
264 f_smob
->frame_id_is_next
= frame_id_is_next
;
266 gdbscm_fill_eqable_gsmob_ptr_slot (slot
, &f_smob
->base
);
271 /* Create a new <gdb:frame> object that encapsulates FRAME.
272 A Scheme exception is thrown if there is an error. */
275 frscm_scm_from_frame_unsafe (struct frame_info
*frame
,
276 struct inferior
*inferior
)
278 SCM f_scm
= frscm_scm_from_frame (frame
, inferior
);
280 if (gdbscm_is_exception (f_scm
))
281 gdbscm_throw (f_scm
);
286 /* Returns the <gdb:frame> object in SELF.
287 Throws an exception if SELF is not a <gdb:frame> object. */
290 frscm_get_frame_arg_unsafe (SCM self
, int arg_pos
, const char *func_name
)
292 SCM_ASSERT_TYPE (frscm_is_frame (self
), self
, arg_pos
, func_name
,
298 /* There is no gdbscm_scm_to_frame function because translating
299 a frame SCM object to a struct frame_info * can throw a GDB error.
300 Thus code working with frames has to handle both Scheme errors (e.g., the
301 object is not a frame) and GDB errors (e.g., the frame lookup failed).
303 To help keep things clear we split gdbscm_scm_to_frame into two:
305 gdbscm_get_frame_smob_arg_unsafe
306 - throws a Scheme error if object is not a frame,
307 or if the inferior is gone or is no longer current
309 gdbscm_frame_smob_to_frame
310 - may throw a gdb error if the conversion fails
311 - it's not clear when it will and won't throw a GDB error,
312 but for robustness' sake we assume that whenever we call out to GDB
313 a GDB error may get thrown (and thus the call must be wrapped in a
316 /* Returns the frame_smob for the object wrapped by FRAME_SCM.
317 A Scheme error is thrown if FRAME_SCM is not a frame. */
320 frscm_get_frame_smob_arg_unsafe (SCM self
, int arg_pos
, const char *func_name
)
322 SCM f_scm
= frscm_get_frame_arg_unsafe (self
, arg_pos
, func_name
);
323 frame_smob
*f_smob
= (frame_smob
*) SCM_SMOB_DATA (f_scm
);
325 if (f_smob
->inferior
== NULL
)
327 gdbscm_invalid_object_error (func_name
, arg_pos
, self
,
330 if (f_smob
->inferior
!= current_inferior ())
331 scm_misc_error (func_name
, _("inferior has changed"), SCM_EOL
);
336 /* Returns the frame_info object wrapped by F_SMOB.
337 If the frame doesn't exist anymore (the frame id doesn't
338 correspond to any frame in the inferior), returns NULL.
339 This function calls GDB routines, so don't assume a GDB error will
343 frscm_frame_smob_to_frame (frame_smob
*f_smob
)
345 struct frame_info
*frame
;
347 frame
= frame_find_by_id (f_smob
->frame_id
);
351 if (f_smob
->frame_id_is_next
)
352 frame
= get_prev_frame (frame
);
357 /* Helper function for frscm_del_inferior_frames to mark the frame
361 frscm_mark_frame_invalid (void **slot
, void *info
)
363 frame_smob
*f_smob
= (frame_smob
*) *slot
;
365 f_smob
->inferior
= NULL
;
369 /* This function is called when an inferior is about to be freed.
370 Invalidate the frame as further actions on the frame could result
371 in bad data. All access to the frame should be gated by
372 frscm_get_frame_smob_arg_unsafe which will raise an exception on
376 frscm_del_inferior_frames (struct inferior
*inferior
, void *datum
)
382 htab_traverse_noresize (htab
, frscm_mark_frame_invalid
, NULL
);
389 /* (frame-valid? <gdb:frame>) -> bool
390 Returns #t if the frame corresponding to the frame_id of this
391 object still exists in the inferior. */
394 gdbscm_frame_valid_p (SCM self
)
397 struct frame_info
*frame
= NULL
;
398 volatile struct gdb_exception except
;
400 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
402 TRY_CATCH (except
, RETURN_MASK_ALL
)
404 frame
= frscm_frame_smob_to_frame (f_smob
);
406 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
408 return scm_from_bool (frame
!= NULL
);
411 /* (frame-name <gdb:frame>) -> string
412 Returns the name of the function corresponding to this frame,
413 or #f if there is no function. */
416 gdbscm_frame_name (SCM self
)
420 enum language lang
= language_minimal
;
421 struct frame_info
*frame
= NULL
;
423 volatile struct gdb_exception except
;
425 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
427 TRY_CATCH (except
, RETURN_MASK_ALL
)
429 frame
= frscm_frame_smob_to_frame (f_smob
);
431 find_frame_funname (frame
, &name
, &lang
, NULL
);
433 if (except
.reason
< 0)
435 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
439 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
445 result
= gdbscm_scm_from_c_string (name
);
454 /* (frame-type <gdb:frame>) -> integer
455 Returns the frame type, namely one of the gdb:*_FRAME constants. */
458 gdbscm_frame_type (SCM self
)
461 enum frame_type type
= NORMAL_FRAME
;
462 struct frame_info
*frame
= NULL
;
463 volatile struct gdb_exception except
;
465 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
467 TRY_CATCH (except
, RETURN_MASK_ALL
)
469 frame
= frscm_frame_smob_to_frame (f_smob
);
471 type
= get_frame_type (frame
);
473 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
477 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
481 return scm_from_int (type
);
484 /* (frame-arch <gdb:frame>) -> <gdb:architecture>
485 Returns the frame's architecture as a gdb:architecture object. */
488 gdbscm_frame_arch (SCM self
)
491 struct frame_info
*frame
= NULL
;
492 volatile struct gdb_exception except
;
494 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
496 TRY_CATCH (except
, RETURN_MASK_ALL
)
498 frame
= frscm_frame_smob_to_frame (f_smob
);
500 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
504 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
508 return arscm_scm_from_arch (f_smob
->gdbarch
);
511 /* (frame-unwind-stop-reason <gdb:frame>) -> integer
512 Returns one of the gdb:FRAME_UNWIND_* constants. */
515 gdbscm_frame_unwind_stop_reason (SCM self
)
518 struct frame_info
*frame
= NULL
;
519 volatile struct gdb_exception except
;
520 enum unwind_stop_reason stop_reason
;
522 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
524 TRY_CATCH (except
, RETURN_MASK_ALL
)
526 frame
= frscm_frame_smob_to_frame (f_smob
);
528 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
532 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
536 stop_reason
= get_frame_unwind_stop_reason (frame
);
538 return scm_from_int (stop_reason
);
541 /* (frame-pc <gdb:frame>) -> integer
542 Returns the frame's resume address. */
545 gdbscm_frame_pc (SCM self
)
549 struct frame_info
*frame
= NULL
;
550 volatile struct gdb_exception except
;
552 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
554 TRY_CATCH (except
, RETURN_MASK_ALL
)
556 frame
= frscm_frame_smob_to_frame (f_smob
);
558 pc
= get_frame_pc (frame
);
560 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
564 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
568 return gdbscm_scm_from_ulongest (pc
);
571 /* (frame-block <gdb:frame>) -> <gdb:block>
572 Returns the frame's code block, or #f if one cannot be found. */
575 gdbscm_frame_block (SCM self
)
578 const struct block
*block
= NULL
, *fn_block
;
579 struct frame_info
*frame
= NULL
;
580 volatile struct gdb_exception except
;
582 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
584 TRY_CATCH (except
, RETURN_MASK_ALL
)
586 frame
= frscm_frame_smob_to_frame (f_smob
);
588 block
= get_frame_block (frame
, NULL
);
590 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
594 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
598 for (fn_block
= block
;
599 fn_block
!= NULL
&& BLOCK_FUNCTION (fn_block
) == NULL
;
600 fn_block
= BLOCK_SUPERBLOCK (fn_block
))
603 if (block
== NULL
|| fn_block
== NULL
|| BLOCK_FUNCTION (fn_block
) == NULL
)
605 scm_misc_error (FUNC_NAME
, _("cannot find block for frame"),
611 return bkscm_scm_from_block
612 (block
, symbol_objfile (BLOCK_FUNCTION (fn_block
)));
618 /* (frame-function <gdb:frame>) -> <gdb:symbol>
619 Returns the symbol for the function corresponding to this frame,
620 or #f if there isn't one. */
623 gdbscm_frame_function (SCM self
)
626 struct symbol
*sym
= NULL
;
627 struct frame_info
*frame
= NULL
;
628 volatile struct gdb_exception except
;
630 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
632 TRY_CATCH (except
, RETURN_MASK_ALL
)
634 frame
= frscm_frame_smob_to_frame (f_smob
);
636 sym
= find_pc_function (get_frame_address_in_block (frame
));
638 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
642 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
647 return syscm_scm_from_symbol (sym
);
652 /* (frame-older <gdb:frame>) -> <gdb:frame>
653 Returns the frame immediately older (outer) to this frame,
654 or #f if there isn't one. */
657 gdbscm_frame_older (SCM self
)
660 struct frame_info
*prev
= NULL
;
661 struct frame_info
*frame
= NULL
;
662 volatile struct gdb_exception except
;
664 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
666 TRY_CATCH (except
, RETURN_MASK_ALL
)
668 frame
= frscm_frame_smob_to_frame (f_smob
);
670 prev
= get_prev_frame (frame
);
672 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
676 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
681 return frscm_scm_from_frame_unsafe (prev
, f_smob
->inferior
);
686 /* (frame-newer <gdb:frame>) -> <gdb:frame>
687 Returns the frame immediately newer (inner) to this frame,
688 or #f if there isn't one. */
691 gdbscm_frame_newer (SCM self
)
694 struct frame_info
*next
= NULL
;
695 struct frame_info
*frame
= NULL
;
696 volatile struct gdb_exception except
;
698 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
700 TRY_CATCH (except
, RETURN_MASK_ALL
)
702 frame
= frscm_frame_smob_to_frame (f_smob
);
704 next
= get_next_frame (frame
);
706 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
710 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
715 return frscm_scm_from_frame_unsafe (next
, f_smob
->inferior
);
720 /* (frame-sal <gdb:frame>) -> <gdb:sal>
721 Returns the frame's symtab and line. */
724 gdbscm_frame_sal (SCM self
)
727 struct symtab_and_line sal
;
728 struct frame_info
*frame
= NULL
;
729 volatile struct gdb_exception except
;
731 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
733 TRY_CATCH (except
, RETURN_MASK_ALL
)
735 frame
= frscm_frame_smob_to_frame (f_smob
);
737 find_frame_sal (frame
, &sal
);
739 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
743 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
747 return stscm_scm_from_sal (sal
);
750 /* (frame-read-var <gdb:frame> <gdb:symbol>) -> <gdb:value>
751 (frame-read-var <gdb:frame> string [#:block <gdb:block>]) -> <gdb:value>
752 If the optional block argument is provided start the search from that block,
753 otherwise search from the frame's current block (determined by examining
754 the resume address of the frame). The variable argument must be a string
755 or an instance of a <gdb:symbol>. The block argument must be an instance of
759 gdbscm_frame_read_var (SCM self
, SCM symbol_scm
, SCM rest
)
761 SCM keywords
[] = { block_keyword
, SCM_BOOL_F
};
764 int block_arg_pos
= -1;
765 SCM block_scm
= SCM_UNDEFINED
;
766 struct frame_info
*frame
= NULL
;
767 struct symbol
*var
= NULL
;
768 struct value
*value
= NULL
;
769 volatile struct gdb_exception except
;
771 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
773 TRY_CATCH (except
, RETURN_MASK_ALL
)
775 frame
= frscm_frame_smob_to_frame (f_smob
);
777 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
781 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
785 gdbscm_parse_function_args (FUNC_NAME
, SCM_ARG3
, keywords
, "#O",
786 rest
, &block_arg_pos
, &block_scm
);
788 if (syscm_is_symbol (symbol_scm
))
790 var
= syscm_get_valid_symbol_arg_unsafe (symbol_scm
, SCM_ARG2
,
792 SCM_ASSERT (SCM_UNBNDP (block_scm
), block_scm
, SCM_ARG3
, FUNC_NAME
);
794 else if (scm_is_string (symbol_scm
))
797 const struct block
*block
= NULL
;
798 struct cleanup
*cleanup
;
799 volatile struct gdb_exception except
;
801 if (! SCM_UNBNDP (block_scm
))
805 gdb_assert (block_arg_pos
> 0);
806 block
= bkscm_scm_to_block (block_scm
, block_arg_pos
, FUNC_NAME
,
809 gdbscm_throw (except_scm
);
812 var_name
= gdbscm_scm_to_c_string (symbol_scm
);
813 cleanup
= make_cleanup (xfree
, var_name
);
814 /* N.B. Between here and the call to do_cleanups, don't do anything
815 to cause a Scheme exception without performing the cleanup. */
817 TRY_CATCH (except
, RETURN_MASK_ALL
)
820 block
= get_frame_block (frame
, NULL
);
821 var
= lookup_symbol (var_name
, block
, VAR_DOMAIN
, NULL
);
823 if (except
.reason
< 0)
824 do_cleanups (cleanup
);
825 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
829 do_cleanups (cleanup
);
830 gdbscm_out_of_range_error (FUNC_NAME
, 0, symbol_scm
,
831 _("variable not found"));
834 do_cleanups (cleanup
);
838 /* Use SCM_ASSERT_TYPE for more consistent error messages. */
839 SCM_ASSERT_TYPE (0, symbol_scm
, SCM_ARG1
, FUNC_NAME
,
840 _("gdb:symbol or string"));
843 TRY_CATCH (except
, RETURN_MASK_ALL
)
845 value
= read_var_value (var
, frame
);
847 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
849 return vlscm_scm_from_value (value
);
852 /* (frame-select <gdb:frame>) -> unspecified
853 Select this frame. */
856 gdbscm_frame_select (SCM self
)
859 struct frame_info
*frame
= NULL
;
860 volatile struct gdb_exception except
;
862 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
864 TRY_CATCH (except
, RETURN_MASK_ALL
)
866 frame
= frscm_frame_smob_to_frame (f_smob
);
868 select_frame (frame
);
870 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
874 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
878 return SCM_UNSPECIFIED
;
881 /* (newest-frame) -> <gdb:frame>
882 Returns the newest frame. */
885 gdbscm_newest_frame (void)
887 struct frame_info
*frame
= NULL
;
888 volatile struct gdb_exception except
;
890 TRY_CATCH (except
, RETURN_MASK_ALL
)
892 frame
= get_current_frame ();
894 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
896 return frscm_scm_from_frame_unsafe (frame
, current_inferior ());
899 /* (selected-frame) -> <gdb:frame>
900 Returns the selected frame. */
903 gdbscm_selected_frame (void)
905 struct frame_info
*frame
= NULL
;
906 volatile struct gdb_exception except
;
908 TRY_CATCH (except
, RETURN_MASK_ALL
)
910 frame
= get_selected_frame (_("No frame is currently selected"));
912 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
914 return frscm_scm_from_frame_unsafe (frame
, current_inferior ());
917 /* (unwind-stop-reason-string integer) -> string
918 Return a string explaining the unwind stop reason. */
921 gdbscm_unwind_stop_reason_string (SCM reason_scm
)
926 gdbscm_parse_function_args (FUNC_NAME
, SCM_ARG1
, NULL
, "i",
927 reason_scm
, &reason
);
929 if (reason
< UNWIND_FIRST
|| reason
> UNWIND_LAST
)
930 scm_out_of_range (FUNC_NAME
, reason_scm
);
932 str
= unwind_stop_reason_to_string (reason
);
933 return gdbscm_scm_from_c_string (str
);
936 /* Initialize the Scheme frame support. */
938 static const scheme_integer_constant frame_integer_constants
[] =
940 #define ENTRY(X) { #X, X }
942 ENTRY (NORMAL_FRAME
),
944 ENTRY (INLINE_FRAME
),
945 ENTRY (TAILCALL_FRAME
),
946 ENTRY (SIGTRAMP_FRAME
),
948 ENTRY (SENTINEL_FRAME
),
952 #define SET(name, description) \
953 { "FRAME_" #name, name },
954 #include "unwind_stop_reasons.def"
957 END_INTEGER_CONSTANTS
960 static const scheme_function frame_functions
[] =
962 { "frame?", 1, 0, 0, gdbscm_frame_p
,
964 Return #t if the object is a <gdb:frame> object." },
966 { "frame-valid?", 1, 0, 0, gdbscm_frame_valid_p
,
968 Return #t if the object is a valid <gdb:frame> object.\n\
969 Frames become invalid when the inferior returns to its caller." },
971 { "frame-name", 1, 0, 0, gdbscm_frame_name
,
973 Return the name of the function corresponding to this frame,\n\
974 or #f if there is no function." },
976 { "frame-arch", 1, 0, 0, gdbscm_frame_arch
,
978 Return the frame's architecture as a <gdb:arch> object." },
980 { "frame-type", 1, 0, 0, gdbscm_frame_type
,
982 Return the frame type, namely one of the gdb:*_FRAME constants." },
984 { "frame-unwind-stop-reason", 1, 0, 0, gdbscm_frame_unwind_stop_reason
,
986 Return one of the gdb:FRAME_UNWIND_* constants explaining why\n\
987 it's not possible to find frames older than this." },
989 { "frame-pc", 1, 0, 0, gdbscm_frame_pc
,
991 Return the frame's resume address." },
993 { "frame-block", 1, 0, 0, gdbscm_frame_block
,
995 Return the frame's code block, or #f if one cannot be found." },
997 { "frame-function", 1, 0, 0, gdbscm_frame_function
,
999 Return the <gdb:symbol> for the function corresponding to this frame,\n\
1000 or #f if there isn't one." },
1002 { "frame-older", 1, 0, 0, gdbscm_frame_older
,
1004 Return the frame immediately older (outer) to this frame,\n\
1005 or #f if there isn't one." },
1007 { "frame-newer", 1, 0, 0, gdbscm_frame_newer
,
1009 Return the frame immediately newer (inner) to this frame,\n\
1010 or #f if there isn't one." },
1012 { "frame-sal", 1, 0, 0, gdbscm_frame_sal
,
1014 Return the frame's symtab-and-line <gdb:sal> object." },
1016 { "frame-read-var", 2, 0, 1, gdbscm_frame_read_var
,
1018 Return the value of the symbol in the frame.\n\
1020 Arguments: <gdb:frame> <gdb:symbol>\n\
1021 Or: <gdb:frame> string [#:block <gdb:block>]" },
1023 { "frame-select", 1, 0, 0, gdbscm_frame_select
,
1025 Select this frame." },
1027 { "newest-frame", 0, 0, 0, gdbscm_newest_frame
,
1029 Return the newest frame." },
1031 { "selected-frame", 0, 0, 0, gdbscm_selected_frame
,
1033 Return the selected frame." },
1035 { "unwind-stop-reason-string", 1, 0, 0, gdbscm_unwind_stop_reason_string
,
1037 Return a string explaining the unwind stop reason.\n\
1039 Arguments: integer (the result of frame-unwind-stop-reason)" },
1045 gdbscm_initialize_frames (void)
1048 = gdbscm_make_smob_type (frame_smob_name
, sizeof (frame_smob
));
1049 scm_set_smob_free (frame_smob_tag
, frscm_free_frame_smob
);
1050 scm_set_smob_print (frame_smob_tag
, frscm_print_frame_smob
);
1052 gdbscm_define_integer_constants (frame_integer_constants
, 1);
1053 gdbscm_define_functions (frame_functions
, 1);
1055 block_keyword
= scm_from_latin1_keyword ("block");
1057 /* Register an inferior "free" callback so we can properly
1058 invalidate frames when an inferior file is about to be deleted. */
1059 frscm_inferior_data_key
1060 = register_inferior_data_with_cleanup (NULL
, frscm_del_inferior_frames
);