From ac41acf3022250d14d13b0020896a65eb19ff61d Mon Sep 17 00:00:00 2001 From: yamt Date: Sat, 26 Nov 2005 12:16:44 +0000 Subject: [PATCH] add a new option DDB_COMMANDONENTER. which can be useful for eg. broken console input. --- sys/conf/files | 3 ++- sys/ddb/db_command.c | 30 ++++++++++++++++++++++++++++-- sys/ddb/db_lex.c | 18 +++++++++++++----- sys/ddb/db_lex.h | 3 ++- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/sys/conf/files b/sys/conf/files index 6203395ac4bf..0228599ce124 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $NetBSD: files,v 1.741 2005/11/25 17:33:56 thorpej Exp $ +# $NetBSD: files,v 1.742 2005/11/26 12:16:44 yamt Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -202,6 +202,7 @@ defflag opt_mbr.h COMPAT_386BSD_MBRPART defflag opt_ddb.h DDB defparam opt_ddbparam.h DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR DDB_KEYCODE SYMTAB_SPACE + DDB_COMMANDONENTER defflag opt_kgdb.h KGDB defparam opt_kgdb.h KGDB_DEV KGDB_DEVNAME KGDB_DEVPORT KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE diff --git a/sys/ddb/db_command.c b/sys/ddb/db_command.c index fd6eb0ee1c71..63d6e34cc88a 100644 --- a/sys/ddb/db_command.c +++ b/sys/ddb/db_command.c @@ -1,4 +1,4 @@ -/* $NetBSD: db_command.c,v 1.79 2005/06/01 12:25:27 drochner Exp $ */ +/* $NetBSD: db_command.c,v 1.80 2005/11/26 12:16:44 yamt Exp $ */ /* * Mach Operating System @@ -31,11 +31,12 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.79 2005/06/01 12:25:27 drochner Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.80 2005/11/26 12:16:44 yamt Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" #include "opt_inet.h" +#include "opt_ddbparam.h" #include #include @@ -201,6 +202,10 @@ static const struct db_command db_command_table[] = { }; static const struct db_command *db_last_command = NULL; +#if defined(DDB_COMMANDONENTER) +const char *db_cmd_on_enter = ___STRING(DDB_COMMANDONENTER); +#endif /* defined(DDB_COMMANDONENTER) */ +#define DB_LINE_SEP ';' /* * Utility routine - discard tokens through end-of-line. @@ -244,6 +249,27 @@ db_command_loop(void) db_recover = &db_jmpbuf; (void) setjmp(&db_jmpbuf); +#if defined(DDB_COMMANDONENTER) + if (db_cmd_on_enter != NULL) { + const struct db_command *dummy = NULL; + const char *cmd = db_cmd_on_enter; + + while (*cmd != '\0') { + const char *ep = cmd; + + while (*ep != '\0' && *ep != DB_LINE_SEP) { + ep++; + } + db_set_line(cmd, ep); + db_command(&dummy, db_command_table); + cmd = ep; + if (*cmd == DB_LINE_SEP) { + cmd++; + } + } + } +#endif /* defined(DDB_COMMANDONENTER) */ + while (!db_cmd_loop_done) { if (db_print_position() != 0) db_printf("\n"); diff --git a/sys/ddb/db_lex.c b/sys/ddb/db_lex.c index 70474d9a53ec..4cbe94730868 100644 --- a/sys/ddb/db_lex.c +++ b/sys/ddb/db_lex.c @@ -1,4 +1,4 @@ -/* $NetBSD: db_lex.c,v 1.18 2003/05/17 09:58:03 scw Exp $ */ +/* $NetBSD: db_lex.c,v 1.19 2005/11/26 12:16:45 yamt Exp $ */ /* * Mach Operating System @@ -34,7 +34,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: db_lex.c,v 1.18 2003/05/17 09:58:03 scw Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_lex.c,v 1.19 2005/11/26 12:16:45 yamt Exp $"); #include #include @@ -52,7 +52,8 @@ db_expr_t db_tok_number; char db_tok_string[TOK_STRING_SIZE]; static char db_line[120]; -static char *db_lp, *db_endlp; +static const char *db_lp; +static const char *db_endlp; static int db_look_char = 0; static int db_look_token = 0; @@ -70,11 +71,18 @@ db_read_line(void) i = db_readline(db_line, sizeof(db_line)); if (i == 0) return (0); /* EOI */ - db_lp = db_line; - db_endlp = db_lp + i; + db_set_line(db_line, db_line + i); return (i); } +void +db_set_line(const char *sp, const char *ep) +{ + + db_lp = sp; + db_endlp = ep; +} + static void db_flush_line(void) { diff --git a/sys/ddb/db_lex.h b/sys/ddb/db_lex.h index d8e535aad22e..b8acf466883e 100644 --- a/sys/ddb/db_lex.h +++ b/sys/ddb/db_lex.h @@ -1,4 +1,4 @@ -/* $NetBSD: db_lex.h,v 1.13 2002/02/15 07:33:51 simonb Exp $ */ +/* $NetBSD: db_lex.h,v 1.14 2005/11/26 12:16:45 yamt Exp $ */ /* * Mach Operating System @@ -35,6 +35,7 @@ void db_flush_lex(void); char *db_num_to_str(db_expr_t); int db_read_line(void); +void db_set_line(const char *, const char *); int db_read_token(void); void db_unread_token(int);