linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/02] scripts/gdb/cpus: Add support for get_current_task for powerpc book3s64
@ 2025-08-30  3:45 Ritesh Harjani (IBM)
  2025-08-30  3:45 ` [PATCH 02/02] scripts/gdb/mm: Add support " Ritesh Harjani (IBM)
  2025-10-30  4:33 ` [PATCH 01/02] scripts/gdb/cpus: Add support for get_current_task " Ritesh Harjani
  0 siblings, 2 replies; 5+ messages in thread
From: Ritesh Harjani (IBM) @ 2025-08-30  3:45 UTC (permalink / raw)
  To: Jan Kiszka, Kieran Bingham
  Cc: linux-kernel, linuxppc-dev, Ritesh Harjani (IBM)

This adds support to query p $lx_current() for ppc64 book3s64.
This allows us to utilize gdb scripts functions like:

function lx_current
function lx_task_by_pid
function lx_thread_info
function lx_thread_info_by_pid

e.g.
(gdb) p $lx_current()->comm
$1 = "swapper\000\000\000\000\000\000\000\00

Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
---
 scripts/gdb/linux/constants.py.in |  1 +
 scripts/gdb/linux/cpus.py         | 17 ++++++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in
index c3886739a028..154db10fe94a 100644
--- a/scripts/gdb/linux/constants.py.in
+++ b/scripts/gdb/linux/constants.py.in
@@ -152,6 +152,7 @@ if IS_BUILTIN(CONFIG_ARM64):
     LX_VALUE(CONFIG_ARM64_VA_BITS)
     LX_VALUE(CONFIG_PAGE_SHIFT)
     LX_VALUE(CONFIG_ARCH_FORCE_MAX_ORDER)
+LX_CONFIG(CONFIG_PPC_BOOK3S_64)
 LX_CONFIG(CONFIG_SPARSEMEM)
 LX_CONFIG(CONFIG_SPARSEMEM_EXTREME)
 LX_CONFIG(CONFIG_SPARSEMEM_VMEMMAP)
diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
index 6edf4ef61636..c250de14ac19 100644
--- a/scripts/gdb/linux/cpus.py
+++ b/scripts/gdb/linux/cpus.py
@@ -13,7 +13,7 @@

 import gdb

-from linux import tasks, utils
+from linux import tasks, utils, constants


 task_type = utils.CachedType("struct task_struct")
@@ -207,6 +207,21 @@ def get_current_task(cpu):
             current_task = scratch_reg.cast(task_ptr_type)

         return current_task.dereference()
+    elif utils.is_target_arch("powerpc"):
+        if not constants.LX_CONFIG_PPC_BOOK3S_64:
+            raise gdb.GdbError('For now only supported for BOOK3S_64')
+
+        msr = gdb.parse_and_eval("(unsigned long)$msr")
+        # PR (Problem State) should be 0 for kernel mode
+        in_kernel = msr & (0x1 << 14) == 0
+        if in_kernel:
+            paca_ptr_type = gdb.lookup_type("struct paca_struct").pointer()
+            paca_ptr = gdb.parse_and_eval("$r13")
+            paca = paca_ptr.cast(paca_ptr_type).dereference()
+            return paca["__current"].cast(task_ptr_type).dereference()
+        else:
+            raise gdb.GdbError("Sorry, obtaining the current task is not allowed "
+                               "while running in userspace (Problem State)")
     else:
         raise gdb.GdbError("Sorry, obtaining the current task is not yet "
                            "supported with this arch")
--
2.50.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-11-03  4:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-30  3:45 [PATCH 01/02] scripts/gdb/cpus: Add support for get_current_task for powerpc book3s64 Ritesh Harjani (IBM)
2025-08-30  3:45 ` [PATCH 02/02] scripts/gdb/mm: Add support " Ritesh Harjani (IBM)
2025-10-30 16:26   ` Jan Kiszka
2025-11-03  4:19     ` Ritesh Harjani
2025-10-30  4:33 ` [PATCH 01/02] scripts/gdb/cpus: Add support for get_current_task " Ritesh Harjani

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).