public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Kevin Pouget <kevin.pouget@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFC] Python Finish Breakpoints
Date: Thu, 19 May 2011 16:21:00 -0000	[thread overview]
Message-ID: <m34o4qd5lh.fsf@fleche.redhat.com> (raw)
In-Reply-To: <BANLkTimmYEmvKT_984jYEVZnA5RGFpEgNw@mail.gmail.com> (Kevin	Pouget's message of "Wed, 18 May 2011 04:57:26 -0400")

>>>>> "Kevin" == Kevin Pouget <kevin.pouget@gmail.com> writes:

Moving to gdb-patches.

Kevin> I've included with this mail a complete patch build agains the
Kevin> current HEAD, and checked that there was no regression in the
Kevin> testsuite

Thanks.

I'm sorry about the delay in my reply.  I'm going to try to prioritize
patch review and email a bit higher in the future.

I think this functionality is very good.  I am not sure about some
aspects of the implementation, though, and I have some style nits to
pick.

Kevin> -static void
Kevin> +void
Kevin>  create_breakpoint_sal (struct gdbarch *gdbarch,
Kevin>  		       struct symtabs_and_lines sals, char *addr_string,
Kevin>  		       char *cond_string,

What is the rationale for using this function in particular?

It seems to me that it would probably be better to make an explicit_pc=1
SAL using the unwound PC.  Then there would be no reason to avoid the
currently exported API.

Kevin> +  struct value *value = get_return_value(func_type, value_type);

Missing space before the "(".  This appears multiple places in the
patch.

Kevin> -  if (inferior_thread ()->control.proceed_to_finish)
Kevin> +  if (gdbpy_is_stopped_at_finish_bp (inferior_thread ()->control.stop_bpstat)
Kevin> +      || inferior_thread ()->control.proceed_to_finish)

gdbpy_is_stopped_at_finish_bp is not safe to call here -- it assumes the 
GIL has been acquired, which it has not.  I would rather it not be changed
to acquire the GIL, however.  I think one of two other approaches would
be preferable.

One way you could handle this is to add a new constant to enum bptype.
This is likely to be pretty invasive.

Another way would be to add a flag to the struct breakpoint itself.

Yet another way would be a new breakpoint_ops method.

This is related, in a way, to the out-of-scope handling.  Right now the
patch tries to reimplement the existing breakpoint re-setting logic in
py-finishbreakpoint.c, via observers.  I think it would be better to
have this be done automatically by the existing code in breakpoint.c,
perhaps adding some additional python-visible notification step.

Kevin> +static char * const outofscope_func = "out_of_scope";

"const char *".

Kevin> +  /* The function finished by this breakpoint.  */
Kevin> +  struct symbol *function;

If you want to store a pointer to a symbol, then you have to account for
the case where the objfile is destroyed.  Otherwise you can end up with
a dangling pointer.

Alternatively, perhaps you could have this refer to a Symbol object; but
then you have to be careful to check it for validity before using it.

Actually, it seems that the symbol is only used to get the function's
return type.  You might as well just compute that up front and store a
Type.

Kevin> +/* Python function to set the 'out_of_scope_notif' attribute of
Kevin> +   FinishBreakpoint.  */
Kevin> +
Kevin> +static int
Kevin> +bpfinishpy_set_outofscope_notif (PyObject *self, PyObject *newvalue,
Kevin> +                                 void *closure)

I don't understand the point of this function.

I think documentation would help.

Kevin> +/* Python function to get the 'return_value' attribute of
Kevin> +   FinishBreakpoint.  */
Kevin> +
Kevin> +static PyObject *
Kevin> +bpfinishpy_get_returnvalue (PyObject *self, void *closure)
Kevin> +{
Kevin> +  struct finish_breakpoint_object *self_finishbp =
Kevin> +      (struct finish_breakpoint_object *) self;
Kevin> +
Kevin> +  BPPY_REQUIRE_VALID (&self_finishbp->py_bp);
Kevin> +
Kevin> +  if (self_finishbp->function == NULL)
Kevin> +    goto return_none;
Kevin> +
Kevin> +  /* Ensure that GDB is stopped at this FinishBreakpoint.  */
Kevin> +  if (inferior_thread ()->control.stop_bpstat != NULL)
Kevin> +    {
Kevin> +      bpstat bs;
Kevin> +
Kevin> +      for(bs = inferior_thread ()->control.stop_bpstat;
Kevin> +          bs; bs = bs->next)

I am not an expert here, but I think it is probably no good to rely on
this state remaining live.

I think it would be better to simply have a stop at one of these
breakpoints compute and cache the Value object immediately.

Kevin> +static void
Kevin> +gdbpy_out_of_scope (struct finish_breakpoint_object *bpfinish_obj)
Kevin> +{
Kevin> +  breakpoint_object *bp_obj = (breakpoint_object *) bpfinish_obj;
Kevin> +  PyObject *py_obj = (PyObject *) bp_obj ;
Kevin> +  
Kevin> +  bpfinish_obj->out_of_scope_notif = 0;
Kevin> +
Kevin> +  if (PyObject_HasAttrString (py_obj, outofscope_func))
Kevin> +    {
Kevin> +      struct gdbarch *garch =  bp_obj->bp->gdbarch ?  
Kevin> +          bp_obj->bp->gdbarch : get_current_arch ();
Kevin> +      struct cleanup *cleanup = ensure_python_env (garch, current_language);

You can't call any Python functions without the GIL.
This applies to PyObject_HasAttrString here.

In this case, though, gdbpy_out_of_scope is called by one function that
already has the GIL.  So, I think the acquisition should be pushed into
its other caller.

Kevin> +  pc = get_frame_pc (prev_frame);

This can throw an exception.  So, it needs to be wrapped in a TRY_CATCH.
This may apply to some other GDB functions called by the "Python-facing"
code, I did not check them all.

Kevin> +static PyMethodDef finish_breakpoint_object_methods[] = {
Kevin> +  { "check_scope", bpfinishpy_check_scope, METH_NOARGS,
Kevin> +    "check_scope () -> Boolean.\n\
Kevin> +Return true if out_of_scope() has been triggered, false if not." },

How is this useful?
And, why a method instead of an attribute?

Kevin> +static PyGetSetDef finish_breakpoint_object_getset[] = {
Kevin> +  { "out_of_scope_notif", bpfinishpy_get_outofscope_notif, bpfinishpy_set_outofscope_notif,

I don't like the name "out_of_scope_notif", particularly if this is an
apt description of its meaning:

Kevin> +    "Boolean telling whether the breakpoint is still within the scope \
Kevin> +of the current callstack.", NULL },


Kevin> diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint-cc.exp b/gdb/testsuite/gdb.python/py-finish-breakpoint-cc.exp

Funny file name.

Kevin> +gdb_test "python ExceptionBreakpoint()" "ExceptionBreakpoint init" "set BP before throwing the exception"
Kevin> +gdb_test "python print len(gdb.breakpoints())" "4" "check number of BPs"
Kevin> +gdb_test "continue" ".*stopped at ExceptionFinishBreakpoint.*" "check FinishBreakpoint in catch()"
Kevin> +gdb_test "python print len(gdb.breakpoints())" "4" "check finish BP removal"

I don't think this tests the most important case -- where an exception
is thrown, invalidating the return breakpoint.

That is, put a breakpoint in throw_exception_1, continue to there, then
set the breakpoint, then continue again.

I didn't examine the longjmp test but the same idea applies there.

Other cases to consider are -

* inferior exec
* inferior exit
* explicit inferior function call
* "return" command

Tom

  parent reply	other threads:[~2011-05-19 16:21 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <BANLkTim+YH64zkWvdz2_kVUUj=AJ7v4LKw@mail.gmail.com>
     [not found] ` <BANLkTi=gtHzWzXOJzB+a19=jkfk1hGwQBg@mail.gmail.com>
     [not found]   ` <BANLkTikVdqbMqjguTV8ct0TWiBDhHGYtLg@mail.gmail.com>
2011-05-11  7:44     ` Kevin Pouget
2011-05-11 10:31       ` Phil Muldoon
2011-05-11 11:29         ` Kevin Pouget
2011-05-12 10:38           ` Kevin Pouget
2011-05-12 10:50         ` Phil Muldoon
2011-05-12 11:29           ` Kevin Pouget
     [not found] ` <BANLkTi=Eu-5B4YyhP2rGdQXgXbBN-EmLKA@mail.gmail.com>
     [not found]   ` <BANLkTikt2hEUcXkGVH44NaUcwiF1SGdMaw@mail.gmail.com>
     [not found]     ` <BANLkTi=UpgogckTD5MZsW+PC5d2F8X-+jA@mail.gmail.com>
     [not found]       ` <BANLkTi==bj50mZgFKq_qA-+3-2CQA3tBVw@mail.gmail.com>
     [not found]         ` <BANLkTimmYEmvKT_984jYEVZnA5RGFpEgNw@mail.gmail.com>
2011-05-19 16:21           ` Tom Tromey [this message]
2011-05-24 12:51             ` Kevin Pouget
2011-05-27 20:30               ` Tom Tromey
2011-05-30  9:29                 ` Kevin Pouget
2011-10-13 14:34                   ` Kevin Pouget
2011-10-20 20:12                     ` Tom Tromey
2011-10-20 20:58                   ` Tom Tromey
2011-10-21  8:15                     ` Kevin Pouget
2011-10-24 11:43                       ` Kevin Pouget
2011-10-24 13:20                         ` Eli Zaretskii
2011-10-24 14:30                           ` Kevin Pouget
2011-10-24 17:14                             ` Eli Zaretskii
2011-10-24 15:31                         ` Kevin Pouget
2011-10-24 16:27                           ` Phil Muldoon
2011-10-25 11:05                             ` Kevin Pouget
2011-10-25 11:37                               ` Phil Muldoon
2011-10-25 12:22                                 ` Kevin Pouget
2011-10-28  8:33                                   ` Kevin Pouget
2011-10-28 20:51                                     ` Tom Tromey
2011-11-02 14:44                                       ` Kevin Pouget
2011-11-04 14:25                                         ` Kevin Pouget
2011-11-04 21:04                                           ` Tom Tromey
2011-11-09 14:10                                             ` Kevin Pouget
2011-11-16 10:53                                               ` Kevin Pouget
2011-11-17 17:49                                                 ` Tom Tromey
2011-11-17 17:48                                               ` Tom Tromey
     [not found]                                                 ` <CAPftXUJwtGJhqFyfX6LVK87QH2xeLkvv5kx=yaEnYJMv0YR_rw@mail.gmail.com>
2011-11-24  8:27                                                   ` Kevin Pouget
2011-11-30 16:02                                                     ` Kevin Pouget
2011-12-02 21:49                                                       ` Tom Tromey
2011-12-05  9:29                                                         ` Kevin Pouget
2011-12-06 21:18                                                           ` Tom Tromey
2011-12-07 13:35                                                             ` Kevin Pouget
2011-12-08 15:30                                                               ` Tom Tromey
2011-12-08 16:10                                                                 ` Kevin Pouget
2011-12-08 18:08                                                                   ` Kevin Pouget
2011-12-09  9:53                                                                     ` Kevin Pouget
2011-12-18 19:22                                                                       ` Kevin Pouget
2011-12-20 20:55                                                                       ` Tom Tromey
2011-12-20 20:58                                                                         ` Kevin Pouget
2011-12-21  7:16                                                                           ` Joel Brobecker
2011-12-21 17:13                                                                             ` Tom Tromey
     [not found]                                                                               ` <CAPftXUKXh9ekZ2kiwQ=5zbrjst+9VH9-eZk8h+Z-9SpQ1WqdLw@mail.gmail.com>
     [not found]                                                                                 ` <CAPftXULQFggY3Nz2byC0fMZA1sg4Nymp3hAhe8aSuLNG4cauFg@mail.gmail.com>
     [not found]                                                                                   ` <CAPftXUJALHd=-fajVwgowqfCDfXO6JMxSkorWD6CQArsg-PedQ@mail.gmail.com>
     [not found]                                                                                     ` <CAPftXULKC8gp3L87+PZEF3dj3crv9bh-uzZpRiYKjqEw_xyptQ@mail.gmail.com>
2011-12-27  4:18                                                                                       ` Joel Brobecker
2011-12-27  9:40                                                                                         ` Kevin Pouget
2011-12-27 12:22                                                                                           ` Joel Brobecker
2011-12-27  9:34                                                                                       ` Kevin Pouget
2011-12-24 23:56                                                                           ` [patch] Fix gdb.python/py-finish-breakpoint.exp new FAIL on x86_64-m32 [Re: [RFC] Python Finish Breakpoints] Jan Kratochvil
2011-12-27 11:13                                                                             ` Kevin Pouget
2011-12-27 21:39                                                                               ` [commit] " Jan Kratochvil
2012-01-04 17:45                                                                             ` Ulrich Weigand
2012-01-04 17:58                                                                               ` [commit 7.4] " Jan Kratochvil
2012-01-04 18:10                                                                                 ` Ulrich Weigand
2011-12-26 11:28                                                                           ` [patch] Fix remote.c crash on gdbserver close (+fix py-finish-breakpoint.exp for gdbserver) " Jan Kratochvil
2011-12-27 23:30                                                                             ` [patch] Fix remote.c crash on gdbserver close (+fix py-finish-breakpoint.exp for gdbserver) [rediff] Jan Kratochvil
2012-01-02 17:57                                                                               ` Tom Tromey
2012-01-02 19:49                                                                               ` Pedro Alves
2012-01-19 16:24                                                                                 ` Call target_close after unpushing, not before (was: Re: [patch] Fix remote.c crash on gdbserver close (+fix py-finish-breakpoint.exp for gdbserver)) Pedro Alves
2012-01-19 16:27                                                                                   ` Jan Kratochvil
2012-01-19 16:37                                                                                     ` Call target_close after unpushing, not before Pedro Alves
2012-01-19 16:53                                                                                     ` [commit] Re: Call target_close after unpushing, not before (was: Re: [patch] Fix remote.c crash on gdbserver close (+fix py-finish-breakpoint.exp for gdbserver)) Jan Kratochvil
2012-01-04 14:49                                                                       ` [RFC] Python Finish Breakpoints Ulrich Weigand
2012-01-04 15:24                                                                         ` Kevin Pouget
2012-01-04 16:29                                                                           ` Ulrich Weigand
2012-01-04 16:42                                                                           ` Tom Tromey
2012-01-04 16:40                                                                         ` Tom Tromey
2012-01-04 17:13                                                                           ` Ulrich Weigand
2012-01-09  9:21                                                                             ` Kevin Pouget
2012-01-27 17:01                                                                               ` Kevin Pouget
2011-10-28 19:26                                   ` 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=m34o4qd5lh.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=kevin.pouget@gmail.com \
    /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).