rbx-trepanning 0.0.5-universal-rubinius-1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +2002 -0
- data/LICENSE +25 -0
- data/NEWS +31 -0
- data/README.textile +34 -0
- data/Rakefile +165 -0
- data/THANKS +14 -0
- data/app/breakpoint.rb +219 -0
- data/app/breakpoint.rbc +3551 -0
- data/app/brkptmgr.rb +140 -0
- data/app/brkptmgr.rbc +2903 -0
- data/app/client.rb +61 -0
- data/app/client.rbc +1225 -0
- data/app/complete.rb +52 -0
- data/app/complete.rbc +1288 -0
- data/app/default.rb +71 -0
- data/app/default.rbc +1132 -0
- data/app/display.rb +148 -0
- data/app/display.rbc +2578 -0
- data/app/frame.rb +98 -0
- data/app/frame.rbc +1808 -0
- data/app/irb.rb +111 -0
- data/app/irb.rbc +2094 -0
- data/app/iseq.rb +117 -0
- data/app/iseq.rbc +2192 -0
- data/app/llvm.rbc +2478 -0
- data/app/method.rb +173 -0
- data/app/method.rbc +2492 -0
- data/app/method_name.rbc +2467 -0
- data/app/mock.rb +13 -0
- data/app/mock.rbc +398 -0
- data/app/options.rb +137 -0
- data/app/options.rbc +2898 -0
- data/app/rbx-llvm.rb +165 -0
- data/app/rbx-llvm.rbc +2478 -0
- data/app/run.rb +86 -0
- data/app/run.rbc +1244 -0
- data/app/util.rb +49 -0
- data/app/util.rbc +1146 -0
- data/app/validate.rb +30 -0
- data/app/validate.rbc +676 -0
- data/bin/trepan.compiled.rbc +1043 -0
- data/bin/trepanx +69 -0
- data/bin/trepanx.compiled.rbc +1049 -0
- data/data/irbrc +41 -0
- data/data/irbrc.compiled.rbc +640 -0
- data/interface/base_intf.rb +105 -0
- data/interface/base_intf.rbc +1899 -0
- data/interface/client.rb +80 -0
- data/interface/client.rbc +1072 -0
- data/interface/comcodes.rb +20 -0
- data/interface/comcodes.rbc +385 -0
- data/interface/script.rb +104 -0
- data/interface/script.rbc +1642 -0
- data/interface/server.rb +143 -0
- data/interface/server.rbc +2213 -0
- data/interface/user.rb +150 -0
- data/interface/user.rbc +2867 -0
- data/io/base_io.rb +148 -0
- data/io/base_io.rbc +2111 -0
- data/io/input.rb +135 -0
- data/io/input.rbc +2528 -0
- data/io/null_output.rb +42 -0
- data/io/null_output.rbc +730 -0
- data/io/string_array.rb +156 -0
- data/io/string_array.rbc +2466 -0
- data/io/tcpclient.rb +129 -0
- data/io/tcpclient.rbc +2419 -0
- data/io/tcpfns.rb +33 -0
- data/io/tcpfns.rbc +694 -0
- data/io/tcpserver.rb +141 -0
- data/io/tcpserver.rbc +2638 -0
- data/lib/trepanning.rb +474 -0
- data/lib/trepanning.rbc +7705 -0
- data/lib/trepanning2.rb +441 -0
- data/processor/breakpoint.rb +164 -0
- data/processor/command/alias.rb +55 -0
- data/processor/command/backtrace.rb +76 -0
- data/processor/command/base/cmd.rb +173 -0
- data/processor/command/base/subcmd.rb +229 -0
- data/processor/command/base/submgr.rb +182 -0
- data/processor/command/base/subsubcmd.rb +103 -0
- data/processor/command/base/subsubmgr.rb +195 -0
- data/processor/command/break.rb +100 -0
- data/processor/command/complete.rb +37 -0
- data/processor/command/continue.rb +91 -0
- data/processor/command/delete.rb +30 -0
- data/processor/command/directory.rb +51 -0
- data/processor/command/disassemble.rb +145 -0
- data/processor/command/display.rb +82 -0
- data/processor/command/down.rb +54 -0
- data/processor/command/eval.rb +51 -0
- data/processor/command/exit.rb +62 -0
- data/processor/command/finish.rb +80 -0
- data/processor/command/frame.rb +89 -0
- data/processor/command/help.rb +251 -0
- data/processor/command/info.rb +28 -0
- data/processor/command/info_subcmd/breakpoints.rb +73 -0
- data/processor/command/info_subcmd/files.rb +209 -0
- data/processor/command/info_subcmd/line.rb +86 -0
- data/processor/command/info_subcmd/method.rb +71 -0
- data/processor/command/info_subcmd/program.rb +49 -0
- data/processor/command/info_subcmd/ruby.rb +62 -0
- data/processor/command/info_subcmd/variables.rb +48 -0
- data/processor/command/irb.rb +128 -0
- data/processor/command/kill.rb +70 -0
- data/processor/command/list.rb +300 -0
- data/processor/command/macro.rb +76 -0
- data/processor/command/next.rb +66 -0
- data/processor/command/nexti.rb +59 -0
- data/processor/command/pr.rb +38 -0
- data/processor/command/ps.rb +40 -0
- data/processor/command/restart.rb +60 -0
- data/processor/command/server.rb +72 -0
- data/processor/command/set.rb +47 -0
- data/processor/command/set_subcmd/auto.rb +27 -0
- data/processor/command/set_subcmd/auto_subcmd/dis.rb +33 -0
- data/processor/command/set_subcmd/auto_subcmd/eval.rb +54 -0
- data/processor/command/set_subcmd/auto_subcmd/irb.rb +34 -0
- data/processor/command/set_subcmd/auto_subcmd/list.rb +34 -0
- data/processor/command/set_subcmd/basename.rb +25 -0
- data/processor/command/set_subcmd/confirm.rb +24 -0
- data/processor/command/set_subcmd/debug.rb +26 -0
- data/processor/command/set_subcmd/debug_subcmd/dbgr.rb +36 -0
- data/processor/command/set_subcmd/debug_subcmd/skip.rb +23 -0
- data/processor/command/set_subcmd/debug_subcmd/step.rb +23 -0
- data/processor/command/set_subcmd/different.rb +59 -0
- data/processor/command/set_subcmd/hidelevel.rb +62 -0
- data/processor/command/set_subcmd/highlight.rb +33 -0
- data/processor/command/set_subcmd/kernelstep.rb +60 -0
- data/processor/command/set_subcmd/max.rb +26 -0
- data/processor/command/set_subcmd/max_subcmd/list.rb +49 -0
- data/processor/command/set_subcmd/max_subcmd/stack.rb +50 -0
- data/processor/command/set_subcmd/max_subcmd/string.rb +76 -0
- data/processor/command/set_subcmd/max_subcmd/width.rb +49 -0
- data/processor/command/set_subcmd/substitute.rb +24 -0
- data/processor/command/set_subcmd/substitute_subcmd/path.rb +56 -0
- data/processor/command/set_subcmd/trace.rb +36 -0
- data/processor/command/set_subcmd/trace_subcmd/print.rb +57 -0
- data/processor/command/show.rb +38 -0
- data/processor/command/show_subcmd/alias.rb +42 -0
- data/processor/command/show_subcmd/args.rb +25 -0
- data/processor/command/show_subcmd/auto.rb +28 -0
- data/processor/command/show_subcmd/auto_subcmd/dis.rb +37 -0
- data/processor/command/show_subcmd/auto_subcmd/eval.rb +28 -0
- data/processor/command/show_subcmd/auto_subcmd/irb.rb +23 -0
- data/processor/command/show_subcmd/auto_subcmd/list.rb +22 -0
- data/processor/command/show_subcmd/basename.rb +20 -0
- data/processor/command/show_subcmd/confirm.rb +18 -0
- data/processor/command/show_subcmd/debug.rb +26 -0
- data/processor/command/show_subcmd/debug_subcmd/dbgr.rb +21 -0
- data/processor/command/show_subcmd/debug_subcmd/skip.rb +22 -0
- data/processor/command/show_subcmd/debug_subcmd/step.rb +22 -0
- data/processor/command/show_subcmd/different.rb +26 -0
- data/processor/command/show_subcmd/hidelevel.rb +41 -0
- data/processor/command/show_subcmd/highlight.rb +24 -0
- data/processor/command/show_subcmd/kernelstep.rb +34 -0
- data/processor/command/show_subcmd/max.rb +27 -0
- data/processor/command/show_subcmd/max_subcmd/list.rb +38 -0
- data/processor/command/show_subcmd/max_subcmd/stack.rb +36 -0
- data/processor/command/show_subcmd/max_subcmd/string.rb +42 -0
- data/processor/command/show_subcmd/max_subcmd/width.rb +37 -0
- data/processor/command/show_subcmd/trace.rb +27 -0
- data/processor/command/show_subcmd/trace_subcmd/print.rb +38 -0
- data/processor/command/show_subcmd/version.rb +23 -0
- data/processor/command/source.rb +126 -0
- data/processor/command/step.rb +84 -0
- data/processor/command/tbreak.rb +19 -0
- data/processor/command/unalias.rb +44 -0
- data/processor/command/undisplay.rb +59 -0
- data/processor/command/up.rb +86 -0
- data/processor/default.rb +58 -0
- data/processor/disassemble.rb +46 -0
- data/processor/display.rb +18 -0
- data/processor/eval.rb +96 -0
- data/processor/frame.rb +211 -0
- data/processor/help.rb +72 -0
- data/processor/hook.rb +133 -0
- data/processor/load_cmds.rb +185 -0
- data/processor/location.rb +137 -0
- data/processor/main.rb +412 -0
- data/processor/mock.rb +144 -0
- data/processor/msg.rb +43 -0
- data/processor/running.rb +234 -0
- data/processor/stepping.rb +114 -0
- data/processor/subcmd.rb +161 -0
- data/processor/validate.rb +355 -0
- data/sample/list-terminal-colors.rb +139 -0
- data/sample/list-terminal-colors.rbc +2318 -0
- data/sample/rocky-dot-trepanxrc +14 -0
- data/sample/rocky-trepanx-colors.rb +47 -0
- data/sample/rocky-trepanx-colors.rbc +530 -0
- data/test/data/enable.right +36 -0
- data/test/data/fname-with-blank.cmd +6 -0
- data/test/data/fname-with-blank.right +4 -0
- data/test/data/inline-call.cmd +6 -0
- data/test/data/inline-call.right +13 -0
- data/test/data/quit-Xdebug.right +3 -0
- data/test/data/quit.cmd +5 -0
- data/test/data/quit.right +2 -0
- data/test/data/quit2.cmd +6 -0
- data/test/data/quit2.right +3 -0
- data/test/data/step-bug.cmd +11 -0
- data/test/data/step-bug.right +3 -0
- data/test/example/fname with blank.rb +1 -0
- data/test/example/gcd-server.rb +22 -0
- data/test/example/gcd.rb +19 -0
- data/test/example/inline-call.rb +23 -0
- data/test/example/null.rb +1 -0
- data/test/example/step-bug.rb +14 -0
- data/test/example/thread1.rb +3 -0
- data/test/functional/fn_helper.rb +112 -0
- data/test/functional/test-break-name.rb +52 -0
- data/test/functional/test-break.rb +51 -0
- data/test/functional/test-finish.rb +70 -0
- data/test/functional/test-fn_helper.rb +43 -0
- data/test/functional/test-list.rb +55 -0
- data/test/functional/test-next-bug.rb +49 -0
- data/test/functional/test-next.rb +101 -0
- data/test/functional/test-step.rb +272 -0
- data/test/functional/test-step2.rb +35 -0
- data/test/functional/test-tbreak.rb +41 -0
- data/test/integration/file-diff.rb +89 -0
- data/test/integration/helper.rb +78 -0
- data/test/integration/skip-test-step-bug.rb +17 -0
- data/test/integration/test-fname-with-blank.rb +16 -0
- data/test/integration/test-inline-call.rb +20 -0
- data/test/integration/test-quit.rb +47 -0
- data/test/unit/cmd-helper.rb +50 -0
- data/test/unit/mock-helper.rb +10 -0
- data/test/unit/test-app-brkpt.rb +29 -0
- data/test/unit/test-app-brkptmgr.rb +51 -0
- data/test/unit/test-app-iseq.rb +64 -0
- data/test/unit/test-app-method.rb +54 -0
- data/test/unit/test-app-options.rb +82 -0
- data/test/unit/test-app-run.rb +16 -0
- data/test/unit/test-app-util.rb +27 -0
- data/test/unit/test-app-validate.rb +18 -0
- data/test/unit/test-base-cmd.rb +47 -0
- data/test/unit/test-base-subcmd.rb +61 -0
- data/test/unit/test-base-submgr.rb +24 -0
- data/test/unit/test-bin-trepanx.rb +48 -0
- data/test/unit/test-cmd-alias.rb +48 -0
- data/test/unit/test-cmd-break.rb +22 -0
- data/test/unit/test-cmd-exit.rb +27 -0
- data/test/unit/test-cmd-finish.rb +27 -0
- data/test/unit/test-cmd-help.rb +104 -0
- data/test/unit/test-cmd-kill.rb +47 -0
- data/test/unit/test-cmd-source.rb +34 -0
- data/test/unit/test-cmd-step.rb +29 -0
- data/test/unit/test-completion.rb +38 -0
- data/test/unit/test-intf-user.rb +46 -0
- data/test/unit/test-io-input.rb +27 -0
- data/test/unit/test-io-tcp.rb +33 -0
- data/test/unit/test-io-tcpclient.rb +54 -0
- data/test/unit/test-io-tcpfns.rb +17 -0
- data/test/unit/test-io-tcpserver.rb +50 -0
- data/test/unit/test-proc-eval.rb +36 -0
- data/test/unit/test-proc-frame.rb +79 -0
- data/test/unit/test-proc-help.rb +16 -0
- data/test/unit/test-proc-hook.rb +30 -0
- data/test/unit/test-proc-load_cmds.rb +50 -0
- data/test/unit/test-proc-location.rb +53 -0
- data/test/unit/test-proc-main.rb +99 -0
- data/test/unit/test-proc-validate.rb +91 -0
- data/test/unit/test-subcmd-help.rb +47 -0
- metadata +398 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
|
2
|
+
require 'linecache'
|
3
|
+
require 'rubygems'; require 'require_relative'
|
4
|
+
require_relative 'disassemble'
|
5
|
+
require_relative 'msg'
|
6
|
+
require_relative 'frame'
|
7
|
+
class Trepan
|
8
|
+
class CmdProcessor
|
9
|
+
attr_accessor :reload_on_change
|
10
|
+
|
11
|
+
def location_initialize
|
12
|
+
@reload_on_change = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def resolve_file_with_dir(path_suffix)
|
16
|
+
settings[:directory].split(/:/).each do |dir|
|
17
|
+
dir =
|
18
|
+
if '$cwd' == dir
|
19
|
+
Dir.pwd
|
20
|
+
elsif '$cdir' == dir
|
21
|
+
Rubinius::OS_STARTUP_DIR
|
22
|
+
else
|
23
|
+
dir
|
24
|
+
end
|
25
|
+
next unless dir && File.directory?(dir)
|
26
|
+
try_file = File.join(dir, path_suffix)
|
27
|
+
return try_file if File.readable?(try_file)
|
28
|
+
end
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
# Get line +line_number+ from file named +filename+. Return "\n"
|
33
|
+
# there was a problem. Leading blanks are stripped off.
|
34
|
+
def line_at(filename, line_number,
|
35
|
+
opts = {
|
36
|
+
:reload_on_change => @reload_on_change,
|
37
|
+
:output => @settings[:highlight]
|
38
|
+
})
|
39
|
+
# We use linecache first to give precidence to user-remapped
|
40
|
+
# file names
|
41
|
+
line = LineCache::getline(filename, line_number, opts)
|
42
|
+
unless line
|
43
|
+
# Try using search directories (set with command "directory")
|
44
|
+
if filename[0..0] != File::SEPARATOR
|
45
|
+
try_filename = resolve_file_with_dir(filename)
|
46
|
+
if try_filename &&
|
47
|
+
line = LineCache::getline(try_filename, line_number, opts)
|
48
|
+
LineCache::remap_file(filename, try_filename)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
return nil unless line
|
53
|
+
return line.lstrip.chomp
|
54
|
+
end
|
55
|
+
|
56
|
+
def loc_and_text(loc, opts=
|
57
|
+
{:reload_on_change => @reload_on_change,
|
58
|
+
:output => @settings[:highlight]
|
59
|
+
})
|
60
|
+
vm_location = @frame.vm_location
|
61
|
+
filename = vm_location.method.active_path
|
62
|
+
line_no = vm_location.line
|
63
|
+
static = vm_location.static_scope
|
64
|
+
|
65
|
+
if @frame.eval?
|
66
|
+
file = LineCache::map_script(static.script)
|
67
|
+
text = LineCache::getline(static.script, line_no, opts)
|
68
|
+
loc += " remapped #{canonic_file(file)}:#{line_no}"
|
69
|
+
else
|
70
|
+
text = line_at(filename, line_no, opts)
|
71
|
+
map_file, map_line = LineCache::map_file_line(filename, line_no)
|
72
|
+
if [filename, line_no] != [map_file, map_line]
|
73
|
+
loc += " remapped #{canonic_file(map_file)}:#{map_line}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
[loc, line_no, text]
|
78
|
+
end
|
79
|
+
|
80
|
+
def print_location
|
81
|
+
# if %w(c-call call).member?(@event)
|
82
|
+
# # FIXME: Fix Ruby so we don't need this workaround?
|
83
|
+
# # See also where.rb
|
84
|
+
# opts = {}
|
85
|
+
# opts[:class] = @core.hook_arg if
|
86
|
+
# 'CFUNC' == @frame.type && @core.hook_arg && 0 == @frame_index
|
87
|
+
# msg format_stack_call(@frame, opts)
|
88
|
+
# elsif 'raise' == @core.event
|
89
|
+
# msg @core.hook_arg.inspect if @core.hook_arg # Exception object
|
90
|
+
# end
|
91
|
+
|
92
|
+
text = nil
|
93
|
+
# source_container = frame_container(@frame, false)
|
94
|
+
ev = if @event.nil? || 0 != @frame_index
|
95
|
+
' '
|
96
|
+
else
|
97
|
+
(EVENT2ICON[@event] || @event)
|
98
|
+
end
|
99
|
+
|
100
|
+
@line_no = @frame.vm_location.line
|
101
|
+
|
102
|
+
loc = source_location_info
|
103
|
+
loc, @line_no, text = loc_and_text(loc)
|
104
|
+
ip_str = frame.method ? " @#{frame.next_ip}" : ''
|
105
|
+
|
106
|
+
msg "#{ev} (#{loc}#{ip_str})"
|
107
|
+
|
108
|
+
# if %w(return c-return).member?(@core.event)
|
109
|
+
# retval = Trepan::Frame.value_returned(@frame, @core.event)
|
110
|
+
# msg 'R=> %s' % retval.inspect
|
111
|
+
# end
|
112
|
+
|
113
|
+
if text && !text.strip.empty?
|
114
|
+
old_maxstring = @settings[:maxstring]
|
115
|
+
@settings[:maxstring] = -1
|
116
|
+
msg text
|
117
|
+
@settings[:maxstring] = old_maxstring
|
118
|
+
@line_no -= 1
|
119
|
+
else
|
120
|
+
show_bytecode
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def source_location_info
|
125
|
+
filename = @frame.vm_location.method.active_path
|
126
|
+
canonic_filename =
|
127
|
+
if @frame.eval?
|
128
|
+
'eval ' + safe_repr(@frame.eval_string.gsub("\n", ';').inspect, 20)
|
129
|
+
else
|
130
|
+
canonic_file(filename)
|
131
|
+
end
|
132
|
+
loc = "#{canonic_filename}:#{@frame.vm_location.line}"
|
133
|
+
return loc
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
data/processor/main.rb
ADDED
@@ -0,0 +1,412 @@
|
|
1
|
+
# Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
|
2
|
+
# The main "driver" class for a command processor. Other parts of the
|
3
|
+
# command class and debugger command objects are pulled in from here.
|
4
|
+
|
5
|
+
require 'set'
|
6
|
+
require 'pathname' # For cleanpath
|
7
|
+
|
8
|
+
require 'rubygems'; require 'require_relative'
|
9
|
+
## %w(default display eventbuf eval load_cmds location frame hook msg
|
10
|
+
## validate).each do
|
11
|
+
%w(default breakpoint disassemble display eval load_cmds location frame hook msg
|
12
|
+
running stepping validate).each do
|
13
|
+
|mod_str|
|
14
|
+
require_relative mod_str
|
15
|
+
end
|
16
|
+
## require_relative '../app/brkptmgr'
|
17
|
+
|
18
|
+
class Trepan
|
19
|
+
class CmdProcessor
|
20
|
+
|
21
|
+
# SEE ALSO attr's in require_relative's of loop above.
|
22
|
+
|
23
|
+
attr_reader :cmd_name # command name before alias or macro resolution
|
24
|
+
attr_reader :cmd_argstr # Current command args, a String.
|
25
|
+
# This is current_command with the command
|
26
|
+
# name removed from the beginning.
|
27
|
+
attr_reader :cmd_queue # queue of commands to run
|
28
|
+
## attr_reader :core # Trepan core object
|
29
|
+
attr_reader :current_command # Current command getting run, a String.
|
30
|
+
attr_accessor :dbgr # Trepan instance (via
|
31
|
+
# Trepan::Core instance)
|
32
|
+
## FIXME 1.9.2 has attr_reader !
|
33
|
+
attr_accessor :debug_nest # Number of nested debugs. Used in showing
|
34
|
+
# prompt.
|
35
|
+
attr_accessor :different_pos # Same type as settings[:different]
|
36
|
+
# this is the temporary value for the
|
37
|
+
# next stop while settings is the default
|
38
|
+
# value to use.
|
39
|
+
attr_accessor :event # Stop event
|
40
|
+
attr_reader :intf # Current interface
|
41
|
+
# Trepan::Core instance)
|
42
|
+
attr_accessor :leave_cmd_loop # Commands set this to signal to leave
|
43
|
+
# the command loop (which often continues to
|
44
|
+
# run the debugged program).
|
45
|
+
attr_accessor :line_no # Last line shown in "list" command
|
46
|
+
attr_accessor :next_thread # Thread. If non-nil then in
|
47
|
+
# stepping the thread has to be
|
48
|
+
# this thread.
|
49
|
+
attr_accessor :pass_exception # Pass an exception back
|
50
|
+
attr_accessor :prompt # String print before requesting input
|
51
|
+
attr_reader :settings # Hash[:symbol] of command
|
52
|
+
# processor settings
|
53
|
+
attr_reader :step_bp
|
54
|
+
|
55
|
+
# The following are used in to force stopping at a different line
|
56
|
+
# number. FIXME: could generalize to a position object.
|
57
|
+
attr_accessor :last_pos # Last position. 6-Tuple: of
|
58
|
+
# [location, container, stack_size,
|
59
|
+
# current_thread, pc_offset]
|
60
|
+
|
61
|
+
|
62
|
+
unless defined?(EVENT2ICON)
|
63
|
+
# Event icons used in printing locations.
|
64
|
+
EVENT2ICON = {
|
65
|
+
'brkpt' => 'xx',
|
66
|
+
'tbrkpt' => 'x1',
|
67
|
+
'c-call' => 'C>',
|
68
|
+
'c-return' => '<C',
|
69
|
+
'step-call' => '->',
|
70
|
+
'call' => '->',
|
71
|
+
'class' => '::',
|
72
|
+
'coverage' => '[]',
|
73
|
+
'debugger-call' => ':o',
|
74
|
+
'end' => '-|',
|
75
|
+
'line' => '--',
|
76
|
+
'raise' => '!!',
|
77
|
+
'return' => '<-',
|
78
|
+
'start' => '>>',
|
79
|
+
'switch' => 'sw',
|
80
|
+
'trace-var' => '$V',
|
81
|
+
'unknown' => '?!',
|
82
|
+
'vm' => 'VM',
|
83
|
+
'vm-insn' => '..',
|
84
|
+
}
|
85
|
+
# These events are important enough event that we always want to
|
86
|
+
# stop on them.
|
87
|
+
UNMASKABLE_EVENTS = Set.new(['end', 'raise', 'unknown'])
|
88
|
+
end
|
89
|
+
|
90
|
+
def initialize(dbgr, settings={})
|
91
|
+
@cmd_queue = []
|
92
|
+
@dbgr = dbgr
|
93
|
+
@debug_nest = 1
|
94
|
+
@hidelevels = {}
|
95
|
+
@last_command = nil
|
96
|
+
@last_pos = [nil, nil, nil, nil, nil, nil]
|
97
|
+
@next_thread = nil
|
98
|
+
@user_variables = 0
|
99
|
+
|
100
|
+
|
101
|
+
start_cmds = settings.delete(:start_cmds)
|
102
|
+
start_file = settings.delete(:start_file)
|
103
|
+
|
104
|
+
@settings = DEFAULT_SETTINGS.merge(settings)
|
105
|
+
@different_pos = @settings[:different]
|
106
|
+
|
107
|
+
# FIXME: Rework using a general "set substitute file" command and
|
108
|
+
# a global default profile which gets read.
|
109
|
+
prelude_file = File.expand_path(File.join(File.dirname(__FILE__),
|
110
|
+
%w(.. data prelude.rb)))
|
111
|
+
|
112
|
+
## Start with empty thread and frame info.
|
113
|
+
frame_teardown
|
114
|
+
|
115
|
+
# Run initialization routines for each of the "submodule"s.
|
116
|
+
# load_cmds has to come first.
|
117
|
+
## %w(load_cmds breakpoint display eventbuf frame running validate
|
118
|
+
## ).each do |submod|
|
119
|
+
%w(load_cmds breakpoint display frame running validate).each do |submod|
|
120
|
+
self.send("#{submod}_initialize")
|
121
|
+
end
|
122
|
+
hook_initialize(commands)
|
123
|
+
end
|
124
|
+
|
125
|
+
def canonic_container(container)
|
126
|
+
[container[0], canonic_file(container[1])]
|
127
|
+
end
|
128
|
+
|
129
|
+
def canonic_file(filename)
|
130
|
+
# For now we want resolved filenames
|
131
|
+
@settings[:basename] ? File.basename(filename) :
|
132
|
+
# Cache this?
|
133
|
+
Pathname.new(filename).cleanpath.to_s
|
134
|
+
end
|
135
|
+
|
136
|
+
def compute_prompt
|
137
|
+
th = @current_thread
|
138
|
+
thread_str =
|
139
|
+
if 2 == Thread.list.size
|
140
|
+
''
|
141
|
+
elsif th == Thread.main
|
142
|
+
'@main'
|
143
|
+
else
|
144
|
+
"@#{th.current.object_id}"
|
145
|
+
end
|
146
|
+
"%s#{settings[:prompt]}%s%s: " %
|
147
|
+
['(' * @debug_nest, thread_str, ')' * @debug_nest]
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
# Check that we meed the criteria that cmd specifies it needs
|
152
|
+
def ok_for_running(cmd, name, nargs)
|
153
|
+
# TODO check execution_set against execution status.
|
154
|
+
# Check we have frame is not null
|
155
|
+
min_args = cmd.class.const_get(:MIN_ARGS)
|
156
|
+
if nargs < min_args
|
157
|
+
errmsg(("Command '%s' needs at least %d argument(s); " +
|
158
|
+
"got %d.") % [name, min_args, nargs])
|
159
|
+
return false
|
160
|
+
end
|
161
|
+
max_args = cmd.class.const_get(:MAX_ARGS)
|
162
|
+
if max_args and nargs > max_args
|
163
|
+
errmsg(("Command '%s' needs at most %d argument(s); " +
|
164
|
+
"got %d.") % [name, max_args, nargs])
|
165
|
+
return false
|
166
|
+
end
|
167
|
+
# if cmd.class.const_get(:NEED_RUNNING) && !...
|
168
|
+
# errmsg "Command '%s' requires a running program." % name
|
169
|
+
# return false
|
170
|
+
# end
|
171
|
+
|
172
|
+
if cmd.class.const_get(:NEED_STACK) && !@frame
|
173
|
+
errmsg "Command '%s' requires a running stack frame." % name
|
174
|
+
return false
|
175
|
+
end
|
176
|
+
|
177
|
+
return true
|
178
|
+
end
|
179
|
+
|
180
|
+
# Run one debugger command. True is returned if we want to quit.
|
181
|
+
def process_command_and_quit?()
|
182
|
+
intf_size = @dbgr.intf.size
|
183
|
+
@intf = @dbgr.intf[-1]
|
184
|
+
return true if @intf.input_eof? && intf_size == 1
|
185
|
+
while intf_size > 1 || !@intf.input_eof?
|
186
|
+
begin
|
187
|
+
@current_command =
|
188
|
+
if @cmd_queue.empty?
|
189
|
+
read_command.strip
|
190
|
+
else
|
191
|
+
@cmd_queue.shift
|
192
|
+
end
|
193
|
+
if @current_command.empty?
|
194
|
+
if @last_command && intf.interactive?
|
195
|
+
@current_command = @last_command
|
196
|
+
else
|
197
|
+
next
|
198
|
+
end
|
199
|
+
end
|
200
|
+
next if @current_command[0..0] == '#' # Skip comment lines
|
201
|
+
break
|
202
|
+
rescue IOError, Errno::EPIPE => e
|
203
|
+
if intf_size > 1
|
204
|
+
@dbgr.intf.pop
|
205
|
+
intf_size = @dbgr.intf.size
|
206
|
+
@intf = @dbgr.intf[-1]
|
207
|
+
@last_command = nil
|
208
|
+
print_location
|
209
|
+
else
|
210
|
+
msg "That's all folks..."
|
211
|
+
## FIXME: think of something better.
|
212
|
+
quit('exit!')
|
213
|
+
return true
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
leave_cmdloop = run_command(@current_command)
|
218
|
+
|
219
|
+
# Save it to the history.
|
220
|
+
@intf.history_io.puts @last_command if @last_command && @intf.history_io
|
221
|
+
end
|
222
|
+
|
223
|
+
def after_cmdloop
|
224
|
+
@cmdloop_posthooks.run
|
225
|
+
end
|
226
|
+
|
227
|
+
def before_cmdloop
|
228
|
+
|
229
|
+
frame_setup
|
230
|
+
|
231
|
+
@unconditional_prehooks.run
|
232
|
+
if breakpoint?
|
233
|
+
delete_breakpoint(@brkpt) if @brkpt.temp?
|
234
|
+
@last_pos = [@frame.vm_location, @stack_size, @current_thread, @event]
|
235
|
+
else
|
236
|
+
if stepping_skip? # || @stack_size <= @hide_level
|
237
|
+
step(@return_to_program, @step_count)
|
238
|
+
return true
|
239
|
+
elsif @event == 'start'
|
240
|
+
step('step', 0)
|
241
|
+
return true
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
@prompt = "(#{@settings[:prompt]}): " # compute_prompt
|
246
|
+
|
247
|
+
@leave_cmd_loop = false
|
248
|
+
print_location unless @settings[:traceprint]
|
249
|
+
# if 'trace-var' == @event
|
250
|
+
# msg "Note: we are stopped *after* the above location."
|
251
|
+
# end
|
252
|
+
|
253
|
+
# @eventbuf.add_mark if @settings[:tracebuffer]
|
254
|
+
|
255
|
+
@return_to_program = false
|
256
|
+
@cmdloop_prehooks.run
|
257
|
+
return false
|
258
|
+
end
|
259
|
+
|
260
|
+
|
261
|
+
# This is the main entry point.
|
262
|
+
def process_commands
|
263
|
+
skip_command = before_cmdloop
|
264
|
+
while not @leave_cmd_loop do
|
265
|
+
begin
|
266
|
+
if !skip_command
|
267
|
+
break if process_command_and_quit?()
|
268
|
+
end
|
269
|
+
if @return_to_program
|
270
|
+
after_cmdloop
|
271
|
+
if @step_count >= 0 && 'finish' != @return_to_program
|
272
|
+
@step_bp = step_over_by(1)
|
273
|
+
run_command('disassemble') if settings[:debugstep]
|
274
|
+
dbgr.listen('step' == @return_to_program)
|
275
|
+
else
|
276
|
+
@step_bp = nil
|
277
|
+
dbgr.listen
|
278
|
+
end
|
279
|
+
skip_command = before_cmdloop
|
280
|
+
end
|
281
|
+
rescue SystemExit
|
282
|
+
## @dbgr.stop
|
283
|
+
raise
|
284
|
+
rescue Exception => exc
|
285
|
+
errmsg("Internal debugger error: #{exc.inspect}")
|
286
|
+
exception_dump(exc, @settings[:debugexcept], $!.backtrace)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
after_cmdloop
|
290
|
+
end
|
291
|
+
|
292
|
+
# Run current_command, a String. @last_command is set after the
|
293
|
+
# command is run if it is a command.
|
294
|
+
def run_command(current_command)
|
295
|
+
eval_command =
|
296
|
+
if current_command[0..0] == '!'
|
297
|
+
current_command[0] = ''
|
298
|
+
else
|
299
|
+
false
|
300
|
+
end
|
301
|
+
|
302
|
+
unless eval_command
|
303
|
+
commands = current_command.split(';;')
|
304
|
+
if commands.size > 1
|
305
|
+
current_command = commands.shift
|
306
|
+
@cmd_queue.unshift *commands
|
307
|
+
end
|
308
|
+
args = current_command.split
|
309
|
+
# Expand macros. FIXME: put in a procedure
|
310
|
+
while true do
|
311
|
+
macro_cmd_name = args[0]
|
312
|
+
return false if args.size == 0
|
313
|
+
break unless @macros.member?(macro_cmd_name)
|
314
|
+
current_command = @macros[macro_cmd_name].call(*args[1..-1])
|
315
|
+
msg current_command if settings[:debugmacro]
|
316
|
+
if current_command.is_a?(Array) &&
|
317
|
+
current_command.any {|val| !val.is_a?(String)}
|
318
|
+
args = (first=current_command.shift).split
|
319
|
+
@cmd_queue += current_command
|
320
|
+
current_command = first
|
321
|
+
elsif current_command.is_a?(String)
|
322
|
+
args = current_command.split
|
323
|
+
else
|
324
|
+
errmsg("macro #{macro_cmd_name} should return an Array " +
|
325
|
+
"of Strings or a String. Got #{current_command.inspect}")
|
326
|
+
return false
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
@cmd_name = args[0]
|
331
|
+
run_cmd_name =
|
332
|
+
if @aliases.member?(@cmd_name)
|
333
|
+
@aliases[@cmd_name]
|
334
|
+
else
|
335
|
+
@cmd_name
|
336
|
+
end
|
337
|
+
|
338
|
+
if @commands.member?(run_cmd_name)
|
339
|
+
cmd = @commands[run_cmd_name]
|
340
|
+
if ok_for_running(cmd, run_cmd_name, args.size-1)
|
341
|
+
@cmd_argstr = current_command[@cmd_name.size..-1].lstrip
|
342
|
+
cmd.run(args)
|
343
|
+
@last_command = current_command
|
344
|
+
end
|
345
|
+
return false
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
# Eval anything that's not a command or has been
|
350
|
+
# requested to be eval'd
|
351
|
+
if settings[:autoeval] || eval_command
|
352
|
+
eval_code(current_command, @settings[:maxstring])
|
353
|
+
else
|
354
|
+
undefined_command(cmd_name)
|
355
|
+
end
|
356
|
+
return false
|
357
|
+
end
|
358
|
+
|
359
|
+
# Error message when a command doesn't exist
|
360
|
+
def undefined_command(cmd_name)
|
361
|
+
errmsg('Undefined command: "%s". Try "help".' % cmd_name)
|
362
|
+
end
|
363
|
+
|
364
|
+
# FIXME: Allow access to both Trepan::CmdProcessor and Trepan
|
365
|
+
# for index [] and []=.
|
366
|
+
# If there is a Trepan::CmdProcessor setting that would take precidence.
|
367
|
+
# def settings
|
368
|
+
# @settings.merge(@dbgr.settings) # wrong because this doesn't allow []=
|
369
|
+
# end
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
if __FILE__ == $0
|
374
|
+
$0 = 'foo' # So we don't get here again
|
375
|
+
require_relative '../lib/trepanning'
|
376
|
+
dbg = Trepan.new(:nx => true)
|
377
|
+
cmdproc = dbg.instance_variable_get('@processor')
|
378
|
+
cmdproc.msg('I am main')
|
379
|
+
cmdproc.errmsg('Whoa!')
|
380
|
+
cmds = cmdproc.commands
|
381
|
+
p cmdproc.aliases
|
382
|
+
p cmdproc.commands.keys.sort
|
383
|
+
cmd_name, cmd_obj = cmds.first
|
384
|
+
puts cmd_obj.class.const_get(:HELP)
|
385
|
+
puts cmd_obj.class.const_get(:SHORT_HELP)
|
386
|
+
|
387
|
+
cmdproc.instance_variable_set('@current_thread', Thread.current)
|
388
|
+
puts cmdproc.compute_prompt
|
389
|
+
Thread.new{ puts cmdproc.compute_prompt }.join
|
390
|
+
|
391
|
+
x = Thread.new{ Thread.pass; x = 1 }
|
392
|
+
puts cmdproc.compute_prompt
|
393
|
+
x.join
|
394
|
+
cmdproc.debug_nest += 1
|
395
|
+
puts cmdproc.compute_prompt
|
396
|
+
|
397
|
+
# if ARGV.size > 0
|
398
|
+
# cmdproc.msg('Enter "q" to quit')
|
399
|
+
# cmdproc.process_commands
|
400
|
+
# else
|
401
|
+
# $input = []
|
402
|
+
# class << cmdproc
|
403
|
+
# def read_command
|
404
|
+
# $input.shift
|
405
|
+
# end
|
406
|
+
# end
|
407
|
+
# $input = ['1+2']
|
408
|
+
# cmdproc.process_command_and_quit?
|
409
|
+
# $input = ['!s = 5'] # ! means eval line
|
410
|
+
# cmdproc.process_command_and_quit?
|
411
|
+
# end
|
412
|
+
end
|