Skip to content

Commit

Permalink
Add --xtrace-to-debug-file.
Browse files Browse the repository at this point in the history
I expect this to be the more common usage (although the flag name is
verbose).

And it fixes a spec test.

Make a dev.DevTools() bundle for convenience.
  • Loading branch information
Andy Chu committed Sep 26, 2018
1 parent 112e88f commit cd5a84f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
9 changes: 8 additions & 1 deletion bin/oil.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def _ShowVersion():
OSH_SPEC.LongFlag('--print-status') # TODO: Replace with a shell hook
OSH_SPEC.LongFlag('--hijack-shebang') # TODO: Implement this
OSH_SPEC.LongFlag('--debug-file', args.Str)
OSH_SPEC.LongFlag('--xtrace-to-debug-file')

# For benchmarks/*.sh
OSH_SPEC.LongFlag('--parser-mem-dump', args.Str)
Expand Down Expand Up @@ -166,8 +167,14 @@ def OshMain(argv0, argv, login_shell):

# Controlled by env variable, flag, or hook?
dumper = dev.CrashDumper(os.getenv('OSH_CRASH_DUMP_DIR', ''))
if opts.xtrace_to_debug_file:
trace_f = debug_f
else:
trace_f = util.DebugFile(sys.stderr)
devtools = dev.DevTools(dumper, debug_f, trace_f)

ex = cmd_exec.Executor(mem, fd_state, funcs, comp_lookup, exec_opts,
parse_ctx, dumper, debug_f)
parse_ctx, devtools)

# NOTE: The rc file can contain both commands and functions... ideally we
# would only want to save nodes/lines for the functions.
Expand Down
13 changes: 5 additions & 8 deletions core/cmd_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Executor(object):
CompoundWord/WordPart.
"""
def __init__(self, mem, fd_state, funcs, comp_lookup, exec_opts, parse_ctx,
dumper, debug_f):
devtools):
"""
Args:
mem: Mem instance for storing variables
Expand All @@ -127,8 +127,8 @@ def __init__(self, mem, fd_state, funcs, comp_lookup, exec_opts, parse_ctx,
self.parse_ctx = parse_ctx
self.arena = parse_ctx.arena
self.aliases = parse_ctx.aliases # alias name -> string
self.dumper = dumper
self.debug_f = debug_f # Used by ShellFuncAction too
self.dumper = devtools.dumper
self.debug_f = devtools.debug_f # Used by ShellFuncAction too

self.splitter = legacy.SplitContext(self.mem)
self.word_ev = word_eval.NormalWordEvaluator(mem, exec_opts, self.splitter,
Expand All @@ -147,13 +147,10 @@ def __init__(self, mem, fd_state, funcs, comp_lookup, exec_opts, parse_ctx,
self.waiter = process.Waiter()
# sleep 5 & puts a (PID, job#) entry here. And then "jobs" displays it.
self.job_state = process.JobState()
self.tracer = Tracer(parse_ctx, exec_opts, mem, self.word_ev,
devtools.trace_f)

self.loop_level = 0 # for detecting bad top-level break/continue
if 1:
trace_f = debug_f
else:
trace_f = util.DebugFile(sys.stderr)
self.tracer = Tracer(parse_ctx, exec_opts, mem, self.word_ev, trace_f)
self.check_command_sub_status = False # a hack

def _EvalHelper(self, c_parser, source_name):
Expand Down
6 changes: 4 additions & 2 deletions core/cmd_exec_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ def InitExecutor(arena=None):
# For the tests, we do not use 'readline'.
exec_opts = state.ExecOpts(mem, None)
parse_ctx = parse_lib.ParseContext(arena, {})
dumper = dev.CrashDumper('')

debug_f = util.DebugFile(sys.stderr)
devtools = dev.DevTools(dev.CrashDumper(''), debug_f, debug_f)

return cmd_exec.Executor(mem, fd_state, funcs, comp_funcs, exec_opts,
parse_ctx, dumper, debug_f)
parse_ctx, devtools)


def InitEvaluator():
Expand Down
2 changes: 1 addition & 1 deletion core/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def Matches(self, words, index, to_complete):
self.log('Got status 124 from %r', self.func.name)
# The previous run may have registered another function via 'complete',
# i.e. by sourcing a file. Try it again.
status = self.ex.RunFuncForCompletion(self.func)
status = self.ex.RunFuncForCompletion(self.func, argv)
if status == 124:
util.warn('Got exit code 124 from function %r twice', self.func.name)

Expand Down
8 changes: 8 additions & 0 deletions core/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

# TODO: Move Tracer here.


class DevTools(object):
def __init__(self, dumper, debug_f, trace_f):
self.dumper = dumper
self.debug_f = debug_f
self.trace_f = trace_f


def SpanIdFromError(error):
#print(parse_error)
if error.span_id != const.NO_INTEGER:
Expand Down
2 changes: 1 addition & 1 deletion scripts/complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ osh-trace() {
# $FUNCNAME displays the whole stack in osh (unlike bash), but ${FUNCNAME[0]}
# displays the top.
env -i OSH_CRASH_DUMP_DIR=_tmp PS4='+[${LINENO}:${FUNCNAME}] ' \
bin/osh -x --debug-file _tmp/debug "$@"
bin/osh -x --debug-file _tmp/debug --xtrace-to-debug-file "$@"
}

bash-bash() {
Expand Down

0 comments on commit cd5a84f

Please sign in to comment.