Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[devtools] Tweaks to log OSH usage during its own release.
- Add support for OSH_DEBUG_DIR in addition to --debug-file. The former will have files named by PID. - Expose the issue with subshells and the CrashDumper. Add a PID to the crash dump filename for now. - Make naming more consistent in demo/ - osh-debug.sh: Shell functions for doing the release interactively under OSH.
- Loading branch information
Andy Chu
committed
Jan 28, 2019
1 parent
5e8af65
commit d40f6b4
Showing
8 changed files
with
140 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
# | ||
# Usage: | ||
# ./crash.sh <function name> | ||
|
||
set -o nounset | ||
set -o pipefail | ||
set -o errexit | ||
|
||
g() { | ||
local g=1 | ||
echo foo > $bar | ||
} | ||
|
||
f() { | ||
shift | ||
local flocal=flocal | ||
FOO=bar g A B | ||
} | ||
|
||
main() { | ||
f a b c | ||
} | ||
|
||
run-with-osh() { | ||
OSH_CRASH_DUMP_DIR=_tmp bin/osh $0 main "$@" | ||
} | ||
|
||
_do-subshell() { | ||
echo PID=$$ | ||
( f a b c ) | ||
} | ||
|
||
# Problem: we get two difference crash dumps, with two different stacks. | ||
# It would be nice to unify these somehow. | ||
# | ||
# Could we add a URL to link related crash dumps? Maybe do it with PPID? If a | ||
# subshell exits with 1, and we have OSH_CRASH_DUMP_DIR, then we know it should | ||
# have exited? | ||
# | ||
# MaybeCollect is done on fatal errors in several places. MaybeDump is done on | ||
# ExecuteAndCatch. Subshells raise SystemExit? | ||
|
||
do-subshell() { | ||
# clear environment so it's smaller | ||
env -i OSH_CRASH_DUMP_DIR=_tmp bin/osh $0 _do-subshell "$@" | ||
} | ||
|
||
"$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
# | ||
# Usage: | ||
# ./osh-debug.sh <function name> | ||
|
||
set -o nounset | ||
set -o pipefail | ||
set -o errexit | ||
|
||
func() { | ||
metrics/source-code.sh osh-cloc | ||
} | ||
|
||
# Make sure it works recursively | ||
# | ||
# Problem: xargs, find -exec, make, etc. won't respect this! They will use the | ||
# real shebang. | ||
|
||
recursive() { | ||
echo === | ||
$0 func | ||
echo === | ||
} | ||
|
||
hijack-recursive() { | ||
# $(which osh) | ||
|
||
local dir=_tmp/osh-debug | ||
mkdir -p $dir | ||
|
||
OSH_DEBUG_DIR=$dir \ | ||
OSH_HIJACK_SHEBANG=bin/osh \ | ||
bin/osh $0 recursive | ||
} | ||
|
||
# | ||
# For the release | ||
# | ||
|
||
readonly RELEASE_LOGS_DIR=_tmp/osh-debug-release | ||
|
||
osh-for-release() { | ||
mkdir -p $RELEASE_LOGS_DIR | ||
rm -f $RELEASE_LOGS_DIR/* | ||
|
||
# NOTE: This runs the SYSTEM osh, because running bin/osh while doing the | ||
# release doesn't work! | ||
OSH_DEBUG_DIR=$RELEASE_LOGS_DIR OSH_HIJACK_SHEBANG=$(which osh) osh | ||
} | ||
|
||
analyze() { | ||
grep '^Hijacked' $RELEASE_LOGS_DIR/* | ||
} | ||
|
||
"$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters