* [PATCH 00/13] Add gdb python scripts as kernel debugging helpers
@ 2012-10-03 11:21 Jan Kiszka
0 siblings, 0 replies; 3+ messages in thread
From: Jan Kiszka @ 2012-10-03 11:21 UTC (permalink / raw)
To: linux-kernel
Cc: Jason Wessel, kgdb-bugreport, David S. Miller, Fenghua Yu,
Kay Sievers, linux-ia64, linux-kbuild, Michal Marek, sparclinux,
Tony Luck
I'm sitting too long on this stuff, time to finally role it out:
This adds the infrastructure and first tools that make kernel debugging
through gdb more comfortable. Since 7.0, gdb supports python scripting.
And this opens the doors to automate steps like the tedious loading of
module symbols at the right address, resolving per-cpu variables or even
retrieving the current kernel log without resuming an stopped target.
Many of the helpers naturally depend on the layout of structures or
internal mechanics of the kernel. So the best place to maintain such
things, keeping them consistent with the corresponding kernel is, well,
the kernel itself.
While these scripts have been originally developed for debugging via
QEMU/KVM, I've now also added the required bits for KGDB. Works fine,
but as QEMU/KVM tends to outperform KGDB it remains the recommendation
- when available.
There are two architecture dependencies so far, one regarding per-cpu,
the other regarding thread_info calculation. None of them I was able to
test on a target, so I'm counting on review/testing by the corresponding
communities.
This series should be considered the foundation of much more kernel
state exploration helper, e.g. around tasks, timers, locks, sockets -
I guess people will have even more ideas.
Hope it's useful!
PS: Also available via git://git.kiszka.org/linux.git queues/gdb-scripts
CC: "David S. Miller" <davem@davemloft.net>
CC: Fenghua Yu <fenghua.yu@intel.com>
CC: Kay Sievers <kay@vrfy.org>
CC: linux-ia64@vger.kernel.org
CC: linux-kbuild@vger.kernel.org
CC: Michal Marek <mmarek@suse.cz>
CC: sparclinux@vger.kernel.org
CC: Tony Luck <tony.luck@intel.com>
Jan Kiszka (13):
scripts/gdb: Add infrastructure
scripts/gdb: Add container_of helper and convenience function
scripts/gdb: Add lx-symbols command
scripts/gdb: Add get_target_endianness helper
scripts/gdb: Add read_u16/32/64 helpers
scripts/gdb: Add lx-dmesg command
scripts/gdb: Add task iteration helper
scripts/gdb: Add helper and convenience function to look up tasks
scripts/gdb: Add is_target_arch helper
scripts/gdb: Add internal helper and convenience function to retrieve
thread_info
scripts/gdb: Add get_gdbserver_type helper
scripts/gdb: Add internal helper and convenience function for per-cpu
lookup
scripts/gdb: Add lx_current convenience function
Makefile | 6 ++-
scripts/Makefile | 3 +-
scripts/gdb/Makefile | 9 +++
scripts/gdb/dmesg.py | 63 +++++++++++++++++++++
scripts/gdb/percpu.py | 76 +++++++++++++++++++++++++
scripts/gdb/symbols.py | 88 +++++++++++++++++++++++++++++
scripts/gdb/task.py | 108 +++++++++++++++++++++++++++++++++++
scripts/gdb/utils.py | 134 ++++++++++++++++++++++++++++++++++++++++++++
scripts/gdb/vmlinux-gdb.py | 26 +++++++++
9 files changed, 511 insertions(+), 2 deletions(-)
create mode 100644 scripts/gdb/Makefile
create mode 100644 scripts/gdb/dmesg.py
create mode 100644 scripts/gdb/percpu.py
create mode 100644 scripts/gdb/symbols.py
create mode 100644 scripts/gdb/task.py
create mode 100644 scripts/gdb/utils.py
create mode 100644 scripts/gdb/vmlinux-gdb.py
--
1.7.3.4
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 00/13] Add gdb python scripts as kernel debugging helpers
@ 2012-11-05 16:08 Jan Kiszka
2012-11-05 16:09 ` [PATCH 10/13] scripts/gdb: Add internal helper and convenience function to retrieve thread_info Jan Kiszka
0 siblings, 1 reply; 3+ messages in thread
From: Jan Kiszka @ 2012-11-05 16:08 UTC (permalink / raw)
To: linux-kernel
Cc: Jason Wessel, kgdb-bugreport, Andi Kleen, David S. Miller,
Fenghua Yu, Kay Sievers, linux-ia64, linux-kbuild, Michal Marek,
sparclinux, Tony Luck
Version 2 of this series is a rebase over 3.7-rc4 to resolve some minor
collision in the top-level makefile. Moreover, this implements automatic
symbol loading for kernel modules using silent breakpoints. See patch 3
for details.
Unless someone complains over this series or suggests a better workflow,
I'm planning to send a pull to Linus during the next merge window.
Here is the original intro for reference:
This adds the infrastructure and first tools that make kernel debugging
through gdb more comfortable. Since 7.0, gdb supports python scripting.
And this opens the doors to automate steps like the tedious loading of
module symbols at the right address, resolving per-cpu variables or even
retrieving the current kernel log without resuming an stopped target.
Many of the helpers naturally depend on the layout of structures or
internal mechanics of the kernel. So the best place to maintain such
things, keeping them consistent with the corresponding kernel is, well,
the kernel itself.
While these scripts have been originally developed for debugging via
QEMU/KVM, I've now also added the required bits for KGDB. Works fine,
but as QEMU/KVM tends to outperform KGDB it remains the recommendation
- when available.
There are two architecture dependencies so far, one regarding per-cpu,
the other regarding thread_info calculation. None of them I was able to
test on a target, so I'm counting on review/testing by the corresponding
communities.
This series should be considered the foundation of much more kernel
state exploration helper, e.g. around tasks, timers, locks, sockets -
I guess people will have even more ideas.
Hope it's useful!
PS: Also available via git://git.kiszka.org/linux.git queues/gdb-scripts
CC: "David S. Miller" <davem@davemloft.net>
CC: Fenghua Yu <fenghua.yu@intel.com>
CC: Kay Sievers <kay@vrfy.org>
CC: linux-ia64@vger.kernel.org
CC: linux-kbuild@vger.kernel.org
CC: Michal Marek <mmarek@suse.cz>
CC: sparclinux@vger.kernel.org
CC: Tony Luck <tony.luck@intel.com>
Jan Kiszka (13):
scripts/gdb: Add infrastructure
scripts/gdb: Add container_of helper and convenience function
scripts/gdb: Add lx-symbols command
scripts/gdb: Add get_target_endianness helper
scripts/gdb: Add read_u16/32/64 helpers
scripts/gdb: Add lx-dmesg command
scripts/gdb: Add task iteration helper
scripts/gdb: Add helper and convenience function to look up tasks
scripts/gdb: Add is_target_arch helper
scripts/gdb: Add internal helper and convenience function to retrieve
thread_info
scripts/gdb: Add get_gdbserver_type helper
scripts/gdb: Add internal helper and convenience function for per-cpu
lookup
scripts/gdb: Add lx_current convenience function
Makefile | 5 +-
scripts/Makefile | 3 +-
scripts/gdb/Makefile | 9 +++
scripts/gdb/dmesg.py | 63 +++++++++++++++++++++
scripts/gdb/percpu.py | 76 +++++++++++++++++++++++++
scripts/gdb/symbols.py | 133 +++++++++++++++++++++++++++++++++++++++++++
scripts/gdb/task.py | 108 +++++++++++++++++++++++++++++++++++
scripts/gdb/utils.py | 134 ++++++++++++++++++++++++++++++++++++++++++++
scripts/gdb/vmlinux-gdb.py | 26 +++++++++
9 files changed, 555 insertions(+), 2 deletions(-)
create mode 100644 scripts/gdb/Makefile
create mode 100644 scripts/gdb/dmesg.py
create mode 100644 scripts/gdb/percpu.py
create mode 100644 scripts/gdb/symbols.py
create mode 100644 scripts/gdb/task.py
create mode 100644 scripts/gdb/utils.py
create mode 100644 scripts/gdb/vmlinux-gdb.py
--
1.7.3.4
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 10/13] scripts/gdb: Add internal helper and convenience function to retrieve thread_info
2012-11-05 16:08 [PATCH 00/13] Add gdb python scripts as kernel debugging helpers Jan Kiszka
@ 2012-11-05 16:09 ` Jan Kiszka
0 siblings, 0 replies; 3+ messages in thread
From: Jan Kiszka @ 2012-11-05 16:09 UTC (permalink / raw)
To: linux-kernel
Cc: Jason Wessel, kgdb-bugreport, Andi Kleen, Tony Luck, Fenghua Yu,
linux-ia64
Add the internal helper get_thread_info that calculated the thread_info
from a given task variable. Also export this service as a convenience
function.
Note: ia64 version is untested.
CC: Tony Luck <tony.luck@intel.com>
CC: Fenghua Yu <fenghua.yu@intel.com>
CC: linux-ia64@vger.kernel.org
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
scripts/gdb/task.py | 39 +++++++++++++++++++++++++++++++++++++++
1 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/scripts/gdb/task.py b/scripts/gdb/task.py
index 41d85cc..523e495 100644
--- a/scripts/gdb/task.py
+++ b/scripts/gdb/task.py
@@ -67,3 +67,42 @@ class LxTaskByPidFunc(gdb.Function):
raise gdb.GdbError("No task of PID " + str(pid))
LxTaskByPidFunc()
+
+
+thread_info_ptr_type = None
+
+def get_thread_info_ptr_type():
+ global thread_info_ptr_type
+ if thread_info_ptr_type = None:
+ thread_info_ptr_type = get_type('struct thread_info').pointer()
+ return thread_info_ptr_type
+
+ia64_task_size = None
+
+def get_thread_info(task):
+ if is_target_arch("ia64"):
+ global ia64_task_size
+ if ia64_task_size = None:
+ ia64_task_size = gdb.parse_and_eval(
+ "sizeof(struct task_struct)")
+ thread_info_addr = task.address + ia64_task_size
+ thread_info = thread_info_addr.cast(get_thread_info_ptr_type())
+ else:
+ thread_info = task['stack'].cast(get_thread_info_ptr_type())
+ return thread_info.dereference()
+
+
+class LxThreadInfoFunc (gdb.Function):
+ # Calculate Linux thread_info from task variable.
+ __doc__ = "Calculate Linux thread_info from task variable.\n" \
+ "\n" \
+ "$lx_thread_info(TASK): Given TASK, return the corresponding thread_info\n" \
+ "variable.\n"
+
+ def __init__(self):
+ super(LxThreadInfoFunc, self).__init__("lx_thread_info")
+
+ def invoke(self, task):
+ return get_thread_info(task)
+
+LxThreadInfoFunc()
--
1.7.3.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-11-05 16:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-05 16:08 [PATCH 00/13] Add gdb python scripts as kernel debugging helpers Jan Kiszka
2012-11-05 16:09 ` [PATCH 10/13] scripts/gdb: Add internal helper and convenience function to retrieve thread_info Jan Kiszka
-- strict thread matches above, loose matches on Subject: below --
2012-10-03 11:21 [PATCH 00/13] Add gdb python scripts as kernel debugging helpers Jan Kiszka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).