1 /* Python interface to breakpoints
3 Copyright (C) 2008-2017 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/>. */
22 #include "python-internal.h"
25 #include "breakpoint.h"
27 #include "gdbthread.h"
29 #include "cli/cli-script.h"
31 #include "arch-utils.h"
36 /* Number of live breakpoints. */
39 /* Variables used to pass information between the Breakpoint
40 constructor and the breakpoint-created hook function. */
41 gdbpy_breakpoint_object
*bppy_pending_object
;
43 /* Function that is called when a Python condition is evaluated. */
44 static char * const stop_func
= "stop";
46 /* This is used to initialize various gdb.bp_* constants. */
55 /* Entries related to the type of user set breakpoints. */
56 static struct pybp_code pybp_codes
[] =
58 { "BP_NONE", bp_none
},
59 { "BP_BREAKPOINT", bp_breakpoint
},
60 { "BP_WATCHPOINT", bp_watchpoint
},
61 { "BP_HARDWARE_WATCHPOINT", bp_hardware_watchpoint
},
62 { "BP_READ_WATCHPOINT", bp_read_watchpoint
},
63 { "BP_ACCESS_WATCHPOINT", bp_access_watchpoint
},
64 {NULL
} /* Sentinel. */
67 /* Entries related to the type of watchpoint. */
68 static struct pybp_code pybp_watch_types
[] =
70 { "WP_READ", hw_read
},
71 { "WP_WRITE", hw_write
},
72 { "WP_ACCESS", hw_access
},
73 {NULL
} /* Sentinel. */
76 /* Python function which checks the validity of a breakpoint object. */
78 bppy_is_valid (PyObject
*self
, PyObject
*args
)
80 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
87 /* Python function to test whether or not the breakpoint is enabled. */
89 bppy_get_enabled (PyObject
*self
, void *closure
)
91 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
93 BPPY_REQUIRE_VALID (self_bp
);
96 if (self_bp
->bp
->enable_state
== bp_enabled
)
101 /* Python function to test whether or not the breakpoint is silent. */
103 bppy_get_silent (PyObject
*self
, void *closure
)
105 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
107 BPPY_REQUIRE_VALID (self_bp
);
108 if (self_bp
->bp
->silent
)
113 /* Python function to set the enabled state of a breakpoint. */
115 bppy_set_enabled (PyObject
*self
, PyObject
*newvalue
, void *closure
)
117 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
120 BPPY_SET_REQUIRE_VALID (self_bp
);
122 if (newvalue
== NULL
)
124 PyErr_SetString (PyExc_TypeError
,
125 _("Cannot delete `enabled' attribute."));
129 else if (! PyBool_Check (newvalue
))
131 PyErr_SetString (PyExc_TypeError
,
132 _("The value of `enabled' must be a boolean."));
136 cmp
= PyObject_IsTrue (newvalue
);
143 enable_breakpoint (self_bp
->bp
);
145 disable_breakpoint (self_bp
->bp
);
147 CATCH (except
, RETURN_MASK_ALL
)
149 GDB_PY_SET_HANDLE_EXCEPTION (except
);
156 /* Python function to set the 'silent' state of a breakpoint. */
158 bppy_set_silent (PyObject
*self
, PyObject
*newvalue
, void *closure
)
160 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
163 BPPY_SET_REQUIRE_VALID (self_bp
);
165 if (newvalue
== NULL
)
167 PyErr_SetString (PyExc_TypeError
,
168 _("Cannot delete `silent' attribute."));
171 else if (! PyBool_Check (newvalue
))
173 PyErr_SetString (PyExc_TypeError
,
174 _("The value of `silent' must be a boolean."));
178 cmp
= PyObject_IsTrue (newvalue
);
182 breakpoint_set_silent (self_bp
->bp
, cmp
);
187 /* Python function to set the thread of a breakpoint. */
189 bppy_set_thread (PyObject
*self
, PyObject
*newvalue
, void *closure
)
191 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
194 BPPY_SET_REQUIRE_VALID (self_bp
);
196 if (newvalue
== NULL
)
198 PyErr_SetString (PyExc_TypeError
,
199 _("Cannot delete `thread' attribute."));
202 else if (PyInt_Check (newvalue
))
204 if (! gdb_py_int_as_long (newvalue
, &id
))
207 if (!valid_global_thread_id (id
))
209 PyErr_SetString (PyExc_RuntimeError
,
210 _("Invalid thread ID."));
214 else if (newvalue
== Py_None
)
218 PyErr_SetString (PyExc_TypeError
,
219 _("The value of `thread' must be an integer or None."));
223 breakpoint_set_thread (self_bp
->bp
, id
);
228 /* Python function to set the (Ada) task of a breakpoint. */
230 bppy_set_task (PyObject
*self
, PyObject
*newvalue
, void *closure
)
232 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
236 BPPY_SET_REQUIRE_VALID (self_bp
);
238 if (newvalue
== NULL
)
240 PyErr_SetString (PyExc_TypeError
,
241 _("Cannot delete `task' attribute."));
244 else if (PyInt_Check (newvalue
))
246 if (! gdb_py_int_as_long (newvalue
, &id
))
251 valid_id
= valid_task_id (id
);
253 CATCH (except
, RETURN_MASK_ALL
)
255 GDB_PY_SET_HANDLE_EXCEPTION (except
);
261 PyErr_SetString (PyExc_RuntimeError
,
262 _("Invalid task ID."));
266 else if (newvalue
== Py_None
)
270 PyErr_SetString (PyExc_TypeError
,
271 _("The value of `task' must be an integer or None."));
275 breakpoint_set_task (self_bp
->bp
, id
);
280 /* Python function which deletes the underlying GDB breakpoint. This
281 triggers the breakpoint_deleted observer which will call
282 gdbpy_breakpoint_deleted; that function cleans up the Python
286 bppy_delete_breakpoint (PyObject
*self
, PyObject
*args
)
288 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
290 BPPY_REQUIRE_VALID (self_bp
);
294 delete_breakpoint (self_bp
->bp
);
296 CATCH (except
, RETURN_MASK_ALL
)
298 GDB_PY_HANDLE_EXCEPTION (except
);
306 /* Python function to set the ignore count of a breakpoint. */
308 bppy_set_ignore_count (PyObject
*self
, PyObject
*newvalue
, void *closure
)
310 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
313 BPPY_SET_REQUIRE_VALID (self_bp
);
315 if (newvalue
== NULL
)
317 PyErr_SetString (PyExc_TypeError
,
318 _("Cannot delete `ignore_count' attribute."));
321 else if (! PyInt_Check (newvalue
))
323 PyErr_SetString (PyExc_TypeError
,
324 _("The value of `ignore_count' must be an integer."));
328 if (! gdb_py_int_as_long (newvalue
, &value
))
336 set_ignore_count (self_bp
->number
, (int) value
, 0);
338 CATCH (except
, RETURN_MASK_ALL
)
340 GDB_PY_SET_HANDLE_EXCEPTION (except
);
347 /* Python function to set the hit count of a breakpoint. */
349 bppy_set_hit_count (PyObject
*self
, PyObject
*newvalue
, void *closure
)
351 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
353 BPPY_SET_REQUIRE_VALID (self_bp
);
355 if (newvalue
== NULL
)
357 PyErr_SetString (PyExc_TypeError
,
358 _("Cannot delete `hit_count' attribute."));
365 if (! gdb_py_int_as_long (newvalue
, &value
))
370 PyErr_SetString (PyExc_AttributeError
,
371 _("The value of `hit_count' must be zero."));
376 self_bp
->bp
->hit_count
= 0;
381 /* Python function to get the location of a breakpoint. */
383 bppy_get_location (PyObject
*self
, void *closure
)
386 gdbpy_breakpoint_object
*obj
= (gdbpy_breakpoint_object
*) self
;
388 BPPY_REQUIRE_VALID (obj
);
390 if (obj
->bp
->type
!= bp_breakpoint
)
393 str
= event_location_to_string (obj
->bp
->location
);
396 return host_string_to_python_string (str
);
399 /* Python function to get the breakpoint expression. */
401 bppy_get_expression (PyObject
*self
, void *closure
)
404 gdbpy_breakpoint_object
*obj
= (gdbpy_breakpoint_object
*) self
;
405 struct watchpoint
*wp
;
407 BPPY_REQUIRE_VALID (obj
);
409 if (!is_watchpoint (obj
->bp
))
412 wp
= (struct watchpoint
*) obj
->bp
;
414 str
= wp
->exp_string
;
418 return host_string_to_python_string (str
);
421 /* Python function to get the condition expression of a breakpoint. */
423 bppy_get_condition (PyObject
*self
, void *closure
)
426 gdbpy_breakpoint_object
*obj
= (gdbpy_breakpoint_object
*) self
;
428 BPPY_REQUIRE_VALID (obj
);
430 str
= obj
->bp
->cond_string
;
434 return host_string_to_python_string (str
);
437 /* Returns 0 on success. Returns -1 on error, with a python exception set.
441 bppy_set_condition (PyObject
*self
, PyObject
*newvalue
, void *closure
)
443 gdb::unique_xmalloc_ptr
<char> exp_holder
;
444 const char *exp
= NULL
;
445 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
446 struct gdb_exception except
= exception_none
;
448 BPPY_SET_REQUIRE_VALID (self_bp
);
450 if (newvalue
== NULL
)
452 PyErr_SetString (PyExc_TypeError
,
453 _("Cannot delete `condition' attribute."));
456 else if (newvalue
== Py_None
)
460 exp_holder
= python_string_to_host_string (newvalue
);
461 if (exp_holder
== NULL
)
463 exp
= exp_holder
.get ();
468 set_breakpoint_condition (self_bp
->bp
, exp
, 0);
470 CATCH (ex
, RETURN_MASK_ALL
)
476 GDB_PY_SET_HANDLE_EXCEPTION (except
);
481 /* Python function to get the commands attached to a breakpoint. */
483 bppy_get_commands (PyObject
*self
, void *closure
)
485 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
486 struct breakpoint
*bp
= self_bp
->bp
;
488 struct ui_file
*string_file
;
490 struct cleanup
*chain
;
492 BPPY_REQUIRE_VALID (self_bp
);
494 if (! self_bp
->bp
->commands
)
497 string_file
= mem_fileopen ();
498 chain
= make_cleanup_ui_file_delete (string_file
);
500 current_uiout
->redirect (string_file
);
503 print_command_lines (current_uiout
, breakpoint_commands (bp
), 0);
505 CATCH (except
, RETURN_MASK_ALL
)
507 current_uiout
->redirect (NULL
);
509 gdbpy_convert_exception (except
);
514 current_uiout
->redirect (NULL
);
515 std::string cmdstr
= ui_file_as_string (string_file
);
516 result
= host_string_to_python_string (cmdstr
.c_str ());
521 /* Python function to get the breakpoint type. */
523 bppy_get_type (PyObject
*self
, void *closure
)
525 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
527 BPPY_REQUIRE_VALID (self_bp
);
529 return PyInt_FromLong (self_bp
->bp
->type
);
532 /* Python function to get the visibility of the breakpoint. */
535 bppy_get_visibility (PyObject
*self
, void *closure
)
537 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
539 BPPY_REQUIRE_VALID (self_bp
);
541 if (user_breakpoint_p (self_bp
->bp
))
547 /* Python function to determine if the breakpoint is a temporary
551 bppy_get_temporary (PyObject
*self
, void *closure
)
553 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
555 BPPY_REQUIRE_VALID (self_bp
);
557 if (self_bp
->bp
->disposition
== disp_del
558 || self_bp
->bp
->disposition
== disp_del_at_next_stop
)
564 /* Python function to determine if the breakpoint is a pending
568 bppy_get_pending (PyObject
*self
, void *closure
)
570 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
572 BPPY_REQUIRE_VALID (self_bp
);
574 if (is_watchpoint (self_bp
->bp
))
576 if (pending_breakpoint_p (self_bp
->bp
))
582 /* Python function to get the breakpoint's number. */
584 bppy_get_number (PyObject
*self
, void *closure
)
586 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
588 BPPY_REQUIRE_VALID (self_bp
);
590 return PyInt_FromLong (self_bp
->number
);
593 /* Python function to get the breakpoint's thread ID. */
595 bppy_get_thread (PyObject
*self
, void *closure
)
597 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
599 BPPY_REQUIRE_VALID (self_bp
);
601 if (self_bp
->bp
->thread
== -1)
604 return PyInt_FromLong (self_bp
->bp
->thread
);
607 /* Python function to get the breakpoint's task ID (in Ada). */
609 bppy_get_task (PyObject
*self
, void *closure
)
611 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
613 BPPY_REQUIRE_VALID (self_bp
);
615 if (self_bp
->bp
->task
== 0)
618 return PyInt_FromLong (self_bp
->bp
->task
);
621 /* Python function to get the breakpoint's hit count. */
623 bppy_get_hit_count (PyObject
*self
, void *closure
)
625 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
627 BPPY_REQUIRE_VALID (self_bp
);
629 return PyInt_FromLong (self_bp
->bp
->hit_count
);
632 /* Python function to get the breakpoint's ignore count. */
634 bppy_get_ignore_count (PyObject
*self
, void *closure
)
636 gdbpy_breakpoint_object
*self_bp
= (gdbpy_breakpoint_object
*) self
;
638 BPPY_REQUIRE_VALID (self_bp
);
640 return PyInt_FromLong (self_bp
->bp
->ignore_count
);
643 /* Python function to create a new breakpoint. */
645 bppy_init (PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
647 static char *keywords
[] = { "spec", "type", "wp_class", "internal",
650 int type
= bp_breakpoint
;
651 int access_type
= hw_write
;
652 PyObject
*internal
= NULL
;
653 PyObject
*temporary
= NULL
;
655 int temporary_bp
= 0;
657 if (! PyArg_ParseTupleAndKeywords (args
, kwargs
, "s|iiOO", keywords
,
658 &spec
, &type
, &access_type
,
659 &internal
, &temporary
))
664 internal_bp
= PyObject_IsTrue (internal
);
665 if (internal_bp
== -1)
669 if (temporary
!= NULL
)
671 temporary_bp
= PyObject_IsTrue (temporary
);
672 if (temporary_bp
== -1)
676 bppy_pending_object
= (gdbpy_breakpoint_object
*) self
;
677 bppy_pending_object
->number
= -1;
678 bppy_pending_object
->bp
= NULL
;
682 gdb::unique_xmalloc_ptr
<char>
683 copy_holder (xstrdup (skip_spaces_const (spec
)));
684 char *copy
= copy_holder
.get ();
690 struct event_location
*location
;
691 struct cleanup
*cleanup
;
694 = string_to_event_location_basic (©
, current_language
);
695 cleanup
= make_cleanup_delete_event_location (location
);
696 create_breakpoint (python_gdbarch
,
697 location
, NULL
, -1, NULL
,
699 temporary_bp
, bp_breakpoint
,
702 &bkpt_breakpoint_ops
,
703 0, 1, internal_bp
, 0);
705 do_cleanups (cleanup
);
710 if (access_type
== hw_write
)
711 watch_command_wrapper (copy
, 0, internal_bp
);
712 else if (access_type
== hw_access
)
713 awatch_command_wrapper (copy
, 0, internal_bp
);
714 else if (access_type
== hw_read
)
715 rwatch_command_wrapper (copy
, 0, internal_bp
);
717 error(_("Cannot understand watchpoint access type."));
721 error(_("Do not understand breakpoint type to set."));
724 CATCH (except
, RETURN_MASK_ALL
)
726 bppy_pending_object
= NULL
;
727 PyErr_Format (except
.reason
== RETURN_QUIT
728 ? PyExc_KeyboardInterrupt
: PyExc_RuntimeError
,
729 "%s", except
.message
);
734 BPPY_SET_REQUIRE_VALID ((gdbpy_breakpoint_object
*) self
);
741 build_bp_list (struct breakpoint
*b
, void *arg
)
743 PyObject
*list
= (PyObject
*) arg
;
744 PyObject
*bp
= (PyObject
*) b
->py_bp_object
;
747 /* Not all breakpoints will have a companion Python object.
748 Only breakpoints that were created via bppy_new, or
749 breakpoints that were created externally and are tracked by
750 the Python Scripting API. */
752 iserr
= PyList_Append (list
, bp
);
760 /* Static function to return a tuple holding all breakpoints. */
763 gdbpy_breakpoints (PyObject
*self
, PyObject
*args
)
766 return PyTuple_New (0);
768 gdbpy_ref
list (PyList_New (0));
772 /* If iterate_over_breakpoints returns non NULL it signals an error
773 condition. In that case abandon building the list and return
775 if (iterate_over_breakpoints (build_bp_list
, list
.get ()) != NULL
)
778 return PyList_AsTuple (list
.get ());
781 /* Call the "stop" method (if implemented) in the breakpoint
782 class. If the method returns True, the inferior will be
783 stopped at the breakpoint. Otherwise the inferior will be
784 allowed to continue. */
786 enum ext_lang_bp_stop
787 gdbpy_breakpoint_cond_says_stop (const struct extension_language_defn
*extlang
,
788 struct breakpoint
*b
)
791 struct gdbpy_breakpoint_object
*bp_obj
= b
->py_bp_object
;
792 PyObject
*py_bp
= (PyObject
*) bp_obj
;
793 struct gdbarch
*garch
;
794 struct cleanup
*cleanup
;
797 return EXT_LANG_BP_STOP_UNSET
;
800 garch
= b
->gdbarch
? b
->gdbarch
: get_current_arch ();
801 cleanup
= ensure_python_env (garch
, current_language
);
803 if (bp_obj
->is_finish_bp
)
804 bpfinishpy_pre_stop_hook (bp_obj
);
806 if (PyObject_HasAttrString (py_bp
, stop_func
))
808 PyObject
*result
= PyObject_CallMethod (py_bp
, stop_func
, NULL
);
813 int evaluate
= PyObject_IsTrue (result
);
816 gdbpy_print_stack ();
818 /* If the "stop" function returns False that means
819 the Python breakpoint wants GDB to continue. */
826 gdbpy_print_stack ();
829 if (bp_obj
->is_finish_bp
)
830 bpfinishpy_post_stop_hook (bp_obj
);
832 do_cleanups (cleanup
);
835 return EXT_LANG_BP_STOP_UNSET
;
836 return stop
? EXT_LANG_BP_STOP_YES
: EXT_LANG_BP_STOP_NO
;
839 /* Checks if the "stop" method exists in this breakpoint.
840 Used by condition_command to ensure mutual exclusion of breakpoint
844 gdbpy_breakpoint_has_cond (const struct extension_language_defn
*extlang
,
845 struct breakpoint
*b
)
849 struct gdbarch
*garch
;
850 struct cleanup
*cleanup
;
852 if (b
->py_bp_object
== NULL
)
855 py_bp
= (PyObject
*) b
->py_bp_object
;
856 garch
= b
->gdbarch
? b
->gdbarch
: get_current_arch ();
857 cleanup
= ensure_python_env (garch
, current_language
);
858 has_func
= PyObject_HasAttrString (py_bp
, stop_func
);
859 do_cleanups (cleanup
);
866 /* Event callback functions. */
868 /* Callback that is used when a breakpoint is created. This function
869 will create a new Python breakpoint object. */
871 gdbpy_breakpoint_created (struct breakpoint
*bp
)
873 gdbpy_breakpoint_object
*newbp
;
874 PyGILState_STATE state
;
876 if (!user_breakpoint_p (bp
) && bppy_pending_object
== NULL
)
879 if (bp
->type
!= bp_breakpoint
880 && bp
->type
!= bp_watchpoint
881 && bp
->type
!= bp_hardware_watchpoint
882 && bp
->type
!= bp_read_watchpoint
883 && bp
->type
!= bp_access_watchpoint
)
886 state
= PyGILState_Ensure ();
888 if (bppy_pending_object
)
890 newbp
= bppy_pending_object
;
891 bppy_pending_object
= NULL
;
894 newbp
= PyObject_New (gdbpy_breakpoint_object
, &breakpoint_object_type
);
897 newbp
->number
= bp
->number
;
899 newbp
->bp
->py_bp_object
= newbp
;
900 newbp
->is_finish_bp
= 0;
906 PyErr_SetString (PyExc_RuntimeError
,
907 _("Error while creating breakpoint from GDB."));
908 gdbpy_print_stack ();
911 if (!evregpy_no_listeners_p (gdb_py_events
.breakpoint_created
))
913 if (evpy_emit_event ((PyObject
*) newbp
,
914 gdb_py_events
.breakpoint_created
) < 0)
915 gdbpy_print_stack ();
918 PyGILState_Release (state
);
921 /* Callback that is used when a breakpoint is deleted. This will
922 invalidate the corresponding Python object. */
924 gdbpy_breakpoint_deleted (struct breakpoint
*b
)
927 PyGILState_STATE state
;
928 struct breakpoint
*bp
= NULL
;
929 gdbpy_breakpoint_object
*bp_obj
;
931 state
= PyGILState_Ensure ();
932 bp
= get_breakpoint (num
);
935 bp_obj
= bp
->py_bp_object
;
938 if (!evregpy_no_listeners_p (gdb_py_events
.breakpoint_deleted
))
940 if (evpy_emit_event ((PyObject
*) bp_obj
,
941 gdb_py_events
.breakpoint_deleted
) < 0)
942 gdbpy_print_stack ();
950 PyGILState_Release (state
);
953 /* Callback that is used when a breakpoint is modified. */
956 gdbpy_breakpoint_modified (struct breakpoint
*b
)
959 PyGILState_STATE state
;
960 struct breakpoint
*bp
= NULL
;
961 gdbpy_breakpoint_object
*bp_obj
;
963 state
= PyGILState_Ensure ();
964 bp
= get_breakpoint (num
);
967 PyObject
*bp_obj
= (PyObject
*) bp
->py_bp_object
;
970 if (!evregpy_no_listeners_p (gdb_py_events
.breakpoint_modified
))
972 if (evpy_emit_event (bp_obj
,
973 gdb_py_events
.breakpoint_modified
) < 0)
974 gdbpy_print_stack ();
978 PyGILState_Release (state
);
983 /* Initialize the Python breakpoint code. */
985 gdbpy_initialize_breakpoints (void)
989 breakpoint_object_type
.tp_new
= PyType_GenericNew
;
990 if (PyType_Ready (&breakpoint_object_type
) < 0)
993 if (gdb_pymodule_addobject (gdb_module
, "Breakpoint",
994 (PyObject
*) &breakpoint_object_type
) < 0)
997 observer_attach_breakpoint_created (gdbpy_breakpoint_created
);
998 observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted
);
999 observer_attach_breakpoint_modified (gdbpy_breakpoint_modified
);
1001 /* Add breakpoint types constants. */
1002 for (i
= 0; pybp_codes
[i
].name
; ++i
)
1004 if (PyModule_AddIntConstant (gdb_module
,
1005 /* Cast needed for Python 2.4. */
1006 (char *) pybp_codes
[i
].name
,
1007 pybp_codes
[i
].code
) < 0)
1011 /* Add watchpoint types constants. */
1012 for (i
= 0; pybp_watch_types
[i
].name
; ++i
)
1014 if (PyModule_AddIntConstant (gdb_module
,
1015 /* Cast needed for Python 2.4. */
1016 (char *) pybp_watch_types
[i
].name
,
1017 pybp_watch_types
[i
].code
) < 0)
1026 /* Helper function that overrides this Python object's
1027 PyObject_GenericSetAttr to allow extra validation of the attribute
1031 local_setattro (PyObject
*self
, PyObject
*name
, PyObject
*v
)
1033 gdbpy_breakpoint_object
*obj
= (gdbpy_breakpoint_object
*) self
;
1034 gdb::unique_xmalloc_ptr
<char> attr (python_string_to_host_string (name
));
1039 /* If the attribute trying to be set is the "stop" method,
1040 but we already have a condition set in the CLI or other extension
1041 language, disallow this operation. */
1042 if (strcmp (attr
.get (), stop_func
) == 0)
1044 const struct extension_language_defn
*extlang
= NULL
;
1046 if (obj
->bp
->cond_string
!= NULL
)
1047 extlang
= get_ext_lang_defn (EXT_LANG_GDB
);
1048 if (extlang
== NULL
)
1049 extlang
= get_breakpoint_cond_ext_lang (obj
->bp
, EXT_LANG_PYTHON
);
1050 if (extlang
!= NULL
)
1055 = xstrprintf (_("Only one stop condition allowed. There is"
1056 " currently a %s stop condition defined for"
1057 " this breakpoint."),
1058 ext_lang_capitalized_name (extlang
));
1059 PyErr_SetString (PyExc_RuntimeError
, error_text
);
1065 return PyObject_GenericSetAttr ((PyObject
*)self
, name
, v
);
1068 static PyGetSetDef breakpoint_object_getset
[] = {
1069 { "enabled", bppy_get_enabled
, bppy_set_enabled
,
1070 "Boolean telling whether the breakpoint is enabled.", NULL
},
1071 { "silent", bppy_get_silent
, bppy_set_silent
,
1072 "Boolean telling whether the breakpoint is silent.", NULL
},
1073 { "thread", bppy_get_thread
, bppy_set_thread
,
1074 "Thread ID for the breakpoint.\n\
1075 If the value is a thread ID (integer), then this is a thread-specific breakpoint.\n\
1076 If the value is None, then this breakpoint is not thread-specific.\n\
1077 No other type of value can be used.", NULL
},
1078 { "task", bppy_get_task
, bppy_set_task
,
1079 "Thread ID for the breakpoint.\n\
1080 If the value is a task ID (integer), then this is an Ada task-specific breakpoint.\n\
1081 If the value is None, then this breakpoint is not task-specific.\n\
1082 No other type of value can be used.", NULL
},
1083 { "ignore_count", bppy_get_ignore_count
, bppy_set_ignore_count
,
1084 "Number of times this breakpoint should be automatically continued.",
1086 { "number", bppy_get_number
, NULL
,
1087 "Breakpoint's number assigned by GDB.", NULL
},
1088 { "hit_count", bppy_get_hit_count
, bppy_set_hit_count
,
1089 "Number of times the breakpoint has been hit.\n\
1090 Can be set to zero to clear the count. No other value is valid\n\
1091 when setting this property.", NULL
},
1092 { "location", bppy_get_location
, NULL
,
1093 "Location of the breakpoint, as specified by the user.", NULL
},
1094 { "expression", bppy_get_expression
, NULL
,
1095 "Expression of the breakpoint, as specified by the user.", NULL
},
1096 { "condition", bppy_get_condition
, bppy_set_condition
,
1097 "Condition of the breakpoint, as specified by the user,\
1098 or None if no condition set."},
1099 { "commands", bppy_get_commands
, NULL
,
1100 "Commands of the breakpoint, as specified by the user."},
1101 { "type", bppy_get_type
, NULL
,
1102 "Type of breakpoint."},
1103 { "visible", bppy_get_visibility
, NULL
,
1104 "Whether the breakpoint is visible to the user."},
1105 { "temporary", bppy_get_temporary
, NULL
,
1106 "Whether this breakpoint is a temporary breakpoint."},
1107 { "pending", bppy_get_pending
, NULL
,
1108 "Whether this breakpoint is a pending breakpoint."},
1109 { NULL
} /* Sentinel. */
1112 static PyMethodDef breakpoint_object_methods
[] =
1114 { "is_valid", bppy_is_valid
, METH_NOARGS
,
1115 "Return true if this breakpoint is valid, false if not." },
1116 { "delete", bppy_delete_breakpoint
, METH_NOARGS
,
1117 "Delete the underlying GDB breakpoint." },
1118 { NULL
} /* Sentinel. */
1121 PyTypeObject breakpoint_object_type
=
1123 PyVarObject_HEAD_INIT (NULL
, 0)
1124 "gdb.Breakpoint", /*tp_name*/
1125 sizeof (gdbpy_breakpoint_object
), /*tp_basicsize*/
1134 0, /*tp_as_sequence*/
1135 0, /*tp_as_mapping*/
1140 (setattrofunc
)local_setattro
, /*tp_setattro */
1142 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
, /*tp_flags*/
1143 "GDB breakpoint object", /* tp_doc */
1144 0, /* tp_traverse */
1146 0, /* tp_richcompare */
1147 0, /* tp_weaklistoffset */
1149 0, /* tp_iternext */
1150 breakpoint_object_methods
, /* tp_methods */
1152 breakpoint_object_getset
, /* tp_getset */
1155 0, /* tp_descr_get */
1156 0, /* tp_descr_set */
1157 0, /* tp_dictoffset */
1158 bppy_init
, /* tp_init */