public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb: fix target_ops reference count for some cases
Date: Thu, 22 Sep 2022 11:00:23 -0400	[thread overview]
Message-ID: <9a31d60a-01a8-e527-71d9-0f5908be2961@simark.ca> (raw)
In-Reply-To: <20220921131200.3983844-1-aburgess@redhat.com>

> diff --git a/gdb/inferior.c b/gdb/inferior.c
> index 7eb2bd97907..0c0b4b78ff5 100644
> --- a/gdb/inferior.c
> +++ b/gdb/inferior.c
> @@ -70,6 +70,16 @@ inferior::~inferior ()
>  {
>    inferior *inf = this;
>  
> +  /* Before the inferior is deleted, all target_ops should be popped from
> +     the target stack, this leaves just the dummy_target behind.  If this
> +     is not done, then any target left in the target stack will be left
> +     with an artificially high reference count.  As the dummy_target is
> +     still on the target stack then we are about to loose a reference to
loose -> lose?

> @@ -191,6 +201,26 @@ delete_inferior (struct inferior *inf)
>  
>    gdb::observers::inferior_removed.notify (inf);
>  
> +  {
> +    /* Limit the change of inferior to an inner scope so that the original
> +       inferior and program space will have been restored by the time that
> +       we delete the inferior INF and (possibly) its related  program

two spaces between related and program.

> +       space.  */
> +    scoped_restore_current_pspace_and_thread restore_pspace_and_thread;

Just wondering, why do we need to restore explicitly the current
pspace, instead of using just scoped_restore_current_thread?

scoped_restore_current_pspace_and_thread's doc says:

/* Save/restore the current program space, thread, inferior and frame.
   Use this when you need to call
   switch_to_program_space_and_thread.  */

... but you are not using switch_to_program_space_and_thread here.
Maybe it's ok and I just don't understand.  Same in
~scoped_mock_context.

> diff --git a/gdb/testsuite/gdb.python/py-connection-removed.exp b/gdb/testsuite/gdb.python/py-connection-removed.exp
> new file mode 100644
> index 00000000000..1b139cedc0d
> --- /dev/null
> +++ b/gdb/testsuite/gdb.python/py-connection-removed.exp
> @@ -0,0 +1,92 @@
> +# Copyright (C) 2022 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +# Check that the gdb.connect_removed event triggers when we expect it
> +# too.

too -> to

> +#
> +# Checking this event has wider implications that simply some corner

simply -> imply?  Or I don't get what you mean.

> +# of the Python API working or not.  The connection_removed event
> +# triggers when the reference count of a process_stratum_target
> +# reaches zero.  If these events stop triggering when expected then
> +# GDB might be getting the reference counting on target_ops objects
> +# wrong.
> +
> +load_lib gdb-python.exp
> +
> +standard_testfile py-connection.c
> +
> +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
> +    return -1
> +}
> +
> +# Skip all tests if Python scripting is not enabled.
> +if { [skip_python_tests] } { continue }
> +
> +if ![runto_main] then {
> +    return 0
> +}
> +
> +# Register a callback that will trigger when a connection is removed
> +# (deleted) within GDB.
> +gdb_test_multiline "Add connection_removed event" \
> +    "python" "" \
> +    "def connection_removed_handler(event):" "" \
> +    "   num = event.connection.num" "" \
> +    "   type = event.connection.type" "" \
> +    "   print(f'Connection {num} ({type}) removed')" "" \

I think unfortunately need to support Python versions that don't know
about f-strings.

Simon


  parent reply	other threads:[~2022-09-22 15:00 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-21 13:12 Andrew Burgess
2022-09-21 15:30 ` Simon Marchi
2022-09-22 14:21   ` Andrew Burgess
2022-09-22 14:52     ` Simon Marchi
2022-09-22 15:00 ` Simon Marchi [this message]
2022-09-22 17:24   ` Andrew Burgess
2022-09-26 14:16     ` Simon Marchi
2022-10-01 20:58       ` Andrew Burgess
2022-10-02 17:04 ` [PATCHv2 0/7] " Andrew Burgess
2022-10-02 17:04   ` [PATCHv2 1/7] gdb/remote: remove some manual reference count handling Andrew Burgess
2022-10-02 17:04   ` [PATCHv2 2/7] gdb: remove decref_target Andrew Burgess
2022-10-02 17:04   ` [PATCHv2 3/7] gdb: have target_stack automate reference count handling Andrew Burgess
2022-10-02 17:04   ` [PATCHv2 4/7] gdb: remove the pop_all_targets (and friends) global functions Andrew Burgess
2022-10-05 20:49     ` Lancelot SIX
2022-10-06 11:14       ` Andrew Burgess
2022-10-02 17:04   ` [PATCHv2 5/7] gdb: ensure all targets are popped before an inferior is destructed Andrew Burgess
2022-10-02 17:04   ` [PATCHv2 6/7] gdb/maint: add core file name to 'maint info program-spaces' output Andrew Burgess
2022-10-02 17:21     ` Eli Zaretskii
2022-10-02 17:04   ` [PATCHv2 7/7] gdb: some process_stratum_target should not be shared Andrew Burgess
2022-10-02 17:21     ` Eli Zaretskii
2022-10-05 21:15     ` Lancelot SIX
2022-10-06 11:44       ` Andrew Burgess
2022-11-18 16:42   ` [PATCHv3 0/7] gdb: fix target_ops reference count for some cases Andrew Burgess
2022-11-18 16:42     ` [PATCHv3 1/7] gdb/remote: remove some manual reference count handling Andrew Burgess
2022-11-18 16:42     ` [PATCHv3 2/7] gdb: remove decref_target Andrew Burgess
2022-11-18 17:22       ` Tom Tromey
2022-11-18 16:42     ` [PATCHv3 3/7] gdb: have target_stack automate reference count handling Andrew Burgess
2022-11-18 17:25       ` Tom Tromey
2022-11-18 16:42     ` [PATCHv3 4/7] gdb: remove the pop_all_targets (and friends) global functions Andrew Burgess
2022-11-18 17:29       ` Tom Tromey
2022-11-18 16:42     ` [PATCHv3 5/7] gdb: ensure all targets are popped before an inferior is destructed Andrew Burgess
2022-11-18 16:42     ` [PATCHv3 6/7] gdb/maint: add core file name to 'maint info program-spaces' output Andrew Burgess
2022-11-18 17:03       ` Eli Zaretskii
2022-11-18 16:42     ` [PATCHv3 7/7] gdb: some process_stratum_target should not be shared Andrew Burgess
2022-11-18 17:02       ` Eli Zaretskii
2022-11-18 18:04       ` Tom Tromey
2022-12-14 13:57         ` Andrew Burgess

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=9a31d60a-01a8-e527-71d9-0f5908be2961@simark.ca \
    --to=simark@simark.ca \
    --cc=aburgess@redhat.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).