From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id DD1A93858D35 for ; Tue, 29 Nov 2022 21:53:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DD1A93858D35 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 2ATLr76n001001 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Nov 2022 16:53:11 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 2ATLr76n001001 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1669758792; bh=HFZiUhQevUK05kN5/tBdxqPJcFeP7KwWjgCCP+RyfJM=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Sqv1X7aDY2bCoaDIEtYp31oQk8qddhzYc8NE5zUNZVSIHRbcUJ8I9g/z0y0Kc8Ych Zf7aX0KC3msrg6uvM/IeZgSpTVKc+wQRKHAsduCJCbwAbaCqvsHkZRiCqYXD9bW0p7 +aq7DQgXGJiIEu2T+25iwmyJhCkx9Qn9hbMu9f2g= Received: from [172.16.0.64] (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (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 F39281E0CB; Tue, 29 Nov 2022 16:53:06 -0500 (EST) Message-ID: <2ce82756-688c-3f32-d2f4-2fa450290c5d@polymtl.ca> Date: Tue, 29 Nov 2022 16:53:06 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH 2/3] gdb: break up core_target initialization Content-Language: fr To: John Baldwin , gdb-patches@sourceware.org References: <20221129025048.44490-1-simon.marchi@polymtl.ca> <20221129025048.44490-2-simon.marchi@polymtl.ca> <65b25c24-eb7e-65fb-ad96-08665bbcbb67@FreeBSD.org> From: Simon Marchi In-Reply-To: <65b25c24-eb7e-65fb-ad96-08665bbcbb67@FreeBSD.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Tue, 29 Nov 2022 21:53:07 +0000 X-Spam-Status: No, score=-3036.9 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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: On 11/29/22 14:27, John Baldwin wrote: > 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. Ack. >> 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/ Fixed. >> @@ -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.  */ I would not say "will", because it's conditional. >     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.  */ What about: core_target::core_target () { /* Find a first arch based on the BFD. It will possibly be overriden by a more precise gdbarch in core_target::initialize */ m_core_gdbarch = gdbarch_from_bfd (core_bfd); } void core_target::initialize () { /* If the initial arch (obtained from the BFD) is able to read a target description from the core, it could yield a more specific gdbarch. */ const struct target_desc *tdesc = read_description (); Simon