@@ -36,8 +36,19 @@ 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+
3942 private var user_entry = ""
4043
44+ init do
45+ super
46+ breakpoint = new Breakpoints (self .modelbuilder )
47+ if modelbuilder .toolcontext .opt_stop .value then
48+ breakpoint .define_breakpoints
49+ end
50+ end
51+
4152 # Print the commands to execute step-by-step execution
4253 fun print_instruction_debug do
4354 print "──────────────────────────────────────────────────────────────────── "
@@ -85,6 +96,10 @@ redef class NaiveInterpreter
8596
8697 # Main function of the step-by-step execution this method is called after each instruction
8798 fun step_execution (recv : nullable Instance ) do
99+ if breakpoint .is_breakpoint (frame .current_node .location ) then
100+ self .deep_old_frame = frames .length
101+ self .debug_flag = true
102+ end
88103 if self .debug_flag then
89104 init_debug_mode
90105 if recv != null then
@@ -102,6 +117,9 @@ redef class NaiveInterpreter
102117 self .object_inspector .print_pin_list_value
103118 self .user_entry = stdin .read_line
104119 self .step_execution (recv )
120+ else if user_entry == "break " then
121+ self .user_entry = ""
122+ self .breakpoint .define_breakpoints
105123 else if user_entry == "continue " then
106124 self .user_entry = ""
107125 self .debug_flag = false
@@ -142,6 +160,101 @@ redef class NaiveInterpreter
142160 super
143161 end
144162end
163+
164+ class Breakpoints
165+
166+ # The map representing the breakpoints with the links of the source file and array of lines
167+ private var breakpoints_list = new ArrayMap [SourceFile ,Array [Int ]]
168+
169+ # The modelbuilder is stored to check the module
170+ var modelbuilder : ModelBuilder
171+
172+ redef fun to_s do
173+ var return_list = ""
174+ for file , lines in breakpoints_list do
175+ return_list += "File : {file .filename } lines : {lines } \n "
176+ end
177+ return return_list
178+ end
179+
180+ # Is there location is a breakpoint?
181+ fun is_breakpoint (location : Location ): Bool do
182+ if breakpoints_list .has_key (location .file ) then
183+ return breakpoints_list [location .file ].has (location .line_start )
184+ end
185+ return false
186+ end
187+
188+ # Method to interact with the breakpoints list
189+ fun define_breakpoints do
190+ print "──────────────────────────────────────────────────────────────────── "
191+ print "Breakpoints list "
192+ print "{self .to_s } "
193+ print "For add enter " + " 'break [file name] [line number,...]' " . yellow + " for remove " + "'clear [file name] [line number,...]' " . yellow
194+ print "To leave the breakpoint mode enter " + "leave " . yellow
195+ print "──────────────────────────────────────────────────────────────────── "
196+ var user_entry = stdin .read_line .split (" " )
197+ if user_entry .length %3 == 0 then
198+ for x in [0 .. user_entry .length [.step (3 ) do
199+ var action = user_entry [x ]
200+ var file = check_file (user_entry [x +1 ])
201+ var lines = check_line (user_entry [x +2 ])
202+ if file != null then
203+ if action == "break " then
204+ add_breakpoints (file ,lines )
205+ else if action == "clear " then
206+ remove_breakpoint (file ,lines )
207+ else
208+ print "Command unknown "
209+ end
210+ end
211+ end
212+ else
213+ print "Error on the number of parameters "
214+ end
215+ end
216+
217+ # Check in the list of modules the source file exists with the name of the parameter.
218+ # If it exists, return this.
219+ fun check_file (name : String ) : nullable SourceFile do
220+ for mmodule in modelbuilder .identified_modules do
221+ if mmodule .location .file .filename .search (name ) != null then return mmodule .location .file
222+ end
223+ print "File not found "
224+ return null
225+ end
226+
227+ # Check the user input line.
228+ fun check_line (string_line : String ) : Array [Int ] do
229+ var lines = string_line .split (", " )
230+ var return_array = new Array [Int ]
231+ for line in lines do
232+ if line .is_int then
233+ return_array .add (line .to_i )
234+ end
235+ end
236+ return return_array
237+ end
238+
239+ fun add_breakpoints (file : SourceFile ,lines : Array [Int ])do
240+ if not lines .is_empty then
241+ if breakpoints_list .has_key (file ) then
242+ breakpoints_list [file ].add_all (lines )
243+ else
244+ breakpoints_list [file ] = lines
245+ end
246+ end
247+ end
248+
249+ fun remove_breakpoint (file : SourceFile ,lines : Array [Int ])do
250+ if not lines .is_empty then
251+ for line in lines do
252+ breakpoints_list [file ].remove_all (line )
253+ end
254+ end
255+ end
256+ end
257+
145258# Represents the inspected object with the relationship between the instance and the name of the object (if it exists)
146259class ObjectInspected
147260 # The instance of the inspected object.
0 commit comments