From 6ff1515c5f8d3787a46b92ded45aacb75cec051e Mon Sep 17 00:00:00 2001 From: rwatson Date: Wed, 26 Dec 2007 09:33:19 +0000 Subject: Add a simple scripting facility to DDB(4), allowing the user to define a set of named scripts. Each script consists of a list of DDB commands separated by ";"s that will be executed verbatim. No higher level language constructs, such as branching, are provided for: scripts are executed by sequentially injecting commands into the DDB input buffer. Four new commands are present in DDB: "run" to run a specific script, "script" to define or print a script, "scripts" to list currently defined scripts, and "unscript" to delete a script, modeled on shell alias commands. Scripts may also be manipulated using sysctls in the debug.ddb.scripting MIB space, although users will prefer to use the soon-to-be-added ddb(8) tool for usability reasons. Scripts with certain names are automatically executed on various DDB events, such as entering the debugger via a panic, a witness error, watchdog, breakpoint, sysctl, serial break, etc, allowing customized handling. MFC after: 3 months --- sys/ddb/db_lex.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'sys/ddb/db_lex.c') diff --git a/sys/ddb/db_lex.c b/sys/ddb/db_lex.c index a04103b..1c8151e 100644 --- a/sys/ddb/db_lex.c +++ b/sys/ddb/db_lex.c @@ -35,11 +35,12 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include -static char db_line[120]; +static char db_line[DB_MAXLINE]; static char * db_lp, *db_endlp; static int db_lex(void); @@ -60,6 +61,32 @@ db_read_line() return (i); } +/* + * Simulate a line of input into DDB. + */ +void +db_inject_line(const char *command) +{ + + strlcpy(db_line, command, sizeof(db_line)); + db_lp = db_line; + db_endlp = db_lp + strlen(command); +} + +/* + * In rare cases, we may want to pull the remainder of the line input + * verbatim, rather than lexing it. For example, when assigning literal + * values associated with scripts. In that case, return a static pointer to + * the current location in the input buffer. The caller must be aware that + * the contents are not stable if other lex/input calls are made. + */ +char * +db_get_line(void) +{ + + return (db_lp); +} + static void db_flush_line() { @@ -264,6 +291,8 @@ db_lex() return (tDOLLAR); case '!': return (tEXCL); + case ';': + return (tSEMI); case '<': c = db_read_char(); if (c == '<') -- cgit v1.1