All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kieran Bingham <kieran.bingham@linaro.org>
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 <kieran.bingham@linaro.org>,
	mmarek@suse.com, linux-kbuild@vger.kernel.org
Subject: [PATCHv4 01/12] scripts/gdb: Provide linux constants
Date: Wed, 30 Mar 2016 13:00:40 +0100	[thread overview]
Message-ID: <1459339251-29611-2-git-send-email-kieran.bingham@linaro.org> (raw)
In-Reply-To: <1459339251-29611-1-git-send-email-kieran.bingham@linaro.org>

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 <kieran.bingham@linaro.org>
---
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,/<!-- end-c-headers -->/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 <kieran.bingham@linaro.org>
+ *
+ * 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 */
+<!-- end-c-headers -->
+
+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
-- 
2.5.0

  reply	other threads:[~2016-03-30 12:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-30 12:00 [PATCHv4 00/12] gdb/scripts: Linux awareness debug commands Kieran Bingham
2016-03-30 12:00 ` Kieran Bingham [this message]
2016-03-30 21:02   ` [PATCHv4 01/12] scripts/gdb: Provide linux constants Jan Kiszka
2016-03-30 12:00 ` [PATCHv4 02/12] scripts/gdb: Provide kernel list item generators Kieran Bingham
2016-03-30 12:00 ` [PATCHv4 03/12] scripts/gdb: Convert modules usage to lists functions Kieran Bingham
2016-03-30 12:00 ` [PATCHv4 04/12] scripts/gdb: Provide exception catching parser Kieran Bingham
2016-03-30 12:00 ` [PATCHv4 05/12] scripts/gdb: Support !CONFIG_MODULES gracefully Kieran Bingham
2016-03-30 12:00 ` [PATCHv4 06/12] scripts/gdb: Provide a dentry_name VFS path helper Kieran Bingham
2016-03-30 12:00 ` [PATCHv4 07/12] scripts/gdb: Add io resource readers Kieran Bingham
2016-03-30 12:00 ` [PATCHv4 08/12] scripts/gdb: Add mount point list command Kieran Bingham
2016-03-30 12:00 ` [PATCHv4 09/12] scripts/gdb: Add cpu iterators Kieran Bingham
2016-03-30 12:00 ` [PATCHv4 10/12] scripts/gdb: Add a Radix Tree Parser Kieran Bingham
2016-03-30 12:00 ` [PATCHv4 11/12] scripts/gdb: Add documentation example for radix tree Kieran Bingham
2016-03-30 12:00 ` [PATCHv4 12/12] scripts/gdb: Add lx_thread_info_by_pid helper Kieran Bingham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1459339251-29611-2-git-send-email-kieran.bingham@linaro.org \
    --to=kieran.bingham@linaro.org \
    --cc=jan.kiszka@siemens.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.coquelin@st.com \
    --cc=mmarek@suse.com \
    --cc=peter.griffin@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.