Skip to contentSkip to conversation

scripts/gdb: Improve s390 support

PATCH New Jens Remus 1 participant 4 messages Dec 4, 2025

Subsystems (2)
lore
Share & tools
lore

Jens Remus

author
#0 lore raw

cover scripts/gdb: Improve s390 support

Patch 1 adds $lx_current([CPU]) support for s390 to obtain the task of the active context or a specific CPU.

Patch 2 adds a $lx_lowcore([CPU]) convenience function on s390 to obtain the s390 lowcore of the active context of a specific CPU. It is based on functionality introduced by patch 1.

Patch 3 adds a $lx_cpu() convenience function to obtain the CPU number of the active context.

Regards,
Jens

Jens Remus (3):
scripts/gdb: add lx_current support for s390 scripts/gdb: add lx_lowcore convenience function on s390 scripts/gdb: add lx_cpu convenience function

 scripts/gdb/linux/constants.py.in | 14 +++++++
 scripts/gdb/linux/cpus.py         | 67 ++++++++++++++++++++++++++++++-
 2 files changed, 80 insertions(+), 1 deletion(-)
Signature · 1 line
2.51.0
author
#1 lore raw

PATCH 1/3 scripts/gdb: add lx_current support for s390

s390 uses lowcore field current_task. Depending on s390 machine feature MFEATURE_LOWCORE the lowcore of the current CPU is either located at 0 or LOWCORE_ALT_ADDRESS. The lowcore address of any other CPUs can be retrieved from lowcore_ptr[], which is indexed by CPU number. Note that due to prefixing the lowcore of the current CPU cannot be addressed using the address in lowcore_ptr[].

Add helpers to test for s390 machine features, test for s390 relocated lowcore, and obtain the s390 lowcore address for a particular CPU. Use these to implement lx_current support for s390.

---
 scripts/gdb/linux/constants.py.in | 14 +++++++++++++
 scripts/gdb/linux/cpus.py         | 35 ++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 1 deletion(-)
scripts/gdb/linux/constants.py.in +14 -0
index c3886739a028..68c45fb27635 100644
@@ -24,6 +24,10 @@
 #include <linux/slab.h>
 #include <linux/threads.h>
 #include <linux/vmalloc.h>
+#ifdef CONFIG_S390
+#include <asm/lowcore.h>
+#include <asm/machine.h>
+#endif
 
 /* We need to stringify expanded macros so that they can be parsed */
 
@@ -122,6 +126,15 @@ LX_GDBPARSED(SLAB_CACHE_DMA32)
 LX_GDBPARSED(SLAB_STORE_USER)
 LX_GDBPARSED(SLAB_PANIC)
 
+/* asm/lowcore.h */
+if IS_BUILTIN(CONFIG_S390):
+    LX_GDBPARSED(LOWCORE_ALT_ADDRESS)
+
+/* asm/machine.h */
+if IS_BUILTIN(CONFIG_S390):
+    LX_VALUE(MFEATURE_LOWCORE)
+    LX_GDBPARSED(MAX_MFEATURE_BIT)
+
 /* Kernel Configs */
 LX_CONFIG(CONFIG_GENERIC_CLOCKEVENTS)
 LX_CONFIG(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
@@ -170,3 +183,4 @@ LX_CONFIG(CONFIG_PAGE_OWNER)
 LX_CONFIG(CONFIG_SLUB_DEBUG)
 LX_CONFIG(CONFIG_SLAB_FREELIST_HARDENED)
 LX_CONFIG(CONFIG_MMU)
+LX_CONFIG(CONFIG_S390)
scripts/gdb/linux/cpus.py +34 -1
index 6edf4ef61636..12bf37d6a4e5 100644
@@ -13,7 +13,7 @@
 
 import gdb
 
-from linux import tasks, utils
+from linux import constants, tasks, utils
 
 
 task_type = utils.CachedType("struct task_struct")
@@ -206,6 +206,11 @@ def get_current_task(cpu):
         if (scratch_reg.cast(utils.get_ulong_type()) > current_tp.cast(utils.get_ulong_type())):
             current_task = scratch_reg.cast(task_ptr_type)
 
+        return current_task.dereference()
+    elif utils.is_target_arch("s390"):
+        lowcore = s390_lowcore(cpu)
+        current_task_addr = lowcore["current_task"]
+        current_task = current_task_addr.cast(task_ptr_type)
         return current_task.dereference()
     else:
         raise gdb.GdbError("Sorry, obtaining the current task is not yet "
@@ -225,3 +230,31 @@ number. If CPU is omitted, the CPU of the current context is used."""
 
 
 LxCurrentFunc()
+
+
+def s390_machine_feature(nr):
+    if nr >= constants.LX_MAX_MFEATURE_BIT:
+        raise gdb.GdbError("Sorry, the s390 machine feature number is "
+                           "out of bounds.")
+
+    machine_features = gdb.parse_and_eval("machine_features")
+    bits_per_entry = machine_features[0].type.sizeof * 8
+    entry = machine_features[nr // bits_per_entry]
+    return (entry & (1 << (nr % bits_per_entry))) != 0
+
+
+def s390_machine_has_relocated_lowcore():
+    return s390_machine_feature(constants.LX_MFEATURE_LOWCORE)
+
+
+def s390_lowcore(cpu):
+    if cpu == -1 or cpu == get_current_cpu():
+        if s390_machine_has_relocated_lowcore():
+            lowcore = constants.LX_LOWCORE_ALT_ADDRESS
+        else:
+            lowcore = gdb.Value(0)
+    else:
+        lowcore = gdb.parse_and_eval("lowcore_ptr[{0}]".format(str(cpu)))
+
+    lowcore_ptr_type = gdb.lookup_type("struct lowcore").pointer()
+    return lowcore.cast(lowcore_ptr_type)
Signature · 1 line
2.51.0
author
#2 lore raw

PATCH 2/3 scripts/gdb: add lx_lowcore convenience function on s390

In reply to Jens Remus

lx_lowcore is a convenience function to retrieve the lowcore of the active context or a specific CPU on s390.

---
 scripts/gdb/linux/cpus.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
scripts/gdb/linux/cpus.py +17 -0
index 12bf37d6a4e5..3e17550cd577 100644
@@ -258,3 +258,20 @@ def s390_lowcore(cpu):
 
     lowcore_ptr_type = gdb.lookup_type("struct lowcore").pointer()
     return lowcore.cast(lowcore_ptr_type)
+
+
+class LxLowcoreFunc(gdb.Function):
+    """Return current s390 lowcore.
+
+$lx_lowcore([CPU]): Return the s390 lowcore for the given CPU number.
+If CPU is omitted, the CPU of the current context is used."""
+
+    def __init__(self):
+        super(LxLowcoreFunc, self).__init__("lx_lowcore")
+
+    def invoke(self, cpu=-1):
+        return s390_lowcore(cpu)
+
+
+if constants.LX_CONFIG_S390:
+    LxLowcoreFunc()
Signature · 1 line
2.51.0
author
#3 lore raw

PATCH 3/3 scripts/gdb: add lx_cpu convenience function

In reply to Jens Remus

lx_cpu is a convenience function to retrieve the current CPU number.

---
 scripts/gdb/linux/cpus.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
scripts/gdb/linux/cpus.py +15 -0
index 3e17550cd577..fa05fc30a090 100644
@@ -119,6 +119,21 @@ def each_active_cpu():
         yield cpu
 
 
+class LxCpuFunc(gdb.Function):
+    """Return current CPU number.
+
+$lx_cpu(): Return the current CPU number."""
+
+    def __init__(self):
+        super(LxCpuFunc, self).__init__("lx_cpu")
+
+    def invoke(self):
+        return get_current_cpu()
+
+
+LxCpuFunc()
+
+
 class LxCpus(gdb.Command):
     """List CPU status arrays
 
Signature · 1 line
2.51.0