+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2013 Lucas Bajolet <lucas.bajolet@gmail.com>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Classes and methods relative to the management of Breakpoints for the Debugger
-module breakpoint
-
-# Contains all the informations of a Breakpoint for the Debugger
-class Breakpoint
-
- # Line to break on
- var line: Int
-
- # File concerned by the breakpoint
- var file: String
-
- # Maximum times to break on self
- var max_breaks: Int
-
- init(line: Int, file: String)
- do
- self.line = line
- self.file = file
- self.max_breaks = -1
- end
-
- fun set_max_breaks(breaks: Int)
- do
- self.max_breaks = breaks
- end
-
- # When the breakpoint is encountered, the check-in function should be called
- fun check_in
- do
- if self.max_breaks > 0 then self.max_breaks -= 1
- end
-
- # Checks if the breakpoint is still valid (that is, if it has a remaining breaks number > 0 or == -1)
- fun is_valid: Bool
- do
- if max_breaks == 0 then
- return false
- else
- return true
- end
- end
-
-end
# Debugging of a nit program using the NaiveInterpreter
module debugger
-import breakpoint
intrude import naive_interpreter
import nitx
intrude import semantize::local_var_init
end
end
+# Contains all the informations of a Breakpoint for the Debugger
+class Breakpoint
+
+ # Line to break on
+ var line: Int
+
+ # File concerned by the breakpoint
+ var file: String
+
+ redef init do
+ if not file.has_suffix(".nit") then file += ".nit"
+ end
+end
+
# The class extending `NaiveInterpreter` by adding debugging methods
class Debugger
super NaiveInterpreter
var breakpoint = find_breakpoint(curr_file, n.location.line_start)
if breakpoints.keys.has(curr_file) and breakpoint != null then
-
- breakpoint.check_in
-
- if not breakpoint.is_valid
- then
- remove_breakpoint(curr_file, n.location.line_start)
- end
-
n.debug("Execute stmt {n.to_s}")
while read_cmd do end
end
else if parts_of_command[0] == "break" or parts_of_command[0] == "b"
then
process_place_break_fun(parts_of_command)
- # Places a temporary breakpoint on line x of file y
- else if parts_of_command[0] == "tbreak" and (parts_of_command.length == 2 or parts_of_command.length == 3)
- then
- process_place_tbreak_fun(parts_of_command)
# Removes a breakpoint on line x of file y
else if parts_of_command[0] == "d" or parts_of_command[0] == "delete" then
process_remove_break_fun(parts_of_command)
end
end
- #Places a breakpoint that will trigger once and be destroyed afterwards
- fun process_place_tbreak_fun(parts_of_command: Array[String])
- do
- var bp = get_breakpoint_from_command(parts_of_command)
- if bp != null
- then
- bp.set_max_breaks(1)
- place_breakpoint(bp)
- end
- end
-
#######################################################################
## Breakpoint removing functions ##
#######################################################################