]> git.tdb.fi Git - gldbg.git/commitdiff
Prompt to terminate target process in exit command if it's still running
authorMikko Rasa <tdb@tdb.fi>
Sat, 19 Dec 2009 14:54:33 +0000 (14:54 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 19 Dec 2009 14:54:33 +0000 (14:54 +0000)
source/commandinterpreter.cpp
source/gldbg.cpp
source/gldbg.h

index 9660aaa0ec8940487feae23a8c1aa74258d8fd9e..abc9dda60b07bc83d5125eac1612f8096d5e25eb 100644 (file)
@@ -6,6 +6,7 @@ Distributed under the GPL
 */
 
 #include <signal.h>
+#include <readline/readline.h>
 #include <msp/core/except.h>
 #include <msp/io/file.h>
 #include <msp/io/print.h>
@@ -155,7 +156,20 @@ void CommandInterpreter::cmd_kill(const string &)
 
 void CommandInterpreter::cmd_exit(const string &)
 {
-       gldbg.quit();
+       if(gldbg.get_process().get_state()!=Process::INACTIVE)
+       {
+               IO::print("Program is still running.  Kill it?\n");
+               char *answer = readline("[y/n] ");
+               if(answer[0]=='y')
+               {
+                       gldbg.get_process().kill();
+                       gldbg.quit(true);
+               }
+               else
+                       IO::print("Not confirmed.\n");
+       }
+       else
+               gldbg.quit(false);
 }
 
 void CommandInterpreter::cmd_trace(const string &args)
index d2ca85e6212b76cda3c1828e683e5462e122f9c0..34e616f4ac37caa5d30da1708892206bc3dea597 100644 (file)
@@ -66,9 +66,9 @@ void GlDbg::launch()
        close(fds[1]);
 }
        
-void GlDbg::quit()
+void GlDbg::quit(bool force)
 {
-       if(process.get_state()!=Process::INACTIVE)
+       if(!force && process.get_state()!=Process::INACTIVE)
                throw InvalidState("Program is still running");
        exit(0);
 }
index ff844518ed68f715e0e3a5036be9b7d4ab95716c..5654715c41845ffca052bbef67f936b86846ec68 100644 (file)
@@ -39,7 +39,7 @@ public:
        GlState &get_glstate() { return glstate; }
        Process &get_process() { return process; }
        void launch();
-       void quit();
+       void quit(bool);
 private:
        void tick();
        void check_child();