rbx-trepanning 0.2.0-universal-rubinius-2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/ChangeLog +2967 -0
- data/LICENSE +25 -0
- data/Makefile +13 -0
- data/NEWS +105 -0
- data/README.textile +34 -0
- data/Rakefile +244 -0
- data/THANKS +14 -0
- data/app/.gitignore +2 -0
- data/app/breakpoint.rb +242 -0
- data/app/brkptmgr.rb +153 -0
- data/app/client.rb +71 -0
- data/app/cmd_parse.kpeg +242 -0
- data/app/cmd_parse.rb +209 -0
- data/app/cmd_parser.rb +2083 -0
- data/app/complete.rb +79 -0
- data/app/condition.rb +22 -0
- data/app/default.rb +71 -0
- data/app/display.rb +186 -0
- data/app/eventbuffer.rb +147 -0
- data/app/file.rb +24 -0
- data/app/frame.rb +120 -0
- data/app/irb.rb +113 -0
- data/app/iseq.rb +188 -0
- data/app/method.rb +178 -0
- data/app/mock.rb +13 -0
- data/app/options.rb +154 -0
- data/app/rbx-llvm.rb +163 -0
- data/app/run.rb +92 -0
- data/app/util.rb +99 -0
- data/app/validate.rb +30 -0
- data/bin/.gitignore +2 -0
- data/bin/trepanx +69 -0
- data/data/.gitignore +2 -0
- data/data/irbrc +41 -0
- data/interface/.gitignore +2 -0
- data/interface/client.rb +84 -0
- data/interface/comcodes.rb +20 -0
- data/interface/script.rb +112 -0
- data/interface/server.rb +147 -0
- data/interface/user.rb +158 -0
- data/interface.rb +109 -0
- data/io/.gitignore +3 -0
- data/io/input.rb +151 -0
- data/io/null_output.rb +46 -0
- data/io/string_array.rb +155 -0
- data/io/tcpclient.rb +129 -0
- data/io/tcpfns.rb +33 -0
- data/io/tcpserver.rb +141 -0
- data/io.rb +148 -0
- data/lib/.gitignore +2 -0
- data/lib/trepanning.rb +467 -0
- data/processor/.gitignore +3 -0
- data/processor/Makefile +7 -0
- data/processor/breakpoint.rb +167 -0
- data/processor/command/.gitignore +2 -0
- data/processor/command/alias.rb +65 -0
- data/processor/command/backtrace.rb +68 -0
- data/processor/command/base/.gitignore +2 -0
- data/processor/command/base/subcmd.rb +226 -0
- data/processor/command/base/submgr.rb +185 -0
- data/processor/command/base/subsubcmd.rb +125 -0
- data/processor/command/base/subsubmgr.rb +196 -0
- data/processor/command/break.rb +78 -0
- data/processor/command/complete.rb +39 -0
- data/processor/command/condition.rb +64 -0
- data/processor/command/continue.rb +61 -0
- data/processor/command/delete.rb +44 -0
- data/processor/command/directory.rb +51 -0
- data/processor/command/disable.rb +71 -0
- data/processor/command/disassemble.rb +180 -0
- data/processor/command/display.rb +84 -0
- data/processor/command/down.rb +54 -0
- data/processor/command/edit.rb +74 -0
- data/processor/command/enable.rb +43 -0
- data/processor/command/eval.rb +93 -0
- data/processor/command/exit.rb +83 -0
- data/processor/command/finish.rb +80 -0
- data/processor/command/frame.rb +93 -0
- data/processor/command/help/.gitignore +1 -0
- data/processor/command/help/README +10 -0
- data/processor/command/help/command.txt +58 -0
- data/processor/command/help/examples.txt +16 -0
- data/processor/command/help/filename.txt +40 -0
- data/processor/command/help/location.txt +37 -0
- data/processor/command/help/suffixes.txt +17 -0
- data/processor/command/help.rb +228 -0
- data/processor/command/info.rb +30 -0
- data/processor/command/info_subcmd/.gitignore +3 -0
- data/processor/command/info_subcmd/breakpoints.rb +103 -0
- data/processor/command/info_subcmd/files.rb +219 -0
- data/processor/command/info_subcmd/frame.rb +68 -0
- data/processor/command/info_subcmd/line.rb +75 -0
- data/processor/command/info_subcmd/locals.rb +22 -0
- data/processor/command/info_subcmd/macro.rb +62 -0
- data/processor/command/info_subcmd/method.rb +71 -0
- data/processor/command/info_subcmd/program.rb +51 -0
- data/processor/command/info_subcmd/ruby.rb +64 -0
- data/processor/command/info_subcmd/source.rb +75 -0
- data/processor/command/info_subcmd/stack.rb +25 -0
- data/processor/command/info_subcmd/variables.rb +35 -0
- data/processor/command/info_subcmd/variables_subcmd/.gitignore +2 -0
- data/processor/command/info_subcmd/variables_subcmd/class.rb +42 -0
- data/processor/command/info_subcmd/variables_subcmd/constant.rb +42 -0
- data/processor/command/info_subcmd/variables_subcmd/globals.rb +69 -0
- data/processor/command/info_subcmd/variables_subcmd/instance.rb +42 -0
- data/processor/command/info_subcmd/variables_subcmd/locals.rb +80 -0
- data/processor/command/kill.rb +79 -0
- data/processor/command/list.rb +234 -0
- data/processor/command/macro.rb +86 -0
- data/processor/command/next.rb +67 -0
- data/processor/command/nexti.rb +59 -0
- data/processor/command/parsetree.rb +51 -0
- data/processor/command/pr.rb +37 -0
- data/processor/command/ps.rb +40 -0
- data/processor/command/restart.rb +60 -0
- data/processor/command/save.rb +58 -0
- data/processor/command/server.rb +72 -0
- data/processor/command/set.rb +47 -0
- data/processor/command/set_subcmd/.gitignore +2 -0
- data/processor/command/set_subcmd/abbrev.rb +25 -0
- data/processor/command/set_subcmd/auto.rb +33 -0
- data/processor/command/set_subcmd/auto_subcmd/.gitignore +2 -0
- data/processor/command/set_subcmd/auto_subcmd/dis.rb +33 -0
- data/processor/command/set_subcmd/auto_subcmd/eval.rb +53 -0
- data/processor/command/set_subcmd/auto_subcmd/irb.rb +33 -0
- data/processor/command/set_subcmd/auto_subcmd/list.rb +33 -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/.gitignore +2 -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 +61 -0
- data/processor/command/set_subcmd/hidelevel.rb +62 -0
- data/processor/command/set_subcmd/highlight.rb +39 -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/.gitignore +2 -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/reload.rb +42 -0
- data/processor/command/set_subcmd/substitute.rb +24 -0
- data/processor/command/set_subcmd/substitute_subcmd/.gitignore +3 -0
- data/processor/command/set_subcmd/substitute_subcmd/path.rb +56 -0
- data/processor/command/set_subcmd/timer.rb +58 -0
- data/processor/command/set_subcmd/trace.rb +37 -0
- data/processor/command/set_subcmd/trace_subcmd/.gitignore +2 -0
- data/processor/command/set_subcmd/trace_subcmd/buffer.rb +42 -0
- data/processor/command/set_subcmd/trace_subcmd/print.rb +41 -0
- data/processor/command/shell.rb +131 -0
- data/processor/command/show.rb +39 -0
- data/processor/command/show_subcmd/.gitignore +3 -0
- data/processor/command/show_subcmd/abbrev.rb +20 -0
- data/processor/command/show_subcmd/aliases.rb +46 -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/.gitignore +3 -0
- data/processor/command/show_subcmd/auto_subcmd/dis.rb +37 -0
- data/processor/command/show_subcmd/auto_subcmd/eval.rb +24 -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/.gitignore +3 -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/directories.rb +22 -0
- data/processor/command/show_subcmd/hidelevel.rb +41 -0
- data/processor/command/show_subcmd/highlight.rb +25 -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/.gitignore +2 -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/reload.rb +18 -0
- data/processor/command/show_subcmd/timer.rb +18 -0
- data/processor/command/show_subcmd/trace.rb +27 -0
- data/processor/command/show_subcmd/trace_subcmd/.gitignore +2 -0
- data/processor/command/show_subcmd/trace_subcmd/buffer.rb +64 -0
- data/processor/command/show_subcmd/trace_subcmd/print.rb +23 -0
- data/processor/command/show_subcmd/version.rb +23 -0
- data/processor/command/source.rb +133 -0
- data/processor/command/step.rb +97 -0
- data/processor/command/tbreak.rb +20 -0
- data/processor/command/unalias.rb +49 -0
- data/processor/command/undisplay.rb +63 -0
- data/processor/command/up.rb +89 -0
- data/processor/command.rb +173 -0
- data/processor/default.rb +64 -0
- data/processor/disassemble.rb +59 -0
- data/processor/display.rb +53 -0
- data/processor/eval.rb +97 -0
- data/processor/eventbuf.rb +101 -0
- data/processor/frame.rb +265 -0
- data/processor/help.rb +94 -0
- data/processor/hook.rb +134 -0
- data/processor/list.rb +123 -0
- data/processor/load_cmds.rb +253 -0
- data/processor/location.rb +228 -0
- data/processor/mock.rb +138 -0
- data/processor/msg.rb +74 -0
- data/processor/running.rb +244 -0
- data/processor/stepping.rb +135 -0
- data/processor/subcmd.rb +136 -0
- data/processor/validate.rb +379 -0
- data/processor/virtual.rb +33 -0
- data/processor.rb +404 -0
- data/rbx-trepanning.gemspec +39 -0
- data/sample/.gitignore +2 -0
- data/sample/list-terminal-colors.rb +139 -0
- data/sample/rocky-dot-trepanxrc +14 -0
- data/sample/rocky-trepanx-colors.rb +46 -0
- data/test/data/.gitignore +1 -0
- data/test/data/enable.right +36 -0
- data/test/data/fname-with-blank.cmd +6 -0
- data/test/data/fname-with-blank.right +6 -0
- data/test/data/inline-call.cmd +6 -0
- data/test/data/inline-call.right +14 -0
- data/test/data/quit-Xdebug.right +3 -0
- data/test/data/quit.cmd +5 -0
- data/test/data/quit.right +3 -0
- data/test/data/quit2.cmd +6 -0
- data/test/data/quit2.right +3 -0
- data/test/example/.gitignore +2 -0
- data/test/example/debugger-stop.rb +16 -0
- data/test/example/factorial.rb +10 -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/goto2goto.rb +11 -0
- data/test/example/inline-call.rb +23 -0
- data/test/example/null.rb +1 -0
- data/test/example/thread1.rb +3 -0
- data/test/functional/.gitignore +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 +85 -0
- data/test/functional/test-eval.rb +115 -0
- data/test/functional/test-finish.rb +70 -0
- data/test/functional/test-fn_helper.rb +43 -0
- data/test/functional/test-list.rb +56 -0
- data/test/functional/test-next-bug.rb +49 -0
- data/test/functional/test-next.rb +101 -0
- data/test/functional/test-recursive-bt.rb +94 -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/.gitignore +3 -0
- data/test/integration/file-diff.rb +89 -0
- data/test/integration/helper.rb +81 -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/.gitignore +3 -0
- data/test/unit/cmd-helper.rb +50 -0
- data/test/unit/mock-helper.rb +10 -0
- data/test/unit/test-app-brkpt.rb +31 -0
- data/test/unit/test-app-brkptmgr.rb +51 -0
- data/test/unit/test-app-cmd_parse.rb +97 -0
- data/test/unit/test-app-cmd_parser.rb +23 -0
- data/test/unit/test-app-complete.rb +39 -0
- data/test/unit/test-app-condition.rb +18 -0
- data/test/unit/test-app-display.rb +22 -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 +94 -0
- data/test/unit/test-app-run.rb +14 -0
- data/test/unit/test-app-util.rb +44 -0
- data/test/unit/test-app-validate.rb +18 -0
- data/test/unit/test-base-cmd.rb +45 -0
- data/test/unit/test-base-subcmd.rb +57 -0
- data/test/unit/test-base-submgr.rb +24 -0
- data/test/unit/test-base-subsubcmd.rb +17 -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 +66 -0
- data/test/unit/test-cmd-edit.rb +34 -0
- data/test/unit/test-cmd-exit.rb +27 -0
- data/test/unit/test-cmd-finish.rb +31 -0
- data/test/unit/test-cmd-help.rb +104 -0
- data/test/unit/test-cmd-kill.rb +54 -0
- data/test/unit/test-cmd-parse_list_cmd.rb +36 -0
- data/test/unit/test-cmd-source.rb +34 -0
- data/test/unit/test-cmd-step.rb +29 -0
- data/test/unit/test-command.rb +45 -0
- data/test/unit/test-completion.rb +48 -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 +35 -0
- data/test/unit/test-proc-frame.rb +81 -0
- data/test/unit/test-proc-help.rb +16 -0
- data/test/unit/test-proc-hook.rb +30 -0
- data/test/unit/test-proc-list.rb +55 -0
- data/test/unit/test-proc-load_cmds.rb +51 -0
- data/test/unit/test-proc-location.rb +67 -0
- data/test/unit/test-proc-main.rb +95 -0
- data/test/unit/test-proc-validate.rb +139 -0
- data/test/unit/test-subcmd-help.rb +43 -0
- metadata +545 -0
data/processor/subcmd.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
|
2
|
+
# gdb-like subcommand processing.
|
3
|
+
|
4
|
+
### FIXME: move into command/base/submgr.rb
|
5
|
+
class Trepan
|
6
|
+
class Subcmd
|
7
|
+
|
8
|
+
attr_reader :subcmds # Hash of subcommands. Key is the subcommand name.
|
9
|
+
# the value is the subcommand object to run.
|
10
|
+
def initialize(cmd)
|
11
|
+
@cmd = cmd
|
12
|
+
@subcmds = {}
|
13
|
+
@cmdlist = []
|
14
|
+
end
|
15
|
+
|
16
|
+
# Find subcmd in self.subcmds
|
17
|
+
def lookup(subcmd_prefix, use_regexp=true)
|
18
|
+
compare =
|
19
|
+
if !@cmd.settings[:abbrev]
|
20
|
+
lambda{|name| name.to_s == subcmd_prefix}
|
21
|
+
elsif use_regexp
|
22
|
+
lambda{|name| name.to_s =~ /^#{subcmd_prefix}/}
|
23
|
+
else
|
24
|
+
lambda{|name| 0 == name.to_s.index(subcmd_prefix)}
|
25
|
+
end
|
26
|
+
candidates = []
|
27
|
+
@subcmds.each do |subcmd_name, subcmd|
|
28
|
+
if compare.call(subcmd_name) &&
|
29
|
+
subcmd_prefix.size >= subcmd.class.const_get(:MIN_ABBREV)
|
30
|
+
candidates << subcmd
|
31
|
+
end
|
32
|
+
end
|
33
|
+
if candidates.size == 1
|
34
|
+
return candidates.first
|
35
|
+
end
|
36
|
+
return nil
|
37
|
+
end
|
38
|
+
|
39
|
+
# Show short help for a subcommand.
|
40
|
+
def short_help(subcmd_cb, subcmd_name, label=false)
|
41
|
+
entry = self.lookup(subcmd_name)
|
42
|
+
if entry
|
43
|
+
if label
|
44
|
+
prefix = entry.name
|
45
|
+
else
|
46
|
+
prefix = ''
|
47
|
+
end
|
48
|
+
if entry.respond_to?(:short_help)
|
49
|
+
prefix += ' -- ' if prefix
|
50
|
+
@proc.msg(prefix + entry.short_help)
|
51
|
+
end
|
52
|
+
else
|
53
|
+
@proc.undefined_subcmd("help", subcmd_name)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Add subcmd to the available subcommands for this object.
|
58
|
+
# It will have the supplied docstring, and subcmd_cb will be called
|
59
|
+
# when we want to run the command. min_len is the minimum length
|
60
|
+
# allowed to abbreviate the command. in_list indicates with the
|
61
|
+
# show command will be run when giving a list of all sub commands
|
62
|
+
# of this object. Some commands have long output like "show commands"
|
63
|
+
# so we might not want to show that.
|
64
|
+
def add(subcmd_cb, subcmd_name=nil)
|
65
|
+
subcmd_name ||= subcmd_cb.name
|
66
|
+
@subcmds[subcmd_name] = subcmd_cb
|
67
|
+
|
68
|
+
# We keep a list of subcommands to assist command completion
|
69
|
+
@cmdlist << subcmd_name
|
70
|
+
end
|
71
|
+
|
72
|
+
# help for subcommands
|
73
|
+
# Note: format of help is compatible with ddd.
|
74
|
+
def help(*args)
|
75
|
+
# Not used but tested for.
|
76
|
+
end
|
77
|
+
|
78
|
+
def list
|
79
|
+
@subcmds.keys.map{|k| k.to_s}.sort
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# When invoked as main program, invoke the debugger on a script
|
85
|
+
if __FILE__ == $0
|
86
|
+
|
87
|
+
require 'rubygems'; require 'require_relative'
|
88
|
+
require_relative 'mock'
|
89
|
+
require_relative 'command'
|
90
|
+
|
91
|
+
class Trepan::TestCommand < Trepan::Command
|
92
|
+
|
93
|
+
HELP = 'Help string string for testing'
|
94
|
+
CATEGORY = 'data'
|
95
|
+
MIN_ARGS = 0
|
96
|
+
MAX_ARGS = 5
|
97
|
+
NAME_ALIASES = %w(test)
|
98
|
+
|
99
|
+
def initialize(proc); @proc = proc end
|
100
|
+
|
101
|
+
def run(args); puts 'test command run' end
|
102
|
+
end
|
103
|
+
|
104
|
+
class TestTestingSubcommand
|
105
|
+
HELP = 'Help string for test testing subcommand'
|
106
|
+
|
107
|
+
def initialize; @name = 'testing' end
|
108
|
+
|
109
|
+
SHORT_HELP = 'This is short help for test testing'
|
110
|
+
MIN_ABREV = 4
|
111
|
+
IN_LIST = true
|
112
|
+
def run(args); puts 'test testing run' end
|
113
|
+
end
|
114
|
+
|
115
|
+
d = MockDebugger::MockDebugger.new
|
116
|
+
testcmd = Trepan::TestCommand.new(nil)
|
117
|
+
# testcmd.debugger = d
|
118
|
+
# testcmd.proc = d.core.processor
|
119
|
+
# testcmdMgr = Subcmd.new('test', testcmd)
|
120
|
+
# testsub = TestTestingSubcommand.new
|
121
|
+
# testcmdMgr.add(testsub)
|
122
|
+
|
123
|
+
# %w(tes test testing testing1).each do |prefix|
|
124
|
+
# x = testcmdMgr.lookup(prefix)
|
125
|
+
# puts x ? x.name : 'Non'
|
126
|
+
# end
|
127
|
+
|
128
|
+
# testcmdMgr.short_help(testcmd, 'testing')
|
129
|
+
# testcmdMgr.short_help(testcmd, 'test', true)
|
130
|
+
# testcmdMgr.short_help(testcmd, 'tes')
|
131
|
+
# puts testcmdMgr.list()
|
132
|
+
# testsub2 = TestTestingSubcommand.new
|
133
|
+
# testsub2.name = 'foobar'
|
134
|
+
# testcmdMgr.add(testsub2)
|
135
|
+
# puts testcmdMgr.list()
|
136
|
+
end
|
@@ -0,0 +1,379 @@
|
|
1
|
+
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
|
2
|
+
|
3
|
+
# Trepan command input validation routines. A String type is
|
4
|
+
# usually passed in as the argument to validation routines.
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'require_relative'
|
8
|
+
require 'linecache'
|
9
|
+
|
10
|
+
require_relative '../app/cmd_parse'
|
11
|
+
require_relative '../app/condition'
|
12
|
+
require_relative '../app/file'
|
13
|
+
require_relative '../app/method'
|
14
|
+
require_relative '../app/validate'
|
15
|
+
|
16
|
+
require_relative 'location' # for resolve_file_with_dir
|
17
|
+
require_relative 'msg' # for errmsg, msg
|
18
|
+
require_relative 'virtual'
|
19
|
+
|
20
|
+
class Trepan
|
21
|
+
class CmdProcessor < Trepan::VirtualCmdProcessor
|
22
|
+
|
23
|
+
attr_reader :dbgr_script_iseqs
|
24
|
+
attr_reader :dbgr_iseqs
|
25
|
+
attr_reader :file_exists_proc # Like File.exists? but checks using
|
26
|
+
# cached files
|
27
|
+
|
28
|
+
include Trepanning::Method
|
29
|
+
include Trepanning::FileName
|
30
|
+
include Trepan::Validate
|
31
|
+
## include Trepan::ThreadHelper
|
32
|
+
include Trepan::Condition
|
33
|
+
|
34
|
+
def confirm(msg, default)
|
35
|
+
@settings[:confirm] ? @dbgr.intf[-1].confirm(msg, default) : true
|
36
|
+
end
|
37
|
+
|
38
|
+
# Check that arg is an Integer between opts[:min_value] and
|
39
|
+
# opts[:max_value]
|
40
|
+
def get_an_int(arg, opts={})
|
41
|
+
ret_value = get_int_noerr(arg)
|
42
|
+
if !ret_value
|
43
|
+
if opts[:msg_on_error]
|
44
|
+
errmsg(opts[:msg_on_error])
|
45
|
+
else
|
46
|
+
errmsg("Expecting an integer, got: #{arg}.")
|
47
|
+
end
|
48
|
+
return nil
|
49
|
+
end
|
50
|
+
if opts[:min_value] and ret_value < opts[:min_value]
|
51
|
+
errmsg("Expecting integer value to be at least %d; got %d." %
|
52
|
+
[opts[:min_value], ret_value])
|
53
|
+
return nil
|
54
|
+
elsif opts[:max_value] and ret_value > opts[:max_value]
|
55
|
+
errmsg("Expecting integer value to be at most %d; got %d." %
|
56
|
+
[opts[:max_value], ret_value])
|
57
|
+
return nil
|
58
|
+
end
|
59
|
+
return ret_value
|
60
|
+
end
|
61
|
+
|
62
|
+
unless defined?(DEFAULT_GET_INT_OPTS)
|
63
|
+
DEFAULT_GET_INT_OPTS = {
|
64
|
+
:min_value => 0, :default => 1, :cmdname => nil, :max_value => nil}
|
65
|
+
end
|
66
|
+
|
67
|
+
# If argument parameter 'arg' is not given, then use what is in
|
68
|
+
# opts[:default]. If String 'arg' evaluates to an integer between
|
69
|
+
# least min_value and at_most, use that. Otherwise report an
|
70
|
+
# error. If there's a stack frame use that for bindings in
|
71
|
+
# evaluation.
|
72
|
+
def get_int(arg, opts={})
|
73
|
+
|
74
|
+
return default unless arg
|
75
|
+
opts = DEFAULT_GET_INT_OPTS.merge(opts)
|
76
|
+
val = arg ? get_int_noerr(arg) : opts[:default]
|
77
|
+
unless val
|
78
|
+
if opts[:cmdname]
|
79
|
+
errmsg(("Command '%s' expects an integer; " +
|
80
|
+
"got: %s.") % [opts[:cmdname], arg])
|
81
|
+
else
|
82
|
+
errmsg('Expecting a positive integer, got: %s' % arg)
|
83
|
+
end
|
84
|
+
return nil
|
85
|
+
end
|
86
|
+
|
87
|
+
if val < opts[:min_value]
|
88
|
+
if opts[:cmdname]
|
89
|
+
errmsg(("Command '%s' expects an integer at least" +
|
90
|
+
' %d; got: %d.') %
|
91
|
+
[opts[:cmdname], opts[:min_value], opts[:default]])
|
92
|
+
else
|
93
|
+
errmsg(("Expecting a positive integer at least" +
|
94
|
+
' %d; got: %d') %
|
95
|
+
[opts[:min_value], opts[:default]])
|
96
|
+
end
|
97
|
+
return nil
|
98
|
+
elsif opts[:max_value] and val > opts[:max_value]
|
99
|
+
if opts[:cmdname]
|
100
|
+
errmsg(("Command '%s' expects an integer at most" +
|
101
|
+
' %d; got: %d.') %
|
102
|
+
[opts[:cmdname], opts[:max_value], val])
|
103
|
+
else
|
104
|
+
errmsg(("Expecting an integer at most %d; got: %d") %
|
105
|
+
[opts[:max_value], val])
|
106
|
+
end
|
107
|
+
return nil
|
108
|
+
end
|
109
|
+
return val
|
110
|
+
end
|
111
|
+
|
112
|
+
def get_int_list(args, opts={})
|
113
|
+
args.map{|arg| get_an_int(arg, opts)}.compact
|
114
|
+
end
|
115
|
+
|
116
|
+
# Eval arg and it is an integer return the value. Otherwise
|
117
|
+
# return nil
|
118
|
+
def get_int_noerr(arg)
|
119
|
+
b = @frame ? @frame.binding : nil
|
120
|
+
val = Integer(eval(arg, b))
|
121
|
+
rescue SyntaxError
|
122
|
+
nil
|
123
|
+
rescue
|
124
|
+
nil
|
125
|
+
end
|
126
|
+
|
127
|
+
def get_thread_from_string(id_or_num_str)
|
128
|
+
if id_or_num_str == '.'
|
129
|
+
Thread.current
|
130
|
+
elsif id_or_num_str.downcase == 'm'
|
131
|
+
Thread.main
|
132
|
+
else
|
133
|
+
num = get_int_noerr(id_or_num_str)
|
134
|
+
if num
|
135
|
+
get_thread(num)
|
136
|
+
else
|
137
|
+
nil
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def position_to_line_and_offset(cm, filename, position, offset_type)
|
143
|
+
case offset_type
|
144
|
+
when :line
|
145
|
+
vm_offset = cm.first_ip_on_line(position, -2)
|
146
|
+
line_no = position
|
147
|
+
when :offset
|
148
|
+
position = position.position unless position.kind_of?(Fixnum)
|
149
|
+
line_no = cm.line_from_ip(position)
|
150
|
+
vm_offset = position
|
151
|
+
when nil
|
152
|
+
vm_offset, line_no =
|
153
|
+
if cm.lines[0] == -1
|
154
|
+
[cm.lines[0], cm.lines.size > 3 ? cm.lines[3] : cm.lines[1]]
|
155
|
+
else
|
156
|
+
[cm.lines[0], cm.lines[1]]
|
157
|
+
end
|
158
|
+
else
|
159
|
+
errmsg "Bad parse offset_type: #{offset_type.inspect}"
|
160
|
+
return [nil, nil]
|
161
|
+
end
|
162
|
+
return [line_no, vm_offset]
|
163
|
+
end
|
164
|
+
|
165
|
+
# Parse a breakpoint position. On success return:
|
166
|
+
# - the CompileMethod the position is in
|
167
|
+
# - the line number - a Fixnum
|
168
|
+
# - vm_offset - a Fixnum
|
169
|
+
# - the condition (by default 'true') to use for this breakpoint
|
170
|
+
# - true condition should be negated. Used in *condition* if/unless
|
171
|
+
def breakpoint_position(position_str, allow_condition)
|
172
|
+
break_cmd_parse = if allow_condition
|
173
|
+
parse_breakpoint(position_str)
|
174
|
+
else
|
175
|
+
parse_breakpoint_no_condition(position_str)
|
176
|
+
end
|
177
|
+
return [nil] * 5 unless break_cmd_parse
|
178
|
+
tail = [break_cmd_parse.condition, break_cmd_parse.negate]
|
179
|
+
cm, file, position, offset_type =
|
180
|
+
parse_position(break_cmd_parse.position)
|
181
|
+
if cm
|
182
|
+
line_no, vm_offset =
|
183
|
+
position_to_line_and_offset(cm, file, position, offset_type)
|
184
|
+
if vm_offset && line_no
|
185
|
+
return [cm, line_no, vm_offset] + tail
|
186
|
+
else
|
187
|
+
errmsg("Unable to set breakpoint in #{cm}")
|
188
|
+
return
|
189
|
+
end
|
190
|
+
end
|
191
|
+
errmsg("Unable to get breakpoint position for #{position_str}")
|
192
|
+
return [nil] * 5
|
193
|
+
end
|
194
|
+
|
195
|
+
# Return true if arg is 'on' or 1 and false arg is 'off' or 0.
|
196
|
+
# Any other value is raises TypeError.
|
197
|
+
def get_onoff(arg, default=nil, print_error=true)
|
198
|
+
unless arg
|
199
|
+
if !default
|
200
|
+
if print_error
|
201
|
+
errmsg("Expecting 'on', 1, 'off', or 0. Got nothing.")
|
202
|
+
end
|
203
|
+
raise TypeError
|
204
|
+
end
|
205
|
+
return default
|
206
|
+
end
|
207
|
+
darg = arg.downcase
|
208
|
+
return true if arg == '1' || darg == 'on'
|
209
|
+
return false if arg == '0' || darg =='off'
|
210
|
+
|
211
|
+
errmsg("Expecting 'on', 1, 'off', or 0. Got: %s." % arg.to_s) if
|
212
|
+
print_error
|
213
|
+
raise TypeError
|
214
|
+
end
|
215
|
+
|
216
|
+
include Trepan::CmdParser
|
217
|
+
|
218
|
+
def get_method(meth)
|
219
|
+
start_binding =
|
220
|
+
begin
|
221
|
+
@frame.binding
|
222
|
+
rescue
|
223
|
+
binding
|
224
|
+
end
|
225
|
+
if meth.kind_of?(String)
|
226
|
+
meth_for_string(meth, start_binding)
|
227
|
+
else
|
228
|
+
begin
|
229
|
+
meth_for_parse_struct(meth, start_binding)
|
230
|
+
rescue NameError
|
231
|
+
errmsg("Can't evaluate #{meth.name} to get a method")
|
232
|
+
return nil
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
# FIXME: this is a ? method but we return
|
238
|
+
# the method value.
|
239
|
+
def method?(meth)
|
240
|
+
get_method(meth)
|
241
|
+
end
|
242
|
+
|
243
|
+
# parse_position(self)->(meth, filename, offset, offset_type)
|
244
|
+
# See app/cmd_parser.kpeg for the syntax of a position which
|
245
|
+
# should include things like:
|
246
|
+
# Parse arg as [filename:]lineno | function | module
|
247
|
+
# Make sure it works for C:\foo\bar.py:12
|
248
|
+
def parse_position(info)
|
249
|
+
info = parse_location(info) if info.kind_of?(String)
|
250
|
+
case info.container_type
|
251
|
+
when :fn
|
252
|
+
unless info.container
|
253
|
+
errmsg "Bad function parse #{info.container.inspect}"
|
254
|
+
return
|
255
|
+
end
|
256
|
+
if meth = method?(info.container)
|
257
|
+
cm = meth.executable
|
258
|
+
return [cm, canonic_file(cm.active_path), info.position,
|
259
|
+
info.position_type]
|
260
|
+
else
|
261
|
+
return [nil] * 4
|
262
|
+
end
|
263
|
+
when :file
|
264
|
+
filename = canonic_file(info.container)
|
265
|
+
cm =
|
266
|
+
if canonic_file(@frame.file) == filename
|
267
|
+
if :line == info.position_type
|
268
|
+
find_method_with_line(@frame.method, info.position)
|
269
|
+
else
|
270
|
+
@frame.method
|
271
|
+
end
|
272
|
+
else
|
273
|
+
LineCache.compiled_method(filename)
|
274
|
+
end
|
275
|
+
return cm, filename, info.position, info.position_type
|
276
|
+
when nil
|
277
|
+
if [:line, :offset].member?(info.position_type)
|
278
|
+
filename = @frame.file
|
279
|
+
cm = @frame.method
|
280
|
+
if :line == info.position_type
|
281
|
+
cm = find_method_with_line(cm, info.position)
|
282
|
+
end
|
283
|
+
return [cm, canonic_file(filename), info.position, info.position_type]
|
284
|
+
elsif !info.position_type
|
285
|
+
errmsg "Can't parse #{arg} as a position"
|
286
|
+
return [nil] * 4
|
287
|
+
else
|
288
|
+
errmsg "Unknown position type #{info.position_type} for location #{arg}"
|
289
|
+
return [nil] * 4
|
290
|
+
end
|
291
|
+
else
|
292
|
+
errmsg "Unknown container type #{info.container_type} for location #{arg}"
|
293
|
+
return [nil] * 4
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
def parse_method(meth_str)
|
298
|
+
begin
|
299
|
+
meth_for_string(meth_str, @frame.binding)
|
300
|
+
rescue NameError
|
301
|
+
nil
|
302
|
+
rescue
|
303
|
+
nil
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
def validate_initialize
|
308
|
+
## top_srcdir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
309
|
+
## @dbgr_script_iseqs, @dbgr_iseqs = filter_scripts(top_srcdir)
|
310
|
+
@file_exists_proc = Proc.new {|filename|
|
311
|
+
if LineCache.cached?(filename) || LineCache.cached_script?(filename) ||
|
312
|
+
(File.readable?(filename) && !File.directory?(filename))
|
313
|
+
true
|
314
|
+
else
|
315
|
+
find_load_path(filename)
|
316
|
+
end
|
317
|
+
}
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
if __FILE__ == $0
|
323
|
+
# Demo it.
|
324
|
+
DIRNAME = File.dirname(__FILE__)
|
325
|
+
load File.join(DIRNAME, 'main.rb')
|
326
|
+
|
327
|
+
require_relative 'mock'
|
328
|
+
dbgr, cmd = MockDebugger::setup('exit', false)
|
329
|
+
cmdproc = cmd.proc
|
330
|
+
onoff = %w(1 0 on off)
|
331
|
+
onoff.each { |val| puts "onoff(#{val}) = #{cmdproc.get_onoff(val)}" }
|
332
|
+
%w(1 1E bad 1+1 -5).each do |val|
|
333
|
+
puts "get_int_noerr(#{val}) = #{cmdproc.get_int_noerr(val).inspect}"
|
334
|
+
end
|
335
|
+
def foo; 5 end
|
336
|
+
|
337
|
+
pos = cmdproc.parse_position('../../rubies/rbx-head/bin/irb')
|
338
|
+
puts pos.inspect
|
339
|
+
|
340
|
+
puts cmdproc.parse_position(__FILE__).inspect
|
341
|
+
puts cmdproc.parse_position('@8').inspect
|
342
|
+
puts cmdproc.parse_position('8').inspect
|
343
|
+
puts cmdproc.parse_position("#{__FILE__} #{__LINE__}").inspect
|
344
|
+
|
345
|
+
cmdproc.method?('cmdproc.errmsg')
|
346
|
+
puts '=' * 40
|
347
|
+
['Array.map', 'Trepan::CmdProcessor.new',
|
348
|
+
'foo', 'cmdproc.errmsg'].each do |str|
|
349
|
+
puts "#{str} should be true: #{cmdproc.method?(str).inspect}"
|
350
|
+
end
|
351
|
+
puts '=' * 40
|
352
|
+
|
353
|
+
# FIXME:
|
354
|
+
# Array#foo should be false: true
|
355
|
+
# Trepan::CmdProcessor.allocate should be false: true
|
356
|
+
|
357
|
+
['food', '.errmsg'].each do |str|
|
358
|
+
puts "#{str} should be false: #{cmdproc.method?(str).inspect}"
|
359
|
+
end
|
360
|
+
puts '-' * 20
|
361
|
+
|
362
|
+
puts "Trepan::CmdProcessor.allocate is: #{cmdproc.get_method('Trepan::CmdProcessor.allocate')}"
|
363
|
+
|
364
|
+
# require_relative '../lib/trepanning'; debugger
|
365
|
+
# pos = cmdproc.breakpoint_position('../processor/validate.rb', true)
|
366
|
+
# p ['breakpoint validate', pos]
|
367
|
+
|
368
|
+
p cmdproc.breakpoint_position('foo', true)
|
369
|
+
p cmdproc.breakpoint_position('@0', true)
|
370
|
+
p cmdproc.breakpoint_position("#{__LINE__}", true)
|
371
|
+
p cmdproc.breakpoint_position("#{__FILE__} @0", false)
|
372
|
+
p cmdproc.breakpoint_position("#{__FILE__}:#{__LINE__}", true)
|
373
|
+
p cmdproc.breakpoint_position("#{__FILE__} #{__LINE__} if 1 == a", true)
|
374
|
+
p cmdproc.breakpoint_position("cmdproc.errmsg", false)
|
375
|
+
p cmdproc.breakpoint_position("cmdproc.errmsg:@0", false)
|
376
|
+
### p cmdproc.breakpoint_position(%w(2 if a > b))
|
377
|
+
p cmdproc.get_int_list(%w(1+0 3-1 3))
|
378
|
+
p cmdproc.get_int_list(%w(a 2 3))
|
379
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# The class serves as the parent for Trepan::CmdProcessor which is
|
2
|
+
# quite large and spans over several files. By declaring "initialize"
|
3
|
+
# below, we have a consistent initialization routine and many of the
|
4
|
+
# others don't need to define "initialize".
|
5
|
+
|
6
|
+
# Also, simple versions of the I/O routines make it possible
|
7
|
+
# to do testing without having to bring in the whole "Interface"
|
8
|
+
# and I/O routines that trepanning (and "main.rb") use.
|
9
|
+
|
10
|
+
# Note that via this file we can change 'class Trepan' to 'module
|
11
|
+
# Trepan' or vice versa. So this takes effect on all of the places
|
12
|
+
# which subclass this. They use class Trepan::CmdProcessor <
|
13
|
+
# Trepan::VirtualCmdProcessor rather than breaking this down into to
|
14
|
+
# parts as below.
|
15
|
+
class Trepan
|
16
|
+
class VirtualCmdProcessor
|
17
|
+
attr_accessor :settings
|
18
|
+
def initialize(interfaces, settings={})
|
19
|
+
@interfaces = interfaces
|
20
|
+
@intf = interfaces[-1]
|
21
|
+
@settings = settings
|
22
|
+
end
|
23
|
+
def errmsg(message)
|
24
|
+
puts "Error: #{message}"
|
25
|
+
end
|
26
|
+
def msg(message)
|
27
|
+
puts message
|
28
|
+
end
|
29
|
+
def section(message, opts={})
|
30
|
+
puts "Section: #{message}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|