Skip to content

Commit 6be7045

Browse files
iostapyshynakpm00
authored andcommitted
scripts/gdb: fix kgdb probing on single-core systems
Patch series "scripts/gdb: Fixes related to lx_per_cpu()". 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. This patch (of 2): 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" Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Illia Ostapyshyn <[email protected]> Cc: Alex Shi <[email protected]> Cc: Brendan Jackman <[email protected]> Cc: Dongliang Mu <[email protected]> Cc: Florian Rommel <[email protected]> Cc: Hu Haowen <[email protected]> Cc: Jan Kiszka <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Kieran Bingham <[email protected]> Cc: Yanteng Si <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent f11c1ef commit 6be7045

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

scripts/gdb/linux/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def probe_qemu():
200200

201201
def probe_kgdb():
202202
try:
203-
thread_info = gdb.execute("info thread 2", to_string=True)
203+
thread_info = gdb.execute("info thread 1", to_string=True)
204204
return "shadowCPU" in thread_info
205205
except gdb.error:
206206
return False

0 commit comments

Comments
 (0)