From patchwork Tue May 10 07:39:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 9055131 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 1FA73BF29F for ; Tue, 10 May 2016 07:52:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0AB3320114 for ; Tue, 10 May 2016 07:52:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F322A20103 for ; Tue, 10 May 2016 07:52:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750983AbcEJHwn (ORCPT ); Tue, 10 May 2016 03:52:43 -0400 Received: from david.siemens.de ([192.35.17.14]:44973 "EHLO david.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750910AbcEJHwn (ORCPT ); Tue, 10 May 2016 03:52:43 -0400 X-Greylist: delayed 739 seconds by postgrey-1.27 at vger.kernel.org; Tue, 10 May 2016 03:52:42 EDT Received: from mail1.siemens.de (mail1.siemens.de [139.23.33.14]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id u4A7dlEp008691 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 May 2016 09:39:47 +0200 Received: from md1f2u6c.ww002.siemens.net ([139.22.129.144]) by mail1.siemens.de (8.15.2/8.15.2) with SMTP id u4A7djq9020382; Tue, 10 May 2016 09:39:46 +0200 From: Jan Kiszka To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Kieran Bingham , mmarek@suse.com, linux-kbuild@vger.kernel.org Subject: [PATCH 02/18] scripts/gdb: Provide linux constants Date: Tue, 10 May 2016 09:39:27 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 From: Kieran Bingham 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 Signed-off-by: Jan Kiszka --- 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 f55cefd..3d0ae15 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 6cf1ecf..cd129e6 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 0000000..79d9d00 --- /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 d5943ec..6e0b0af 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