172 int result; 173 174 t = db_read_token(); 175 if (t == tEOL) { 176 /* empty line repeats last command, at 'next' */ 177 cmd = *last_cmdp; 178 addr = (db_expr_t)db_next; 179 have_addr = FALSE; 180 count = 1; 181 modif[0] = '\0'; 182 } 183 else if (t == tEXCL) { 184 void db_fncall(); 185 db_fncall(); 186 return; 187 } 188 else if (t != tIDENT) { 189 db_printf("?\n"); 190 db_flush_lex(); 191 return; 192 } 193 else { 194 /* 195 * Search for command 196 */ 197 while (cmd_table) { 198 result = db_cmd_search(db_tok_string, 199 cmd_table, 200 &cmd); 201 switch (result) { 202 case CMD_NONE: 203 db_printf("No such command\n"); 204 db_flush_lex(); 205 return; 206 case CMD_AMBIGUOUS: 207 db_printf("Ambiguous\n"); 208 db_flush_lex(); 209 return; 210 case CMD_HELP: 211 db_cmd_list(cmd_table); 212 db_flush_lex(); 213 return; 214 default: 215 break; 216 } 217 if ((cmd_table = cmd->more) != 0) { 218 t = db_read_token(); 219 if (t != tIDENT) { 220 db_cmd_list(cmd_table); 221 db_flush_lex(); 222 return; 223 } 224 } 225 } 226 227 if ((cmd->flag & CS_OWN) == 0) { 228 /* 229 * Standard syntax: 230 * command [/modifier] [addr] [,count] 231 */ 232 t = db_read_token(); 233 if (t == tSLASH) { 234 t = db_read_token(); 235 if (t != tIDENT) { 236 db_printf("Bad modifier\n"); 237 db_flush_lex(); 238 return; 239 } 240 db_strcpy(modif, db_tok_string); 241 } 242 else { 243 db_unread_token(t); 244 modif[0] = '\0'; 245 } 246 247 if (db_expression(&addr)) { 248 db_dot = (db_addr_t) addr; 249 db_last_addr = db_dot; 250 have_addr = TRUE; 251 } 252 else { 253 addr = (db_expr_t) db_dot; 254 have_addr = FALSE; 255 } 256 t = db_read_token(); 257 if (t == tCOMMA) { 258 if (!db_expression(&count)) { 259 db_printf("Count missing\n"); 260 db_flush_lex(); 261 return; 262 } 263 } 264 else { 265 db_unread_token(t); 266 count = -1; 267 } 268 if ((cmd->flag & CS_MORE) == 0) { 269 db_skip_to_eol(); 270 } 271 } 272 } 273 *last_cmdp = cmd; 274 if (cmd != 0) { 275 /* 276 * Execute the command. 277 */ 278 (*cmd->fcn)(addr, have_addr, count, modif); 279 280 if (cmd->flag & CS_SET_DOT) { 281 /* 282 * If command changes dot, set dot to 283 * previous address displayed (if 'ed' style). 284 */ 285 if (db_ed_style) { 286 db_dot = db_prev; 287 } 288 else { 289 db_dot = db_next; 290 } 291 } 292 else { 293 /* 294 * If command does not change dot, 295 * set 'next' location to be the same. 296 */ 297 db_next = db_dot; 298 } 299 } 300} 301 302/* 303 * 'show' commands 304 */ 305extern void db_listbreak_cmd(); 306extern void db_listwatch_cmd(); 307extern void db_show_regs(), db_show_one_thread(), db_show_all_threads(); 308extern void vm_map_print(), vm_object_print(), vm_page_print(); 309extern void ipc_port_print(); 310void db_show_help(); 311 312struct command db_show_all_cmds[] = { 313#if 0 314 { "threads", db_show_all_threads,0, 0 }, 315#endif 316 { (char *)0 } 317}; 318 319struct command db_show_cmds[] = { 320 { "all", 0, 0, db_show_all_cmds }, 321 { "registers", db_show_regs, 0, 0 }, 322 { "breaks", db_listbreak_cmd, 0, 0 }, 323 { "watches", db_listwatch_cmd, 0, 0 }, 324#if 0 325 { "thread", db_show_one_thread, 0, 0 }, 326#endif 327 { "map", vm_map_print, 0, 0 }, 328 { "object", vm_object_print, 0, 0 }, 329#if 0 330 { "page", vm_page_print, 0, 0 }, 331#endif 332#if 0 333 { "port", ipc_port_print, 0, 0 }, 334#endif 335 { (char *)0, } 336}; 337 338extern void db_print_cmd(), db_examine_cmd(), db_set_cmd(); 339extern void db_search_cmd(); 340extern void db_write_cmd(); 341extern void db_delete_cmd(), db_breakpoint_cmd(); 342extern void db_deletewatch_cmd(), db_watchpoint_cmd(); 343extern void db_single_step_cmd(), db_trace_until_call_cmd(), 344 db_trace_until_matching_cmd(), db_continue_cmd(); 345extern void db_stack_trace_cmd(); 346void db_help_cmd(); 347void db_fncall(); 348 349struct command db_command_table[] = { 350 { "print", db_print_cmd, 0, 0 }, 351 { "examine", db_examine_cmd, CS_SET_DOT, 0 }, 352 { "x", db_examine_cmd, CS_SET_DOT, 0 }, 353 { "search", db_search_cmd, CS_OWN|CS_SET_DOT, 0 }, 354 { "set", db_set_cmd, CS_OWN, 0 }, 355 { "write", db_write_cmd, CS_MORE|CS_SET_DOT, 0 }, 356 { "w", db_write_cmd, CS_MORE|CS_SET_DOT, 0 }, 357 { "delete", db_delete_cmd, 0, 0 }, 358 { "d", db_delete_cmd, 0, 0 }, 359 { "break", db_breakpoint_cmd, 0, 0 }, 360 { "dwatch", db_deletewatch_cmd, 0, 0 }, 361 { "watch", db_watchpoint_cmd, CS_MORE,0 }, 362 { "step", db_single_step_cmd, 0, 0 }, 363 { "s", db_single_step_cmd, 0, 0 }, 364 { "continue", db_continue_cmd, 0, 0 }, 365 { "c", db_continue_cmd, 0, 0 }, 366 { "until", db_trace_until_call_cmd,0, 0 }, 367 { "next", db_trace_until_matching_cmd,0, 0 }, 368 { "match", db_trace_until_matching_cmd,0, 0 }, 369 { "trace", db_stack_trace_cmd, 0, 0 }, 370 { "call", db_fncall, CS_OWN, 0 }, 371 { "show", 0, 0, db_show_cmds }, 372 { (char *)0, } 373}; 374 375struct command *db_last_command = 0; 376 377void 378db_help_cmd() 379{ 380 struct command *cmd = db_command_table; 381 382 while (cmd->name != 0) { 383 db_printf("%-12s", cmd->name); 384 db_end_line(); 385 cmd++; 386 } 387} 388 389void 390db_command_loop() 391{ 392 /* 393 * Initialize 'prev' and 'next' to dot. 394 */ 395 db_prev = db_dot; 396 db_next = db_dot; 397 398 db_cmd_loop_done = 0; 399 while (!db_cmd_loop_done) { 400 401 (void) setjmp(db_jmpbuf); 402 if (db_print_position() != 0) 403 db_printf("\n"); 404 405 db_printf("db> "); 406 (void) db_read_line(); 407 408 db_command(&db_last_command, db_command_table); 409 } 410} 411 412void 413db_error(s) 414 char *s; 415{ 416 if (s) 417 db_printf(s); 418 db_flush_lex(); 419 longjmp(db_jmpbuf, 1); 420} 421 422 423/* 424 * Call random function: 425 * !expr(arg,arg,arg) 426 */ 427void 428db_fncall() 429{ 430 db_expr_t fn_addr; 431#define MAXARGS 11 432 db_expr_t args[MAXARGS]; 433 int nargs = 0; 434 db_expr_t retval; 435 db_expr_t (*func)(); 436 int t; 437 438 if (!db_expression(&fn_addr)) { 439 db_printf("Bad function\n"); 440 db_flush_lex(); 441 return; 442 } 443 func = (db_expr_t (*) ()) fn_addr; 444 445 t = db_read_token(); 446 if (t == tLPAREN) { 447 if (db_expression(&args[0])) { 448 nargs++; 449 while ((t = db_read_token()) == tCOMMA) { 450 if (nargs == MAXARGS) { 451 db_printf("Too many arguments\n"); 452 db_flush_lex(); 453 return; 454 } 455 if (!db_expression(&args[nargs])) { 456 db_printf("Argument missing\n"); 457 db_flush_lex(); 458 return; 459 } 460 nargs++; 461 } 462 db_unread_token(t); 463 } 464 if (db_read_token() != tRPAREN) { 465 db_printf("?\n"); 466 db_flush_lex(); 467 return; 468 } 469 } 470 db_skip_to_eol(); 471 472 while (nargs < MAXARGS) { 473 args[nargs++] = 0; 474 } 475 476 retval = (*func)(args[0], args[1], args[2], args[3], args[4], 477 args[5], args[6], args[7], args[8], args[9] ); 478 db_printf("%#n\n", retval); 479}
| 173 int result; 174 175 t = db_read_token(); 176 if (t == tEOL) { 177 /* empty line repeats last command, at 'next' */ 178 cmd = *last_cmdp; 179 addr = (db_expr_t)db_next; 180 have_addr = FALSE; 181 count = 1; 182 modif[0] = '\0'; 183 } 184 else if (t == tEXCL) { 185 void db_fncall(); 186 db_fncall(); 187 return; 188 } 189 else if (t != tIDENT) { 190 db_printf("?\n"); 191 db_flush_lex(); 192 return; 193 } 194 else { 195 /* 196 * Search for command 197 */ 198 while (cmd_table) { 199 result = db_cmd_search(db_tok_string, 200 cmd_table, 201 &cmd); 202 switch (result) { 203 case CMD_NONE: 204 db_printf("No such command\n"); 205 db_flush_lex(); 206 return; 207 case CMD_AMBIGUOUS: 208 db_printf("Ambiguous\n"); 209 db_flush_lex(); 210 return; 211 case CMD_HELP: 212 db_cmd_list(cmd_table); 213 db_flush_lex(); 214 return; 215 default: 216 break; 217 } 218 if ((cmd_table = cmd->more) != 0) { 219 t = db_read_token(); 220 if (t != tIDENT) { 221 db_cmd_list(cmd_table); 222 db_flush_lex(); 223 return; 224 } 225 } 226 } 227 228 if ((cmd->flag & CS_OWN) == 0) { 229 /* 230 * Standard syntax: 231 * command [/modifier] [addr] [,count] 232 */ 233 t = db_read_token(); 234 if (t == tSLASH) { 235 t = db_read_token(); 236 if (t != tIDENT) { 237 db_printf("Bad modifier\n"); 238 db_flush_lex(); 239 return; 240 } 241 db_strcpy(modif, db_tok_string); 242 } 243 else { 244 db_unread_token(t); 245 modif[0] = '\0'; 246 } 247 248 if (db_expression(&addr)) { 249 db_dot = (db_addr_t) addr; 250 db_last_addr = db_dot; 251 have_addr = TRUE; 252 } 253 else { 254 addr = (db_expr_t) db_dot; 255 have_addr = FALSE; 256 } 257 t = db_read_token(); 258 if (t == tCOMMA) { 259 if (!db_expression(&count)) { 260 db_printf("Count missing\n"); 261 db_flush_lex(); 262 return; 263 } 264 } 265 else { 266 db_unread_token(t); 267 count = -1; 268 } 269 if ((cmd->flag & CS_MORE) == 0) { 270 db_skip_to_eol(); 271 } 272 } 273 } 274 *last_cmdp = cmd; 275 if (cmd != 0) { 276 /* 277 * Execute the command. 278 */ 279 (*cmd->fcn)(addr, have_addr, count, modif); 280 281 if (cmd->flag & CS_SET_DOT) { 282 /* 283 * If command changes dot, set dot to 284 * previous address displayed (if 'ed' style). 285 */ 286 if (db_ed_style) { 287 db_dot = db_prev; 288 } 289 else { 290 db_dot = db_next; 291 } 292 } 293 else { 294 /* 295 * If command does not change dot, 296 * set 'next' location to be the same. 297 */ 298 db_next = db_dot; 299 } 300 } 301} 302 303/* 304 * 'show' commands 305 */ 306extern void db_listbreak_cmd(); 307extern void db_listwatch_cmd(); 308extern void db_show_regs(), db_show_one_thread(), db_show_all_threads(); 309extern void vm_map_print(), vm_object_print(), vm_page_print(); 310extern void ipc_port_print(); 311void db_show_help(); 312 313struct command db_show_all_cmds[] = { 314#if 0 315 { "threads", db_show_all_threads,0, 0 }, 316#endif 317 { (char *)0 } 318}; 319 320struct command db_show_cmds[] = { 321 { "all", 0, 0, db_show_all_cmds }, 322 { "registers", db_show_regs, 0, 0 }, 323 { "breaks", db_listbreak_cmd, 0, 0 }, 324 { "watches", db_listwatch_cmd, 0, 0 }, 325#if 0 326 { "thread", db_show_one_thread, 0, 0 }, 327#endif 328 { "map", vm_map_print, 0, 0 }, 329 { "object", vm_object_print, 0, 0 }, 330#if 0 331 { "page", vm_page_print, 0, 0 }, 332#endif 333#if 0 334 { "port", ipc_port_print, 0, 0 }, 335#endif 336 { (char *)0, } 337}; 338 339extern void db_print_cmd(), db_examine_cmd(), db_set_cmd(); 340extern void db_search_cmd(); 341extern void db_write_cmd(); 342extern void db_delete_cmd(), db_breakpoint_cmd(); 343extern void db_deletewatch_cmd(), db_watchpoint_cmd(); 344extern void db_single_step_cmd(), db_trace_until_call_cmd(), 345 db_trace_until_matching_cmd(), db_continue_cmd(); 346extern void db_stack_trace_cmd(); 347void db_help_cmd(); 348void db_fncall(); 349 350struct command db_command_table[] = { 351 { "print", db_print_cmd, 0, 0 }, 352 { "examine", db_examine_cmd, CS_SET_DOT, 0 }, 353 { "x", db_examine_cmd, CS_SET_DOT, 0 }, 354 { "search", db_search_cmd, CS_OWN|CS_SET_DOT, 0 }, 355 { "set", db_set_cmd, CS_OWN, 0 }, 356 { "write", db_write_cmd, CS_MORE|CS_SET_DOT, 0 }, 357 { "w", db_write_cmd, CS_MORE|CS_SET_DOT, 0 }, 358 { "delete", db_delete_cmd, 0, 0 }, 359 { "d", db_delete_cmd, 0, 0 }, 360 { "break", db_breakpoint_cmd, 0, 0 }, 361 { "dwatch", db_deletewatch_cmd, 0, 0 }, 362 { "watch", db_watchpoint_cmd, CS_MORE,0 }, 363 { "step", db_single_step_cmd, 0, 0 }, 364 { "s", db_single_step_cmd, 0, 0 }, 365 { "continue", db_continue_cmd, 0, 0 }, 366 { "c", db_continue_cmd, 0, 0 }, 367 { "until", db_trace_until_call_cmd,0, 0 }, 368 { "next", db_trace_until_matching_cmd,0, 0 }, 369 { "match", db_trace_until_matching_cmd,0, 0 }, 370 { "trace", db_stack_trace_cmd, 0, 0 }, 371 { "call", db_fncall, CS_OWN, 0 }, 372 { "show", 0, 0, db_show_cmds }, 373 { (char *)0, } 374}; 375 376struct command *db_last_command = 0; 377 378void 379db_help_cmd() 380{ 381 struct command *cmd = db_command_table; 382 383 while (cmd->name != 0) { 384 db_printf("%-12s", cmd->name); 385 db_end_line(); 386 cmd++; 387 } 388} 389 390void 391db_command_loop() 392{ 393 /* 394 * Initialize 'prev' and 'next' to dot. 395 */ 396 db_prev = db_dot; 397 db_next = db_dot; 398 399 db_cmd_loop_done = 0; 400 while (!db_cmd_loop_done) { 401 402 (void) setjmp(db_jmpbuf); 403 if (db_print_position() != 0) 404 db_printf("\n"); 405 406 db_printf("db> "); 407 (void) db_read_line(); 408 409 db_command(&db_last_command, db_command_table); 410 } 411} 412 413void 414db_error(s) 415 char *s; 416{ 417 if (s) 418 db_printf(s); 419 db_flush_lex(); 420 longjmp(db_jmpbuf, 1); 421} 422 423 424/* 425 * Call random function: 426 * !expr(arg,arg,arg) 427 */ 428void 429db_fncall() 430{ 431 db_expr_t fn_addr; 432#define MAXARGS 11 433 db_expr_t args[MAXARGS]; 434 int nargs = 0; 435 db_expr_t retval; 436 db_expr_t (*func)(); 437 int t; 438 439 if (!db_expression(&fn_addr)) { 440 db_printf("Bad function\n"); 441 db_flush_lex(); 442 return; 443 } 444 func = (db_expr_t (*) ()) fn_addr; 445 446 t = db_read_token(); 447 if (t == tLPAREN) { 448 if (db_expression(&args[0])) { 449 nargs++; 450 while ((t = db_read_token()) == tCOMMA) { 451 if (nargs == MAXARGS) { 452 db_printf("Too many arguments\n"); 453 db_flush_lex(); 454 return; 455 } 456 if (!db_expression(&args[nargs])) { 457 db_printf("Argument missing\n"); 458 db_flush_lex(); 459 return; 460 } 461 nargs++; 462 } 463 db_unread_token(t); 464 } 465 if (db_read_token() != tRPAREN) { 466 db_printf("?\n"); 467 db_flush_lex(); 468 return; 469 } 470 } 471 db_skip_to_eol(); 472 473 while (nargs < MAXARGS) { 474 args[nargs++] = 0; 475 } 476 477 retval = (*func)(args[0], args[1], args[2], args[3], args[4], 478 args[5], args[6], args[7], args[8], args[9] ); 479 db_printf("%#n\n", retval); 480}
|