Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/aarch64 use panic() instead of some printf to show ...
details: https://anonhg.NetBSD.org/src/rev/ef09bfd7d650
branches: trunk
changeset: 320735:ef09bfd7d650
user: ryo <ryo%NetBSD.org@localhost>
date: Tue Jul 17 10:07:49 2018 +0000
description:
use panic() instead of some printf to show fault status.
useful for ddb "show panic" command.
diffstat:
sys/arch/aarch64/aarch64/db_disasm.c | 61 +++++++++++++++++++++++++++++++++-
sys/arch/aarch64/aarch64/disasm.c | 9 ++++-
sys/arch/aarch64/aarch64/fault.c | 51 ++++++++++++++++++++--------
sys/arch/aarch64/include/db_machdep.h | 6 +--
4 files changed, 104 insertions(+), 23 deletions(-)
diffs (232 lines):
diff -r 902dcb45b6b3 -r ef09bfd7d650 sys/arch/aarch64/aarch64/db_disasm.c
--- a/sys/arch/aarch64/aarch64/db_disasm.c Tue Jul 17 10:01:59 2018 +0000
+++ b/sys/arch/aarch64/aarch64/db_disasm.c Tue Jul 17 10:07:49 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: db_disasm.c,v 1.2 2018/04/01 04:35:03 ryo Exp $ */
+/* $NetBSD: db_disasm.c,v 1.3 2018/07/17 10:07:49 ryo Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.2 2018/04/01 04:35:03 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.3 2018/07/17 10:07:49 ryo Exp $");
#include <sys/param.h>
#include <machine/db_machdep.h>
@@ -63,3 +63,60 @@
{
return disasm(&db_disasm_interface, loc);
}
+
+
+static char *strdisasm_ptr;
+static char strdisasm_buf[256];
+
+static uint32_t
+strdisasm_readword(uintptr_t address)
+{
+ return *(uint32_t *)address;
+}
+
+static void
+strdisasm_printf(const char *fmt, ...)
+{
+ va_list ap;
+ int len;
+
+ /* calculation spaces to append a string */
+ len = strdisasm_buf + sizeof(strdisasm_buf) - strdisasm_ptr;
+
+ va_start(ap, fmt);
+ len = vsnprintf(strdisasm_ptr, len, fmt, ap);
+ va_end(ap);
+
+ strdisasm_ptr += len;
+}
+
+static void
+strdisasm_printaddr(uintptr_t address)
+{
+ strdisasm_printf("0x%lx", address);
+}
+
+static const disasm_interface_t strdisasm_interface = {
+ .di_readword = strdisasm_readword,
+ .di_printaddr = strdisasm_printaddr,
+ .di_printf = strdisasm_printf
+};
+
+const char *
+strdisasm(vaddr_t pc)
+{
+ char *p;
+
+ strdisasm_ptr = strdisasm_buf;
+ disasm(&strdisasm_interface, (db_addr_t)pc);
+
+ /* replace tab to space, and chomp '\n' */
+ for (p = strdisasm_buf; *p != '\0'; p++) {
+ if (*p == '\t')
+ *p = ' ';
+ }
+ if ((p > strdisasm_buf) && (p[-1] == '\n'))
+ p[-1] = '\0';
+
+ return strdisasm_buf;
+}
diff -r 902dcb45b6b3 -r ef09bfd7d650 sys/arch/aarch64/aarch64/disasm.c
--- a/sys/arch/aarch64/aarch64/disasm.c Tue Jul 17 10:01:59 2018 +0000
+++ b/sys/arch/aarch64/aarch64/disasm.c Tue Jul 17 10:07:49 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: disasm.c,v 1.2 2018/06/14 08:27:10 ryo Exp $ */
+/* $NetBSD: disasm.c,v 1.3 2018/07/17 10:07:49 ryo Exp $ */
/*
* Copyright (c) 2018 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: disasm.c,v 1.2 2018/06/14 08:27:10 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: disasm.c,v 1.3 2018/07/17 10:07:49 ryo Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -708,8 +708,13 @@
return SHIFTOP4(shift, "lsl", "lsr", "asr", "ror");
}
+#ifdef DISASM_WITH_COMMENT
#define UNDEFINED(pc, insn, comment) \
PRINTF(".insn\t0x%08x\t# %s\n", insn, comment);
+#else
+#define UNDEFINED(pc, insn, comment) \
+ PRINTF(".insn\t0x%08x\n", insn);
+#endif
static void
extendreg_common(const disasm_interface_t *di, uint64_t pc, uint32_t insn,
diff -r 902dcb45b6b3 -r ef09bfd7d650 sys/arch/aarch64/aarch64/fault.c
--- a/sys/arch/aarch64/aarch64/fault.c Tue Jul 17 10:01:59 2018 +0000
+++ b/sys/arch/aarch64/aarch64/fault.c Tue Jul 17 10:07:49 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fault.c,v 1.2 2018/07/17 00:31:46 christos Exp $ */
+/* $NetBSD: fault.c,v 1.3 2018/07/17 10:07:49 ryo Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fault.c,v 1.2 2018/07/17 00:31:46 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fault.c,v 1.3 2018/07/17 10:07:49 ryo Exp $");
#include "opt_ddb.h"
#include "opt_uvmhist.h"
@@ -128,11 +128,12 @@
vaddr_t va;
uint32_t esr, fsc, rw;
vm_prot_t ftype;
- int error = 0;
+ int error = 0, len;
const bool user = (__SHIFTOUT(tf->tf_spsr, SPSR_M) == SPSR_M_EL0T) ?
true : false;
bool fatalabort;
const char *faultstr;
+ static char panicinfo[256];
UVMHIST_FUNC(__func__);
UVMHIST_CALLED(pmaphist);
@@ -294,36 +295,56 @@
}
/*
- * fatal abort. dump trapframe and panic
+ * fatal abort. analyze fault status code to show by panic()
*/
- printf("Trap: %s:", trapname);
+ len = snprintf(panicinfo, sizeof(panicinfo), "Trap: %s:", trapname);
if ((fsc >= __arraycount(fault_status_code)) ||
((faultstr = fault_status_code[fsc]) == NULL))
- printf(" unknown fault status 0x%x ", fsc);
+ len += snprintf(panicinfo + len, sizeof(panicinfo) - len,
+ " unknown fault status 0x%x ", fsc);
else
- printf(" %s", faultstr);
+ len += snprintf(panicinfo + len, sizeof(panicinfo) - len,
+ " %s", faultstr);
if ((__SHIFTOUT(esr, ESR_EC) == ESR_EC_DATA_ABT_EL1) ||
(__SHIFTOUT(esr, ESR_EC) == ESR_EC_DATA_ABT_EL0))
- printf(" with %s access", (rw == 0) ? "read" : "write");
+ len += snprintf(panicinfo + len, sizeof(panicinfo) - len,
+ " with %s access", (rw == 0) ? "read" : "write");
+
+ len += snprintf(panicinfo + len, sizeof(panicinfo) - len,
+ " for %016"PRIxREGISTER, tf->tf_far);
if (__SHIFTOUT(esr, ESR_ISS_DATAABORT_EA) != 0)
- printf(", External abort");
+ len += snprintf(panicinfo + len, sizeof(panicinfo) - len,
+ ", External abort");
if (__SHIFTOUT(esr, ESR_ISS_DATAABORT_S1PTW) != 0)
- printf(", State 2 Fault");
+ len += snprintf(panicinfo + len, sizeof(panicinfo) - len,
+ ", State 2 Fault");
+
+ len += snprintf(panicinfo + len, sizeof(panicinfo) - len,
+ ": pc %016"PRIxREGISTER, tf->tf_pc);
- printf("\n");
+ len += snprintf(panicinfo + len, sizeof(panicinfo) - len,
+ ": opcode %08x", *(uint32_t *)tf->tf_pc);
+
#ifdef DDB
- dump_trapframe(tf, printf);
+ /* ...and disassemble the instruction */
+ len += snprintf(panicinfo + len, sizeof(panicinfo) - len,
+ ": %s", strdisasm(tf->tf_pc));
#endif
-#ifdef DEBUG_DDB_ON_USERFAULT
- if (user)
+ if (user) {
+#if defined(DEBUG_DDB_ON_USERFAULT) && defined(DDB)
+ printf("%s\n", panicinfo);
Debugger();
+#elif defined(DEBUG_DUMP_ON_USERFAULT)
+ printf("%s\n", panicinfo);
+ dump_trapframe(tf, printf);
#endif
+ }
if (!user)
- panic("Fatal abort: %s", trapname);
+ panic("%s\n", panicinfo);
}
diff -r 902dcb45b6b3 -r ef09bfd7d650 sys/arch/aarch64/include/db_machdep.h
--- a/sys/arch/aarch64/include/db_machdep.h Tue Jul 17 10:01:59 2018 +0000
+++ b/sys/arch/aarch64/include/db_machdep.h Tue Jul 17 10:07:49 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: db_machdep.h,v 1.5 2018/04/28 17:42:07 ryo Exp $ */
+/* $NetBSD: db_machdep.h,v 1.6 2018/07/17 10:07:49 ryo Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -201,9 +201,7 @@
#define DB_MACHINE_COMMANDS
void dump_trapframe(struct trapframe *, void (*)(const char *, ...));
-
-
-
+const char *strdisasm(vaddr_t);
void db_machdep_init(void);
/* hardware breakpoint/watchpoint functions */
Home |
Main Index |
Thread Index |
Old Index