db_command.c revision 1.37 1 1.37 chs /* $NetBSD: db_command.c,v 1.37 2000/04/11 02:21:16 chs 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.5 mycroft
31 1.1 cgd /*
32 1.1 cgd * Command dispatcher.
33 1.1 cgd */
34 1.7 mycroft #include <sys/param.h>
35 1.18 christos #include <sys/systm.h>
36 1.23 scottr #include <sys/reboot.h>
37 1.7 mycroft #include <sys/proc.h>
38 1.36 chs #include <sys/vnode.h>
39 1.31 thorpej #include <sys/pool.h>
40 1.15 gwr
41 1.1 cgd #include <machine/db_machdep.h> /* type definitions */
42 1.1 cgd
43 1.34 sommerfe #if defined(_KERNEL) && !defined(_LKM)
44 1.34 sommerfe #include "opt_multiprocessor.h"
45 1.34 sommerfe #endif
46 1.34 sommerfe #ifdef MULTIPROCESSOR
47 1.34 sommerfe #include <machine/cpu.h>
48 1.34 sommerfe #endif
49 1.34 sommerfe
50 1.1 cgd #include <ddb/db_lex.h>
51 1.1 cgd #include <ddb/db_output.h>
52 1.10 pk #include <ddb/db_command.h>
53 1.16 christos #include <ddb/db_break.h>
54 1.16 christos #include <ddb/db_watch.h>
55 1.16 christos #include <ddb/db_run.h>
56 1.16 christos #include <ddb/db_variables.h>
57 1.16 christos #include <ddb/db_interface.h>
58 1.16 christos #include <ddb/db_sym.h>
59 1.16 christos #include <ddb/db_extern.h>
60 1.16 christos
61 1.16 christos #include <vm/vm.h>
62 1.1 cgd
63 1.24 mrg #include <uvm/uvm_extern.h>
64 1.26 jonathan #include <uvm/uvm_ddb.h>
65 1.24 mrg
66 1.1 cgd /*
67 1.1 cgd * Exported global variables
68 1.1 cgd */
69 1.1 cgd boolean_t db_cmd_loop_done;
70 1.17 gwr label_t *db_recover;
71 1.1 cgd
72 1.1 cgd /*
73 1.1 cgd * if 'ed' style: 'dot' is set at start of last item printed,
74 1.1 cgd * and '+' points to next line.
75 1.1 cgd * Otherwise: 'dot' points to next item, '..' points to last.
76 1.1 cgd */
77 1.1 cgd boolean_t db_ed_style = TRUE;
78 1.1 cgd
79 1.1 cgd /*
80 1.1 cgd * Utility routine - discard tokens through end-of-line.
81 1.1 cgd */
82 1.1 cgd void
83 1.1 cgd db_skip_to_eol()
84 1.1 cgd {
85 1.1 cgd int t;
86 1.1 cgd do {
87 1.1 cgd t = db_read_token();
88 1.1 cgd } while (t != tEOL);
89 1.1 cgd }
90 1.1 cgd
91 1.1 cgd /*
92 1.1 cgd * Results of command search.
93 1.1 cgd */
94 1.1 cgd #define CMD_UNIQUE 0
95 1.1 cgd #define CMD_FOUND 1
96 1.1 cgd #define CMD_NONE 2
97 1.1 cgd #define CMD_AMBIGUOUS 3
98 1.1 cgd #define CMD_HELP 4
99 1.1 cgd
100 1.1 cgd /*
101 1.1 cgd * Search for command prefix.
102 1.1 cgd */
103 1.1 cgd int
104 1.1 cgd db_cmd_search(name, table, cmdp)
105 1.10 pk char *name;
106 1.10 pk struct db_command *table;
107 1.10 pk struct db_command **cmdp; /* out */
108 1.1 cgd {
109 1.10 pk struct db_command *cmd;
110 1.10 pk int result = CMD_NONE;
111 1.1 cgd
112 1.1 cgd for (cmd = table; cmd->name != 0; cmd++) {
113 1.35 augustss char *lp;
114 1.35 augustss char *rp;
115 1.35 augustss int c;
116 1.1 cgd
117 1.1 cgd lp = name;
118 1.1 cgd rp = cmd->name;
119 1.1 cgd while ((c = *lp) == *rp) {
120 1.1 cgd if (c == 0) {
121 1.1 cgd /* complete match */
122 1.1 cgd *cmdp = cmd;
123 1.1 cgd return (CMD_UNIQUE);
124 1.1 cgd }
125 1.1 cgd lp++;
126 1.1 cgd rp++;
127 1.1 cgd }
128 1.1 cgd if (c == 0) {
129 1.1 cgd /* end of name, not end of command -
130 1.1 cgd partial match */
131 1.1 cgd if (result == CMD_FOUND) {
132 1.1 cgd result = CMD_AMBIGUOUS;
133 1.1 cgd /* but keep looking for a full match -
134 1.1 cgd this lets us match single letters */
135 1.1 cgd }
136 1.1 cgd else {
137 1.1 cgd *cmdp = cmd;
138 1.1 cgd result = CMD_FOUND;
139 1.1 cgd }
140 1.1 cgd }
141 1.1 cgd }
142 1.1 cgd if (result == CMD_NONE) {
143 1.1 cgd /* check for 'help' */
144 1.1 cgd if (name[0] == 'h' && name[1] == 'e'
145 1.1 cgd && name[2] == 'l' && name[3] == 'p')
146 1.1 cgd result = CMD_HELP;
147 1.1 cgd }
148 1.1 cgd return (result);
149 1.1 cgd }
150 1.1 cgd
151 1.1 cgd void
152 1.1 cgd db_cmd_list(table)
153 1.10 pk struct db_command *table;
154 1.1 cgd {
155 1.33 jdolecek int i, j, w, columns, lines, width=0, items, numcmds;
156 1.32 lukem char *p;
157 1.1 cgd
158 1.32 lukem for (numcmds = 0; table[numcmds].name != NULL; numcmds++) {
159 1.32 lukem w = strlen(table[numcmds].name);
160 1.32 lukem if (w > width)
161 1.32 lukem width = w;
162 1.32 lukem }
163 1.32 lukem width = DB_NEXT_TAB(width);
164 1.32 lukem items = 0;
165 1.32 lukem
166 1.32 lukem columns = db_max_width / width;
167 1.32 lukem if (columns == 0)
168 1.32 lukem columns = 1;
169 1.32 lukem lines = (numcmds + columns - 1) / columns;
170 1.32 lukem for (i = 0; i < lines; i++) {
171 1.32 lukem for (j = 0; j < columns; j++) {
172 1.32 lukem p = table[j * lines + i].name;
173 1.32 lukem if (p)
174 1.32 lukem db_printf("%s", p);
175 1.32 lukem if (j * lines + i + lines >= numcmds) {
176 1.32 lukem db_putchar('\n');
177 1.32 lukem break;
178 1.32 lukem }
179 1.32 lukem w = strlen(p);
180 1.32 lukem while (w < width) {
181 1.32 lukem w = DB_NEXT_TAB(w);
182 1.32 lukem db_putchar('\t');
183 1.32 lukem }
184 1.32 lukem }
185 1.1 cgd }
186 1.1 cgd }
187 1.1 cgd
188 1.1 cgd void
189 1.1 cgd db_command(last_cmdp, cmd_table)
190 1.10 pk struct db_command **last_cmdp; /* IN_OUT */
191 1.10 pk struct db_command *cmd_table;
192 1.1 cgd {
193 1.10 pk struct db_command *cmd;
194 1.1 cgd int t;
195 1.1 cgd char modif[TOK_STRING_SIZE];
196 1.1 cgd db_expr_t addr, count;
197 1.16 christos boolean_t have_addr = FALSE;
198 1.1 cgd int result;
199 1.1 cgd
200 1.1 cgd t = db_read_token();
201 1.1 cgd if (t == tEOL) {
202 1.1 cgd /* empty line repeats last command, at 'next' */
203 1.1 cgd cmd = *last_cmdp;
204 1.1 cgd addr = (db_expr_t)db_next;
205 1.1 cgd have_addr = FALSE;
206 1.1 cgd count = 1;
207 1.1 cgd modif[0] = '\0';
208 1.1 cgd }
209 1.1 cgd else if (t == tEXCL) {
210 1.16 christos db_fncall(0, 0, 0, NULL);
211 1.1 cgd return;
212 1.1 cgd }
213 1.1 cgd else if (t != tIDENT) {
214 1.1 cgd db_printf("?\n");
215 1.1 cgd db_flush_lex();
216 1.1 cgd return;
217 1.1 cgd }
218 1.1 cgd else {
219 1.1 cgd /*
220 1.1 cgd * Search for command
221 1.1 cgd */
222 1.1 cgd while (cmd_table) {
223 1.1 cgd result = db_cmd_search(db_tok_string,
224 1.1 cgd cmd_table,
225 1.1 cgd &cmd);
226 1.1 cgd switch (result) {
227 1.1 cgd case CMD_NONE:
228 1.1 cgd db_printf("No such command\n");
229 1.1 cgd db_flush_lex();
230 1.1 cgd return;
231 1.1 cgd case CMD_AMBIGUOUS:
232 1.1 cgd db_printf("Ambiguous\n");
233 1.1 cgd db_flush_lex();
234 1.1 cgd return;
235 1.1 cgd case CMD_HELP:
236 1.1 cgd db_cmd_list(cmd_table);
237 1.1 cgd db_flush_lex();
238 1.1 cgd return;
239 1.1 cgd default:
240 1.1 cgd break;
241 1.1 cgd }
242 1.1 cgd if ((cmd_table = cmd->more) != 0) {
243 1.1 cgd t = db_read_token();
244 1.1 cgd if (t != tIDENT) {
245 1.1 cgd db_cmd_list(cmd_table);
246 1.1 cgd db_flush_lex();
247 1.1 cgd return;
248 1.1 cgd }
249 1.1 cgd }
250 1.1 cgd }
251 1.1 cgd
252 1.1 cgd if ((cmd->flag & CS_OWN) == 0) {
253 1.1 cgd /*
254 1.1 cgd * Standard syntax:
255 1.1 cgd * command [/modifier] [addr] [,count]
256 1.1 cgd */
257 1.1 cgd t = db_read_token();
258 1.1 cgd if (t == tSLASH) {
259 1.1 cgd t = db_read_token();
260 1.1 cgd if (t != tIDENT) {
261 1.1 cgd db_printf("Bad modifier\n");
262 1.1 cgd db_flush_lex();
263 1.1 cgd return;
264 1.1 cgd }
265 1.1 cgd db_strcpy(modif, db_tok_string);
266 1.1 cgd }
267 1.1 cgd else {
268 1.1 cgd db_unread_token(t);
269 1.1 cgd modif[0] = '\0';
270 1.1 cgd }
271 1.1 cgd
272 1.1 cgd if (db_expression(&addr)) {
273 1.1 cgd db_dot = (db_addr_t) addr;
274 1.1 cgd db_last_addr = db_dot;
275 1.1 cgd have_addr = TRUE;
276 1.1 cgd }
277 1.1 cgd else {
278 1.1 cgd addr = (db_expr_t) db_dot;
279 1.1 cgd have_addr = FALSE;
280 1.1 cgd }
281 1.1 cgd t = db_read_token();
282 1.1 cgd if (t == tCOMMA) {
283 1.1 cgd if (!db_expression(&count)) {
284 1.1 cgd db_printf("Count missing\n");
285 1.1 cgd db_flush_lex();
286 1.1 cgd return;
287 1.1 cgd }
288 1.1 cgd }
289 1.1 cgd else {
290 1.1 cgd db_unread_token(t);
291 1.1 cgd count = -1;
292 1.1 cgd }
293 1.1 cgd if ((cmd->flag & CS_MORE) == 0) {
294 1.1 cgd db_skip_to_eol();
295 1.1 cgd }
296 1.1 cgd }
297 1.1 cgd }
298 1.1 cgd *last_cmdp = cmd;
299 1.1 cgd if (cmd != 0) {
300 1.1 cgd /*
301 1.1 cgd * Execute the command.
302 1.1 cgd */
303 1.1 cgd (*cmd->fcn)(addr, have_addr, count, modif);
304 1.1 cgd
305 1.1 cgd if (cmd->flag & CS_SET_DOT) {
306 1.1 cgd /*
307 1.1 cgd * If command changes dot, set dot to
308 1.1 cgd * previous address displayed (if 'ed' style).
309 1.1 cgd */
310 1.1 cgd if (db_ed_style) {
311 1.1 cgd db_dot = db_prev;
312 1.1 cgd }
313 1.1 cgd else {
314 1.1 cgd db_dot = db_next;
315 1.1 cgd }
316 1.1 cgd }
317 1.1 cgd else {
318 1.1 cgd /*
319 1.1 cgd * If command does not change dot,
320 1.1 cgd * set 'next' location to be the same.
321 1.1 cgd */
322 1.1 cgd db_next = db_dot;
323 1.1 cgd }
324 1.1 cgd }
325 1.1 cgd }
326 1.1 cgd
327 1.4 brezak /*ARGSUSED*/
328 1.4 brezak void
329 1.4 brezak db_map_print_cmd(addr, have_addr, count, modif)
330 1.4 brezak db_expr_t addr;
331 1.4 brezak int have_addr;
332 1.4 brezak db_expr_t count;
333 1.4 brezak char * modif;
334 1.4 brezak {
335 1.4 brezak boolean_t full = FALSE;
336 1.4 brezak
337 1.4 brezak if (modif[0] == 'f')
338 1.4 brezak full = TRUE;
339 1.4 brezak
340 1.24 mrg uvm_map_printit((vm_map_t) addr, full, db_printf);
341 1.4 brezak }
342 1.4 brezak
343 1.4 brezak /*ARGSUSED*/
344 1.4 brezak void
345 1.4 brezak db_object_print_cmd(addr, have_addr, count, modif)
346 1.4 brezak db_expr_t addr;
347 1.4 brezak int have_addr;
348 1.4 brezak db_expr_t count;
349 1.4 brezak char * modif;
350 1.4 brezak {
351 1.4 brezak boolean_t full = FALSE;
352 1.4 brezak
353 1.4 brezak if (modif[0] == 'f')
354 1.4 brezak full = TRUE;
355 1.4 brezak
356 1.24 mrg uvm_object_printit((struct uvm_object *) addr, full, db_printf);
357 1.24 mrg }
358 1.24 mrg
359 1.24 mrg /*ARGSUSED*/
360 1.24 mrg void
361 1.24 mrg db_page_print_cmd(addr, have_addr, count, modif)
362 1.24 mrg db_expr_t addr;
363 1.24 mrg int have_addr;
364 1.24 mrg db_expr_t count;
365 1.24 mrg char * modif;
366 1.24 mrg {
367 1.24 mrg boolean_t full = FALSE;
368 1.24 mrg
369 1.24 mrg if (modif[0] == 'f')
370 1.24 mrg full = TRUE;
371 1.24 mrg
372 1.24 mrg uvm_page_printit((struct vm_page *) addr, full, db_printf);
373 1.36 chs }
374 1.36 chs
375 1.36 chs /*ARGSUSED*/
376 1.36 chs void
377 1.36 chs db_buf_print_cmd(addr, have_addr, count, modif)
378 1.36 chs db_expr_t addr;
379 1.36 chs int have_addr;
380 1.36 chs db_expr_t count;
381 1.36 chs char * modif;
382 1.36 chs {
383 1.36 chs boolean_t full = FALSE;
384 1.36 chs
385 1.36 chs if (modif[0] == 'f')
386 1.36 chs full = TRUE;
387 1.36 chs
388 1.36 chs vfs_buf_print((struct buf *)addr, full, db_printf);
389 1.36 chs }
390 1.36 chs
391 1.36 chs /*ARGSUSED*/
392 1.36 chs void
393 1.36 chs db_vnode_print_cmd(addr, have_addr, count, modif)
394 1.36 chs db_expr_t addr;
395 1.36 chs int have_addr;
396 1.36 chs db_expr_t count;
397 1.36 chs char * modif;
398 1.36 chs {
399 1.36 chs boolean_t full = FALSE;
400 1.36 chs
401 1.36 chs if (modif[0] == 'f')
402 1.36 chs full = TRUE;
403 1.36 chs
404 1.36 chs vfs_vnode_print((struct vnode *)addr, full, db_printf);
405 1.4 brezak }
406 1.4 brezak
407 1.31 thorpej /*ARGSUSED*/
408 1.31 thorpej void
409 1.31 thorpej db_pool_print_cmd(addr, have_addr, count, modif)
410 1.31 thorpej db_expr_t addr;
411 1.31 thorpej int have_addr;
412 1.31 thorpej db_expr_t count;
413 1.31 thorpej char * modif;
414 1.31 thorpej {
415 1.31 thorpej
416 1.31 thorpej pool_printit((struct pool *) addr, modif, db_printf);
417 1.31 thorpej }
418 1.31 thorpej
419 1.1 cgd /*
420 1.1 cgd * 'show' commands
421 1.1 cgd */
422 1.1 cgd
423 1.10 pk struct db_command db_show_all_cmds[] = {
424 1.32 lukem { "callout", db_show_callout, 0, NULL },
425 1.16 christos { "procs", db_show_all_procs, 0, NULL },
426 1.16 christos { NULL, NULL, 0, NULL }
427 1.1 cgd };
428 1.1 cgd
429 1.10 pk struct db_command db_show_cmds[] = {
430 1.16 christos { "all", NULL, 0, db_show_all_cmds },
431 1.16 christos { "breaks", db_listbreak_cmd, 0, NULL },
432 1.16 christos { "map", db_map_print_cmd, 0, NULL },
433 1.16 christos { "object", db_object_print_cmd, 0, NULL },
434 1.24 mrg { "page", db_page_print_cmd, 0, NULL },
435 1.37 chs { "buf", db_buf_print_cmd, 0, NULL },
436 1.37 chs { "vnode", db_vnode_print_cmd, 0, NULL },
437 1.31 thorpej { "pool", db_pool_print_cmd, 0, NULL },
438 1.32 lukem { "registers", db_show_regs, 0, NULL },
439 1.32 lukem { "watches", db_listwatch_cmd, 0, NULL },
440 1.32 lukem { NULL, NULL, 0, NULL }
441 1.1 cgd };
442 1.1 cgd
443 1.10 pk struct db_command db_command_table[] = {
444 1.32 lukem { "break", db_breakpoint_cmd, 0, NULL },
445 1.32 lukem { "c", db_continue_cmd, 0, NULL },
446 1.32 lukem { "call", db_fncall, CS_OWN, NULL },
447 1.32 lukem { "callout", db_show_callout, 0, NULL },
448 1.32 lukem { "continue", db_continue_cmd, 0, NULL },
449 1.32 lukem { "d", db_delete_cmd, 0, NULL },
450 1.32 lukem { "delete", db_delete_cmd, 0, NULL },
451 1.32 lukem { "dwatch", db_deletewatch_cmd, 0, NULL },
452 1.32 lukem { "examine", db_examine_cmd, CS_SET_DOT, NULL },
453 1.32 lukem { "kill", db_kill_proc, CS_OWN, NULL },
454 1.6 brezak #ifdef DB_MACHINE_COMMANDS
455 1.32 lukem { "machine", NULL, 0, NULL },
456 1.6 brezak #endif
457 1.32 lukem { "match", db_trace_until_matching_cmd,0, NULL },
458 1.32 lukem { "next", db_trace_until_matching_cmd,0, NULL },
459 1.16 christos { "print", db_print_cmd, 0, NULL },
460 1.32 lukem { "ps", db_show_all_procs, 0, NULL },
461 1.32 lukem { "reboot", db_reboot_cmd, CS_OWN, NULL },
462 1.32 lukem { "s", db_single_step_cmd, 0, NULL },
463 1.16 christos { "search", db_search_cmd, CS_OWN|CS_SET_DOT, NULL },
464 1.16 christos { "set", db_set_cmd, CS_OWN, NULL },
465 1.32 lukem { "show", NULL, 0, db_show_cmds },
466 1.32 lukem { "step", db_single_step_cmd, 0, NULL },
467 1.32 lukem { "sync", db_sync_cmd, CS_OWN, NULL },
468 1.32 lukem { "trace", db_stack_trace_cmd, 0, NULL },
469 1.32 lukem { "until", db_trace_until_call_cmd,0, NULL },
470 1.16 christos { "w", db_write_cmd, CS_MORE|CS_SET_DOT, NULL },
471 1.16 christos { "watch", db_watchpoint_cmd, CS_MORE, NULL },
472 1.32 lukem { "write", db_write_cmd, CS_MORE|CS_SET_DOT, NULL },
473 1.32 lukem { "x", db_examine_cmd, CS_SET_DOT, NULL },
474 1.16 christos { NULL, NULL, 0, NULL }
475 1.1 cgd };
476 1.6 brezak
477 1.6 brezak #ifdef DB_MACHINE_COMMANDS
478 1.6 brezak
479 1.32 lukem /*
480 1.32 lukem * this function should be called to install the machine dependent
481 1.32 lukem * commands. It should be called before the debugger is enabled
482 1.32 lukem */
483 1.32 lukem void
484 1.32 lukem db_machine_commands_install(ptr)
485 1.32 lukem struct db_command *ptr;
486 1.6 brezak {
487 1.32 lukem struct db_command *cmd;
488 1.32 lukem
489 1.32 lukem for (cmd = db_command_table; cmd != 0; cmd++) {
490 1.32 lukem if (strcmp(cmd->name, "machine") == 0) {
491 1.32 lukem cmd->more = ptr;
492 1.32 lukem break;
493 1.32 lukem }
494 1.32 lukem }
495 1.6 brezak }
496 1.6 brezak
497 1.6 brezak #endif
498 1.1 cgd
499 1.10 pk struct db_command *db_last_command = 0;
500 1.1 cgd
501 1.1 cgd void
502 1.1 cgd db_command_loop()
503 1.1 cgd {
504 1.17 gwr label_t db_jmpbuf;
505 1.17 gwr label_t *savejmp;
506 1.8 mycroft extern int db_output_line;
507 1.4 brezak
508 1.1 cgd /*
509 1.1 cgd * Initialize 'prev' and 'next' to dot.
510 1.1 cgd */
511 1.1 cgd db_prev = db_dot;
512 1.1 cgd db_next = db_dot;
513 1.1 cgd
514 1.1 cgd db_cmd_loop_done = 0;
515 1.17 gwr
516 1.17 gwr savejmp = db_recover;
517 1.17 gwr db_recover = &db_jmpbuf;
518 1.17 gwr (void) setjmp(&db_jmpbuf);
519 1.8 mycroft
520 1.1 cgd while (!db_cmd_loop_done) {
521 1.8 mycroft if (db_print_position() != 0)
522 1.8 mycroft db_printf("\n");
523 1.8 mycroft db_output_line = 0;
524 1.1 cgd
525 1.34 sommerfe #ifdef MULTIPROCESSOR
526 1.34 sommerfe db_printf("(cpu %d)", cpu_number());
527 1.34 sommerfe #endif
528 1.8 mycroft db_printf("db> ");
529 1.8 mycroft (void) db_read_line();
530 1.1 cgd
531 1.8 mycroft db_command(&db_last_command, db_command_table);
532 1.8 mycroft }
533 1.1 cgd
534 1.8 mycroft db_recover = savejmp;
535 1.1 cgd }
536 1.1 cgd
537 1.1 cgd void
538 1.1 cgd db_error(s)
539 1.1 cgd char *s;
540 1.1 cgd {
541 1.1 cgd if (s)
542 1.1 cgd db_printf(s);
543 1.1 cgd db_flush_lex();
544 1.19 christos longjmp(db_recover);
545 1.1 cgd }
546 1.1 cgd
547 1.1 cgd
548 1.1 cgd /*
549 1.1 cgd * Call random function:
550 1.1 cgd * !expr(arg,arg,arg)
551 1.1 cgd */
552 1.16 christos /*ARGSUSED*/
553 1.1 cgd void
554 1.16 christos db_fncall(addr, have_addr, count, modif)
555 1.16 christos db_expr_t addr;
556 1.16 christos int have_addr;
557 1.16 christos db_expr_t count;
558 1.16 christos char * modif;
559 1.1 cgd {
560 1.1 cgd db_expr_t fn_addr;
561 1.1 cgd #define MAXARGS 11
562 1.1 cgd db_expr_t args[MAXARGS];
563 1.1 cgd int nargs = 0;
564 1.1 cgd db_expr_t retval;
565 1.16 christos db_expr_t (*func) __P((db_expr_t, ...));
566 1.1 cgd int t;
567 1.1 cgd
568 1.1 cgd if (!db_expression(&fn_addr)) {
569 1.1 cgd db_printf("Bad function\n");
570 1.1 cgd db_flush_lex();
571 1.1 cgd return;
572 1.1 cgd }
573 1.16 christos func = (db_expr_t (*) __P((db_expr_t, ...))) fn_addr;
574 1.1 cgd
575 1.1 cgd t = db_read_token();
576 1.1 cgd if (t == tLPAREN) {
577 1.1 cgd if (db_expression(&args[0])) {
578 1.1 cgd nargs++;
579 1.1 cgd while ((t = db_read_token()) == tCOMMA) {
580 1.1 cgd if (nargs == MAXARGS) {
581 1.1 cgd db_printf("Too many arguments\n");
582 1.1 cgd db_flush_lex();
583 1.1 cgd return;
584 1.1 cgd }
585 1.1 cgd if (!db_expression(&args[nargs])) {
586 1.1 cgd db_printf("Argument missing\n");
587 1.1 cgd db_flush_lex();
588 1.1 cgd return;
589 1.1 cgd }
590 1.1 cgd nargs++;
591 1.1 cgd }
592 1.1 cgd db_unread_token(t);
593 1.1 cgd }
594 1.1 cgd if (db_read_token() != tRPAREN) {
595 1.1 cgd db_printf("?\n");
596 1.1 cgd db_flush_lex();
597 1.1 cgd return;
598 1.1 cgd }
599 1.1 cgd }
600 1.1 cgd db_skip_to_eol();
601 1.1 cgd
602 1.1 cgd while (nargs < MAXARGS) {
603 1.1 cgd args[nargs++] = 0;
604 1.1 cgd }
605 1.1 cgd
606 1.1 cgd retval = (*func)(args[0], args[1], args[2], args[3], args[4],
607 1.20 christos args[5], args[6], args[7], args[8], args[9]);
608 1.21 mycroft db_printf("%#ln\n", retval);
609 1.23 scottr }
610 1.23 scottr
611 1.23 scottr void
612 1.23 scottr db_reboot_cmd(addr, have_addr, count, modif)
613 1.23 scottr db_expr_t addr;
614 1.23 scottr int have_addr;
615 1.23 scottr db_expr_t count;
616 1.23 scottr char * modif;
617 1.23 scottr {
618 1.23 scottr db_expr_t bootflags;
619 1.23 scottr
620 1.23 scottr /* Flags, default to RB_AUTOBOOT */
621 1.23 scottr if (!db_expression(&bootflags))
622 1.23 scottr bootflags = (db_expr_t)RB_AUTOBOOT;
623 1.23 scottr if (db_read_token() != tEOL) {
624 1.23 scottr db_error("?\n");
625 1.23 scottr /*NOTREACHED*/
626 1.23 scottr }
627 1.23 scottr cpu_reboot((int)bootflags, NULL);
628 1.32 lukem }
629 1.32 lukem
630 1.32 lukem void
631 1.32 lukem db_sync_cmd(addr, have_addr, count, modif)
632 1.32 lukem db_expr_t addr;
633 1.32 lukem int have_addr;
634 1.32 lukem db_expr_t count;
635 1.32 lukem char * modif;
636 1.32 lukem {
637 1.32 lukem
638 1.32 lukem cpu_reboot(RB_DUMP, NULL);
639 1.1 cgd }
640