public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: Phil Muldoon <pmuldoon@redhat.com>
To: Project Archer <archer@sourceware.org>
Subject: [patch] Add watchpoint support to save_breakpoints.py (and add supporting methods to python-breakpoint.c)
Date: Thu, 11 Jun 2009 13:53:00 -0000	[thread overview]
Message-ID: <4A310C5F.5000407@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1586 bytes --]

Something that has been on my mind for awhile is that 
save_breakpoints.py does not handle watchpoints very well.  I like 
watchpoints, and use them all the time! So I propose this patch:

This patch adds watchpoint support to the save_breakpoints.py command.  
I added two new methods to python_breakpoint.c to achieve this goal.  As 
watchpoints only seemed to be represented as an expression, then the 
bppy_get_expression function had to be included to interrogate the 
expression behind the gdb breakpoint.  To differentiate between the 
types of watchpoint (and other breakpoints ...), I added a bppy_get_type 
function along with supporting constants.  Included are documentation 
entries also.  I elected not to include catchpoint support as catchpoint 
"type" seems to be hidden behind the struct bp_ops function pointers in 
the breakpoint struct. If there is another way to differentiate between 
the different catchpoints by type, I'd be happy to add them into this 
patch, too.

Regards

Phil

ChangeLog

2009-06-11  Phil Muldoon <pmuldoon@redhat.com>

     * python/python-breakpoint.c (bppy_get_expression): New Function.
     (bppy_get_type): Likewise.
     (gdbpy_initialize_breakpoints): Initialize breakpoint constants.
     * python/lib/gdb/command/save_breakpoints.py
     (SaveBreakpointsCommand.breakpoint_type): New function.
     (SaveBreakpointsCommand.invoke): Use breakpoint_type.

doc/ChangeLog

2009-06-11  Phil Muldoon <pmuldoon@redhat.com>

     * gdb.texinfo (Breakpoints In Python): Add expression, type
     variable text. Add breakpoint constants.



[-- Attachment #2: py_watchpoints.patch --]
[-- Type: text/plain, Size: 6860 bytes --]

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;
+    }
 }
 
 \f
@@ -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.  */
 };
 

             reply	other threads:[~2009-06-11 13:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-11 13:53 Phil Muldoon [this message]
2009-06-29 15:46 ` Phil Muldoon
2009-07-24 17:11   ` Phil Muldoon
2009-07-31 18:22 ` Tom Tromey
2009-07-31 19:37   ` Phil Muldoon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A310C5F.5000407@redhat.com \
    --to=pmuldoon@redhat.com \
    --cc=archer@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).