diff options
author | Robert Watson <rwatson@FreeBSD.org> | 2007-12-26 09:33:19 +0000 |
---|---|---|
committer | Robert Watson <rwatson@FreeBSD.org> | 2007-12-26 09:33:19 +0000 |
commit | c9b0cc3b9623c30583400b137b82ec92483435ad (patch) | |
tree | a166a654090db301023b94b02c647554eb7320ae /sys/ddb/db_lex.c | |
parent | e361d7d421054f4f4a30ff48ed4590ee5292db05 (diff) | |
download | src-c9b0cc3b9623c30583400b137b82ec92483435ad.tar.gz src-c9b0cc3b9623c30583400b137b82ec92483435ad.zip |
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
Notes
Notes:
svn path=/head/; revision=174914
Diffstat (limited to 'sys/ddb/db_lex.c')
-rw-r--r-- | sys/ddb/db_lex.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/sys/ddb/db_lex.c b/sys/ddb/db_lex.c index a04103b00deb..1c8151e5371c 100644 --- a/sys/ddb/db_lex.c +++ b/sys/ddb/db_lex.c @@ -35,11 +35,12 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> +#include <sys/libkern.h> #include <ddb/ddb.h> #include <ddb/db_lex.h> -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 == '<') |