* [PATCH 0/2] scripts/gdb: Fixes related to lx_per_cpu()
@ 2025-05-03 12:32 Illia Ostapyshyn
2025-05-03 12:32 ` [PATCH 1/2] scripts/gdb: Fix kgdb probing on single-core systems Illia Ostapyshyn
2025-05-03 12:32 ` [PATCH 2/2] scripts/gdb: Update documentation for lx_per_cpu Illia Ostapyshyn
0 siblings, 2 replies; 3+ messages in thread
From: Illia Ostapyshyn @ 2025-05-03 12:32 UTC (permalink / raw)
To: linux-kernel, workflows, linux-doc
Cc: Jan Kiszka, Kieran Bingham, Andrew Morton, Florian Rommel,
Jonathan Corbet, Alex Shi, Yanteng Si, Dongliang Mu, Hu Haowen,
Brendan Jackman, Illia Ostapyshyn
Hi all,
these patches (1) fix kgdb detection on systems featuring a single CPU and
(2) update the documentation to reflect the current usage of lx_per_cpu()
and update an outdated example of its usage.
Illia Ostapyshyn (2):
scripts/gdb: Fix kgdb probing on single-core systems
scripts/gdb: Update documentation for lx_per_cpu
.../debugging/gdb-kernel-debugging.rst | 34 ++++++++-----------
.../zh_CN/dev-tools/gdb-kernel-debugging.rst | 34 ++++++++-----------
.../zh_TW/dev-tools/gdb-kernel-debugging.rst | 34 ++++++++-----------
scripts/gdb/linux/cpus.py | 4 +--
scripts/gdb/linux/utils.py | 2 +-
5 files changed, 48 insertions(+), 60 deletions(-)
base-commit: 95d3481af6dc90fd7175a7643fd108cdcb808ce5
--
2.47.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] scripts/gdb: Fix kgdb probing on single-core systems
2025-05-03 12:32 [PATCH 0/2] scripts/gdb: Fixes related to lx_per_cpu() Illia Ostapyshyn
@ 2025-05-03 12:32 ` Illia Ostapyshyn
2025-05-03 12:32 ` [PATCH 2/2] scripts/gdb: Update documentation for lx_per_cpu Illia Ostapyshyn
1 sibling, 0 replies; 3+ messages in thread
From: Illia Ostapyshyn @ 2025-05-03 12:32 UTC (permalink / raw)
To: linux-kernel, workflows, linux-doc
Cc: Jan Kiszka, Kieran Bingham, Andrew Morton, Florian Rommel,
Jonathan Corbet, Alex Shi, Yanteng Si, Dongliang Mu, Hu Haowen,
Brendan Jackman, Illia Ostapyshyn
When requested the list of threads via qfThreadInfo, gdb_cmd_query in
kernel/debug/gdbstub.c first returns "shadow" threads for CPUs followed
by the actual tasks in the system. Extended qThreadExtraInfo queries
yield "shadowCPU%d" as the name for the CPU core threads.
This behavior is used by get_gdbserver_type() to probe for KGDB by
matching the name for the thread 2 against "shadowCPU". This breaks
down on single-core systems, where thread 2 is the first nonshadow
thread. Request the name for thread 1 instead.
As GDB assigns thread IDs in the order of their appearance, it is safe
to assume shadowCPU0 at ID 1 as long as CPU0 is not hotplugged.
Before:
(gdb) info threads
Id Target Id Frame
1 Thread 4294967294 (shadowCPU0) kgdb_breakpoint ()
* 2 Thread 1 (swapper/0) kgdb_breakpoint ()
3 Thread 2 (kthreadd) 0x0000000000000000 in ?? ()
...
(gdb) p $lx_current().comm
Sorry, obtaining the current CPU is not yet supported with this gdb server.
After:
(gdb) info threads
Id Target Id Frame
1 Thread 4294967294 (shadowCPU0) kgdb_breakpoint ()
* 2 Thread 1 (swapper/0) kgdb_breakpoint ()
3 Thread 2 (kthreadd) 0x0000000000000000 in ?? ()
...
(gdb) p $lx_current().comm
$1 = "swapper/0\000\000\000\000\000\000"
Signed-off-by: Illia Ostapyshyn <illia@yshyn.com>
---
scripts/gdb/linux/utils.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/gdb/linux/utils.py b/scripts/gdb/linux/utils.py
index 03ebdccf5f69..877404e92dbb 100644
--- a/scripts/gdb/linux/utils.py
+++ b/scripts/gdb/linux/utils.py
@@ -200,7 +200,7 @@ def get_gdbserver_type():
def probe_kgdb():
try:
- thread_info = gdb.execute("info thread 2", to_string=True)
+ thread_info = gdb.execute("info thread 1", to_string=True)
return "shadowCPU" in thread_info
except gdb.error:
return False
--
2.47.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] scripts/gdb: Update documentation for lx_per_cpu
2025-05-03 12:32 [PATCH 0/2] scripts/gdb: Fixes related to lx_per_cpu() Illia Ostapyshyn
2025-05-03 12:32 ` [PATCH 1/2] scripts/gdb: Fix kgdb probing on single-core systems Illia Ostapyshyn
@ 2025-05-03 12:32 ` Illia Ostapyshyn
1 sibling, 0 replies; 3+ messages in thread
From: Illia Ostapyshyn @ 2025-05-03 12:32 UTC (permalink / raw)
To: linux-kernel, workflows, linux-doc
Cc: Jan Kiszka, Kieran Bingham, Andrew Morton, Florian Rommel,
Jonathan Corbet, Alex Shi, Yanteng Si, Dongliang Mu, Hu Haowen,
Brendan Jackman, Illia Ostapyshyn
Commit db08c53fdd542bb7f83b ("scripts/gdb: fix parameter handling in
$lx_per_cpu") changed the parameter handling of lx_per_cpu to use
GdbValue instead of parsing the variable name. Update the documentation
to reflect the new lx_per_cpu usage. Update the hrtimer_bases example
to use rb_tree instead of the timerqueue_head.next pointer removed in
commit 511885d7061eda3eb1fa ("lib/timerqueue: Rely on rbtree semantics
for next timer").
Signed-off-by: Illia Ostapyshyn <illia@yshyn.com>
---
.../debugging/gdb-kernel-debugging.rst | 34 ++++++++-----------
.../zh_CN/dev-tools/gdb-kernel-debugging.rst | 34 ++++++++-----------
.../zh_TW/dev-tools/gdb-kernel-debugging.rst | 34 ++++++++-----------
scripts/gdb/linux/cpus.py | 4 +--
4 files changed, 47 insertions(+), 59 deletions(-)
diff --git a/Documentation/process/debugging/gdb-kernel-debugging.rst b/Documentation/process/debugging/gdb-kernel-debugging.rst
index 895285c037c7..9475c759c722 100644
--- a/Documentation/process/debugging/gdb-kernel-debugging.rst
+++ b/Documentation/process/debugging/gdb-kernel-debugging.rst
@@ -127,35 +127,31 @@ Examples of using the Linux-provided gdb helpers
- Make use of the per-cpu function for the current or a specified CPU::
- (gdb) p $lx_per_cpu("runqueues").nr_running
+ (gdb) p $lx_per_cpu(runqueues).nr_running
$3 = 1
- (gdb) p $lx_per_cpu("runqueues", 2).nr_running
+ (gdb) p $lx_per_cpu(runqueues, 2).nr_running
$4 = 0
- Dig into hrtimers using the container_of helper::
- (gdb) set $next = $lx_per_cpu("hrtimer_bases").clock_base[0].active.next
- (gdb) p *$container_of($next, "struct hrtimer", "node")
+ (gdb) set $leftmost = $lx_per_cpu(hrtimer_bases).clock_base[0].active.rb_root.rb_leftmost
+ (gdb) p *$container_of($leftmost, "struct hrtimer", "node")
$5 = {
node = {
node = {
- __rb_parent_color = 18446612133355256072,
- rb_right = 0x0 <irq_stack_union>,
- rb_left = 0x0 <irq_stack_union>
+ __rb_parent_color = 18446612686384860673,
+ rb_right = 0xffff888231da8b00,
+ rb_left = 0x0
},
- expires = {
- tv64 = 1835268000000
- }
+ expires = 1228461000000
},
- _softexpires = {
- tv64 = 1835268000000
- },
- function = 0xffffffff81078232 <tick_sched_timer>,
- base = 0xffff88003fd0d6f0,
- state = 1,
- start_pid = 0,
- start_site = 0xffffffff81055c1f <hrtimer_start_range_ns+20>,
- start_comm = "swapper/2\000\000\000\000\000\000"
+ _softexpires = 1228461000000,
+ function = 0xffffffff8137ab20 <tick_nohz_handler>,
+ base = 0xffff888231d9b4c0,
+ state = 1 '\001',
+ is_rel = 0 '\000',
+ is_soft = 0 '\000',
+ is_hard = 1 '\001'
}
diff --git a/Documentation/translations/zh_CN/dev-tools/gdb-kernel-debugging.rst b/Documentation/translations/zh_CN/dev-tools/gdb-kernel-debugging.rst
index 3c133a918f30..282aacd33442 100644
--- a/Documentation/translations/zh_CN/dev-tools/gdb-kernel-debugging.rst
+++ b/Documentation/translations/zh_CN/dev-tools/gdb-kernel-debugging.rst
@@ -120,35 +120,31 @@ Kgdb内核调试器、QEMU等虚拟机管理程序或基于JTAG的硬件接口
- 对当前或指定的CPU使用per-cpu函数::
- (gdb) p $lx_per_cpu("runqueues").nr_running
+ (gdb) p $lx_per_cpu(runqueues).nr_running
$3 = 1
- (gdb) p $lx_per_cpu("runqueues", 2).nr_running
+ (gdb) p $lx_per_cpu(runqueues, 2).nr_running
$4 = 0
- 使用container_of查看更多hrtimers信息::
- (gdb) set $next = $lx_per_cpu("hrtimer_bases").clock_base[0].active.next
- (gdb) p *$container_of($next, "struct hrtimer", "node")
+ (gdb) set $leftmost = $lx_per_cpu(hrtimer_bases).clock_base[0].active.rb_root.rb_leftmost
+ (gdb) p *$container_of($leftmost, "struct hrtimer", "node")
$5 = {
node = {
node = {
- __rb_parent_color = 18446612133355256072,
- rb_right = 0x0 <irq_stack_union>,
- rb_left = 0x0 <irq_stack_union>
+ __rb_parent_color = 18446612686384860673,
+ rb_right = 0xffff888231da8b00,
+ rb_left = 0x0
},
- expires = {
- tv64 = 1835268000000
- }
+ expires = 1228461000000
},
- _softexpires = {
- tv64 = 1835268000000
- },
- function = 0xffffffff81078232 <tick_sched_timer>,
- base = 0xffff88003fd0d6f0,
- state = 1,
- start_pid = 0,
- start_site = 0xffffffff81055c1f <hrtimer_start_range_ns+20>,
- start_comm = "swapper/2\000\000\000\000\000\000"
+ _softexpires = 1228461000000,
+ function = 0xffffffff8137ab20 <tick_nohz_handler>,
+ base = 0xffff888231d9b4c0,
+ state = 1 '\001',
+ is_rel = 0 '\000',
+ is_soft = 0 '\000',
+ is_hard = 1 '\001'
}
diff --git a/Documentation/translations/zh_TW/dev-tools/gdb-kernel-debugging.rst b/Documentation/translations/zh_TW/dev-tools/gdb-kernel-debugging.rst
index c881e8872b19..b595af59ba78 100644
--- a/Documentation/translations/zh_TW/dev-tools/gdb-kernel-debugging.rst
+++ b/Documentation/translations/zh_TW/dev-tools/gdb-kernel-debugging.rst
@@ -116,35 +116,31 @@ Kgdb內核調試器、QEMU等虛擬機管理程序或基於JTAG的硬件接口
- 對當前或指定的CPU使用per-cpu函數::
- (gdb) p $lx_per_cpu("runqueues").nr_running
+ (gdb) p $lx_per_cpu(runqueues).nr_running
$3 = 1
- (gdb) p $lx_per_cpu("runqueues", 2).nr_running
+ (gdb) p $lx_per_cpu(runqueues, 2).nr_running
$4 = 0
- 使用container_of查看更多hrtimers信息::
- (gdb) set $next = $lx_per_cpu("hrtimer_bases").clock_base[0].active.next
- (gdb) p *$container_of($next, "struct hrtimer", "node")
+ (gdb) set $leftmost = $lx_per_cpu(hrtimer_bases).clock_base[0].active.rb_root.rb_leftmost
+ (gdb) p *$container_of($leftmost, "struct hrtimer", "node")
$5 = {
node = {
node = {
- __rb_parent_color = 18446612133355256072,
- rb_right = 0x0 <irq_stack_union>,
- rb_left = 0x0 <irq_stack_union>
+ __rb_parent_color = 18446612686384860673,
+ rb_right = 0xffff888231da8b00,
+ rb_left = 0x0
},
- expires = {
- tv64 = 1835268000000
- }
+ expires = 1228461000000
},
- _softexpires = {
- tv64 = 1835268000000
- },
- function = 0xffffffff81078232 <tick_sched_timer>,
- base = 0xffff88003fd0d6f0,
- state = 1,
- start_pid = 0,
- start_site = 0xffffffff81055c1f <hrtimer_start_range_ns+20>,
- start_comm = "swapper/2\000\000\000\000\000\000"
+ _softexpires = 1228461000000,
+ function = 0xffffffff8137ab20 <tick_nohz_handler>,
+ base = 0xffff888231d9b4c0,
+ state = 1 '\001',
+ is_rel = 0 '\000',
+ is_soft = 0 '\000',
+ is_hard = 1 '\001'
}
diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
index f506965ea759..6edf4ef61636 100644
--- a/scripts/gdb/linux/cpus.py
+++ b/scripts/gdb/linux/cpus.py
@@ -141,7 +141,7 @@ LxCpus()
class PerCpu(gdb.Function):
"""Return per-cpu variable.
-$lx_per_cpu("VAR"[, CPU]): Return the per-cpu variable called VAR for the
+$lx_per_cpu(VAR[, CPU]): Return the per-cpu variable called VAR for the
given CPU number. If CPU is omitted, the CPU of the current context is used.
Note that VAR has to be quoted as string."""
@@ -158,7 +158,7 @@ PerCpu()
class PerCpuPtr(gdb.Function):
"""Return per-cpu pointer.
-$lx_per_cpu_ptr("VAR"[, CPU]): Return the per-cpu pointer called VAR for the
+$lx_per_cpu_ptr(VAR[, CPU]): Return the per-cpu pointer called VAR for the
given CPU number. If CPU is omitted, the CPU of the current context is used.
Note that VAR has to be quoted as string."""
--
2.47.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-05-03 12:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-03 12:32 [PATCH 0/2] scripts/gdb: Fixes related to lx_per_cpu() Illia Ostapyshyn
2025-05-03 12:32 ` [PATCH 1/2] scripts/gdb: Fix kgdb probing on single-core systems Illia Ostapyshyn
2025-05-03 12:32 ` [PATCH 2/2] scripts/gdb: Update documentation for lx_per_cpu Illia Ostapyshyn
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).