Mon Dec 12 12:36:48 2011 UTC ()
Print lwp values on syscall entry


(reinoud)
diff -r1.13 -r1.14 src/sys/arch/usermode/usermode/syscall.c

cvs diff -r1.13 -r1.14 src/sys/arch/usermode/usermode/syscall.c (expand / switch to unified diff)

--- src/sys/arch/usermode/usermode/syscall.c 2011/12/11 20:33:52 1.13
+++ src/sys/arch/usermode/usermode/syscall.c 2011/12/12 12:36:48 1.14
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: syscall.c,v 1.13 2011/12/11 20:33:52 reinoud Exp $ */ 1/* $NetBSD: syscall.c,v 1.14 2011/12/12 12:36:48 reinoud Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
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.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.13 2011/12/11 20:33:52 reinoud Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.14 2011/12/12 12:36:48 reinoud Exp $");
31 31
32#include <sys/types.h> 32#include <sys/types.h>
33#include <sys/param.h> 33#include <sys/param.h>
34#include <sys/systm.h> 34#include <sys/systm.h>
35#include <sys/proc.h> 35#include <sys/proc.h>
36#include <sys/lwp.h> 36#include <sys/lwp.h>
37#include <sys/sched.h> 37#include <sys/sched.h>
38#include <sys/ktrace.h> 38#include <sys/ktrace.h>
39#include <sys/syscall.h> 39#include <sys/syscall.h>
40#include <sys/syscallvar.h> 40#include <sys/syscallvar.h>
41#include <sys/syscallargs.h> 41#include <sys/syscallargs.h>
42 42
43#include <sys/userret.h> 43#include <sys/userret.h>
@@ -61,27 +61,27 @@ child_return(void *arg) @@ -61,27 +61,27 @@ child_return(void *arg)
61 lwp_t *l = arg; 61 lwp_t *l = arg;
62// struct pcb *pcb = lwp_getpcb(l); 62// struct pcb *pcb = lwp_getpcb(l);
63 63
64 /* XXX? */ 64 /* XXX? */
65// frame->registers[0] = 0; 65// frame->registers[0] = 0;
66 66
67 aprint_debug("child return! lwp %p\n", l); 67 aprint_debug("child return! lwp %p\n", l);
68 userret(l); 68 userret(l);
69 ktrsysret(SYS_fork, 0, 0); 69 ktrsysret(SYS_fork, 0, 0);
70} 70}
71 71
72extern const char *const syscallnames[]; 72extern const char *const syscallnames[];
73 73
74static void syscall_args_print(int code, int nargs, int argsize, 74static void syscall_args_print(lwp_t *l, int code, int nargs, int argsize,
75 register_t *args); 75 register_t *args);
76static void syscall_retvals_print(int code, int nargs, register_t *args, 76static void syscall_retvals_print(int code, int nargs, register_t *args,
77 int error, register_t *rval); 77 int error, register_t *rval);
78 78
79 79
80void 80void
81syscall(void) 81syscall(void)
82{  82{
83 lwp_t *l = curlwp; 83 lwp_t *l = curlwp;
84 const struct proc * const p = l->l_proc; 84 const struct proc * const p = l->l_proc;
85 const struct sysent *callp; 85 const struct sysent *callp;
86 struct pcb *pcb = lwp_getpcb(l); 86 struct pcb *pcb = lwp_getpcb(l);
87 ucontext_t *ucp = &pcb->pcb_userret_ucp; 87 ucontext_t *ucp = &pcb->pcb_userret_ucp;
@@ -112,27 +112,27 @@ syscall(void) @@ -112,27 +112,27 @@ syscall(void)
112#if 0 112#if 0
113 aprint_debug("syscall no. %d, ", code); 113 aprint_debug("syscall no. %d, ", code);
114 aprint_debug("nargs %d, argsize %d => ", nargs, argsize); 114 aprint_debug("nargs %d, argsize %d => ", nargs, argsize);
115 dprintf_debug("syscall no. %d, ", code); 115 dprintf_debug("syscall no. %d, ", code);
116 dprintf_debug("nargs %d, argsize %d => ", nargs, argsize); 116 dprintf_debug("nargs %d, argsize %d => ", nargs, argsize);
117#endif 117#endif
118 118
119 /* 119 /*
120 * TODO change the pre and post printing into functions so they can be 120 * TODO change the pre and post printing into functions so they can be
121 * easily adjusted and dont clobber up this space 121 * easily adjusted and dont clobber up this space
122 */ 122 */
123 123
124 if (!error) 124 if (!error)
125 syscall_args_print(code, nargs, argsize, args); 125 syscall_args_print(l, code, nargs, argsize, args);
126 126
127 md_syscall_inc_pc(ucp, opcode); 127 md_syscall_inc_pc(ucp, opcode);
128 128
129 if (!error)  129 if (!error)
130 error = (*callp->sy_call)(l, args, rval); 130 error = (*callp->sy_call)(l, args, rval);
131 131
132 syscall_retvals_print(code, nargs, args, error, rval); 132 syscall_retvals_print(code, nargs, args, error, rval);
133 133
134//out: 134//out:
135 switch (error) { 135 switch (error) {
136 default: 136 default:
137 /* fall trough */ 137 /* fall trough */
138 case 0: 138 case 0:
@@ -142,55 +142,57 @@ syscall(void) @@ -142,55 +142,57 @@ syscall(void)
142 break; 142 break;
143 case ERESTART: 143 case ERESTART:
144 md_syscall_dec_pc(ucp, opcode); 144 md_syscall_dec_pc(ucp, opcode);
145 /* nothing to do */ 145 /* nothing to do */
146 break; 146 break;
147 } 147 }
148 //dprintf_debug("end of syscall : return to userland\n"); 148 //dprintf_debug("end of syscall : return to userland\n");
149//if (code != 4) printf("userret() code %d\n", code); 149//if (code != 4) printf("userret() code %d\n", code);
150 userret(l); 150 userret(l);
151} 151}
152 152
153 153
154static void 154static void
155syscall_args_print(int code, int nargs, int argsize, register_t *args) 155syscall_args_print(lwp_t *l, int code, int nargs, int argsize, register_t *args)
156{ 156{
 157//return;
157 if (code != 4) { 158 if (code != 4) {
158 printf("code %3d, nargs %d, argsize %3d\t%s(",  159 printf("lwp %p, code %3d, nargs %d, argsize %3d\t%s(",
159 code, nargs, argsize, syscallnames[code]); 160 l, code, nargs, argsize, syscallnames[code]);
160 switch (code) { 161 switch (code) {
161 case 5: 162 case 5:
162 printf("\"%s\", %"PRIx32", %"PRIx32"", (char *) (args[0]), (uint) args[1], (uint) args[2]); 163 printf("\"%s\", %"PRIx32", %"PRIx32"", (char *) (args[0]), (uint) args[1], (uint) args[2]);
163 break; 164 break;
164 case 33: 165 case 33:
165 printf("\"%s\", %"PRIx32"", (char *) (args[0]), (uint) args[1]); 166 printf("\"%s\", %"PRIx32"", (char *) (args[0]), (uint) args[1]);
166 break; 167 break;
167 case 50: 168 case 50:
168 printf("\"%s\"", (char *) (args[0])); 169 printf("\"%s\"", (char *) (args[0]));
169 break; 170 break;
170 case 58: 171 case 58:
171 printf("\"%s\", %"PRIx32", %"PRIx32"", (char *) (args[0]), (uint) (args[1]), (uint) args[2]); 172 printf("\"%s\", %"PRIx32", %"PRIx32"", (char *) (args[0]), (uint) (args[1]), (uint) args[2]);
172 default: 173 default:
173 for (int i = 0; i < nargs; i++) 174 for (int i = 0; i < nargs; i++)
174 printf("%"PRIx32", ", (uint) args[i]); 175 printf("%"PRIx32", ", (uint) args[i]);
175 if (nargs) 176 if (nargs)
176 printf("\b\b"); 177 printf("\b\b");
177 } 178 }
178 printf(") "); 179 printf(") ");
179 } 180 }
180#if 1 181#if 0
181 if ((code == 4)) { 182 if ((code == 4)) {
182 dprintf_debug("[us] %s", (char *) args[1]); 183// dprintf_debug("[us] %s", (char *) args[1]);
183// printf("[us] %s", (char *) args[1]); 184 printf("[us] %s", (char *) args[1]);
184 } 185 }
185#endif 186#endif
186} 187}
187 188
188 189
189static void 190static void
190syscall_retvals_print(int code, int nargs, register_t *args, int error, register_t *rval) 191syscall_retvals_print(int code, int nargs, register_t *args, int error, register_t *rval)
191{ 192{
 193//return;
192 if (code != 4) 194 if (code != 4)
193 printf("=> %s: %d, (%"PRIx32", %"PRIx32")\n", 195 printf("=> %s: %d, (%"PRIx32", %"PRIx32")\n",
194 error?"ERROR":"OK", error, (uint) (rval[0]), (uint) (rval[1])); 196 error?"ERROR":"OK", error, (uint) (rval[0]), (uint) (rval[1]));
195} 197}
196 198