Mercurial > octave
changeset 22164:5d4a286061c8
Track line numbers when in debug mode (bug #45764)
* pt-eval.cc (visit_statement): update location if new variable
Vtrack_line_number is true, rather than simply not debugging.
* input.{h,cc}: Declare and define Vtrack_line_number.
* input.cc (do_keyboard): set Vtrack_line_number = false, because
commands entered from the keyboard do not have valid line numbers.
* ov-usr-fcn.cc (octave_user_script::do_multi_index_op,
octave_user_function::do_multi_index_op): Set Vtrack_line_number =
true whenever executing a function or script, since these line
numbers are meaningful. Unwind/protect so future keyboard commands
do not corrupt the program line number.
* debug.cc (Fdbcont, Fdbstep): set Vtrack_line_number = true when
resuming running code.
author | Lachlan Andrew <lachlanbis@gmail.com> |
---|---|
date | Thu, 30 Jun 2016 18:17:26 +1000 |
parents | ae89334cb536 |
children | 20e684ec108e |
files | libinterp/corefcn/debug.cc libinterp/corefcn/input.cc libinterp/corefcn/input.h libinterp/octave-value/ov-usr-fcn.cc libinterp/parse-tree/pt-eval.cc |
diffstat | 5 files changed, 25 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/debug.cc Wed Jul 20 16:27:49 2016 +0200 +++ b/libinterp/corefcn/debug.cc Thu Jun 30 18:17:26 2016 +1000 @@ -2094,12 +2094,14 @@ if (arg == "in") { Vdebugging = false; + Vtrack_line_num = true; tree_evaluator::dbstep_flag = -1; } else if (arg == "out") { Vdebugging = false; + Vtrack_line_num = true; tree_evaluator::dbstep_flag = -2; } @@ -2111,6 +2113,7 @@ error ("dbstep: invalid argument"); Vdebugging = false; + Vtrack_line_num = true; tree_evaluator::dbstep_flag = n; } @@ -2118,6 +2121,7 @@ else { Vdebugging = false; + Vtrack_line_num = true; tree_evaluator::dbstep_flag = 1; } @@ -2141,6 +2145,7 @@ print_usage (); Vdebugging = false; + Vtrack_line_num = true; tree_evaluator::reset_debug_state ();
--- a/libinterp/corefcn/input.cc Wed Jul 20 16:27:49 2016 +0200 +++ b/libinterp/corefcn/input.cc Thu Jun 30 18:17:26 2016 +1000 @@ -108,6 +108,11 @@ // TRUE if we are in debugging mode. bool Vdebugging = false; +// TRUE if we are recording line numbers in a source file. +// Always true except when debugging and taking input directly from +// the terminal. +bool Vtrack_line_num = true; + // If we are in debugging mode, this is the last command entered, so // that we can repeat the previous command if the user just types RET. static std::string last_debugging_command = "\n"; @@ -621,6 +626,8 @@ { try { + Vtrack_line_num = false; + reset_error_handler (); curr_parser.reset (); @@ -885,6 +892,7 @@ // stmt.accept (tpc); Vdebugging = true; + Vtrack_line_num = false; std::string prompt = "debug> "; if (nargin > 0)
--- a/libinterp/corefcn/input.h Wed Jul 20 16:27:49 2016 +0200 +++ b/libinterp/corefcn/input.h Thu Jun 30 18:17:26 2016 +1000 @@ -50,6 +50,9 @@ // TRUE if we are in debugging mode. extern OCTINTERP_API bool Vdebugging; +// TRUE if we are not executing a command direct from debug> prompt. +extern OCTINTERP_API bool Vtrack_line_num; + extern void initialize_command_input (void); extern bool octave_yes_or_no (const std::string& prompt);
--- a/libinterp/octave-value/ov-usr-fcn.cc Wed Jul 20 16:27:49 2016 +0200 +++ b/libinterp/octave-value/ov-usr-fcn.cc Thu Jun 30 18:17:26 2016 +1000 @@ -141,6 +141,9 @@ frame.add_fcn (octave_call_stack::pop); + frame.protect_var (Vtrack_line_num); + Vtrack_line_num = true; // update line no. even if debugging + frame.protect_var (tree_evaluator::statement_context); tree_evaluator::statement_context = tree_evaluator::script; @@ -504,6 +507,9 @@ int context = active_context (); octave_call_stack::push (this, local_scope, context); + + frame.protect_var (Vtrack_line_num); + Vtrack_line_num = true; // update source line numbers, even if debugging frame.add_fcn (octave_call_stack::pop); if (call_depth > 0 && ! is_anonymous_function ())
--- a/libinterp/parse-tree/pt-eval.cc Wed Jul 20 16:27:49 2016 +0200 +++ b/libinterp/parse-tree/pt-eval.cc Thu Jun 30 18:17:26 2016 +1000 @@ -663,9 +663,10 @@ if (statement_context == function || statement_context == script) { // Skip commands issued at a debug> prompt to avoid disturbing - // the state of the program we are debugging. + // the state of the program we are debugging, but still track + // progress through user functions called from debug> prompt. - if (! Vdebugging) + if (Vtrack_line_num) octave_call_stack::set_location (stmt.line (), stmt.column ()); if ((statement_context == script