Mon Mar 29 03:09:42 2021 UTC ()
Expose kdbpeek() and kdbrpeek() for dtrace.


(simonb)
diff -r1.36 -r1.37 src/sys/arch/mips/include/db_machdep.h
diff -r1.7 -r1.8 src/sys/arch/mips/mips/mips_stacktrace.c

cvs diff -r1.36 -r1.37 src/sys/arch/mips/include/db_machdep.h (expand / switch to unified diff)

--- src/sys/arch/mips/include/db_machdep.h 2021/03/29 03:07:33 1.36
+++ src/sys/arch/mips/include/db_machdep.h 2021/03/29 03:09:41 1.37
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: db_machdep.h,v 1.36 2021/03/29 03:07:33 simonb Exp $ */ 1/* $NetBSD: db_machdep.h,v 1.37 2021/03/29 03:09:41 simonb Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 Jonathan Stone (hereinafter referred to as the author) 4 * Copyright (c) 1997 Jonathan Stone (hereinafter referred to as the author)
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -89,26 +89,32 @@ db_addr_t db_disasm_insn(int insn, db_ad @@ -89,26 +89,32 @@ db_addr_t db_disasm_insn(int insn, db_ad
89 89
90/* 90/*
91 * Entrypoints to DDB for kernel, keyboard drivers, init hook 91 * Entrypoints to DDB for kernel, keyboard drivers, init hook
92 */ 92 */
93void kdb_kbd_trap(db_regs_t *); 93void kdb_kbd_trap(db_regs_t *);
94int kdb_trap(int type, struct reg *); 94int kdb_trap(int type, struct reg *);
95 95
96static inline void 96static inline void
97db_set_ddb_regs(int type, struct reg *regs) 97db_set_ddb_regs(int type, struct reg *regs)
98{ 98{
99 ddb_regs = *regs; 99 ddb_regs = *regs;
100} 100}
101 101
 102/*
 103 * Helper functions for fetching 32-bit and 64-bit kernel memory.
 104 */
 105bool kdbpeek(vaddr_t, unsigned *);
 106mips_reg_t kdbrpeek(vaddr_t addr, size_t n);
 107
102 108
103/* 109/*
104 * Constants for KGDB. 110 * Constants for KGDB.
105 */ 111 */
106typedef mips_reg_t kgdb_reg_t; 112typedef mips_reg_t kgdb_reg_t;
107#define KGDB_NUMREGS 90 113#define KGDB_NUMREGS 90
108#define KGDB_BUFLEN 1024 114#define KGDB_BUFLEN 1024
109 115
110/* 116/*
111 * MIPS cpus have no hardware single-step. 117 * MIPS cpus have no hardware single-step.
112 */ 118 */
113#define SOFTWARE_SSTEP 119#define SOFTWARE_SSTEP
114 120

cvs diff -r1.7 -r1.8 src/sys/arch/mips/mips/mips_stacktrace.c (expand / switch to unified diff)

--- src/sys/arch/mips/mips/mips_stacktrace.c 2020/09/24 03:17:18 1.7
+++ src/sys/arch/mips/mips/mips_stacktrace.c 2021/03/29 03:09:42 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mips_stacktrace.c,v 1.7 2020/09/24 03:17:18 mrg Exp $ */ 1/* $NetBSD: mips_stacktrace.c,v 1.8 2021/03/29 03:09:42 simonb Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988 University of Utah. 4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1992, 1993 5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved. 6 * The Regents of the University of California. All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to Berkeley by 8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer 9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department and Ralph Campbell. 10 * Science Department and Ralph Campbell.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -30,27 +30,27 @@ @@ -30,27 +30,27 @@
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE. 34 * SUCH DAMAGE.
35 * 35 *
36 * from: NetBSD: trap.c,v 1.255 2020/07/13 09:00:40 simonb Exp 36 * from: NetBSD: trap.c,v 1.255 2020/07/13 09:00:40 simonb Exp
37 * from: Utah Hdr: trap.c 1.32 91/04/06 37 * from: Utah Hdr: trap.c 1.32 91/04/06
38 * 38 *
39 * @(#)trap.c 8.5 (Berkeley) 1/11/94 39 * @(#)trap.c 8.5 (Berkeley) 1/11/94
40 */ 40 */
41 41
42#include <sys/cdefs.h> 42#include <sys/cdefs.h>
43__KERNEL_RCSID(0, "$NetBSD: mips_stacktrace.c,v 1.7 2020/09/24 03:17:18 mrg Exp $"); 43__KERNEL_RCSID(0, "$NetBSD: mips_stacktrace.c,v 1.8 2021/03/29 03:09:42 simonb Exp $");
44 44
45#ifdef _KERNEL_OPT 45#ifdef _KERNEL_OPT
46#include "opt_ddb.h" 46#include "opt_ddb.h"
47#include "opt_kgdb.h" 47#include "opt_kgdb.h"
48#endif 48#endif
49 49
50#include <sys/param.h> 50#include <sys/param.h>
51#include <sys/systm.h> 51#include <sys/systm.h>
52#include <sys/proc.h> 52#include <sys/proc.h>
53 53
54#include <mips/locore.h> 54#include <mips/locore.h>
55#include <mips/mips_opcode.h> 55#include <mips/mips_opcode.h>
56#include <mips/regnum.h> 56#include <mips/regnum.h>
@@ -181,47 +181,47 @@ static const struct { void *addr; const  @@ -181,47 +181,47 @@ static const struct { void *addr; const
181 Name(mips64r2_user_gen_exception), 181 Name(mips64r2_user_gen_exception),
182 Name(mips64r2_systemcall), 182 Name(mips64r2_systemcall),
183 Name(mips64r2_kern_intr), 183 Name(mips64r2_kern_intr),
184 Name(mips64r2_user_intr), 184 Name(mips64r2_user_intr),
185#endif /* MIPS64R2 */ 185#endif /* MIPS64R2 */
186 186
187 Name(cpu_idle), 187 Name(cpu_idle),
188 Name(cpu_switchto), 188 Name(cpu_switchto),
189#endif /* _KERNEL */ 189#endif /* _KERNEL */
190 {0, 0} 190 {0, 0}
191}; 191};
192 192
193 193
194static bool 194bool
195kdbpeek(vaddr_t addr, unsigned *valp) 195kdbpeek(vaddr_t addr, unsigned *valp)
196{ 196{
197 if (addr & 3) { 197 if (addr & 3) {
198 printf("kdbpeek: unaligned address %#"PRIxVADDR"\n", addr); 198 printf("kdbpeek: unaligned address %#"PRIxVADDR"\n", addr);
199 /* We might have been called from DDB, so do not go there. */ 199 /* We might have been called from DDB, so do not go there. */
200 return false; 200 return false;
201 } else if (addr == 0) { 201 } else if (addr == 0) {
202 printf("kdbpeek: NULL\n"); 202 printf("kdbpeek: NULL\n");
203 return false; 203 return false;
204 } else { 204 } else {
205#if _KERNEL 205#if _KERNEL
206 *valp = *(unsigned *)addr; 206 *valp = *(unsigned *)addr;
207#else 207#else
208 db_read_bytes((db_addr_t)addr, sizeof(unsigned), (char *)valp); 208 db_read_bytes((db_addr_t)addr, sizeof(unsigned), (char *)valp);
209#endif 209#endif
210 return true; 210 return true;
211 } 211 }
212} 212}
213 213
214static mips_reg_t 214mips_reg_t
215kdbrpeek(vaddr_t addr, size_t n) 215kdbrpeek(vaddr_t addr, size_t n)
216{ 216{
217 mips_reg_t rc = 0; 217 mips_reg_t rc = 0;
218 218
219 if (addr & (n - 1)) { 219 if (addr & (n - 1)) {
220 printf("kdbrpeek: unaligned address %#"PRIxVADDR"\n", addr); 220 printf("kdbrpeek: unaligned address %#"PRIxVADDR"\n", addr);
221#if _KERNEL 221#if _KERNEL
222 /* We might have been called from DDB, so do not go there. */ 222 /* We might have been called from DDB, so do not go there. */
223 stacktrace(); 223 stacktrace();
224#endif 224#endif
225 rc = -1; 225 rc = -1;
226 } else if (addr == 0) { 226 } else if (addr == 0) {
227 printf("kdbrpeek: NULL\n"); 227 printf("kdbrpeek: NULL\n");