Skip to content

Commit

Permalink
scripts/gdb: document lx_current is only supported by x86
Browse files Browse the repository at this point in the history
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: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Barry Song <[email protected]>
Cc: Jan Kiszka <[email protected]>
Cc: Kieran Bingham <[email protected]>
Cc: Jonathan Corbet <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Barry Song authored and torvalds committed May 7, 2021
1 parent 2392154 commit dc95868
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Documentation/dev-tools/gdb-kernel-debugging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Examples of using the Linux-provided gdb helpers
[ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
....

- Examine fields of the current task struct::
- Examine fields of the current task struct(supported by x86 only)::

(gdb) p $lx_current().pid
$1 = 4998
Expand Down
10 changes: 8 additions & 2 deletions scripts/gdb/linux/cpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ def invoke(self, var_name, cpu=-1):

PerCpu()

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.
Expand All @@ -167,8 +174,7 @@ def __init__(self):
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)


LxCurrentFunc()

0 comments on commit dc95868

Please sign in to comment.