diff options
author | Devin Teske <dteske@FreeBSD.org> | 2018-04-22 02:20:17 +0000 |
---|---|---|
committer | Devin Teske <dteske@FreeBSD.org> | 2018-04-22 02:20:17 +0000 |
commit | bcce9a2b33a8e9187a63f435726a7a801e89f326 (patch) | |
tree | e70d1f3b731bf0408328a7fa8ec283f394e44ba4 /cddl/usr.sbin | |
parent | bd674818334166efa698c71952d913e8ab350405 (diff) | |
download | src-bcce9a2b33a8e9187a63f435726a7a801e89f326.tar.gz src-bcce9a2b33a8e9187a63f435726a7a801e89f326.zip |
dwatch(1): Add `-dev' option to aid debugging of profiles
The options `-d' (debug), `-e' (exit after compile), and `-v' (verbose)
when combined in any order (though best remembered as `-dev') will run
the conflated script through dtrace(1), test for error conditions, and
show the line that dtrace(1) failed at (with context).
If no errors are found, the output is the same as `-e[v]'.
When writing a new profile for dwatch(1), you can quickly test to
make sure it compiles by running `dwatch -devX profile_name' where
profiles live in /usr/libexec/dwatch or /usr/local/libexec/dwatch
(the latter being where profiles installed via ports should go).
Sponsored by: Smule, Inc.
Notes
Notes:
svn path=/head/; revision=332865
Diffstat (limited to 'cddl/usr.sbin')
-rwxr-xr-x | cddl/usr.sbin/dwatch/dwatch | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/cddl/usr.sbin/dwatch/dwatch b/cddl/usr.sbin/dwatch/dwatch index c6cec1a3b709..05a007dccde1 100755 --- a/cddl/usr.sbin/dwatch/dwatch +++ b/cddl/usr.sbin/dwatch/dwatch @@ -47,7 +47,7 @@ DTRACE_PRAGMA=" ############################################################ GLOBALS -VERSION='$Version: 1.0 $' # -V +VERSION='$Version: 1.1 $' # -V pgm="${0##*/}" # Program basename @@ -67,6 +67,7 @@ CUSTOM_DETAILS= # -E code CUSTOM_TEST= # -t test DEBUG= # -d DESTRUCTIVE_ACTIONS= # -w +DEVELOPER= # -dev EXECNAME= # -k name EXECREGEX= # -z regex EXIT_AFTER_COMPILE= # -e @@ -835,6 +836,11 @@ if [ "$PROBE_ARG" ]; then fi # +# Developer switch +# +[ "$DEBUG" -a "$EXIT_AFTER_COMPILE" -a "$VERBOSE" ] && DEVELOPER=1 DEBUG= + +# # Set default event details if `-E code' was not given # [ "$CUSTOM_DETAILS" ] || EVENT_DETAILS=$( pproc_dump 0 ) @@ -966,6 +972,61 @@ PSARGS_ACTION=$( cat <&9 ) exec 3>&1 console_stdout=3 + # + # Developer debugging aide + # + if [ "$DEVELOPER" ]; then + # + # Run, capture the error line, and focus it + # + # Example error text to capture line number from: + # dtrace: failed to compile script /dev/stdin: line 669: ... + # + errline= + stdin_buf=$( cat ) + stderr_buf=$( echo "$stdin_buf" | + dtrace_cmd -t -es /dev/stdin "$@" 2>&1 > /dev/null ) + status=$? + if [ "$stderr_buf" ]; then + errline=$( echo "$stderr_buf" | awk ' + BEGIN { + ti = "\033[31m" + te = "\033[39m" + } + { line = $0 } + sub(/.*: line /, "") && sub(/:.*/, "") { + print # to errline + sub("line " $0, ti "&" te, line) + } + { print line > "/dev/stderr" } + ' 2>&3 ) + fi + if [ "$errline" ]; then + echo "$stdin_buf" | awk -v line="${errline%%[^0-9]*}" ' + BEGIN { + start = line < 10 ? 1 : line - 10 + end = line + 10 + slen = length(sprintf("%u", start)) + elen = length(sprintf("%u", end)) + N = elen > slen ? elen : slen + for (i = start; i <= end; i++) { + ti[i] = "\033[2m" + te[i] = "\033[22m" + } + ti[line] = "\033[31m" + te[line] = "\033[39m" + fmt = "%s%*u %s%s\n" + } + NR < start { next } + NR == start, NR == end { + printf(fmt, ti[NR], N, NR, $0, te[NR]) + } + NR > end { exit } + ' # END-QUOTE + fi + exit $status + fi + if [ $COUNT -eq 0 -a ! "$EXECREGEX$FILTER$GROUP$OUTPUT_CMD$PID$USER" ] then case "$OUTPUT" in @@ -1285,6 +1346,7 @@ $( pproc_dump -v 3 )} } EOF +# NOTREACHED ################################################################################ # END |