source: trunk/minix/commands/mdb/decode.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 8.0 KB
Line 
1/*
2 * decode.c for mdb -- decodes a Minix system call
3 */
4#include "mdb.h"
5#ifdef SYSCALLS_SUPPORT
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9#include <fcntl.h>
10#include <sys/stat.h>
11#define ptrace mdbtrace
12#include <sys/ptrace.h>
13#include <minix/type.h>
14#include <minix/callnr.h>
15#include "proto.h"
16
17FORWARD _PROTOTYPE( void get_message, (message *m, unsigned bx) );
18FORWARD _PROTOTYPE( void get_data, (char *s, unsigned bx, int cnt) );
19
20PRIVATE message sent;
21PRIVATE message recv;
22PRIVATE unsigned saved_addr;
23PRIVATE int last_call;
24
25#define NOSYS 0
26#define NOP 1
27
28#define _M1 0x0100
29#define _M2 0x0200
30#define _M3 0x0400
31#define _M4 0x0800
32
33#define _M13 0x0500
34
35#define M1_I1 (_M1|1)
36#define M1_I2 (_M1|2)
37#define M1_I3 (_M1|4)
38#define M1_P1 (_M1|8)
39#define M1_P2 (_M1|16)
40#define M1_P3 (_M1|32)
41
42#define M2_I1 (_M2|1)
43#define M2_I2 (_M2|2)
44#define M2_I3 (_M2|4)
45#define M2_L1 (_M2|8)
46#define M2_L2 (_M2|16)
47#define M2_P1 (_M2|32)
48
49#define M3_I1 (_M3|1)
50#define M3_I2 (_M3|2)
51#define M3_P1 (_M3|4)
52#define M3_C1 (_M3|8)
53
54#define M4_L1 (_M4|1)
55#define M4_L2 (_M4|2)
56#define M4_L3 (_M4|4)
57#define M4_L4 (_M4|8)
58#define M4_L5 (_M4|16)
59
60#define M13_OPEN (_M13|1)
61
62#define M1_I12 (M1_I1|M1_I2)
63#define M1_NAME1 (M1_I1|M1_P1)
64#define M1_NAME2 (M1_I2|M1_P2)
65#define M1_2NAMES (M1_I1|M1_P1|M1_I2|M1_P2)
66#define M1_SIGACTION (M1_I2|M1_P1|M1_P2|M1_P3)
67
68#define M2_IOCTL (M2_I1|M2_I3|M2_L1|M2_L2)
69#define M2_4P (M2_I1|M2_I2|M2_L1|M2_L2)
70#define M2_SIGRETURN (M2_I2|M2_L1|M2_P1)
71#define M2_SIGPROC (M2_I1|M2_L1)
72#define M2_UTIME (M2_I1|M2_I2|M2_L1|M2_L2|M2_P1)
73
74#define M3_LOAD (M3_I1|M3_C1)
75
76struct decode_system {
77 int syscall;
78 unsigned int sflag;
79 unsigned int rflag;
80 char *name;
81} decode[NCALLS] = {
82 0, NOSYS, NOP, NULL,
83 EXIT, M1_I1, NOP, "EXIT",
84 FORK, NOP, NOP, "FORK",
85 READ, M1_I12, NOP, "READ",
86 WRITE, M1_I12, NOP, "WRITE",
87 OPEN, M13_OPEN, NOP, "OPEN",
88 CLOSE, M1_I1, NOP, "CLOSE",
89 WAIT, NOP, M2_I1, "WAIT",
90 CREAT, M3_LOAD, NOP, "CREAT",
91 LINK, M1_2NAMES, NOP, "LINK",
92 UNLINK, M3_LOAD, NOP, "UNLINK",
93 WAITPID, M1_I1, M2_I1, "WAITPID",
94 CHDIR, M3_LOAD, NOP, "CHDIR",
95 TIME, NOP, M2_L1, "TIME",
96 MKNOD, M1_NAME1, NOP, "MKNOD",
97 CHMOD, M3_LOAD, NOP, "CHMOD",
98 CHOWN, M1_NAME1, NOP, "CHOWN",
99 BRK, M1_P1, M2_P1, "BRK",
100 STAT, M1_NAME1, NOP, "STAT",
101 LSEEK, M1_I1, NOP, "LSEEK",
102 GETPID, NOP, NOP, "GETPID",
103 MOUNT, M1_2NAMES, NOP, "MOUNT",
104 UMOUNT, M3_LOAD, NOP, "UMOUNT",
105 SETUID, M1_I1, NOP, "SETUID",
106 GETUID, NOP, NOP, "GETUID",
107 STIME, M2_L1, NOP, "STIME",
108 PTRACE, M2_4P, NOP, "PTRACE",
109 ALARM, M1_I1, NOP, "ALARM",
110 FSTAT, M1_I1, NOP, "FSTAT",
111 PAUSE, NOP, NOP, "PAUSE",
112 UTIME, M2_UTIME, NOP, "UTIME",
113 31, NOSYS, NOP, NULL,
114 32, NOSYS, NOP, NULL,
115 ACCESS, M3_LOAD, NOP, "ACCESS",
116 34, NOSYS, NOP, NULL,
117 35, NOSYS, NOP, NULL,
118 SYNC, NOP, NOP, "SYNC",
119 KILL, M1_I12, NOP, "KILL",
120 RENAME, M1_2NAMES, NOP, "RENAME",
121 MKDIR, M1_NAME1, NOP, "MKDIR",
122 RMDIR, M3_LOAD, NOP, "RMDIR",
123 DUP, NOP, NOP, "DUP",
124 PIPE, NOP, M1_I12, "PIPE",
125 TIMES, M4_L5, NOP, "TIMES",
126 44, NOSYS, NOP, NULL,
127 45, NOSYS, NOP, NULL,
128 SETGID, M1_I1, NOP, "SETGID",
129 GETGID, NOP, NOP, "GETGID",
130 SIGNAL, NOP, NOP, "SIGNAL",
131 49, NOSYS, NOP, NULL,
132 50, NOSYS, NOP, NULL,
133 51, NOSYS, NOP, NULL,
134 52, NOSYS, NOP, NULL,
135 53, NOSYS, NOP, NULL,
136 IOCTL, M2_IOCTL, M2_IOCTL, "IOCTL",
137 FCNTL, M1_I12, NOP, "FCNTL",
138#if ENABLE_SYMLINK
139 RDLINK, M1_NAME1, NOP, "RDLINK",
140 SLINK, M1_NAME1, NOP, "SLINK",
141 LSTAT, M1_NAME1, NOP, "LSTAT",
142#else
143 56, NOSYS, NOP, NULL,
144 57, NOSYS, NOP, NULL,
145 58, NOSYS, NOP, NULL,
146#endif
147 EXEC, M1_NAME1, NOP, "EXEC",
148 UMASK, M1_I1, NOP, "UMASK",
149 CHROOT, M3_LOAD, NOP, "CHROOT",
150 SETSID, NOP, NOP, "SETSID",
151 GETPGRP, NOP, NOP, "GETPGRP",
152 KSIG, NOSYS, NOP, "KSIG",
153 UNPAUSE, NOSYS, NOP, "UNPAUSE",
154 66, NOSYS, NOP, NULL,
155 REVIVE, NOSYS, NOP, "REVIVE",
156 TASK_REPLY, NOSYS, NOP, "TASK_REPLY",
157 69, NOSYS, NOP, NULL,
158 70, NOSYS, NOP, NULL,
159 SIGACTION, M1_SIGACTION, NOP, "SIGACTION",
160 SIGSUSPEND, M2_L1, NOP, "SIGSUSPEND",
161 SIGPENDING, NOP, M2_L1, "SIGPENDING",
162 SIGPROCMASK, M2_SIGPROC, NOP, "SIGPROCMASK",
163 SIGRETURN, M2_SIGRETURN, NOP, "SIGRETURN",
164 REBOOT, M1_I1, NOP, "REBOOT"
165};
166
167PRIVATE void get_message(m,bx)
168message *m;
169unsigned bx;
170{
171 unsigned addr;
172 int i;
173 long buffer[ MESS_SIZE/4 + 1 ];
174
175 addr = bx;
176 for (i = 0; i< sizeof(buffer)/4; i++)
177 buffer[i] = ptrace(T_GETDATA,curpid,
178 (long) (addr+i*4) ,0L);
179
180 memcpy(m,buffer,MESS_SIZE);
181
182}
183
184PRIVATE void get_data(s, bx, cnt)
185char *s;
186unsigned bx;
187int cnt;
188{
189 unsigned addr;
190 int i,nl;
191 long buffer[PATH_MAX/4 + 1];
192
193 addr = bx;
194 nl = (cnt / 4) + 1;
195 for (i = 0; i< nl; i++)
196 buffer[i] = ptrace(T_GETDATA, curpid, (long) (addr+i*4) ,0L);
197
198 memcpy(s, buffer, cnt);
199}
200
201
202PUBLIC void decode_result()
203{
204
205 /* Update message */
206 get_message(&recv,saved_addr);
207 Printf("result=%d\n", recv.m_type);
208
209 if (last_call < 0 || last_call >NCALLS) {
210 Printf("Bad call in decode_result\n");
211 return;
212 }
213
214 switch (decode[last_call].rflag) {
215 case NOP:
216 return;
217 break;
218 case M1_I12:
219 Printf("m1_l1=%d m1_i2=%d ",recv.m1_i1,recv.m1_i2);
220 break;
221 case M2_IOCTL:
222 decode_ioctl('R',&recv);
223 break;
224 case M2_P1:
225 Printf("m2_p1=%lx ",(unsigned long)recv.m2_p1);
226 break;
227 case M2_L1:
228 Printf("m2_l1=%lx ",recv.m2_l1);
229 break;
230 case M2_I1:
231 Printf("m2_i1=%x ",recv.m2_i1);
232 break;
233 default:
234 Printf("rflag=%d ",decode[last_call].rflag);
235 break;
236 }
237 Printf("\n");
238}
239
240
241void decode_message(bx)
242unsigned bx;
243{
244int t;
245int slen;
246unsigned int flag;
247char path[PATH_MAX];
248
249 /* Save address of message */
250 saved_addr = bx;
251 get_message(&sent,bx);
252
253 t = sent.m_type;
254
255 if ( t <= 0 || t >= NCALLS ) {
256 Printf("Bad call - not in range\n");
257 last_call = 0;
258 return;
259 }
260
261 flag = decode[t].sflag;
262
263 if ( flag == NOSYS) {
264 Printf("Bad call - not in system\n");
265 last_call = 0;
266 return;
267 }
268 else
269 last_call = t;
270
271 Printf(" type %s (%d) ", decode[last_call].name, last_call);
272
273 switch (flag) {
274 case NOP:
275 break;
276 case M1_I1:
277 case M1_I12:
278 Printf("i1=%d ",sent.m1_i1);
279 if ( flag == M1_I1) break;
280 case M1_I2:
281 Printf("i2=%d ",sent.m1_i2);
282 break;
283 case M1_P1:
284 Printf("p1=%lx ",(unsigned long)sent.m1_p1);
285 break;
286 case M1_NAME1:
287 case M1_2NAMES:
288 slen = sent.m1_i1;
289 get_data(path, (unsigned long) sent.m1_p1, slen);
290 path[slen] = '\0';
291 Printf("s1=%s ",path);
292 if ( flag == M1_NAME1) break;
293 slen = sent.m1_i2;
294 get_data(path, (unsigned long) sent.m1_p2, slen);
295 path[slen] = '\0';
296 Printf("s2=%s ",path);
297 break;
298 case M2_UTIME:
299 if ( sent.m2_i1 == 0 )
300 slen = sent.m2_i2;
301 else
302 slen = sent.m2_i1;
303 get_data(path, (unsigned long) sent.m2_p1, slen);
304 path[slen] = '\0';
305 Printf("p1=%s ",path);
306 if ( sent.m2_i1 != 0 )
307 Printf("l1=%lx l2=%lx ",sent.m2_l1,sent.m2_l2);
308 break;
309 case M1_SIGACTION:
310 Printf("m1_i2=%d p1=%lx p2=%lx p3=%lx\n",
311 sent.m1_i2,
312 (unsigned long)sent.m1_p1,
313 (unsigned long)sent.m1_p2,
314 (unsigned long)sent.m1_p3);
315 break;
316 case M2_4P: Printf("m2_i1=%d m2_i2=%d m2_l1=%lx m2_l2=%lx ",
317 sent.m2_i1,sent.m2_i2,sent.m2_l1,sent.m2_l2);
318 break;
319 case M2_L1:
320 Printf("m2_l1=%ld ",sent.m2_l1);
321 break;
322 case M2_IOCTL:
323 decode_ioctl('S',&sent);
324 break;
325 case M2_SIGRETURN:
326 Printf("m2_i2=%d l1=%lx p1=%lx ",
327 sent.m2_i2,sent.m2_l1,
328 (unsigned long)sent.m1_p1);
329 break;
330 case M2_SIGPROC:
331 Printf("m2_i1=%d l1=%lx ", sent.m2_i1,sent.m2_l1);
332 break;
333 case M13_OPEN:
334 if (sent.m1_i2 & O_CREAT) {
335 slen = sent.m1_i1;
336 get_data(path, (unsigned long) sent.m1_p1, slen);
337 path[slen] = '\0';
338 Printf("s1=%s ",path);
339 break;
340 }
341 /* fall to M3_LOAD */
342 case M3_LOAD:
343 slen = sent.m3_i1;
344 if ( slen <= M3_STRING)
345 strncpy(path,sent.m3_ca1,M3_STRING);
346 else
347 get_data(path, (unsigned long) sent.m3_ca1, slen);
348 path[slen] = '\0';
349 Printf("m3_name=%s ",path);
350 break;
351 case M4_L5:
352 Printf("m4_l5=%ld ",sent.m4_l5);
353 break;
354 default: Printf("sflag=%d ",decode[last_call].sflag);
355 break;
356 }
357 Printf("\n");
358}
359
360#endif /* SYSCALLS_SUPPORT */
Note: See TracBrowser for help on using the repository browser.