summaryrefslogtreecommitdiffstats
path: root/sys/ddb/db_lex.c
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2007-12-26 09:33:19 +0000
committerrwatson <rwatson@FreeBSD.org>2007-12-26 09:33:19 +0000
commit6ff1515c5f8d3787a46b92ded45aacb75cec051e (patch)
treea166a654090db301023b94b02c647554eb7320ae /sys/ddb/db_lex.c
parent19ae9a5e773935b7d124c45606ca64d72213a810 (diff)
downloadFreeBSD-src-6ff1515c5f8d3787a46b92ded45aacb75cec051e.zip
FreeBSD-src-6ff1515c5f8d3787a46b92ded45aacb75cec051e.tar.gz
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
Diffstat (limited to 'sys/ddb/db_lex.c')
-rw-r--r--sys/ddb/db_lex.c31
1 files changed, 30 insertions, 1 deletions
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 <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 == '<')
OpenPOWER on IntegriCloud