nitdbg: Added function to continue execution automatically with -c option
authorLucas Bajolet <r4pass@localhost.localdomain>
Thu, 14 Mar 2013 21:01:59 +0000 (17:01 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Tue, 19 Mar 2013 18:08:16 +0000 (14:08 -0400)
Signed-off-by: Lucas BAJOLET <r4pass@hotmail.com>

src/debugger.nit
src/nit.nit

index 46750fc..274c8e4 100644 (file)
@@ -23,11 +23,14 @@ intrude import naive_interpreter
 redef class ToolContext
        # -d
        var opt_debugger_mode: OptionBool = new OptionBool("Launches the target program with the debugger attached to it", "-d")
+       # -c
+       var opt_debugger_autorun: OptionBool = new OptionBool("Launches the target program with the interpreter, such as when the program fails, the debugging prompt is summoned", "-c")
 
        redef init
        do
                super
                self.option_context.add_option(self.opt_debugger_mode)
+               self.option_context.add_option(self.opt_debugger_autorun)
        end
 end
 
@@ -50,6 +53,20 @@ redef class ModelBuilder
                var time1 = get_time
                self.toolcontext.info("*** END INTERPRETING: {time1-time0} ***", 2)
        end
+
+       fun run_debugger_autorun(mainmodule: MModule, arguments: Array[String])
+       do
+               var time0 = get_time
+               self.toolcontext.info("*** START INTERPRETING ***", 1)
+
+               var interpreter = new Debugger(self, mainmodule, arguments)
+               interpreter.autocontinue = true
+
+               init_naive_interpreter(interpreter, mainmodule)
+
+               var time1 = get_time
+               self.toolcontext.info("*** END INTERPRETING: {time1-time0} ***", 2)
+       end
 end
 
 # The class extending NaiveInterpreter by adding debugging methods
@@ -93,6 +110,9 @@ class Debugger
        # If it is not, then, the remapping won't be happening
        var frame_count_aftermath = 1
 
+       # Auto continues the execution until the end or until an error is encountered
+       var autocontinue = false
+
        #######################################################################
        ##                  Execution of statement function                  ##
        #######################################################################
@@ -106,16 +126,18 @@ class Debugger
                var old = frame.current_node
                frame.current_node = n
 
-               if not n isa ABlockExpr then
-                       steps_fun_call(n)
+               if not self.autocontinue then
+                       if not n isa ABlockExpr then
+                               steps_fun_call(n)
 
-                       breakpoint_check(n)
+                               breakpoint_check(n)
 
-                       check_funcall_and_traced_args(n)
+                               check_funcall_and_traced_args(n)
 
-                       remap(n)
+                               remap(n)
 
-                       check_if_vars_are_traced(n)
+                               check_if_vars_are_traced(n)
+                       end
                end
 
                n.stmt(self)
index eca3d4f..eedb11d 100644 (file)
@@ -53,7 +53,9 @@ if toolcontext.opt_only_metamodel.value then exit(0)
 assert mmodules.length == 1
 var mainmodule = mmodules.first
 
-if toolcontext.opt_debugger_mode.value then
+if toolcontext.opt_debugger_autorun.value then
+       modelbuilder.run_debugger_autorun(mainmodule, arguments)
+else if toolcontext.opt_debugger_mode.value then
        modelbuilder.run_debugger(mainmodule, arguments)
 else
        modelbuilder.run_naive_interpreter(mainmodule, arguments)