diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 958a74f..ee2634b 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -19511,6 +19511,42 @@ This attribute holds the breakpoint's number -- the identifier used by the user to manipulate the breakpoint. This attribute is not writable. @end defivar +@defivar Breakpoint type +This attribute holds the breakpoint's type -- the identifier used to +determine the actual breakpoint type or use-case. This attribute is not +writable. +@end defivar + +The available types are represented by constants defined in the @code{gdb} +module: + +@table @code +@findex BP_BREAKPOINT +@findex gdb.BP_BREAKPOINT +@item BP_BREAKPOINT +Normal code breakpoint. + +@findex BP_WATCHPOINT +@findex gdb.BP_WATCHPOINT +@item BP_WATCHPOINT +Watchpoint breakpoint. + +@findex BP_HARDWARE_WATCHPOINT +@findex gdb.BP_HARDWARE_WATCHPOINT +@item BP_HARDWARE_WATCHPOINT +Hardware assisted watchpoint. + +@findex BP_READ_WATCHPOINT +@findex gdb.BP_READ_WATCHPOINT +@item BP_READ_WATCHPOINT +Hardware assisted read watchpoint. + +@findex BP_ACCESS_WATCHPOINT +@findex gdb.BP_ACCESS_WATCHPOINT +@item BP_ACCESS_WATCHPOINT +Hardware assisted access watchpoint. +@end table + @defivar Breakpoint hit_count This attribute holds the hit count for the breakpoint, an integer. This attribute is writable, but currently it can only be set to zero. @@ -19521,6 +19557,11 @@ This attribute holds the location of the breakpoint, as specified by the user. It is a string. This attribute is not writable. @end defivar +@defivar Breakpoint expression +This attribute holds the breakpoint expression, as specified by +the user. It is a string. This attribute is not writable. +@end defivar + @defivar Breakpoint condition This attribute holds the condition of the breakpoint, as specified by the user. It is a string. If there is no condition, this attribute's diff --git a/gdb/python/lib/gdb/command/save_breakpoints.py b/gdb/python/lib/gdb/command/save_breakpoints.py index 90e07db..c08f69f 100644 --- a/gdb/python/lib/gdb/command/save_breakpoints.py +++ b/gdb/python/lib/gdb/command/save_breakpoints.py @@ -36,6 +36,19 @@ The breakpoints can be restored using the 'source' command.""" gdb.COMMAND_SUPPORT, gdb.COMPLETE_FILENAME) + def breakpoint_type (self, b): + if b.type == gdb.BP_BREAKPOINT: + s = "break " + b.location + elif b.type == gdb.BP_WATCHPOINT or b.type == gdb.BP_HARDWARE_WATCHPOINT: + s = "watch " + b.expression + elif b.type == gdb.BP_READ_WATCHPOINT: + s = "rwatch " + b.expression + elif b.type == gdb.BP_ACCESS_WATCHPOINT: + s = "awatch " + b.expression + else: + s = "" + return s + def invoke (self, arg, from_tty): self.dont_repeat () bps = gdb.breakpoints () @@ -43,7 +56,7 @@ The breakpoints can be restored using the 'source' command.""" raise RuntimeError, 'No breakpoints to save' with open (arg.strip (), 'w') as f: for bp in bps: - print >> f, "break", bp.location, + print >> f, self.breakpoint_type (bp), if bp.thread is not None: print >> f, " thread", bp.thread, if bp.condition is not None: diff --git a/gdb/python/python-breakpoint.c b/gdb/python/python-breakpoint.c index 5e87af6..99df498 100644 --- a/gdb/python/python-breakpoint.c +++ b/gdb/python/python-breakpoint.c @@ -93,6 +93,26 @@ struct breakpoint_object } \ } while (0) +/* This is used to initialize various gdb.bp_* constants. */ +struct pybp_code +{ + /* The name. */ + const char *name; + /* The code. */ + enum type_code code; +}; + +/* Entries related to the type of user set breakpoints. */ +static struct pybp_code pybp_codes[] = +{ + {"BP_NONE", bp_none}, + {"BP_BREAKPOINT", bp_breakpoint}, + {"BP_WATCHPOINT", bp_watchpoint}, + {"BP_HARDWARE_WATCHPOINT", bp_hardware_watchpoint}, + {"BP_READ_WATCHPOINT", bp_read_watchpoint}, + {"BP_ACCESS_WATCHPOINT", bp_access_watchpoint}, +}; + /* Python function which checks the validity of a breakpoint object. */ static PyObject * bppy_is_valid (PyObject *self, PyObject *args) @@ -291,6 +311,19 @@ bppy_get_location (PyObject *self, void *closure) return PyString_Decode (str, strlen (str), host_charset (), NULL); } +/* Python function to get the breakpoint expression. */ +static PyObject * +bppy_get_expression (PyObject *self, void *closure) +{ + char *str; + + BPPY_REQUIRE_VALID ((breakpoint_object *) self); + str = ((breakpoint_object *) self)->bp->exp_string; + if (! str) + str = ""; + return PyString_Decode (str, strlen (str), host_charset (), NULL); +} + /* Python function to get the condition expression of a breakpoint. */ static PyObject * bppy_get_condition (PyObject *self, void *closure) @@ -373,6 +406,16 @@ bppy_get_commands (PyObject *self, void *closure) return result; } +/* Python function to get the breakpoint type. */ +static PyObject * +bppy_get_type (PyObject *self, void *closure) +{ + + breakpoint_object *self_bp = (breakpoint_object *) self; + BPPY_REQUIRE_VALID (self_bp); + return PyInt_FromLong (self_bp->bp->type); +} + /* Python function to get the breakpoint's number. */ static PyObject * bppy_get_number (PyObject *self, void *closure) @@ -578,6 +621,8 @@ gdbpy_breakpoint_deleted (int num) void gdbpy_initialize_breakpoints (void) { + int i; + breakpoint_object_type.tp_new = bppy_new; if (PyType_Ready (&breakpoint_object_type) < 0) return; @@ -588,6 +633,15 @@ gdbpy_initialize_breakpoints (void) observer_attach_breakpoint_created (gdbpy_breakpoint_created); observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted); + + for (i = 0; pybp_codes[i].name; ++i) + { + if (PyModule_AddIntConstant (gdb_module, + /* Cast needed for Python 2.4. */ + (char *) pybp_codes[i].name, + pybp_codes[i].code) < 0) + return; + } } @@ -613,11 +667,15 @@ Can be set to zero to clear the count. No other value is valid\n\ when setting this property.", NULL }, { "location", bppy_get_location, NULL, "Location of the breakpoint, as specified by the user.", NULL}, + { "expression", bppy_get_expression, NULL, + "Expression of the breakpoint, as specified by the user.", NULL}, { "condition", bppy_get_condition, bppy_set_condition, "Condition of the breakpoint, as specified by the user,\ or None if no condition set."}, { "commands", bppy_get_commands, NULL, "Commands of the breakpoint, as specified by the user."}, + { "type", bppy_get_type, NULL, + "Type of breakpoint."}, { NULL } /* Sentinel. */ };