Skip to content

Commit

Permalink
test/common: Make sure that extdebug is enabled as soon as possible
Browse files Browse the repository at this point in the history
if given script, which executes under the debug tracer, fails before
xtrace_restore() is called, the BASH_ARGC[] will miss all the arguments
which were passed down till that very point. Similar case can be
experienced after tracer is disabled as then all the arguments hold by
BASH_ARG{C,V}[] become unavailable (i.e. until tracer is enabled again).

Since there's no actual benefit from toggling the extdebug (in fact, it
could break DEBUG|RETURN traps if ever used), enable it once when
autotest_common.sh is sourced and keep it enabled throughout entire
execution of given script.

Change-Id: I01001ead1570967a2e550d993f85f12b9f62553e
Signed-off-by: Michal Berger <michalx.berger@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/477
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
  • Loading branch information
Michal Berger authored and tomzawadzki committed Feb 11, 2020
1 parent db65d58 commit a8d0169
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/common/autotest_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ function xtrace_disable() {
XTRACE_DISABLED="yes"
fi
set +x
shopt -u extdebug
elif [ -z $XTRACE_NESTING_LEVEL ]; then
XTRACE_NESTING_LEVEL=1
else
Expand All @@ -31,7 +30,7 @@ function xtrace_enable() {
alias xtrace_restore=\
'if [ -z $XTRACE_NESTING_LEVEL ]; then
if [[ "$PREV_BASH_OPTS" == *"x"* ]]; then
XTRACE_DISABLED="no"; PREV_BASH_OPTS=""; shopt -s extdebug; set -x; xtrace_enable;
XTRACE_DISABLED="no"; PREV_BASH_OPTS=""; set -x; xtrace_enable;
fi
else
XTRACE_NESTING_LEVEL=$((--XTRACE_NESTING_LEVEL));
Expand Down Expand Up @@ -1065,6 +1064,7 @@ function opal_revert_cleanup {
}

set -o errtrace
shopt -s extdebug
trap "trap - ERR; print_backtrace >&2" ERR

PS4=' \t \$ '
Expand Down

0 comments on commit a8d0169

Please sign in to comment.