changeset 25402:ef2b9d4abf4a

eliminate some global variables from tree_evaluator * debug.cc (F__db_next_breakpoint_quiet__): Define with DEFMETHOD. * octave-cmd.cc (octave_cmd_debug::execute): Call F__db_next_breakpoint_quiet__ as an interpreter method. * pt-eval.h, pt-eval.cc (tree_evaluator::m_current_frame, tree_evaluator::m_debug_mode, tree_evaluator::m_quiet_breakpoint_flag): New data members to replace static data members. (tree_evaluator::current_frame, tree_evaluator::debug_mode, tree_evaluator::quiet_breakpoint_flag): New functions. Adapat usage.
author John W. Eaton <jwe@octave.org>
date Tue, 22 May 2018 11:39:44 -0400
parents 6f6479125d80
children 2b7d7a3f5f57
files libgui/src/octave-cmd.cc libinterp/corefcn/debug.cc libinterp/corefcn/error.cc libinterp/corefcn/input.cc libinterp/parse-tree/bp-table.cc libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt-eval.h
diffstat 7 files changed, 86 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/octave-cmd.cc	Tue May 22 00:53:15 2018 -0400
+++ b/libgui/src/octave-cmd.cc	Tue May 22 11:39:44 2018 -0400
@@ -79,19 +79,19 @@
   {
     if (m_cmd == "step")
       {
-        F__db_next_breakpoint_quiet__ (ovl (m_suppress_dbg_location));
+        F__db_next_breakpoint_quiet__ (interp, ovl (m_suppress_dbg_location));
         Fdbstep (interp);
       }
     else if (m_cmd == "cont")
       {
-        F__db_next_breakpoint_quiet__ (ovl (m_suppress_dbg_location));
+        F__db_next_breakpoint_quiet__ (interp, ovl (m_suppress_dbg_location));
         Fdbcont (interp);
       }
     else if (m_cmd == "quit")
       Fdbquit (interp);
     else
       {
-        F__db_next_breakpoint_quiet__ (ovl (m_suppress_dbg_location));
+        F__db_next_breakpoint_quiet__ (interp, ovl (m_suppress_dbg_location));
         Fdbstep (interp, ovl (m_cmd.toStdString ()));
       }
 
--- a/libinterp/corefcn/debug.cc	Tue May 22 00:53:15 2018 -0400
+++ b/libinterp/corefcn/debug.cc	Tue May 22 11:39:44 2018 -0400
@@ -1202,8 +1202,8 @@
   return ovl (Vdebugging);
 }
 
-DEFUN (__db_next_breakpoint_quiet__, args, ,
-       doc: /* -*- texinfo -*-
+DEFMETHOD (__db_next_breakpoint_quiet__, interp, args, ,
+           doc: /* -*- texinfo -*-
 @deftypefn  {} {} __db_next_breakpoint_quiet__ ()
 @deftypefnx {} {} __db_next_breakpoint_quiet__ (@var{flag})
 Disable line info printing at the next breakpoint.
@@ -1221,7 +1221,9 @@
   if (nargin == 1)
     state = args(0).bool_value ();
 
-  octave::tree_evaluator::quiet_breakpoint_flag = state;
+  octave::tree_evaluator& tw = interp.get_evaluator ();
+
+  tw.quiet_breakpoint_flag (state);
 
   return ovl ();
 }
--- a/libinterp/corefcn/error.cc	Tue May 22 00:53:15 2018 -0400
+++ b/libinterp/corefcn/error.cc	Tue May 22 11:39:44 2018 -0400
@@ -368,9 +368,11 @@
       frame.protect_var (Vdebug_on_error);
       Vdebug_on_error = false;
 
-      octave::tree_evaluator::debug_mode = true;
+      octave::tree_evaluator& tw
+        = octave::__get_evaluator__ ("maybe_enter_debugger");
 
-      octave::tree_evaluator::current_frame = cs.current_frame ();
+      tw.debug_mode (true);
+      tw.current_frame (cs.current_frame ());
 
       if (show_stack_trace)
         {
@@ -767,9 +769,11 @@
           frame.protect_var (Vdebug_on_warning);
           Vdebug_on_warning = false;
 
-          octave::tree_evaluator::debug_mode = true;
+          octave::tree_evaluator& tw
+            = octave::__get_evaluator__ ("maybe_enter_debugger");
 
-          octave::tree_evaluator::current_frame = cs.current_frame ();
+          tw.debug_mode (true);
+          tw.current_frame (cs.current_frame ());
 
           do_keyboard (octave_value_list ());
         }
--- a/libinterp/corefcn/input.cc	Tue May 22 00:53:15 2018 -0400
+++ b/libinterp/corefcn/input.cc	Tue May 22 11:39:44 2018 -0400
@@ -623,8 +623,9 @@
 {
   octave::unwind_protect frame;
 
-  bool silent = octave::tree_evaluator::quiet_breakpoint_flag;
-  octave::tree_evaluator::quiet_breakpoint_flag = false;
+  octave::tree_evaluator& tw = interp.get_evaluator ();
+
+  bool silent = tw.quiet_breakpoint_flag (false);
 
   octave::call_stack& cs = interp.get_call_stack ();
 
@@ -719,8 +720,6 @@
 
   octave::parser curr_parser;
 
-  octave::tree_evaluator& tw = interp.get_evaluator ();
-
   while (Vdebugging)
     {
       try
@@ -1073,10 +1072,11 @@
   // Skip the frame assigned to the keyboard function.
   cs.goto_frame_relative (0);
 
-  octave::tree_evaluator::debug_mode = true;
-  octave::tree_evaluator::quiet_breakpoint_flag = false;
+  octave::tree_evaluator& tw = interp.get_evaluator ();
 
-  octave::tree_evaluator::current_frame = cs.current_frame ();
+  tw.debug_mode (true);
+  tw.quiet_breakpoint_flag (false);
+  tw.current_frame (cs.current_frame ());
 
   do_keyboard (interp, args);
 
--- a/libinterp/parse-tree/bp-table.cc	Tue May 22 00:53:15 2018 -0400
+++ b/libinterp/parse-tree/bp-table.cc	Tue May 22 11:39:44 2018 -0400
@@ -591,7 +591,7 @@
           }
       }
 
-    tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging;
+    m_evaluator.debug_mode (bp_table::have_breakpoints () || Vdebugging);
 
     return retval;
   }
@@ -687,7 +687,7 @@
           }
       }
 
-    tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging;
+    m_evaluator.debug_mode (bp_table::have_breakpoints () || Vdebugging);
 
     return retval;
   }
@@ -721,7 +721,7 @@
       error ("remove_all_breakpoint_in_file: "
              "unable to find function %s\n", fname.c_str ());
 
-    tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging;
+    m_evaluator.debug_mode (bp_table::have_breakpoints () || Vdebugging);
 
     return retval;
   }
@@ -738,7 +738,7 @@
         remove_all_breakpoints_in_file (*it);
       }
 
-    tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging;
+    m_evaluator.debug_mode (bp_table::have_breakpoints () || Vdebugging);
   }
 
   std::string find_bkpt_list (octave_value_list slist, std::string match)
--- a/libinterp/parse-tree/pt-eval.cc	Tue May 22 00:53:15 2018 -0400
+++ b/libinterp/parse-tree/pt-eval.cc	Tue May 22 11:39:44 2018 -0400
@@ -61,12 +61,6 @@
 
 namespace octave
 {
-  size_t tree_evaluator::current_frame = 0;
-
-  bool tree_evaluator::debug_mode = false;
-
-  bool tree_evaluator::quiet_breakpoint_flag = false;
-
   // Normal evaluator.
 
   void
@@ -334,7 +328,7 @@
         m_echo_file_pos = line + 1;
       }
 
-    if (debug_mode)
+    if (m_debug_mode)
       do_breakpoint (cmd.is_breakpoint (true));
 
     if (m_in_loop_command)
@@ -416,7 +410,7 @@
         m_echo_file_pos = line + 1;
       }
 
-    if (debug_mode)
+    if (m_debug_mode)
       do_breakpoint (cmd.is_breakpoint (true));
 
     if (m_in_loop_command)
@@ -433,7 +427,7 @@
   void
   tree_evaluator::reset_debug_state (void)
   {
-    debug_mode = m_bp_table.have_breakpoints () || Vdebugging;
+    m_debug_mode = m_bp_table.have_breakpoints () || Vdebugging;
 
     m_dbstep_flag = 0;
   }
@@ -441,7 +435,7 @@
   void
   tree_evaluator::reset_debug_state (bool mode)
   {
-    debug_mode = mode;
+    m_debug_mode = mode;
 
     m_dbstep_flag = 0;
   }
@@ -889,7 +883,7 @@
         m_echo_file_pos = line + 1;
       }
 
-    if (debug_mode)
+    if (m_debug_mode)
       do_breakpoint (cmd.is_breakpoint (true));
 
     tree_decl_init_list *init_list = cmd.initializer_list ();
@@ -975,7 +969,7 @@
         line++;
       }
 
-    if (debug_mode)
+    if (m_debug_mode)
       do_breakpoint (cmd.is_breakpoint (true));
 
     // FIXME: need to handle PARFOR loops here using cmd.in_parallel ()
@@ -1113,7 +1107,7 @@
         line++;
       }
 
-    if (debug_mode)
+    if (m_debug_mode)
       do_breakpoint (cmd.is_breakpoint (true));
 
     unwind_protect frame;
@@ -1582,7 +1576,7 @@
             || m_statement_context == SC_SCRIPT)
           m_call_stack.set_location (tic->line (), tic->column ());
 
-        if (debug_mode && ! tic->is_else_clause ())
+        if (m_debug_mode && ! tic->is_else_clause ())
           do_breakpoint (tic->is_breakpoint (true));
 
         if (tic->is_else_clause () || is_logically_true (expr, "if"))
@@ -2196,7 +2190,7 @@
         m_echo_file_pos = line + 1;
       }
 
-    if (debug_mode && cmd.is_end_of_fcn_or_script ())
+    if (m_debug_mode && cmd.is_end_of_fcn_or_script ())
       do_breakpoint (cmd.is_breakpoint (true), true);
   }
 
@@ -2356,12 +2350,12 @@
         m_echo_file_pos = line + 1;
       }
 
-    if (debug_mode)
+    if (m_debug_mode)
       do_breakpoint (cmd.is_breakpoint (true));
 
     // Act like dbcont.
 
-    if (Vdebugging && m_call_stack.current_frame () == current_frame)
+    if (Vdebugging && m_call_stack.current_frame () == m_current_frame)
       {
         Vdebugging = false;
 
@@ -2490,7 +2484,7 @@
                     m_echo_file_pos = line + 1;
                   }
 
-                if (debug_mode)
+                if (m_debug_mode)
                   do_breakpoint (expr->is_breakpoint (true));
 
                 // FIXME: maybe all of this should be packaged in
@@ -2544,7 +2538,7 @@
             // If we are debugging, then continue with next statement.
             // Otherwise, jump out of here.
 
-            if (debug_mode)
+            if (m_debug_mode)
               interpreter::recover_from_exception ();
             else
               throw;
@@ -2625,7 +2619,7 @@
         m_echo_file_pos = line + 1;
       }
 
-    if (debug_mode)
+    if (m_debug_mode)
       do_breakpoint (cmd.is_breakpoint (true));
 
     tree_expression *expr = cmd.switch_value ();
@@ -2893,7 +2887,7 @@
         if (m_echo_state)
           m_echo_file_pos = line;
 
-        if (debug_mode)
+        if (m_debug_mode)
           do_breakpoint (cmd.is_breakpoint (true));
 
         if (is_logically_true (expr, "while"))
@@ -2953,7 +2947,7 @@
         if (quit_loop_now ())
           break;
 
-        if (debug_mode)
+        if (m_debug_mode)
           do_breakpoint (cmd.is_breakpoint (true));
 
         m_call_stack.set_location (until_line, until_column);
@@ -3010,7 +3004,7 @@
 
         octave_debug_on_interrupt_state = false;
 
-        current_frame = m_call_stack.current_frame ();
+        m_current_frame = m_call_stack.current_frame ();
       }
     else if (is_breakpoint)
       {
@@ -3018,11 +3012,11 @@
 
         m_dbstep_flag = 0;
 
-        current_frame = m_call_stack.current_frame ();
+        m_current_frame = m_call_stack.current_frame ();
       }
     else if (m_dbstep_flag > 0)
       {
-        if (m_call_stack.current_frame () == current_frame)
+        if (m_call_stack.current_frame () == m_current_frame)
           {
             if (m_dbstep_flag == 1 || is_end_of_fcn_or_script)
               {
@@ -3045,11 +3039,11 @@
 
           }
         else if (m_dbstep_flag == 1
-                 && m_call_stack.current_frame () < current_frame)
+                 && m_call_stack.current_frame () < m_current_frame)
           {
             // We stepped out from the end of a function.
 
-            current_frame = m_call_stack.current_frame ();
+            m_current_frame = m_call_stack.current_frame ();
 
             break_on_this_statement = true;
 
@@ -3064,7 +3058,7 @@
 
         m_dbstep_flag = 0;
 
-        current_frame = m_call_stack.current_frame ();
+        m_current_frame = m_call_stack.current_frame ();
       }
     else if (m_dbstep_flag == -2)
       {
@@ -3075,7 +3069,7 @@
         // that frame.
 
         if (is_end_of_fcn_or_script
-            && m_call_stack.current_frame () == current_frame)
+            && m_call_stack.current_frame () == m_current_frame)
           m_dbstep_flag = -1;
       }
 
--- a/libinterp/parse-tree/pt-eval.h	Tue May 22 00:53:15 2018 -0400
+++ b/libinterp/parse-tree/pt-eval.h	Tue May 22 11:39:44 2018 -0400
@@ -130,7 +130,8 @@
         m_result_type (RT_UNDEFINED), m_expr_result_value (),
         m_expr_result_value_list (), m_lvalue_list_stack (),
         m_nargout_stack (), m_bp_table (*this), m_call_stack (interp),
-        m_profiler (), m_max_recursion_depth (256),
+        m_profiler (), m_current_frame (0), m_debug_mode (false),
+        m_quiet_breakpoint_flag (false), m_max_recursion_depth (256),
         m_silent_functions (false), m_string_fill_char (' '),
         m_PS4 ("+ "), m_dbstep_flag (0), m_echo (ECHO_OFF),
         m_echo_state (false), m_echo_file_name (), m_echo_file_pos (1),
@@ -257,13 +258,6 @@
 
     void set_dbstep_flag (int step) { m_dbstep_flag = step; }
 
-    // The number of the stack frame we are currently debugging.
-    static size_t current_frame;
-
-    static bool debug_mode;
-
-    static bool quiet_breakpoint_flag;
-
     // Possible types of evaluation contexts.
     enum stmt_list_type
     {
@@ -413,6 +407,33 @@
     octave_value
     silent_functions (const octave_value_list& args, int nargout);
 
+    size_t current_frame (void) const { return m_current_frame; }
+
+    size_t current_frame (size_t n)
+    {
+      size_t val = m_current_frame;
+      m_current_frame = n;
+      return val;
+    }
+
+    bool debug_mode (void) const { return m_debug_mode; }
+
+    bool debug_mode (bool flag)
+    {
+      bool val = m_debug_mode;
+      m_debug_mode = flag;
+      return val;
+    }
+
+    bool quiet_breakpoint_flag (void) const { return m_quiet_breakpoint_flag; }
+
+    bool quiet_breakpoint_flag (bool flag)
+    {
+      bool val = m_quiet_breakpoint_flag;
+      m_quiet_breakpoint_flag = flag;
+      return val;
+    }
+
     char string_fill_char (void) const { return m_string_fill_char; }
 
     char string_fill_char (char c)
@@ -526,6 +547,13 @@
 
     profiler m_profiler;
 
+    // The number of the stack frame we are currently debugging.
+    size_t m_current_frame;
+
+    bool m_debug_mode;
+
+    bool m_quiet_breakpoint_flag;
+
     // Maximum nesting level for functions, scripts, or sourced files
     // called recursively.
     int m_max_recursion_depth;