path: root/scripts/gdb
diff options
authorBarry Song <>2021-05-06 18:05:09 -0700
committerLinus Torvalds <>2021-05-07 00:26:33 -0700
commit526940e3962620f1a24d5e30c3dac7358194d963 (patch)
tree0790f466d62ce8fa68a4a6a9de151b7b56d40363 /scripts/gdb
parentdc9586823f3e06867344e6cf88741688c2c7737f (diff)
scripts/gdb: add lx_current support for arm64
arm64 uses SP_EL0 to save the current task_struct address. While running in EL0, SP_EL0 is clobbered by userspace. So if the upper bit is not 1 (not TTBR1), the current address is invalid. This patch checks the upper bit of SP_EL0, if the upper bit is 1, lx_current() of arm64 will return the derefrence of current task. Otherwise, lx_current() will tell users they are running in userspace(EL0). While arm64 is running in EL0, it is actually pointless to print current task as the memory of kernel space is not accessible in EL0. Link: Signed-off-by: Barry Song <> Cc: Jan Kiszka <> Cc: Jonathan Corbet <> Cc: Kieran Bingham <> Signed-off-by: Andrew Morton <> Signed-off-by: Linus Torvalds <>
Diffstat (limited to 'scripts/gdb')
1 files changed, 13 insertions, 0 deletions
diff --git a/scripts/gdb/linux/ b/scripts/gdb/linux/
index f382762509d3..15fc4626d236 100644
--- a/scripts/gdb/linux/
+++ b/scripts/gdb/linux/
@@ -16,6 +16,9 @@ import gdb
from linux import tasks, utils
+task_type = utils.CachedType("struct task_struct")
MAX_CPUS = 4096
@@ -157,9 +160,19 @@ Note that VAR has to be quoted as string."""
def get_current_task(cpu):
+ task_ptr_type = task_type.get_type().pointer()
if utils.is_target_arch("x86"):
var_ptr = gdb.parse_and_eval("&current_task")
return per_cpu(var_ptr, cpu).dereference()
+ elif utils.is_target_arch("aarch64"):
+ current_task_addr = gdb.parse_and_eval("$SP_EL0")
+ if((current_task_addr >> 63) != 0):
+ current_task = current_task_addr.cast(task_ptr_type)
+ return current_task.dereference()
+ else:
+ raise gdb.GdbError("Sorry, obtaining the current task is not allowed "
+ "while running in userspace(EL0)")
raise gdb.GdbError("Sorry, obtaining the current task is not yet "
"supported with this arch")