From patchwork Tue Jan 29 05:03:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omair Javaid X-Patchwork-Id: 31240 Received: (qmail 38043 invoked by alias); 29 Jan 2019 05:04:04 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 37985 invoked by uid 89); 29 Jan 2019 05:04:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm1-f66.google.com Received: from mail-wm1-f66.google.com (HELO mail-wm1-f66.google.com) (209.85.128.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Jan 2019 05:04:01 +0000 Received: by mail-wm1-f66.google.com with SMTP id g67so16230213wmd.2 for ; Mon, 28 Jan 2019 21:04:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=asXfeC+U0NgTpfnOtAv4ZaronYnrFja3TrwEBh3MBSw=; b=W5hOdnNHXN6MJuCWW5CqlLV+BZyldIETBSdOywjtVT6KGPv5tO3s8JnBMW/HaTrz3z vA0O5pooi0w7TwEk5ZEyRh1G336WKtD0M08cpPcHCuWPi8LU+qb9GUCGBBzhHYkLDqfk x4EIK/6HQc3rEcC8WtHv5V4AHFpSY2Jhq63oI= Return-Path: Received: from localhost.localdomain ([43.251.253.48]) by smtp.gmail.com with ESMTPSA id s1sm170325615wro.9.2019.01.28.21.03.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Jan 2019 21:03:58 -0800 (PST) From: Omair Javaid 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 Subject: [RFC PATCH 6/6] Linux kernel thread awareness AArch64 target support Date: Tue, 29 Jan 2019 10:03:19 +0500 Message-Id: <1548738199-9403-7-git-send-email-omair.javaid@linaro.org> In-Reply-To: <1548738199-9403-1-git-send-email-omair.javaid@linaro.org> References: <1548738199-9403-1-git-send-email-omair.javaid@linaro.org> X-IsSubscribed: yes 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 . */ + +#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 ;;