Wed Oct 3 17:43:22 2012 UTC ()
Use db_read_value to read the trapframe fields in db_nextframe.

Fixes SIGSEGV on bt in crash(8) when the stack trace ends in syscall,
and probably other problems as well.

ok christos


(riastradh)
diff -r1.3 -r1.4 src/sys/arch/amd64/amd64/db_machdep.c

cvs diff -r1.3 -r1.4 src/sys/arch/amd64/amd64/db_machdep.c (expand / switch to unified diff)

--- src/sys/arch/amd64/amd64/db_machdep.c 2012/07/12 17:14:39 1.3
+++ src/sys/arch/amd64/amd64/db_machdep.c 2012/10/03 17:43:22 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: db_machdep.c,v 1.3 2012/07/12 17:14:39 dsl Exp $ */ 1/* $NetBSD: db_machdep.c,v 1.4 2012/10/03 17:43:22 riastradh Exp $ */
2 2
3/*  3/*
4 * Mach Operating System 4 * Mach Operating System
5 * Copyright (c) 1991,1990 Carnegie Mellon University 5 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * All Rights Reserved. 6 * All Rights Reserved.
7 *  7 *
8 * Permission to use, copy, modify and distribute this software and its 8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright 9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the 10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions 11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation. 12 * thereof, and that both notices appear in supporting documentation.
13 *  13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
@@ -16,27 +16,27 @@ @@ -16,27 +16,27 @@
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 *  17 *
18 * Carnegie Mellon requests users of this software to return to 18 * Carnegie Mellon requests users of this software to return to
19 *  19 *
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science 21 * School of Computer Science
22 * Carnegie Mellon University 22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890 23 * Pittsburgh PA 15213-3890
24 *  24 *
25 * any improvements or extensions that they make and grant Carnegie the 25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes. 26 * rights to redistribute these changes.
27 */ 27 */
28#include <sys/cdefs.h> 28#include <sys/cdefs.h>
29__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.3 2012/07/12 17:14:39 dsl Exp $"); 29__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.4 2012/10/03 17:43:22 riastradh Exp $");
30 30
31#include <sys/param.h> 31#include <sys/param.h>
32#include <sys/systm.h> 32#include <sys/systm.h>
33#include <sys/proc.h> 33#include <sys/proc.h>
34 34
35#include <machine/frame.h> 35#include <machine/frame.h>
36#include <machine/trap.h> 36#include <machine/trap.h>
37#include <machine/intrdefs.h> 37#include <machine/intrdefs.h>
38 38
39#include <machine/db_machdep.h> 39#include <machine/db_machdep.h>
40#include <ddb/db_sym.h> 40#include <ddb/db_sym.h>
41#include <ddb/db_access.h> 41#include <ddb/db_access.h>
42#include <ddb/db_variables.h> 42#include <ddb/db_variables.h>
@@ -124,37 +124,40 @@ db_nextframe(long **nextframe, long **re @@ -124,37 +124,40 @@ db_nextframe(long **nextframe, long **re
124 *retaddr = (long *)&fp->f_retaddr; 124 *retaddr = (long *)&fp->f_retaddr;
125 *arg0 = (long *)&fp->f_arg0; 125 *arg0 = (long *)&fp->f_arg0;
126 break; 126 break;
127 127
128 case TRAP: 128 case TRAP:
129 case SYSCALL: 129 case SYSCALL:
130 case INTERRUPT: 130 case INTERRUPT:
131 default: 131 default:
132 132
133 /* The only argument to trap() or syscall() is the trapframe. */ 133 /* The only argument to trap() or syscall() is the trapframe. */
134 tf = (struct trapframe *)argp; 134 tf = (struct trapframe *)argp;
135 switch (is_trap) { 135 switch (is_trap) {
136 case TRAP: 136 case TRAP:
137 (*pr)("--- trap (number %d) ---\n", tf->tf_trapno); 137 (*pr)("--- trap (number %"DDB_EXPR_FMT"u) ---\n",
 138 db_get_value((long)&tf->tf_trapno, 8, false));
138 break; 139 break;
139 case SYSCALL: 140 case SYSCALL:
140 (*pr)("--- syscall (number %ld) ---\n", tf->tf_rax); 141 (*pr)("--- syscall (number %"DDB_EXPR_FMT"u) ---\n",
 142 db_get_value((long)&tf->tf_rax, 8, false));
141 break; 143 break;
142 case INTERRUPT: 144 case INTERRUPT:
143 (*pr)("--- interrupt ---\n"); 145 (*pr)("--- interrupt ---\n");
144 break; 146 break;
145 } 147 }
146 *ip = (db_addr_t)tf->tf_rip; 148 *ip = (db_addr_t)db_get_value((long)&tf->tf_rip, 8, false);
147 fp = (struct x86_64_frame *)tf->tf_rbp; 149 fp = (struct x86_64_frame *)
 150 db_get_value((long)&tf->tf_rbp, 8, false);
148 if (fp == NULL) 151 if (fp == NULL)
149 return 0; 152 return 0;
150 *nextframe = (long *)&fp->f_frame; 153 *nextframe = (long *)&fp->f_frame;
151 *retaddr = (long *)&fp->f_retaddr; 154 *retaddr = (long *)&fp->f_retaddr;
152 *arg0 = (long *)&fp->f_arg0; 155 *arg0 = (long *)&fp->f_arg0;
153 break; 156 break;
154 } 157 }
155 158
156 /* 159 /*
157 * A bit of a hack. Since %rbp may be used in the stub code, 160 * A bit of a hack. Since %rbp may be used in the stub code,
158 * walk the stack looking for a valid interrupt frame. Such 161 * walk the stack looking for a valid interrupt frame. Such
159 * a frame can be recognized by always having 162 * a frame can be recognized by always having
160 * err 0 or IREENT_MAGIC and trapno T_ASTFLT. 163 * err 0 or IREENT_MAGIC and trapno T_ASTFLT.