From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A3FD4384F6C6 for ; Fri, 18 Nov 2022 16:43:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A3FD4384F6C6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668789792; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ujf7l89RFOdOWL4M9S+ZuSNG5UVs/Xtla4pJEA3y2qw=; b=jGC0T0dg7Qo7ZHoH4e08eRVXXWtDeAdKfn3K28SF/vQidUdQRgQevYy+voOhW3PyzVY21i eTVo/KNYav/tVsjEabdGxg7Kh9PYodD2bFHNBPfwA/BK6bm5CLDwo4iDsp7/3RD264ysq4 rb/es80xPWPMy6vXaa9/LraRpUVgxaw= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-482--xrGR11iOrq336JElt045Q-1; Fri, 18 Nov 2022 11:43:11 -0500 X-MC-Unique: -xrGR11iOrq336JElt045Q-1 Received: by mail-wm1-f72.google.com with SMTP id bi19-20020a05600c3d9300b003cf9d6c4016so4698638wmb.8 for ; Fri, 18 Nov 2022 08:43:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ujf7l89RFOdOWL4M9S+ZuSNG5UVs/Xtla4pJEA3y2qw=; b=aVrW6ekeosKvn2e69Unms3L5Vd6WmDafxls0UhqGdUWMnuxkWbJMZl06KEzwoFys5C o26UbV7lKgtLOb4YFwxp0S9mI8AX7zhieJlnXrKddD98fx0+Nl9bKlEIU2GMOnnDrwHm 2VDp/1wC8MiCVjSgs7ewsk4icNBagD6uWdYuPR3Gro3cYDx1nCMWOanTS5Z41UD6C2bx GS/R8zj4V46213X0Gbeek/en1urPM8sYaaZqTm3nQ7Z07hLX0ki22wUnjHvDxPNaBbxg xWudvCSf9S9fdCUcLJ8IUBux65eoN+jZQBM7txj2RiQ/MmRamWVvvOSDG4oA+b9oBdRG KmfA== X-Gm-Message-State: ANoB5pl9H9HMcegfk5VW+IbkIT1oMl1uvLVdTCZop7QVPjZByvnD3eVI Slg1XkcF43sSlTgS5p8ryMVhMXiVm9zv7D5777xp9WDDP5Yt/kTvDqq8ltBichsSLl1BiibggP+ KMd7NYtH8J8C86p6S0eJo7ihZ/d8DUSMt2i/NgvWznVaLTKTeCFqdBftz60Ws0Gqmj0t+T8ZKpg == X-Received: by 2002:a5d:54d2:0:b0:241:c224:201e with SMTP id x18-20020a5d54d2000000b00241c224201emr2139829wrv.43.1668789789717; Fri, 18 Nov 2022 08:43:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf7TjsjQyKzqGHA2AP0Q9UTldPb7SHIN47RDUhq2fZdX+saD9FnUe9Bpcj1qyi/tFkOGGRt7aw== X-Received: by 2002:a5d:54d2:0:b0:241:c224:201e with SMTP id x18-20020a5d54d2000000b00241c224201emr2139816wrv.43.1668789789441; Fri, 18 Nov 2022 08:43:09 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id fc18-20020a05600c525200b003c71358a42dsm12833969wmb.18.2022.11.18.08.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 08:43:09 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 5/7] gdb: ensure all targets are popped before an inferior is destructed Date: Fri, 18 Nov 2022 16:42:56 +0000 Message-Id: <2e7400a931704b3b3f366d8c5b7c5d40c0931da9.1668789658.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Now that the inferiors target_stack automatically manages target reference counts, we might think that we don't need to unpush targets when an inferior is deleted... ...unfortunately that is not the case. The inferior::unpush function can do some work depending on the type of target, so it is important that we still pass through this function. To ensure that this is the case, in this commit I've added an assert to inferior::~inferior that ensures the inferior's target_stack is empty (except for the ever present dummy_target). I've then added a pop_all_targets call to delete_inferior, otherwise the new assert will fire in, e.g. the gdb.python/py-inferior.exp test. --- gdb/inferior.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gdb/inferior.c b/gdb/inferior.c index 4bad2198af7..f4b9828a425 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -70,6 +70,15 @@ 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 + that target, leaving its reference count artificially high. However, + this is not critical as the dummy_target is a singleton. */ + gdb_assert (m_target_stack.top ()->stratum () == dummy_stratum); + m_continuations.clear (); target_desc_info_free (inf->tdesc_info); } @@ -230,6 +239,12 @@ delete_inferior (struct inferior *inf) gdb::observers::inferior_removed.notify (inf); + /* Pop all targets now, this ensures that inferior::unpush is called + correctly. As pop_all_targets ends up making a temporary switch to + inferior INF then we need to make this call before we delete the + program space, which we do below. */ + inf->pop_all_targets (); + /* If this program space is rendered useless, remove it. */ if (inf->pspace->empty ()) delete inf->pspace; -- 2.25.4