From patchwork Thu Mar 3 11:40:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8491751 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 521A4C0553 for ; Thu, 3 Mar 2016 11:47:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5D3FB201EF for ; Thu, 3 Mar 2016 11:47:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 47D2B2011B for ; Thu, 3 Mar 2016 11:47:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756773AbcCCLlV (ORCPT ); Thu, 3 Mar 2016 06:41:21 -0500 Received: from mail-wm0-f54.google.com ([74.125.82.54]:34389 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756011AbcCCLlT (ORCPT ); Thu, 3 Mar 2016 06:41:19 -0500 Received: by mail-wm0-f54.google.com with SMTP id p65so30697972wmp.1 for ; Thu, 03 Mar 2016 03:41:18 -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=drcAvcps9WW2qpspE7Q8pWFrN4h6LJMMOnarNhx6ra0=; b=UuYZjz57pt1GrlskwtqfppJAbi6P/dRIzR2pEH8F2DKezGkw1ZrlN5kuFBn69E5Jz6 0WhwjPkeJZEFpnQ4yeb5WqVvq9EWzXSrK9sVqYsImwRzL4A/YvfRQxOMvfyzTk5u0qkm muWnm7t/1O+xwKSaFay4DmpDW6BtrdiTxX94A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=drcAvcps9WW2qpspE7Q8pWFrN4h6LJMMOnarNhx6ra0=; b=GqLUpVOC/xMzx3H8HlJIRFEqW9lyXRW37auBup044ohQdbPW8w8Fn7NwaKTqiK6Z8R DYEMO0bzKAVC3obaQjfmRcobXrRLSVYBZ0ayNBFO8DMEVO9xT+7wO+jCvDQgApQrkkCn JReEmDPpdh3311/ZMy/I4jjlVSIg/wZiRpLXd78uP/e+XJMPeVTQqLRvpcgvJXj5HVrR abroOrA0G1yUfIbsHJmF3cJEL/5eoOwAYK8E/w0h3oi5+Q+DR97UtuVA3HFHQgzu2iY/ VmIJkzPo15hgVLpQqgLSMmLrOPkHSrl5iC9rA6cjzhtL8Vpw590I5rb46L8QxipI4z2e EgJA== X-Gm-Message-State: AD7BkJLpmam/PkOe7IIGLmd0zReu0AngmKmpq5I/5Dix2P2dWAhJk5QlTWbqImXyDTR0aXun X-Received: by 10.194.185.108 with SMTP id fb12mr2592427wjc.89.1457005277570; Thu, 03 Mar 2016 03:41:17 -0800 (PST) Received: from localhost.localdomain (cpc87017-aztw30-2-0-cust65.18-1.cable.virginm.net. [92.232.232.66]) by smtp.gmail.com with ESMTPSA id e19sm8570696wmd.1.2016.03.03.03.41.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Mar 2016 03:41:16 -0800 (PST) From: Kieran Bingham To: jan.kiszka@siemens.com, linux-kernel@vger.kernel.org Cc: lee.jones@linaro.org, peter.griffin@linaro.org, maxime.coquelin@st.com, Kieran Bingham , mmarek@suse.com, linux-kbuild@vger.kernel.org Subject: [PATCHv3 01/13] scripts/gdb: Provide linux constants Date: Thu, 3 Mar 2016 11:40:55 +0000 Message-Id: <1457005267-843-2-git-send-email-kieran.bingham@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1457005267-843-1-git-send-email-kieran.bingham@linaro.org> References: <1457005267-843-1-git-send-email-kieran.bingham@linaro.org> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some macro's and defines are needed when parsing memory, and without compiling the kernel as -g3 they are not available in the debug-symbols. We use the pre-processor here to extract constants to a dedicated module for the linux debugger extensions Top level Kbuild is used to call in and generate the constants file, while maintaining dependencies on autogenerated files in include/generated CC: mmarek@suse.com CC: linux-kbuild@vger.kernel.org Signed-off-by: Kieran Bingham --- Changes since v1: Kbuild: - Call to generate constants_py with dependancy on generated files scripts/gdb/linux/Makefile: - Use call if_changed, and correct quiet invocation - Annouce "GEN $@" instead of GDB PP scripts/gdb/linux/constants.py.in: - Updated to use better macro implementations for one line defines --- Kbuild | 10 ++++++++++ scripts/gdb/linux/Makefile | 12 +++++++++++- scripts/gdb/linux/constants.py.in | 32 ++++++++++++++++++++++++++++++++ scripts/gdb/vmlinux-gdb.py | 1 + 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 scripts/gdb/linux/constants.py.in diff --git a/Kbuild b/Kbuild index f55cefd9bf29..3d0ae152af7c 100644 --- a/Kbuild +++ b/Kbuild @@ -5,6 +5,7 @@ # 2) Generate timeconst.h # 3) Generate asm-offsets.h (may need bounds.h and timeconst.h) # 4) Check for missing system calls +# 5) Generate constants.py (may need bounds.h) # Default sed regexp - multiline due to syntax constraints define sed-y @@ -96,5 +97,14 @@ quiet_cmd_syscalls = CALL $< missing-syscalls: scripts/checksyscalls.sh $(offsets-file) FORCE $(call cmd,syscalls) +##### +# 5) Generate constants for Python GDB integration +# + +extra-$(CONFIG_GDB_SCRIPTS) += build_constants_py + +build_constants_py: $(obj)/$(timeconst-file) $(obj)/$(bounds-file) + @$(MAKE) $(build)=scripts/gdb/linux $@ + # Keep these three files during make clean no-clean-files := $(bounds-file) $(offsets-file) $(timeconst-file) diff --git a/scripts/gdb/linux/Makefile b/scripts/gdb/linux/Makefile index 6cf1ecf61057..cd129e65d1ff 100644 --- a/scripts/gdb/linux/Makefile +++ b/scripts/gdb/linux/Makefile @@ -8,4 +8,14 @@ ifneq ($(KBUILD_SRC),) endif @: -clean-files := *.pyc *.pyo $(if $(KBUILD_SRC),*.py) +quiet_cmd_gen_constants_py = GEN $@ + cmd_gen_constants_py = \ + $(CPP) -E -x c -P $(c_flags) $< > $@ ;\ + sed -i '1,//d;' $@ + +$(obj)/constants.py: $(SRCTREE)/$(obj)/constants.py.in + $(call if_changed,gen_constants_py) + +build_constants_py: $(obj)/constants.py + +clean-files := *.pyc *.pyo $(if $(KBUILD_SRC),*.py) $(obj)/constants.py diff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in new file mode 100644 index 000000000000..79d9d0092452 --- /dev/null +++ b/scripts/gdb/linux/constants.py.in @@ -0,0 +1,32 @@ +/* + * gdb helper commands and functions for Linux kernel debugging + * + * Kernel constants derived from include files. + * + * Copyright (c) 2016 Linaro Ltd + * + * Authors: + * Kieran Bingham + * + * This work is licensed under the terms of the GNU GPL version 2. + * + */ + +/* We need to stringify expanded macros so that they can be parsed */ +#define STRING(x) #x +#define XSTRING(x) STRING(x) + +#define LX_VALUE(x) LX_##x = x +#define LX_GDBPARSED(x) LX_##x = gdb.parse_and_eval(XSTRING(x)) + +/* + * IS_ENABLED generates (a || b) which is not compatible with python + * We can only switch on configuration items we know are available + * Therefore - IS_BUILTIN() is more appropriate + */ +#define LX_CONFIG(x) LX_##x = IS_BUILTIN(x) + +/* The build system will take care of deleting everything above this marker */ + + +import gdb diff --git a/scripts/gdb/vmlinux-gdb.py b/scripts/gdb/vmlinux-gdb.py index d5943eca19cd..6e0b0afd888a 100644 --- a/scripts/gdb/vmlinux-gdb.py +++ b/scripts/gdb/vmlinux-gdb.py @@ -30,3 +30,4 @@ else: import linux.cpus import linux.lists import linux.proc + import linux.constants