Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Siva Chandra <sivachandra@google.com>
To: gdb-patches@sourceware.org
Subject: [RFC] Extend gdb.Breakpoint to allow setting a breakpoint at the current execution address
Date: Fri, 27 Apr 2012 10:52:00 -0000	[thread overview]
Message-ID: <CAGyQ6gwgaeptA6-C3-WFC6+1t_DW4pVc+pgJbQbAcZo=+SQ=bQ@mail.gmail.com> (raw)

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

Hi all,

I didn't find a way to set a breakpoint at the current execution
address through the existing Python API.  The attached patch 'extends'
gdb.Breakpoint to allow this.  Probably 'extend' is not the right
word, but what this patch does is to allow the SPEC argument of the
gdb.Breakpoint constructor to be 'None' or "" or white space space
string.  When SPEC takes one of these values, a breakpoint is set at
the current execution address.  Though this is not valid for a
watchpoint, the existing error mechanism will handle this correctly.

2012-04-27  Siva Chandra Reddy  <sivachandra@google.com>

        * breakpoint.c (parse_breakpoint_sals, watch_command_1): Treat
        argument with all white space to be equivalent to NULL argument.
        * python/py-breakpoint.c (bppy_init): Make the 'spec' argument
        optional and allow it to take the value 'None'.

doc/
2012-04-27  Siva Chandra Reddy  <sivachandra@google.com>

        * gdb.texinfo (Breakpoints In Python): Document that 'spec'
        argument, of the constructor of gdb.Breakpoint when setting
        breakpoints, is optional and can also be all white space or None
        when used.

testsuite/
2012-04-27  Siva Chandra Reddy  <sivachandra@google.com>

        * gdb.python/py-breakpoint.exp: Test setting breakpoints at the
        current execution address using different values for the 'spec'
        argument of the constructor of gdb.Breakpoint.

Thanks,
Siva Chandra

[-- Attachment #2: bp_patch_v1.txt --]
[-- Type: text/plain, Size: 5246 bytes --]

Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.668
diff -u -p -r1.668 breakpoint.c
--- breakpoint.c	24 Apr 2012 14:33:12 -0000	1.668
+++ breakpoint.c	27 Apr 2012 07:55:09 -0000
@@ -8528,7 +8528,7 @@ parse_breakpoint_sals (char **address,
 
   /* If no arg given, or if first arg is 'if ', use the default
      breakpoint.  */
-  if ((*address) == NULL
+  if ((*address) == NULL || (*skip_spaces (*address)) == '\0'
       || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
     {
       /* The last displayed codepoint, if it's valid, is our default breakpoint
@@ -10054,7 +10054,7 @@ watch_command_1 (char *arg, int accessfl
   struct watchpoint *w;
 
   /* Make sure that we actually have parameters to parse.  */
-  if (arg != NULL && arg[0] != '\0')
+  if (arg != NULL && (*skip_spaces (arg)) != '\0')
     {
       char *value_start;
 
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.950
diff -u -p -r1.950 gdb.texinfo
--- doc/gdb.texinfo	25 Apr 2012 16:13:17 -0000	1.950
+++ doc/gdb.texinfo	27 Apr 2012 07:55:14 -0000
@@ -24981,12 +24981,16 @@ Return the symbol table's source absolut
 Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
 class.
 
-@defun Breakpoint.__init__ (spec @r{[}, type @r{[}, wp_class @r{[},internal@r{]]]})
+@defun Breakpoint.__init__ (@r{[}spec @r{[}, type @r{[}, wp_class @r{[},internal@r{]]]]})
 Create a new breakpoint.  @var{spec} is a string naming the
 location of the breakpoint, or an expression that defines a
 watchpoint.  The contents can be any location recognized by the
 @code{break} command, or in the case of a watchpoint, by the @code{watch}
-command.  The optional @var{type} denotes the breakpoint to create
+command.  For a breakpoint, omitting  or setting @var{spec} to all white
+space sets a breakpoint at the current execution address of the selected
+stack frame.  For a watchpoint, @var{spec} should not be omitted and
+should be a valid expression in the current context of the program being
+debugged.  The optional @var{type} denotes the breakpoint to create
 from the types defined later in this chapter.  This argument can be
 either: @code{gdb.BP_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}.  @var{type}
 defaults to @code{gdb.BP_BREAKPOINT}.  The optional @var{internal} argument
Index: python/py-breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-breakpoint.c,v
retrieving revision 1.33
diff -u -p -r1.33 py-breakpoint.c
--- python/py-breakpoint.c	13 Mar 2012 13:30:42 -0000	1.33
+++ python/py-breakpoint.c	27 Apr 2012 07:55:14 -0000
@@ -590,14 +590,14 @@ static int
 bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 {
   static char *keywords[] = { "spec", "type", "wp_class", "internal", NULL };
-  const char *spec;
+  const char *spec = NULL;
   int type = bp_breakpoint;
   int access_type = hw_write;
   PyObject *internal = NULL;
   int internal_bp = 0;
   volatile struct gdb_exception except;
 
-  if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiO", keywords,
+  if (! PyArg_ParseTupleAndKeywords (args, kwargs, "|ziiO", keywords,
 				     &spec, &type, &access_type, &internal))
     return -1;
 
@@ -614,8 +614,13 @@ bppy_init (PyObject *self, PyObject *arg
   
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
-      char *copy = xstrdup (spec);
-      struct cleanup *cleanup = make_cleanup (xfree, copy);
+      char *copy = NULL;
+      struct cleanup *cleanup;
+
+      if (spec)
+        copy = xstrdup (spec);
+
+      cleanup = make_cleanup (xfree, copy);
 
       switch (type)
 	{
Index: testsuite/gdb.python/py-breakpoint.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-breakpoint.exp,v
retrieving revision 1.14
diff -u -p -r1.14 py-breakpoint.exp
--- testsuite/gdb.python/py-breakpoint.exp	16 Jan 2012 16:21:52 -0000	1.14
+++ testsuite/gdb.python/py-breakpoint.exp	27 Apr 2012 07:55:14 -0000
@@ -79,6 +79,14 @@ gdb_test "python print blist\[0\].number
 gdb_test "python print blist\[1\].number" "2" "Check breakpoint number"
 gdb_test "python print blist\[2\].number" "3" "Check breakpoint number"
 
+# Test setting breakpoint at the current execution address.
+gdb_py_test_silent_cmd "python blist_len = len(gdb.breakpoints())" "Get the number of breakpoints in the list" 0
+gdb_py_test_silent_cmd "python gdb.Breakpoint()" "Check breakpoint set at current execution address with spec omitted" 0
+gdb_py_test_silent_cmd "python gdb.Breakpoint(spec=\"\")" "Check breakpoint set at current execution address with NUL spec" 0
+gdb_py_test_silent_cmd "python gdb.Breakpoint(spec=\"  \")" "Check breakpoint set at current execution address with white space spec" 0
+gdb_py_test_silent_cmd "python gdb.Breakpoint(spec=None)" "Check breakpoint set at current execution address with spec None" 0
+gdb_test "python print len(gdb.breakpoints()) == 4 + blist_len" "True" "Check addition of breakpoints"
+
 # Start with a fresh gdb.
 clean_restart ${testfile}
 

             reply	other threads:[~2012-04-27 10:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-27 10:52 Siva Chandra [this message]
2012-04-27 15:32 ` Eli Zaretskii
2012-04-27 15:41 ` Tom Tromey
2012-04-30 20:01   ` Siva Chandra
2012-05-07 18:56     ` Tom Tromey

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='CAGyQ6gwgaeptA6-C3-WFC6+1t_DW4pVc+pgJbQbAcZo=+SQ=bQ@mail.gmail.com' \
    --to=sivachandra@google.com \
    --cc=gdb-patches@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