[Pdbg] [PATCH 10/10] pdbg: add basic kernel stack trace to 'regs' command

Nicholas Piggin npiggin at gmail.com
Thu May 3 16:27:02 AEST 2018


NIA   : 0xc000000000984604
CFAR  : 0xc00000000098461c
MSR   : 0x9000000000009033
LR    : 0xc0000000009846e4
CTR   : 0xc000000000984560
TAR   : 0x0000000000000000
CR    : 0x24004424
XER   : 0x00000000
GPRS  :
 0xc0000000009845a8 0xc000000006e07d90 0xc000000001306000 0x0000000000000000
 0x0000000000000001 0x0000000000000000 0x0000000000000009 0x0000000000000808
 0x0000000000000000 0x00000565ba95ebcd 0xc000000006e04000 0x822ca467ef411b43
 0xc000000000984560 0xc000000ffffe0200 0xc000000006e07f90 0x0000000000000000
 0x0000000000000000 0xc000000000029d8c 0xc000000000043630 0xc000000000fa5410
 0x0000000000000800 0xc0000000013481f4 0x0000000000000026 0x0000000000000000
 0x0000000000000001 0x0000000000000000 0x0000000000000000 0x0000000000000000
 0xc000000001266ba0 0xc000000ff57a1d58 0x0000000000000000 0x00000565ba95f7b5
LPCR  : 0x0040400001d2f012
PTCR  : 0x0040400001d2f012
LPIDR : 0x0000000000000000
PIDR  : 0x0000000000080081
HFSCR : 0x000000000000059f
HDSISR: 0x00000000
HDAR  : 0x0000000000000000
HSRR0 : 0xc000000000984618
HSRR1 : 0x9000000000009033
HDEC  : 0xfffffaa5941c2f0a
HSPRG0: 0xc000000ffffe0200
HSPRG1: 0xc000000ffffe0200
FSCR  : 0x0000000000000184
DSISR : 0x00000000
DAR   : 0x0000000000000000
SRR0  : 0xc000000000984608
SRR1  : 0x9000000000009033
DEC   : 0xfffffffee1c2b8cf
TB    : 0x00000566dd7f0784
SPRG0 : 0x0000000000000000
SPRG1 : 0x0000000000000000
SPRG2 : 0x0000000000000000
SPRG3 : 0x0000000000000000
PPR   : 0x0004000000000000
STACK:
 0xc000000006e07dd0 0xc00000000098170c
 0xc000000006e07e40 0xc00000000013e60c
 0xc000000006e07e60 0xc00000000013e920
 0xc000000006e07ed0 0xc00000000013eeb8
 0xc000000006e07f00 0xc000000000045bc4
 0xc000000006e07f90 0xc00000000000af70

Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
 src/mem.c    | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/mem.h    |  2 ++
 src/thread.c |  8 +++++++-
 3 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/src/mem.c b/src/mem.c
index 4f12dcf..f8346f4 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -77,6 +77,57 @@ static int putmem(uint64_t addr)
 	return rc;
 }
 
+static bool is_real_address(struct thread_regs *regs, uint64_t addr)
+{
+	return true;
+	if ((addr & 0xf000000000000000ULL) == 0xc000000000000000ULL)
+		return true;
+	return false;
+}
+
+static int load8(struct pdbg_target *target, uint64_t addr, uint64_t *value)
+{
+	if (adu_getmem(target, addr, (uint8_t *)value, 8)) {
+		PR_ERROR("Unable to read memory address=%016" PRIx64 ".\n", addr);
+		return 0;
+	}
+
+	return 1;
+}
+
+int dump_stack(struct thread_regs *regs)
+{
+	struct pdbg_target *target;
+	uint64_t sp = regs->gprs[1];
+	uint64_t pc;
+
+	pdbg_for_each_class_target("adu", target) {
+		if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED)
+			continue;
+		break;
+	}
+
+	printf("STACK:\n");
+	if (!target)
+		PR_ERROR("Unable to read memory (no ADU found)\n");
+
+	if (sp && is_real_address(regs, sp)) {
+		if (!load8(target, sp, &sp))
+			return 1;
+		while (sp && is_real_address(regs, sp)) {
+			if (!load8(target, sp + 16, &pc))
+				return 1;
+
+			printf(" 0x%016" PRIx64 " 0x%16" PRIx64 "\n", sp, pc);
+
+			if (!load8(target, sp, &sp))
+				return 1;
+		}
+	}
+
+	return 0;
+}
+
 int handle_mem(int optind, int argc, char *argv[])
 {
 	uint64_t addr;
diff --git a/src/mem.h b/src/mem.h
index 6148de5..42bdc04 100644
--- a/src/mem.h
+++ b/src/mem.h
@@ -14,5 +14,7 @@
  * limitations under the License.
  */
 #include <inttypes.h>
+#include <libpdbg.h>
 
+int dump_stack(struct thread_regs *regs);
 int handle_mem(int optind, int argc, char *argv[]);
diff --git a/src/thread.c b/src/thread.c
index a6e096b..0e4627f 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -24,6 +24,7 @@
 #include <operations.h>
 
 #include "main.h"
+#include "mem.h"
 
 static int print_thread_status(struct pdbg_target *target, uint32_t index, uint64_t *status, uint64_t *unused1)
 {
@@ -131,7 +132,12 @@ static int state_thread(struct pdbg_target *thread_target, uint32_t index, uint6
 {
 	struct thread_regs regs;
 
-	return ram_state_thread(thread_target, &regs) ? 0 : 1;
+	if (ram_state_thread(thread_target, &regs))
+		return 0;
+
+	dump_stack(&regs);
+
+	return 1;
 }
 
 int thread_start(int optind, int argc, char *argv[])
-- 
2.17.0



More information about the Pdbg mailing list