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: 156932 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4230948jaa; Mon, 28 Jan 2019 21:04:21 -0800 (PST) X-Google-Smtp-Source: ALg8bN5Ko9NFTZSzV0tiZqFpjnOOY0qmNRV40EJ2IWYKJ0YK/qDH2nMOGWkMU3ZNnmUer1897O++ X-Received: by 2002:a63:1d1d:: with SMTP id d29mr22542566pgd.49.1548738261502; Mon, 28 Jan 2019 21:04:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548738261; cv=none; d=google.com; s=arc-20160816; b=EyolVGnhGWScyvayo97lpFph1bW7Dwms8lHaC7ecElTM8077+ie9eFrXUmpF0/5pCn wlPAD8oTz5/BgSeKF4kcWUHs6FayTxLJFsQVKT9wk0h0P1MuMoADTra0qJL1JBaWObmD rsjlPjTuaza74XdLa8E4yxbLgDXPX3gk9oOpRrTa+OhMF+6vVU1FpS+k5175k7dRnId8 w/2pwonANlS5n+01P5aWzHQqeT5y2RicyB7C/L00FxqcoSD6cHwUFFUmbyGZXS5DhpLi NZhuGpKuqPkAHArTnIgCfshViG2OYPAUiFXAV+terBzWAMVwrJwWpbZdhPt529NE2P24 3KQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=asXfeC+U0NgTpfnOtAv4ZaronYnrFja3TrwEBh3MBSw=; b=kgfjaKWo0Vvbz1KxrBrUQA6vFK8Jf0fhnm0Qwd9qu8aT82N52lRgZEeNAI7iojENS6 YMEzemeTPGJLkPlwyVw6Y06M8bE2LM5pAOLRr+xSb4AQ0zwPTjK7ZOu/0f6z5XWPLYdf bz1UIff7pW4R4Wkw8zVsQsPxztMkToxHSBNpJ4LtP2Pzbnx4GIIxjBrvtXEgsoSgjjJ3 w7O4hIUaf3PNwpcNdx4RfGFv7ytmBDVsCAL4QeTtniily6NUfvQd39AjMzaZDL7MReHs 43PdUTWcVz5KQMN5HeaSPwDbAJpiKVS9fh9fttVOsf3buASFiuLODX/FbHSsXNU8JgER OyMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=ik5VrXPN; dkim=pass header.i=@linaro.org header.s=google header.b=W5hOdnNH; spf=pass (google.com: domain of gdb-patches-return-153711-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gdb-patches-return-153711-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id v21si10320165plo.417.2019.01.28.21.04.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 21:04:21 -0800 (PST) Received-SPF: pass (google.com: domain of gdb-patches-return-153711-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=ik5VrXPN; dkim=pass header.i=@linaro.org header.s=google header.b=W5hOdnNH; spf=pass (google.com: domain of gdb-patches-return-153711-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gdb-patches-return-153711-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=xTvgoBMCydx3ymPXPw3NljmM8AUAsUj CI+/xPzoUJFMF/lAQ7dhq1ueDhWy6XkvmOtuZzoXiAGVhmntyGM3vqv9mOV25E8G nMY84DUYbfBNQ4Ed0o6ih4j1FB0DQXgWUDBbPL1dfw6nvPV75zdS2h/OxzNxI9SH znEvSxrk0IBw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=X5HWE9jQteWottTDHHtjTzQtDOU=; b=ik5Vr XPNQLEN0hNs8pVKBg2spqp/8OT+R/FrqtrfI8elqC4KpjFBnnD0bF/SifZL5oi1Q pmegiPOZc6fdQM+VmB1k8FQnuA79Wmr9Z6LCifu9TpQyXs28k5gaVkongPt2Q28h selCTPJ3mdqWUS3nl6rgCn0rNKlupKbfVIRvkA= 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 -- 2.7.4 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 ;;