10 #define ptrace mdbtrace
11 #include <sys/ptrace.h>
14 FORWARD
_PROTOTYPE( void pr_ascii
, (long val
, int size
));
17 PRIVATE
void pr_ascii(val
, size
)
31 for (i
= 0; i
< size
; i
++) {
32 v
= (int) (val
>> sh
) & 0xFF;
38 Printf(isprint(v
) ? "%c" : "\\%03o", v
);
44 PUBLIC
void dump_stack(cnt
)
51 size
= INTSIZE
; /* size of stack element */
53 if (num
<= 0) num
= 0;
54 if (num
> sk_size
) num
= (int) sk_size
/ size
;
55 nmode
= num
; /* Save mode */
58 sp
= get_reg(curpid
, reg_addr("sp"));
60 /* Starting address is top of stack seg -1 */
61 vi
= (vir_bytes
) sk_addr
+ (vir_bytes
) sk_size
- size
;
64 v
= (vir_bytes
) end_addr
;
65 if (nmode
== 0) v
= MAX(v
, sp
);
67 Printf("Stack Dump SP=%*lx\nAddr\tHex\tAscii\n", 2 * size
, sp
);
69 val
= (ptrace(T_GETDATA
, curpid
, (long) vi
, 0L) >> SHIFT(size
))
71 Printf("%*lx\t", 2 * ADDRSIZE
, (vi
>> SHIFT(ADDRSIZE
))
73 Printf("%*lx\t", 2 * size
, val
);
77 } while (vi
>= v
&& (nmode
? num
> 0 : 1));
83 PUBLIC off_t
file_size(fd
)
88 if(fstat(fd
,&st
) <0 ) {
89 Printf("Cannot stat\n");
97 PUBLIC
void help_page()
99 outstr("\nHelp for mdb. For more details, type 'command ?'\n");
100 outstr("!#\t- Shell escape / Set Variable or register\n");
101 outstr("Tt\t- Current call / Backtrace all\n");
102 outstr("/nsf\t- Display for n size s with format f\n");
103 outstr("Xx [n]\t- Disasm / & display reg for n instructions\n");
104 outstr("Rr a\t- Run / with arguments a\n");
105 outstr("Cc [n]\t- Continue with current signal / no signal n times\n");
106 outstr("Ii [n]\t- Single step with / no signal for n instructions\n");
107 outstr("Mm t n\t- Trace until / Stop when modified t type for n instructions\n");
108 outstr("k \t- Kill traced process\n");
109 outstr("Bb\t- Display / Set Break-pt\n");
110 outstr("Dd\t- Delete all / one break-points\n");
111 outstr("P\t- Toggle Paging\n");
112 outstr("Ll name\t- Log to file name / and to standard output\n");
114 outstr("Vv\t- Version info / Toggle debug flag\n");
116 outstr("V\t- Version info\n");
118 outstr("e [t]\t- List symbols for type t\n");
119 outstr("y\t- Print segment mappings\n");
120 outstr("s [n]\t- Dump stack for n words\n");
122 outstr("z [a]\t- Trace syscalls with address a\n");
124 outstr("? \t- Help - this screen\n");
125 outstr("@ file\t- Execute commands from file\n");
126 outstr("Qq\t- Quit / and kill traced process\n");
128 outstr("Usage: mdb -x debug-level [-Ll]logfile exec-file core-file @command-file\n");
130 outstr("Usage: mdb [-Ll]logfile exec-file core-file @command-file\n");
132 outstr(" mdb [-fc] file\n");
135 PUBLIC
void version_info()
137 Printf("\nmdb version %s.%d for Minix", MDBVERSION
, MDBBUILD
);
138 Printf(" %s.%s", OS_RELEASE
, OS_VERSION
);
152 /* Print help message on command */
153 PUBLIC
void help_on(h
)
159 outstr("<address> /nsf\t- Display for n items of size s with format f from address\n");
160 outstr("\t n defaults to 1\n");
161 outstr("\t s defaults to size of int\n");
162 outstr("\t can be b for byte h for short l for long\n");
163 outstr("\t f defaults to d for decimal\n");
164 outstr("\t can be x X o d D c s or u as in printf\n");
165 outstr("\t y treat value as address\n");
166 outstr("\t i disasm\n");
169 outstr("@ file\t- Execute commands from file\n");
172 outstr("# <address> cs value\t- Set Variable(s) at address to value\n");
173 outstr("\t\t\t for c count and size s\n");
174 outstr("\t\t\t b for byte h for short or l for long\n");
175 outstr("\t\t\t Count or size must be specified\n");
176 outstr("# $xx value\t\t- Set register $xx to value\n");
179 outstr("C [n]\t- Continue with curent signal n times\n");
180 outstr("\t n defaults to 1\n");
183 outstr("c [n]\t- Continue with no signal n times\n");
184 outstr("\t n defaults to 1\n");
187 outstr("e [t]\t- List symbols for type t\n");
190 outstr("s [n]\t- Dump stack for n words\n");
191 outstr("\t n defaults to whole stack\n");
194 outstr("I n\t- Single step with signal for n instructions n defaults to 1\n");
197 outstr("i n\t- Single step with no signal for n instructions n defaults to 1\n");
202 outstr("<address> M t n\t- Trace until\n");
204 outstr("<address> m t n\t- Stop when\n");
205 outstr("\t\t<address> is modified t type for n instructions\n");
206 outstr("\t\tn defaults to 1\n");
207 outstr("\t\tb for byte h for short l for long defaults to size of int\n");
210 outstr("T\t- Display current call\n");
213 outstr("t\t- Backtrace all calls\n");
216 outstr("![command]\t- Shell escape or spawn command\n");
219 outstr("R\t- Run the exec-file\n");
222 outstr("r [arguments]\t- Run the exec-file with arguments\n");
225 outstr("k\t- Kill traced process\n");
228 outstr("B\t- Display all the Break points\n");
231 outstr("<address> b [commands]\t- Set Break-pt at address\n");
232 outstr("\t\t\t commands will be executed by mdb at break-pt\n");
235 outstr("D\t- Delete all break-points\n");
238 outstr("<address> d\t- Delete one break-point at address\n");
241 outstr("q\t- Quit mdb (and kill traced program)\n");
244 outstr("Q\t- Quit mdb immediately\n");
247 outstr("P\t- Toggle Paging\n");
248 outstr("\t Defaults is OFF\n");
251 outstr("L name\t- Log to file name\n");
252 outstr("L\t- Reset output to standard output\n");
255 outstr("l name\t- Log to file name and standard output\n");
256 outstr("l\t- Reset output to standard output\n");
257 outstr("\t Defaults to none\n");
261 outstr("v\t- Toggle debug flag\n");
265 outstr("V\t- Print Version Information for mdb\n");
268 outstr("<address> X [n] [offset]\t- Disasm for n instructions\n");
269 outstr("\t\t\t Starting at address+offset\n");
272 outstr("<address> x [n] offset\t- Disasm & display registers for n instructions\n");
273 outstr("\t\t\t Starting at address+offset\n");
276 outstr("y\t- Print segment mappings\n");
280 outstr("z [address]\t- Trace system calls using address\n");
281 outstr("\t\t If the exec-file has symbols, mdb looks for __sendrec\n");
285 Printf("No help on command '%c' is available\n",h
);