1 /* Scheme interface to stack frames.
3 Copyright (C) 2008-2015 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 struct frame_id frame_id
= null_frame_id
;
224 struct gdbarch
*gdbarch
= NULL
;
225 int frame_id_is_next
= 0;
227 /* If we've already created a gsmob for this frame, return it.
228 This makes frames eq?-able. */
229 htab
= frscm_inferior_frame_map (inferior
);
230 f_smob_for_lookup
.frame_id
= get_frame_id (frame
);
231 f_smob_for_lookup
.inferior
= inferior
;
232 slot
= gdbscm_find_eqable_gsmob_ptr_slot (htab
, &f_smob_for_lookup
.base
);
234 return (*slot
)->containing_scm
;
238 /* Try to get the previous frame, to determine if this is the last frame
239 in a corrupt stack. If so, we need to store the frame_id of the next
240 frame and not of this one (which is possibly invalid). */
241 if (get_prev_frame (frame
) == NULL
242 && get_frame_unwind_stop_reason (frame
) != UNWIND_NO_REASON
243 && get_next_frame (frame
) != NULL
)
245 frame_id
= get_frame_id (get_next_frame (frame
));
246 frame_id_is_next
= 1;
250 frame_id
= get_frame_id (frame
);
251 frame_id_is_next
= 0;
253 gdbarch
= get_frame_arch (frame
);
255 CATCH (except
, RETURN_MASK_ALL
)
257 return gdbscm_scm_from_gdb_exception (except
);
261 f_scm
= frscm_make_frame_smob ();
262 f_smob
= (frame_smob
*) SCM_SMOB_DATA (f_scm
);
263 f_smob
->frame_id
= frame_id
;
264 f_smob
->gdbarch
= gdbarch
;
265 f_smob
->inferior
= inferior
;
266 f_smob
->frame_id_is_next
= frame_id_is_next
;
268 gdbscm_fill_eqable_gsmob_ptr_slot (slot
, &f_smob
->base
);
273 /* Create a new <gdb:frame> object that encapsulates FRAME.
274 A Scheme exception is thrown if there is an error. */
277 frscm_scm_from_frame_unsafe (struct frame_info
*frame
,
278 struct inferior
*inferior
)
280 SCM f_scm
= frscm_scm_from_frame (frame
, inferior
);
282 if (gdbscm_is_exception (f_scm
))
283 gdbscm_throw (f_scm
);
288 /* Returns the <gdb:frame> object in SELF.
289 Throws an exception if SELF is not a <gdb:frame> object. */
292 frscm_get_frame_arg_unsafe (SCM self
, int arg_pos
, const char *func_name
)
294 SCM_ASSERT_TYPE (frscm_is_frame (self
), self
, arg_pos
, func_name
,
300 /* There is no gdbscm_scm_to_frame function because translating
301 a frame SCM object to a struct frame_info * can throw a GDB error.
302 Thus code working with frames has to handle both Scheme errors (e.g., the
303 object is not a frame) and GDB errors (e.g., the frame lookup failed).
305 To help keep things clear we split what would be gdbscm_scm_to_frame
308 frscm_get_frame_smob_arg_unsafe
309 - throws a Scheme error if object is not a frame,
310 or if the inferior is gone or is no longer current
312 frscm_frame_smob_to_frame
313 - may throw a gdb error if the conversion fails
314 - it's not clear when it will and won't throw a GDB error,
315 but for robustness' sake we assume that whenever we call out to GDB
316 a GDB error may get thrown (and thus the call must be wrapped in a
319 /* Returns the frame_smob for the object wrapped by FRAME_SCM.
320 A Scheme error is thrown if FRAME_SCM is not a frame. */
323 frscm_get_frame_smob_arg_unsafe (SCM self
, int arg_pos
, const char *func_name
)
325 SCM f_scm
= frscm_get_frame_arg_unsafe (self
, arg_pos
, func_name
);
326 frame_smob
*f_smob
= (frame_smob
*) SCM_SMOB_DATA (f_scm
);
328 if (f_smob
->inferior
== NULL
)
330 gdbscm_invalid_object_error (func_name
, arg_pos
, self
,
333 if (f_smob
->inferior
!= current_inferior ())
334 scm_misc_error (func_name
, _("inferior has changed"), SCM_EOL
);
339 /* Returns the frame_info object wrapped by F_SMOB.
340 If the frame doesn't exist anymore (the frame id doesn't
341 correspond to any frame in the inferior), returns NULL.
342 This function calls GDB routines, so don't assume a GDB error will
346 frscm_frame_smob_to_frame (frame_smob
*f_smob
)
348 struct frame_info
*frame
;
350 frame
= frame_find_by_id (f_smob
->frame_id
);
354 if (f_smob
->frame_id_is_next
)
355 frame
= get_prev_frame (frame
);
360 /* Helper function for frscm_del_inferior_frames to mark the frame
364 frscm_mark_frame_invalid (void **slot
, void *info
)
366 frame_smob
*f_smob
= (frame_smob
*) *slot
;
368 f_smob
->inferior
= NULL
;
372 /* This function is called when an inferior is about to be freed.
373 Invalidate the frame as further actions on the frame could result
374 in bad data. All access to the frame should be gated by
375 frscm_get_frame_smob_arg_unsafe which will raise an exception on
379 frscm_del_inferior_frames (struct inferior
*inferior
, void *datum
)
385 htab_traverse_noresize (htab
, frscm_mark_frame_invalid
, NULL
);
392 /* (frame-valid? <gdb:frame>) -> bool
393 Returns #t if the frame corresponding to the frame_id of this
394 object still exists in the inferior. */
397 gdbscm_frame_valid_p (SCM self
)
400 struct frame_info
*frame
= NULL
;
402 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
406 frame
= frscm_frame_smob_to_frame (f_smob
);
408 CATCH (except
, RETURN_MASK_ALL
)
410 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
414 return scm_from_bool (frame
!= NULL
);
417 /* (frame-name <gdb:frame>) -> string
418 Returns the name of the function corresponding to this frame,
419 or #f if there is no function. */
422 gdbscm_frame_name (SCM self
)
426 enum language lang
= language_minimal
;
427 struct frame_info
*frame
= NULL
;
430 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
434 frame
= frscm_frame_smob_to_frame (f_smob
);
436 find_frame_funname (frame
, &name
, &lang
, NULL
);
438 CATCH (except
, RETURN_MASK_ALL
)
441 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
447 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
453 result
= gdbscm_scm_from_c_string (name
);
462 /* (frame-type <gdb:frame>) -> integer
463 Returns the frame type, namely one of the gdb:*_FRAME constants. */
466 gdbscm_frame_type (SCM self
)
469 enum frame_type type
= NORMAL_FRAME
;
470 struct frame_info
*frame
= NULL
;
472 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
476 frame
= frscm_frame_smob_to_frame (f_smob
);
478 type
= get_frame_type (frame
);
480 CATCH (except
, RETURN_MASK_ALL
)
482 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
488 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
492 return scm_from_int (type
);
495 /* (frame-arch <gdb:frame>) -> <gdb:architecture>
496 Returns the frame's architecture as a gdb:architecture object. */
499 gdbscm_frame_arch (SCM self
)
502 struct frame_info
*frame
= NULL
;
504 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
508 frame
= frscm_frame_smob_to_frame (f_smob
);
510 CATCH (except
, RETURN_MASK_ALL
)
512 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
518 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
522 return arscm_scm_from_arch (f_smob
->gdbarch
);
525 /* (frame-unwind-stop-reason <gdb:frame>) -> integer
526 Returns one of the gdb:FRAME_UNWIND_* constants. */
529 gdbscm_frame_unwind_stop_reason (SCM self
)
532 struct frame_info
*frame
= NULL
;
533 enum unwind_stop_reason stop_reason
;
535 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
539 frame
= frscm_frame_smob_to_frame (f_smob
);
541 CATCH (except
, RETURN_MASK_ALL
)
543 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
549 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
553 stop_reason
= get_frame_unwind_stop_reason (frame
);
555 return scm_from_int (stop_reason
);
558 /* (frame-pc <gdb:frame>) -> integer
559 Returns the frame's resume address. */
562 gdbscm_frame_pc (SCM self
)
566 struct frame_info
*frame
= NULL
;
568 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
572 frame
= frscm_frame_smob_to_frame (f_smob
);
574 pc
= get_frame_pc (frame
);
576 CATCH (except
, RETURN_MASK_ALL
)
578 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
584 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
588 return gdbscm_scm_from_ulongest (pc
);
591 /* (frame-block <gdb:frame>) -> <gdb:block>
592 Returns the frame's code block, or #f if one cannot be found. */
595 gdbscm_frame_block (SCM self
)
598 const struct block
*block
= NULL
, *fn_block
;
599 struct frame_info
*frame
= NULL
;
601 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
605 frame
= frscm_frame_smob_to_frame (f_smob
);
607 block
= get_frame_block (frame
, NULL
);
609 CATCH (except
, RETURN_MASK_ALL
)
611 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
617 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
621 for (fn_block
= block
;
622 fn_block
!= NULL
&& BLOCK_FUNCTION (fn_block
) == NULL
;
623 fn_block
= BLOCK_SUPERBLOCK (fn_block
))
626 if (block
== NULL
|| fn_block
== NULL
|| BLOCK_FUNCTION (fn_block
) == NULL
)
628 scm_misc_error (FUNC_NAME
, _("cannot find block for frame"),
634 return bkscm_scm_from_block
635 (block
, symbol_objfile (BLOCK_FUNCTION (fn_block
)));
641 /* (frame-function <gdb:frame>) -> <gdb:symbol>
642 Returns the symbol for the function corresponding to this frame,
643 or #f if there isn't one. */
646 gdbscm_frame_function (SCM self
)
649 struct symbol
*sym
= NULL
;
650 struct frame_info
*frame
= NULL
;
652 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
656 frame
= frscm_frame_smob_to_frame (f_smob
);
658 sym
= find_pc_function (get_frame_address_in_block (frame
));
660 CATCH (except
, RETURN_MASK_ALL
)
662 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
668 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
673 return syscm_scm_from_symbol (sym
);
678 /* (frame-older <gdb:frame>) -> <gdb:frame>
679 Returns the frame immediately older (outer) to this frame,
680 or #f if there isn't one. */
683 gdbscm_frame_older (SCM self
)
686 struct frame_info
*prev
= NULL
;
687 struct frame_info
*frame
= NULL
;
689 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
693 frame
= frscm_frame_smob_to_frame (f_smob
);
695 prev
= get_prev_frame (frame
);
697 CATCH (except
, RETURN_MASK_ALL
)
699 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
705 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
710 return frscm_scm_from_frame_unsafe (prev
, f_smob
->inferior
);
715 /* (frame-newer <gdb:frame>) -> <gdb:frame>
716 Returns the frame immediately newer (inner) to this frame,
717 or #f if there isn't one. */
720 gdbscm_frame_newer (SCM self
)
723 struct frame_info
*next
= NULL
;
724 struct frame_info
*frame
= NULL
;
726 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
730 frame
= frscm_frame_smob_to_frame (f_smob
);
732 next
= get_next_frame (frame
);
734 CATCH (except
, RETURN_MASK_ALL
)
736 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
742 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
747 return frscm_scm_from_frame_unsafe (next
, f_smob
->inferior
);
752 /* (frame-sal <gdb:frame>) -> <gdb:sal>
753 Returns the frame's symtab and line. */
756 gdbscm_frame_sal (SCM self
)
759 struct symtab_and_line sal
;
760 struct frame_info
*frame
= NULL
;
762 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
766 frame
= frscm_frame_smob_to_frame (f_smob
);
768 find_frame_sal (frame
, &sal
);
770 CATCH (except
, RETURN_MASK_ALL
)
772 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
778 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
782 return stscm_scm_from_sal (sal
);
785 /* (frame-read-var <gdb:frame> <gdb:symbol>) -> <gdb:value>
786 (frame-read-var <gdb:frame> string [#:block <gdb:block>]) -> <gdb:value>
787 If the optional block argument is provided start the search from that block,
788 otherwise search from the frame's current block (determined by examining
789 the resume address of the frame). The variable argument must be a string
790 or an instance of a <gdb:symbol>. The block argument must be an instance of
794 gdbscm_frame_read_var (SCM self
, SCM symbol_scm
, SCM rest
)
796 SCM keywords
[] = { block_keyword
, SCM_BOOL_F
};
799 int block_arg_pos
= -1;
800 SCM block_scm
= SCM_UNDEFINED
;
801 struct frame_info
*frame
= NULL
;
802 struct symbol
*var
= NULL
;
803 struct value
*value
= NULL
;
805 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
809 frame
= frscm_frame_smob_to_frame (f_smob
);
811 CATCH (except
, RETURN_MASK_ALL
)
813 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
819 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
823 gdbscm_parse_function_args (FUNC_NAME
, SCM_ARG3
, keywords
, "#O",
824 rest
, &block_arg_pos
, &block_scm
);
826 if (syscm_is_symbol (symbol_scm
))
828 var
= syscm_get_valid_symbol_arg_unsafe (symbol_scm
, SCM_ARG2
,
830 SCM_ASSERT (SCM_UNBNDP (block_scm
), block_scm
, SCM_ARG3
, FUNC_NAME
);
832 else if (scm_is_string (symbol_scm
))
835 const struct block
*block
= NULL
;
836 struct cleanup
*cleanup
;
837 struct gdb_exception except
= exception_none
;
839 if (! SCM_UNBNDP (block_scm
))
843 gdb_assert (block_arg_pos
> 0);
844 block
= bkscm_scm_to_block (block_scm
, block_arg_pos
, FUNC_NAME
,
847 gdbscm_throw (except_scm
);
850 var_name
= gdbscm_scm_to_c_string (symbol_scm
);
851 cleanup
= make_cleanup (xfree
, var_name
);
852 /* N.B. Between here and the call to do_cleanups, don't do anything
853 to cause a Scheme exception without performing the cleanup. */
858 block
= get_frame_block (frame
, NULL
);
859 var
= lookup_symbol (var_name
, block
, VAR_DOMAIN
, NULL
);
861 CATCH (ex
, RETURN_MASK_ALL
)
867 do_cleanups (cleanup
);
868 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
872 do_cleanups (cleanup
);
873 gdbscm_out_of_range_error (FUNC_NAME
, 0, symbol_scm
,
874 _("variable not found"));
877 do_cleanups (cleanup
);
881 /* Use SCM_ASSERT_TYPE for more consistent error messages. */
882 SCM_ASSERT_TYPE (0, symbol_scm
, SCM_ARG1
, FUNC_NAME
,
883 _("gdb:symbol or string"));
888 value
= read_var_value (var
, frame
);
890 CATCH (except
, RETURN_MASK_ALL
)
892 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
896 return vlscm_scm_from_value (value
);
899 /* (frame-select <gdb:frame>) -> unspecified
900 Select this frame. */
903 gdbscm_frame_select (SCM self
)
906 struct frame_info
*frame
= NULL
;
908 f_smob
= frscm_get_frame_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
912 frame
= frscm_frame_smob_to_frame (f_smob
);
914 select_frame (frame
);
916 CATCH (except
, RETURN_MASK_ALL
)
918 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
924 gdbscm_invalid_object_error (FUNC_NAME
, SCM_ARG1
, self
,
928 return SCM_UNSPECIFIED
;
931 /* (newest-frame) -> <gdb:frame>
932 Returns the newest frame. */
935 gdbscm_newest_frame (void)
937 struct frame_info
*frame
= NULL
;
941 frame
= get_current_frame ();
943 CATCH (except
, RETURN_MASK_ALL
)
945 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
949 return frscm_scm_from_frame_unsafe (frame
, current_inferior ());
952 /* (selected-frame) -> <gdb:frame>
953 Returns the selected frame. */
956 gdbscm_selected_frame (void)
958 struct frame_info
*frame
= NULL
;
962 frame
= get_selected_frame (_("No frame is currently selected"));
964 CATCH (except
, RETURN_MASK_ALL
)
966 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
970 return frscm_scm_from_frame_unsafe (frame
, current_inferior ());
973 /* (unwind-stop-reason-string integer) -> string
974 Return a string explaining the unwind stop reason. */
977 gdbscm_unwind_stop_reason_string (SCM reason_scm
)
982 gdbscm_parse_function_args (FUNC_NAME
, SCM_ARG1
, NULL
, "i",
983 reason_scm
, &reason
);
985 if (reason
< UNWIND_FIRST
|| reason
> UNWIND_LAST
)
986 scm_out_of_range (FUNC_NAME
, reason_scm
);
988 str
= unwind_stop_reason_to_string (reason
);
989 return gdbscm_scm_from_c_string (str
);
992 /* Initialize the Scheme frame support. */
994 static const scheme_integer_constant frame_integer_constants
[] =
996 #define ENTRY(X) { #X, X }
998 ENTRY (NORMAL_FRAME
),
1000 ENTRY (INLINE_FRAME
),
1001 ENTRY (TAILCALL_FRAME
),
1002 ENTRY (SIGTRAMP_FRAME
),
1004 ENTRY (SENTINEL_FRAME
),
1008 #define SET(name, description) \
1009 { "FRAME_" #name, name },
1010 #include "unwind_stop_reasons.def"
1013 END_INTEGER_CONSTANTS
1016 static const scheme_function frame_functions
[] =
1018 { "frame?", 1, 0, 0, gdbscm_frame_p
,
1020 Return #t if the object is a <gdb:frame> object." },
1022 { "frame-valid?", 1, 0, 0, gdbscm_frame_valid_p
,
1024 Return #t if the object is a valid <gdb:frame> object.\n\
1025 Frames become invalid when the inferior returns to its caller." },
1027 { "frame-name", 1, 0, 0, gdbscm_frame_name
,
1029 Return the name of the function corresponding to this frame,\n\
1030 or #f if there is no function." },
1032 { "frame-arch", 1, 0, 0, gdbscm_frame_arch
,
1034 Return the frame's architecture as a <gdb:arch> object." },
1036 { "frame-type", 1, 0, 0, gdbscm_frame_type
,
1038 Return the frame type, namely one of the gdb:*_FRAME constants." },
1040 { "frame-unwind-stop-reason", 1, 0, 0, gdbscm_frame_unwind_stop_reason
,
1042 Return one of the gdb:FRAME_UNWIND_* constants explaining why\n\
1043 it's not possible to find frames older than this." },
1045 { "frame-pc", 1, 0, 0, gdbscm_frame_pc
,
1047 Return the frame's resume address." },
1049 { "frame-block", 1, 0, 0, gdbscm_frame_block
,
1051 Return the frame's code block, or #f if one cannot be found." },
1053 { "frame-function", 1, 0, 0, gdbscm_frame_function
,
1055 Return the <gdb:symbol> for the function corresponding to this frame,\n\
1056 or #f if there isn't one." },
1058 { "frame-older", 1, 0, 0, gdbscm_frame_older
,
1060 Return the frame immediately older (outer) to this frame,\n\
1061 or #f if there isn't one." },
1063 { "frame-newer", 1, 0, 0, gdbscm_frame_newer
,
1065 Return the frame immediately newer (inner) to this frame,\n\
1066 or #f if there isn't one." },
1068 { "frame-sal", 1, 0, 0, gdbscm_frame_sal
,
1070 Return the frame's symtab-and-line <gdb:sal> object." },
1072 { "frame-read-var", 2, 0, 1, gdbscm_frame_read_var
,
1074 Return the value of the symbol in the frame.\n\
1076 Arguments: <gdb:frame> <gdb:symbol>\n\
1077 Or: <gdb:frame> string [#:block <gdb:block>]" },
1079 { "frame-select", 1, 0, 0, gdbscm_frame_select
,
1081 Select this frame." },
1083 { "newest-frame", 0, 0, 0, gdbscm_newest_frame
,
1085 Return the newest frame." },
1087 { "selected-frame", 0, 0, 0, gdbscm_selected_frame
,
1089 Return the selected frame." },
1091 { "unwind-stop-reason-string", 1, 0, 0, gdbscm_unwind_stop_reason_string
,
1093 Return a string explaining the unwind stop reason.\n\
1095 Arguments: integer (the result of frame-unwind-stop-reason)" },
1101 gdbscm_initialize_frames (void)
1104 = gdbscm_make_smob_type (frame_smob_name
, sizeof (frame_smob
));
1105 scm_set_smob_free (frame_smob_tag
, frscm_free_frame_smob
);
1106 scm_set_smob_print (frame_smob_tag
, frscm_print_frame_smob
);
1108 gdbscm_define_integer_constants (frame_integer_constants
, 1);
1109 gdbscm_define_functions (frame_functions
, 1);
1111 block_keyword
= scm_from_latin1_keyword ("block");
1113 /* Register an inferior "free" callback so we can properly
1114 invalidate frames when an inferior file is about to be deleted. */
1115 frscm_inferior_data_key
1116 = register_inferior_data_with_cleanup (NULL
, frscm_del_inferior_frames
);