Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/crash/arch mostly complete basic port of crash(8) t...



details:   https://anonhg.NetBSD.org/src/rev/4a5ef4af5c8d
branches:  trunk
changeset: 937379:4a5ef4af5c8d
user:      mrg <mrg%NetBSD.org@localhost>
date:      Mon Aug 17 04:15:33 2020 +0000

description:
mostly complete basic port of crash(8) to mips.

tested on mipsel and mips64eb.  basic functionality works
on the running kernel, not yet tested on crash dumps.

diffstat:

 sys/arch/mips/include/pcb.h          |    8 +-
 sys/arch/mips/mips/db_trace.c        |  141 ++++++++++++++++++++--------------
 sys/arch/mips/mips/mips_stacktrace.c |   19 ++-
 usr.sbin/crash/Makefile              |    8 +-
 usr.sbin/crash/arch/mips.c           |   73 ++++++++++++++++++
 usr.sbin/crash/crash.c               |    6 +-
 6 files changed, 184 insertions(+), 71 deletions(-)

diffs (truncated from 424 to 300 lines):

diff -r aa3fd5483944 -r 4a5ef4af5c8d sys/arch/mips/include/pcb.h
--- a/sys/arch/mips/include/pcb.h       Mon Aug 17 03:22:13 2020 +0000
+++ b/sys/arch/mips/include/pcb.h       Mon Aug 17 04:15:33 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcb.h,v 1.25 2020/08/17 03:19:35 mrg Exp $     */
+/*     $NetBSD: pcb.h,v 1.26 2020/08/17 04:15:33 mrg Exp $     */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -76,4 +76,10 @@
 #ifdef _KERNEL
 #define        PCB_FSR(pcb)    ((pcb)->pcb_fpregs.r_regs[_R_FSR - _FPBASE])
 #endif
+
+#ifndef _KERNEL
+/* Connect the dots for crash(8). */
+vaddr_t db_mach_addr_cpuswitch(void);
+#endif
+
 #endif /*_MIPS_PCB_H_*/
diff -r aa3fd5483944 -r 4a5ef4af5c8d sys/arch/mips/mips/db_trace.c
--- a/sys/arch/mips/mips/db_trace.c     Mon Aug 17 03:22:13 2020 +0000
+++ b/sys/arch/mips/mips/db_trace.c     Mon Aug 17 04:15:33 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_trace.c,v 1.44 2020/08/15 07:42:07 mrg Exp $        */
+/*     $NetBSD: db_trace.c,v 1.45 2020/08/17 04:15:34 mrg Exp $        */
 
 /*
  * Mach Operating System
@@ -27,9 +27,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.44 2020/08/15 07:42:07 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.45 2020/08/17 04:15:34 mrg Exp $");
 
+#ifdef _KERNEL_OPT
 #include "opt_ddb.h"
+#endif
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -43,6 +45,8 @@
 #include <machine/db_machdep.h>
 #include <machine/locore.h>
 
+#include <ddb/db_access.h>
+#include <ddb/db_access.h>
 #include <ddb/db_interface.h>
 #include <ddb/db_output.h>
 #include <ddb/db_variables.h>
@@ -81,54 +85,54 @@
 #define DBREGS_REG()
 
 const struct db_variable db_regs[] = {
-       { "at", (long *)&ddb_regs.r_regs[_R_AST],  DB_SETF_REGS },
-       { "v0", (long *)&ddb_regs.r_regs[_R_V0],  DB_SETF_REGS },
-       { "v1", (long *)&ddb_regs.r_regs[_R_V1],  DB_SETF_REGS },
-       { "a0", (long *)&ddb_regs.r_regs[_R_A0],  DB_SETF_REGS },
-       { "a1", (long *)&ddb_regs.r_regs[_R_A1],  DB_SETF_REGS },
-       { "a2", (long *)&ddb_regs.r_regs[_R_A2],  DB_SETF_REGS },
-       { "a3", (long *)&ddb_regs.r_regs[_R_A3],  DB_SETF_REGS },
+       { "at", (long *)&ddb_regs.r_regs[_R_AST],  DB_SETF_REGS, NULL },
+       { "v0", (long *)&ddb_regs.r_regs[_R_V0],  DB_SETF_REGS, NULL },
+       { "v1", (long *)&ddb_regs.r_regs[_R_V1],  DB_SETF_REGS, NULL },
+       { "a0", (long *)&ddb_regs.r_regs[_R_A0],  DB_SETF_REGS, NULL },
+       { "a1", (long *)&ddb_regs.r_regs[_R_A1],  DB_SETF_REGS, NULL },
+       { "a2", (long *)&ddb_regs.r_regs[_R_A2],  DB_SETF_REGS, NULL },
+       { "a3", (long *)&ddb_regs.r_regs[_R_A3],  DB_SETF_REGS, NULL },
 #if defined(__mips_n32) || defined(__mips_n64)
-       { "a4", (long *)&ddb_regs.r_regs[_R_A4],  DB_SETF_REGS },
-       { "a5", (long *)&ddb_regs.r_regs[_R_A5],  DB_SETF_REGS },
-       { "a6", (long *)&ddb_regs.r_regs[_R_A6],  DB_SETF_REGS },
-       { "a7", (long *)&ddb_regs.r_regs[_R_A7],  DB_SETF_REGS },
-       { "t0", (long *)&ddb_regs.r_regs[_R_T0],  DB_SETF_REGS },
-       { "t1", (long *)&ddb_regs.r_regs[_R_T1],  DB_SETF_REGS },
-       { "t2", (long *)&ddb_regs.r_regs[_R_T2],  DB_SETF_REGS },
-       { "t3", (long *)&ddb_regs.r_regs[_R_T3],  DB_SETF_REGS },
+       { "a4", (long *)&ddb_regs.r_regs[_R_A4],  DB_SETF_REGS, NULL },
+       { "a5", (long *)&ddb_regs.r_regs[_R_A5],  DB_SETF_REGS, NULL },
+       { "a6", (long *)&ddb_regs.r_regs[_R_A6],  DB_SETF_REGS, NULL },
+       { "a7", (long *)&ddb_regs.r_regs[_R_A7],  DB_SETF_REGS, NULL },
+       { "t0", (long *)&ddb_regs.r_regs[_R_T0],  DB_SETF_REGS, NULL },
+       { "t1", (long *)&ddb_regs.r_regs[_R_T1],  DB_SETF_REGS, NULL },
+       { "t2", (long *)&ddb_regs.r_regs[_R_T2],  DB_SETF_REGS, NULL },
+       { "t3", (long *)&ddb_regs.r_regs[_R_T3],  DB_SETF_REGS, NULL },
 #else
-       { "t0", (long *)&ddb_regs.r_regs[_R_T0],  DB_SETF_REGS },
-       { "t1", (long *)&ddb_regs.r_regs[_R_T1],  DB_SETF_REGS },
-       { "t2", (long *)&ddb_regs.r_regs[_R_T2],  DB_SETF_REGS },
-       { "t3", (long *)&ddb_regs.r_regs[_R_T3],  DB_SETF_REGS },
-       { "t4", (long *)&ddb_regs.r_regs[_R_T4],  DB_SETF_REGS },
-       { "t5", (long *)&ddb_regs.r_regs[_R_T5],  DB_SETF_REGS },
-       { "t6", (long *)&ddb_regs.r_regs[_R_T6],  DB_SETF_REGS },
-       { "t7", (long *)&ddb_regs.r_regs[_R_T7],  DB_SETF_REGS },
+       { "t0", (long *)&ddb_regs.r_regs[_R_T0],  DB_SETF_REGS, NULL },
+       { "t1", (long *)&ddb_regs.r_regs[_R_T1],  DB_SETF_REGS, NULL },
+       { "t2", (long *)&ddb_regs.r_regs[_R_T2],  DB_SETF_REGS, NULL },
+       { "t3", (long *)&ddb_regs.r_regs[_R_T3],  DB_SETF_REGS, NULL },
+       { "t4", (long *)&ddb_regs.r_regs[_R_T4],  DB_SETF_REGS, NULL },
+       { "t5", (long *)&ddb_regs.r_regs[_R_T5],  DB_SETF_REGS, NULL },
+       { "t6", (long *)&ddb_regs.r_regs[_R_T6],  DB_SETF_REGS, NULL },
+       { "t7", (long *)&ddb_regs.r_regs[_R_T7],  DB_SETF_REGS, NULL },
 #endif /* __mips_n32 || __mips_n64 */
-       { "s0", (long *)&ddb_regs.r_regs[_R_S0],  DB_SETF_REGS },
-       { "s1", (long *)&ddb_regs.r_regs[_R_S1],  DB_SETF_REGS },
-       { "s2", (long *)&ddb_regs.r_regs[_R_S2],  DB_SETF_REGS },
-       { "s3", (long *)&ddb_regs.r_regs[_R_S3],  DB_SETF_REGS },
-       { "s4", (long *)&ddb_regs.r_regs[_R_S4],  DB_SETF_REGS },
-       { "s5", (long *)&ddb_regs.r_regs[_R_S5],  DB_SETF_REGS },
-       { "s6", (long *)&ddb_regs.r_regs[_R_S6],  DB_SETF_REGS },
-       { "s7", (long *)&ddb_regs.r_regs[_R_S7],  DB_SETF_REGS },
-       { "t8", (long *)&ddb_regs.r_regs[_R_T8],  DB_SETF_REGS },
-       { "t9", (long *)&ddb_regs.r_regs[_R_T9],  DB_SETF_REGS },
-       { "k0", (long *)&ddb_regs.r_regs[_R_K0],  DB_SETF_REGS },
-       { "k1", (long *)&ddb_regs.r_regs[_R_K1],  DB_SETF_REGS },
-       { "gp", (long *)&ddb_regs.r_regs[_R_GP],  DB_SETF_REGS },
-       { "sp", (long *)&ddb_regs.r_regs[_R_SP],  DB_SETF_REGS },
-       { "fp", (long *)&ddb_regs.r_regs[_R_S8],  DB_SETF_REGS },/* frame ptr */
-       { "ra", (long *)&ddb_regs.r_regs[_R_RA],  DB_SETF_REGS },
-       { "sr", (long *)&ddb_regs.r_regs[_R_SR],  DB_SETF_REGS },
-       { "mdlo",(long *)&ddb_regs.r_regs[_R_MULLO],  DB_SETF_REGS },
-       { "mdhi",(long *)&ddb_regs.r_regs[_R_MULHI],  DB_SETF_REGS },
-       { "bad", (long *)&ddb_regs.r_regs[_R_BADVADDR], DB_SETF_REGS },
-       { "cs", (long *)&ddb_regs.r_regs[_R_CAUSE],  DB_SETF_REGS },
-       { "pc", (long *)&ddb_regs.r_regs[_R_PC],  DB_SETF_REGS },
+       { "s0", (long *)&ddb_regs.r_regs[_R_S0],  DB_SETF_REGS, NULL },
+       { "s1", (long *)&ddb_regs.r_regs[_R_S1],  DB_SETF_REGS, NULL },
+       { "s2", (long *)&ddb_regs.r_regs[_R_S2],  DB_SETF_REGS, NULL },
+       { "s3", (long *)&ddb_regs.r_regs[_R_S3],  DB_SETF_REGS, NULL },
+       { "s4", (long *)&ddb_regs.r_regs[_R_S4],  DB_SETF_REGS, NULL },
+       { "s5", (long *)&ddb_regs.r_regs[_R_S5],  DB_SETF_REGS, NULL },
+       { "s6", (long *)&ddb_regs.r_regs[_R_S6],  DB_SETF_REGS, NULL },
+       { "s7", (long *)&ddb_regs.r_regs[_R_S7],  DB_SETF_REGS, NULL },
+       { "t8", (long *)&ddb_regs.r_regs[_R_T8],  DB_SETF_REGS, NULL },
+       { "t9", (long *)&ddb_regs.r_regs[_R_T9],  DB_SETF_REGS, NULL },
+       { "k0", (long *)&ddb_regs.r_regs[_R_K0],  DB_SETF_REGS, NULL },
+       { "k1", (long *)&ddb_regs.r_regs[_R_K1],  DB_SETF_REGS, NULL },
+       { "gp", (long *)&ddb_regs.r_regs[_R_GP],  DB_SETF_REGS, NULL },
+       { "sp", (long *)&ddb_regs.r_regs[_R_SP],  DB_SETF_REGS, NULL },
+       { "fp", (long *)&ddb_regs.r_regs[_R_S8],  DB_SETF_REGS, NULL },/* frame ptr */
+       { "ra", (long *)&ddb_regs.r_regs[_R_RA],  DB_SETF_REGS, NULL },
+       { "sr", (long *)&ddb_regs.r_regs[_R_SR],  DB_SETF_REGS, NULL },
+       { "mdlo",(long *)&ddb_regs.r_regs[_R_MULLO],  DB_SETF_REGS, NULL },
+       { "mdhi",(long *)&ddb_regs.r_regs[_R_MULHI],  DB_SETF_REGS, NULL },
+       { "bad", (long *)&ddb_regs.r_regs[_R_BADVADDR], DB_SETF_REGS, NULL },
+       { "cs", (long *)&ddb_regs.r_regs[_R_CAUSE],  DB_SETF_REGS, NULL },
+       { "pc", (long *)&ddb_regs.r_regs[_R_PC],  DB_SETF_REGS, NULL },
 };
 const struct db_variable * const db_eregs = db_regs + __arraycount(db_regs);
 
@@ -138,11 +142,15 @@
 {
 #ifndef DDB_TRACE
        struct pcb *pcb;
-       struct proc *p;
-       struct lwp *l;
+       struct proc p;
+       struct lwp l;
        const char *cp = modif;
        char c;
        bool lwpaddr = false;
+       vaddr_t pc, sp, s8, ra;
+#ifndef _KERNEL
+       mips_label_t label;
+#endif
 
        if (!have_addr) {
                struct reg * regs = &ddb_regs;
@@ -166,28 +174,43 @@
        }
 
        if (lwpaddr) {
-               l = (struct lwp *)(intptr_t)addr;
-               (*pr)("pid %d.%d ", l->l_proc->p_pid, l->l_lid);
+               db_read_bytes(addr, sizeof(l), (char *)&l);
+               db_read_bytes((db_addr_t)l.l_proc, sizeof(p), (char *)&p);
+               (*pr)("pid %d.%d ", p.p_pid, l.l_lid);
        } else {
                /* "trace/t" */
 
                (*pr)("pid %d ", (int)addr);
-               p = proc_find_raw(addr);
-               if (p == NULL) {
+#ifdef _KERNEL
+               struct proc *p2 = proc_find_raw(addr);
+               if (p2 == NULL) {
                        (*pr)("not found\n");
                        return;
                }       
-               l = LIST_FIRST(&p->p_lwps); /* XXX NJWLWP */
+               l = *LIST_FIRST(&p2->p_lwps); /* XXX NJWLWP */
+#else
+               (*pr)("no proc_find_raw() in crash\n");
+               return;
+#endif
        }
 
-       pcb = lwp_getpcb(l);
+       pcb = lwp_getpcb(&l);
        (*pr)("at %p\n", pcb);
 
+#ifdef _KERNEL
+       pc = (vaddr_t)cpu_switchto;
+       sp = pcb->pcb_context.val[_L_SP];
+       s8 = pcb->pcb_context.val[_L_S8];
+       ra = pcb->pcb_context.val[_L_RA];
+#else
+       pc = db_mach_addr_cpuswitch();
+       db_read_bytes((db_addr_t)&pcb->pcb_context, sizeof(label), (char *)&label);
+       sp = label.val[_L_SP];
+       s8 = label.val[_L_S8];
+       ra = label.val[_L_RA];
+#endif
        stacktrace_subr(0,0,0,0,        /* no args known */
-                       (vaddr_t)cpu_switchto,
-                       pcb->pcb_context.val[_L_SP],
-                       pcb->pcb_context.val[_L_S8],
-                       pcb->pcb_context.val[_L_RA],
+                       pc, sp, s8, ra,
                        pr);
 #else
 /*
diff -r aa3fd5483944 -r 4a5ef4af5c8d sys/arch/mips/mips/mips_stacktrace.c
--- a/sys/arch/mips/mips/mips_stacktrace.c      Mon Aug 17 03:22:13 2020 +0000
+++ b/sys/arch/mips/mips/mips_stacktrace.c      Mon Aug 17 04:15:33 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mips_stacktrace.c,v 1.2 2020/08/17 03:19:35 mrg Exp $  */
+/*     $NetBSD: mips_stacktrace.c,v 1.3 2020/08/17 04:15:34 mrg Exp $  */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mips_stacktrace.c,v 1.2 2020/08/17 03:19:35 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mips_stacktrace.c,v 1.3 2020/08/17 04:15:34 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -55,11 +55,16 @@
 #include <mips/mips_opcode.h>
 #include <mips/stacktrace.h>
 
+#if defined(_KMEMUSER) && !defined(DDB)
+#define DDB 1
+#endif
+
 #ifdef DDB
 #include <machine/db_machdep.h>
 #include <ddb/db_sym.h>
 #endif
 #include <ddb/db_user.h>
+#include <ddb/db_access.h>
 
 #ifdef KGDB
 #include <sys/kgdb.h>
@@ -196,7 +201,7 @@
                printf("kdbpeek: NULL\n");
                return false;
        } else {
-               *valp = *(unsigned *)addr;
+               db_read_bytes((db_addr_t)addr, sizeof(unsigned), (char *)valp);
                return true;
        }
 }
@@ -204,7 +209,7 @@
 static mips_reg_t
 kdbrpeek(vaddr_t addr, size_t n)
 {
-       mips_reg_t rc;
+       mips_reg_t rc = 0;
 
        if (addr & (n - 1)) {
                printf("kdbrpeek: unaligned address %#"PRIxVADDR"\n", addr);
@@ -212,15 +217,15 @@
                /* We might have been called from DDB, so do not go there. */
                stacktrace();
 #endif
-               rc = -1 ;
+               rc = -1;
        } else if (addr == 0) {
                printf("kdbrpeek: NULL\n");
                rc = 0xdeadfeed;
        } else {
                if (sizeof(mips_reg_t) == 8 && n == 8)
-                       rc = *(int64_t *)addr;
+                       db_read_bytes((db_addr_t)addr, sizeof(int64_t), (char *)&rc);
                else
-                       rc = *(int32_t *)addr;
+                       db_read_bytes((db_addr_t)addr, sizeof(int32_t), (char *)&rc);
        }
        return rc;
 }
diff -r aa3fd5483944 -r 4a5ef4af5c8d usr.sbin/crash/Makefile
--- a/usr.sbin/crash/Makefile   Mon Aug 17 03:22:13 2020 +0000
+++ b/usr.sbin/crash/Makefile   Mon Aug 17 04:15:33 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.44 2020/03/09 05:10:19 rin Exp $



Home | Main Index | Thread Index | Old Index