1 /* Scheme interface to breakpoints.
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. */
25 #include "breakpoint.h"
27 #include "gdbthread.h"
29 #include "cli/cli-script.h"
31 #include "arch-utils.h"
33 #include "guile-internal.h"
35 /* The <gdb:breakpoint> smob.
36 N.B.: The name of this struct is known to breakpoint.h.
38 Note: Breakpoints are added to gdb using a two step process:
39 1) Call make-breakpoint to create a <gdb:breakpoint> object.
40 2) Call register-breakpoint! to add the breakpoint to gdb.
41 It is done this way so that the constructor, make-breakpoint, doesn't have
42 any side-effects. This means that the smob needs to store everything
43 that was passed to make-breakpoint. */
45 typedef struct gdbscm_breakpoint_object
47 /* This always appears first. */
50 /* Non-zero if this breakpoint was created with make-breakpoint. */
53 /* For breakpoints created with make-breakpoint, these are the parameters
54 that were passed to make-breakpoint. These values are not used except
55 to register the breakpoint with GDB. */
58 /* The string representation of the breakpoint.
59 Space for this lives in GC space. */
62 /* The kind of breakpoint.
63 At the moment this can only be one of bp_breakpoint, bp_watchpoint. */
66 /* If a watchpoint, the kind of watchpoint. */
67 enum target_hw_bp_type access_type
;
69 /* Non-zero if the breakpoint is an "internal" breakpoint. */
73 /* The breakpoint number according to gdb.
74 For breakpoints created from Scheme, this has the value -1 until the
75 breakpoint is registered with gdb.
76 This is recorded here because BP will be NULL when deleted. */
79 /* The gdb breakpoint object, or NULL if the breakpoint has not been
80 registered yet, or has been deleted. */
81 struct breakpoint
*bp
;
83 /* Backlink to our containing <gdb:breakpoint> smob.
84 This is needed when we are deleted, we need to unprotect the object
88 /* A stop condition or #f. */
92 static const char breakpoint_smob_name
[] = "gdb:breakpoint";
94 /* The tag Guile knows the breakpoint smob by. */
95 static scm_t_bits breakpoint_smob_tag
;
97 /* Variables used to pass information between the breakpoint_smob
98 constructor and the breakpoint-created hook function. */
99 static SCM pending_breakpoint_scm
= SCM_BOOL_F
;
101 /* Keywords used by create-breakpoint!. */
102 static SCM type_keyword
;
103 static SCM wp_class_keyword
;
104 static SCM internal_keyword
;
106 /* Administrivia for breakpoint smobs. */
108 /* The smob "free" function for <gdb:breakpoint>. */
111 bpscm_free_breakpoint_smob (SCM self
)
113 breakpoint_smob
*bp_smob
= (breakpoint_smob
*) SCM_SMOB_DATA (self
);
116 bp_smob
->bp
->scm_bp_object
= NULL
;
118 /* Not necessary, done to catch bugs. */
120 bp_smob
->containing_scm
= SCM_UNDEFINED
;
121 bp_smob
->stop
= SCM_UNDEFINED
;
126 /* Return the name of TYPE.
127 This doesn't handle all types, just the ones we export. */
130 bpscm_type_to_string (enum bptype type
)
134 case bp_none
: return "BP_NONE";
135 case bp_breakpoint
: return "BP_BREAKPOINT";
136 case bp_watchpoint
: return "BP_WATCHPOINT";
137 case bp_hardware_watchpoint
: return "BP_HARDWARE_WATCHPOINT";
138 case bp_read_watchpoint
: return "BP_READ_WATCHPOINT";
139 case bp_access_watchpoint
: return "BP_ACCESS_WATCHPOINT";
140 default: return "internal/other";
144 /* Return the name of ENABLE_STATE. */
147 bpscm_enable_state_to_string (enum enable_state enable_state
)
149 switch (enable_state
)
151 case bp_disabled
: return "disabled";
152 case bp_enabled
: return "enabled";
153 case bp_call_disabled
: return "call_disabled";
154 case bp_permanent
: return "permanent";
155 default: return "unknown";
159 /* The smob "print" function for <gdb:breakpoint>. */
162 bpscm_print_breakpoint_smob (SCM self
, SCM port
, scm_print_state
*pstate
)
164 breakpoint_smob
*bp_smob
= (breakpoint_smob
*) SCM_SMOB_DATA (self
);
165 struct breakpoint
*b
= bp_smob
->bp
;
167 gdbscm_printf (port
, "#<%s", breakpoint_smob_name
);
169 /* Only print what we export to the user.
170 The rest are possibly internal implementation details. */
172 gdbscm_printf (port
, " #%d", bp_smob
->number
);
174 /* Careful, the breakpoint may be invalid. */
177 gdbscm_printf (port
, " %s %s %s",
178 bpscm_type_to_string (b
->type
),
179 bpscm_enable_state_to_string (b
->enable_state
),
180 b
->silent
? "silent" : "noisy");
182 gdbscm_printf (port
, " hit:%d", b
->hit_count
);
183 gdbscm_printf (port
, " ignore:%d", b
->ignore_count
);
185 if (b
->addr_string
!= NULL
)
186 gdbscm_printf (port
, " @%s", b
->addr_string
);
189 scm_puts (">", port
);
191 scm_remember_upto_here_1 (self
);
193 /* Non-zero means success. */
197 /* Low level routine to create a <gdb:breakpoint> object. */
200 bpscm_make_breakpoint_smob (void)
202 breakpoint_smob
*bp_smob
= (breakpoint_smob
*)
203 scm_gc_malloc (sizeof (breakpoint_smob
), breakpoint_smob_name
);
206 memset (bp_smob
, 0, sizeof (*bp_smob
));
207 bp_smob
->number
= -1;
208 bp_smob
->stop
= SCM_BOOL_F
;
209 bp_scm
= scm_new_smob (breakpoint_smob_tag
, (scm_t_bits
) bp_smob
);
210 bp_smob
->containing_scm
= bp_scm
;
211 gdbscm_init_gsmob (&bp_smob
->base
);
216 /* Return non-zero if we want a Scheme wrapper for breakpoint B.
217 If FROM_SCHEME is non-zero,this is called for a breakpoint created
218 by the user from Scheme. Otherwise it is zero. */
221 bpscm_want_scm_wrapper_p (struct breakpoint
*bp
, int from_scheme
)
223 /* Don't create <gdb:breakpoint> objects for internal GDB breakpoints. */
224 if (bp
->number
< 0 && !from_scheme
)
227 /* The others are not supported. */
228 if (bp
->type
!= bp_breakpoint
229 && bp
->type
!= bp_watchpoint
230 && bp
->type
!= bp_hardware_watchpoint
231 && bp
->type
!= bp_read_watchpoint
232 && bp
->type
!= bp_access_watchpoint
)
238 /* Install the Scheme side of a breakpoint, CONTAINING_SCM, in
242 bpscm_attach_scm_to_breakpoint (struct breakpoint
*bp
, SCM containing_scm
)
244 breakpoint_smob
*bp_smob
;
246 bp_smob
= (breakpoint_smob
*) SCM_SMOB_DATA (containing_scm
);
247 bp_smob
->number
= bp
->number
;
249 bp_smob
->containing_scm
= containing_scm
;
250 bp_smob
->bp
->scm_bp_object
= bp_smob
;
252 /* The owner of this breakpoint is not in GC-controlled memory, so we need
253 to protect it from GC until the breakpoint is deleted. */
254 scm_gc_protect_object (containing_scm
);
257 /* Return non-zero if SCM is a breakpoint smob. */
260 bpscm_is_breakpoint (SCM scm
)
262 return SCM_SMOB_PREDICATE (breakpoint_smob_tag
, scm
);
265 /* (breakpoint? scm) -> boolean */
268 gdbscm_breakpoint_p (SCM scm
)
270 return scm_from_bool (bpscm_is_breakpoint (scm
));
273 /* Returns the <gdb:breakpoint> object in SELF.
274 Throws an exception if SELF is not a <gdb:breakpoint> object. */
277 bpscm_get_breakpoint_arg_unsafe (SCM self
, int arg_pos
, const char *func_name
)
279 SCM_ASSERT_TYPE (bpscm_is_breakpoint (self
), self
, arg_pos
, func_name
,
280 breakpoint_smob_name
);
285 /* Returns a pointer to the breakpoint smob of SELF.
286 Throws an exception if SELF is not a <gdb:breakpoint> object. */
288 static breakpoint_smob
*
289 bpscm_get_breakpoint_smob_arg_unsafe (SCM self
, int arg_pos
,
290 const char *func_name
)
292 SCM bp_scm
= bpscm_get_breakpoint_arg_unsafe (self
, arg_pos
, func_name
);
293 breakpoint_smob
*bp_smob
= (breakpoint_smob
*) SCM_SMOB_DATA (bp_scm
);
298 /* Return non-zero if breakpoint BP_SMOB is valid. */
301 bpscm_is_valid (breakpoint_smob
*bp_smob
)
303 return bp_smob
->bp
!= NULL
;
306 /* Returns the breakpoint smob in SELF, verifying it's valid.
307 Throws an exception if SELF is not a <gdb:breakpoint> object,
310 static breakpoint_smob
*
311 bpscm_get_valid_breakpoint_smob_arg_unsafe (SCM self
, int arg_pos
,
312 const char *func_name
)
314 breakpoint_smob
*bp_smob
315 = bpscm_get_breakpoint_smob_arg_unsafe (self
, arg_pos
, func_name
);
317 if (!bpscm_is_valid (bp_smob
))
319 gdbscm_invalid_object_error (func_name
, arg_pos
, self
,
320 _("<gdb:breakpoint>"));
326 /* Breakpoint methods. */
328 /* (make-breakpoint string [#:type integer] [#:wp-class integer]
329 [#:internal boolean) -> <gdb:breakpoint>
331 The result is the <gdb:breakpoint> Scheme object.
332 The breakpoint is not available to be used yet, however.
333 It must still be added to gdb with register-breakpoint!. */
336 gdbscm_make_breakpoint (SCM location_scm
, SCM rest
)
338 const SCM keywords
[] = {
339 type_keyword
, wp_class_keyword
, internal_keyword
, SCM_BOOL_F
343 int type_arg_pos
= -1, access_type_arg_pos
= -1, internal_arg_pos
= -1;
344 int type
= bp_breakpoint
;
345 int access_type
= hw_write
;
348 breakpoint_smob
*bp_smob
;
350 gdbscm_parse_function_args (FUNC_NAME
, SCM_ARG1
, keywords
, "s#iit",
351 location_scm
, &location
, rest
,
352 &type_arg_pos
, &type
,
353 &access_type_arg_pos
, &access_type
,
354 &internal_arg_pos
, &internal
);
356 result
= bpscm_make_breakpoint_smob ();
357 bp_smob
= (breakpoint_smob
*) SCM_SMOB_DATA (result
);
360 location
= gdbscm_gc_xstrdup (s
);
366 if (access_type_arg_pos
> 0)
368 gdbscm_misc_error (FUNC_NAME
, access_type_arg_pos
,
369 scm_from_int (access_type
),
370 _("access type with breakpoint is not allowed"));
381 gdbscm_out_of_range_error (FUNC_NAME
, access_type_arg_pos
,
382 scm_from_int (access_type
),
383 _("invalid watchpoint class"));
387 gdbscm_out_of_range_error (FUNC_NAME
, access_type_arg_pos
,
389 _("invalid breakpoint type"));
392 bp_smob
->is_scheme_bkpt
= 1;
393 bp_smob
->spec
.location
= location
;
394 bp_smob
->spec
.type
= type
;
395 bp_smob
->spec
.access_type
= access_type
;
396 bp_smob
->spec
.is_internal
= internal
;
401 /* (register-breakpoint! <gdb:breakpoint>) -> unspecified
403 It is an error to register a breakpoint created outside of Guile,
404 or an already-registered breakpoint. */
407 gdbscm_register_breakpoint_x (SCM self
)
409 breakpoint_smob
*bp_smob
410 = bpscm_get_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
411 volatile struct gdb_exception except
;
413 /* We only support registering breakpoints created with make-breakpoint. */
414 if (!bp_smob
->is_scheme_bkpt
)
415 scm_misc_error (FUNC_NAME
, _("not a Scheme breakpoint"), SCM_EOL
);
417 if (bpscm_is_valid (bp_smob
))
418 scm_misc_error (FUNC_NAME
, _("breakpoint is already registered"), SCM_EOL
);
420 pending_breakpoint_scm
= self
;
422 TRY_CATCH (except
, RETURN_MASK_ALL
)
424 char *location
= bp_smob
->spec
.location
;
425 int internal
= bp_smob
->spec
.is_internal
;
427 switch (bp_smob
->spec
.type
)
431 create_breakpoint (get_current_arch (),
432 location
, NULL
, -1, NULL
,
437 &bkpt_breakpoint_ops
,
443 enum target_hw_bp_type access_type
= bp_smob
->spec
.access_type
;
445 if (access_type
== hw_write
)
446 watch_command_wrapper (location
, 0, internal
);
447 else if (access_type
== hw_access
)
448 awatch_command_wrapper (location
, 0, internal
);
449 else if (access_type
== hw_read
)
450 rwatch_command_wrapper (location
, 0, internal
);
452 gdb_assert_not_reached ("invalid access type");
456 gdb_assert_not_reached ("invalid breakpoint type");
459 /* Ensure this gets reset, even if there's an error. */
460 pending_breakpoint_scm
= SCM_BOOL_F
;
461 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
463 return SCM_UNSPECIFIED
;
466 /* (delete-breakpoint! <gdb:breakpoint>) -> unspecified
467 Scheme function which deletes (removes) the underlying GDB breakpoint
468 from GDB's list of breakpoints. This triggers the breakpoint_deleted
469 observer which will call gdbscm_breakpoint_deleted; that function cleans
470 up the Scheme bits. */
473 gdbscm_delete_breakpoint_x (SCM self
)
475 breakpoint_smob
*bp_smob
476 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
477 volatile struct gdb_exception except
;
479 TRY_CATCH (except
, RETURN_MASK_ALL
)
481 delete_breakpoint (bp_smob
->bp
);
483 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
485 return SCM_UNSPECIFIED
;
488 /* iterate_over_breakpoints function for gdbscm_breakpoints. */
491 bpscm_build_bp_list (struct breakpoint
*bp
, void *arg
)
494 breakpoint_smob
*bp_smob
= bp
->scm_bp_object
;
496 /* Lazily create wrappers for breakpoints created outside Scheme. */
500 if (bpscm_want_scm_wrapper_p (bp
, 0))
504 bp_scm
= bpscm_make_breakpoint_smob ();
505 bpscm_attach_scm_to_breakpoint (bp
, bp_scm
);
507 bp_smob
= bp
->scm_bp_object
;
511 /* Not all breakpoints will have a companion Scheme object.
512 Only breakpoints that trigger the created_breakpoint observer call,
513 and satisfy certain conditions (see bpscm_want_scm_wrapper_p),
514 get a companion object (this includes Scheme-created breakpoints). */
517 *list
= scm_cons (bp_smob
->containing_scm
, *list
);
522 /* (breakpoints) -> list
523 Return a list of all breakpoints. */
526 gdbscm_breakpoints (void)
530 /* If iterate_over_breakpoints returns non-NULL it means the iteration
532 In that case abandon building the list and return #f. */
533 if (iterate_over_breakpoints (bpscm_build_bp_list
, &list
) != NULL
)
536 return scm_reverse_x (list
, SCM_EOL
);
539 /* (breakpoint-valid? <gdb:breakpoint>) -> boolean
540 Returns #t if SELF is still valid. */
543 gdbscm_breakpoint_valid_p (SCM self
)
545 breakpoint_smob
*bp_smob
546 = bpscm_get_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
548 return scm_from_bool (bpscm_is_valid (bp_smob
));
551 /* (breakpoint-enabled? <gdb:breakpoint>) -> boolean */
554 gdbscm_breakpoint_enabled_p (SCM self
)
556 breakpoint_smob
*bp_smob
557 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
559 return scm_from_bool (bp_smob
->bp
->enable_state
== bp_enabled
);
562 /* (set-breakpoint-enabled? <gdb:breakpoint> boolean) -> unspecified */
565 gdbscm_set_breakpoint_enabled_x (SCM self
, SCM newvalue
)
567 breakpoint_smob
*bp_smob
568 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
569 volatile struct gdb_exception except
;
571 SCM_ASSERT_TYPE (gdbscm_is_bool (newvalue
), newvalue
, SCM_ARG2
, FUNC_NAME
,
574 TRY_CATCH (except
, RETURN_MASK_ALL
)
576 if (gdbscm_is_true (newvalue
))
577 enable_breakpoint (bp_smob
->bp
);
579 disable_breakpoint (bp_smob
->bp
);
581 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
583 return SCM_UNSPECIFIED
;
586 /* (breakpoint-silent? <gdb:breakpoint>) -> boolean */
589 gdbscm_breakpoint_silent_p (SCM self
)
591 breakpoint_smob
*bp_smob
592 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
594 return scm_from_bool (bp_smob
->bp
->silent
);
597 /* (set-breakpoint-silent?! <gdb:breakpoint> boolean) -> unspecified */
600 gdbscm_set_breakpoint_silent_x (SCM self
, SCM newvalue
)
602 breakpoint_smob
*bp_smob
603 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
604 volatile struct gdb_exception except
;
606 SCM_ASSERT_TYPE (gdbscm_is_bool (newvalue
), newvalue
, SCM_ARG2
, FUNC_NAME
,
609 TRY_CATCH (except
, RETURN_MASK_ALL
)
611 breakpoint_set_silent (bp_smob
->bp
, gdbscm_is_true (newvalue
));
613 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
615 return SCM_UNSPECIFIED
;
618 /* (breakpoint-ignore-count <gdb:breakpoint>) -> integer */
621 gdbscm_breakpoint_ignore_count (SCM self
)
623 breakpoint_smob
*bp_smob
624 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
626 return scm_from_long (bp_smob
->bp
->ignore_count
);
629 /* (set-breakpoint-ignore-count! <gdb:breakpoint> integer)
633 gdbscm_set_breakpoint_ignore_count_x (SCM self
, SCM newvalue
)
635 breakpoint_smob
*bp_smob
636 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
638 volatile struct gdb_exception except
;
640 SCM_ASSERT_TYPE (scm_is_signed_integer (newvalue
, LONG_MIN
, LONG_MAX
),
641 newvalue
, SCM_ARG2
, FUNC_NAME
, _("integer"));
643 value
= scm_to_long (newvalue
);
647 TRY_CATCH (except
, RETURN_MASK_ALL
)
649 set_ignore_count (bp_smob
->number
, (int) value
, 0);
651 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
653 return SCM_UNSPECIFIED
;
656 /* (breakpoint-hit-count <gdb:breakpoint>) -> integer */
659 gdbscm_breakpoint_hit_count (SCM self
)
661 breakpoint_smob
*bp_smob
662 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
664 return scm_from_long (bp_smob
->bp
->hit_count
);
667 /* (set-breakpoint-hit-count! <gdb:breakpoint> integer) -> unspecified */
670 gdbscm_set_breakpoint_hit_count_x (SCM self
, SCM newvalue
)
672 breakpoint_smob
*bp_smob
673 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
676 SCM_ASSERT_TYPE (scm_is_signed_integer (newvalue
, LONG_MIN
, LONG_MAX
),
677 newvalue
, SCM_ARG2
, FUNC_NAME
, _("integer"));
679 value
= scm_to_long (newvalue
);
685 gdbscm_out_of_range_error (FUNC_NAME
, SCM_ARG2
, newvalue
,
686 _("hit-count must be zero"));
689 bp_smob
->bp
->hit_count
= 0;
691 return SCM_UNSPECIFIED
;
694 /* (breakpoint-thread <gdb:breakpoint>) -> integer */
697 gdbscm_breakpoint_thread (SCM self
)
699 breakpoint_smob
*bp_smob
700 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
702 if (bp_smob
->bp
->thread
== -1)
705 return scm_from_long (bp_smob
->bp
->thread
);
708 /* (set-breakpoint-thread! <gdb:breakpoint> integer) -> unspecified */
711 gdbscm_set_breakpoint_thread_x (SCM self
, SCM newvalue
)
713 breakpoint_smob
*bp_smob
714 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
717 if (scm_is_signed_integer (newvalue
, LONG_MIN
, LONG_MAX
))
719 id
= scm_to_long (newvalue
);
720 if (! valid_thread_id (id
))
722 gdbscm_out_of_range_error (FUNC_NAME
, SCM_ARG2
, newvalue
,
723 _("invalid thread id"));
726 else if (gdbscm_is_false (newvalue
))
729 SCM_ASSERT_TYPE (0, newvalue
, SCM_ARG2
, FUNC_NAME
, _("integer or #f"));
731 breakpoint_set_thread (bp_smob
->bp
, id
);
733 return SCM_UNSPECIFIED
;
736 /* (breakpoint-task <gdb:breakpoint>) -> integer */
739 gdbscm_breakpoint_task (SCM self
)
741 breakpoint_smob
*bp_smob
742 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
744 if (bp_smob
->bp
->task
== 0)
747 return scm_from_long (bp_smob
->bp
->task
);
750 /* (set-breakpoint-task! <gdb:breakpoint> integer) -> unspecified */
753 gdbscm_set_breakpoint_task_x (SCM self
, SCM newvalue
)
755 breakpoint_smob
*bp_smob
756 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
759 volatile struct gdb_exception except
;
761 if (scm_is_signed_integer (newvalue
, LONG_MIN
, LONG_MAX
))
763 id
= scm_to_long (newvalue
);
765 TRY_CATCH (except
, RETURN_MASK_ALL
)
767 valid_id
= valid_task_id (id
);
769 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
773 gdbscm_out_of_range_error (FUNC_NAME
, SCM_ARG2
, newvalue
,
774 _("invalid task id"));
777 else if (gdbscm_is_false (newvalue
))
780 SCM_ASSERT_TYPE (0, newvalue
, SCM_ARG2
, FUNC_NAME
, _("integer or #f"));
782 TRY_CATCH (except
, RETURN_MASK_ALL
)
784 breakpoint_set_task (bp_smob
->bp
, id
);
786 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
788 return SCM_UNSPECIFIED
;
791 /* (breakpoint-location <gdb:breakpoint>) -> string */
794 gdbscm_breakpoint_location (SCM self
)
796 breakpoint_smob
*bp_smob
797 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
800 if (bp_smob
->bp
->type
!= bp_breakpoint
)
803 str
= bp_smob
->bp
->addr_string
;
807 return gdbscm_scm_from_c_string (str
);
810 /* (breakpoint-expression <gdb:breakpoint>) -> string
811 This is only valid for watchpoints.
812 Returns #f for non-watchpoints. */
815 gdbscm_breakpoint_expression (SCM self
)
817 breakpoint_smob
*bp_smob
818 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
820 struct watchpoint
*wp
;
822 if (!is_watchpoint (bp_smob
->bp
))
825 wp
= (struct watchpoint
*) bp_smob
->bp
;
827 str
= wp
->exp_string
;
831 return gdbscm_scm_from_c_string (str
);
834 /* (breakpoint-condition <gdb:breakpoint>) -> string */
837 gdbscm_breakpoint_condition (SCM self
)
839 breakpoint_smob
*bp_smob
840 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
843 str
= bp_smob
->bp
->cond_string
;
847 return gdbscm_scm_from_c_string (str
);
850 /* (set-breakpoint-condition! <gdb:breakpoint> string|#f)
854 gdbscm_set_breakpoint_condition_x (SCM self
, SCM newvalue
)
856 breakpoint_smob
*bp_smob
857 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
859 volatile struct gdb_exception except
;
861 SCM_ASSERT_TYPE (scm_is_string (newvalue
) || gdbscm_is_false (newvalue
),
862 newvalue
, SCM_ARG2
, FUNC_NAME
,
865 if (gdbscm_is_false (newvalue
))
868 exp
= gdbscm_scm_to_c_string (newvalue
);
870 TRY_CATCH (except
, RETURN_MASK_ALL
)
872 set_breakpoint_condition (bp_smob
->bp
, exp
? exp
: "", 0);
875 GDBSCM_HANDLE_GDB_EXCEPTION (except
);
877 return SCM_UNSPECIFIED
;
880 /* (breakpoint-stop <gdb:breakpoint>) -> procedure or #f */
883 gdbscm_breakpoint_stop (SCM self
)
885 breakpoint_smob
*bp_smob
886 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
888 return bp_smob
->stop
;
891 /* (set-breakpoint-stop! <gdb:breakpoint> procedure|#f)
895 gdbscm_set_breakpoint_stop_x (SCM self
, SCM newvalue
)
897 breakpoint_smob
*bp_smob
898 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
899 const struct extension_language_defn
*extlang
= NULL
;
901 SCM_ASSERT_TYPE (gdbscm_is_procedure (newvalue
)
902 || gdbscm_is_false (newvalue
),
903 newvalue
, SCM_ARG2
, FUNC_NAME
,
904 _("procedure or #f"));
906 if (bp_smob
->bp
->cond_string
!= NULL
)
907 extlang
= get_ext_lang_defn (EXT_LANG_GDB
);
909 extlang
= get_breakpoint_cond_ext_lang (bp_smob
->bp
, EXT_LANG_GUILE
);
913 = xstrprintf (_("Only one stop condition allowed. There is"
914 " currently a %s stop condition defined for"
915 " this breakpoint."),
916 ext_lang_capitalized_name (extlang
));
918 scm_dynwind_begin (0);
919 gdbscm_dynwind_xfree (error_text
);
920 gdbscm_out_of_range_error (FUNC_NAME
, SCM_ARG1
, self
, error_text
);
921 /* The following line, while unnecessary, is present for completeness
926 bp_smob
->stop
= newvalue
;
928 return SCM_UNSPECIFIED
;
931 /* (breakpoint-commands <gdb:breakpoint>) -> string */
934 gdbscm_breakpoint_commands (SCM self
)
936 breakpoint_smob
*bp_smob
937 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
938 struct breakpoint
*bp
;
940 volatile struct gdb_exception except
;
941 struct ui_file
*string_file
;
942 struct cleanup
*chain
;
948 if (bp
->commands
== NULL
)
951 string_file
= mem_fileopen ();
952 chain
= make_cleanup_ui_file_delete (string_file
);
954 ui_out_redirect (current_uiout
, string_file
);
955 TRY_CATCH (except
, RETURN_MASK_ALL
)
957 print_command_lines (current_uiout
, breakpoint_commands (bp
), 0);
959 ui_out_redirect (current_uiout
, NULL
);
960 if (except
.reason
< 0)
963 gdbscm_throw_gdb_exception (except
);
966 cmdstr
= ui_file_xstrdup (string_file
, &length
);
967 make_cleanup (xfree
, cmdstr
);
968 result
= gdbscm_scm_from_c_string (cmdstr
);
974 /* (breakpoint-type <gdb:breakpoint>) -> integer */
977 gdbscm_breakpoint_type (SCM self
)
979 breakpoint_smob
*bp_smob
980 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
982 return scm_from_long (bp_smob
->bp
->type
);
985 /* (breakpoint-visible? <gdb:breakpoint>) -> boolean */
988 gdbscm_breakpoint_visible (SCM self
)
990 breakpoint_smob
*bp_smob
991 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
993 return scm_from_bool (bp_smob
->bp
->number
>= 0);
996 /* (breakpoint-number <gdb:breakpoint>) -> integer */
999 gdbscm_breakpoint_number (SCM self
)
1001 breakpoint_smob
*bp_smob
1002 = bpscm_get_valid_breakpoint_smob_arg_unsafe (self
, SCM_ARG1
, FUNC_NAME
);
1004 return scm_from_long (bp_smob
->number
);
1007 /* Return TRUE if "stop" has been set for this breakpoint.
1009 This is the extension_language_ops.breakpoint_has_cond "method". */
1012 gdbscm_breakpoint_has_cond (const struct extension_language_defn
*extlang
,
1013 struct breakpoint
*b
)
1015 breakpoint_smob
*bp_smob
= b
->scm_bp_object
;
1017 if (bp_smob
== NULL
)
1020 return gdbscm_is_procedure (bp_smob
->stop
);
1023 /* Call the "stop" method in the breakpoint class.
1024 This must only be called if gdbscm_breakpoint_has_cond returns true.
1025 If the stop method returns #t, the inferior will be stopped at the
1026 breakpoint. Otherwise the inferior will be allowed to continue
1027 (assuming other conditions don't indicate "stop").
1029 This is the extension_language_ops.breakpoint_cond_says_stop "method". */
1031 enum ext_lang_bp_stop
1032 gdbscm_breakpoint_cond_says_stop
1033 (const struct extension_language_defn
*extlang
, struct breakpoint
*b
)
1035 breakpoint_smob
*bp_smob
= b
->scm_bp_object
;
1036 SCM predicate_result
;
1039 if (bp_smob
== NULL
)
1040 return EXT_LANG_BP_STOP_UNSET
;
1041 if (!gdbscm_is_procedure (bp_smob
->stop
))
1042 return EXT_LANG_BP_STOP_UNSET
;
1047 = gdbscm_safe_call_1 (bp_smob
->stop
, bp_smob
->containing_scm
, NULL
);
1049 if (gdbscm_is_exception (predicate_result
))
1050 ; /* Exception already printed. */
1051 /* If the "stop" function returns #f that means
1052 the Scheme breakpoint wants GDB to continue. */
1053 else if (gdbscm_is_false (predicate_result
))
1056 return stop
? EXT_LANG_BP_STOP_YES
: EXT_LANG_BP_STOP_NO
;
1059 /* Event callback functions. */
1061 /* Callback that is used when a breakpoint is created.
1062 For breakpoints created by Scheme, i.e., gdbscm_create_breakpoint_x, finish
1063 object creation by connecting the Scheme wrapper to the gdb object.
1064 We ignore breakpoints created from gdb or python here, we create the
1065 Scheme wrapper for those when there's a need to, e.g.,
1066 gdbscm_breakpoints. */
1069 bpscm_breakpoint_created (struct breakpoint
*bp
)
1073 if (gdbscm_is_false (pending_breakpoint_scm
))
1076 /* Verify our caller error checked the user's request. */
1077 gdb_assert (bpscm_want_scm_wrapper_p (bp
, 1));
1079 bp_scm
= pending_breakpoint_scm
;
1080 pending_breakpoint_scm
= SCM_BOOL_F
;
1082 bpscm_attach_scm_to_breakpoint (bp
, bp_scm
);
1085 /* Callback that is used when a breakpoint is deleted. This will
1086 invalidate the corresponding Scheme object. */
1089 bpscm_breakpoint_deleted (struct breakpoint
*b
)
1091 int num
= b
->number
;
1092 struct breakpoint
*bp
;
1094 /* TODO: Why the lookup? We have B. */
1096 bp
= get_breakpoint (num
);
1099 breakpoint_smob
*bp_smob
= bp
->scm_bp_object
;
1104 bp_smob
->number
= -1;
1105 bp_smob
->stop
= SCM_BOOL_F
;
1106 scm_gc_unprotect_object (bp_smob
->containing_scm
);
1111 /* Initialize the Scheme breakpoint code. */
1113 static const scheme_integer_constant breakpoint_integer_constants
[] =
1115 { "BP_NONE", bp_none
},
1116 { "BP_BREAKPOINT", bp_breakpoint
},
1117 { "BP_WATCHPOINT", bp_watchpoint
},
1118 { "BP_HARDWARE_WATCHPOINT", bp_hardware_watchpoint
},
1119 { "BP_READ_WATCHPOINT", bp_read_watchpoint
},
1120 { "BP_ACCESS_WATCHPOINT", bp_access_watchpoint
},
1122 { "WP_READ", hw_read
},
1123 { "WP_WRITE", hw_write
},
1124 { "WP_ACCESS", hw_access
},
1126 END_INTEGER_CONSTANTS
1129 static const scheme_function breakpoint_functions
[] =
1131 { "make-breakpoint", 1, 0, 1, gdbscm_make_breakpoint
,
1133 Create a GDB breakpoint object.\n\
1136 location [#:type <type>] [#:wp-class <wp-class>] [#:internal <bool>]\n\
1138 <gdb:breakpoint object" },
1140 { "register-breakpoint!", 1, 0, 0, gdbscm_register_breakpoint_x
,
1142 Register a <gdb:breakpoint> object with GDB." },
1144 { "delete-breakpoint!", 1, 0, 0, gdbscm_delete_breakpoint_x
,
1146 Delete the breakpoint from GDB." },
1148 { "breakpoints", 0, 0, 0, gdbscm_breakpoints
,
1150 Return a list of all GDB breakpoints.\n\
1154 { "breakpoint?", 1, 0, 0, gdbscm_breakpoint_p
,
1156 Return #t if the object is a <gdb:breakpoint> object." },
1158 { "breakpoint-valid?", 1, 0, 0, gdbscm_breakpoint_valid_p
,
1160 Return #t if the breakpoint has not been deleted from GDB." },
1162 { "breakpoint-number", 1, 0, 0, gdbscm_breakpoint_number
,
1164 Return the breakpoint's number." },
1166 { "breakpoint-type", 1, 0, 0, gdbscm_breakpoint_type
,
1168 Return the type of the breakpoint." },
1170 { "breakpoint-visible?", 1, 0, 0, gdbscm_breakpoint_visible
,
1172 Return #t if the breakpoint is visible to the user." },
1174 { "breakpoint-location", 1, 0, 0, gdbscm_breakpoint_location
,
1176 Return the location of the breakpoint as specified by the user." },
1178 { "breakpoint-expression", 1, 0, 0, gdbscm_breakpoint_expression
,
1180 Return the expression of the breakpoint as specified by the user.\n\
1181 Valid for watchpoints only, returns #f for non-watchpoints." },
1183 { "breakpoint-enabled?", 1, 0, 0, gdbscm_breakpoint_enabled_p
,
1185 Return #t if the breakpoint is enabled." },
1187 { "set-breakpoint-enabled!", 2, 0, 0, gdbscm_set_breakpoint_enabled_x
,
1189 Set the breakpoint's enabled state.\n\
1191 Arguments: <gdb:breakpoint> boolean" },
1193 { "breakpoint-silent?", 1, 0, 0, gdbscm_breakpoint_silent_p
,
1195 Return #t if the breakpoint is silent." },
1197 { "set-breakpoint-silent!", 2, 0, 0, gdbscm_set_breakpoint_silent_x
,
1199 Set the breakpoint's silent state.\n\
1201 Arguments: <gdb:breakpoint> boolean" },
1203 { "breakpoint-ignore-count", 1, 0, 0, gdbscm_breakpoint_ignore_count
,
1205 Return the breakpoint's \"ignore\" count." },
1207 { "set-breakpoint-ignore-count!", 2, 0, 0,
1208 gdbscm_set_breakpoint_ignore_count_x
,
1210 Set the breakpoint's \"ignore\" count.\n\
1212 Arguments: <gdb:breakpoint> count" },
1214 { "breakpoint-hit-count", 1, 0, 0, gdbscm_breakpoint_hit_count
,
1216 Return the breakpoint's \"hit\" count." },
1218 { "set-breakpoint-hit-count!", 2, 0, 0, gdbscm_set_breakpoint_hit_count_x
,
1220 Set the breakpoint's \"hit\" count. The value must be zero.\n\
1222 Arguments: <gdb:breakpoint> 0" },
1224 { "breakpoint-thread", 1, 0, 0, gdbscm_breakpoint_thread
,
1226 Return the breakpoint's thread id or #f if there isn't one." },
1228 { "set-breakpoint-thread!", 2, 0, 0, gdbscm_set_breakpoint_thread_x
,
1230 Set the thread id for this breakpoint.\n\
1232 Arguments: <gdb:breakpoint> thread-id" },
1234 { "breakpoint-task", 1, 0, 0, gdbscm_breakpoint_task
,
1236 Return the breakpoint's Ada task-id or #f if there isn't one." },
1238 { "set-breakpoint-task!", 2, 0, 0, gdbscm_set_breakpoint_task_x
,
1240 Set the breakpoint's Ada task-id.\n\
1242 Arguments: <gdb:breakpoint> task-id" },
1244 { "breakpoint-condition", 1, 0, 0, gdbscm_breakpoint_condition
,
1246 Return the breakpoint's condition as specified by the user.\n\
1247 Return #f if there isn't one." },
1249 { "set-breakpoint-condition!", 2, 0, 0, gdbscm_set_breakpoint_condition_x
,
1251 Set the breakpoint's condition.\n\
1253 Arguments: <gdb:breakpoint> condition\n\
1254 condition: a string" },
1256 { "breakpoint-stop", 1, 0, 0, gdbscm_breakpoint_stop
,
1258 Return the breakpoint's stop predicate.\n\
1259 Return #f if there isn't one." },
1261 { "set-breakpoint-stop!", 2, 0, 0, gdbscm_set_breakpoint_stop_x
,
1263 Set the breakpoint's stop predicate.\n\
1265 Arguments: <gdb:breakpoint> procedure\n\
1266 procedure: A procedure of one argument, the breakpoint.\n\
1267 Its result is true if program execution should stop." },
1269 { "breakpoint-commands", 1, 0, 0, gdbscm_breakpoint_commands
,
1271 Return the breakpoint's commands." },
1277 gdbscm_initialize_breakpoints (void)
1280 = gdbscm_make_smob_type (breakpoint_smob_name
, sizeof (breakpoint_smob
));
1281 scm_set_smob_free (breakpoint_smob_tag
, bpscm_free_breakpoint_smob
);
1282 scm_set_smob_print (breakpoint_smob_tag
, bpscm_print_breakpoint_smob
);
1284 observer_attach_breakpoint_created (bpscm_breakpoint_created
);
1285 observer_attach_breakpoint_deleted (bpscm_breakpoint_deleted
);
1287 gdbscm_define_integer_constants (breakpoint_integer_constants
, 1);
1288 gdbscm_define_functions (breakpoint_functions
, 1);
1290 type_keyword
= scm_from_latin1_keyword ("type");
1291 wp_class_keyword
= scm_from_latin1_keyword ("wp-class");
1292 internal_keyword
= scm_from_latin1_keyword ("internal");