path: root/scripts/gdb/linux/
diff options
authorBarry Song <>2021-05-06 18:05:06 -0700
committerLinus Torvalds <>2021-05-07 00:26:33 -0700
commitdc9586823f3e06867344e6cf88741688c2c7737f (patch)
tree98edf6b61a8b533edd579bcdaca807396c43a610 /scripts/gdb/linux/
parent23921540d2c0a4d8530078f6f64fc3e28444ca9d (diff)
scripts/gdb: document lx_current is only supported by x86
Patch series "scripts/gdb: clarify the platforms supporting lx_current and add arm64 support", v2. lx_current depends on per_cpu current_task variable which exists on x86 only. so it actually works on x86 only. the 1st patch documents this clearly; the 2nd patch adds support for arm64. This patch (of 2): x86 is the only architecture which has per_cpu current_task: arch$ git grep current_task | grep -i per_cpu x86/include/asm/current.h:DECLARE_PER_CPU(struct task_struct *, current_task); x86/kernel/cpu/common.c:DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned = x86/kernel/cpu/common.c:EXPORT_PER_CPU_SYMBOL(current_task); x86/kernel/cpu/common.c:DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task; x86/kernel/cpu/common.c:EXPORT_PER_CPU_SYMBOL(current_task); x86/kernel/smpboot.c: per_cpu(current_task, cpu) = idle; On other architectures, lx_current() will lead to a python exception: (gdb) p $lx_current().pid Python Exception <class 'gdb.error'> No symbol "current_task" in current context.: Error occurred in Python: No symbol "current_task" in current context. To avoid more people struggling and wasting time in other architectures, document it. Link: Link: Signed-off-by: Barry Song <> Cc: Jan Kiszka <> Cc: Kieran Bingham <> Cc: Jonathan Corbet <> Signed-off-by: Andrew Morton <> Signed-off-by: Linus Torvalds <>
Diffstat (limited to 'scripts/gdb/linux/')
1 files changed, 8 insertions, 2 deletions
diff --git a/scripts/gdb/linux/ b/scripts/gdb/linux/
index 008e62f3190d..f382762509d3 100644
--- a/scripts/gdb/linux/
+++ b/scripts/gdb/linux/
@@ -156,6 +156,13 @@ Note that VAR has to be quoted as string."""
+def get_current_task(cpu):
+ if utils.is_target_arch("x86"):
+ var_ptr = gdb.parse_and_eval("&current_task")
+ return per_cpu(var_ptr, cpu).dereference()
+ else:
+ raise gdb.GdbError("Sorry, obtaining the current task is not yet "
+ "supported with this arch")
class LxCurrentFunc(gdb.Function):
"""Return current task.
@@ -167,8 +174,7 @@ number. If CPU is omitted, the CPU of the current context is used."""
super(LxCurrentFunc, self).__init__("lx_current")
def invoke(self, cpu=-1):
- var_ptr = gdb.parse_and_eval("&current_task")
- return per_cpu(var_ptr, cpu).dereference()
+ return get_current_task(cpu)