]>
Commit | Line | Data |
---|---|---|
88dae46d SB |
1 | /* |
2 | * System call tracing and debugging | |
3 | * | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
2231197c | 19 | #include "qemu/osdep.h" |
84778508 | 20 | #include <sys/select.h> |
84778508 | 21 | #include <sys/syscall.h> |
88dae46d | 22 | #include <sys/ioccom.h> |
ea1ab4cf | 23 | #include <ctype.h> |
84778508 | 24 | |
88dae46d | 25 | #include "qemu.h" |
84778508 | 26 | |
ea1ab4cf SS |
27 | #include "os-strace.h" /* OS dependent strace print functions */ |
28 | ||
88dae46d | 29 | int do_strace; |
84778508 BS |
30 | |
31 | /* | |
32 | * Utility functions | |
33 | */ | |
34 | ||
80b34604 SB |
35 | static void print_sysctl(const struct syscallname *name, abi_long arg1, |
36 | abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, | |
37 | abi_long arg6) | |
38 | { | |
39 | uint32_t i; | |
40 | int32_t *namep; | |
41 | ||
42 | gemu_log("%s({ ", name->name); | |
43 | namep = lock_user(VERIFY_READ, arg1, sizeof(int32_t) * arg2, 1); | |
44 | if (namep) { | |
45 | int32_t *p = namep; | |
46 | ||
47 | for (i = 0; i < (uint32_t)arg2; i++) { | |
48 | gemu_log("%d ", tswap32(*p++)); | |
49 | } | |
50 | unlock_user(namep, arg1, 0); | |
51 | } | |
52 | gemu_log("}, %u, 0x" TARGET_ABI_FMT_lx ", 0x" TARGET_ABI_FMT_lx ", 0x" | |
53 | TARGET_ABI_FMT_lx ", 0x" TARGET_ABI_FMT_lx ")", | |
54 | (uint32_t)arg2, arg3, arg4, arg5, arg6); | |
55 | } | |
56 | ||
88dae46d SB |
57 | static void print_execve(const struct syscallname *name, abi_long arg1, |
58 | abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, | |
59 | abi_long arg6) | |
84778508 BS |
60 | { |
61 | abi_ulong arg_ptr_addr; | |
62 | char *s; | |
63 | ||
88dae46d SB |
64 | s = lock_user_string(arg1); |
65 | if (s == NULL) { | |
84778508 | 66 | return; |
88dae46d | 67 | } |
84778508 BS |
68 | gemu_log("%s(\"%s\",{", name->name, s); |
69 | unlock_user(s, arg1, 0); | |
70 | ||
71 | for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) { | |
18c9a9c3 | 72 | abi_ulong *arg_ptr, arg_addr; |
84778508 BS |
73 | |
74 | arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1); | |
88dae46d | 75 | if (!arg_ptr) { |
84778508 | 76 | return; |
88dae46d | 77 | } |
84778508 BS |
78 | arg_addr = tswapl(*arg_ptr); |
79 | unlock_user(arg_ptr, arg_ptr_addr, 0); | |
88dae46d | 80 | if (!arg_addr) { |
84778508 | 81 | break; |
88dae46d | 82 | } |
84778508 BS |
83 | if ((s = lock_user_string(arg_addr))) { |
84 | gemu_log("\"%s\",", s); | |
18c9a9c3 | 85 | unlock_user(s, arg_addr, 0); |
84778508 BS |
86 | } |
87 | } | |
84778508 BS |
88 | gemu_log("NULL})"); |
89 | } | |
90 | ||
b85159a3 SB |
91 | static void print_ioctl(const struct syscallname *name, |
92 | abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, | |
93 | abi_long arg5, abi_long arg6) | |
94 | { | |
95 | /* Decode the ioctl request */ | |
96 | gemu_log("%s(%d, 0x%0lx { IO%s%s GRP:0x%x('%c') CMD:%d LEN:%d }, 0x" | |
97 | TARGET_ABI_FMT_lx ", ...)", | |
98 | name->name, | |
99 | (int)arg1, | |
100 | (unsigned long)arg2, | |
101 | arg2 & IOC_OUT ? "R" : "", | |
102 | arg2 & IOC_IN ? "W" : "", | |
103 | (unsigned)IOCGROUP(arg2), | |
104 | isprint(IOCGROUP(arg2)) ? (char)IOCGROUP(arg2) : '?', | |
105 | (int)arg2 & 0xFF, | |
106 | (int)IOCPARM_LEN(arg2), | |
107 | arg3); | |
108 | } | |
109 | ||
ea1ab4cf SS |
110 | static void print_sysarch(const struct syscallname *name, abi_long arg1, |
111 | abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, | |
112 | abi_long arg6) | |
113 | { | |
114 | /* This is os dependent. */ | |
115 | do_os_print_sysarch(name, arg1, arg2, arg3, arg4, arg5, arg6); | |
116 | } | |
117 | ||
84778508 BS |
118 | /* |
119 | * Variants for the return value output function | |
120 | */ | |
121 | ||
88dae46d | 122 | static void print_syscall_ret_addr(const struct syscallname *name, abi_long ret) |
84778508 | 123 | { |
88dae46d | 124 | if (ret == -1) { |
84778508 BS |
125 | gemu_log(" = -1 errno=%d (%s)\n", errno, strerror(errno)); |
126 | } else { | |
127 | gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret); | |
128 | } | |
129 | } | |
130 | ||
131 | #if 0 /* currently unused */ | |
132 | static void | |
133 | print_syscall_ret_raw(struct syscallname *name, abi_long ret) | |
134 | { | |
135 | gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret); | |
136 | } | |
137 | #endif | |
138 | ||
139 | /* | |
140 | * An array of all of the syscalls we know about | |
141 | */ | |
142 | ||
143 | static const struct syscallname freebsd_scnames[] = { | |
144 | #include "freebsd/strace.list" | |
145 | }; | |
146 | static const struct syscallname netbsd_scnames[] = { | |
147 | #include "netbsd/strace.list" | |
148 | }; | |
149 | static const struct syscallname openbsd_scnames[] = { | |
150 | #include "openbsd/strace.list" | |
151 | }; | |
152 | ||
88dae46d SB |
153 | static void print_syscall(int num, const struct syscallname *scnames, |
154 | unsigned int nscnames, abi_long arg1, abi_long arg2, abi_long arg3, | |
155 | abi_long arg4, abi_long arg5, abi_long arg6) | |
84778508 BS |
156 | { |
157 | unsigned int i; | |
158 | const char *format="%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," | |
159 | TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," | |
160 | TARGET_ABI_FMT_ld ")"; | |
161 | ||
162 | gemu_log("%d ", getpid() ); | |
163 | ||
88dae46d | 164 | for (i = 0; i < nscnames; i++) { |
84778508 BS |
165 | if (scnames[i].nr == num) { |
166 | if (scnames[i].call != NULL) { | |
167 | scnames[i].call(&scnames[i], arg1, arg2, arg3, arg4, arg5, | |
88dae46d | 168 | arg6); |
84778508 BS |
169 | } else { |
170 | /* XXX: this format system is broken because it uses | |
171 | host types and host pointers for strings */ | |
88dae46d | 172 | if (scnames[i].format != NULL) { |
84778508 | 173 | format = scnames[i].format; |
88dae46d SB |
174 | } |
175 | gemu_log(format, scnames[i].name, arg1, arg2, arg3, arg4, arg5, | |
176 | arg6); | |
84778508 BS |
177 | } |
178 | return; | |
179 | } | |
88dae46d | 180 | } |
84778508 BS |
181 | gemu_log("Unknown syscall %d\n", num); |
182 | } | |
183 | ||
88dae46d SB |
184 | static void print_syscall_ret(int num, abi_long ret, |
185 | const struct syscallname *scnames, unsigned int nscnames) | |
84778508 BS |
186 | { |
187 | unsigned int i; | |
188 | ||
88dae46d | 189 | for (i = 0; i < nscnames; i++) { |
84778508 BS |
190 | if (scnames[i].nr == num) { |
191 | if (scnames[i].result != NULL) { | |
192 | scnames[i].result(&scnames[i], ret); | |
193 | } else { | |
88dae46d | 194 | if (ret < 0) { |
84778508 BS |
195 | gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n", -ret, |
196 | strerror(-ret)); | |
197 | } else { | |
198 | gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret); | |
199 | } | |
200 | } | |
201 | break; | |
202 | } | |
88dae46d | 203 | } |
84778508 BS |
204 | } |
205 | ||
206 | /* | |
207 | * The public interface to this module. | |
208 | */ | |
88dae46d SB |
209 | void print_freebsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3, |
210 | abi_long arg4, abi_long arg5, abi_long arg6) | |
84778508 | 211 | { |
88dae46d SB |
212 | |
213 | print_syscall(num, freebsd_scnames, ARRAY_SIZE(freebsd_scnames), arg1, arg2, | |
214 | arg3, arg4, arg5, arg6); | |
84778508 BS |
215 | } |
216 | ||
88dae46d | 217 | void print_freebsd_syscall_ret(int num, abi_long ret) |
84778508 | 218 | { |
88dae46d | 219 | |
84778508 BS |
220 | print_syscall_ret(num, ret, freebsd_scnames, ARRAY_SIZE(freebsd_scnames)); |
221 | } | |
222 | ||
88dae46d SB |
223 | void print_netbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3, |
224 | abi_long arg4, abi_long arg5, abi_long arg6) | |
84778508 | 225 | { |
88dae46d | 226 | |
84778508 BS |
227 | print_syscall(num, netbsd_scnames, ARRAY_SIZE(netbsd_scnames), |
228 | arg1, arg2, arg3, arg4, arg5, arg6); | |
229 | } | |
230 | ||
88dae46d | 231 | void print_netbsd_syscall_ret(int num, abi_long ret) |
84778508 | 232 | { |
88dae46d | 233 | |
84778508 BS |
234 | print_syscall_ret(num, ret, netbsd_scnames, ARRAY_SIZE(netbsd_scnames)); |
235 | } | |
236 | ||
88dae46d SB |
237 | void print_openbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3, |
238 | abi_long arg4, abi_long arg5, abi_long arg6) | |
84778508 | 239 | { |
88dae46d SB |
240 | |
241 | print_syscall(num, openbsd_scnames, ARRAY_SIZE(openbsd_scnames), arg1, arg2, | |
242 | arg3, arg4, arg5, arg6); | |
84778508 BS |
243 | } |
244 | ||
88dae46d | 245 | void print_openbsd_syscall_ret(int num, abi_long ret) |
84778508 | 246 | { |
88dae46d | 247 | |
84778508 BS |
248 | print_syscall_ret(num, ret, openbsd_scnames, ARRAY_SIZE(openbsd_scnames)); |
249 | } |