From patchwork Sun Oct 2 17:04:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 58278 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BA9DD3854143 for ; Sun, 2 Oct 2022 17:06:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA9DD3854143 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664730388; bh=mAPYZ+X5rIrlKYdncz0uIo1CsBp96kLuEoG3lFbw2qM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=rijLPBQxTe3IB/fsGTjG49qPa2PIva0dZxAX/u0vS5a9vtTAS/peZ85FJ8VfRoJru G9iAxy2BLt7GnsKTj/nDbNcyzkVCIGF97orXwn10R3lySgEBmxHKGoBS2zOrCIq2nZ 2vTElYa+Z1xKFhDKEFE9cfIyFZxH9mcL7AkD+q8I= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 6288C3858D38 for ; Sun, 2 Oct 2022 17:04:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6288C3858D38 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-54-Dg9LyUVENquLZYeGGo5ccg-1; Sun, 02 Oct 2022 13:04:54 -0400 X-MC-Unique: Dg9LyUVENquLZYeGGo5ccg-1 Received: by mail-wr1-f70.google.com with SMTP id d22-20020adfa356000000b0022e224b21c0so850247wrb.9 for ; Sun, 02 Oct 2022 10:04:54 -0700 (PDT) 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; bh=mAPYZ+X5rIrlKYdncz0uIo1CsBp96kLuEoG3lFbw2qM=; b=RyR0AWJ0xR/nibBfpBe/g5BI+bHHCkZ3hRRf8GqCyCeHYXVyg27pwjTkKSOAncJV3Z ySVY6Flk/3aeYsIBXP0Qg7AATGYRrdoeJPZoWk9YkxlxdrytGeJTIs9K3sEy9JHr6MOm hTo+Y82h9G8452wYsUABCs41MsYrYbNxdjzF4liVfeDAE6F34ny45hJ8aUMqYPozXN7j a4b9iOHjMfqASfizmjKMkZy5vfINdq50kUegoIQo1blMB9qp0d43EVElOoGMtIyW+b+4 LAhVzzSi50SByXyWULyrOcbmdpheZC78j2iWFxMiOjbR9v5qgZOPg6jcr417QPS9Tnme T4cw== X-Gm-Message-State: ACrzQf3q1+7MCMe4pMByaMNUHQjGjyU8QrVIo44nfywPuH8w9Tqj6gNh 3znz54/1EnkCbbUDGJJPYpqe907EhNNKDSyz5BL/kMPdL23NF1M6mkK7bGC1Jy9pZhCnnOXyvcJ POqc7PyEBUn8zbbZ7fYIGBJesrwh9HJoJTi3Q8exC+5wcuVRNTDukea6xtWW27jsQs1+IVc29lw == X-Received: by 2002:a05:600c:281:b0:3b5:a5:7c9c with SMTP id 1-20020a05600c028100b003b500a57c9cmr4502937wmk.202.1664730293035; Sun, 02 Oct 2022 10:04:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6hffIhZYyUnNBJEihmHSF0OySRyzOYLyMNHe14KU3O3ZrwHRreEfSMTGGcv4Vb+RdZAAzE6g== X-Received: by 2002:a05:600c:281:b0:3b5:a5:7c9c with SMTP id 1-20020a05600c028100b003b500a57c9cmr4502925wmk.202.1664730292732; Sun, 02 Oct 2022 10:04:52 -0700 (PDT) Received: from localhost (52.72.115.87.dyn.plus.net. [87.115.72.52]) by smtp.gmail.com with ESMTPSA id x7-20020adfffc7000000b0022cbf4cda62sm6739951wrs.27.2022.10.02.10.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Oct 2022 10:04:52 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCHv2 1/7] gdb/remote: remove some manual reference count handling Date: Sun, 2 Oct 2022 18:04:42 +0100 Message-Id: <5c946ed5f149bc1a1491bf30750ae1d61e9c81ea.1664729721.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <20220921131200.3983844-1-aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" While working on some other target_ops reference count related code, I spotted that in remote.c we do some manual reference count handling, i.e. we call target_ops::incref and decref_target (which wraps target_ops::decref). I think it would be better to make use of gdb::ref_ptr to automate the reference count management. So, this commit updates scoped_mark_target_starting in two ways, first, I use gdb::ref_ptr to handle the reference counts. Then, instead of using the scoped_mark_target_starting constructor and destructor to set and reset the starting_up flag, I now use a scoped_restore_tmpl object to set and restore the flag. The above changes mean that the scoped_mark_target_starting destructor can be completely removed, and the constructor body is now empty. I've also fixed a typo in the class comment. The only change in behaviour after this commit is that previously we didn't care what the value of starting_up was, we just set it to true in the constructor and false in the destructor. Now, I assert that the flag is initially false, then set the flag true when the scoped_mark_target_starting is created. As the starting_up flag is initialized to false then, for the assert to fire, we would need to recursively enter remote_target::start_remote_1, which I don't think is something we should be doing, so I think the new assert is an improvement. --- gdb/remote.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 2f6cb2d01ee..5a71c41d61e 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -4706,7 +4706,7 @@ remote_target::process_initial_stop_replies (int from_tty) } } -/* Mark a remote_target as marking (by setting the starting_up flag within +/* Mark a remote_target as starting (by setting the starting_up flag within its remote_state) for the lifetime of this object. The reference count on the remote target is temporarily incremented, to prevent the target being deleted under our feet. */ @@ -4716,26 +4716,32 @@ struct scoped_mark_target_starting /* Constructor, TARGET is the target to be marked as starting, its reference count will be incremented. */ scoped_mark_target_starting (remote_target *target) - : m_remote_target (target) - { - m_remote_target->incref (); - remote_state *rs = m_remote_target->get_remote_state (); - rs->starting_up = true; - } + : m_remote_target (remote_target_ref::new_reference (target)), + m_restore_starting_up (set_starting_up_flag (target)) + { /* Nothing. */ } + +private: - /* Destructor, mark the target being worked on as no longer starting, and - decrement the reference count. */ - ~scoped_mark_target_starting () + /* Helper function, set the starting_up flag on TARGET and return an + object which, when it goes out of scope, will restore the previous + value of the starting_up flag. */ + static scoped_restore_tmpl + set_starting_up_flag (remote_target *target) { - remote_state *rs = m_remote_target->get_remote_state (); - rs->starting_up = false; - decref_target (m_remote_target); + remote_state *rs = target->get_remote_state (); + gdb_assert (!rs->starting_up); + return make_scoped_restore (&rs->starting_up, true); } -private: + /* A gdb::ref_ptr pointer to a remote_target. */ + using remote_target_ref = gdb::ref_ptr; + + /* A reference to the target on which we are operating. */ + remote_target_ref m_remote_target; - /* The target on which we are operating. */ - remote_target *m_remote_target; + /* An object which restores the previous value of the starting_up flag + when it goes out of scope. */ + scoped_restore_tmpl m_restore_starting_up; }; /* Helper for remote_target::start_remote, start the remote connection and From patchwork Sun Oct 2 17:04:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 58281 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EA5FF385C32C for ; Sun, 2 Oct 2022 17:06:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA5FF385C32C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664730416; bh=TFsmOshZnWjJVju45Rep8QUlW12A6bWmGabaNMVMDAI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=VN0bavnZKqSVltqeyaTxl15MRkcKnttuLJONr9R7QxIJ8r5yLBM9o2OR5Qg30ZA9h eGZ3qiq7bBYqJ/RaPepQBKi/mT6Nj8ZbaqtoyfmgGiDUsYcYmBoiPT2ymjhL3e8ytC QmTaxnwX1Nc4LVkpEjkUPkBpmZd5xILeY1DCjRHQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 A7CDB3858C2C for ; Sun, 2 Oct 2022 17:04:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A7CDB3858C2C Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-594-3ljVeDmZN4erDDez7Rykfw-1; Sun, 02 Oct 2022 13:04:56 -0400 X-MC-Unique: 3ljVeDmZN4erDDez7Rykfw-1 Received: by mail-wm1-f69.google.com with SMTP id c3-20020a7bc843000000b003b486fc6a40so2194626wml.7 for ; Sun, 02 Oct 2022 10:04:56 -0700 (PDT) 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; bh=TFsmOshZnWjJVju45Rep8QUlW12A6bWmGabaNMVMDAI=; b=tbLNVvWpzpEhLXaffKCDjP35Z8EMw/55775aHWt92TTFonAgP+uUXUkHm8sxEdhMo1 3HAkUyt6eG1zUQoJpSU7qVGtFYFGe+gPiF9jwTqXq9SxgUSnGOY/DzvPP0FksfOzrVAL g+415vDJsCY68KjKdv6e8yASHGjWWt1+g4Gd6CN1Ky4fIHV9+1wAiHY/eV1PjxGqtp+3 3fOcJ95uJ4pjEcgbB+Di3HQR/p2n3a3LGx6NJdOyM1Q2zM+mj7IuKxetv+feap6What0 HKfcwzOb0kiDXy+7nZXjTuJs23z4und+XNM5Txl4v7zgnOagJ7sMIHWrk1aNXIrxVPqr /gxg== X-Gm-Message-State: ACrzQf3yEGy8aAxFpT++RWC8JONEwVf/m0W5zQ3hU2gXuf9ifL6G9xmK XmtGvmkgdHw+amZz6RV2NUowl2mYG4i3wZRkpqUTnwjKAYMHEVco5h1+lmlrvBiG0B98djBFDZt giAdzOZAr97srJHSzwecKmCrmCcNIDvm8rMJf2MaCnsang9bE/drt3mzRAw5IpQyqztNDc/QWtA == X-Received: by 2002:a05:600c:35cf:b0:3b4:c0c2:d213 with SMTP id r15-20020a05600c35cf00b003b4c0c2d213mr4864531wmq.162.1664730295097; Sun, 02 Oct 2022 10:04:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7kPdrwY9zAMAtq9tsOuuLOea5ecnGaEL5I9gAMEPc3rUsIUVyPSV//Cs46h1vkriJYBIunaQ== X-Received: by 2002:a05:600c:35cf:b0:3b4:c0c2:d213 with SMTP id r15-20020a05600c35cf00b003b4c0c2d213mr4864518wmq.162.1664730294780; Sun, 02 Oct 2022 10:04:54 -0700 (PDT) Received: from localhost (52.72.115.87.dyn.plus.net. [87.115.72.52]) by smtp.gmail.com with ESMTPSA id q63-20020a1c4342000000b003b4bd18a23bsm14018629wma.12.2022.10.02.10.04.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Oct 2022 10:04:54 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCHv2 2/7] gdb: remove decref_target Date: Sun, 2 Oct 2022 18:04:43 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <20220921131200.3983844-1-aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The decref_target function is not really needed. Calling target_ops::decref will just redirect to decref_target anyway, so why not just rename decref_target to target_ops::decref? That's what this commit does. It's not exactly renaming to target_ops::decref, because the decref functionality is handled by a policy class, so the new name is now target_ops_ref_policy::decref. There should be no user visible change after this commit. --- gdb/target.c | 2 +- gdb/target.h | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/gdb/target.c b/gdb/target.c index 28560983625..9db44a83d55 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -1158,7 +1158,7 @@ to_execution_direction must be implemented for reverse async"); /* See target.h. */ void -decref_target (target_ops *t) +target_ops_ref_policy::decref (target_ops *t) { t->decref (); if (t->refcount () == 0) diff --git a/gdb/target.h b/gdb/target.h index 28aa9273893..0f5038fb9b2 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1337,9 +1337,6 @@ struct target_ops_deleter /* A unique pointer for target_ops. */ typedef std::unique_ptr target_ops_up; -/* Decref a target and close if, if there are no references left. */ -extern void decref_target (target_ops *t); - /* A policy class to interface gdb::ref_ptr with target_ops. */ struct target_ops_ref_policy @@ -1349,10 +1346,9 @@ struct target_ops_ref_policy t->incref (); } - static void decref (target_ops *t) - { - decref_target (t); - } + /* Decrement the reference count on T, and, if the reference count + reaches zero, close the target. */ + static void decref (target_ops *t); }; /* A gdb::ref_ptr pointer to a target_ops. */ From patchwork Sun Oct 2 17:04:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 58282 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7BF043857B9D for ; Sun, 2 Oct 2022 17:07:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BF043857B9D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664730428; bh=GmmL34ihBRWQL+uHvHQ5tuBfUxuSeAk2v5xIdqB9XL4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=K+ExFxkmt607xePRU07nQPUdOeEPimRX/LTFSeARP9hZa7CCZeUYVPqu+ncG7BF8e mP432oGlPSBhsuL9AFVZc+JMJ08VQlBVcyrBBezMlQLfIdWwKulnQ2GkTLBtB9ObuO 3DIUtPliXhYIOaos/5x0n7TKARSCUaJDSB1CUA7s= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 2DB303858401 for ; Sun, 2 Oct 2022 17:05:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2DB303858401 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-9-n7pnrQukNsq4ow2ek6pXNA-1; Sun, 02 Oct 2022 13:04:59 -0400 X-MC-Unique: n7pnrQukNsq4ow2ek6pXNA-1 Received: by mail-wm1-f72.google.com with SMTP id c2-20020a1c3502000000b003b535aacc0bso7830717wma.2 for ; Sun, 02 Oct 2022 10:04:58 -0700 (PDT) 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; bh=GmmL34ihBRWQL+uHvHQ5tuBfUxuSeAk2v5xIdqB9XL4=; b=iATLk5xlV3a4BRxP5Zyan9SveYpMHS7aRSEnfBZ4gmTQrdZA72zxCXVoEPZDZkNOb9 KDivTCsTH4MeeUA0/2uuWOwmxdf7VQuZuwEIuIZAEFEDTRxmtd9FqOSWRcV3hWbqkEDs E7N84jRgHS6l2KC9cB4KoyZunyMXRQP1JdGLDQadE85HR05b+tCkEgVuAImToLz2dGIG c8L7cCMpSkyT8Q+tt2duw5W0A2I430I5kB4cG+O1HwsmvyaUDd20E+gZWM5qW9Dm/145 zBk0SLHema3i5tCTGVi6S2jOvv1Zkrn/nZH0Xi9xiZSeOZf5gEQMUEGPDGKv8jJY/jTK x6eg== X-Gm-Message-State: ACrzQf3u2wbayWrRebusEdhhuAhB+XLUecmB5yMfnnkgP7IZH88fBYdl jaFj8TPuKVbMgSwsVRLSksQmAPkYyd0oGd+0Ffx42jvTBmdZv5KRgDhzKcrkZoSMYYRpayEXFVP VmpAESr3e/Gy7eIYnKqapakv41KKNhxIpsxTHHcqKGcs+t5mF7EZNyMS4MoYu+5VmxdM2JpoJ8w == X-Received: by 2002:adf:a28e:0:b0:22a:7428:3b04 with SMTP id s14-20020adfa28e000000b0022a74283b04mr11278772wra.75.1664730297145; Sun, 02 Oct 2022 10:04:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5lcvCbIAINUDCnKeC5+BphBDlHIv0TzW/+NZXI6wbBlO1ZTU35GEEvo5AL/CAwdyMDbhFqCw== X-Received: by 2002:adf:a28e:0:b0:22a:7428:3b04 with SMTP id s14-20020adfa28e000000b0022a74283b04mr11278750wra.75.1664730296530; Sun, 02 Oct 2022 10:04:56 -0700 (PDT) Received: from localhost (52.72.115.87.dyn.plus.net. [87.115.72.52]) by smtp.gmail.com with ESMTPSA id h9-20020a1c2109000000b003b4fac020c8sm13430470wmh.16.2022.10.02.10.04.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Oct 2022 10:04:56 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCHv2 3/7] gdb: have target_stack automate reference count handling Date: Sun, 2 Oct 2022 18:04:44 +0100 Message-Id: <8644cdfec11ab031b9cd1513a474f683c917ca87.1664729721.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <20220921131200.3983844-1-aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit changes the target_stack class from using a C style array of 'target_ops *' to using a C++ std::array. The benefit of this change is that some of the reference counting of target_ops objects is now done automatically. This commit fixes a crash in gdb.python/py-inferior.exp where GDB crashes at exit, leaving a core file behind. The crash occurs in connpy_connection_dealloc, and is actually triggered by this assert: gdb_assert (conn_obj->target == nullptr); Now a little aside... ... the assert is never actually printed, instead GDB crashes due to calling a pure virtual function. The backtrace at the point of crash looks like this: #7 0x00007fef7e2cf747 in std::terminate() () from /lib64/libstdc++.so.6 #8 0x00007fef7e2d0515 in __cxa_pure_virtual () from /lib64/libstdc++.so.6 #9 0x0000000000de334d in target_stack::find_beneath (this=0x4934d78, t=0x2bda270 ) at ../../s> #10 0x0000000000df4380 in inferior::find_target_beneath (this=0x4934b50, t=0x2bda270 ) at ../.> #11 0x0000000000de2381 in target_ops::beneath (this=0x2bda270 ) at ../../src/gdb/target.c:3047 #12 0x0000000000de68aa in target_ops::supports_terminal_ours (this=0x2bda270 ) at ../../src/gd> #13 0x0000000000dde6b9 in target_supports_terminal_ours () at ../../src/gdb/target.c:1112 #14 0x0000000000ee55f1 in internal_vproblem(internal_problem *, const char *, int, const char *, typedef __va_li> Notice in frame #12 we called target_ops::supports_terminal_ours, however, this is the_dummy_target, which is of type dummy_target, and so we should have called dummy_target::supports_terminal_ours. I believe the reason we ended up in the wrong implementation of supports_terminal_ours (which is a virtual function) is because we made the call during GDB's shut-down, and, I suspect, the vtables were in a weird state. Anyway, the point of this patch is not to fix GDB's ability to print an assert during exit, but to address the root cause of the assert. With that aside out of the way, we can return to the main story... Connections are represented in Python with gdb.TargtetConnection objects (or its sub-classes). The assert in question confirms that when a gdb.TargtetConnection is deallocated, the underlying GDB connection has itself been removed from GDB. If this is not true then we risk creating multiple different gdb.TargtetConnection objects for the same connection, which would be bad. To ensure that we have one gdb.TargtetConnection object for each connection, the all_connection_objects map exists, this maps the process_stratum_target object (the connection) to the gdb.TargtetConnection object that represents the connection. When a connection is removed in GDB the connection_removed observer fires, which we catch with connpy_connection_removed, this function then sets conn_obj->target to nullptr, and removes the corresponding entry from the all_connection_objects map. The first issue here is that connpy_connection_dealloc is being called as part of GDB's exit code, which is run after the Python interpreter has been shut down. The connpy_connection_dealloc function is used to deallocate the gdb.TargtetConnection Python object. Surely it is wrong for us to be deallocating Python objects after the interpreter has been shut down. The reason why connpy_connection_dealloc is called during GDB's exit is that the global all_connection_objects map is still holding a reference to the gdb.TargtetConnection object. When the map is destroyed during GDB's exit, the gdb.TargtetConnection objects within the map can finally be deallocated. The reason why all_connection_objects has contents when GDB exits, and the reason the assert fires, is that, when GDB exits, there are still some connections that have not yet been removed from GDB, that is, they have a non-zero reference count. If we take a look at quit_force (top.c) you can see that, for each inferior, we call pop_all_targets before we (later in the function) call do_final_cleanups. It is the do_final_cleanups call that is responsible for shutting down the Python interpreter. The pop_all_targets calls should, in theory, cause all the connections to be removed from GDB. That this isn't working indicates that some targets have a non-zero reference count even after this final pop_all_targets call, and indeed, when I debug GDB, that is what I see. I tracked the problem down to delete_inferior where we do some house keeping, and then delete the inferior object, which calls inferior::~inferior. In neither delete_inferior or inferior::~inferior do we call pop_all_targets, and it is this missing call that means we leak some references to the target_ops objects on the inferior's target_stack. In this commit I will provide a partial fix for the problem. I say partial fix, but this will actually be enough to resolve the crash. In a later commit I will provide the final part of the fix. As mentioned at the start of the commit message, this commit changes the m_stack in target_stack to hold target_ops_ref objects. This means that when inferior::~inferior is called, and m_stack is released, we automatically decrement the target_ops reference count. With this change in place we no longer leak any references, and now, in quit_force the final pop_all_targets calls will release the final references. This means that the targets will be correctly closed at this point, which means the connections will be removed from GDB and the Python objects deallocated before the Python interpreter shuts down. There's a slight oddity in target_stack::unpush, where we std::move the reference out of m_stack like this: auto ref = std::move (m_stack[stratum]); the `ref' isn't used explicitly, but it serves to hold the target_ops_ref until the end of the scope while allowing the m_stack entry to be reset back to nullptr. The alternative would be to directly set the m_stack entry to nullptr, like this: m_stack[stratum] = nullptr; The problem here is that when we set the m_stack entry to nullptr we first decrement the target_ops reference count, and then set the array entry to nullptr. If the decrement means that the target_ops object reaches a zero reference count then the target_ops object will be closed by calling target_close. In target_close we ensure that the target being closed is not in any inferiors target_stack. As we decrement before clearing, then this check in target_close will fail, and an assert will trigger. By using std::move to move the reference out of m_stack, this clears the m_stack entry, meaning the inferior no longer contains the target_ops in its target_stack. Now when the REF object goes out of scope and the reference count is decremented, target_close can run successfully. I've made use of the Python connection_removed listener API to add a test for this issue. The test installs a listener and then causes delete_inferior to be called, we can then see that the connection is then correctly removed (because the listener triggers). --- gdb/target.c | 43 +++++---- gdb/target.h | 4 +- .../gdb.python/py-connection-removed.exp | 92 +++++++++++++++++++ 3 files changed, 118 insertions(+), 21 deletions(-) create mode 100644 gdb/testsuite/gdb.python/py-connection-removed.exp diff --git a/gdb/target.c b/gdb/target.c index 9db44a83d55..0f4d6d01057 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -1174,23 +1174,28 @@ target_ops_ref_policy::decref (target_ops *t) void target_stack::push (target_ops *t) { - t->incref (); + /* We must create a new reference first. It is possible that T is + already pushed on this target stack, in which case we will first + unpush it below, before re-pushing it. If we don't increment the + reference count now, then when we unpush it, we might end up deleting + T, which is not good. */ + auto ref = target_ops_ref::new_reference (t); strata stratum = t->stratum (); - if (stratum == process_stratum) - connection_list_add (as_process_stratum_target (t)); - /* If there's already a target at this stratum, remove it. */ - if (m_stack[stratum] != NULL) - unpush (m_stack[stratum]); + if (m_stack[stratum].get () != nullptr) + unpush (m_stack[stratum].get ()); /* Now add the new one. */ - m_stack[stratum] = t; + m_stack[stratum] = std::move (ref); if (m_top < stratum) m_top = stratum; + + if (stratum == process_stratum) + connection_list_add (as_process_stratum_target (t)); } /* See target.h. */ @@ -1216,19 +1221,19 @@ target_stack::unpush (target_ops *t) return false; } - /* Unchain the target. */ - m_stack[stratum] = NULL; - if (m_top == stratum) m_top = this->find_beneath (t)->stratum (); - /* Finally close the target, if there are no inferiors - referencing this target still. Note we do this after unchaining, - so any target method calls from within the target_close - implementation don't end up in T anymore. Do leave the target - open if we have are other inferiors referencing this target - still. */ - decref_target (t); + /* Move the target reference off the target stack, this sets the pointer + held in m_stack to nullptr, and places the reference in ref. When + ref goes out of scope its reference count will be decremented, which + might cause the target to close. + + We have to do it this way, and not just set the value in m_stack to + nullptr directly, because doing so would decrement the reference + count first, which might close the target, and closing the target + does a check that the target is not on any inferiors target_stack. */ + auto ref = std::move (m_stack[stratum]); return true; } @@ -3604,8 +3609,8 @@ target_stack::find_beneath (const target_ops *t) const { /* Look for a non-empty slot at stratum levels beneath T's. */ for (int stratum = t->stratum () - 1; stratum >= 0; --stratum) - if (m_stack[stratum] != NULL) - return m_stack[stratum]; + if (m_stack[stratum].get () != NULL) + return m_stack[stratum].get (); return NULL; } diff --git a/gdb/target.h b/gdb/target.h index 0f5038fb9b2..68446a39c1b 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1385,7 +1385,7 @@ class target_stack { return at (t->stratum ()) == t; } /* Return the target at STRATUM. */ - target_ops *at (strata stratum) const { return m_stack[stratum]; } + target_ops *at (strata stratum) const { return m_stack[stratum].get (); } /* Return the target at the top of the stack. */ target_ops *top () const { return at (m_top); } @@ -1400,7 +1400,7 @@ class target_stack /* The stack, represented as an array, with one slot per stratum. If no target is pushed at some stratum, the corresponding slot is null. */ - target_ops *m_stack[(int) debug_stratum + 1] {}; + std::array m_stack; }; /* Return the dummy target. */ 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..6a0dbd17fe0 --- /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 . + +# Check that the gdb.connect_removed event triggers when we expect it +# too. +# +# Checking this event has wider implications that simply some corner +# 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('Connection %d (%s) removed' % (num, type))" "" \ + "gdb.events.connection_removed.connect (connection_removed_handler)" "" \ + "end" "" + +if { [target_info exists gdb_protocol] } { + if { [target_info gdb_protocol] == "extended-remote" } { + set connection_type "extended-remote" + } else { + set connection_type "remote" + } +} else { + set connection_type "native" +} + +# Add an inferior that shares a connection with inferior 1. +gdb_test "add-inferior" "Added inferior 2 on connection 1 \[^\r\n\]+" + +# Add an inferior with no connection. +gdb_test "add-inferior -no-connection" "Added inferior 3" + +# Kill the first inferior. If we are using the plain 'remote' protocol then +# it as this point that the remote target connection is removed. For the +# 'extended-remote' and 'native' targets the connection is removed later. +if { $connection_type == "remote" } { + gdb_test "with confirm off -- kill" \ + "Connection 1 \\(remote\\) removed\r\n.*" "kill inferior" +} else { + gdb_test "with confirm off -- kill" "" "kill inferior" +} + +# Switch to inferior 3 (the one with no connection). +gdb_test "inferior 3" + +# Remove inferior 1, not expecting anything interesting at this point. +gdb_test_no_output "remove-inferiors 1" + +# Now removed inferior 2. For the 'remote' target the connection has +# already been removed (see above), but for 'extended-remote' and 'native' +# targets, it is at this point that the connection is removed. +if { $connection_type == "remote" } { + gdb_test_no_output "remove-inferiors 2" +} else { + gdb_test "remove-inferiors 2" \ + "Connection 1 \\(${connection_type}\\) removed" +} From patchwork Sun Oct 2 17:04:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 58279 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BACFC385E440 for ; Sun, 2 Oct 2022 17:06:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BACFC385E440 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664730397; bh=VdBFh/7KYHTehCVd//IQ1lXGWTvqM5B1aQLxndy/Qa0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QZ8USWHaXsBq9UZQu41bIEvsH4pH6R992wb4pU+Wq4QO2zQTfTt0mGaTuBhBl+mUu kgo30oEjyHskK/eqBefI95kvzB9jUDlxNktl2oJ5d4qSjTyFoqHfO/PuOc9r3eiw1e iOnPnWv+K6/X3yb45gj5LJUeOO5Nd9g5hullpY3M= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 C2D3B3858407 for ; Sun, 2 Oct 2022 17:05:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C2D3B3858407 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-168-r3o9kTrrM3yjWyrt-EjXfw-1; Sun, 02 Oct 2022 13:05:00 -0400 X-MC-Unique: r3o9kTrrM3yjWyrt-EjXfw-1 Received: by mail-wr1-f72.google.com with SMTP id q28-20020adfab1c000000b0022e0399964dso1258182wrc.8 for ; Sun, 02 Oct 2022 10:05:00 -0700 (PDT) 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; bh=VdBFh/7KYHTehCVd//IQ1lXGWTvqM5B1aQLxndy/Qa0=; b=6zAy1xlkZMixQc/qDAPG3Bc2esMTpYXCtc+6//QOTOaRTaP3LoYUVEoqGzIhvIUzm2 /aeGQXmE/aKinyOU0iSaEX82+wt3U7+qsowt74rvhgFfrxAA/v7Z7kDICoEd1/9aPGm2 +cXCxEncTdenirIWPBW3ZLFJ/KxbJvxfj12p2RCaM6tuVEUVhy4qEZtrfpqymmq6EFv3 Rt3/gSZ2RAYthoITZVQVQgt6Q+X6/rS8nVMSZOH1KWEwLWiW0i/5Ml2S9Ug4faTzFhhF gJaUqf9wyWsyAgQpP5fvhsGKxe4jqnEvYr/0SFmvmRQgCY6m/0sGJkuKHMk8tdBJbyPR TpNA== X-Gm-Message-State: ACrzQf0s3wfkehGvEgICnD4us6TL91BEdNZCyhFk2fr+xh5tTIRkzVm8 HRjuO2zTZK4M2rdSkbaaH3Ufnt0kI2S/hyXRVGbHJvyR/GlGqO3S6hjF8p1vngz39YJjMkOsHx9 +YN2M7NarJoXF6NXMwGQ5l/PPb7G90pk2L+VdJ3nM0sTfE8OO0uwNfs9aZpf2V+vcsBPm0vTWrA == X-Received: by 2002:a5d:47cc:0:b0:22c:86fe:ad94 with SMTP id o12-20020a5d47cc000000b0022c86fead94mr11467792wrc.599.1664730298674; Sun, 02 Oct 2022 10:04:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7QLlMF9Gtd1uNeD2Ypy6aeZ2pHC3y8I00eP7RaaJmVIqpeq2849YFwq5kB8I8sQmNG6s4U9Q== X-Received: by 2002:a5d:47cc:0:b0:22c:86fe:ad94 with SMTP id o12-20020a5d47cc000000b0022c86fead94mr11467775wrc.599.1664730298341; Sun, 02 Oct 2022 10:04:58 -0700 (PDT) Received: from localhost (52.72.115.87.dyn.plus.net. [87.115.72.52]) by smtp.gmail.com with ESMTPSA id t20-20020a05600c199400b003b4fe03c881sm14180583wmq.48.2022.10.02.10.04.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Oct 2022 10:04:57 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCHv2 4/7] gdb: remove the pop_all_targets (and friends) global functions Date: Sun, 2 Oct 2022 18:04:45 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <20220921131200.3983844-1-aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit removes the global functions pop_all_targets, pop_all_targets_above, and pop_all_targets_at_and_above, and makes them methods on the inferior class. As the pop_all_targets functions will unpush each target, which decrements the targets reference count, it is possible that the target might be closed. Right now, closing a target, in some cases, depends on the current inferior being set correctly, that is, to the inferior from which the target was popped. To facilitate this I have used switch_to_inferior_no_thread within the new methods. Previously it was the responsibility of the caller to ensure that the correct inferior was selected. In a couple of places (event-top.c and top.c) I have been able to remove a previous switch_to_inferior_no_thread call. In remote_unpush_target (remote.c) I have left the switch_to_inferior_no_thread call as it is required for the generic_mourn_inferior call. --- gdb/event-top.c | 3 +-- gdb/inferior.c | 40 ++++++++++++++++++++++++++++++++++++++ gdb/inferior.h | 20 +++++++++++++++++++ gdb/remote.c | 2 +- gdb/scoped-mock-context.h | 2 +- gdb/target.c | 41 +-------------------------------------- gdb/target.h | 11 ----------- gdb/top.c | 3 +-- 8 files changed, 65 insertions(+), 57 deletions(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index 88c53b720a9..836e6b935e3 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -1293,10 +1293,9 @@ async_disconnect (gdb_client_data arg) for (inferior *inf : all_inferiors ()) { - switch_to_inferior_no_thread (inf); try { - pop_all_targets (); + inf->pop_all_targets (); } catch (const gdb_exception &exception) { diff --git a/gdb/inferior.c b/gdb/inferior.c index 7eb2bd97907..2014bf926b7 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -103,6 +103,46 @@ inferior::unpush_target (struct target_ops *t) return m_target_stack.unpush (t); } +/* See inferior.h. */ + +void inferior::unpush_target_and_assert (struct target_ops *target) +{ + gdb_assert (current_inferior () == this); + + if (!unpush_target (target)) + internal_error (__FILE__, __LINE__, + "pop_all_targets couldn't find target %s\n", + target->shortname ()); +} + +/* See inferior.h. */ + +void inferior::pop_all_targets_above (enum strata stratum) +{ + /* Unpushing a target might cause it to close. Some targets currently + rely on the current_inferior being set for their ::close method, so we + temporarily switch inferior now. */ + scoped_restore_current_pspace_and_thread restore_pspace_and_thread; + switch_to_inferior_no_thread (this); + + while ((int) (top_target ()->stratum ()) > (int) stratum) + unpush_target_and_assert (top_target ()); +} + +/* See inferior.h. */ + +void inferior::pop_all_targets_at_and_above (enum strata stratum) +{ + /* Unpushing a target might cause it to close. Some targets currently + rely on the current_inferior being set for their ::close method, so we + temporarily switch inferior now. */ + scoped_restore_current_pspace_and_thread restore_pspace_and_thread; + switch_to_inferior_no_thread (this); + + while ((int) (top_target ()->stratum ()) >= (int) stratum) + unpush_target_and_assert (top_target ()); +} + void inferior::set_tty (std::string terminal_name) { diff --git a/gdb/inferior.h b/gdb/inferior.h index bb3aec1e8f8..344974c4811 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -380,6 +380,22 @@ class inferior : public refcounted_object, target_ops *top_target () { return m_target_stack.top (); } + /* Unpush all targets except the dummy target from m_target_stack. As + targets are removed from m_target_stack their reference count is + decremented, which may cause a target to close. */ + void pop_all_targets () + { pop_all_targets_above (dummy_stratum); } + + /* Unpush all targets above STRATUM from m_target_stack. As targets are + removed from m_target_stack their reference count is decremented, + which may cause a target to close. */ + void pop_all_targets_above (enum strata stratum); + + /* Unpush all targets at and above STRATUM from m_target_stack. As + targets are removed from m_target_stack their reference count is + decremented, which may cause a target to close. */ + void pop_all_targets_at_and_above (enum strata stratum); + /* Return the target at process_stratum level in this inferior's target stack. */ struct process_stratum_target *process_target () @@ -598,6 +614,10 @@ class inferior : public refcounted_object, registry registry_fields; private: + + /* Unpush TARGET and assert that it worked. */ + void unpush_target_and_assert (struct target_ops *target); + /* The inferior's target stack. */ target_stack m_target_stack; diff --git a/gdb/remote.c b/gdb/remote.c index 5a71c41d61e..4864e9a55c3 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -5721,7 +5721,7 @@ remote_unpush_target (remote_target *target) for (inferior *inf : all_inferiors (target)) { switch_to_inferior_no_thread (inf); - pop_all_targets_at_and_above (process_stratum); + inf->pop_all_targets_at_and_above (process_stratum); generic_mourn_inferior (); } diff --git a/gdb/scoped-mock-context.h b/gdb/scoped-mock-context.h index a9895303015..87c1df0d206 100644 --- a/gdb/scoped-mock-context.h +++ b/gdb/scoped-mock-context.h @@ -71,7 +71,7 @@ struct scoped_mock_context ~scoped_mock_context () { inferior_list.erase (inferior_list.iterator_to (mock_inferior)); - pop_all_targets_at_and_above (process_stratum); + mock_inferior.pop_all_targets_at_and_above (process_stratum); } }; diff --git a/gdb/target.c b/gdb/target.c index 0f4d6d01057..1e447f604d9 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -1238,45 +1238,6 @@ target_stack::unpush (target_ops *t) return true; } -/* Unpush TARGET and assert that it worked. */ - -static void -unpush_target_and_assert (struct target_ops *target) -{ - if (!current_inferior ()->unpush_target (target)) - { - gdb_printf (gdb_stderr, - "pop_all_targets couldn't find target %s\n", - target->shortname ()); - internal_error (__FILE__, __LINE__, - _("failed internal consistency check")); - } -} - -void -pop_all_targets_above (enum strata above_stratum) -{ - while ((int) (current_inferior ()->top_target ()->stratum ()) - > (int) above_stratum) - unpush_target_and_assert (current_inferior ()->top_target ()); -} - -/* See target.h. */ - -void -pop_all_targets_at_and_above (enum strata stratum) -{ - while ((int) (current_inferior ()->top_target ()->stratum ()) - >= (int) stratum) - unpush_target_and_assert (current_inferior ()->top_target ()); -} - -void -pop_all_targets (void) -{ - pop_all_targets_above (dummy_stratum); -} - void target_unpusher::operator() (struct target_ops *ops) const { @@ -2533,7 +2494,7 @@ target_preopen (int from_tty) it doesn't (which seems like a win for UDI), remove it now. */ /* Leave the exec target, though. The user may be switching from a live process to a core of the same program. */ - pop_all_targets_above (file_stratum); + current_inferior ()->pop_all_targets_above (file_stratum); target_pre_inferior (from_tty); } diff --git a/gdb/target.h b/gdb/target.h index 68446a39c1b..547ee8a3bbd 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -2389,17 +2389,6 @@ extern void target_pre_inferior (int); extern void target_preopen (int); -/* Does whatever cleanup is required to get rid of all pushed targets. */ -extern void pop_all_targets (void); - -/* Like pop_all_targets, but pops only targets whose stratum is at or - above STRATUM. */ -extern void pop_all_targets_at_and_above (enum strata stratum); - -/* Like pop_all_targets, but pops only targets whose stratum is - strictly above ABOVE_STRATUM. */ -extern void pop_all_targets_above (enum strata above_stratum); - extern CORE_ADDR target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset); diff --git a/gdb/top.c b/gdb/top.c index 54c7c922142..5f64c6bddf0 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1845,10 +1845,9 @@ quit_force (int *exit_arg, int from_tty) them all out. */ for (inferior *inf : all_inferiors ()) { - switch_to_inferior_no_thread (inf); try { - pop_all_targets (); + inf->pop_all_targets (); } catch (const gdb_exception &ex) { From patchwork Sun Oct 2 17:04:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 58280 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 519BA3853808 for ; Sun, 2 Oct 2022 17:06:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 519BA3853808 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664730398; bh=HxhYM++0RjvJEu8CISnZW3K5C0pZi1gKg663mdTbMzw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=LHWL35s0i71KEhc5H81rczsw6HyElkB6LLmtuSNUgtaRemjSz9e4manHBTVdaCa84 7M1lChvZ/2WlaCohKHv/mNMNt93tLT8rD0tIMh9S8o1iSOjmcRBsRntX0gNF6iTiiS tDKLX0LmT1y0DEztwkI0BUzxvRLJYUrbjpuES4As= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 693C63858413 for ; Sun, 2 Oct 2022 17:05:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 693C63858413 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-210-y34ryelxOr2PPUbVb7IzvA-1; Sun, 02 Oct 2022 13:05:01 -0400 X-MC-Unique: y34ryelxOr2PPUbVb7IzvA-1 Received: by mail-wm1-f72.google.com with SMTP id r128-20020a1c4486000000b003b3309435a9so7085357wma.6 for ; Sun, 02 Oct 2022 10:05:01 -0700 (PDT) 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; bh=HxhYM++0RjvJEu8CISnZW3K5C0pZi1gKg663mdTbMzw=; b=zDAXXxbhW/UTXqSPBtFf3/4DQvcOFqLG3jGFgKq8tUJmQXOcPokMsrt3nixVA2pBgq 8uWFNh5BTu2rBoKFrd0acJvyqFIykuVbgmwl8P//BIqBYpID/SgEBRx9tyYxHsMHSvdj A1kgD+3H6jrWsrkhwXNql9KhdmNjnNHUFtZCZMlIk52DrSxEMmrNcdE95Zp1l2rZzast zAzwNDdgg6EShkE3xrab+YvHcThWtCjywSVJM36dqakF9h2O3+SXwmdeq3iDfpeF8dMC M7WtPGrNQ1BL4XB/RlsO5E0285qNiT0kMaV6qANsIW0/bA96Hs2TGYWHNkyxxLhGqVad wh8Q== X-Gm-Message-State: ACrzQf09/13hd5+pAzUM9bJLD646ayOzcYFErAcwYrujPu+ivF9SmnyG RC+mdLeWWdGs1bxpGayxC9P7a0DTum8tamqK2Swnkj5+ao8eAlyxhfnEgGhJw3wOaGYTtytBr0N YYiB6TlYx+xwH2ehbPF3rYnrAn51eNfjcBBRtnDODGkdiQiissbiIYVN5HXTDeoFDmlq6b9y1ug == X-Received: by 2002:a05:600c:1910:b0:3b4:bb80:c95e with SMTP id j16-20020a05600c191000b003b4bb80c95emr4401796wmq.54.1664730300292; Sun, 02 Oct 2022 10:05:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5iLukubpIWZEtgaZyGhP7GuZFhtHB/aocPlR1f5/lnrcVrdicosQ9+jIMsrUU9RWC5jE2dXA== X-Received: by 2002:a05:600c:1910:b0:3b4:bb80:c95e with SMTP id j16-20020a05600c191000b003b4bb80c95emr4401784wmq.54.1664730300028; Sun, 02 Oct 2022 10:05:00 -0700 (PDT) Received: from localhost (52.72.115.87.dyn.plus.net. [87.115.72.52]) by smtp.gmail.com with ESMTPSA id j29-20020adfa55d000000b00228d6bc8450sm9576745wrb.108.2022.10.02.10.04.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Oct 2022 10:04:59 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCHv2 5/7] gdb: ensure all targets are popped before an inferior is destructed Date: Sun, 2 Oct 2022 18:04:46 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <20220921131200.3983844-1-aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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 2014bf926b7..a498b9d493c 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); } @@ -231,6 +240,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; From patchwork Sun Oct 2 17:04:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 58284 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B5DF3854152 for ; Sun, 2 Oct 2022 17:07:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B5DF3854152 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664730457; bh=faT3zpzxUZgoCYTOqtUgjBtGZj5gR1XUL+XSfwfAUB0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=vbycyRaeJdr438Q1DoKIR/LDusAwr347U+jVyZ/F9XDCH/DCuh5WWGcRLz7LtmLcq MicXvQWehosECE7Z1913amS+R1hmLzn/4Z3cmeqh4njApC2VIvWv3LvjW4rdNm67Cp 6pQrav3WovdaFiyaUCXyUwsJwa4hXCcuEgTWyaZs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 1CCC3385841F for ; Sun, 2 Oct 2022 17:05:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1CCC3385841F Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-632-naHhQfrFObyHR_F_lDBGQQ-1; Sun, 02 Oct 2022 13:05:05 -0400 X-MC-Unique: naHhQfrFObyHR_F_lDBGQQ-1 Received: by mail-wm1-f69.google.com with SMTP id p36-20020a05600c1da400b003b4faefa2b9so5147587wms.6 for ; Sun, 02 Oct 2022 10:05:05 -0700 (PDT) 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; bh=faT3zpzxUZgoCYTOqtUgjBtGZj5gR1XUL+XSfwfAUB0=; b=GGxxjBdfp9/Zp5SbhwrbJs5T61I4qNhx3UwlcMBfPS7WvIQ9JPnjnjTmDFpOnPbl8U rBujH/wegcfEx6yDkLSfITqS0qoWvyopfBOQXmXw7TAsztyExSvo2yqxKDA5mTIW/MUL MtTm6V9q3b1yAXvgeaLKgAJyXn9L1xsl3DU/HI8GJqV6HqgEDWaAZZAKHvBXIGkjGd/U PJzVQULygnBgm1tVTf/kTTeZ0+4odtbBwF9ORHYow9RMht2bgrQJ7UGrp2FY8Bg7yzsf gA8n08hi6NV9kWrOfhi2lJaGHZvsUfjq+dhyByT/IrqBPdlFZyHagPZgT0xD45OpEQ3i SdkQ== X-Gm-Message-State: ACrzQf0NWrbEzElc9crS39t8BqBLVQWQFDMpDRQyhMuULr6GjvRUqhJo fkSEwQXqiwtC1SKzPcjOIxG5kQnGiQsRlVBprHt56Z4YLNS+G8I+Cu/c8AwpSBX1p4AIVJtzmj0 MwIMvBqKwxLJuWYHEiYZWIkknKixj92svaRkuZUBVcWtArTmXyTfRaW057JBpV4ZYIAChrMPIxQ == X-Received: by 2002:a05:6000:1e12:b0:22e:37d2:95aa with SMTP id bj18-20020a0560001e1200b0022e37d295aamr1795225wrb.135.1664730303933; Sun, 02 Oct 2022 10:05:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM61uRtXIY2FgG+duFMakGfqhiKXckJ6+G0X04FrKCKfgTg8t4vXFWks6DTfJZlvPexa/Ks/KA== X-Received: by 2002:a05:6000:1e12:b0:22e:37d2:95aa with SMTP id bj18-20020a0560001e1200b0022e37d295aamr1795214wrb.135.1664730303702; Sun, 02 Oct 2022 10:05:03 -0700 (PDT) Received: from localhost (52.72.115.87.dyn.plus.net. [87.115.72.52]) by smtp.gmail.com with ESMTPSA id j13-20020a5d452d000000b00228a6ce17b4sm7847271wra.37.2022.10.02.10.05.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Oct 2022 10:05:03 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCHv2 6/7] gdb/maint: add core file name to 'maint info program-spaces' output Date: Sun, 2 Oct 2022 18:04:47 +0100 Message-Id: <7c09a82cb88d20e3ff3449fcf854fcedb5f9ea58.1664729721.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <20220921131200.3983844-1-aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Each program space can have an associated core file. Include this information in the output of 'maint info program-spaces'. --- gdb/NEWS | 4 ++++ gdb/doc/gdb.texinfo | 8 ++++++-- gdb/progspace.c | 18 ++++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 796a4ef8072..a6ea7c9f98f 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -128,6 +128,10 @@ maintenance info line-table entry corresponds to an address where a breakpoint should be placed to be at the first instruction past a function's prologue. +maintenance info program-spaces + This command now includes a 'Core File' column which indicates the + name of the core file associated with each program space. + * New targets GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux* diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 44d87e95748..107df84d108 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -3465,6 +3465,10 @@ the name of the executable loaded into the program space, with e.g., the @code{file} command. +@item +the name of the core file loaded into the program space, with e.g., +the @code{core-file} command. + @end enumerate @noindent @@ -3477,7 +3481,7 @@ @smallexample (@value{GDBP}) maint info program-spaces - Id Executable + Id Executable Core File * 1 hello 2 goodbye Bound inferiors: ID 1 (process 21561) @@ -3491,7 +3495,7 @@ @smallexample (@value{GDBP}) maint info program-spaces - Id Executable + Id Executable Core File * 1 vfork-test Bound inferiors: ID 2 (process 18050), ID 1 (process 18045) @end smallexample diff --git a/gdb/progspace.c b/gdb/progspace.c index 90003d964fe..4f58d44a0e6 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -251,22 +251,30 @@ print_program_space (struct ui_out *uiout, int requested) { int count = 0; + /* Start with a minimum width of 17 for the executable name column. */ + size_t longest_exec_name = 17; + /* Compute number of pspaces we will print. */ for (struct program_space *pspace : program_spaces) { if (requested != -1 && pspace->num != requested) continue; + if (pspace->exec_filename != nullptr) + longest_exec_name = std::max (strlen (pspace->exec_filename.get ()), + longest_exec_name); + ++count; } /* There should always be at least one. */ gdb_assert (count > 0); - ui_out_emit_table table_emitter (uiout, 3, count, "pspaces"); + ui_out_emit_table table_emitter (uiout, 4, count, "pspaces"); uiout->table_header (1, ui_left, "current", ""); uiout->table_header (4, ui_left, "id", "Id"); - uiout->table_header (17, ui_left, "exec", "Executable"); + uiout->table_header (longest_exec_name, ui_left, "exec", "Executable"); + uiout->table_header (17, ui_left, "core", "Core File"); uiout->table_body (); for (struct program_space *pspace : program_spaces) @@ -291,6 +299,12 @@ print_program_space (struct ui_out *uiout, int requested) else uiout->field_skip ("exec"); + if (pspace->cbfd != nullptr) + uiout->field_string ("core", bfd_get_filename (pspace->cbfd.get ()), + file_name_style.style ()); + else + uiout->field_skip ("core"); + /* Print extra info that doesn't really fit in tabular form. Currently, we print the list of inferiors bound to a pspace. There can be more than one inferior bound to the same pspace, From patchwork Sun Oct 2 17:04:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 58283 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A950C3852761 for ; Sun, 2 Oct 2022 17:07:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A950C3852761 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664730433; bh=pIOMhbDVoLAg1dWQFEOI3pVyNciImjc7JQO2gpF5HQQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=n0HoSUei49wfOYK47O5vl5bAgEi2Fy645a7j2OApitjPWKOigDYoVa6lKjIMdom/S XBvVxoTHO9yASdxKUhqb2ycWV/I9YXBTJuTfR/c6DdwfMLaMx0Ao09d4odHvFlKDBF YRlWFQrCDRa2L3G/hDi8mizpzB1JfrLsYXSiThzE= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 086143858430 for ; Sun, 2 Oct 2022 17:05:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 086143858430 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-466-uzEin6SIOrKw8KoPw-tTJw-1; Sun, 02 Oct 2022 13:05:07 -0400 X-MC-Unique: uzEin6SIOrKw8KoPw-tTJw-1 Received: by mail-wm1-f70.google.com with SMTP id p36-20020a05600c1da400b003b4faefa2b9so5147628wms.6 for ; Sun, 02 Oct 2022 10:05:07 -0700 (PDT) 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; bh=pIOMhbDVoLAg1dWQFEOI3pVyNciImjc7JQO2gpF5HQQ=; b=6P1O3qbhWvs/Mv/tETLBlHXc5qNtj4RQx0pTdKlNasW4K8XaDM6LrSSwI1mbpGckDu CMWvH17G3LgbfL+n+BDXFvWeuahnrxrMhT+wm+E4M+VehckITe16k/K+R1kiAqNTH/bW H6R0HY/ZaNyxZ5nxmyy8qX6llEavCBgV+EsiWnZj30XYAdExCf9ZHtBHioWM/EyAEwI+ 4gQe5g9PJV0cFWCXfiNRh0d5E2jA1OHv4B49pJgOhIeFUWYIOG0hoUMjCo1FNRNEo6WJ ei+EOSl+cQiugXpC4xIc0T5NdQ+dTNgGREvYfvH7XSd4V88jmr3iavbKGMnKI9NVKUNq Yy5Q== X-Gm-Message-State: ACrzQf32VLe3ke4mVNrvnCm+vKUrBM8v80PLOgjkVRs9aXAeM0xQEJbB vT5mm84nxtEKveJ7SPRvZmv6yr6mlNY2g7hkWbWgGk0e83C2a6qGgHf1q7ifTwzi84de1vLGE7e vmSU0pdPht9XZhbbDm4IiTn53oTBqCXUFWf57+i+I/M9/u6Y6BpDtnL9gCTLvuTCHzx6mMq19Hw == X-Received: by 2002:adf:f1c8:0:b0:22e:3512:6989 with SMTP id z8-20020adff1c8000000b0022e35126989mr2501895wro.285.1664730305868; Sun, 02 Oct 2022 10:05:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6faIVi4/ItAOk3+KsrqB6ByNMnPbiz7aP5hbONMgMi8NsLk38mvSZf3c6CiNNBVgr2FimMtg== X-Received: by 2002:adf:f1c8:0:b0:22e:3512:6989 with SMTP id z8-20020adff1c8000000b0022e35126989mr2501875wro.285.1664730305262; Sun, 02 Oct 2022 10:05:05 -0700 (PDT) Received: from localhost (52.72.115.87.dyn.plus.net. [87.115.72.52]) by smtp.gmail.com with ESMTPSA id f13-20020a5d568d000000b0022584c82c80sm7747081wrv.19.2022.10.02.10.05.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Oct 2022 10:05:04 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCHv2 7/7] gdb: some process_stratum_target should not be shared Date: Sun, 2 Oct 2022 18:04:48 +0100 Message-Id: <3ea56551906f0e7815950c3dc98747ce86b6e64d.1664729722.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <20220921131200.3983844-1-aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" When multi-target support was added to GDB, an assumption was made that all process_stratum_target sub-classes could be shared by multiple inferiors. For things like the Linux and FreeBSD native targets, as well as the remote target, this is absolutely true (or was made true). But some targets were never updated to be shareable, for example, the core_target, which is used when reading core-files, stores some of its state in the program_space, but also, the core-file and the executable being debugged are closely related. As each add-inferior call creates an inferior with a new program_space, and doesn't automatically copy the executable, or the current core-file, I don't think it really makes sense to "share" core_target objects between inferiors. Consider this session: $ gdb -q (gdb) file test1 Reading symbols from test1... (gdb) core-file core.test1.433190 [New LWP 433190] Core was generated by `./test1'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x0000000000401111 in foo () at test1.c:6 6 return *global_ptr; (gdb) add-inferior [New inferior 2] Added inferior 2 on connection 1 (core) (gdb) info inferiors Num Description Connection Executable * 1 process 433190 1 (core) /tmp/multi-core/test1 2 1 (core) (gdb) info connections Num What Description * 1 core Local core dump file (gdb) inferior 2 [Switching to inferior 2 [] ()] (gdb) file test2 Reading symbols from test2... (gdb) core-file core.test2.433203 [New LWP 433203] Core was generated by `./test2'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x0000000000401111 in main () at test2.c:6 6 return *global_ptr; (gdb) info inferiors Num Description Connection Executable 1 process 433190 1 (core) /tmp/multi-core/test1 * 2 process 433203 2 (core) /tmp/multi-core/test2 (gdb) info connections Num What Description 1 core Local core dump file * 2 core Local core dump file (gdb) After the 'add-inferior' the core_target connection is shared between the inferiors. However, as soon as the user sets up the core-file and executable in the new inferior a new core connection has been created. I think this behaviour might be confusing, so I'd like to have GDB not initially share the core connection. Instead, when the user tries to add the new inferior a warning is given, and the new inferior is created without a connection, like this: $ gdb -q (gdb) file test1 Reading symbols from test1... (gdb) core-file core.test1.433190 [New LWP 433190] Core was generated by `./test1'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x0000000000401111 in foo () at test1.c:6 6 return *global_ptr; (gdb) add-inferior [New inferior 2] warning: can't share connection 1 (core) between inferiors Added inferior 2 (gdb) info inferiors Num Description Connection Executable * 1 process 433190 1 (core) /tmp/multi-core/test1 2 (gdb) If the user explicitly asks for the new inferior to be created without a connection, then no warning will be given. At this point the user is free to setup inferior 2 with a different executable and core file (or to do anything they like with the inferior). In an earlier version of this patch I had GDB error instead of giving a warning. However, the error message ended up being something like: can't share connection ..... between inferiors, use -no-connection option to create an inferior without sharing a connection. but it seemed better to just create the inferior. I've updated the docs, and added a NEWS entry for the new warning. In the docs for clone-inferior I've added reference to -no-connection, which was previously missing. --- gdb/NEWS | 7 + gdb/corelow.c | 5 + gdb/doc/gdb.texinfo | 37 ++++- gdb/inferior.c | 16 ++ gdb/inferior.h | 6 +- gdb/target.c | 14 ++ gdb/target.h | 8 + gdb/testsuite/gdb.multi/multi-core-files-1.c | 37 +++++ gdb/testsuite/gdb.multi/multi-core-files-2.c | 31 ++++ gdb/testsuite/gdb.multi/multi-core-files.exp | 156 +++++++++++++++++++ 10 files changed, 313 insertions(+), 4 deletions(-) create mode 100644 gdb/testsuite/gdb.multi/multi-core-files-1.c create mode 100644 gdb/testsuite/gdb.multi/multi-core-files-2.c create mode 100644 gdb/testsuite/gdb.multi/multi-core-files.exp diff --git a/gdb/NEWS b/gdb/NEWS index a6ea7c9f98f..cb576edd203 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -71,6 +71,13 @@ For both /r and /b GDB is now better at using whitespace in order to align the disassembled instruction text. +* The add-inferior, clone-inferior, and MI -add-inferior commands will + now give a warning, and create the new inferior without a + connection, when the current inferior, at the time the command is + given, is a core-file target. The core-file target could never + really be shared between inferiors, GDB is now more vocal about what + is going on. + * New commands maintenance set ignore-prologue-end-flag on|off diff --git a/gdb/corelow.c b/gdb/corelow.c index 293bc8d4f59..4d8393a3587 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -128,6 +128,11 @@ class core_target final : public process_stratum_target /* See definition. */ void info_proc_mappings (struct gdbarch *gdbarch); + /* The core_target only works for the inferior in which it was initially + opened, and can't be copied to some other inferior's target_stack. */ + bool is_shareable () override + { return false; } + private: /* per-core data */ /* Get rid of the core inferior. */ diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 107df84d108..a558fc4de38 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -3358,8 +3358,31 @@ remote} command to connect to some other @code{gdbserver} instance, use @code{run} to spawn a local program, etc. +Not all connections can be shared between inferiors. For example, the +@code{target core} target is unique for each inferior. That is, +multiple inferiors can use @code{target core} at the same time, but +each @code{target core} is different. If you try to +@code{add-inferior}, and the current inferior is @code{target core}, +then @value{GDBN} will give a warning and create the new inferior +without a connection, like this: + +@smallexample +(@value{GDBP}) file test1 +Reading symbols from test1... +(@value{GDBP}) target core core.test1.433190 +[New LWP 433190] +Core was generated by `./test1'. +Program terminated with signal SIGSEGV, Segmentation fault. +#0 0x0000000000401111 in foo () at test1.c:6 +6 return *global_ptr; +(@value{GDBP}) add-inferior +[New inferior 2] +warning: can't share connection 1 (core) between inferiors +Added inferior 2 +@end smallexample + @kindex clone-inferior -@item clone-inferior [ -copies @var{n} ] [ @var{infno} ] +@item clone-inferior [ -copies @var{n} ] [ -no-connection ] [ @var{infno} ] Adds @var{n} inferiors ready to execute the same program as inferior @var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the number of the current inferior. This command copies the values of the @@ -3384,6 +3407,13 @@ You can now simply switch focus to inferior 2 and run it. +Like @code{add-inferior}, @code{clone-inferior} shares the connection +with the inferior @var{infno}. If the @var{-no-connection} option is +given then the new inferior will be created without a connection. If +the connection of inferior @var{infno} can't be shared, then +@value{GDBN} will give a warning, and the new inferior will be created +without a connection. + @kindex remove-inferiors @item remove-inferiors @var{infno}@dots{} Removes the inferior or inferiors @var{infno}@dots{}. It is not @@ -37786,6 +37816,11 @@ @code{gdbserver} instance, use @code{-exec-run} to spawn a local program, etc. +If the connection of the current inferior cannot be shared, e.g.@: the +@code{-target-select core} target cannot be shared between inferiors, +then @value{GDBN} will give a warning and create the new inferior +without a connection. + The command response always has a field, @var{inferior}, whose value is the identifier of the thread group corresponding to the new inferior. diff --git a/gdb/inferior.c b/gdb/inferior.c index a498b9d493c..0868a55593a 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -817,6 +817,22 @@ switch_to_inferior_and_push_target (inferior *new_inf, symbols. */ switch_to_inferior_no_thread (new_inf); + if (!no_connection && proc_target != nullptr + && !proc_target->is_shareable ()) + { + if (proc_target->connection_string () != nullptr) + warning (_("can't share connection %d (%s %s) between inferiors"), + proc_target->connection_number, + proc_target->shortname (), + proc_target->connection_string ()); + else + warning (_("can't share connection %d (%s) between inferiors"), + proc_target->connection_number, + proc_target->shortname ()); + + proc_target = nullptr; + } + /* Reuse the target for new inferior. */ if (!no_connection && proc_target != NULL) { diff --git a/gdb/inferior.h b/gdb/inferior.h index 344974c4811..639364e5de3 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -762,9 +762,9 @@ extern struct inferior *add_inferior_with_spaces (void); /* Print the current selected inferior. */ extern void print_selected_inferior (struct ui_out *uiout); -/* Switch to inferior NEW_INF, a new inferior, and unless - NO_CONNECTION is true, push the process_stratum_target of ORG_INF - to NEW_INF. */ +/* Switch to inferior NEW_INF, a new inferior, and unless NO_CONNECTION is + true, or the process_stratum_target of ORG_INF is not shareable, push + the process_stratum_target of ORG_INF to NEW_INF. */ extern void switch_to_inferior_and_push_target (inferior *new_inf, bool no_connection, inferior *org_inf); diff --git a/gdb/target.c b/gdb/target.c index 1e447f604d9..65bc0e7246e 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -1188,6 +1188,12 @@ target_stack::push (target_ops *t) if (m_stack[stratum].get () != nullptr) unpush (m_stack[stratum].get ()); + /* If this target can't be shared, then check that the target doesn't + already appear on some other target stack. */ + if (!t->is_shareable ()) + for (inferior *inf : all_inferiors ()) + gdb_assert (!inf->target_is_pushed (t)); + /* Now add the new one. */ m_stack[stratum] = std::move (ref); @@ -3226,6 +3232,14 @@ target_ops::fileio_readlink (struct inferior *inf, const char *filename, /* See target.h. */ +bool +target_ops::is_shareable () +{ + return true; +} + +/* See target.h. */ + int target_fileio_open (struct inferior *inf, const char *filename, int flags, int mode, bool warn_if_slow, fileio_error *target_errno) diff --git a/gdb/target.h b/gdb/target.h index 547ee8a3bbd..30e5085a543 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1321,6 +1321,14 @@ struct target_ops virtual bool store_memtags (CORE_ADDR address, size_t len, const gdb::byte_vector &tags, int type) TARGET_DEFAULT_NORETURN (tcomplain ()); + + /* Return true if this target can be shared on multiple target_stacks, + or false if this target should only appear on a single target_stack. + When this function returns false multiple separate instances of the + same target_ops sub-class can still appear on different + target_stacks, but the same concrete instance can only appear on a + single target_stack. */ + virtual bool is_shareable (); }; /* Deleter for std::unique_ptr. See comments in diff --git a/gdb/testsuite/gdb.multi/multi-core-files-1.c b/gdb/testsuite/gdb.multi/multi-core-files-1.c new file mode 100644 index 00000000000..f996973023e --- /dev/null +++ b/gdb/testsuite/gdb.multi/multi-core-files-1.c @@ -0,0 +1,37 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 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 . */ + +#include + +int +bar () +{ + abort (); + return 0; +} + +int +baz () +{ + return bar (); +} + +int +main () +{ + return baz (); +} diff --git a/gdb/testsuite/gdb.multi/multi-core-files-2.c b/gdb/testsuite/gdb.multi/multi-core-files-2.c new file mode 100644 index 00000000000..fb99e137c3f --- /dev/null +++ b/gdb/testsuite/gdb.multi/multi-core-files-2.c @@ -0,0 +1,31 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 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 . */ + +#include + +int +foo () +{ + abort (); + return 0; +} + +int +main () +{ + return foo (); +} diff --git a/gdb/testsuite/gdb.multi/multi-core-files.exp b/gdb/testsuite/gdb.multi/multi-core-files.exp new file mode 100644 index 00000000000..9cf188b0caa --- /dev/null +++ b/gdb/testsuite/gdb.multi/multi-core-files.exp @@ -0,0 +1,156 @@ +# Copyright 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 . + +# This script runs some basic tests that GDB can support multiple +# inferiors each debugging different core files. +# +# We also check the behaviour of GDB if the user attempts to clone or +# duplicate an inferior that is debugging a core file. + +standard_testfile -1.c -2.c + +set binfile1 "${binfile}-1" +set binfile2 "${binfile}-2" + +if {[build_executable "build first executable" $binfile1 $srcfile \ + debug] == -1} { + untested "failed to compile first executable" + return -1 +} + +if {[build_executable "build first executable" $binfile2 $srcfile2 \ + debug] == -1} { + untested "failed to compile second executable" + return -1 +} + +set corefile1 [core_find $binfile1] +set corefile2 [core_find $binfile2] + +# Start GDB, and load the first executable and corefile into the first +# inferior. +clean_restart ${binfile1} +gdb_test "core-file $corefile1" "Program terminated with .*" \ + "load core file" +gdb_test "bt" "bar \\(\\) at .*" \ + "check backtrace in inferior 1" + +# Try to use add-inferior and clone-inferior to create new +# inferiors. In both cases this will try to share the core_target +# between inferior 1 and the new inferior. As the core_target can't +# be shared we should get a warning, and the inferior should be +# created without a connection. +gdb_test "add-inferior" \ + [multi_line \ + "\\\[New inferior 2\\\]" \ + "warning: can't share connection 1 \\(core\\) between inferiors" \ + "Added inferior 2"] +gdb_test "clone-inferior" \ + [multi_line \ + "\\\[New inferior 3\\\]" \ + "warning: can't share connection 1 \\(core\\) between inferiors" \ + "Added inferior 3"] + +# Check the MI -add-inferior command. Do this using interpreter-exec. +# We're not doing a full MI test here, just checking this one command. +gdb_test "interpreter-exec mi \"-add-inferior\"" \ + [multi_line \ + "~\"\\\[New inferior 4\\\]..\"" \ + "&\"warning: can't share connection 1 \\(core\\) between inferiors..\"" \ + "~\"Added inferior 4..\"" \ + "\\^done,inferior=\"\[^\"\]+\""] + +# Now check that non of the new inferiors have a connection. +gdb_test "info inferiors" \ + [multi_line \ + "\\*\\s+1\\s+\[^\r\n\]+\\s+1 \\(core\\)\\s+\[^\r\n\]+.*" \ + "\\s+2\\s+\\s+" \ + "\\s+3\\s+\\s+\[^\r\n\]+" \ + "\\s+4\\s+\\s+"] \ + "first info inferiors call" + +# Now use add-inferior and clone-inferior but this time with the +# -no-connection option, this should avoid issuing the warning. We +# also use interpreter-exec to test the MI version of this command. +gdb_test "add-inferior -no-connection" \ + [multi_line \ + "\\\[New inferior 5\\\]" \ + "Added inferior 5"] +gdb_test "clone-inferior -no-connection" \ + [multi_line \ + "\\\[New inferior 6\\\]" \ + "Added inferior 6"] +gdb_test "interpreter-exec mi \"-add-inferior --no-connection\"" \ + "\\\[New inferior 7\\\].*Added inferior 7.*" + +# Now check that non of the new inferiors have a connection. +gdb_test "info inferiors" \ + [multi_line \ + "\\*\\s+1\\s+\[^\r\n\]+\\s+1 \\(core\\)\\s+\[^\r\n\]+.*" \ + "\\s+2\\s+\\s+" \ + "\\s+3\\s+\\s+\[^\r\n\]+" \ + "\\s+4\\s+\\s+" \ + "\\s+5\\s+\\s+" \ + "\\s+6\\s+\\s+\[^\r\n\]+" \ + "\\s+7\\s+\\s+"] \ + "second info inferiors call" + +# Check after all the new inferiors have been created that we still +# only have a single connection. +gdb_test "info connections" \ + "\\*\\s+1\\s+\\s+core\\s+Local core dump file\\s*" + +# Now switch to inferior 2 and load the second executable and core +# file. Check the backtrace for the presence of function 'foo', this +# indicates we are seeing the correct core file. +gdb_test "inferior 2" "Switching to inferior 2 .*" +gdb_test "file $binfile2" \ + "Reading symbols from .*" \ + "Loaded second test binary" +gdb_test "core-file $corefile2" \ + "Program terminated with signal SIGABRT, Aborted.*" \ + "Loaded second core file" +gdb_test "bt" "foo \\(\\) at .*" \ + "check backtrace in inferior 2" + +# Switch to inferior 3, this one was cloned from inferior 1, so is +# already debugging the first binary file. Check its backtrace for +# 'bar', which indicates we are debugging the correct core file. +gdb_test "inferior 3" "Switching to inferior 3 .*" +gdb_test "core-file $corefile1" \ + "Program terminated with signal SIGABRT, Aborted.*" \ + "Loaded first core file into inferior 3" +gdb_test "bt" "bar \\(\\) at .*" \ + "check backtrace in inferior 3" + +# Detach from some of the core files and delete some of the inferiors. +gdb_test "detach" "No core file now\\." \ + "detach from inferior 3 core file" +gdb_test "inferior 2" "Switching to inferior 2 .*" \ + "switch back to inferior 2" +gdb_test_no_output "remove-inferiors 3 4" + +# Now detach in inferior 2, and delete the inferior. +gdb_test "detach" "No core file now\\." \ + "detach from inferior 2 core file" +gdb_test "inferior 1" "Switching to inferior 1 .*" \ + "switch back to inferior 1" +gdb_test_no_output "remove-inferiors 2" + +# Finally, check that inferior 1 backtrace is still working. +gdb_test "bt" "bar \\(\\) at .*" \ + "check backtrace in inferior 1 again" +gdb_test "detach" "No core file now\\." \ + "detach from inferior 1 core file"