@@ -36,8 +36,20 @@ redef class NaiveInterpreter
3636 # This flag is used to launch setp by step interpreter
3737 var debug_flag = false
3838
39+ # The breakpoint tool
40+ private var breakpoint : Breakpoints
41+
42+ # The user entry is use for the step by step execution
3943 private var user_entry = ""
4044
45+ init do
46+ super
47+ breakpoint = new Breakpoints (self .modelbuilder )
48+ if modelbuilder .toolcontext .opt_stop .value then
49+ breakpoint .define_breakpoints
50+ end
51+ end
52+
4153 # Print the commands to execute step-by-step execution
4254 fun print_instruction_debug do
4355 print "──────────────────────────────────────────────────────────────────── "
@@ -85,6 +97,10 @@ redef class NaiveInterpreter
8597
8698 # Main function of the step-by-step execution this method is called after each instruction
8799 fun step_execution (recv : nullable Instance ) do
100+ if frame isa InterpreterFrame and breakpoint .is_breakpoint (frame .current_node .location ) then
101+ self .deep_old_frame = frames .length
102+ self .debug_flag = true
103+ end
88104 if self .debug_flag then
89105 init_debug_mode
90106 if recv != null then
@@ -102,6 +118,9 @@ redef class NaiveInterpreter
102118 self .object_inspector .print_pin_list_value
103119 self .user_entry = stdin .read_line
104120 self .step_execution (recv )
121+ else if user_entry == "break " then
122+ self .user_entry = ""
123+ self .breakpoint .define_breakpoints
105124 else if user_entry == "continue " then
106125 self .user_entry = ""
107126 self .debug_flag = false
@@ -111,13 +130,17 @@ redef class NaiveInterpreter
111130 end
112131 end
113132
133+ # Step into method
134+ # He execute the step-by-step execution in the method
114135 fun step_into do
115136 print "{self .get_color_line } "
116137 deep_old_frame = frames .length
117138 user_entry = stdin .read_line
118139 old_line_number = frame .current_node .location .line_start
119140 end
120141
142+ # Step over method
143+ # He keep the step-by-step execution in the method
121144 fun step_over do
122145 # Check if the new instruction is in the same method or the new instruction is in the appellant method
123146 # Check the line to execute all instruction line
@@ -126,7 +149,7 @@ redef class NaiveInterpreter
126149 end
127150 end
128151
129- redef fun expr (n : AExpr ): nullable Instance
152+ redef fun expr (n )
130153 do
131154 var i = super
132155 if i != null then step_execution (i )
@@ -142,6 +165,105 @@ redef class NaiveInterpreter
142165 super
143166 end
144167end
168+
169+ class Breakpoints
170+
171+ # The map representing the breakpoints with the links of the source file and array of lines
172+ private var breakpoints_list = new ArrayMap [SourceFile ,Array [Int ]]
173+
174+ # The modelbuilder is stored to check the module
175+ var modelbuilder : ModelBuilder
176+
177+ redef fun to_s do
178+ var return_list = ""
179+ for file , lines in breakpoints_list do
180+ return_list += "File : {file .filename } lines : {lines } \n "
181+ end
182+ return return_list
183+ end
184+
185+ # Is there location is a breakpoint?
186+ fun is_breakpoint (location : Location ): Bool do
187+ if breakpoints_list .has_key (location .file ) then
188+ return breakpoints_list [location .file ].has (location .line_start )
189+ end
190+ return false
191+ end
192+
193+ # Method to interact with the breakpoints list
194+ fun define_breakpoints do
195+ print "──────────────────────────────────────────────────────────────────── "
196+ print "Breakpoints list "
197+ print "{self .to_s } "
198+ print "For add enter " + " 'break [file name] [line number,...]' " . yellow + " for remove " + "'clear [file name] [line number,...]' " . yellow
199+ print "To leave the breakpoint mode enter " + "leave " . yellow
200+ print "──────────────────────────────────────────────────────────────────── "
201+ var user_entry = stdin .read_line .split (" " )
202+ if user_entry .length %3 == 0 then
203+ for x in [0 .. user_entry .length [.step (3 ) do
204+ var action = user_entry [x ]
205+ var file = check_file (user_entry [x +1 ])
206+ var lines = check_line (user_entry [x +2 ])
207+ if file != null then
208+ if action == "break " then
209+ add_breakpoints (file ,lines )
210+ else if action == "clear " then
211+ remove_breakpoint (file ,lines )
212+ else
213+ print "Command unknown "
214+ end
215+ end
216+ end
217+ else
218+ print "Error on the number of parameters "
219+ end
220+ end
221+
222+ # Check in the list of modules the source file exists with the name of the parameter.
223+ # If it exists, return this.
224+ fun check_file (name : String ) : nullable SourceFile do
225+ for mmodule in modelbuilder .identified_modules do
226+ if mmodule .location .file .filename .search (name ) != null then return mmodule .location .file
227+ end
228+ print "File not found "
229+ return null
230+ end
231+
232+ # Check the user input line.
233+ fun check_line (string_line : String ) : Array [Int ] do
234+ var lines = string_line .split (", " )
235+ var return_array = new Array [Int ]
236+ for line in lines do
237+ if line .is_int then
238+ return_array .add (line .to_i )
239+ end
240+ end
241+ return return_array
242+ end
243+
244+ # Method to add an breakpoint
245+ # Take a source file and an lines array representing the breakpoints
246+ fun add_breakpoints (file : SourceFile ,lines : Array [Int ])do
247+ if not lines .is_empty then
248+ if breakpoints_list .has_key (file ) then
249+ breakpoints_list [file ].add_all (lines )
250+ else
251+ breakpoints_list [file ] = lines
252+ end
253+ end
254+ end
255+
256+ # Method to remove an breakpoint
257+ # Take a source file and an lines array representing the breakpoints
258+ fun remove_breakpoint (file : SourceFile ,lines : Array [Int ])do
259+ if not lines .is_empty then
260+ for line in lines do
261+ breakpoints_list [file ].remove_all (line )
262+ end
263+ end
264+ end
265+ end
266+
145267# Represents the inspected object with the relationship between the instance and the name of the object (if it exists)
146268class ObjectInspected
147269 # The instance of the inspected object.
@@ -313,7 +435,7 @@ class ObjectInspector
313435end
314436
315437redef class AMethPropdef
316- redef fun intern_call (v : NaiveInterpreter , mpropdef : MMethodDef , args : Array [ Instance ]): nullable Instance
438+ redef fun intern_call (v , mpropdef , args )
317439 do
318440 var pname = mpropdef .mproperty .name
319441 if pname == "inspect_o " then
0 commit comments