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