db_command.c revision 1.50 1 1.50 sommerfe /* $NetBSD: db_command.c,v 1.50 2000/07/08 17:10:22 sommerfeld Exp $ */
2 1.12 cgd
3 1.1 cgd /*
4 1.1 cgd * Mach Operating System
5 1.1 cgd * Copyright (c) 1991,1990 Carnegie Mellon University
6 1.1 cgd * All Rights Reserved.
7 1.1 cgd *
8 1.1 cgd * Permission to use, copy, modify and distribute this software and its
9 1.1 cgd * documentation is hereby granted, provided that both the copyright
10 1.1 cgd * notice and this permission notice appear in all copies of the
11 1.1 cgd * software, derivative works or modified versions, and any portions
12 1.1 cgd * thereof, and that both notices appear in supporting documentation.
13 1.1 cgd *
14 1.30 pk * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 1.1 cgd * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 1.1 cgd * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 1.1 cgd *
18 1.1 cgd * Carnegie Mellon requests users of this software to return to
19 1.1 cgd *
20 1.1 cgd * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 1.1 cgd * School of Computer Science
22 1.1 cgd * Carnegie Mellon University
23 1.1 cgd * Pittsburgh PA 15213-3890
24 1.1 cgd *
25 1.1 cgd * any improvements or extensions that they make and grant Carnegie the
26 1.1 cgd * rights to redistribute these changes.
27 1.1 cgd */
28 1.25 mrg
29 1.27 tron #include "opt_ddb.h"
30 1.40 jhawk #include "opt_inet.h"
31 1.5 mycroft
32 1.1 cgd /*
33 1.1 cgd * Command dispatcher.
34 1.1 cgd */
35 1.7 mycroft #include <sys/param.h>
36 1.18 christos #include <sys/systm.h>
37 1.23 scottr #include <sys/reboot.h>
38 1.7 mycroft #include <sys/proc.h>
39 1.36 chs #include <sys/vnode.h>
40 1.31 thorpej #include <sys/pool.h>
41 1.15 gwr
42 1.1 cgd #include <machine/db_machdep.h> /* type definitions */
43 1.1 cgd
44 1.34 sommerfe #if defined(_KERNEL) && !defined(_LKM)
45 1.34 sommerfe #include "opt_multiprocessor.h"
46 1.34 sommerfe #endif
47 1.34 sommerfe #ifdef MULTIPROCESSOR
48 1.34 sommerfe #include <machine/cpu.h>
49 1.34 sommerfe #endif
50 1.34 sommerfe
51 1.1 cgd #include <ddb/db_lex.h>
52 1.1 cgd #include <ddb/db_output.h>
53 1.10 pk #include <ddb/db_command.h>
54 1.16 christos #include <ddb/db_break.h>
55 1.16 christos #include <ddb/db_watch.h>
56 1.16 christos #include <ddb/db_run.h>
57 1.16 christos #include <ddb/db_variables.h>
58 1.16 christos #include <ddb/db_interface.h>
59 1.16 christos #include <ddb/db_sym.h>
60 1.16 christos #include <ddb/db_extern.h>
61 1.1 cgd
62 1.24 mrg #include <uvm/uvm_extern.h>
63 1.26 jonathan #include <uvm/uvm_ddb.h>
64 1.24 mrg
65 1.46 jhawk #include "arp.h"
66 1.46 jhawk
67 1.1 cgd /*
68 1.1 cgd * Exported global variables
69 1.1 cgd */
70 1.1 cgd boolean_t db_cmd_loop_done;
71 1.17 gwr label_t *db_recover;
72 1.1 cgd
73 1.1 cgd /*
74 1.1 cgd * if 'ed' style: 'dot' is set at start of last item printed,
75 1.1 cgd * and '+' points to next line.
76 1.1 cgd * Otherwise: 'dot' points to next item, '..' points to last.
77 1.1 cgd */
78 1.1 cgd boolean_t db_ed_style = TRUE;
79 1.1 cgd
80 1.1 cgd /*
81 1.1 cgd * Utility routine - discard tokens through end-of-line.
82 1.1 cgd */
83 1.1 cgd void
84 1.1 cgd db_skip_to_eol()
85 1.1 cgd {
86 1.1 cgd int t;
87 1.1 cgd do {
88 1.1 cgd t = db_read_token();
89 1.1 cgd } while (t != tEOL);
90 1.1 cgd }
91 1.1 cgd
92 1.1 cgd /*
93 1.1 cgd * Results of command search.
94 1.1 cgd */
95 1.1 cgd #define CMD_UNIQUE 0
96 1.1 cgd #define CMD_FOUND 1
97 1.1 cgd #define CMD_NONE 2
98 1.1 cgd #define CMD_AMBIGUOUS 3
99 1.1 cgd #define CMD_HELP 4
100 1.1 cgd
101 1.1 cgd /*
102 1.1 cgd * Search for command prefix.
103 1.1 cgd */
104 1.1 cgd int
105 1.1 cgd db_cmd_search(name, table, cmdp)
106 1.10 pk char *name;
107 1.10 pk struct db_command *table;
108 1.10 pk struct db_command **cmdp; /* out */
109 1.1 cgd {
110 1.10 pk struct db_command *cmd;
111 1.10 pk int result = CMD_NONE;
112 1.1 cgd
113 1.1 cgd for (cmd = table; cmd->name != 0; cmd++) {
114 1.35 augustss char *lp;
115 1.35 augustss char *rp;
116 1.35 augustss int c;
117 1.1 cgd
118 1.1 cgd lp = name;
119 1.1 cgd rp = cmd->name;
120 1.1 cgd while ((c = *lp) == *rp) {
121 1.1 cgd if (c == 0) {
122 1.1 cgd /* complete match */
123 1.1 cgd *cmdp = cmd;
124 1.1 cgd return (CMD_UNIQUE);
125 1.1 cgd }
126 1.1 cgd lp++;
127 1.1 cgd rp++;
128 1.1 cgd }
129 1.1 cgd if (c == 0) {
130 1.1 cgd /* end of name, not end of command -
131 1.1 cgd partial match */
132 1.1 cgd if (result == CMD_FOUND) {
133 1.1 cgd result = CMD_AMBIGUOUS;
134 1.1 cgd /* but keep looking for a full match -
135 1.1 cgd this lets us match single letters */
136 1.1 cgd }
137 1.1 cgd else {
138 1.1 cgd *cmdp = cmd;
139 1.1 cgd result = CMD_FOUND;
140 1.1 cgd }
141 1.1 cgd }
142 1.1 cgd }
143 1.1 cgd if (result == CMD_NONE) {
144 1.1 cgd /* check for 'help' */
145 1.1 cgd if (name[0] == 'h' && name[1] == 'e'
146 1.1 cgd && name[2] == 'l' && name[3] == 'p')
147 1.1 cgd result = CMD_HELP;
148 1.1 cgd }
149 1.1 cgd return (result);
150 1.1 cgd }
151 1.1 cgd
152 1.1 cgd void
153 1.1 cgd db_cmd_list(table)
154 1.10 pk struct db_command *table;
155 1.1 cgd {
156 1.33 jdolecek int i, j, w, columns, lines, width=0, items, numcmds;
157 1.32 lukem char *p;
158 1.1 cgd
159 1.32 lukem for (numcmds = 0; table[numcmds].name != NULL; numcmds++) {
160 1.32 lukem w = strlen(table[numcmds].name);
161 1.32 lukem if (w > width)
162 1.32 lukem width = w;
163 1.32 lukem }
164 1.32 lukem width = DB_NEXT_TAB(width);
165 1.32 lukem items = 0;
166 1.32 lukem
167 1.32 lukem columns = db_max_width / width;
168 1.32 lukem if (columns == 0)
169 1.32 lukem columns = 1;
170 1.32 lukem lines = (numcmds + columns - 1) / columns;
171 1.32 lukem for (i = 0; i < lines; i++) {
172 1.32 lukem for (j = 0; j < columns; j++) {
173 1.32 lukem p = table[j * lines + i].name;
174 1.32 lukem if (p)
175 1.32 lukem db_printf("%s", p);
176 1.32 lukem if (j * lines + i + lines >= numcmds) {
177 1.32 lukem db_putchar('\n');
178 1.32 lukem break;
179 1.32 lukem }
180 1.32 lukem w = strlen(p);
181 1.32 lukem while (w < width) {
182 1.32 lukem w = DB_NEXT_TAB(w);
183 1.32 lukem db_putchar('\t');
184 1.32 lukem }
185 1.32 lukem }
186 1.1 cgd }
187 1.1 cgd }
188 1.1 cgd
189 1.1 cgd void
190 1.1 cgd db_command(last_cmdp, cmd_table)
191 1.10 pk struct db_command **last_cmdp; /* IN_OUT */
192 1.10 pk struct db_command *cmd_table;
193 1.1 cgd {
194 1.10 pk struct db_command *cmd;
195 1.1 cgd int t;
196 1.1 cgd char modif[TOK_STRING_SIZE];
197 1.1 cgd db_expr_t addr, count;
198 1.16 christos boolean_t have_addr = FALSE;
199 1.1 cgd int result;
200 1.1 cgd
201 1.38 jhawk static db_expr_t last_count = 0;
202 1.38 jhawk
203 1.1 cgd t = db_read_token();
204 1.38 jhawk if ((t == tEOL) || (t == tCOMMA)) {
205 1.38 jhawk /*
206 1.38 jhawk * An empty line repeats last command, at 'next'.
207 1.38 jhawk * Only a count repeats the last command with the new count.
208 1.38 jhawk */
209 1.1 cgd cmd = *last_cmdp;
210 1.1 cgd addr = (db_expr_t)db_next;
211 1.38 jhawk if (t == tCOMMA) {
212 1.38 jhawk if (!db_expression(&count)) {
213 1.48 jhawk db_printf("Count missing\n");
214 1.48 jhawk db_flush_lex();
215 1.48 jhawk return;
216 1.48 jhawk }
217 1.38 jhawk } else
218 1.48 jhawk count = last_count;
219 1.1 cgd have_addr = FALSE;
220 1.1 cgd modif[0] = '\0';
221 1.48 jhawk db_skip_to_eol();
222 1.1 cgd }
223 1.1 cgd else if (t == tEXCL) {
224 1.16 christos db_fncall(0, 0, 0, NULL);
225 1.1 cgd return;
226 1.1 cgd }
227 1.1 cgd else if (t != tIDENT) {
228 1.1 cgd db_printf("?\n");
229 1.1 cgd db_flush_lex();
230 1.1 cgd return;
231 1.1 cgd }
232 1.1 cgd else {
233 1.1 cgd /*
234 1.1 cgd * Search for command
235 1.1 cgd */
236 1.1 cgd while (cmd_table) {
237 1.1 cgd result = db_cmd_search(db_tok_string,
238 1.1 cgd cmd_table,
239 1.1 cgd &cmd);
240 1.1 cgd switch (result) {
241 1.1 cgd case CMD_NONE:
242 1.1 cgd db_printf("No such command\n");
243 1.1 cgd db_flush_lex();
244 1.1 cgd return;
245 1.1 cgd case CMD_AMBIGUOUS:
246 1.1 cgd db_printf("Ambiguous\n");
247 1.1 cgd db_flush_lex();
248 1.1 cgd return;
249 1.1 cgd case CMD_HELP:
250 1.1 cgd db_cmd_list(cmd_table);
251 1.1 cgd db_flush_lex();
252 1.1 cgd return;
253 1.1 cgd default:
254 1.1 cgd break;
255 1.1 cgd }
256 1.1 cgd if ((cmd_table = cmd->more) != 0) {
257 1.1 cgd t = db_read_token();
258 1.1 cgd if (t != tIDENT) {
259 1.1 cgd db_cmd_list(cmd_table);
260 1.1 cgd db_flush_lex();
261 1.1 cgd return;
262 1.1 cgd }
263 1.1 cgd }
264 1.1 cgd }
265 1.1 cgd
266 1.1 cgd if ((cmd->flag & CS_OWN) == 0) {
267 1.1 cgd /*
268 1.1 cgd * Standard syntax:
269 1.1 cgd * command [/modifier] [addr] [,count]
270 1.1 cgd */
271 1.1 cgd t = db_read_token();
272 1.1 cgd if (t == tSLASH) {
273 1.1 cgd t = db_read_token();
274 1.1 cgd if (t != tIDENT) {
275 1.1 cgd db_printf("Bad modifier\n");
276 1.1 cgd db_flush_lex();
277 1.1 cgd return;
278 1.1 cgd }
279 1.1 cgd db_strcpy(modif, db_tok_string);
280 1.1 cgd }
281 1.1 cgd else {
282 1.1 cgd db_unread_token(t);
283 1.1 cgd modif[0] = '\0';
284 1.1 cgd }
285 1.1 cgd
286 1.1 cgd if (db_expression(&addr)) {
287 1.1 cgd db_dot = (db_addr_t) addr;
288 1.1 cgd db_last_addr = db_dot;
289 1.1 cgd have_addr = TRUE;
290 1.1 cgd }
291 1.1 cgd else {
292 1.1 cgd addr = (db_expr_t) db_dot;
293 1.1 cgd have_addr = FALSE;
294 1.1 cgd }
295 1.1 cgd t = db_read_token();
296 1.1 cgd if (t == tCOMMA) {
297 1.1 cgd if (!db_expression(&count)) {
298 1.1 cgd db_printf("Count missing\n");
299 1.1 cgd db_flush_lex();
300 1.1 cgd return;
301 1.1 cgd }
302 1.1 cgd }
303 1.1 cgd else {
304 1.1 cgd db_unread_token(t);
305 1.1 cgd count = -1;
306 1.1 cgd }
307 1.1 cgd if ((cmd->flag & CS_MORE) == 0) {
308 1.1 cgd db_skip_to_eol();
309 1.1 cgd }
310 1.1 cgd }
311 1.1 cgd }
312 1.1 cgd *last_cmdp = cmd;
313 1.38 jhawk last_count = count;
314 1.1 cgd if (cmd != 0) {
315 1.1 cgd /*
316 1.1 cgd * Execute the command.
317 1.1 cgd */
318 1.1 cgd (*cmd->fcn)(addr, have_addr, count, modif);
319 1.1 cgd
320 1.1 cgd if (cmd->flag & CS_SET_DOT) {
321 1.1 cgd /*
322 1.1 cgd * If command changes dot, set dot to
323 1.1 cgd * previous address displayed (if 'ed' style).
324 1.1 cgd */
325 1.1 cgd if (db_ed_style) {
326 1.1 cgd db_dot = db_prev;
327 1.1 cgd }
328 1.1 cgd else {
329 1.1 cgd db_dot = db_next;
330 1.1 cgd }
331 1.1 cgd }
332 1.1 cgd else {
333 1.1 cgd /*
334 1.1 cgd * If command does not change dot,
335 1.1 cgd * set 'next' location to be the same.
336 1.1 cgd */
337 1.1 cgd db_next = db_dot;
338 1.1 cgd }
339 1.1 cgd }
340 1.1 cgd }
341 1.1 cgd
342 1.4 brezak /*ARGSUSED*/
343 1.4 brezak void
344 1.4 brezak db_map_print_cmd(addr, have_addr, count, modif)
345 1.4 brezak db_expr_t addr;
346 1.4 brezak int have_addr;
347 1.4 brezak db_expr_t count;
348 1.4 brezak char * modif;
349 1.4 brezak {
350 1.4 brezak boolean_t full = FALSE;
351 1.4 brezak
352 1.4 brezak if (modif[0] == 'f')
353 1.4 brezak full = TRUE;
354 1.4 brezak
355 1.24 mrg uvm_map_printit((vm_map_t) addr, full, db_printf);
356 1.4 brezak }
357 1.4 brezak
358 1.4 brezak /*ARGSUSED*/
359 1.4 brezak void
360 1.4 brezak db_object_print_cmd(addr, have_addr, count, modif)
361 1.4 brezak db_expr_t addr;
362 1.4 brezak int have_addr;
363 1.4 brezak db_expr_t count;
364 1.4 brezak char * modif;
365 1.4 brezak {
366 1.4 brezak boolean_t full = FALSE;
367 1.4 brezak
368 1.4 brezak if (modif[0] == 'f')
369 1.4 brezak full = TRUE;
370 1.4 brezak
371 1.24 mrg uvm_object_printit((struct uvm_object *) addr, full, db_printf);
372 1.24 mrg }
373 1.24 mrg
374 1.24 mrg /*ARGSUSED*/
375 1.24 mrg void
376 1.24 mrg db_page_print_cmd(addr, have_addr, count, modif)
377 1.24 mrg db_expr_t addr;
378 1.24 mrg int have_addr;
379 1.24 mrg db_expr_t count;
380 1.24 mrg char * modif;
381 1.24 mrg {
382 1.24 mrg boolean_t full = FALSE;
383 1.24 mrg
384 1.24 mrg if (modif[0] == 'f')
385 1.24 mrg full = TRUE;
386 1.24 mrg
387 1.24 mrg uvm_page_printit((struct vm_page *) addr, full, db_printf);
388 1.36 chs }
389 1.36 chs
390 1.36 chs /*ARGSUSED*/
391 1.36 chs void
392 1.36 chs db_buf_print_cmd(addr, have_addr, count, modif)
393 1.36 chs db_expr_t addr;
394 1.36 chs int have_addr;
395 1.36 chs db_expr_t count;
396 1.36 chs char * modif;
397 1.36 chs {
398 1.36 chs boolean_t full = FALSE;
399 1.36 chs
400 1.36 chs if (modif[0] == 'f')
401 1.36 chs full = TRUE;
402 1.36 chs
403 1.36 chs vfs_buf_print((struct buf *)addr, full, db_printf);
404 1.36 chs }
405 1.36 chs
406 1.36 chs /*ARGSUSED*/
407 1.36 chs void
408 1.36 chs db_vnode_print_cmd(addr, have_addr, count, modif)
409 1.36 chs db_expr_t addr;
410 1.36 chs int have_addr;
411 1.36 chs db_expr_t count;
412 1.36 chs char * modif;
413 1.36 chs {
414 1.36 chs boolean_t full = FALSE;
415 1.36 chs
416 1.36 chs if (modif[0] == 'f')
417 1.36 chs full = TRUE;
418 1.36 chs
419 1.36 chs vfs_vnode_print((struct vnode *)addr, full, db_printf);
420 1.4 brezak }
421 1.4 brezak
422 1.31 thorpej /*ARGSUSED*/
423 1.31 thorpej void
424 1.31 thorpej db_pool_print_cmd(addr, have_addr, count, modif)
425 1.31 thorpej db_expr_t addr;
426 1.31 thorpej int have_addr;
427 1.31 thorpej db_expr_t count;
428 1.31 thorpej char * modif;
429 1.31 thorpej {
430 1.31 thorpej
431 1.31 thorpej pool_printit((struct pool *) addr, modif, db_printf);
432 1.31 thorpej }
433 1.31 thorpej
434 1.1 cgd /*
435 1.1 cgd * 'show' commands
436 1.1 cgd */
437 1.1 cgd
438 1.10 pk struct db_command db_show_all_cmds[] = {
439 1.32 lukem { "callout", db_show_callout, 0, NULL },
440 1.16 christos { "procs", db_show_all_procs, 0, NULL },
441 1.16 christos { NULL, NULL, 0, NULL }
442 1.1 cgd };
443 1.1 cgd
444 1.10 pk struct db_command db_show_cmds[] = {
445 1.16 christos { "all", NULL, 0, db_show_all_cmds },
446 1.46 jhawk #if defined(INET) && (NARP > 0)
447 1.40 jhawk { "arptab", db_show_arptab, 0, NULL },
448 1.40 jhawk #endif
449 1.16 christos { "breaks", db_listbreak_cmd, 0, NULL },
450 1.16 christos { "map", db_map_print_cmd, 0, NULL },
451 1.16 christos { "object", db_object_print_cmd, 0, NULL },
452 1.24 mrg { "page", db_page_print_cmd, 0, NULL },
453 1.37 chs { "buf", db_buf_print_cmd, 0, NULL },
454 1.37 chs { "vnode", db_vnode_print_cmd, 0, NULL },
455 1.31 thorpej { "pool", db_pool_print_cmd, 0, NULL },
456 1.32 lukem { "registers", db_show_regs, 0, NULL },
457 1.32 lukem { "watches", db_listwatch_cmd, 0, NULL },
458 1.32 lukem { NULL, NULL, 0, NULL }
459 1.1 cgd };
460 1.1 cgd
461 1.10 pk struct db_command db_command_table[] = {
462 1.32 lukem { "break", db_breakpoint_cmd, 0, NULL },
463 1.32 lukem { "c", db_continue_cmd, 0, NULL },
464 1.32 lukem { "call", db_fncall, CS_OWN, NULL },
465 1.32 lukem { "callout", db_show_callout, 0, NULL },
466 1.32 lukem { "continue", db_continue_cmd, 0, NULL },
467 1.32 lukem { "d", db_delete_cmd, 0, NULL },
468 1.32 lukem { "delete", db_delete_cmd, 0, NULL },
469 1.32 lukem { "dwatch", db_deletewatch_cmd, 0, NULL },
470 1.32 lukem { "examine", db_examine_cmd, CS_SET_DOT, NULL },
471 1.32 lukem { "kill", db_kill_proc, CS_OWN, NULL },
472 1.6 brezak #ifdef DB_MACHINE_COMMANDS
473 1.32 lukem { "machine", NULL, 0, NULL },
474 1.6 brezak #endif
475 1.32 lukem { "match", db_trace_until_matching_cmd,0, NULL },
476 1.32 lukem { "next", db_trace_until_matching_cmd,0, NULL },
477 1.39 jhawk { "p", db_print_cmd, 0, NULL },
478 1.16 christos { "print", db_print_cmd, 0, NULL },
479 1.32 lukem { "ps", db_show_all_procs, 0, NULL },
480 1.32 lukem { "reboot", db_reboot_cmd, CS_OWN, NULL },
481 1.32 lukem { "s", db_single_step_cmd, 0, NULL },
482 1.16 christos { "search", db_search_cmd, CS_OWN|CS_SET_DOT, NULL },
483 1.16 christos { "set", db_set_cmd, CS_OWN, NULL },
484 1.32 lukem { "show", NULL, 0, db_show_cmds },
485 1.41 jhawk { "sifting", db_sifting_cmd, CS_OWN, NULL },
486 1.32 lukem { "step", db_single_step_cmd, 0, NULL },
487 1.32 lukem { "sync", db_sync_cmd, CS_OWN, NULL },
488 1.32 lukem { "trace", db_stack_trace_cmd, 0, NULL },
489 1.32 lukem { "until", db_trace_until_call_cmd,0, NULL },
490 1.16 christos { "w", db_write_cmd, CS_MORE|CS_SET_DOT, NULL },
491 1.16 christos { "watch", db_watchpoint_cmd, CS_MORE, NULL },
492 1.32 lukem { "write", db_write_cmd, CS_MORE|CS_SET_DOT, NULL },
493 1.32 lukem { "x", db_examine_cmd, CS_SET_DOT, NULL },
494 1.16 christos { NULL, NULL, 0, NULL }
495 1.1 cgd };
496 1.6 brezak
497 1.6 brezak #ifdef DB_MACHINE_COMMANDS
498 1.6 brezak
499 1.32 lukem /*
500 1.32 lukem * this function should be called to install the machine dependent
501 1.32 lukem * commands. It should be called before the debugger is enabled
502 1.32 lukem */
503 1.32 lukem void
504 1.32 lukem db_machine_commands_install(ptr)
505 1.32 lukem struct db_command *ptr;
506 1.6 brezak {
507 1.32 lukem struct db_command *cmd;
508 1.32 lukem
509 1.32 lukem for (cmd = db_command_table; cmd != 0; cmd++) {
510 1.32 lukem if (strcmp(cmd->name, "machine") == 0) {
511 1.32 lukem cmd->more = ptr;
512 1.32 lukem break;
513 1.32 lukem }
514 1.32 lukem }
515 1.6 brezak }
516 1.6 brezak
517 1.6 brezak #endif
518 1.1 cgd
519 1.10 pk struct db_command *db_last_command = 0;
520 1.1 cgd
521 1.1 cgd void
522 1.1 cgd db_command_loop()
523 1.1 cgd {
524 1.17 gwr label_t db_jmpbuf;
525 1.17 gwr label_t *savejmp;
526 1.8 mycroft extern int db_output_line;
527 1.4 brezak
528 1.1 cgd /*
529 1.1 cgd * Initialize 'prev' and 'next' to dot.
530 1.1 cgd */
531 1.1 cgd db_prev = db_dot;
532 1.1 cgd db_next = db_dot;
533 1.1 cgd
534 1.1 cgd db_cmd_loop_done = 0;
535 1.17 gwr
536 1.17 gwr savejmp = db_recover;
537 1.17 gwr db_recover = &db_jmpbuf;
538 1.17 gwr (void) setjmp(&db_jmpbuf);
539 1.8 mycroft
540 1.1 cgd while (!db_cmd_loop_done) {
541 1.8 mycroft if (db_print_position() != 0)
542 1.8 mycroft db_printf("\n");
543 1.8 mycroft db_output_line = 0;
544 1.1 cgd
545 1.44 sommerfe
546 1.34 sommerfe #ifdef MULTIPROCESSOR
547 1.44 sommerfe db_printf("db{%ld}> ", (long)cpu_number());
548 1.44 sommerfe #else
549 1.44 sommerfe db_printf("db> ");
550 1.34 sommerfe #endif
551 1.8 mycroft (void) db_read_line();
552 1.1 cgd
553 1.8 mycroft db_command(&db_last_command, db_command_table);
554 1.8 mycroft }
555 1.1 cgd
556 1.8 mycroft db_recover = savejmp;
557 1.1 cgd }
558 1.1 cgd
559 1.1 cgd void
560 1.1 cgd db_error(s)
561 1.1 cgd char *s;
562 1.1 cgd {
563 1.1 cgd if (s)
564 1.50 sommerfe db_printf("%s", s);
565 1.1 cgd db_flush_lex();
566 1.19 christos longjmp(db_recover);
567 1.1 cgd }
568 1.1 cgd
569 1.1 cgd
570 1.1 cgd /*
571 1.1 cgd * Call random function:
572 1.1 cgd * !expr(arg,arg,arg)
573 1.1 cgd */
574 1.16 christos /*ARGSUSED*/
575 1.1 cgd void
576 1.16 christos db_fncall(addr, have_addr, count, modif)
577 1.16 christos db_expr_t addr;
578 1.16 christos int have_addr;
579 1.16 christos db_expr_t count;
580 1.16 christos char * modif;
581 1.1 cgd {
582 1.1 cgd db_expr_t fn_addr;
583 1.1 cgd #define MAXARGS 11
584 1.1 cgd db_expr_t args[MAXARGS];
585 1.1 cgd int nargs = 0;
586 1.1 cgd db_expr_t retval;
587 1.16 christos db_expr_t (*func) __P((db_expr_t, ...));
588 1.1 cgd int t;
589 1.1 cgd
590 1.1 cgd if (!db_expression(&fn_addr)) {
591 1.1 cgd db_printf("Bad function\n");
592 1.1 cgd db_flush_lex();
593 1.1 cgd return;
594 1.1 cgd }
595 1.16 christos func = (db_expr_t (*) __P((db_expr_t, ...))) fn_addr;
596 1.1 cgd
597 1.1 cgd t = db_read_token();
598 1.1 cgd if (t == tLPAREN) {
599 1.1 cgd if (db_expression(&args[0])) {
600 1.1 cgd nargs++;
601 1.1 cgd while ((t = db_read_token()) == tCOMMA) {
602 1.1 cgd if (nargs == MAXARGS) {
603 1.1 cgd db_printf("Too many arguments\n");
604 1.1 cgd db_flush_lex();
605 1.1 cgd return;
606 1.1 cgd }
607 1.1 cgd if (!db_expression(&args[nargs])) {
608 1.1 cgd db_printf("Argument missing\n");
609 1.1 cgd db_flush_lex();
610 1.1 cgd return;
611 1.1 cgd }
612 1.1 cgd nargs++;
613 1.1 cgd }
614 1.1 cgd db_unread_token(t);
615 1.1 cgd }
616 1.1 cgd if (db_read_token() != tRPAREN) {
617 1.1 cgd db_printf("?\n");
618 1.1 cgd db_flush_lex();
619 1.1 cgd return;
620 1.1 cgd }
621 1.1 cgd }
622 1.1 cgd db_skip_to_eol();
623 1.1 cgd
624 1.1 cgd while (nargs < MAXARGS) {
625 1.1 cgd args[nargs++] = 0;
626 1.1 cgd }
627 1.1 cgd
628 1.1 cgd retval = (*func)(args[0], args[1], args[2], args[3], args[4],
629 1.20 christos args[5], args[6], args[7], args[8], args[9]);
630 1.45 jhawk db_printf("%s\n", db_num_to_str(retval));
631 1.23 scottr }
632 1.23 scottr
633 1.23 scottr void
634 1.23 scottr db_reboot_cmd(addr, have_addr, count, modif)
635 1.23 scottr db_expr_t addr;
636 1.23 scottr int have_addr;
637 1.23 scottr db_expr_t count;
638 1.23 scottr char * modif;
639 1.23 scottr {
640 1.23 scottr db_expr_t bootflags;
641 1.23 scottr
642 1.23 scottr /* Flags, default to RB_AUTOBOOT */
643 1.23 scottr if (!db_expression(&bootflags))
644 1.23 scottr bootflags = (db_expr_t)RB_AUTOBOOT;
645 1.23 scottr if (db_read_token() != tEOL) {
646 1.23 scottr db_error("?\n");
647 1.23 scottr /*NOTREACHED*/
648 1.23 scottr }
649 1.47 sommerfe /*
650 1.47 sommerfe * We are leaving DDB, never to return upward.
651 1.47 sommerfe * Clear db_recover so that we can debug faults in functions
652 1.47 sommerfe * called from cpu_reboot.
653 1.47 sommerfe */
654 1.47 sommerfe db_recover = 0;
655 1.23 scottr cpu_reboot((int)bootflags, NULL);
656 1.41 jhawk }
657 1.41 jhawk
658 1.41 jhawk void
659 1.41 jhawk db_sifting_cmd(addr, have_addr, count, omodif)
660 1.41 jhawk db_expr_t addr;
661 1.41 jhawk int have_addr;
662 1.41 jhawk db_expr_t count;
663 1.41 jhawk char * omodif;
664 1.41 jhawk {
665 1.41 jhawk int mode, t;
666 1.41 jhawk
667 1.41 jhawk t = db_read_token();
668 1.41 jhawk if (t == tSLASH) {
669 1.41 jhawk t = db_read_token();
670 1.41 jhawk if (t != tIDENT) {
671 1.41 jhawk bad_modifier:
672 1.41 jhawk db_printf("Bad modifier\n");
673 1.41 jhawk db_flush_lex();
674 1.41 jhawk return;
675 1.41 jhawk }
676 1.41 jhawk if (!strcmp(db_tok_string, "F"))
677 1.41 jhawk mode = 'F';
678 1.41 jhawk else
679 1.41 jhawk goto bad_modifier;
680 1.41 jhawk t = db_read_token();
681 1.41 jhawk } else
682 1.41 jhawk mode = 0;
683 1.41 jhawk
684 1.41 jhawk if (t==tIDENT)
685 1.41 jhawk db_sifting(db_tok_string, mode);
686 1.41 jhawk else {
687 1.41 jhawk db_printf("Bad argument (non-string)\n");
688 1.41 jhawk db_flush_lex();
689 1.41 jhawk }
690 1.43 jhawk }
691 1.43 jhawk
692 1.43 jhawk void
693 1.43 jhawk db_stack_trace_cmd(addr, have_addr, count, modif)
694 1.43 jhawk db_expr_t addr;
695 1.43 jhawk boolean_t have_addr;
696 1.43 jhawk db_expr_t count;
697 1.43 jhawk char *modif;
698 1.43 jhawk {
699 1.43 jhawk if (count == -1)
700 1.43 jhawk count = 65535;
701 1.43 jhawk
702 1.43 jhawk db_stack_trace_print(addr, have_addr, count, modif, db_printf);
703 1.32 lukem }
704 1.32 lukem
705 1.32 lukem void
706 1.32 lukem db_sync_cmd(addr, have_addr, count, modif)
707 1.32 lukem db_expr_t addr;
708 1.32 lukem int have_addr;
709 1.32 lukem db_expr_t count;
710 1.32 lukem char * modif;
711 1.32 lukem {
712 1.47 sommerfe /*
713 1.47 sommerfe * We are leaving DDB, never to return upward.
714 1.47 sommerfe * Clear db_recover so that we can debug faults in functions
715 1.47 sommerfe * called from cpu_reboot.
716 1.47 sommerfe */
717 1.47 sommerfe db_recover = 0;
718 1.32 lukem cpu_reboot(RB_DUMP, NULL);
719 1.1 cgd }
720