From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.freebsd.org (mx2.freebsd.org [IPv6:2610:1c1:1:606c::19:2]) by sourceware.org (Postfix) with ESMTPS id 9771A3858D1E for ; Tue, 29 Nov 2022 19:27:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9771A3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 4NMC5y274wz3xP0; Tue, 29 Nov 2022 19:27:34 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NMC5y1DX8z3Ggq; Tue, 29 Nov 2022 19:27:34 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669750054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lLNS370QWM1XYisxOvfToXCdO2wpPlb7jbx+4wqEYSQ=; b=shQmvQJ0lDhcxRkvb62XnFcKy8+DhvU60aKCnk1USz2iprGmJf0zoF0GxM3JEYCZMFL0Q3 Z7HxHwFpi0K+nhSgJ/IRceuleniMkhpU2tuYO12BAPLcZugPlKpFlEX64gwelcF2KsQU+0 haSLuqq2x4ld20EY9gqVROSDY31OWIK6WoKYa8ouDy3R5TYeVEtsIFp1VLM+LIBXNl7RCz coQyMOLfGwHfVQCRKsmmFbnvsn+0ImqqT9hsajWR53pXLIyQQ9OwZy2Ej/RvHITVisOYHd WisyzDZp7p1ODeMKzwuzyr6Th+LFY/tRtVOobMxRKmrVkzixwfLVyUtWcTT7ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669750054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lLNS370QWM1XYisxOvfToXCdO2wpPlb7jbx+4wqEYSQ=; b=BR/VYKX922EARLNmMN1wiLVbaseEP0zlFbgcxCb0fSvskgbzrMjPag1k8TF+A1QUAXKAUn 5phnHPYfZXxj4pcK2rBtGFn8fwk+aFwxgTrVQ2Suyynlgae8PsQyqngfypVyfAswNbES5W gGb1RzvayjIHVz4JigDkurFEiRylXHzknT3T9bSVrs8OCg6w0v6enLhqoDqmqxNXjatfs/ NCj9g1zLljm424DA3mMvWT2qeIWKeR5tKevbkcE88G8y1oJJTyrHpsoAaWxXau7ZM/prB2 Dr9WUASHm5jHRtv0U/r9sCvV5XtBKOGYUgMpNASJqB1bmo6D7xv7BcsVgukHvw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669750054; a=rsa-sha256; cv=none; b=qz3PwnYUaxVwy1KZU4JLTwnF1MRaxhKoDoBIVFQUhTiKlug0Zyg3KDBcyPEizBBS/v+937 lKT7PjftaWV/yePKniZrfgdQoY6CL4dbniL7r63RsXGrC0aa5evKoP2f1Dk2sXDcxUukaV 47x0f3qYRmhWCyX+H3BnzaJ8ebYyUcGNZwirCV+eUfeREJcsRd2/cjO1SotgsFEPyvDu25 o06ozF8bHbxIa0J8b7qEg1y5W+zwO4/zc7RsB58xDDNop4Z0tRJKGD3yD9HEqS1RuFrvu4 3QdXw7X0GUp9n6jJIgkZVUxYzlWzvgJDU95ZdLlz7Mb0dpb4EXOTb5U3+mjsVw== Received: from [10.0.1.4] (ralph.baldwin.cx [66.234.199.215]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 4NMC5x5CZnzfqH; Tue, 29 Nov 2022 19:27:33 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: <65b25c24-eb7e-65fb-ad96-08665bbcbb67@FreeBSD.org> Date: Tue, 29 Nov 2022 11:27:32 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Content-Language: en-US To: Simon Marchi , gdb-patches@sourceware.org References: <20221129025048.44490-1-simon.marchi@polymtl.ca> <20221129025048.44490-2-simon.marchi@polymtl.ca> From: John Baldwin Subject: Re: [PATCH 2/3] gdb: break up core_target initialization In-Reply-To: <20221129025048.44490-2-simon.marchi@polymtl.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_NONE,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: On 11/28/22 6:50 PM, Simon Marchi via Gdb-patches wrote: > In the core target constructor, we currently have to jump through some > hoops to read the auxv data from the core, in order to choose an > appropriate gdbarch for the inferior. The core BFD gives us a gdbarch, > but it might not tell the whole story. By reading some auxv fields, > some architectures are able to choose a more specific gdbarch. The > problem is that to read auxv from the core using the inferior's target > stack, the core target needs to be pushed on the inferior's target > stack. But this work is done in the core target constructor, so it > can't be pushed at this point. The current solution is to pass a > pointer to the core target to gdbarch_core_read_description, in > core_target::read_description. That "hack" must then propagate to many > functions involved in selecting the architecture and reading auxv. > > With this patch, I propose to break things up to avoid the problem. The > core_target constructor will now do only trivial stuff that doesn't need > to call things outside core_target. Then, we'll push the core_target on > the inferior's target stack. And finally, complete the initialization > that potentially requires doing target calls. The target calls to read > auxv at this point will just be regular target calls. I think this is a nice solution to the problem. > diff --git a/gdb/corelow.c b/gdb/corelow.c > index 293bc8d4f593..c8cd5b7a2570 100644 > --- a/gdb/corelow.c > +++ b/gdb/corelow.c > @@ -72,6 +72,13 @@ class core_target final : public process_stratum_target > public: > core_target (); > > + /* Complete the initialization. > + > + Called after construction, after pushing the target to the inferior's > + target stack, so that arches are can do target calls, for instance to read > + auxv. */ > + void initialize (); s/arches are can/arches can/ > @@ -170,7 +177,11 @@ core_target::core_target () > /* Find a first arch based on the BFD. We need the initial gdbarch so > we can setup the hooks to find a target description. */ > m_core_gdbarch = gdbarch_from_bfd (core_bfd); > +} > > +void > +core_target::initialize () > +{ > /* If the arch is able to read a target description from the core, it > could yield a more specific gdbarch. */ > const struct target_desc *tdesc = read_description (); I do wonder if the comments above want expanding slightly as we are now in a new function and over time it might move around in the file so that these two comments aren't right next to each other? Maybe something like like: /* Find a first arch based on the BFD. We need the initial gdbarch so we can provide a barebones target able to read information such as auxv data. The final gdbarch will be set in initialize. */ m_core_gdbarch = gdbarch_from_bfd (core_bfd); } void core_target::initialize () { /* If the initial arch from the BFD is able to read a target description from the core, it could yield a more specific gdbarch. */ -- John Baldwin