public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: John Baldwin <jhb@FreeBSD.org>
To: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb: nat/x86-dregs.c: add and use x86_dr_low_can_get_status
Date: Fri, 16 Jul 2021 16:38:28 -0400	[thread overview]
Message-ID: <9a52e7ac-58ab-73d9-b40b-a13a021f9cb1@FreeBSD.org> (raw)
In-Reply-To: <20210715195312.2105187-1-simon.marchi@polymtl.ca>

On 7/15/21 12:53 PM, Simon Marchi via Gdb-patches wrote:
> I built and tried gdb on OpenBSD, and it immediately segfaults when
> running a program.  I tracked down the problem to x86_dr_low.get_status
> being nullptr at this point:

I've looked, and another way to possibly fix this is to make the x86_bsd_nat_target
class not inherit from x86_nat_target<> when x86 debug registers aren't supported.
Something like this in x86-bsd-nat.h:

/* A prototype *BSD/x86 target.  */

#ifdef HAVE_PT_GETDBREGS
template<typename BaseTarget>
class x86bsd_nat_target : public x86_nat_target<BaseTarget>
{
   using base_class = x86_nat_target<BaseTarget>
public:
   void mourn_inferior () override
   {
     x86_cleanup_dregs ();
     base_class::mourn_inferior ();
   }
};
#else /* !HAVE_PT_GETDBREGS */
template<typename BaseTarget>
class x86bsd_nat_target : public BaseTarget
{
};
#endif /* HAVE_PT_GETDBREGS */

I would be further tempted to then remove x86-bsd-nat.o from OpenBSD's configure.nat
lines entirely sine it shouldn't be needed at that point, and maybe adjust x86-bsd-nat.c
to start with something like:

#ifndef HAVE_PT_GETDBREGS
#error "x86-bsd-nat.c requires PT_GETDBREGS"
#endif

My other series that divorces FreeBSD from using i386-bsd-nat.c and
amd64-bsd-nat.c almost makes it so that we could further clean those
files up perhaps so that NetBSD explicitly used x86bsd_nat_target as the
Base class passed to the templates defined in i386-bsd-nat.c and
amd64-bsd-nat.c so that we wouldn't even need an empty version of
x86bsd_nat_target for the OpenBSD case, but I think we should try to
fix the immediate issue on OpenBSD first and maybe do that cleanup
later.

I wouldn't be opposed to this fix also going in, but I kind of think it's
cleaner overall for the OpenBSD target to not use x86-nat.c at all if
it doesn't support the x86 debug registers.  I can take a stab at a
patch to do what I described above if that is easier (I don't currently
have an OpenBSD VM around, but it shouldn't be too hard for me to spin
one up to test this)

-- 
John Baldwin

  reply	other threads:[~2021-07-16 20:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15 19:53 Simon Marchi
2021-07-16 20:38 ` John Baldwin [this message]
2021-07-18 22:39   ` John Baldwin
2021-07-19 14:44     ` Simon Marchi
2021-07-27  0:26       ` John Baldwin

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=9a52e7ac-58ab-73d9-b40b-a13a021f9cb1@FreeBSD.org \
    --to=jhb@freebsd.org \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /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).