Mercurial > hg > octave-kai
changeset 9484:bbe033dcfe13
make dbwhere work when called at keyboard prompt
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 04 Aug 2009 15:32:14 -0400 |
parents | 25c2e92ee03c |
children | 3cee58bf4acf |
files | src/ChangeLog src/debug.cc src/input.cc src/pt-eval.cc src/pt-eval.h src/toplev.cc src/toplev.h |
diffstat | 7 files changed, 75 insertions(+), 80 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,27 @@ +2009-08-04 John W. Eaton <jwe@octave.org> + + * debug.cc (Fdbwhere): Call octave_call_stack::goto_frame_relative + to move to user code frame. Get line and column information from + call stack. + * input.cc (Fkeyboard): Don't pass verbose flag to + octave_call_stack::goto_frame_relative. + (get_debug_input): Get line and column information from call stack. + * pt-eval.h, pt-eval.cc (tree_evaluator::debug_line, + tree_evaluator::debug_column, tree_evaluator::db_line, + tree_evaluator::db_column): Delete. + * pt-eval.cc (tree_evaluator::do_breakpoint): Don't print function + name and location info here. Delete line and column number args. + Change all callers. + + * toplev.h (octave_call_stack::do_current, + octave_call_stack::do_current_statement): New functions. + (octave_call_stack::current): Call do_current, not top. + (octave_call_stack::current_statement): Call do_current_statement, + not top_statement. + (octave_call_stack::top, octave_call_stack::top_statement, + octave_call_stack::do_top, octave_call_stack::do_top_statement): + Delete. + 2009-08-04 John W. Eaton <jwe@octave.org> * toplev.cc (octave_call_stack::do_goto_frame_relative): Allow
--- a/src/debug.cc +++ b/src/debug.cc @@ -661,13 +661,21 @@ octave_stdout << name << ":"; - int l = tree_evaluator::debug_line (); + unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); + + unwind_protect::add_fcn (octave_call_stack::restore_frame, + octave_call_stack::current_frame ()); + + // Skip the frame assigned to the dbwhere function. + octave_call_stack::goto_frame_relative (0); + + int l = octave_call_stack::current_line (); if (l > 0) { octave_stdout << " line " << l; - int c = tree_evaluator::debug_column (); + int c = octave_call_stack::current_column (); if (c > 0) octave_stdout << ", column " << c; @@ -684,6 +692,8 @@ } else octave_stdout << " (unknown line)\n"; + + unwind_protect::run_frame (uwp_frame); } else error ("dbwhere: must be inside of a user function to use dbwhere\n");
--- a/src/input.cc +++ b/src/input.cc @@ -598,7 +598,7 @@ octave_user_code *caller = octave_call_stack::caller_user_code (); std::string nm; - int curr_debug_line = tree_evaluator::debug_line (); + int curr_debug_line = octave_call_stack::current_line (); bool have_file = false; @@ -649,12 +649,7 @@ std::string msg = buf.str (); if (! msg.empty ()) - { - if (! Vgud_mode) - std::cerr << "keyboard: "; - - std::cerr << msg << std::endl; - } + std::cerr << msg << std::endl; unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); @@ -902,6 +897,12 @@ unwind_protect::add_fcn (octave_call_stack::restore_frame, octave_call_stack::current_frame ()); + // FIXME -- probably we just want to print one line, not the + // entire statement, which might span many lines... + // + // tree_print_code tpc (octave_stdout); + // stmt.accept (tpc); + Vsaving_history = true; Vdebugging = true; @@ -944,7 +945,7 @@ octave_call_stack::current_frame ()); // Skip the frame assigned to the keyboard function. - octave_call_stack::goto_frame_relative (0, true); + octave_call_stack::goto_frame_relative (0); do_keyboard (args);
--- a/src/pt-eval.cc +++ b/src/pt-eval.cc @@ -57,9 +57,6 @@ bool tree_evaluator::in_loop_command = false; -int tree_evaluator::db_line = -1; -int tree_evaluator::db_column = -1; - // If TRUE, turn off printing of results in functions (as if a // semicolon has been appended to each statement). static bool Vsilent_functions = false; @@ -90,7 +87,7 @@ if (! error_state) { if (debug_mode) - do_breakpoint (cmd.is_breakpoint (), cmd.line (), cmd.column ()); + do_breakpoint (cmd.is_breakpoint ()); tree_break_command::breaking = 1; } @@ -189,7 +186,7 @@ tree_evaluator::visit_global_command (tree_global_command& cmd) { if (debug_mode) - do_breakpoint (cmd.is_breakpoint (), cmd.line (), cmd.column ()); + do_breakpoint (cmd.is_breakpoint ()); do_decl_init_list (do_global_init, cmd.initializer_list ()); } @@ -198,7 +195,7 @@ tree_evaluator::visit_static_command (tree_static_command& cmd) { if (debug_mode) - do_breakpoint (cmd.is_breakpoint (), cmd.line (), cmd.column ()); + do_breakpoint (cmd.is_breakpoint ()); do_decl_init_list (do_static_init, cmd.initializer_list ()); } @@ -280,7 +277,7 @@ return; if (debug_mode) - do_breakpoint (cmd.is_breakpoint (), cmd.line (), cmd.column ()); + do_breakpoint (cmd.is_breakpoint ()); unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); @@ -402,7 +399,7 @@ return; if (debug_mode) - do_breakpoint (cmd.is_breakpoint (), cmd.line (), cmd.column ()); + do_breakpoint (cmd.is_breakpoint ()); unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); @@ -541,7 +538,7 @@ tree_expression *expr = tic->condition (); if (debug_mode && ! tic->is_else_clause ()) - do_breakpoint (tic->is_breakpoint (), tic->line (), tic->column ()); + do_breakpoint (tic->is_breakpoint ()); if (tic->is_else_clause () || expr->is_logically_true ("if")) { @@ -586,7 +583,7 @@ tree_evaluator::visit_no_op_command (tree_no_op_command& cmd) { if (debug_mode && cmd.is_end_of_fcn_or_script ()) - do_breakpoint (cmd.is_breakpoint (), cmd.line (), cmd.column (), true); + do_breakpoint (cmd.is_breakpoint (), true); } void @@ -625,7 +622,7 @@ if (! error_state) { if (debug_mode) - do_breakpoint (cmd.is_breakpoint (), cmd.line (), cmd.column ()); + do_breakpoint (cmd.is_breakpoint ()); tree_return_command::returning = 1; } @@ -666,8 +663,7 @@ else { if (debug_mode) - do_breakpoint (expr->is_breakpoint (), expr->line (), - expr->column ()); + do_breakpoint (expr->is_breakpoint ()); if (in_fcn_or_script_body && Vsilent_functions) expr->set_print_flag (false); @@ -797,7 +793,7 @@ tree_switch_case *t = *p; if (debug_mode && ! t->is_default_case ()) - do_breakpoint (t->is_breakpoint (), t->line (), t->column ()); + do_breakpoint (t->is_breakpoint ()); if (t->is_default_case () || t->label_matches (val)) { @@ -1006,13 +1002,10 @@ if (! expr) panic_impossible (); - int l = expr->line (); - int c = expr->column (); - for (;;) { if (debug_mode) - do_breakpoint (cmd.is_breakpoint (), l, c); + do_breakpoint (cmd.is_breakpoint ()); if (expr->is_logically_true ("while")) { @@ -1054,9 +1047,6 @@ if (! expr) panic_impossible (); - int l = expr->line (); - int c = expr->column (); - for (;;) { tree_statement_list *loop_body = cmd.body (); @@ -1073,7 +1063,7 @@ break; if (debug_mode) - do_breakpoint (cmd.is_breakpoint (), l, c); + do_breakpoint (cmd.is_breakpoint ()); if (expr->is_logically_true ("do-until")) break; @@ -1086,12 +1076,11 @@ void tree_evaluator::do_breakpoint (tree_statement& stmt) const { - do_breakpoint (stmt.is_breakpoint (), stmt.line (), stmt.column (), - stmt.is_end_of_fcn_or_script ()); + do_breakpoint (stmt.is_breakpoint (), stmt.is_end_of_fcn_or_script ()); } void -tree_evaluator::do_breakpoint (bool is_breakpoint, int l, int c, +tree_evaluator::do_breakpoint (bool is_breakpoint, bool is_end_of_fcn_or_script) const { bool break_on_this_statement = false; @@ -1160,25 +1149,7 @@ } if (break_on_this_statement) - { - octave_function *xfcn = octave_call_stack::current (); - - if (xfcn) - std::cerr << xfcn->name () << ": "; - - std::cerr << "line " << l << ", " << "column " << c << std::endl; - - db_line = l; - db_column = c; - - // FIXME -- probably we just want to print one line, not the - // entire statement, which might span many lines... - // - // tree_print_code tpc (octave_stdout); - // stmt.accept (tpc); - - do_keyboard (); - } + do_keyboard (); } DEFUN (silent_functions, args, nargout,
--- a/src/pt-eval.h +++ b/src/pt-eval.h @@ -132,10 +132,6 @@ void visit_do_until_command (tree_do_until_command&); - static int debug_line (void) { return db_line; } - - static int debug_column (void) { return db_column; } - // If > 0, stop executing at the (N-1)th stopping point, counting // from the the current execution point in the current frame. // @@ -160,12 +156,9 @@ void do_breakpoint (tree_statement& stmt) const; - void do_breakpoint (bool is_breakpoint, int l, int c, + void do_breakpoint (bool is_breakpoint, bool is_end_of_fcn_or_script = false) const; - static int db_line; - static int db_column; - // No copying! tree_evaluator (const tree_evaluator&);
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -104,7 +104,7 @@ int octave_call_stack::do_current_line (void) const { - tree_statement *stmt = do_top_statement (); + tree_statement *stmt = do_current_statement (); return stmt ? stmt->line () : -1; } @@ -112,7 +112,7 @@ int octave_call_stack::do_current_column (void) const { - tree_statement *stmt = do_top_statement (); + tree_statement *stmt = do_current_statement (); return stmt ? stmt->column () : -1; }
--- a/src/toplev.h +++ b/src/toplev.h @@ -135,10 +135,16 @@ } // Current function (top of stack). - static octave_function *current (void) { return top (); } + static octave_function *current (void) + { + return instance_ok () ? instance->do_current () : 0; + } // Current statement (top of stack). - static tree_statement *current_statement (void) { return top_statement (); } + static tree_statement *current_statement (void) + { + return instance_ok () ? instance->do_current_statement () : 0; + } // Current line in current function. static int current_line (void) @@ -226,16 +232,6 @@ instance->do_push (0, scope, context); } - static octave_function *top (void) - { - return instance_ok () ? instance->do_top (): 0; - } - - static tree_statement *top_statement (void) - { - return instance_ok () ? instance->do_top_statement (): 0; - } - static void set_statement (tree_statement *s) { if (instance_ok ()) @@ -358,26 +354,26 @@ symbol_table::set_scope_and_context (scope, context); } - octave_function *do_top (void) const + octave_function *do_current (void) const { octave_function *retval = 0; if (! cs.empty ()) { - const call_stack_elt& elt = cs.back (); + const call_stack_elt& elt = cs[curr_frame]; retval = elt.fcn; } return retval; } - tree_statement *do_top_statement (void) const + tree_statement *do_current_statement (void) const { tree_statement *retval = 0; if (! cs.empty ()) { - const call_stack_elt& elt = cs.back (); + const call_stack_elt& elt = cs[curr_frame]; retval = elt.stmt; }