From patchwork Tue Jan 29 05:03:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omair Javaid X-Patchwork-Id: 31239 Received: (qmail 37665 invoked by alias); 29 Jan 2019 05:04:01 -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 37613 invoked by uid 89); 29 Jan 2019 05:04:01 -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=hooks X-HELO: mail-wr1-f66.google.com Received: from mail-wr1-f66.google.com (HELO mail-wr1-f66.google.com) (209.85.221.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Jan 2019 05:03:58 +0000 Received: by mail-wr1-f66.google.com with SMTP id u4so20532530wrp.3 for ; Mon, 28 Jan 2019 21:03:58 -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=zFyF5j15YVndxHisOrryyJ0Eq6OuAJ5wzvkdNwZAVXo=; b=d92LXVtHiq7W/prGKckyz4dA57Ip0Q3GMFJFfn7Q89rqz9Pj5zh12YiT/yn+Cah7dW VUk2yEt1/458QqCoouj7yKRIjJEndW8hfPvoLxAo9TzvdixGUgVK1eZE+acZDF00LHz9 O1oHNQboxeYJrsE5Kn9f0KfpbOFf7E69olt50= Return-Path: Received: from localhost.localdomain ([43.251.253.48]) by smtp.gmail.com with ESMTPSA id s1sm170325615wro.9.2019.01.28.21.03.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Jan 2019 21:03:55 -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 5/6] Linux kernel thread awareness Arm target support Date: Tue, 29 Jan 2019 10:03:18 +0500 Message-Id: <1548738199-9403-6-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 Arm targets. It implements arm_linux_kernel_ops derived class to provide Arm targets specific functionality to linux_kernel_ops class. gdb/ChangeLog: * Makefile.in (ALL_TARGET_OBS): Add arm-lk-tdep.o. (ALLDEPFILES): Add arm-lk-tdep.c. * configure.tgt (arm*-*-linux*): Add arm-lk-tdep.o and lk_tobjs. * arm-lk-tdep.c: New file. --- gdb/Makefile.in | 2 + gdb/arm-lk-tdep.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/configure.tgt | 3 +- 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 gdb/arm-lk-tdep.c diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 74c9da2..f6dbfdd 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -677,6 +677,7 @@ ALL_TARGET_OBS = \ arm-bsd-tdep.o \ arm-fbsd-tdep.o \ arm-linux-tdep.o \ + arm-lk-tdep.o \ arm-nbsd-tdep.o \ arm-obsd-tdep.o \ arm-pikeos-tdep.o \ @@ -2195,6 +2196,7 @@ ALLDEPFILES = \ arm-linux.c \ arm-linux-nat.c \ arm-linux-tdep.c \ + arm-lk-tdep.c \ arm-nbsd-nat.c \ arm-nbsd-tdep.c \ arm-obsd-tdep.c \ diff --git a/gdb/arm-lk-tdep.c b/gdb/arm-lk-tdep.c new file mode 100644 index 0000000..f046490 --- /dev/null +++ b/gdb/arm-lk-tdep.c @@ -0,0 +1,139 @@ +/* Target-dependent code of Linux kernel target for ARM 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/arm.h" + +#include "lk-low.h" + +/* Define register map and set. */ + +/* Referring to Linux kernel source arch/arm/include/asm/thread_info.h + struct cpu_context_save. */ + +static const struct regcache_map_entry arm_gregmap_lk[] = + { + { 8, ARM_A4_REGNUM + 1 }, + { 1, ARM_SP_REGNUM }, + { 1, ARM_PC_REGNUM }, + { -2, REGCACHE_MAP_SKIP, 4 }, + { 0 } + }; + +const struct regset arm_gregset_lk = + { + arm_gregmap_lk, + regcache_supply_regset, + regcache_collect_regset + }; + +/* Arm specific implementation for linux_kernel_ops. */ + +class arm_linux_kernel_ops : public linux_kernel_ops +{ +public: + arm_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 +arm_linux_kernel_ops::arch_read_symbols () +{ + declare_field ("task_struct->stack", LK_CONFIG_ALWAYS); + declare_field ("thread_info->cpu_context", LK_CONFIG_ALWAYS); +} + +/* Implement linux_kernel_ops->get_registers virtual method. */ + +void +arm_linux_kernel_ops::get_registers (CORE_ADDR task, + struct regcache *regcache, int regnum) +{ + CORE_ADDR cpu_context, thread_info; + gdb_byte buf[48]; + size_t size; + + /* Read thread_info address. */ + thread_info = lk_read_addr (task + offset ("task_struct->stack")); + + /* Calculate cpu_context address from thread_info address. */ + cpu_context = thread_info + offset ("thread_info->cpu_context"); + + size = FIELD_SIZE (field ("thread_info->cpu_context")); + + gdb_assert (size <= sizeof (buf)); + + read_memory (cpu_context, buf, size); + + regcache->supply_regset (&arm_gregset_lk, -1, buf, size); +} + +/* Implement gdbarch get_new_lk_ops hook. */ + +static linux_kernel_ops * +arm_get_new_lk_ops (struct gdbarch *gdbarch) +{ + return new arm_linux_kernel_ops; +} + +/* Initialize Linux kernel specific gdbarch hooks. */ + +static void +arm_lk_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) +{ + /* Support linux kernel debugging. */ + set_gdbarch_get_new_lk_ops (gdbarch, arm_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 +arm_lk_osabi_sniffer (bfd *abfd) +{ + if (bfd_get_section_by_name (abfd, "__ksymtab")) + return GDB_OSABI_LINUX_KERNEL; + + return GDB_OSABI_UNKNOWN; +} + +void +_initialize_arm_lk_tdep (void) +{ + /* Hook us into the OSABI mechanism. */ + gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_LINUX_KERNEL, + arm_lk_init_abi); + + /* Add OSABI sniffer. */ + gdbarch_register_osabi_sniffer (bfd_arch_arm, bfd_target_elf_flavour, + arm_lk_osabi_sniffer); +} diff --git a/gdb/configure.tgt b/gdb/configure.tgt index 3713b9b..fe5a653 100644 --- a/gdb/configure.tgt +++ b/gdb/configure.tgt @@ -167,7 +167,8 @@ arm*-wince-pe | arm*-*-mingw32ce*) arm*-*-linux*) # Target: ARM based machine running GNU/Linux gdb_target_obs="arch/arm-linux.o arm-linux-tdep.o glibc-tdep.o \ - solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o" + solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o \ + arm-lk-tdep.o ${lk_tobjs}" build_gdbserver=yes ;; arm*-*-freebsd*)