From: John Baldwin <jhb@FreeBSD.org>
To: binutils@sourceware.org, gdb-patches@sourceware.org
Subject: [PATCH 4/5] FreeBSD/x86: Read segment base registers from NT_X86_SEGBASES.
Date: Thu, 24 Mar 2022 13:56:15 -0700 [thread overview]
Message-ID: <20220324205616.8517-5-jhb@FreeBSD.org> (raw)
In-Reply-To: <20220324205616.8517-1-jhb@FreeBSD.org>
FreeBSD kernels recently grew a new register core dump note containing
the base addresses of the %fs and %gs segments (corresponding to the
%fsbase and %gsbase registers). Parse this note to permit inspecting
TLS variables in core dumps. Native processes already supported TLS
via older ptrace() operations.
---
gdb/amd64-fbsd-tdep.c | 18 ++++++++++++++++++
gdb/i386-fbsd-tdep.c | 18 ++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c
index da5c297902d..55764beaad2 100644
--- a/gdb/amd64-fbsd-tdep.c
+++ b/gdb/amd64-fbsd-tdep.c
@@ -37,6 +37,9 @@
16-bit segment registers. */
#define AMD64_FBSD_SIZEOF_GREGSET (22 * 8)
+/* The segment base register set consists of 2 64-bit registers. */
+#define AMD64_FBSD_SIZEOF_SEGBASES_REGSET (2 * 8)
+
/* Register maps. */
static const struct regcache_map_entry amd64_fbsd_gregmap[] =
@@ -70,6 +73,13 @@ static const struct regcache_map_entry amd64_fbsd_gregmap[] =
{ 0 }
};
+static const struct regcache_map_entry amd64_fbsd_segbases_regmap[] =
+{
+ { 1, AMD64_FSBASE_REGNUM, 0 },
+ { 1, AMD64_GSBASE_REGNUM, 0 },
+ { 0 }
+};
+
/* This layout including fsbase and gsbase was adopted in FreeBSD
8.0. */
@@ -120,6 +130,11 @@ const struct regset amd64_fbsd_gregset =
amd64_fbsd_gregmap, regcache_supply_regset, regcache_collect_regset
};
+const struct regset amd64_fbsd_segbases_regset =
+{
+ amd64_fbsd_segbases_regmap, regcache_supply_regset, regcache_collect_regset
+};
+
/* Support for signal handlers. */
/* In a signal frame, rsp points to a 'struct sigframe' which is
@@ -253,6 +268,9 @@ amd64fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
&amd64_fbsd_gregset, NULL, cb_data);
cb (".reg2", tdep->sizeof_fpregset, tdep->sizeof_fpregset, &amd64_fpregset,
NULL, cb_data);
+ cb (".reg-x86-segbases", AMD64_FBSD_SIZEOF_SEGBASES_REGSET,
+ AMD64_FBSD_SIZEOF_SEGBASES_REGSET, &amd64_fbsd_segbases_regset,
+ "segment bases", cb_data);
cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0), X86_XSTATE_SIZE (tdep->xcr0),
&amd64fbsd_xstateregset, "XSAVE extended state", cb_data);
}
diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c
index 16ffd576323..fad091f8472 100644
--- a/gdb/i386-fbsd-tdep.c
+++ b/gdb/i386-fbsd-tdep.c
@@ -35,6 +35,9 @@
/* The general-purpose regset consists of 19 32-bit slots. */
#define I386_FBSD_SIZEOF_GREGSET (19 * 4)
+/* The segment base register set consists of 2 32-bit registers. */
+#define I386_FBSD_SIZEOF_SEGBASES_REGSET (2 * 4)
+
/* Register maps. */
static const struct regcache_map_entry i386_fbsd_gregmap[] =
@@ -61,6 +64,13 @@ static const struct regcache_map_entry i386_fbsd_gregmap[] =
{ 0 }
};
+static const struct regcache_map_entry i386_fbsd_segbases_regmap[] =
+{
+ { 1, I386_FSBASE_REGNUM, 0 },
+ { 1, I386_GSBASE_REGNUM, 0 },
+ { 0 }
+};
+
/* This layout including fsbase and gsbase was adopted in FreeBSD
8.0. */
@@ -103,6 +113,11 @@ const struct regset i386_fbsd_gregset =
i386_fbsd_gregmap, regcache_supply_regset, regcache_collect_regset
};
+const struct regset i386_fbsd_segbases_regset =
+{
+ i386_fbsd_segbases_regmap, regcache_supply_regset, regcache_collect_regset
+};
+
/* Support for signal handlers. */
/* In a signal frame, esp points to a 'struct sigframe' which is
@@ -316,6 +331,9 @@ i386fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
&i386_fbsd_gregset, NULL, cb_data);
cb (".reg2", tdep->sizeof_fpregset, tdep->sizeof_fpregset, &i386_fpregset,
NULL, cb_data);
+ cb (".reg-x86-segbases", I386_FBSD_SIZEOF_SEGBASES_REGSET,
+ I386_FBSD_SIZEOF_SEGBASES_REGSET, &i386_fbsd_segbases_regset,
+ "segment bases", cb_data);
if (tdep->xcr0 & X86_XSTATE_AVX)
cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0),
--
2.34.1
next prev parent reply other threads:[~2022-03-24 20:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-24 20:56 [PATCH 0/5] Handle FreeBSD's NT_X86_SEGBASES core dump note John Baldwin
2022-03-24 20:56 ` [PATCH 1/5] elfcore_grok_freebsd_note: Remove checks of note->namesz John Baldwin
2022-03-24 20:56 ` [PATCH 2/5] Recognize FreeBSD core dump note for x86 segment base registers John Baldwin
2022-03-24 20:56 ` [PATCH 3/5] Use pseudosections for NT_FREEBSD_X86_SEGBASES core dump notes John Baldwin
2022-03-24 20:56 ` John Baldwin [this message]
2022-03-24 20:56 ` [PATCH 5/5] Use I386_GSBASE_REGNUM in i386fbsd_get_thread_local_address 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=20220324205616.8517-5-jhb@FreeBSD.org \
--to=jhb@freebsd.org \
--cc=binutils@sourceware.org \
--cc=gdb-patches@sourceware.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).