changeset 21027:8000dacaea98

GUI: no more extra command queue for debug commands * main-window.cc (constructor): remove initializations for debug queue; (debug_continue,debug_step_into,debug_step_over,debug_step_out,debug_quit): queue new debug commands into common queue; (queue_debug): removed obsolete function; (execute_debug_callback): move this function into the execute method of the new octave_cmd_debug class; * main-window.h: remove obsolete prototypes and class variables * octave-cmd.cc (octave_cmd_debug::execute): execute method of new class for debug commands; (octave-cmd.h): changed private into protected for inheritance, new class octave_cmd_debug derived from octave_cmd_exec
author Torsten <ttl@justmail.de>
date Sun, 03 Jan 2016 11:49:16 +0100
parents 5a340d8458d6
children 4a7d9c335402
files libgui/src/main-window.cc libgui/src/main-window.h libgui/src/octave-cmd.cc libgui/src/octave-cmd.h
diffstat 4 files changed, 61 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Sat Jan 02 10:28:59 2016 -0800
+++ b/libgui/src/main-window.cc	Sun Jan 03 11:49:16 2016 +0100
@@ -92,9 +92,6 @@
     _cmd_queue (QList<octave_cmd *> ()),  // no command pending
     _cmd_processing (1),
     _cmd_queue_mutex (),
-    _dbg_queue (new QStringList ()),  // no debug pending
-    _dbg_processing (1),
-    _dbg_queue_mutex (),
     _prevent_readline_conflicts (true),
     _suppress_dbg_location (true),
     _start_gui (start_gui)
@@ -958,31 +955,36 @@
 void
 main_window::debug_continue (void)
 {
-  queue_debug ("cont");
+  octave_cmd_debug *cmd = new octave_cmd_debug ("cont", _suppress_dbg_location);
+  queue_command (cmd);
 }
 
 void
 main_window::debug_step_into (void)
 {
-  queue_debug ("in");
+  octave_cmd_debug *cmd = new octave_cmd_debug ("in", _suppress_dbg_location);
+  queue_command (cmd);
 }
 
 void
 main_window::debug_step_over (void)
 {
-  queue_debug ("step");
+  octave_cmd_debug *cmd = new octave_cmd_debug ("step", _suppress_dbg_location);
+  queue_command (cmd);
 }
 
 void
 main_window::debug_step_out (void)
 {
-  queue_debug ("out");
+  octave_cmd_debug *cmd = new octave_cmd_debug ("out", _suppress_dbg_location);
+  queue_command (cmd);
 }
 
 void
 main_window::debug_quit (void)
 {
-  queue_debug ("quit");
+  octave_cmd_debug *cmd = new octave_cmd_debug ("quit", _suppress_dbg_location);
+  queue_command (cmd);
 }
 
 void
@@ -2166,65 +2168,6 @@
   _octave_qt_link->update_directory ();
 }
 
-// The next callbacks are invoked by GUI buttons.  Those buttons
-// should only be active when we are doing debugging, which means that
-// Octave is waiting for input in get_debug_input.  Calling
-// command_editor::interrupt will force readline to return even if it
-// has not read any input, and then get_debug_input will return,
-// allowing the evaluator to continue and execute the next statement.
-
-void
-main_window::queue_debug (QString debug_cmd)
-{
-  _dbg_queue_mutex.lock ();
-  _dbg_queue->append (debug_cmd);   // queue command
-  _dbg_queue_mutex.unlock ();
-
-  if (_dbg_processing.tryAcquire ())  // if callback not processing, post event
-    octave_link::post_event (this, &main_window::execute_debug_callback);
-}
-
-void
-main_window::execute_debug_callback ()
-{
-  bool repost = false;          // flag for reposting event for this callback
-
-  if (! _dbg_queue->isEmpty ())  // list can not be empty here, just to make sure
-    {
-      _dbg_queue_mutex.lock (); // critical path
-      QString debug = _dbg_queue->takeFirst ();
-      if (_dbg_queue->isEmpty ())
-        _dbg_processing.release ();  // cmd queue empty, processing will stop
-      else
-        repost = true;          // not empty, repost at end
-      _dbg_queue_mutex.unlock ();
-
-      if (debug == "step")
-        {
-          F__db_next_breakpoint_quiet__ (ovl (_suppress_dbg_location));
-          Fdbstep ();
-        }
-      else if (debug == "cont")
-        {
-          F__db_next_breakpoint_quiet__ (ovl (_suppress_dbg_location));
-          Fdbcont ();
-        }
-      else if (debug == "quit")
-        Fdbquit ();
-      else
-        {
-          F__db_next_breakpoint_quiet__ (ovl (_suppress_dbg_location));
-          Fdbstep (ovl (debug.toStdString ()));
-        }
-
-      command_editor::interrupt (true);
-    }
-
-  if (repost)  // queue not empty, so repost event for further processing
-    octave_link::post_event (this, &main_window::execute_debug_callback);
-
-}
-
 void
 main_window::find_files (const QString &start_dir)
 {
--- a/libgui/src/main-window.h	Sat Jan 02 10:28:59 2016 -0800
+++ b/libgui/src/main-window.h	Sun Jan 03 11:49:16 2016 +0100
@@ -288,10 +288,6 @@
 
   void queue_command (octave_cmd *cmd);
 
-  void queue_debug (QString command);
-
-  void execute_debug_callback ();
-
   void configure_shortcuts ();
 
   workspace_model *_workspace_model;
@@ -404,11 +400,6 @@
   QSemaphore   _cmd_processing;
   QMutex       _cmd_queue_mutex;
 
-  // semaphore to synchronize debug signals and related callbacks
-  QStringList *_dbg_queue;
-  QSemaphore   _dbg_processing;
-  QMutex       _dbg_queue_mutex;
-
   bool _prevent_readline_conflicts;
   bool _suppress_dbg_location;
   bool _start_gui;
--- a/libgui/src/octave-cmd.cc	Sat Jan 02 10:28:59 2016 -0800
+++ b/libgui/src/octave-cmd.cc	Sun Jan 03 11:49:16 2016 +0100
@@ -80,3 +80,31 @@
 
   command_editor::accept_line ();
 }
+
+
+// ---------------------------------------------------------------------
+//  class octave_cmd_debug: executing a debugger command
+
+void
+octave_cmd_debug::execute ()
+{
+  if (_cmd == "step")
+    {
+      F__db_next_breakpoint_quiet__ (ovl (_suppress_dbg_location));
+      Fdbstep ();
+    }
+  else if (_cmd == "cont")
+    {
+      F__db_next_breakpoint_quiet__ (ovl (_suppress_dbg_location));
+      Fdbcont ();
+    }
+  else if (_cmd == "quit")
+    Fdbquit ();
+  else
+    {
+      F__db_next_breakpoint_quiet__ (ovl (_suppress_dbg_location));
+      Fdbstep (ovl (_cmd.toStdString ()));
+    }
+
+  command_editor::interrupt (true);
+}
--- a/libgui/src/octave-cmd.h	Sat Jan 02 10:28:59 2016 -0800
+++ b/libgui/src/octave-cmd.h	Sun Jan 03 11:49:16 2016 +0100
@@ -49,7 +49,7 @@
   octave_cmd_exec (const QString& cmd) : octave_cmd () { _cmd = cmd; };
   void execute ();
 
-private:
+protected:
 
   QString _cmd;
 };
@@ -65,8 +65,29 @@
   octave_cmd_eval (const QFileInfo& info) : octave_cmd () { _info = info; };
   void execute ();
 
-private:
+protected:
 
   QFileInfo _info;
 };
+
+
+// ---------------------------------------------------------------------
+//  class octave_cmd_debug
+
+class octave_cmd_debug : public octave_cmd_exec
+{
+public:
+
+  octave_cmd_debug (const QString& cmd, bool suppress_location)
+    : octave_cmd_exec (cmd)
+  {
+    _suppress_dbg_location = suppress_location;
+  };
+
+  void execute ();
+
+protected:
+
+  bool _suppress_dbg_location;
+};
 #endif