53#define BPLOCPY_REQUIRE_VALID(Breakpoint, Location) \
55 if ((Breakpoint)->bp != (Location)->bp_loc->owner) \
56 return PyErr_Format (PyExc_RuntimeError, \
57 _("Breakpoint location is invalid.")); \
62#define BPLOCPY_SET_REQUIRE_VALID(Breakpoint, Location) \
64 if ((Breakpoint)->bp != (Location)->bp_loc->owner) \
66 PyErr_Format (PyExc_RuntimeError, \
67 _("Breakpoint location is invalid.")); \
87#define pybp_debug_printf(fmt, ...) \
88 debug_prefixed_printf_cond (pybp_debug, "py-breakpoint", fmt, ##__VA_ARGS__)
92#define PYBP_SCOPED_DEBUG_ENTER_EXIT \
93 scoped_debug_enter_exit (pybp_debug, "py-breakpoint")
131 {
"WP_READ", hw_read},
132 {
"WP_WRITE", hw_write},
133 {
"WP_ACCESS", hw_access},
183 if (newvalue == NULL)
185 PyErr_SetString (PyExc_TypeError,
186 _(
"Cannot delete `enabled' attribute."));
190 else if (! PyBool_Check (newvalue))
192 PyErr_SetString (PyExc_TypeError,
193 _(
"The value of `enabled' must be a boolean."));
197 cmp = PyObject_IsTrue (newvalue);
208 catch (
const gdb_exception &except)
225 if (newvalue == NULL)
227 PyErr_SetString (PyExc_TypeError,
228 _(
"Cannot delete `silent' attribute."));
231 else if (! PyBool_Check (newvalue))
233 PyErr_SetString (PyExc_TypeError,
234 _(
"The value of `silent' must be a boolean."));
238 cmp = PyObject_IsTrue (newvalue);
256 if (newvalue == NULL)
258 PyErr_SetString (PyExc_TypeError,
259 _(
"Cannot delete `thread' attribute."));
262 else if (PyLong_Check (newvalue))
269 PyErr_SetString (PyExc_RuntimeError,
270 _(
"Invalid thread ID."));
274 else if (newvalue == Py_None)
278 PyErr_SetString (PyExc_TypeError,
279 _(
"The value of `thread' must be an integer or None."));
298 if (newvalue == NULL)
300 PyErr_SetString (PyExc_TypeError,
301 _(
"Cannot delete `task' attribute."));
304 else if (PyLong_Check (newvalue))
313 catch (
const gdb_exception &except)
320 PyErr_SetString (PyExc_RuntimeError,
321 _(
"Invalid task ID."));
325 else if (newvalue == Py_None)
329 PyErr_SetString (PyExc_TypeError,
330 _(
"The value of `task' must be an integer or None."));
355 catch (
const gdb_exception &except)
373 if (newvalue == NULL)
375 PyErr_SetString (PyExc_TypeError,
376 _(
"Cannot delete `ignore_count' attribute."));
379 else if (!PyLong_Check (newvalue))
381 PyErr_SetString (PyExc_TypeError,
382 _(
"The value of `ignore_count' must be an integer."));
396 catch (
const gdb_exception &except)
412 if (newvalue == NULL)
414 PyErr_SetString (PyExc_TypeError,
415 _(
"Cannot delete `hit_count' attribute."));
427 PyErr_SetString (PyExc_AttributeError,
428 _(
"The value of `hit_count' must be zero."));
450 const char *str = obj->
bp->
locspec->to_string ();
500 gdb::unique_xmalloc_ptr<char> exp_holder;
501 const char *
exp = NULL;
503 struct gdb_exception except;
507 if (newvalue == NULL)
509 PyErr_SetString (PyExc_TypeError,
510 _(
"Cannot delete `condition' attribute."));
513 else if (newvalue == Py_None)
518 if (exp_holder == NULL)
520 exp = exp_holder.get ();
527 catch (gdb_exception &ex)
529 except = std::move (ex);
556 catch (
const gdb_exception &except)
571 struct gdb_exception except;
575 gdb::unique_xmalloc_ptr<char> commands
577 if (commands ==
nullptr)
583 char *save_ptr =
nullptr;
585 = [&] (std::string &buffer)
587 const char *result = strtok_r (first ? commands.get () :
nullptr,
596 catch (gdb_exception &ex)
598 except = std::move (ex);
700 if (self_bp->
bp->
task == 0)
745 if (py_bploc ==
nullptr)
752 py_bploc->owner = self_bp;
753 py_bploc->bp_loc = ref.release ();
754 if (PyList_Append (list.get (), (PyObject *) py_bploc.get ()) != 0)
757 return list.release ();
765 char *function,
char *label,
772 if (source != NULL || function != NULL || label != NULL || line != NULL)
774 PyErr_SetString (PyExc_RuntimeError,
775 _(
"Breakpoints specified with spec cannot "
776 "have source, function, label or line defined."));
786 PyErr_SetString (PyExc_RuntimeError,
787 _(
"Watchpoints cannot be set by explicit "
788 "location parameters."));
794 if (source == NULL && function == NULL && label == NULL
797 PyErr_SetString (PyExc_RuntimeError,
798 _(
"Neither spec nor explicit location set."));
803 if (source != NULL && function == NULL && label == NULL
806 PyErr_SetString (PyExc_RuntimeError,
807 _(
"Specifying a source must also include a "
808 "line, label or function."));
818bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
820 static const char *keywords[] = {
"spec",
"type",
"wp_class",
"internal",
821 "temporary",
"source",
"function",
822 "label",
"line",
"qualified", NULL };
823 const char *spec = NULL;
825 int access_type = hw_write;
826 PyObject *internal = NULL;
827 PyObject *temporary = NULL;
828 PyObject *lineobj = NULL;;
830 int temporary_bp = 0;
831 gdb::unique_xmalloc_ptr<char> line;
834 char *function = NULL;
835 PyObject * qualified = NULL;
838 &spec, &
type, &access_type,
841 &function, &label, &lineobj,
848 if (PyLong_Check (lineobj))
849 line = xstrprintf (
"%ld", PyLong_AsLong (lineobj));
850 else if (PyUnicode_Check (lineobj))
854 PyErr_SetString (PyExc_RuntimeError,
855 _(
"Line keyword should be an integer or a string. "));
862 internal_bp = PyObject_IsTrue (internal);
863 if (internal_bp == -1)
867 if (temporary != NULL)
869 temporary_bp = PyObject_IsTrue (temporary);
870 if (temporary_bp == -1)
891 = (qualified != NULL && PyObject_IsTrue (qualified)
897 gdb::unique_xmalloc_ptr<char>
898 copy_holder (xstrdup (skip_spaces (spec)));
899 const char *copy = copy_holder.get ();
903 func_name_match_type);
907 std::unique_ptr<explicit_location_spec> explicit_loc
910 explicit_loc->source_filename
911 = source !=
nullptr ? xstrdup (source) :
nullptr;
912 explicit_loc->function_name
913 = function !=
nullptr ? xstrdup (function) :
nullptr;
914 explicit_loc->label_name
915 = label !=
nullptr ? xstrdup (label) :
nullptr;
918 explicit_loc->line_offset
921 explicit_loc->func_name_match_type = func_name_match_type;
923 locspec.reset (explicit_loc.release ());
930 locspec.get (), NULL, -1, NULL,
false,
936 0, 1, internal_bp, 0);
941 spec = skip_spaces (spec);
943 if (access_type == hw_write)
945 else if (access_type == hw_access)
947 else if (access_type == hw_read)
950 error(_(
"Cannot understand watchpoint access type."));
954 error (_(
"BP_CATCHPOINT not supported"));
956 error(_(
"Do not understand breakpoint type to set."));
959 catch (
const gdb_exception &except)
987 return PyList_Append (list,
bp) == 0;
1016 return PyTuple_New (0);
1028 return PyList_AsTuple (list.get ());
1042 PyObject *py_bp = (PyObject *) bp_obj;
1054 if (PyObject_HasAttrString (py_bp,
stop_func))
1061 int evaluate = PyObject_IsTrue (result.get ());
1099 return PyObject_HasAttrString (py_bp,
stop_func);
1157 PyErr_SetString (PyExc_RuntimeError,
1158 _(
"Error while creating breakpoint from GDB."));
1216 PyObject *bp_obj = (PyObject *)
bp->py_bp_object;
1303 if (strcmp (attr.get (),
stop_func) == 0)
1309 if (extlang == NULL)
1311 if (extlang != NULL)
1313 std::string error_text
1314 = string_printf (_(
"Only one stop condition allowed. There is"
1315 " currently a %s stop condition defined for"
1316 " this breakpoint."),
1318 PyErr_SetString (PyExc_RuntimeError, error_text.c_str ());
1323 return PyObject_GenericSetAttr (self,
name, v);
1328 "Boolean telling whether the breakpoint is enabled.", NULL },
1330 "Boolean telling whether the breakpoint is silent.", NULL },
1332 "Thread ID for the breakpoint.\n\
1333If the value is a thread ID (integer), then this is a thread-specific breakpoint.\n\
1334If the value is None, then this breakpoint is not thread-specific.\n\
1335No other type of value can be used.", NULL },
1337 "Thread ID for the breakpoint.\n\
1338If the value is a task ID (integer), then this is an Ada task-specific breakpoint.\n\
1339If the value is None, then this breakpoint is not task-specific.\n\
1340No other type of value can be used.", NULL },
1342 "Number of times this breakpoint should be automatically continued.",
1345 "Breakpoint's number assigned by GDB.", NULL },
1347 "Number of times the breakpoint has been hit.\n\
1348Can be set to zero to clear the count. No other value is valid\n\
1349when setting this property.", NULL },
1351 "Location of the breakpoint, as specified by the user.", NULL},
1353 "Expression of the breakpoint, as specified by the user.", NULL},
1355 "Condition of the breakpoint, as specified by the user,\
1356or None if no condition set."},
1358 "Commands of the breakpoint, as specified by the user."},
1360 "Type of breakpoint."},
1362 "Whether the breakpoint is visible to the user."},
1364 "Whether this breakpoint is a temporary breakpoint."},
1366 "Whether this breakpoint is a pending breakpoint."},
1368 "Get locations where this breakpoint was set"},
1375 "Return true if this breakpoint is valid, false if not." },
1377 "Delete the underlying GDB breakpoint." },
1383 PyVarObject_HEAD_INIT (NULL, 0)
1402 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
1403 "GDB breakpoint object",
1428 _(
"Set Python breakpoint debugging."),
1429 _(
"Show Python breakpoint debugging."),
1430 _(
"When on, Python breakpoint debugging is enabled."),
1445 if (newvalue ==
nullptr)
1447 PyErr_SetString (PyExc_TypeError,
1448 _(
"Cannot delete 'enabled' attribute."));
1451 else if (!PyBool_Check (newvalue))
1453 PyErr_SetString (PyExc_TypeError,
1454 _(
"The value of 'enabled' must be a boolean."));
1458 int cmp = PyObject_IsTrue (newvalue);
1466 catch (
const gdb_exception &except)
1482 if (self->bp_loc->enabled)
1508 Py_INCREF (self->owner);
1509 return (PyObject *) self->owner;
1521 if (self->bp_loc->symtab)
1529 if (filename ==
nullptr)
1532 if (line ==
nullptr)
1534 if (PyTuple_SetItem (tup.get (), 0, filename.release ()) == -1
1535 || PyTuple_SetItem (tup.get (), 1, line.release ()) == -1)
1537 return tup.release ();
1551 const auto fn_name = self->bp_loc->function_name.get ();
1552 if (fn_name !=
nullptr)
1564 if (list ==
nullptr)
1568 if (
inf->pspace == self->bp_loc->pspace)
1573 if (PyList_Append (list.get (), num.release ()) != 0)
1577 return list.release ();
1586 const auto symtab = self->bp_loc->symtab;
1591 return fullname.release ();
1603 Py_XDECREF (self->owner);
1604 Py_TYPE (py_self)->tp_free (py_self);
1611 "Boolean telling whether the breakpoint is enabled.", NULL },
1613 "Get the breakpoint owner object", NULL },
1615 "Get address of where this location was set", NULL},
1617 "Get file and line number of where this location was set", NULL},
1619 "Get function of where this location was set", NULL },
1621 "Get fullname of where this location was set", NULL },
1623 "Get thread groups where this location is in", NULL },
1629 PyVarObject_HEAD_INIT (NULL, 0)
1630 "gdb.BreakpointLocation",
1649 "GDB breakpoint location object",
void enable_breakpoint(struct breakpoint *bpt)
void delete_breakpoint(struct breakpoint *bpt)
void enable_disable_bp_location(bp_location *loc, bool enable)
void breakpoint_set_thread(struct breakpoint *b, int thread)
struct breakpoint * get_breakpoint(int num)
void watch_command_wrapper(const char *arg, int from_tty, bool internal)
void rwatch_command_wrapper(const char *arg, int from_tty, bool internal)
int create_breakpoint(struct gdbarch *gdbarch, location_spec *locspec, const char *cond_string, int thread, const char *extra_string, bool force_condition, int parse_extra, int tempflag, enum bptype type_wanted, int ignore_count, enum auto_boolean pending_break_support, const struct breakpoint_ops *ops, int from_tty, int enabled, int internal, unsigned flags)
bool is_watchpoint(const struct breakpoint *bpt)
void awatch_command_wrapper(const char *arg, int from_tty, bool internal)
struct command_line * breakpoint_commands(struct breakpoint *b)
void breakpoint_set_silent(struct breakpoint *b, int silent)
void disable_breakpoint(struct breakpoint *bpt)
void breakpoint_set_task(struct breakpoint *b, int task)
void breakpoint_set_commands(struct breakpoint *b, counted_command_line &&commands)
void set_ignore_count(int bptnum, int count, int from_tty)
void set_breakpoint_condition(struct breakpoint *b, const char *exp, int from_tty, bool force)
int user_breakpoint_p(struct breakpoint *b)
int pending_breakpoint_p(struct breakpoint *b)
const struct breakpoint_ops * breakpoint_ops_for_location_spec(const location_spec *locspec, bool is_tracepoint)
breakpoint_range all_breakpoints()
gdb::ref_ptr< bp_location, bp_location_ref_policy > bp_location_ref_ptr
static struct gdbarch * get_gdbarch()
const char * c_str() const
struct cmd_list_element * showdebuglist
struct cmd_list_element * setdebuglist
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
counted_command_line read_command_lines_1(read_next_line_ftype read_next_line_func, int parse_commands, gdb::function_view< void(const char *)> validator)
void print_command_lines(struct ui_out *uiout, struct command_line *cmd, unsigned int depth)
std::shared_ptr< command_line > counted_command_line
const struct extension_language_defn * get_breakpoint_cond_ext_lang(struct breakpoint *b, enum extension_language skip_lang)
const struct extension_language_defn * get_ext_lang_defn(enum extension_language lang)
const char * ext_lang_capitalized_name(const struct extension_language_defn *extlang)
int valid_global_thread_id(int global_id)
all_inferiors_range all_inferiors(process_stratum_target *proc_target=nullptr)
const struct language_defn * current_language
struct line_offset linespec_parse_line_offset(const char *string)
location_spec_up string_to_location_spec(const char **stringp, const struct language_defn *language, symbol_name_match_type match_type)
std::unique_ptr< location_spec > location_spec_up
observable< struct breakpoint * > breakpoint_created
observable< struct breakpoint * > breakpoint_modified
observable< struct breakpoint * > breakpoint_deleted
PyObject * gdbpy_breakpoints(PyObject *self, PyObject *args)
static int bppy_init_validate_args(const char *spec, char *source, char *function, char *label, char *line, enum bptype type)
static void show_pybp_debug(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
bool gdbpy_breakpoint_init_breakpoint_type()
PyTypeObject breakpoint_object_type
void _initialize_py_breakpoint()
static gdb_PyGetSetDef bp_location_object_getset[]
static void gdbpy_breakpoint_deleted(struct breakpoint *b)
#define BPLOCPY_SET_REQUIRE_VALID(Breakpoint, Location)
static void gdbpy_breakpoint_created(struct breakpoint *bp)
static int bplocpy_set_enabled(PyObject *py_self, PyObject *newvalue, void *closure)
#define PYBP_SCOPED_DEBUG_ENTER_EXIT
static int bppy_set_hit_count(PyObject *self, PyObject *newvalue, void *closure)
static PyObject * bplocpy_get_owner(PyObject *py_self, void *closure)
static PyObject * bppy_get_task(PyObject *self, void *closure)
static void gdbpy_breakpoint_modified(struct breakpoint *b)
static int bppy_set_ignore_count(PyObject *self, PyObject *newvalue, void *closure)
static PyObject * bppy_get_condition(PyObject *self, void *closure)
PyTypeObject breakpoint_location_object_type
static int bppy_set_commands(PyObject *self, PyObject *newvalue, void *closure)
static bool build_bp_list(struct breakpoint *b, PyObject *list)
static PyObject * bppy_get_type(PyObject *self, void *closure)
static PyObject * bppy_get_hit_count(PyObject *self, void *closure)
static int bppy_set_silent(PyObject *self, PyObject *newvalue, void *closure)
static PyObject * bppy_delete_breakpoint(PyObject *self, PyObject *args)
static struct pybp_code pybp_codes[]
int gdbpy_breakpoint_has_cond(const struct extension_language_defn *extlang, struct breakpoint *b)
enum ext_lang_bp_stop gdbpy_breakpoint_cond_says_stop(const struct extension_language_defn *extlang, struct breakpoint *b)
static PyObject * bppy_get_location(PyObject *self, void *closure)
gdbpy_breakpoint_object * bppy_pending_object
static int bppy_init(PyObject *self, PyObject *args, PyObject *kwargs)
static int bppy_set_task(PyObject *self, PyObject *newvalue, void *closure)
static PyObject * bppy_get_silent(PyObject *self, void *closure)
static gdb_PyGetSetDef breakpoint_object_getset[]
static int bppy_set_enabled(PyObject *self, PyObject *newvalue, void *closure)
static PyObject * bplocpy_get_source_location(PyObject *py_self, void *closure)
static int local_setattro(PyObject *self, PyObject *name, PyObject *v)
static PyObject * bppy_get_temporary(PyObject *self, void *closure)
static void bplocpy_dealloc(PyObject *py_self)
static PyObject * bplocpy_get_function(PyObject *py_self, void *closure)
static PyObject * bppy_get_thread(PyObject *self, void *closure)
static PyObject * bppy_get_pending(PyObject *self, void *closure)
static PyObject * bplocpy_get_thread_groups(PyObject *py_self, void *closure)
static int bppy_set_thread(PyObject *self, PyObject *newvalue, void *closure)
static PyObject * bppy_get_enabled(PyObject *self, void *closure)
static PyObject * bppy_get_locations(PyObject *self, void *closure)
int gdbpy_initialize_breakpoint_locations()
static PyObject * bplocpy_get_address(PyObject *py_self, void *closure)
static PyObject * bppy_get_commands(PyObject *self, void *closure)
static PyObject * bplocpy_get_enabled(PyObject *py_self, void *closure)
static PyMethodDef breakpoint_object_methods[]
int gdbpy_initialize_breakpoints(void)
#define pybp_debug_printf(fmt,...)
static PyObject * bppy_is_valid(PyObject *self, PyObject *args)
static const char stop_func[]
#define BPLOCPY_REQUIRE_VALID(Breakpoint, Location)
static PyObject * bppy_get_number(PyObject *self, void *closure)
static int bppy_set_condition(PyObject *self, PyObject *newvalue, void *closure)
static PyObject * bppy_get_ignore_count(PyObject *self, void *closure)
static PyObject * bppy_get_expression(PyObject *self, void *closure)
static struct pybp_code pybp_watch_types[]
static PyObject * bplocpy_get_fullname(PyObject *py_self, void *closure)
static PyObject * bppy_get_visibility(PyObject *self, void *closure)
int evpy_emit_event(PyObject *event, eventregistry_object *registry)
events_object gdb_py_events
bool evregpy_no_listeners_p(eventregistry_object *registry)
void bpfinishpy_post_stop_hook(struct gdbpy_breakpoint_object *bp_obj)
void bpfinishpy_pre_stop_hook(struct gdbpy_breakpoint_object *bp_obj)
gdb::ref_ptr< T, gdbpy_ref_policy< T > > gdbpy_ref
gdbpy_ref host_string_to_python_string(const char *str)
gdbpy_ref gdb_py_object_from_longest(LONGEST l)
void gdbpy_convert_exception(const struct gdb_exception &exception)
int gdb_py_int_as_long(PyObject *obj, long *result)
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
gdbpy_ref gdb_py_object_from_ulongest(ULONGEST l)
void gdbpy_print_stack(void)
#define PyObject_CallMethod
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
#define GDB_PY_SET_HANDLE_EXCEPTION(Exception)
#define BPPY_SET_REQUIRE_VALID(Breakpoint)
#define BPPY_REQUIRE_VALID(Breakpoint)
#define GDB_PY_HANDLE_EXCEPTION(Exception)
static int gdb_PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, const char **keywords,...)
counted_command_line commands
gdb::unique_xmalloc_ptr< char > cond_string
gdbpy_breakpoint_object * py_bp_object
enum enable_state enable_state
gdbpy_breakpoint_object * owner
PyObject_HEAD bp_location * bp_loc
gdb::unique_xmalloc_ptr< char > exp_string
void gdb_printf(struct ui_file *stream, const char *format,...)