nitdbg: Added capacity to interpret with debugger in nit.nit
[nit.git] / src / debugger.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2013 Lucas Bajolet <lucas.bajolet@gmail.com>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Debugging of a nit program using the NaiveInterpreter
18 module debugger
19
20 intrude import naive_interpreter
21
22 redef class ToolContext
23 # -d
24 var opt_debugger_mode: OptionBool = new OptionBool("Launches the target program with the debugger attached to it", "-d")
25
26 redef init
27 do
28 super
29 self.option_context.add_option(self.opt_debugger_mode)
30 end
31 end
32
33 redef class ModelBuilder
34 # Execute the program from the entry point (Sys::main) of the `mainmodule'
35 # `arguments' are the command-line arguments in order
36 # REQUIRE that:
37 # 1. the AST is fully loaded.
38 # 2. the model is fully built.
39 # 3. the instructions are fully analysed.
40 fun run_debugger(mainmodule: MModule, arguments: Array[String])
41 do
42 var time0 = get_time
43 self.toolcontext.info("*** START INTERPRETING ***", 1)
44
45 var interpreter = new Debugger(self, mainmodule, arguments)
46
47 init_naive_interpreter(interpreter, mainmodule)
48
49 var time1 = get_time
50 self.toolcontext.info("*** END INTERPRETING: {time1-time0} ***", 2)
51 end
52 end
53
54 # The class extending NaiveInterpreter by adding debugging methods
55 class Debugger
56 super NaiveInterpreter
57
58 end