public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Pierre-Marie de Rodat <derodat@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix use of a dangling pointer for Python breakpoint objects
Date: Thu, 23 Jun 2016 16:15:00 -0000	[thread overview]
Message-ID: <02138a22-5087-44ad-6023-7c87251f3d19@redhat.com> (raw)
In-Reply-To: <20160621104021.15093-1-derodat@adacore.com>

On 06/21/2016 11:40 AM, Pierre-Marie de Rodat wrote:
> Hello,
> 
> When a Python script tries to create a breakpoint but fails to do so,
> gdb.Breakpoint.__init__ raises an exception and the breakpoint does not
> exist anymore in the Python interpreter. However, GDB still keeps a
> reference to the Python object to be used for a later hook, which is
> wrong.

Urgh, this code is ugly.

So the problem is that the next time gdbpy_breakpoint_created
is called, for some other breakpoint, we'll dereference the dangling
pointer then, correct?

> +
> +# Skip all tests if Python scripting is not enabled.
> +if { [skip_python_tests] } { continue }
> +
> +gdb_test "source py-breakpoint2.py"
> +
> +# The following used to trigger an internal error because of a dangling
> +# reference to a Python breakpoint object.
> +gdb_test "start"

"start" doesn't work with "target remote" testing.  Try:

$ make check \
   RUNTESTFLAGS="--target_board=native-gdbserver" \
   TESTS="gdb.python/py-breakpoint2.exp"

Can we instead run to main first, and then source the python
script?

> +
> +bp1 = gdb.Breakpoint('main', gdb.BP_BREAKPOINT)

I don't understand the idea behind creating this breakpoint
before the failing watchpoint one.

> +
> +# The following will create a breakpoint whose construction will abort (there
> +# is no such symbol), so GDB should not keep a reference to the corresponding
> +# Python object.
> +try:
> +    bp2 = gdb.Breakpoint('does_not_exist', gdb.BP_WATCHPOINT)
> +except RuntimeError:
> +    pass
> +else:
> +    assert False

Wouldn't it better to create a breakpoint after the one
that failed, explicitly?  Either in python, or perhaps
simpler, a regular command line breakpoint directly in
the .exp file.  

Ah, I think I see -- I guess the test is relying on "start" creating
a magic breakpoint at "main", and that one being the one
that dereferences the dangling pointer.  But, see above about
remote testing.

Thanks,
Pedro Alves

  reply	other threads:[~2016-06-23 16:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-21 10:40 Pierre-Marie de Rodat
2016-06-23 16:15 ` Pedro Alves [this message]
2016-06-24  9:21   ` Pierre-Marie de Rodat
2016-06-24 16:41     ` Pedro Alves
2016-06-27  9:11       ` Pierre-Marie de Rodat
2016-06-27 10:03         ` Pedro Alves
2016-06-27 10:13           ` Pierre-Marie de Rodat

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=02138a22-5087-44ad-6023-7c87251f3d19@redhat.com \
    --to=palves@redhat.com \
    --cc=derodat@adacore.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).