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: 156931 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4230861jaa; Mon, 28 Jan 2019 21:04:15 -0800 (PST) X-Google-Smtp-Source: ALg8bN4ggfeO840OzZE6iUGRvHRDTAF4TsxC/fxGMbj5ldJg7VgNIYSCN+QMxBZ/FCt3Ra2fvuCE X-Received: by 2002:a17:902:930b:: with SMTP id bc11mr25155637plb.17.1548738255790; Mon, 28 Jan 2019 21:04:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548738255; cv=none; d=google.com; s=arc-20160816; b=YeqV28OonITIShPZd1sQ+9nQ9wKZ9k9PtNbFTG+QjIDt+Fp2N2Bjhrf8qUZuQBWflP a3YRTOc4KQUEwby5VjK3i2Q/79LNQsROxwgfFkGYUB5rwWJm78nCNcr2yJB2/rBOO0Jf jTQAHkKkv9AwcnPoWb0Ucj8KFXhKByjXNUOh7HTERh4iyIpxZg7+ZfSo0m3W1wxSJtOv hOU8vsqAAVadidiFxUyoKI4o72bkN/73oBVPYmFDxH44NV4sFiBGDde3jGzuX+u7nnQX F7Zx+a2Zb1E3xlKT4QxK0TkyafIw75G4h0L9SOKazkBq1cuUWZgWR0fJliTrd2uu47AO tGcQ== 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=zFyF5j15YVndxHisOrryyJ0Eq6OuAJ5wzvkdNwZAVXo=; b=fw+ldGwYa0unPKThazDdRBkjOmxP3x4bg77XFAMGd2xnJHkEHRN1mJhFQ5M+uGk/jr SjOmD0bB3GzifDZMhxNECtN0GOo60VTi/ByZa3QialtVaA/ArzaJHx9fK3mInkyOs94H rpUDh54otvDjLmTwkk7XLml91YcK7N4xuniUxTi/qCoDWxxEz6PmxPCz/6SV5KMNXfy6 OQrhvO893CiOyNSiLScPjTY31wmdSRXUbBvu0v8wgwTrFaB651q/6GSiz0v5IRixSc4+ 5OtjWs/1sViEDJOCPvNXOxtTFPkHHkIpfq0q8/b3Nk78Cv7kap+0hKiO8bvJ+yetkoam rdjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=A121na7Y; dkim=pass header.i=@linaro.org header.s=google header.b=d92LXVtH; spf=pass (google.com: domain of gdb-patches-return-153710-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gdb-patches-return-153710-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 63si35675519pla.65.2019.01.28.21.04.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 21:04:15 -0800 (PST) Received-SPF: pass (google.com: domain of gdb-patches-return-153710-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=A121na7Y; dkim=pass header.i=@linaro.org header.s=google header.b=d92LXVtH; spf=pass (google.com: domain of gdb-patches-return-153710-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gdb-patches-return-153710-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=Cu8LYZVop9pejc7XowvDoN+ACqmOpoW aWrr4tl1jYnlpz03Nk9Y87DlcDyQv4mCdyutP/IBd3Fe5tmELqEnFOY0sTbErR6C KjJwzi0ub1vxI4TYzntJSxQFQy6qiCOdix0fo/M1SX4HQAypsgKkXO6/QDq1OptM 4Ey7JiYbIz7M= 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=HYuwUJmzQxpIxOp0HTWviIBv5yw=; b=A121n a7Yl9Al+Ynx8SfcUkWOikm045DK8Vujq9udfW6q6WZF0L9NPWrUVbpK1NeaxOJWe hOzuJYjzo98aGR+9imjX94l2rDGvKi+N7aa+yrt8vIQlaXDvGyNEqN4IgqD+jLft KTxL44phEesZ+p0V4gTnOicgHs/FGN2WhDrhW8= 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 -- 2.7.4 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*)