From: Omair Javaid <omair.javaid@linaro.org>
To: gdb-patches@sourceware.org
Cc: palves@redhat.com, prudo@linux.ibm.com, arnez@linux.vnet.ibm.com,
peter.griffin@linaro.org, Ulrich.Weigand@de.ibm.com,
kieran@linuxembedded.co.uk,
Omair Javaid <omair.javaid@linaro.org>
Subject: [RFC PATCH 6/6] Linux kernel thread awareness AArch64 target support
Date: Tue, 29 Jan 2019 05:04:00 -0000 [thread overview]
Message-ID: <1548738199-9403-7-git-send-email-omair.javaid@linaro.org> (raw)
In-Reply-To: <1548738199-9403-1-git-send-email-omair.javaid@linaro.org>
This patch adds support for linux kernel thread aware debugging on
AArch64 targets. It implements aarch64_linux_kernel_ops derived class to
provide AArch64 targets specific functionality to linux_kernel_ops class.
gdb/ChangeLog:
* Makefile.in (ALL_TARGET_OBS): Add aarch64-lk-tdep.o.
(ALLDEPFILES): Add aarch64-lk-tdep.c.
* configure.tgt (aarch64*-*-linux*): Add aarch64-lk-tdep.o and lk_tobjs.
* aarch64-lk-tdep.c: New file.
---
gdb/Makefile.in | 2 +
gdb/aarch64-lk-tdep.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++
gdb/configure.tgt | 2 +-
3 files changed, 138 insertions(+), 1 deletion(-)
create mode 100644 gdb/aarch64-lk-tdep.c
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index f6dbfdd..e0f4ff7 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -633,6 +633,7 @@ TARGET_OBS = @TARGET_OBS@
ALL_64_TARGET_OBS = \
aarch64-fbsd-tdep.o \
aarch64-linux-tdep.o \
+ aarch64-lk-tdep.o \
aarch64-newlib-tdep.o \
aarch64-ravenscar-thread.o \
aarch64-tdep.o \
@@ -2161,6 +2162,7 @@ ALLDEPFILES = \
aarch64-fbsd-tdep.c \
aarch64-linux-nat.c \
aarch64-linux-tdep.c \
+ aarch64-lk-tdep.c \
aarch64-newlib-tdep.c \
aarch64-ravenscar-thread.c \
aarch64-tdep.c \
diff --git a/gdb/aarch64-lk-tdep.c b/gdb/aarch64-lk-tdep.c
new file mode 100644
index 0000000..f380e6e
--- /dev/null
+++ b/gdb/aarch64-lk-tdep.c
@@ -0,0 +1,135 @@
+/* Target-dependent code for linux-kernel target on AArch64 architecture.
+ Copyright (C) 2019 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "defs.h"
+#include "osabi.h"
+#include "regset.h"
+#include "gdbcore.h"
+
+#include "arch/aarch64.h"
+#include "lk-low.h"
+
+/* Define register map and set. */
+
+/* From linux kernel source arch/arm64/include/asm/processor.h
+ struct cpu_context. */
+
+static const struct regcache_map_entry aarch64_gregmap_lk[] =
+ {
+ { 11, AARCH64_X0_REGNUM + 19, 8 },
+ { 1, AARCH64_SP_REGNUM, 8 },
+ { 1, AARCH64_PC_REGNUM, 8 },
+ { 0 }
+ };
+
+const struct regset aarch64_gregset_lk =
+ {
+ aarch64_gregmap_lk,
+ regcache_supply_regset,
+ regcache_collect_regset
+ };
+
+/* AArch64 specific implementation for linux_kernel_ops. */
+
+class aarch64_linux_kernel_ops : public linux_kernel_ops
+{
+public:
+ aarch64_linux_kernel_ops ()
+ {}
+
+ void get_registers (CORE_ADDR task, struct regcache *regcache,
+ int regnum) override;
+protected:
+ void arch_read_symbols () override;
+};
+
+/* Implement linux_kernel_ops->arch_read_symbols virtual method. */
+
+void
+aarch64_linux_kernel_ops::arch_read_symbols ()
+{
+ declare_field ("task_struct->thread", LK_CONFIG_ALWAYS);
+ declare_field ("thread_struct->cpu_context", LK_CONFIG_ALWAYS);
+}
+
+/* Implement linux_kernel_ops->get_registers virtual method. */
+
+void
+aarch64_linux_kernel_ops::get_registers (CORE_ADDR task,
+ struct regcache *regcache, int regnum)
+{
+ CORE_ADDR cpu_context;
+ gdb_byte buf[104];
+ size_t size;
+
+ /* Calculate cpu_context address from task_struct address. */
+ cpu_context = task + offset ("task_struct->thread")
+ + offset ("thread_struct->cpu_context");
+
+ size = FIELD_SIZE (field ("thread_struct->cpu_context"));
+
+ gdb_assert (size <= sizeof (buf));
+
+ read_memory (cpu_context, buf, size);
+
+ regcache->supply_regset (&aarch64_gregset_lk, -1, buf, size);
+}
+
+/* Implement gdbarch get_new_lk_ops hook. */
+
+static linux_kernel_ops *
+aarch64_get_new_lk_ops (struct gdbarch *gdbarch)
+{
+ return new aarch64_linux_kernel_ops;
+}
+
+/* Initialize Linux kernel specific gdbarch hooks. */
+
+static void
+aarch64_lk_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
+{
+ /* Support linux kernel debugging. */
+ set_gdbarch_get_new_lk_ops (gdbarch, aarch64_get_new_lk_ops);
+}
+
+/* From the ELF-headers point of view Linux kernel- and user-space binaries
+ are the same. So we have to rely on some heuristics to distinguish them.
+
+ For the heuristic we check for __ksymtab section in the vmlinux and
+ modules .ko files. */
+
+static enum gdb_osabi
+aarch64_lk_osabi_sniffer (bfd *abfd)
+{
+ if (bfd_get_section_by_name (abfd, "__ksymtab"))
+ return GDB_OSABI_LINUX_KERNEL;
+
+ return GDB_OSABI_UNKNOWN;
+}
+
+void
+_initialize_aarch64_lk_tdep (void)
+{
+ /* Hook us into the OSABI mechanism. */
+ gdbarch_register_osabi (bfd_arch_aarch64, 0, GDB_OSABI_LINUX_KERNEL,
+ aarch64_lk_init_abi);
+
+ /* Add OSABI sniffer. */
+ gdbarch_register_osabi_sniffer (bfd_arch_aarch64, bfd_target_elf_flavour,
+ aarch64_lk_osabi_sniffer);
+}
diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index fe5a653..d45deef 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -128,7 +128,7 @@ aarch64*-*-linux*)
arch/arm.o arch/arm-linux.o arch/arm-get-next-pcs.o \
arm-tdep.o arm-linux-tdep.o \
glibc-tdep.o linux-tdep.o solib-svr4.o \
- symfile-mem.o linux-record.o"
+ symfile-mem.o linux-record.o aarch64-lk-tdep.o ${lk_tobjs}"
build_gdbserver=yes
;;
--
2.7.4
next prev parent reply other threads:[~2019-01-29 5:04 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-29 5:03 [RFC PATCH 0/6] Support for Linux kernel thread aware debug Omair Javaid
2019-01-29 5:03 ` [RFC PATCH 2/6] Add libiberty/concat styled concat_path function Omair Javaid
2019-01-29 5:03 ` [RFC PATCH 1/6] Convert substitute_path_component to C++ Omair Javaid
2019-01-29 5:03 ` [RFC PATCH 3/6] Add scoped_restore_regcache_ptid Omair Javaid
2019-01-29 5:04 ` Omair Javaid [this message]
2019-01-29 5:04 ` [RFC PATCH 5/6] Linux kernel thread awareness Arm target support Omair Javaid
2019-01-29 5:04 ` [RFC PATCH 4/6] Linux kernel debug infrastructure and target Linux kernel Omair Javaid
2019-01-29 17:50 ` John Baldwin
2019-01-31 11:43 ` Philipp Rudo
2019-01-31 16:14 ` Philipp Rudo
2019-02-04 9:35 ` Omair Javaid
2019-02-05 14:15 ` Philipp Rudo
2019-02-08 8:53 ` Omair Javaid
[not found] ` <6c29e316-f1cb-ee65-bc0b-844cba5d74ad@FreeBSD.org>
2019-01-30 15:02 ` [RFC PATCH 0/6] Support for Linux kernel thread aware debug Andreas Arnez
2019-02-04 9:13 ` Omair Javaid
2019-02-04 17:52 ` John Baldwin
2019-02-08 8:54 ` Omair Javaid
2019-03-07 11:50 ` Omair Javaid
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=1548738199-9403-7-git-send-email-omair.javaid@linaro.org \
--to=omair.javaid@linaro.org \
--cc=Ulrich.Weigand@de.ibm.com \
--cc=arnez@linux.vnet.ibm.com \
--cc=gdb-patches@sourceware.org \
--cc=kieran@linuxembedded.co.uk \
--cc=palves@redhat.com \
--cc=peter.griffin@linaro.org \
--cc=prudo@linux.ibm.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