diff options
author | Jan Kiszka <jan.kiszka@siemens.com> | 2015-02-17 16:47:21 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-17 17:34:54 -0500 |
commit | fe7f9ed98dad611ceaf17403f1c5bfd016eadcaa (patch) | |
tree | 469d69f6e6ede329e2e09e513117915aebc7447d /scripts | |
parent | a4d86792c78d23257ab8ddd29ca16ce597361403 (diff) |
scripts/gdb: add internal helper and convenience function for per-cpu lookup
This function allows to obtain a per-cpu variable, either of the current
or an explicitly specified CPU.
Note: sparc64 version is untested.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jason Wessel <jason.wessel@windriver.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Ben Widawsky <ben@bwidawsk.net>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/gdb/linux/cpus.py | 68 | ||||
-rw-r--r-- | scripts/gdb/vmlinux-gdb.py | 1 |
2 files changed, 69 insertions, 0 deletions
diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py new file mode 100644 index 000000000000..18337e01ddef --- /dev/null +++ b/scripts/gdb/linux/cpus.py | |||
@@ -0,0 +1,68 @@ | |||
1 | # | ||
2 | # gdb helper commands and functions for Linux kernel debugging | ||
3 | # | ||
4 | # per-cpu tools | ||
5 | # | ||
6 | # Copyright (c) Siemens AG, 2011-2013 | ||
7 | # | ||
8 | # Authors: | ||
9 | # Jan Kiszka <jan.kiszka@siemens.com> | ||
10 | # | ||
11 | # This work is licensed under the terms of the GNU GPL version 2. | ||
12 | # | ||
13 | |||
14 | import gdb | ||
15 | |||
16 | from linux import tasks, utils | ||
17 | |||
18 | |||
19 | MAX_CPUS = 4096 | ||
20 | |||
21 | |||
22 | def get_current_cpu(): | ||
23 | if utils.get_gdbserver_type() == utils.GDBSERVER_QEMU: | ||
24 | return gdb.selected_thread().num - 1 | ||
25 | elif utils.get_gdbserver_type() == utils.GDBSERVER_KGDB: | ||
26 | tid = gdb.selected_thread().ptid[2] | ||
27 | if tid > (0x100000000 - MAX_CPUS - 2): | ||
28 | return 0x100000000 - tid - 2 | ||
29 | else: | ||
30 | return tasks.get_thread_info(tasks.get_task_by_pid(tid))['cpu'] | ||
31 | else: | ||
32 | raise gdb.GdbError("Sorry, obtaining the current CPU is not yet " | ||
33 | "supported with this gdb server.") | ||
34 | |||
35 | |||
36 | def per_cpu(var_ptr, cpu): | ||
37 | if cpu == -1: | ||
38 | cpu = get_current_cpu() | ||
39 | if utils.is_target_arch("sparc:v9"): | ||
40 | offset = gdb.parse_and_eval( | ||
41 | "trap_block[{0}].__per_cpu_base".format(str(cpu))) | ||
42 | else: | ||
43 | try: | ||
44 | offset = gdb.parse_and_eval( | ||
45 | "__per_cpu_offset[{0}]".format(str(cpu))) | ||
46 | except gdb.error: | ||
47 | # !CONFIG_SMP case | ||
48 | offset = 0 | ||
49 | pointer = var_ptr.cast(utils.get_long_type()) + offset | ||
50 | return pointer.cast(var_ptr.type).dereference() | ||
51 | |||
52 | |||
53 | class PerCpu(gdb.Function): | ||
54 | """Return per-cpu variable. | ||
55 | |||
56 | $lx_per_cpu("VAR"[, CPU]): Return the per-cpu variable called VAR for the | ||
57 | given CPU number. If CPU is omitted, the CPU of the current context is used. | ||
58 | Note that VAR has to be quoted as string.""" | ||
59 | |||
60 | def __init__(self): | ||
61 | super(PerCpu, self).__init__("lx_per_cpu") | ||
62 | |||
63 | def invoke(self, var_name, cpu=-1): | ||
64 | var_ptr = gdb.parse_and_eval("&" + var_name.string()) | ||
65 | return per_cpu(var_ptr, cpu) | ||
66 | |||
67 | |||
68 | PerCpu() | ||
diff --git a/scripts/gdb/vmlinux-gdb.py b/scripts/gdb/vmlinux-gdb.py index 4d7eb2c409aa..48489285f119 100644 --- a/scripts/gdb/vmlinux-gdb.py +++ b/scripts/gdb/vmlinux-gdb.py | |||
@@ -27,3 +27,4 @@ else: | |||
27 | import linux.modules | 27 | import linux.modules |
28 | import linux.dmesg | 28 | import linux.dmesg |
29 | import linux.tasks | 29 | import linux.tasks |
30 | import linux.cpus | ||