Skip to content

Commit 9b04ba9

Browse files
committed
Adding the breakpoint feature
Adding the Possibility to add and remove breakpoint during the interpretationNew breakpoint future Signed-off-by: Florian Deljarry <[email protected]>
1 parent 9b5774b commit 9b04ba9

File tree

8 files changed

+134
-18
lines changed

8 files changed

+134
-18
lines changed

src/interpreter/naive_interpreter.nit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ private import frontend::explain_assert_api
2727
redef class ToolContext
2828
# --discover-call-trace
2929
var opt_discover_call_trace = new OptionBool("Trace calls of the first invocation of methods", "--discover-call-trace")
30+
# --stop-at
31+
var opt_stop = new OptionBool("Indicates the line where the interpreter should be stop","--break")
3032

3133
redef init
3234
do
3335
super
3436
self.option_context.add_option(self.opt_discover_call_trace)
37+
self.option_context.add_option(self.opt_stop)
3538
end
3639
end
3740

src/interpreter/step_interpreter.nit

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
144162
end
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)
146259
class ObjectInspected
147260
# The instance of the inspected object.

tests/sav/error_class_glob.res

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
../lib/core/kernel.nit:32,1--225,3: Error: `kernel$Object` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
2-
../lib/core/kernel.nit:227,1--300,3: Error: `kernel$Sys` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
3-
../lib/core/kernel.nit:313,1--371,3: Error: `kernel$Comparable` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
4-
../lib/core/kernel.nit:373,1--410,3: Error: `kernel$Discrete` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
5-
../lib/core/kernel.nit:412,1--429,3: Error: `kernel$Cloneable` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
6-
../lib/core/kernel.nit:431,1--486,3: Error: `kernel$Numeric` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
7-
../lib/core/kernel.nit:492,1--515,3: Error: `kernel$Bool` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
8-
../lib/core/kernel.nit:517,1--599,3: Error: `kernel$Float` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
9-
../lib/core/kernel.nit:601,1--700,3: Error: `kernel$Byte` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
10-
../lib/core/kernel.nit:702,1--883,3: Error: `kernel$Int` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
11-
../lib/core/kernel.nit:885,1--1064,3: Error: `kernel$Char` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
12-
../lib/core/kernel.nit:1066,1--1083,3: Error: `kernel$Pointer` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
13-
../lib/core/kernel.nit:1085,1--1094,3: Error: `kernel$Task` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
1+
../lib/core/kernel.nit:32,1--230,3: Error: `kernel$Object` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
2+
../lib/core/kernel.nit:232,1--305,3: Error: `kernel$Sys` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
3+
../lib/core/kernel.nit:318,1--376,3: Error: `kernel$Comparable` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
4+
../lib/core/kernel.nit:378,1--415,3: Error: `kernel$Discrete` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
5+
../lib/core/kernel.nit:417,1--434,3: Error: `kernel$Cloneable` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
6+
../lib/core/kernel.nit:436,1--491,3: Error: `kernel$Numeric` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
7+
../lib/core/kernel.nit:497,1--520,3: Error: `kernel$Bool` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
8+
../lib/core/kernel.nit:522,1--604,3: Error: `kernel$Float` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
9+
../lib/core/kernel.nit:606,1--710,3: Error: `kernel$Byte` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
10+
../lib/core/kernel.nit:707,1--888,3: Error: `kernel$Int` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
11+
../lib/core/kernel.nit:890,1--1069,3: Error: `kernel$Char` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
12+
../lib/core/kernel.nit:1071,1--1088,3: Error: `kernel$Pointer` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?
13+
../lib/core/kernel.nit:1090,1--1099,3: Error: `kernel$Task` does not specialize `module_0$Object`. Possible duplication of the root class `Object`?

tests/sav/nitce/fixme/base_gen_reassign_alt4.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:723)
1+
Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:728)
22
11
33
21
44
31

tests/sav/nitce/fixme/base_gen_reassign_alt5.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:723)
1+
Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:728)
22
11
33
21
44
31

tests/sav/nitce/fixme/base_gen_reassign_alt6.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:723)
1+
Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:728)
22
11
33
21
44
31

tests/sav/nituml_args3.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ digraph G {
1212
fontsize = 8
1313
]
1414
Object [
15-
label = "{interface\nObject||+ object_id(): Int\l+ is_same_type(other: Object): Bool\l+ is_same_instance(other: nullable Object): Bool\l+ ==(other: nullable Object): Bool\l+ !=(other: nullable Object): Bool\l+ output()\l+ output_class_name()\l+ hash(): Int\l+ sys(): Sys\l+ init()\l}"
15+
label = "{interface\nObject||+ object_id(): Int\l+ is_same_type(other: Object): Bool\l+ is_same_instance(other: nullable Object): Bool\l+ ==(other: nullable Object): Bool\l+ !=(other: nullable Object): Bool\l+ output()\l+ output_class_name()\l+ hash(): Int\l+ inspect_o()\l+ sys(): Sys\l+ init()\l}"
1616
]
1717

1818
Sys [

tests/sav/nituml_args4.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ digraph G {
1212
fontsize = 8
1313
]
1414
Object [
15-
label = "{interface\nObject||+ object_id(): Int\l+ is_same_type(other: Object): Bool\l+ is_same_instance(other: nullable Object): Bool\l+ ==(other: nullable Object): Bool\l+ !=(other: nullable Object): Bool\l+ output()\l+ output_class_name()\l+ hash(): Int\l+ sys(): Sys\l+ init()\l}"
15+
label = "{interface\nObject||+ object_id(): Int\l+ is_same_type(other: Object): Bool\l+ is_same_instance(other: nullable Object): Bool\l+ ==(other: nullable Object): Bool\l+ !=(other: nullable Object): Bool\l+ output()\l+ output_class_name()\l+ hash(): Int\l+ inspect_o()\l+ sys(): Sys\l+ init()\l}"
1616
]
1717

1818
Sys [

0 commit comments

Comments
 (0)