public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: John Baldwin <jhb@FreeBSD.org>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/3] gdb: break up core_target initialization
Date: Tue, 29 Nov 2022 16:53:06 -0500	[thread overview]
Message-ID: <2ce82756-688c-3f32-d2f4-2fa450290c5d@polymtl.ca> (raw)
In-Reply-To: <65b25c24-eb7e-65fb-ad96-08665bbcbb67@FreeBSD.org>

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

  reply	other threads:[~2022-11-29 21:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-29  2:50 [PATCH 1/3] gdb: add inferior_target_stack_changed observer, use it to clear auxv cache Simon Marchi
2022-11-29  2:50 ` [PATCH 2/3] gdb: break up core_target initialization Simon Marchi
2022-11-29 19:27   ` John Baldwin
2022-11-29 21:53     ` Simon Marchi [this message]
2022-11-30 17:29       ` John Baldwin
2022-11-30 16:05   ` Tom Tromey
2022-12-02 19:38     ` Simon Marchi
2022-11-29  2:50 ` [PATCH 3/3] gdb: remove target_ops parameter from gdbarch_core_read_description Simon Marchi
2022-11-29 19:16   ` John Baldwin
2022-11-29 21:45     ` Simon Marchi
2022-12-02 20:51   ` [PATCH v1.1 " Simon Marchi
2022-11-30 15:44 ` [PATCH 1/3] gdb: add inferior_target_stack_changed observer, use it to clear auxv cache Tom Tromey
2022-12-02 19:36   ` Simon Marchi
2022-12-02 20:59     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2ce82756-688c-3f32-d2f4-2fa450290c5d@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=jhb@FreeBSD.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).