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