#
# Returns a boolean value, representing whether or not to
# continue reading commands from the console input
- fun process_debug_command(command:String): Bool
+ fun process_debug_command(command: String): Bool
do
# Step-out command
if command == "finish"
# Step-over command
else if command == "n" then
return step_over
+ # Shows help
+ else if command == "help" then
+ help
+ return true
# Opens a new NitIndex prompt on current model
else if command == "nitx" then
new NitIndex.with_infos(modelbuilder, self.mainmodule).prompt
return true
+ else if command == "bt" or command == "backtrack" then
+ print stack_trace
+ return true
# Continues execution until the end
else if command == "c" then
return continue_exec
print stack_trace
exit(0)
else
- var parts_of_command = command.split_with(' ')
+ var parts = command.split_with(' ')
+ var cname = parts.first
# Shows the value of a variable in the current frame
- if parts_of_command[0] == "p" or parts_of_command[0] == "print" then
- print_command(parts_of_command)
+ if cname == "p" or cname == "print" then
+ print_command(parts)
# Places a breakpoint on line x of file y
- else if parts_of_command[0] == "break" or parts_of_command[0] == "b"
- then
- process_place_break_fun(parts_of_command)
+ else if cname == "break" or cname == "b" then
+ process_place_break_fun(parts)
# 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)
+ else if cname == "d" or cname == "delete" then
+ process_remove_break_fun(parts)
# Sets an alias for a variable
- else if parts_of_command.length == 3 and parts_of_command[1] == "as"
- then
- add_alias(parts_of_command[0], parts_of_command[2])
+ else if parts.length == 2 and parts[1] == "as" then
+ process_alias(parts)
# Modifies the value of a variable in the current frame
- else if parts_of_command.length >= 3 and parts_of_command[1] == "=" then
- process_mod_function(parts_of_command)
+ else if parts.length == 3 and parts[1] == "=" then
+ process_mod_function(parts)
# Traces the modifications on a variable
- else if parts_of_command.length >= 2 and parts_of_command[0] == "trace" then
- process_trace_command(parts_of_command)
+ else if cname == "trace" then
+ process_trace_command(parts)
# Untraces the modifications on a variable
- else if parts_of_command.length == 2 and parts_of_command[0] == "untrace" then
- process_untrace_command(parts_of_command)
+ else if cname == "untrace" then
+ process_untrace_command(parts)
else
- print "Unknown command \"{command}\""
+ bad_command(command)
end
end
return true
# Prints the demanded variable in the command
#
# The name of the variable in in position 1 of the array 'parts_of_command'
- fun print_command(parts_of_command: Array[String])
+ fun print_command(parts: Array[String])
do
- if parts_of_command[1] == "*" then
+ if parts.length != 2 then
+ bad_command(parts.join(" "))
+ return
+ end
+ if parts[1] == "*" then
var map_of_instances = frame.map
var keys = map_of_instances.iterator
for instance in map_of_instances.keys do
print "{instance.to_s}: {map_of_instances[instance].to_s}"
end
- else if parts_of_command[1] == "stack" then
- print self.stack_trace
- else if parts_of_command[1].chars.has('[') and parts_of_command[1].chars.has(']') then
- process_array_command(parts_of_command)
+ else if parts[1].chars.has('[') and parts[1].chars.has(']') then
+ process_array_command(parts)
else
- var instance = seek_variable(get_real_variable_name(parts_of_command[1]), frame)
+ var instance = seek_variable(get_real_variable_name(parts[1]), frame)
if instance != null
then
print_instance(instance)
else
- print "Cannot find variable {parts_of_command[1]}"
+ print "Cannot find variable {parts[1]}"
end
end
end
+ # Process the input command to set an alias for a variable
+ fun process_alias(parts: Array[String]) do
+ if parts.length != 3 then
+ bad_command(parts.join(" "))
+ return
+ end
+ add_alias(parts.first, parts.last)
+ end
+
# Processes the input string to know where to put a breakpoint
- fun process_place_break_fun(parts_of_command: Array[String])
+ fun process_place_break_fun(parts: Array[String])
do
- var bp = get_breakpoint_from_command(parts_of_command)
+ if parts.length != 3 then
+ bad_command(parts.join(" "))
+ return
+ end
+ var bp = get_breakpoint_from_command(parts)
if bp != null then
place_breakpoint(bp)
end
end
# Returns a breakpoint containing the informations stored in the command
- fun get_breakpoint_from_command(parts_of_command: Array[String]): nullable Breakpoint
+ fun get_breakpoint_from_command(parts: Array[String]): nullable Breakpoint
do
- if parts_of_command[1].is_numeric then
- return new Breakpoint(parts_of_command[1].to_i, curr_file)
- else if parts_of_command.length >= 3 and parts_of_command[2].is_numeric then
- return new Breakpoint(parts_of_command[2].to_i, parts_of_command[1])
+ if parts[1].is_numeric then
+ return new Breakpoint(parts[1].to_i, curr_file)
+ else if parts.length >= 3 and parts[2].is_numeric then
+ return new Breakpoint(parts[2].to_i, parts[1])
else
return null
end
end
# Processes the command of removing a breakpoint on specified line and file
- fun process_remove_break_fun(parts_of_command: Array[String])
+ fun process_remove_break_fun(parts: Array[String])
do
- if parts_of_command[1].is_numeric then
- remove_breakpoint(self.curr_file, parts_of_command[1].to_i)
- else if parts_of_command.length >= 3 and parts_of_command[2].is_numeric then
- remove_breakpoint(parts_of_command[1], parts_of_command[2].to_i)
+ if parts.length != 2 then
+ bad_command(parts.join(" "))
+ return
+ end
+ if parts[1].is_numeric then
+ remove_breakpoint(self.curr_file, parts[1].to_i)
+ else if parts.length >= 3 and parts[2].is_numeric then
+ remove_breakpoint(parts[1], parts[2].to_i)
end
end
# Processes an array print command
- fun process_array_command(parts_of_command: Array[String])
+ fun process_array_command(parts: Array[String])
do
- var index_of_first_brace = parts_of_command[1].chars.index_of('[')
- var variable_name = get_real_variable_name(parts_of_command[1].substring(0,index_of_first_brace))
- var braces = parts_of_command[1].substring_from(index_of_first_brace)
+ var index_of_first_brace = parts[1].chars.index_of('[')
+ var variable_name = get_real_variable_name(parts[1].substring(0,index_of_first_brace))
+ var braces = parts[1].substring_from(index_of_first_brace)
var indexes = remove_braces(braces)
# Processes the modification function to modify a variable dynamically
#
# Command of type variable = value
- fun process_mod_function(parts_of_command: Array[String])
+ fun process_mod_function(parts: Array[String])
do
- parts_of_command[0] = get_real_variable_name(parts_of_command[0])
- var parts_of_variable = parts_of_command[0].split_with(".")
+ if parts.length != 3 then
+ bad_command(parts.join(" "))
+ return
+ end
+ var p0 = parts[0]
+ p0 = get_real_variable_name(p0)
+ var parts_of_variable = p0.split_with(".")
if parts_of_variable.length > 1 then
var last_part = parts_of_variable.pop
- var first_part = parts_of_command[0].substring(0,parts_of_command[0].length - last_part.length - 1)
+ var first_part = p0.substring(0,p0.length - last_part.length - 1)
var papa = seek_variable(first_part, frame)
if papa != null and papa isa MutableInstance then
var attribute = get_attribute_in_mutable_instance(papa, last_part)
if attribute != null then
- modify_argument_of_complex_type(papa, attribute, parts_of_command[2])
+ modify_argument_of_complex_type(papa, attribute, parts[2])
end
end
else
var target = seek_variable(parts_of_variable[0], frame)
if target != null then
- modify_in_frame(target, parts_of_command[2])
+ modify_in_frame(target, parts[2])
end
end
end
# Processes the untrace variable command
#
# Command pattern : "untrace variable"
- fun process_untrace_command(parts_of_command: Array[String])
+ fun process_untrace_command(parts: Array[String])
do
- var variable_name = get_real_variable_name(parts_of_command[1])
+ if parts.length != 2 then
+ bad_command(parts.join(" "))
+ return
+ end
+ var variable_name = get_real_variable_name(parts[1])
if untrace_variable(variable_name) then
- print "Untraced variable {parts_of_command[1]}"
+ print "Untraced variable {parts[1]}"
else
- print "{parts_of_command[1]} is not traced"
+ print "{parts[1]} is not traced"
end
end
# Processes the trace variable command
#
# Command pattern : "trace variable [break/print]"
- fun process_trace_command(parts_of_command: Array[String])
+ fun process_trace_command(parts: Array[String])
do
- var variable_name = get_real_variable_name(parts_of_command[1])
+ if parts.length != 3 then
+ bad_command(parts.join(" "))
+ return
+ end
+ var variable_name = get_real_variable_name(parts[1])
var breaker:Bool
if seek_variable(variable_name, frame) == null then
- print "Cannot find a variable called {parts_of_command[1]}"
+ print "Cannot find a variable called {parts[1]}"
return
end
- if parts_of_command.length == 3 then
- if parts_of_command[2] == "break" then
- breaker = true
- else
- breaker = false
- end
+ if parts[2] == "break" then
+ breaker = true
else
breaker = false
end
trace_variable(variable_name, breaker)
- print "Successfully tracing {parts_of_command[1]}"
+ print "Successfully tracing {parts[1]}"
end
#######################################################################