📄 db_command.cxx
字号:
/* $NetBSD: db_command.c,v 1.13 1994/10/09 08:29:59 mycroft Exp $ *//* * Mach Operating System * Copyright (c) 1991,1990 Carnegie Mellon University * All Rights Reserved. * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. *//* * Command dispatcher. */#include <arch-kerninc/db_machdep.hxx> /* type definitions */#include <ddb/db_lex.hxx>#include <ddb/db_output.hxx>#include <ddb/db_command.hxx>#include <ddb/db_expr.hxx>#include <eros/setjmp.h>#include <kerninc/util.h>/* * Exported global variables */bool db_cmd_loop_done;jmp_buf *db_recover;db_addr_t db_dot; /* current location */db_addr_t db_last_addr; /* last explicit address typed */db_addr_t db_prev; /* last address examined or written */db_addr_t db_next; /* next address to be examined or written *//* * if 'ed' style: 'dot' is set at start of last item printed, * and '+' points to next line. * Otherwise: 'dot' points to next item, '..' points to last. */bool db_ed_style = true;/* * Utility routine - discard tokens through end-of-line. */voiddb_skip_to_eol(){ int t; do { t = db_read_token(); } while (t != tEOL);}/* * Results of command search. */#define CMD_UNIQUE 0#define CMD_FOUND 1#define CMD_NONE 2#define CMD_AMBIGUOUS 3#define CMD_HELP 4/* * Search for command prefix. */intdb_cmd_search(char *name, db_command *table, db_command **cmdp /* out */){ struct db_command *cmd; int result = CMD_NONE; for (cmd = table; cmd->name != 0; cmd++) { register char *lp; register char *rp; register int c; lp = name; rp = cmd->name; while ((c = *lp) == *rp) { if (c == 0) { /* complete match */ *cmdp = cmd; return (CMD_UNIQUE); } lp++; rp++; } if (c == 0) { /* end of name, not end of command - partial match */ if (result == CMD_FOUND) { result = CMD_AMBIGUOUS; /* but keep looking for a full match - this lets us match single letters */ } else { *cmdp = cmd; result = CMD_FOUND; } } } if (result == CMD_NONE) { /* check for 'help' */ if (name[0] == 'h' && name[1] == 'e' && name[2] == 'l' && name[3] == 'p') result = CMD_HELP; } return (result);}voiddb_cmd_list(db_command *table){ int i = 0; register struct db_command *cmd; for (cmd = table; cmd->name != 0; cmd++) { db_printf("%-12s", cmd->name); i++; if ((i % 6) == 0) db_printf("\n"); db_end_line(); }}voiddb_command(db_command **last_cmdp /* IN_OUT */, db_command *cmd_table){ struct db_command *cmd; int t; char modif[TOK_STRING_SIZE]; db_expr_t addr, count; bool have_addr = false; int result; t = db_read_token(); if (t == tEOL) { /* empty line repeats last command, at 'next' */ cmd = *last_cmdp; addr = (db_expr_t)db_next; have_addr = false; count = 1; modif[0] = '\0'; } else if (t == tEXCL) { void db_fncall(db_expr_t, int, db_expr_t, char*); db_fncall(0,0,0,0); return; } else if (t == tQUERY) { extern void db_sym_match(const char *symstr); t = db_read_token(); db_sym_match(db_tok_string); return; } else if (t != tIDENT) { db_printf("?\n"); db_flush_lex(); return; } else { /* * Search for command */ while (cmd_table) { result = db_cmd_search(db_tok_string, cmd_table, &cmd); switch (result) { case CMD_NONE: db_printf("No such command\n"); db_flush_lex(); return; case CMD_AMBIGUOUS: db_printf("Ambiguous\n"); db_flush_lex(); return; case CMD_HELP: db_cmd_list(cmd_table); db_flush_lex(); return; default: break; } if ((cmd_table = cmd->more) != 0) { t = db_read_token(); if (t != tIDENT) { db_cmd_list(cmd_table); db_flush_lex(); return; } } } if ((cmd->flag & CS_OWN) == 0) { /* * Standard syntax: * command [/modifier] [addr] [,count] */ t = db_read_token(); if (t == tSLASH) { t = db_read_token(); if (t != tIDENT) { db_printf("Bad modifier\n"); db_flush_lex(); return; } strcpy(modif, db_tok_string); } else { db_unread_token(t); modif[0] = '\0'; } if (db_expression(&addr)) { db_dot = (db_addr_t) addr; db_last_addr = db_dot; have_addr = true; } else { addr = (db_expr_t) db_dot; have_addr = false; } t = db_read_token(); if (t == tCOMMA) { if (!db_expression(&count)) { db_printf("Count missing\n"); db_flush_lex(); return; } } else { db_unread_token(t); count = -1; } if ((cmd->flag & CS_MORE) == 0) { db_skip_to_eol(); } } } *last_cmdp = cmd; if (cmd != 0) { /* * Execute the command. */ (*cmd->fcn)(addr, have_addr, count, modif); if (cmd->flag & CS_SET_DOT) { /* * If command changes dot, set dot to * previous address displayed (if 'ed' style). */ if (db_ed_style) { db_dot = db_prev; } else { db_dot = db_next; } } else { /* * If command does not change dot, * set 'next' location to be the same. */ db_next = db_dot; } }}#if 0/*ARGSUSED*/voiddb_map_print_cmd(db_expr_t /* addr */, int /* have_addr */, db_expr_t /* count */, char * /* modif */){ extern void _vm_map_print(db_expr_t, bool, void (*)(const char *, ...)); bool full = false; if (modif[0] == 'f') full = true; _vm_map_print(addr, full, db_printf);}#endif/*ARGSUSED*/#if 0voiddb_object_print_cmd(db_expr_t /* addr */, int /* have_addr */, db_expr_t /* count */, char * /* modif */){ extern void _vm_object_print(db_expr_t, bool, void (*)(const char *, ...)); bool full = false; if (modif[0] == 'f') full = true; _vm_object_print(addr, full, db_printf);}#endif/* * 'show' commands */#if 0extern void db_show_all_procs(db_expr_t, int, db_expr_t, char*);extern void db_show_callout(db_expr_t, int, db_expr_t, char*);#endifextern void db_listbreak_cmd(db_expr_t, int, db_expr_t, char*);#ifdef OPTION_OPTION_DDB_WATCHextern void db_listwatch_cmd(db_expr_t, int, db_expr_t, char*);#endifextern void db_show_regs(db_expr_t, int, db_expr_t, char*);void db_show_help(db_expr_t, int, db_expr_t, char*);extern void db_rsrv_print_cmd(db_expr_t, int, db_expr_t, char*);extern void db_rsrvchain_print_cmd(db_expr_t, int, db_expr_t, char*);extern void db_ctxt_print_cmd(db_expr_t, int, db_expr_t, char*);extern void db_ctxt_kr_print_cmd(db_expr_t, int, db_expr_t, char*);extern void db_ctxt_keys_print_cmd(db_expr_t, int, db_expr_t, char*);extern void db_thread_print_cmd(db_expr_t, int, db_expr_t, char*);extern void db_inv_print_cmd(db_expr_t, int, db_expr_t, char*);extern void db_entry_print_cmd(db_expr_t, int, db_expr_t, char*);extern void db_exit_print_cmd(db_expr_t, int, db_expr_t, char*);extern void db_invokee_print_cmd(db_expr_t, int, db_expr_t, char*);extern void db_invokee_kr_print_cmd(db_expr_t, int, db_expr_t, char*);extern void db_invokee_keys_print_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_irq_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_pins_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_pmem_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_pte_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_mappings_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_uthread_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_reserves_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_kreserves_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_pages_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_nodes_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_counters_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_key_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_node_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_obhdr_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_sources(db_expr_t, int, db_expr_t, char*);extern void db_show_savearea_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_sizes_cmd(db_expr_t, int, db_expr_t, char*);extern void db_show_gdt(db_expr_t, int, db_expr_t, char*);extern void db_show_walkinfo_cmd(db_expr_t, int, db_expr_t, char*);struct db_command db_show_all_cmds[] = {#if 0 { "procs", db_show_all_procs,0, 0 }, { "callout", db_show_callout,0, 0 },#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -