10 #include <sys/param.h>
11 #define ptrace mdbtrace
12 #include <sys/ptrace.h>
15 static void pr_ascii(long val
, int size
);
18 static void pr_ascii(val
, size
)
32 for (i
= 0; i
< size
; i
++) {
33 v
= (int) (val
>> sh
) & 0xFF;
39 Printf(isprint(v
) ? "%c" : "\\%03o", v
);
52 size
= INTSIZE
; /* size of stack element */
54 if (num
<= 0) num
= 0;
55 if (num
> sk_size
) num
= (int) sk_size
/ size
;
56 nmode
= num
; /* Save mode */
59 sp
= get_reg(curpid
, reg_addr("sp"));
61 /* Starting address is top of stack seg -1 */
62 vi
= (vir_bytes
) sk_addr
+ (vir_bytes
) sk_size
- size
;
65 v
= (vir_bytes
) end_addr
;
66 if (nmode
== 0) v
= MAX(v
, sp
);
68 Printf("Stack Dump SP=%*lx\nAddr\tHex\tAscii\n", 2 * size
, sp
);
70 val
= (ptrace(T_GETDATA
, curpid
, (long) vi
, 0L) >> SHIFT(size
))
72 Printf("%*lx\t", 2 * ADDRSIZE
, (vi
>> SHIFT(ADDRSIZE
))
74 Printf("%*lx\t", 2 * size
, val
);
78 } while (vi
>= v
&& (nmode
? num
> 0 : 1));
89 if(fstat(fd
,&st
) <0 ) {
90 Printf("Cannot stat\n");
100 outstr("\nHelp for mdb. For more details, type 'command ?'\n");
101 outstr("!#\t- Shell escape / Set Variable or register\n");
102 outstr("Tt\t- Current call / Backtrace all\n");
103 outstr("/nsf\t- Display for n size s with format f\n");
104 outstr("Xx [n]\t- Disasm / & display reg for n instructions\n");
105 outstr("Rr a\t- Run / with arguments a\n");
106 outstr("Cc [n]\t- Continue with current signal / no signal n times\n");
107 outstr("Ii [n]\t- Single step with / no signal for n instructions\n");
108 outstr("Mm t n\t- Trace until / Stop when modified t type for n instructions\n");
109 outstr("k \t- Kill traced process\n");
110 outstr("Bb\t- Display / Set Break-pt\n");
111 outstr("Dd\t- Delete all / one break-points\n");
112 outstr("P\t- Toggle Paging\n");
113 outstr("Ll name\t- Log to file name / and to standard output\n");
115 outstr("Vv\t- Version info / Toggle debug flag\n");
117 outstr("V\t- Version info\n");
119 outstr("e [t]\t- List symbols for type t\n");
120 outstr("y\t- Print segment mappings\n");
121 outstr("s [n]\t- Dump stack for n words\n");
123 outstr("z [a]\t- Trace syscalls with address a\n");
125 outstr("? \t- Help - this screen\n");
126 outstr("@ file\t- Execute commands from file\n");
127 outstr("Qq\t- Quit / and kill traced process\n");
129 outstr("Usage: mdb -x debug-level [-Ll]logfile exec-file core-file @command-file\n");
131 outstr("Usage: mdb [-Ll]logfile exec-file core-file @command-file\n");
133 outstr(" mdb [-fc] file\n");
138 Printf("\nmdb version %s.%d for Minix", MDBVERSION
, MDBBUILD
);
139 Printf(" %s.%s", OS_RELEASE
, OS_VERSION
);
153 /* Print help message on command */
160 outstr("<address> /nsf\t- Display for n items of size s with format f from address\n");
161 outstr("\t n defaults to 1\n");
162 outstr("\t s defaults to size of int\n");
163 outstr("\t can be b for byte h for short l for long\n");
164 outstr("\t f defaults to d for decimal\n");
165 outstr("\t can be x X o d D c s or u as in printf\n");
166 outstr("\t y treat value as address\n");
167 outstr("\t i disasm\n");
170 outstr("@ file\t- Execute commands from file\n");
173 outstr("# <address> cs value\t- Set Variable(s) at address to value\n");
174 outstr("\t\t\t for c count and size s\n");
175 outstr("\t\t\t b for byte h for short or l for long\n");
176 outstr("\t\t\t Count or size must be specified\n");
177 outstr("# $xx value\t\t- Set register $xx to value\n");
180 outstr("C [n]\t- Continue with curent signal n times\n");
181 outstr("\t n defaults to 1\n");
184 outstr("c [n]\t- Continue with no signal n times\n");
185 outstr("\t n defaults to 1\n");
188 outstr("e [t]\t- List symbols for type t\n");
191 outstr("s [n]\t- Dump stack for n words\n");
192 outstr("\t n defaults to whole stack\n");
195 outstr("I n\t- Single step with signal for n instructions n defaults to 1\n");
198 outstr("i n\t- Single step with no signal for n instructions n defaults to 1\n");
203 outstr("<address> M t n\t- Trace until\n");
205 outstr("<address> m t n\t- Stop when\n");
206 outstr("\t\t<address> is modified t type for n instructions\n");
207 outstr("\t\tn defaults to 1\n");
208 outstr("\t\tb for byte h for short l for long defaults to size of int\n");
211 outstr("T\t- Display current call\n");
214 outstr("t\t- Backtrace all calls\n");
217 outstr("![command]\t- Shell escape or spawn command\n");
220 outstr("R\t- Run the exec-file\n");
223 outstr("r [arguments]\t- Run the exec-file with arguments\n");
226 outstr("k\t- Kill traced process\n");
229 outstr("B\t- Display all the Break points\n");
232 outstr("<address> b [commands]\t- Set Break-pt at address\n");
233 outstr("\t\t\t commands will be executed by mdb at break-pt\n");
236 outstr("D\t- Delete all break-points\n");
239 outstr("<address> d\t- Delete one break-point at address\n");
242 outstr("q\t- Quit mdb (and kill traced program)\n");
245 outstr("Q\t- Quit mdb immediately\n");
248 outstr("P\t- Toggle Paging\n");
249 outstr("\t Defaults is OFF\n");
252 outstr("L name\t- Log to file name\n");
253 outstr("L\t- Reset output to standard output\n");
256 outstr("l name\t- Log to file name and standard output\n");
257 outstr("l\t- Reset output to standard output\n");
258 outstr("\t Defaults to none\n");
262 outstr("v\t- Toggle debug flag\n");
266 outstr("V\t- Print Version Information for mdb\n");
269 outstr("<address> X [n] [offset]\t- Disasm for n instructions\n");
270 outstr("\t\t\t Starting at address+offset\n");
273 outstr("<address> x [n] offset\t- Disasm & display registers for n instructions\n");
274 outstr("\t\t\t Starting at address+offset\n");
277 outstr("y\t- Print segment mappings\n");
281 outstr("z [address]\t- Trace system calls using address\n");
282 outstr("\t\t If the exec-file has symbols, mdb looks for __sendrec\n");
286 Printf("No help on command '%c' is available\n",h
);