forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.c
More file actions
289 lines (269 loc) · 7.24 KB
/
Copy pathmisc.c
File metadata and controls
289 lines (269 loc) · 7.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
* misc.c for mdb
*/
#include "mdb.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#define ptrace mdbtrace
#include <sys/ptrace.h>
#include "proto.h"
FORWARD _PROTOTYPE( void pr_ascii , (long val , int size ));
/* Print ascii */
PRIVATE void pr_ascii(val, size)
long val;
int size;
{
int i;
int v;
int sh;
#ifdef BYTES_SWAPPED
sh = 8 * size;
#else
sh = 0;
#endif
for (i = 0; i < size; i++) {
v = (int) (val >> sh) & 0xFF;
#ifdef BYTES_SWAPPED
sh -= 8;
#else
sh += 8;
#endif
Printf(isprint(v) ? "%c" : "\\%03o", v);
}
Printf("\n");
}
/* Dump stack */
PUBLIC void dump_stack(cnt)
long cnt;
{
vir_bytes v, vi;
long val, sp;
int num, size, nmode;
size = INTSIZE; /* size of stack element */
num = (int) cnt;
if (num <= 0) num = 0;
if (num > sk_size) num = (int) sk_size / size;
nmode = num; /* Save mode */
/* Get current SP */
sp = get_reg(curpid, reg_addr("sp"));
/* Starting address is top of stack seg -1 */
vi = (vir_bytes) sk_addr + (vir_bytes) sk_size - size;
/* Ending address */
v = (vir_bytes) end_addr;
if (nmode == 0) v = MAX(v, sp);
Printf("Stack Dump SP=%*lx\nAddr\tHex\tAscii\n", 2 * size, sp);
do {
val = (ptrace(T_GETDATA, curpid, (long) vi, 0L) >> SHIFT(size))
& MASK(size);
Printf("%*lx\t", 2 * ADDRSIZE, (vi >> SHIFT(ADDRSIZE))
& MASK(ADDRSIZE));
Printf("%*lx\t", 2 * size, val);
pr_ascii(val, size);
num -= 1;
vi -= size;
} while (vi >= v && (nmode ? num > 0 : 1));
}
/* Get file size */
PUBLIC off_t file_size(fd)
int fd;
{
struct stat st;
if(fstat(fd,&st) <0 ) {
Printf("Cannot stat\n");
return 0L;
}
else
return st.st_size;
}
/* Print help page */
PUBLIC void help_page()
{
outstr("\nHelp for mdb. For more details, type 'command ?'\n");
outstr("!#\t- Shell escape / Set Variable or register\n");
outstr("Tt\t- Current call / Backtrace all\n");
outstr("/nsf\t- Display for n size s with format f\n");
outstr("Xx [n]\t- Disasm / & display reg for n instructions\n");
outstr("Rr a\t- Run / with arguments a\n");
outstr("Cc [n]\t- Continue with current signal / no signal n times\n");
outstr("Ii [n]\t- Single step with / no signal for n instructions\n");
outstr("Mm t n\t- Trace until / Stop when modified t type for n instructions\n");
outstr("k \t- Kill traced process\n");
outstr("Bb\t- Display / Set Break-pt\n");
outstr("Dd\t- Delete all / one break-points\n");
outstr("P\t- Toggle Paging\n");
outstr("Ll name\t- Log to file name / and to standard output\n");
#ifdef DEBUG
outstr("Vv\t- Version info / Toggle debug flag\n");
#else
outstr("V\t- Version info\n");
#endif
outstr("e [t]\t- List symbols for type t\n");
outstr("y\t- Print segment mappings\n");
outstr("s [n]\t- Dump stack for n words\n");
#if SYSCALLS_SUPPORT
outstr("z [a]\t- Trace syscalls with address a\n");
#endif
outstr("? \t- Help - this screen\n");
outstr("@ file\t- Execute commands from file\n");
outstr("Qq\t- Quit / and kill traced process\n");
#ifdef DEBUG
outstr("Usage: mdb -x debug-level [-Ll]logfile exec-file core-file @command-file\n");
#else
outstr("Usage: mdb [-Ll]logfile exec-file core-file @command-file\n");
#endif
outstr(" mdb [-fc] file\n");
}
PUBLIC void version_info()
{
Printf("\nmdb version %s.%d for Minix", MDBVERSION, MDBBUILD );
Printf(" %s.%s", OS_RELEASE, OS_VERSION);
#ifdef MINIX_PC
#ifdef __i386
Printf(" (32-bit)");
#else
Printf(" (16-bit)");
#endif
#endif
#ifdef MINIX_ST
Printf("-ST");
#endif
Printf("\n");
}
/* Print help message on command */
PUBLIC void help_on(h)
int h;
{
switch (h) {
case '/':
outstr("<address> /nsf\t- Display for n items of size s with format f from address\n");
outstr("\t n defaults to 1\n");
outstr("\t s defaults to size of int\n");
outstr("\t can be b for byte h for short l for long\n");
outstr("\t f defaults to d for decimal\n");
outstr("\t can be x X o d D c s or u as in printf\n");
outstr("\t y treat value as address\n");
outstr("\t i disasm\n");
break;
case '@':
outstr("@ file\t- Execute commands from file\n");
break;
case '#':
outstr("# <address> cs value\t- Set Variable(s) at address to value\n");
outstr("\t\t\t for c count and size s\n");
outstr("\t\t\t b for byte h for short or l for long\n");
outstr("\t\t\t Count or size must be specified\n");
outstr("# $xx value\t\t- Set register $xx to value\n");
break;
case 'C':
outstr("C [n]\t- Continue with curent signal n times\n");
outstr("\t n defaults to 1\n");
break;
case 'c':
outstr("c [n]\t- Continue with no signal n times\n");
outstr("\t n defaults to 1\n");
break;
case 'e':
outstr("e [t]\t- List symbols for type t\n");
break;
case 's':
outstr("s [n]\t- Dump stack for n words\n");
outstr("\t n defaults to whole stack\n");
break;
case 'I':
outstr("I n\t- Single step with signal for n instructions n defaults to 1\n");
break;
case 'i':
outstr("i n\t- Single step with no signal for n instructions n defaults to 1\n");
break;
case 'M':
case 'm':
if ( h == 'M')
outstr("<address> M t n\t- Trace until\n");
else
outstr("<address> m t n\t- Stop when\n");
outstr("\t\t<address> is modified t type for n instructions\n");
outstr("\t\tn defaults to 1\n");
outstr("\t\tb for byte h for short l for long defaults to size of int\n");
break;
case 'T':
outstr("T\t- Display current call\n");
break;
case 't':
outstr("t\t- Backtrace all calls\n");
break;
case '!':
outstr("![command]\t- Shell escape or spawn command\n");
break;
case 'R':
outstr("R\t- Run the exec-file\n");
break;
case 'r':
outstr("r [arguments]\t- Run the exec-file with arguments\n");
break;
case 'k':
outstr("k\t- Kill traced process\n");
break;
case 'B':
outstr("B\t- Display all the Break points\n");
break;
case 'b':
outstr("<address> b [commands]\t- Set Break-pt at address\n");
outstr("\t\t\t commands will be executed by mdb at break-pt\n");
break;
case 'D':
outstr("D\t- Delete all break-points\n");
break;
case 'd':
outstr("<address> d\t- Delete one break-point at address\n");
break;
case 'q':
outstr("q\t- Quit mdb (and kill traced program)\n");
break;
case 'Q':
outstr("Q\t- Quit mdb immediately\n");
break;
case 'P':
outstr("P\t- Toggle Paging\n");
outstr("\t Defaults is OFF\n");
break;
case 'L':
outstr("L name\t- Log to file name\n");
outstr("L\t- Reset output to standard output\n");
break;
case 'l':
outstr("l name\t- Log to file name and standard output\n");
outstr("l\t- Reset output to standard output\n");
outstr("\t Defaults to none\n");
break;
#ifdef DEBUG
case 'v':
outstr("v\t- Toggle debug flag\n");
break;
#endif
case 'V':
outstr("V\t- Print Version Information for mdb\n");
break;
case 'X':
outstr("<address> X [n] [offset]\t- Disasm for n instructions\n");
outstr("\t\t\t Starting at address+offset\n");
break;
case 'x':
outstr("<address> x [n] offset\t- Disasm & display registers for n instructions\n");
outstr("\t\t\t Starting at address+offset\n");
break;
case 'y':
outstr("y\t- Print segment mappings\n");
break;
#if SYSCALLS_SUPPORT
case 'z':
outstr("z [address]\t- Trace system calls using address\n");
outstr("\t\t If the exec-file has symbols, mdb looks for __sendrec\n");
break;
#endif
default:
Printf("No help on command '%c' is available\n",h);
break;
}
}