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 829E23858D33 for ; Wed, 1 Feb 2023 20:16:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 829E23858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca 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)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 199EA1E112; Wed, 1 Feb 2023 15:16:40 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1675282600; bh=qUZ+p8ncuXT5xLQxpyl+7SI/hl5P3gZOdmx8j4zJxhQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=eGUdUvz+TaZ29wwLBjlAkQJY/HA+6QSSEoTlE/AiR4rm52ttOZcffNhlORF+DTbRZ P19sw+LuSCQJLcHHtodtjBQbaoprsq5EKQtSQrrcDPUVYb+UI3Z69ndo1hKSFXdevK qFVj4bGCXpL1NtIxhkSEaMJ6okPcOSn/b07RBW7s= Message-ID: Date: Wed, 1 Feb 2023 15:16:39 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH v3 6/8] gdb/remote: Parse tdesc field in stop reply and threads list XML Content-Language: en-US To: Andrew Burgess , Thiago Jung Bauermann via Gdb-patches Cc: Thiago Jung Bauermann References: <20230130044518.3322695-1-thiago.bauermann@linaro.org> <20230130044518.3322695-7-thiago.bauermann@linaro.org> <87edr9tq0c.fsf@redhat.com> <9f5deefd-52fc-9792-f9a5-dede9c415777@simark.ca> From: Simon Marchi In-Reply-To: <9f5deefd-52fc-9792-f9a5-dede9c415777@simark.ca> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.9 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 List-Id: > IIUC, the tdescs would be deleted during the > pop_all_targets_at_and_above, when the refcount of the remote_target > gets to 0 and it gets deleted. And the threads would be removed in > generic_mourn_inferior just after. > > An idea could be to call generic_mourn_inferior before > remote_unpush_target (no idea if it works). Another one would be to > get a temporary reference to the remote_target object in > remote_unpush_target, just so that it outlives the threads. > Or maybe we should say that it's a process target's responsibility to > delete any thread it "owns" before getting deleted itself. Another question related to this popped while reading the following patch. When creating a gdbarch from a tdesc, the gdbarch keeps a pointer to that tdesc (accessible through gdbarch_target_desc). And AFAIK, we never delete gdbarches. So I suppose the gdbarch will refer a stale target desc. At first I thought it wouldn't be a problem in practice, because while that gdbarch object still exists, nothing references it (it is effectively leaked). But then I remember that we cache gdbarches to avoid creating arches with duplicate features. So later (let's say if you connect again to a remote), we might want to create a gdbarch with the same features as before, and we'll dig up the old gdbarch, that points to the now deleted tdesc. Perhaps it's possible to generate a crash with the current implementation by connecting, disconnecting, connecting again, and then doing something that uses the thread-specific gdbarch. Simon