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
data/processor/subcmd.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
|
2
|
+
# gdb-like subcommand processing.
|
3
|
+
|
4
|
+
class Trepan
|
5
|
+
class Subcmd
|
6
|
+
|
7
|
+
attr_reader :subcmds # Hash of subcommands. Key is the subcommand name.
|
8
|
+
# the value is the subcommand object to run.
|
9
|
+
def initialize(cmd)
|
10
|
+
@cmd = cmd
|
11
|
+
@subcmds = {}
|
12
|
+
@cmdlist = []
|
13
|
+
end
|
14
|
+
|
15
|
+
# Find subcmd in self.subcmds
|
16
|
+
def lookup(subcmd_prefix, use_regexp=true)
|
17
|
+
compare = if use_regexp
|
18
|
+
lambda{|name| name.to_s =~ /^#{subcmd_prefix}/}
|
19
|
+
else
|
20
|
+
lambda{|name| 0 == name.to_s.index(subcmd_prefix)}
|
21
|
+
end
|
22
|
+
@subcmds.each do |subcmd_name, subcmd|
|
23
|
+
if compare.call(subcmd_name) &&
|
24
|
+
subcmd_prefix.size >= subcmd.class.const_get(:MIN_ABBREV)
|
25
|
+
return subcmd
|
26
|
+
end
|
27
|
+
end
|
28
|
+
return nil
|
29
|
+
end
|
30
|
+
|
31
|
+
# Show short help for a subcommand.
|
32
|
+
def short_help(subcmd_cb, subcmd_name, label=false)
|
33
|
+
entry = self.lookup(subcmd_name)
|
34
|
+
if entry
|
35
|
+
if label
|
36
|
+
prefix = entry.name
|
37
|
+
else
|
38
|
+
prefix = ''
|
39
|
+
end
|
40
|
+
if entry.respond_to?(:short_help)
|
41
|
+
prefix += ' -- ' if prefix
|
42
|
+
@proc.msg(prefix + entry.short_help)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
@proc.undefined_subcmd("help", subcmd_name)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Add subcmd to the available subcommands for this object.
|
50
|
+
# It will have the supplied docstring, and subcmd_cb will be called
|
51
|
+
# when we want to run the command. min_len is the minimum length
|
52
|
+
# allowed to abbreviate the command. in_list indicates with the
|
53
|
+
# show command will be run when giving a list of all sub commands
|
54
|
+
# of this object. Some commands have long output like "show commands"
|
55
|
+
# so we might not want to show that.
|
56
|
+
def add(subcmd_cb, subcmd_name=nil)
|
57
|
+
subcmd_name ||= subcmd_cb.name
|
58
|
+
@subcmds[subcmd_name.to_s] = subcmd_cb
|
59
|
+
|
60
|
+
# We keep a list of subcommands to assist command completion
|
61
|
+
@cmdlist << subcmd_name
|
62
|
+
end
|
63
|
+
|
64
|
+
# Run subcmd_name with args using obj for the environent
|
65
|
+
def run( subcmd_name, arg)
|
66
|
+
entry=lookup(subcmd_name)
|
67
|
+
if entry
|
68
|
+
entry['callback'].send(arg)
|
69
|
+
else
|
70
|
+
@proc.undefined_cmd(entry.__class__.name, subcmd_name)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# help for subcommands
|
75
|
+
# Note: format of help is compatible with ddd.
|
76
|
+
def help(*args)
|
77
|
+
|
78
|
+
msg args
|
79
|
+
subcmd_prefix = args[0]
|
80
|
+
if not subcmd_prefix or subcmd_prefix.size == 0
|
81
|
+
@proc.msg(self.doc)
|
82
|
+
@proc.msg("\nList of %s subcommands:\n" % [@name])
|
83
|
+
@list.each do |subcmd_name|
|
84
|
+
subcmd_helper(subcmd_name, obj, true, true)
|
85
|
+
end
|
86
|
+
|
87
|
+
entry = lookup(subcmd_prefix)
|
88
|
+
if entry and entry.respond_to? :help
|
89
|
+
entry.help(args)
|
90
|
+
else
|
91
|
+
@proc.errmsg("Unknown 'help %s' subcommand %s" %
|
92
|
+
[@name, subcmd_prefix])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def list
|
98
|
+
@subcmds.keys.sort
|
99
|
+
end
|
100
|
+
|
101
|
+
# Error message when a subcommand doesn't exist.
|
102
|
+
def undefined_subcmd(cmd, subcmd)
|
103
|
+
@proc.errmsg('Undefined "%s" command: "%s". Try "help".' %
|
104
|
+
[cmd, subcmd])
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# When invoked as main program, invoke the debugger on a script
|
110
|
+
if __FILE__ == $0
|
111
|
+
|
112
|
+
require 'rubygems'; require 'require_relative'
|
113
|
+
require_relative 'mock'
|
114
|
+
require_relative 'command/base/cmd'
|
115
|
+
|
116
|
+
class Trepan::TestCommand < Trepan::Command
|
117
|
+
|
118
|
+
HELP = 'Help string string for testing'
|
119
|
+
CATEGORY = 'data'
|
120
|
+
MIN_ARGS = 0
|
121
|
+
MAX_ARGS = 5
|
122
|
+
NAME_ALIASES = %w(test)
|
123
|
+
|
124
|
+
def initialize(proc); @proc = proc end
|
125
|
+
|
126
|
+
def run(args); puts 'test command run' end
|
127
|
+
end
|
128
|
+
|
129
|
+
class TestTestingSubcommand
|
130
|
+
HELP = 'Help string for test testing subcommand'
|
131
|
+
|
132
|
+
def initialize; @name = 'testing' end
|
133
|
+
|
134
|
+
SHORT_HELP = 'This is short help for test testing'
|
135
|
+
MIN_ABREV = 4
|
136
|
+
IN_LIST = true
|
137
|
+
def run(args); puts 'test testing run' end
|
138
|
+
end
|
139
|
+
|
140
|
+
d = MockDebugger::MockDebugger.new
|
141
|
+
testcmd = Trepan::TestCommand.new(nil)
|
142
|
+
# testcmd.debugger = d
|
143
|
+
# testcmd.proc = d.core.processor
|
144
|
+
# testcmdMgr = Subcmd.new('test', testcmd)
|
145
|
+
# testsub = TestTestingSubcommand.new
|
146
|
+
# testcmdMgr.add(testsub)
|
147
|
+
|
148
|
+
# %w(tes test testing testing1).each do |prefix|
|
149
|
+
# x = testcmdMgr.lookup(prefix)
|
150
|
+
# puts x ? x.name : 'Non'
|
151
|
+
# end
|
152
|
+
|
153
|
+
# testcmdMgr.short_help(testcmd, 'testing')
|
154
|
+
# testcmdMgr.short_help(testcmd, 'test', true)
|
155
|
+
# testcmdMgr.short_help(testcmd, 'tes')
|
156
|
+
# puts testcmdMgr.list()
|
157
|
+
# testsub2 = TestTestingSubcommand.new
|
158
|
+
# testsub2.name = 'foobar'
|
159
|
+
# testcmdMgr.add(testsub2)
|
160
|
+
# puts testcmdMgr.list()
|
161
|
+
end
|
@@ -0,0 +1,355 @@
|
|
1
|
+
# Copyright (C) 2010 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
|
+
require_relative '../app/method'
|
10
|
+
require_relative '../app/validate'
|
11
|
+
## require_relative '../app/condition'
|
12
|
+
## require_relative '../app/file'
|
13
|
+
class Trepan
|
14
|
+
class CmdProcessor
|
15
|
+
|
16
|
+
attr_reader :dbgr_script_iseqs
|
17
|
+
attr_reader :dbgr_iseqs
|
18
|
+
|
19
|
+
include Trepanning::Method
|
20
|
+
include Trepan::Validate
|
21
|
+
## include Trepan::ThreadHelper
|
22
|
+
## include Trepan::Condition
|
23
|
+
|
24
|
+
def confirm(msg, default)
|
25
|
+
@settings[:confirm] ? @dbgr.intf[-1].confirm(msg, default) : true
|
26
|
+
end
|
27
|
+
|
28
|
+
# Like cmdfns.get_an_int(), but if there's a stack frame use that
|
29
|
+
# in evaluation.
|
30
|
+
def get_an_int(arg, opts={})
|
31
|
+
ret_value = get_int_noerr(arg)
|
32
|
+
if !ret_value
|
33
|
+
if opts[:msg_on_error]
|
34
|
+
errmsg(opts[:msg_on_error])
|
35
|
+
else
|
36
|
+
errmsg("Expecting an integer, got: #{arg}.")
|
37
|
+
end
|
38
|
+
return nil
|
39
|
+
end
|
40
|
+
if opts[:min_value] and ret_value < opts[:min_value]
|
41
|
+
errmsg("Expecting integer value to be at least %d; got %d." %
|
42
|
+
[opts[:min_value], ret_value])
|
43
|
+
return nil
|
44
|
+
elsif opts[:max_value] and ret_value > opts[:max_value]
|
45
|
+
errmsg("Expecting integer value to be at most %d; got %d." %
|
46
|
+
[opts[:max_value], ret_value])
|
47
|
+
return nil
|
48
|
+
end
|
49
|
+
return ret_value
|
50
|
+
end
|
51
|
+
|
52
|
+
unless defined?(DEFAULT_GET_INT_OPTS)
|
53
|
+
DEFAULT_GET_INT_OPTS = {
|
54
|
+
:min_value => 0, :default => 1, :cmdname => nil, :max_value => nil}
|
55
|
+
end
|
56
|
+
|
57
|
+
# If argument parameter 'arg' is not given, then use what is in
|
58
|
+
# opts[:default]. If String 'arg' evaluates to an integer between
|
59
|
+
# least min_value and at_most, use that. Otherwise report an
|
60
|
+
# error. If there's a stack frame use that for bindings in
|
61
|
+
# evaluation.
|
62
|
+
def get_int(arg, opts={})
|
63
|
+
|
64
|
+
return default unless arg
|
65
|
+
opts = DEFAULT_GET_INT_OPTS.merge(opts)
|
66
|
+
val = arg ? get_int_noerr(arg) : opts[:default]
|
67
|
+
unless val
|
68
|
+
if opts[:cmdname]
|
69
|
+
errmsg(("Command '%s' expects an integer; " +
|
70
|
+
"got: %s.") % [opts[:cmdname], arg])
|
71
|
+
else
|
72
|
+
errmsg('Expecting a positive integer, got: %s' % arg)
|
73
|
+
end
|
74
|
+
return nil
|
75
|
+
end
|
76
|
+
|
77
|
+
if val < opts[:min_value]
|
78
|
+
if opts[:cmdname]
|
79
|
+
errmsg(("Command '%s' expects an integer at least" +
|
80
|
+
' %d; got: %d.') %
|
81
|
+
[opts[:cmdname], opts[:min_value], opts[:default]])
|
82
|
+
else
|
83
|
+
errmsg(("Expecting a positive integer at least" +
|
84
|
+
' %d; got: %d') %
|
85
|
+
[opts[:min_value], opts[:default]])
|
86
|
+
end
|
87
|
+
return nil
|
88
|
+
elsif opts[:max_value] and val > opts[:max_value]
|
89
|
+
if opts[:cmdname]
|
90
|
+
errmsg(("Command '%s' expects an integer at most" +
|
91
|
+
' %d; got: %d.') %
|
92
|
+
[opts[:cmdname], opts[:max_value], val])
|
93
|
+
else
|
94
|
+
errmsg(("Expecting an integer at most %d; got: %d") %
|
95
|
+
[opts[:max_value], val])
|
96
|
+
end
|
97
|
+
return nil
|
98
|
+
end
|
99
|
+
return val
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_int_list(args, opts={})
|
103
|
+
args.map{|arg| get_an_int(arg, opts)}.compact
|
104
|
+
end
|
105
|
+
|
106
|
+
# Eval arg and it is an integer return the value. Otherwise
|
107
|
+
# return nil
|
108
|
+
def get_int_noerr(arg)
|
109
|
+
b = @frame ? @frame.binding : nil
|
110
|
+
val = Integer(eval(arg, b))
|
111
|
+
rescue SyntaxError
|
112
|
+
nil
|
113
|
+
rescue
|
114
|
+
nil
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_thread_from_string(id_or_num_str)
|
118
|
+
if id_or_num_str == '.'
|
119
|
+
Thread.current
|
120
|
+
elsif id_or_num_str.downcase == 'm'
|
121
|
+
Thread.main
|
122
|
+
else
|
123
|
+
num = get_int_noerr(id_or_num_str)
|
124
|
+
if num
|
125
|
+
get_thread(num)
|
126
|
+
else
|
127
|
+
nil
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Parse a breakpoint position. On success return
|
133
|
+
# - a string "description"
|
134
|
+
# - the method the position is in - a CompiledMethod or a String
|
135
|
+
# - the line - a Fixnum
|
136
|
+
# - whether the position is an instance or not
|
137
|
+
# On failure, an error message is shown and we return nil.
|
138
|
+
def breakpoint_position(args)
|
139
|
+
ip = nil
|
140
|
+
if args.size == 0
|
141
|
+
args = [frame.line.to_s]
|
142
|
+
end
|
143
|
+
if args[0] == 'main.__script__'
|
144
|
+
if args.size > 2
|
145
|
+
errmsg 'Expecting only a line number'
|
146
|
+
return nil
|
147
|
+
elsif args.size == 2
|
148
|
+
ip, line = line_or_ip(args[1])
|
149
|
+
unless line || ip
|
150
|
+
errmsg ("Expecting a line or an IP offset number")
|
151
|
+
return nil
|
152
|
+
end
|
153
|
+
else
|
154
|
+
ip, line = nil, nil
|
155
|
+
end
|
156
|
+
return [args.join(' '), '.', '__script__', line, ip]
|
157
|
+
elsif args.size == 1
|
158
|
+
meth = parse_method(args[0])
|
159
|
+
if meth
|
160
|
+
cm = meth.executable
|
161
|
+
return [args[0], nil, true, cm, cm.lines[1], cm.lines[0]]
|
162
|
+
else
|
163
|
+
m = /([A-Z]\w*(?:::[A-Z]\w*)*)([.#])(\w+[!?=]?)(?:[:]([oO])?(\d+))?/.match(args[0])
|
164
|
+
if m
|
165
|
+
if m[4]
|
166
|
+
return [m[0], m[1], m[2], m[3], nil, m[5] ? m[5].to_i : nil]
|
167
|
+
else
|
168
|
+
return [m[0], m[1], m[2], m[3], (m[4] ? m[4].to_i : nil), nil]
|
169
|
+
end
|
170
|
+
else
|
171
|
+
ip, line = line_or_ip(args[0])
|
172
|
+
unless line || ip
|
173
|
+
errmsg ("Expecting a line or an IP offset number")
|
174
|
+
return nil
|
175
|
+
end
|
176
|
+
if line
|
177
|
+
meth = find_method_with_line(frame.method, line)
|
178
|
+
unless meth
|
179
|
+
errmsg "Cannot find method location for line #{line}"
|
180
|
+
return nil
|
181
|
+
end
|
182
|
+
elsif valid_ip?(frame.method, ip)
|
183
|
+
return [args.join(' '), meth.class, '#', frame.method, nil, ip]
|
184
|
+
else
|
185
|
+
errmsg 'Cannot parse breakpoint location'
|
186
|
+
return nil
|
187
|
+
end
|
188
|
+
|
189
|
+
return ["#{meth.describe}", nil, '#', meth, line, nil]
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
errmsg 'Cannot parse breakpoint location'
|
194
|
+
return nil
|
195
|
+
end
|
196
|
+
|
197
|
+
# Return true if arg is 'on' or 1 and false arg is 'off' or 0.
|
198
|
+
# Any other value is raises TypeError.
|
199
|
+
def get_onoff(arg, default=nil, print_error=true)
|
200
|
+
unless arg
|
201
|
+
if !default
|
202
|
+
if print_error
|
203
|
+
errmsg("Expecting 'on', 1, 'off', or 0. Got nothing.")
|
204
|
+
end
|
205
|
+
raise TypeError
|
206
|
+
end
|
207
|
+
return default
|
208
|
+
end
|
209
|
+
darg = arg.downcase
|
210
|
+
return true if arg == '1' || darg == 'on'
|
211
|
+
return false if arg == '0' || darg =='off'
|
212
|
+
|
213
|
+
errmsg("Expecting 'on', 1, 'off', or 0. Got: %s." % arg.to_s) if
|
214
|
+
print_error
|
215
|
+
raise TypeError
|
216
|
+
end
|
217
|
+
|
218
|
+
def method?(method_string)
|
219
|
+
obj, type, meth =
|
220
|
+
if method_string =~ /(.+)(#|::|\.)(.+)/
|
221
|
+
[$1, $2, $3]
|
222
|
+
else
|
223
|
+
['self', '.', method_string]
|
224
|
+
end
|
225
|
+
ret = debug_eval_no_errmsg("#{obj}.method(#{meth.inspect})")
|
226
|
+
return true if ret
|
227
|
+
return debug_eval_no_errmsg("#{obj}.is_a?(Class)") &&
|
228
|
+
debug_eval_no_errmsg("#{obj}.method_defined?(#{meth.inspect})")
|
229
|
+
end
|
230
|
+
|
231
|
+
# parse_position(self, arg)->(fn, container, lineno)
|
232
|
+
#
|
233
|
+
# Parse arg as [filename:]lineno | function | module
|
234
|
+
# Make sure it works for C:\foo\bar.py:12
|
235
|
+
def parse_position(arg, old_mod=nil, allow_offset = false)
|
236
|
+
colon = arg.rindex(':')
|
237
|
+
if colon
|
238
|
+
# First handle part before the colon
|
239
|
+
arg1 = arg[0...colon].rstrip
|
240
|
+
lineno_str = arg[colon+1..-1].lstrip
|
241
|
+
mf, container, lineno = parse_position_one_arg(arg1, old_mod, false, allow_offset)
|
242
|
+
return nil, nil, nil unless container
|
243
|
+
filename = canonic_file(arg1)
|
244
|
+
# Next handle part after the colon
|
245
|
+
val = get_an_int(lineno_str)
|
246
|
+
lineno = val if val
|
247
|
+
else
|
248
|
+
mf, container, lineno = parse_position_one_arg(arg, old_mod, true, allow_offset)
|
249
|
+
end
|
250
|
+
|
251
|
+
return mf, container, lineno
|
252
|
+
end
|
253
|
+
|
254
|
+
# parse_position_one_arg(self,arg)->(module/function, container, lineno)
|
255
|
+
#
|
256
|
+
# See if arg is a line number, function name, or module name.
|
257
|
+
# Return what we've found. nil can be returned as a value in
|
258
|
+
# the triple.
|
259
|
+
def parse_position_one_arg(arg, old_mod=nil, show_errmsg=true, allow_offset=false)
|
260
|
+
name, filename = nil, nil, nil
|
261
|
+
begin
|
262
|
+
# First see if argument is an integer
|
263
|
+
lineno = Integer(arg)
|
264
|
+
rescue
|
265
|
+
else
|
266
|
+
filename = @frame.file
|
267
|
+
return nil, canonic_file(filename), lineno
|
268
|
+
end
|
269
|
+
|
270
|
+
# Next see if argument is a file name
|
271
|
+
if LineCache::cached?(arg)
|
272
|
+
return nil, canonic_file(arg), 1
|
273
|
+
elsif File.readable?(arg)
|
274
|
+
return nil, canonic_file(arg), 1
|
275
|
+
end
|
276
|
+
|
277
|
+
# How about a method name with an instruction sequence?
|
278
|
+
meth = parse_method(arg)
|
279
|
+
if meth
|
280
|
+
cm = meth.executable
|
281
|
+
return arg, canonic_file(cm.active_path), cm.lines[1]
|
282
|
+
end
|
283
|
+
|
284
|
+
if show_errmsg
|
285
|
+
unless (allow_offset && arg.size > 0 && arg[0].downcase == 'o')
|
286
|
+
errmsg("#{arg} is not a line number, filename or method " +
|
287
|
+
"we can get location information about")
|
288
|
+
end
|
289
|
+
end
|
290
|
+
return nil, nil, nil
|
291
|
+
end
|
292
|
+
|
293
|
+
def parse_method(meth_str)
|
294
|
+
# For meth_str = "foo", try via method("foo".to_sym)
|
295
|
+
str = "method(#{meth_str.inspect}.to_sym)"
|
296
|
+
meth = debug_eval_no_errmsg(str)
|
297
|
+
return meth if meth
|
298
|
+
last_dot = meth_str.rindex('.')
|
299
|
+
if last_dot
|
300
|
+
# For meth_str = "a.b.foo",
|
301
|
+
# try via a.b.method("foo".to_sym)
|
302
|
+
try_eval = "#{meth_str[0..last_dot]}method" +
|
303
|
+
"(#{meth_str[last_dot+1..-1].inspect}.to_sym)"
|
304
|
+
meth = debug_eval_no_errmsg(try_eval)
|
305
|
+
end
|
306
|
+
return meth
|
307
|
+
end
|
308
|
+
|
309
|
+
def validate_initialize
|
310
|
+
## top_srcdir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
311
|
+
## @dbgr_script_iseqs, @dbgr_iseqs = filter_scripts(top_srcdir)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
if __FILE__ == $0
|
317
|
+
# Demo it.
|
318
|
+
require_relative './mock'
|
319
|
+
dbgr, cmd = MockDebugger::setup('exit', false)
|
320
|
+
proc = cmd.proc
|
321
|
+
onoff = %w(1 0 on off)
|
322
|
+
onoff.each { |val| puts "onoff(#{val}) = #{proc.get_onoff(val)}" }
|
323
|
+
%w(1 1E bad 1+1 -5).each do |val|
|
324
|
+
puts "get_int_noerr(#{val}) = #{proc.get_int_noerr(val).inspect}"
|
325
|
+
end
|
326
|
+
def foo; 5 end
|
327
|
+
def proc.errmsg(msg)
|
328
|
+
puts msg
|
329
|
+
end
|
330
|
+
puts proc.parse_position_one_arg('tmpdir.rb').inspect
|
331
|
+
|
332
|
+
puts '=' * 40
|
333
|
+
['Array#map', 'Trepan::CmdProcessor.new',
|
334
|
+
'foo', 'proc.errmsg'].each do |str|
|
335
|
+
puts "#{str} should be true: #{proc.method?(str).inspect}"
|
336
|
+
end
|
337
|
+
puts '=' * 40
|
338
|
+
|
339
|
+
# FIXME:
|
340
|
+
# Array#foo should be false: true
|
341
|
+
# Trepan::CmdProcessor.allocate should be false: true
|
342
|
+
|
343
|
+
['food', '.errmsg'].each do |str|
|
344
|
+
puts "#{str} should be false: #{proc.method?(str).inspect}"
|
345
|
+
end
|
346
|
+
puts '-' * 20
|
347
|
+
# require_relative '../lib/trepanning'
|
348
|
+
# Trepan.start
|
349
|
+
p proc.breakpoint_position(%w(O0))
|
350
|
+
p proc.breakpoint_position(%w(1))
|
351
|
+
p proc.breakpoint_position(%w(__LINE__))
|
352
|
+
# p proc.breakpoint_position(%w(2 if a > b))
|
353
|
+
p proc.get_int_list(%w(1+0 3-1 3))
|
354
|
+
p proc.get_int_list(%w(a 2 3))
|
355
|
+
end
|