From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: tim@sifive.com (Tim Newsome)
Cc: gdb@sourceware.org (gdb)
Subject: Re: gdbarch_init, ABI, and registers
Date: Fri, 08 Dec 2017 12:20:00 -0000 [thread overview]
Message-ID: <20171208122016.B8336D8043A@oc3748833570.ibm.com> (raw)
In-Reply-To: <CAGDihenB_Kuu8GJHc6g7-VnVZCY3kgNkWEa0Bto2PMYxJkcMtw@mail.gmail.com> from "Tim Newsome" at Dec 07, 2017 01:22:22 PM
Tim Newsome wrote:
> I've made some progress here.
>
> gdb does keep track of the description for the current target, and it can
> be retrieved by calling target_current_description(). My problems stemmed
> from the fact that sometimes riscv_gdbarch_init() was called with an info
> structure that did not have the current target description filled out. I
> tracked this down to gdbarch_from_bfd(), which doesn't set
> info.target_desc. set_gdbarch_from_file() does do so (since 2008), and the
> following patch makes everything work for me:
>
> diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
> index 2ae3413087..6c84f100af 100644
> --- a/gdb/arch-utils.c
> +++ b/gdb/arch-utils.c
> @@ -600,6 +600,7 @@ gdbarch_from_bfd (bfd *abfd)
> gdbarch_info_init (&info);
>
> info.abfd =3D abfd;
> + info.target_desc =3D target_current_description ();
> return gdbarch_find_by_info (info);
> }
>
> Does this seem like the right solution? A better one might be to put this
> assignment in gdbarch_info_init(). Or I could just call
> target_current_description() in riscv_arch_init() when no target
> description is passed in. The latter goes against the comment accompanying
> target_current_description(), but it would only be a target-dependent
> change.
No, this doesn't look correct to me. Note that it is normal during
GDB operation that several different gdbarch objects are in use,
which have somewhat different contents and are used for different
purposes.
In particular, there are gdbarch objects that describe a *target*
(i.e. an inferior GDB is operating on) -- those use target descriptions,
and care about registers etc.
But then there are also gdbarch objects that are used solely when
looking at an *object file*, without involving any connection to a
target -- those don't have target descriptions, and don't care about
registers.
The second type is generated by gdbarch_from_bfd, so those *should*
not get any target description. This function can be called even
when there is no target currently active at all.
[ As an aside, it would probably be cleaner to actually use two
different data structures for those different purposes in the first
place. This hasn't been done yet, mostly because it would be a lot
of effort to update all places where platform-specific gdbarch
information is created ... ]
I guess I still haven't quite understood why exactly any of this
is causing a problem for you. Yes, gdbarch objects returned from
gdbarch_from_bfd will not have correct register info. But those
objects also should never be used in any context where registers
matter. Can you be more specific what the actual problem you're
seeing is?
Bye,
Ulrich
--
Dr. Ulrich Weigand
GNU/Linux compilers and toolchain
Ulrich.Weigand@de.ibm.com
next prev parent reply other threads:[~2017-12-08 12:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-06 20:21 Tim Newsome
2017-12-07 14:21 ` Handling language trampoline Dmitry Antipov
2017-12-07 14:58 ` Pedro Alves
2017-12-08 6:39 ` Dmitry Antipov
2017-12-08 11:12 ` Pedro Alves
2017-12-07 21:22 ` gdbarch_init, ABI, and registers Tim Newsome
2017-12-08 12:20 ` Ulrich Weigand [this message]
2017-12-08 20:03 ` Tim Newsome
2017-12-09 11:27 ` Ulrich Weigand
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=20171208122016.B8336D8043A@oc3748833570.ibm.com \
--to=uweigand@de.ibm.com \
--cc=gdb@sourceware.org \
--cc=tim@sifive.com \
/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