* [PATCH 0/4] scripts/gdb: Fixes for $lx_current and $lx_per_cpu
@ 2024-04-25 15:34 Florian Rommel
2024-04-25 15:34 ` [PATCH 1/4] scripts/gdb: Fix failing KGDB detection during probe Florian Rommel
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Florian Rommel @ 2024-04-25 15:34 UTC (permalink / raw)
To: Jan Kiszka, Kieran Bingham
Cc: Kuan-Ying Lee, Palmer Dabbelt, Deepak Gupta, Andrew Jones,
Andrew Morton, linux-kernel, Florian Rommel
Hi all,
This series fixes several bugs in the GDB scripts related to the
$lx_current and $lx_per_cpu functions. The changes were tested with
GDB 10, 11, 12, 13, and 14.
Patch 1 fixes false-negative results when probing for KGDB
Patch 2 fixes the $lx_per_cpu function, which is currently non-functional
in QEMU-GDB and KGDB.
Patch 3 fixes an additional bug in $lx_per_cpu that occurs with KGDB.
Patch 4 fixes the incorrect detection of the current CPU number in KGDB,
which silently breaks $lx_per_cpu and $lx_current.
Regards,
Flo
Florian Rommel (4):
scripts/gdb: Fix failing KGDB detection during probe
scripts/gdb: Fix parameter handling in $lx_per_cpu
scripts/gdb: Make get_thread_info accept pointers
scripts/gdb: Fix detection of current CPU in KGDB
scripts/gdb/linux/cpus.py | 11 +++--------
scripts/gdb/linux/tasks.py | 2 +-
scripts/gdb/linux/utils.py | 2 +-
3 files changed, 5 insertions(+), 10 deletions(-)
--
2.44.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] scripts/gdb: Fix failing KGDB detection during probe
2024-04-25 15:34 [PATCH 0/4] scripts/gdb: Fixes for $lx_current and $lx_per_cpu Florian Rommel
@ 2024-04-25 15:34 ` Florian Rommel
2024-04-25 15:34 ` [PATCH 2/4] scripts/gdb: Fix parameter handling in $lx_per_cpu Florian Rommel
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Florian Rommel @ 2024-04-25 15:34 UTC (permalink / raw)
To: Jan Kiszka, Kieran Bingham
Cc: Kuan-Ying Lee, Palmer Dabbelt, Deepak Gupta, Andrew Jones,
Andrew Morton, linux-kernel, Florian Rommel
The KGDB probe function sometimes failed to detect KGDB for SMP machines as
it assumed that task 2 (kthreadd) is running on CPU 0, which is not
necessarily the case. Now, the detection is agnostic to kthreadd's CPU.
Signed-off-by: Florian Rommel <mail@florommel.de>
---
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 7d5278d815fa..245ab297ea84 100644
--- a/scripts/gdb/linux/utils.py
+++ b/scripts/gdb/linux/utils.py
@@ -196,7 +196,7 @@ def get_gdbserver_type():
def probe_kgdb():
try:
thread_info = gdb.execute("info thread 2", to_string=True)
- return "shadowCPU0" in thread_info
+ return "shadowCPU" in thread_info
except gdb.error:
return False
--
2.44.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/4] scripts/gdb: Fix parameter handling in $lx_per_cpu
2024-04-25 15:34 [PATCH 0/4] scripts/gdb: Fixes for $lx_current and $lx_per_cpu Florian Rommel
2024-04-25 15:34 ` [PATCH 1/4] scripts/gdb: Fix failing KGDB detection during probe Florian Rommel
@ 2024-04-25 15:34 ` Florian Rommel
2024-04-25 15:35 ` [PATCH 3/4] scripts/gdb: Make get_thread_info accept pointers Florian Rommel
2024-04-25 15:35 ` [PATCH 4/4] scripts/gdb: Fix detection of current CPU in KGDB Florian Rommel
3 siblings, 0 replies; 5+ messages in thread
From: Florian Rommel @ 2024-04-25 15:34 UTC (permalink / raw)
To: Jan Kiszka, Kieran Bingham
Cc: Kuan-Ying Lee, Palmer Dabbelt, Deepak Gupta, Andrew Jones,
Andrew Morton, linux-kernel, Florian Rommel
Before, the script tried to get the address by constructing a pointer to
the parameter (by name). However, since GDB now passes the parameter as a
GdbValue, we cannot get its name. Instead, we retrieve the address through
GdbValue's address attribute.
Before:
>>> p $lx_per_cpu(cpu_info)
Traceback (most recent call last):
File "./scripts/gdb/linux/cpus.py", line 152, in invoke
var_ptr = gdb.parse_and_eval("&" + var_name.string())
^^^^^^^^^^^^^^^^^
gdb.error: Trying to read string with inappropriate type `struct cpuinfo_x86'.
Signed-off-by: Florian Rommel <mail@florommel.de>
---
scripts/gdb/linux/cpus.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
index cba589e5b57d..2b51a3abd363 100644
--- a/scripts/gdb/linux/cpus.py
+++ b/scripts/gdb/linux/cpus.py
@@ -152,9 +152,8 @@ Note that VAR has to be quoted as string."""
def __init__(self):
super(PerCpu, self).__init__("lx_per_cpu")
- def invoke(self, var_name, cpu=-1):
- var_ptr = gdb.parse_and_eval("&" + var_name.string())
- return per_cpu(var_ptr, cpu)
+ def invoke(self, var, cpu=-1):
+ return per_cpu(var.address, cpu)
PerCpu()
--
2.44.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/4] scripts/gdb: Make get_thread_info accept pointers
2024-04-25 15:34 [PATCH 0/4] scripts/gdb: Fixes for $lx_current and $lx_per_cpu Florian Rommel
2024-04-25 15:34 ` [PATCH 1/4] scripts/gdb: Fix failing KGDB detection during probe Florian Rommel
2024-04-25 15:34 ` [PATCH 2/4] scripts/gdb: Fix parameter handling in $lx_per_cpu Florian Rommel
@ 2024-04-25 15:35 ` Florian Rommel
2024-04-25 15:35 ` [PATCH 4/4] scripts/gdb: Fix detection of current CPU in KGDB Florian Rommel
3 siblings, 0 replies; 5+ messages in thread
From: Florian Rommel @ 2024-04-25 15:35 UTC (permalink / raw)
To: Jan Kiszka, Kieran Bingham
Cc: Kuan-Ying Lee, Palmer Dabbelt, Deepak Gupta, Andrew Jones,
Andrew Morton, linux-kernel, Florian Rommel
get_thread_info ($lx_thread_info) only accepted a dereferenced task
parameter. Passing a pointer to a task_struct (like $lx_per_cpu does with
KGDB) threw an exception.
With this patch, both (dereferenced values and pointers) are accepted.
Before (on x86, KGDB):
>>> p $lx_per_cpu(cpu_info)
Traceback (most recent call last):
File "./scripts/gdb/linux/cpus.py", line 158, in invoke
return per_cpu(var_ptr, cpu)
^^^^^^^^^^^^^^^^^^^^^
File "./scripts/gdb/linux/cpus.py", line 42, in per_cpu
cpu = get_current_cpu()
^^^^^^^^^^^^^^^^^
File "./scripts/gdb/linux/cpus.py", line 33, in get_current_cpu
return tasks.get_thread_info(tasks.get_task_by_pid(tid))['cpu']
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "./scripts/gdb/linux/tasks.py", line 88, in get_thread_info
if task.type.fields()[0].type == thread_info_type.get_type():
~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
Signed-off-by: Florian Rommel <mail@florommel.de>
---
scripts/gdb/linux/tasks.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/gdb/linux/tasks.py b/scripts/gdb/linux/tasks.py
index 6793d6e86e77..62348397c1f5 100644
--- a/scripts/gdb/linux/tasks.py
+++ b/scripts/gdb/linux/tasks.py
@@ -85,7 +85,7 @@ thread_info_type = utils.CachedType("struct thread_info")
def get_thread_info(task):
thread_info_ptr_type = thread_info_type.get_type().pointer()
- if task.type.fields()[0].type == thread_info_type.get_type():
+ if task_type.get_type().fields()[0].type == thread_info_type.get_type():
return task['thread_info']
thread_info = task['stack'].cast(thread_info_ptr_type)
return thread_info.dereference()
--
2.44.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 4/4] scripts/gdb: Fix detection of current CPU in KGDB
2024-04-25 15:34 [PATCH 0/4] scripts/gdb: Fixes for $lx_current and $lx_per_cpu Florian Rommel
` (2 preceding siblings ...)
2024-04-25 15:35 ` [PATCH 3/4] scripts/gdb: Make get_thread_info accept pointers Florian Rommel
@ 2024-04-25 15:35 ` Florian Rommel
3 siblings, 0 replies; 5+ messages in thread
From: Florian Rommel @ 2024-04-25 15:35 UTC (permalink / raw)
To: Jan Kiszka, Kieran Bingham
Cc: Kuan-Ying Lee, Palmer Dabbelt, Deepak Gupta, Andrew Jones,
Andrew Morton, linux-kernel, Florian Rommel
Directly read the current CPU number from the kgdb_active variable.
Before, the active CPU was obtained through the current task, which
required searching the task list for the pid of GDB's selected thread.
Obtaining the pid was buggy:
GDB may use selected_thread().ptid[1] (LWPID) instead of .ptid[2] (TID) to
store the threads pid; see
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Threads-In-Python.html
As a result, the detection could return the wrong CPU number, leading to
incorrect results for $lx_per_cpu and $lx_current.
As a side effect, the patch significantly speeds up $lx_per_cpu and
$lx_current in KGDB by avoiding the task-list iteration.
Signed-off-by: Florian Rommel <mail@florommel.de>
---
scripts/gdb/linux/cpus.py | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
index 2b51a3abd363..2f11c4f9c345 100644
--- a/scripts/gdb/linux/cpus.py
+++ b/scripts/gdb/linux/cpus.py
@@ -26,11 +26,7 @@ def get_current_cpu():
if utils.get_gdbserver_type() == utils.GDBSERVER_QEMU:
return gdb.selected_thread().num - 1
elif utils.get_gdbserver_type() == utils.GDBSERVER_KGDB:
- tid = gdb.selected_thread().ptid[2]
- if tid > (0x100000000 - MAX_CPUS - 2):
- return 0x100000000 - tid - 2
- else:
- return tasks.get_thread_info(tasks.get_task_by_pid(tid))['cpu']
+ return gdb.parse_and_eval("kgdb_active.counter")
else:
raise gdb.GdbError("Sorry, obtaining the current CPU is not yet "
"supported with this gdb server.")
--
2.44.0
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-04-25 16:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-25 15:34 [PATCH 0/4] scripts/gdb: Fixes for $lx_current and $lx_per_cpu Florian Rommel
2024-04-25 15:34 ` [PATCH 1/4] scripts/gdb: Fix failing KGDB detection during probe Florian Rommel
2024-04-25 15:34 ` [PATCH 2/4] scripts/gdb: Fix parameter handling in $lx_per_cpu Florian Rommel
2024-04-25 15:35 ` [PATCH 3/4] scripts/gdb: Make get_thread_info accept pointers Florian Rommel
2024-04-25 15:35 ` [PATCH 4/4] scripts/gdb: Fix detection of current CPU in KGDB Florian Rommel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®