diff --git a/README.md b/README.md index ed4a086..a3b5d60 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,9 @@ Querying: - `st`: show the "status" (current function, source code and current expression to run) - `bt`: show a backtrace - `fr [i::Int]`: show all variables in the current or `i`th frame +- `p` + - `p`: print all currently defined variables + - `p x` : print the value of the variable `x` Evaluation: - `w` diff --git a/src/commands.jl b/src/commands.jl index bc38666..feb0120 100644 --- a/src/commands.jl +++ b/src/commands.jl @@ -1,4 +1,3 @@ - function assert_allow_step(state) if state.broke_on_error printstyled(stderr, "Cannot step after breaking on error\n"; color=Base.error_color()) @@ -140,6 +139,26 @@ function execute_command(state::DebuggerState, v::Union{Val{:up}, Val{:down}}, c end return execute_command(state, Val(:f), string("f ", state.level + offset)) end + +function execute_command(state::DebuggerState, ::Val{:p}, cmd::AbstractString) + cmds = split(cmd, r" +") + io = Base.pipe_writer(state.terminal) + frame = active_frame(state) + if length(cmds) == 1 + print_locals(io, frame) + else + vars = JuliaInterpreter.locals(frame) + for requested_var in cmds[2:end] + for var in vars + if string(var.name) == requested_var + print_var(io, var) + end + end + end + end + return false +end + function execute_command(state::DebuggerState, ::Val{:w}, cmd::AbstractString) # TODO show some info messages? cmds = split(cmd, r" +") @@ -269,6 +288,9 @@ function execute_command(state::DebuggerState, ::Union{Val{:help}, Val{:?}}, cmd - `st`: show the "status" (current function, source code and current expression to run)\\ - `bt`: show a backtrace\\ - `fr [i::Int]`: show all variables in the current or `i`th frame\\ + - `p`\\ + - `p`: print all currently defined variables\\ + - `p x` : print the value of the variable `x`\\ Evaluation:\\