From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id E114F3858422 for ; Thu, 22 Sep 2022 14:52:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E114F3858422 Received: from [10.0.0.11] (unknown [217.28.27.60]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 1BD1F1E0D3; Thu, 22 Sep 2022 10:52:50 -0400 (EDT) Message-ID: Date: Thu, 22 Sep 2022 10:52:49 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH] gdb: fix target_ops reference count for some cases Content-Language: en-US To: Andrew Burgess , gdb-patches@sourceware.org References: <20220921131200.3983844-1-aburgess@redhat.com> <87eae56e-e370-0f02-86b4-d4d2edb4dfa8@simark.ca> <87edw3ebgm.fsf@redhat.com> From: Simon Marchi In-Reply-To: <87edw3ebgm.fsf@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, 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-List-Received-Date: Thu, 22 Sep 2022 14:52:53 -0000 > I agree with you 100%. Unfortunately, the following targets all seem to > depend on current_inferior being set (in their ::close method): > > bsd_kvm_target > core_target > darwin_nat_target > record_btrace_target > ctf_target > tfile_target > windows_nat_target (though this is only for debug output) > > I suspect that this means these targets only really work when GDB has a > single inferior maybe? In most cases GDB seems to be clearing out some > per-inferior state relating to the target... I need to investigate more, > but I guess I wanted to raise this in case you (or anyone) had thoughts. Ah, ok. Yeah I see some targets calling exit_inferior_silent on the current inferior, among other things. I guess I misunderstand what target_ops::close is meant to do, I thought this would have been done earlier. Different targets seem to use the close method for different things. So, in any case, my proposition falls into "no doable right now". >>> At the moment the inferior's program_space is deleted in >>> delete_inferior before we call inferior::~inferior, so, I think, to >>> place the pop_all_targets call into inferior::~inferior would require >>> additional adjustment to GDB. As delete_inferior already exists, and >>> includes various house keeping tasks, it doesn't seem unreasonable to >>> place the pop_all_targets call there. >> >> I don't object to fixing it like this. I'm just wondering, did you >> consider changing target_stack::m_stack to make it hold string >> references, something like std::vector? I haven't tried >> so maybe this doesn't make sense / is too difficult. But if it does, I >> guess the problem would take care of itself. When deleting an inferior >> that still has some targets pushed, they would be automatically decref'd >> and closed if needed. > > I did think about this. I think in the end the fix I proposed here > was just less churn. Agreed. > As I mention above, right now it seems we do need th correct inferior > selected, so we might need something like this, I'll see how my new > patches work out. I think your approach is ok, it fixes a real bug, so big refactorings should not get in the way of that. I'll take a look at the code now. Simon