Module Name: src Committed By: bouyer Date: Thu Feb 8 19:16:24 UTC 2018
Modified Files: src/sys/arch/mips/include: locore.h src/sys/arch/mips/mips: db_interface.c trap.c Log Message: Allow kdbpeek() to return failure. If it does, stop the stack trace. Prevents an infinite loop in ddb if something goes wrong. To generate a diff of this commit: cvs rdiff -u -r1.102 -r1.103 src/sys/arch/mips/include/locore.h cvs rdiff -u -r1.79 -r1.80 src/sys/arch/mips/mips/db_interface.c cvs rdiff -u -r1.245 -r1.246 src/sys/arch/mips/mips/trap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/mips/include/locore.h diff -u src/sys/arch/mips/include/locore.h:1.102 src/sys/arch/mips/include/locore.h:1.103 --- src/sys/arch/mips/include/locore.h:1.102 Thu Mar 16 16:13:20 2017 +++ src/sys/arch/mips/include/locore.h Thu Feb 8 19:16:24 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.h,v 1.102 2017/03/16 16:13:20 chs Exp $ */ +/* $NetBSD: locore.h,v 1.103 2018/02/08 19:16:24 bouyer Exp $ */ /* * This file should not be included by MI code!!! @@ -723,7 +723,7 @@ int ustore_uint32_isync(void *, uint32_t /* trap.c */ void netintr(void); -int kdbpeek(vaddr_t); +bool kdbpeek(vaddr_t, int *); /* mips_dsp.c */ void dsp_init(void); Index: src/sys/arch/mips/mips/db_interface.c diff -u src/sys/arch/mips/mips/db_interface.c:1.79 src/sys/arch/mips/mips/db_interface.c:1.80 --- src/sys/arch/mips/mips/db_interface.c:1.79 Mon Jul 11 16:15:36 2016 +++ src/sys/arch/mips/mips/db_interface.c Thu Feb 8 19:16:24 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: db_interface.c,v 1.79 2016/07/11 16:15:36 matt Exp $ */ +/* $NetBSD: db_interface.c,v 1.80 2018/02/08 19:16:24 bouyer Exp $ */ /* * Mach Operating System @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.79 2016/07/11 16:15:36 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.80 2018/02/08 19:16:24 bouyer Exp $"); #include "opt_multiprocessor.h" #include "opt_cputype.h" /* which mips CPUs do we support? */ @@ -96,13 +96,14 @@ paddr_t kvtophys(vaddr_t); CTASSERT(sizeof(ddb_regs) == sizeof(struct reg)); #ifdef DDB_TRACE -int -kdbpeek(vaddr_t addr) +bool +kdbpeek(vaddr_t addr, int *valp) { if (addr == 0 || (addr & 3)) - return 0; - return *(int *)addr; + return false; + *valp = *(int *)addr; + return true; } #endif Index: src/sys/arch/mips/mips/trap.c diff -u src/sys/arch/mips/mips/trap.c:1.245 src/sys/arch/mips/mips/trap.c:1.246 --- src/sys/arch/mips/mips/trap.c:1.245 Fri Dec 22 22:59:25 2017 +++ src/sys/arch/mips/mips/trap.c Thu Feb 8 19:16:24 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.245 2017/12/22 22:59:25 maya Exp $ */ +/* $NetBSD: trap.c,v 1.246 2018/02/08 19:16:24 bouyer Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -39,7 +39,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.245 2017/12/22 22:59:25 maya Exp $"); +__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.246 2018/02/08 19:16:24 bouyer Exp $"); #include "opt_cputype.h" /* which mips CPU levels do we support? */ #include "opt_ddb.h" @@ -748,23 +748,20 @@ mips_singlestep(struct lwp *l) #if defined(DEBUG) || defined(DDB) || defined(KGDB) || defined(geo) mips_reg_t kdbrpeek(vaddr_t, size_t); -int -kdbpeek(vaddr_t addr) +bool +kdbpeek(vaddr_t addr, int *valp) { - int rc; - if (addr & 3) { printf("kdbpeek: unaligned address %#"PRIxVADDR"\n", addr); /* We might have been called from DDB, so do not go there. */ - stacktrace(); - rc = -1 ; + return false; } else if (addr == 0) { printf("kdbpeek: NULL\n"); - rc = 0xdeadfeed; + return false; } else { - rc = *(int *)addr; + *valp = *(int *)addr; + return true; } - return rc; } mips_reg_t @@ -909,7 +906,8 @@ loop: sym = db_search_symbol(pc, DB_STGY_ANY, &diff); if (sym != DB_SYM_NULL && diff == 0) { /* check func(foo) __attribute__((__noreturn__)) case */ - instr = kdbpeek(pc - 2 * sizeof(int)); + if (!kdbpeek(pc - 2 * sizeof(int), &instr)) + return; i.word = instr; if (i.JType.op == OP_JAL) { sym = db_search_symbol(pc - sizeof(int), @@ -937,7 +935,8 @@ loop: va -= sizeof(int); if (va <= (vaddr_t)verylocore) goto finish; - instr = kdbpeek(va); + if (!kdbpeek(va, &instr)) + return; if (instr == MIPS_ERET) goto mips3_eret; } while (instr != MIPS_JR_RA && instr != MIPS_JR_K0); @@ -946,8 +945,12 @@ loop: mips3_eret: va += sizeof(int); /* skip over nulls which might separate .o files */ - while ((instr = kdbpeek(va)) == 0) + instr = 0; + while (instr == 0) { + if (!kdbpeek(va, &instr)) + return; va += sizeof(int); + } #endif subr = va; @@ -961,7 +964,8 @@ mips3_eret: /* stop if hit our current position */ if (va >= pc) break; - instr = kdbpeek(va); + if (!kdbpeek(va, &instr)) + return; i.word = instr; switch (i.JType.op) { case OP_SPECIAL: