trepanning 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +4422 -0
- data/LICENSE +23 -0
- data/NEWS +12 -0
- data/README.textile +56 -0
- data/Rakefile +171 -0
- data/app/Makefile +7 -0
- data/app/breakpoint.rb +157 -0
- data/app/brkptmgr.rb +149 -0
- data/app/condition.rb +22 -0
- data/app/core.rb +203 -0
- data/app/default.rb +54 -0
- data/app/disassemble.rb +61 -0
- data/app/display.rb +148 -0
- data/app/file.rb +135 -0
- data/app/frame.rb +275 -0
- data/app/irb.rb +112 -0
- data/app/mock.rb +22 -0
- data/app/options.rb +122 -0
- data/app/run.rb +95 -0
- data/app/thread.rb +24 -0
- data/app/util.rb +32 -0
- data/bin/trepan +63 -0
- data/data/custom_require.rb +44 -0
- data/data/irbrc +55 -0
- data/data/prelude.rb +38 -0
- data/interface/base_intf.rb +95 -0
- data/interface/script.rb +103 -0
- data/interface/user.rb +90 -0
- data/io/base_io.rb +92 -0
- data/io/input.rb +111 -0
- data/io/string_array.rb +155 -0
- data/lib/Makefile +7 -0
- data/lib/trepanning.rb +277 -0
- data/processor/breakpoint.rb +108 -0
- data/processor/command/alias.rb +55 -0
- data/processor/command/backtrace.rb +95 -0
- data/processor/command/base/cmd.rb +97 -0
- data/processor/command/base/subcmd.rb +207 -0
- data/processor/command/base/submgr.rb +178 -0
- data/processor/command/base/subsubcmd.rb +102 -0
- data/processor/command/base/subsubmgr.rb +182 -0
- data/processor/command/break.rb +85 -0
- data/processor/command/condition.rb +64 -0
- data/processor/command/continue.rb +61 -0
- data/processor/command/debug.rb +85 -0
- data/processor/command/delete.rb +54 -0
- data/processor/command/directory.rb +43 -0
- data/processor/command/disable.rb +65 -0
- data/processor/command/disassemble.rb +103 -0
- data/processor/command/display.rb +81 -0
- data/processor/command/down.rb +56 -0
- data/processor/command/enable.rb +43 -0
- data/processor/command/exit.rb +54 -0
- data/processor/command/finish.rb +81 -0
- data/processor/command/frame.rb +117 -0
- data/processor/command/help.rb +146 -0
- data/processor/command/info.rb +28 -0
- data/processor/command/info_subcmd/args.rb +56 -0
- data/processor/command/info_subcmd/breakpoints.rb +162 -0
- data/processor/command/info_subcmd/file.rb +162 -0
- data/processor/command/info_subcmd/frame.rb +39 -0
- data/processor/command/info_subcmd/iseq.rb +83 -0
- data/processor/command/info_subcmd/locals.rb +88 -0
- data/processor/command/info_subcmd/program.rb +54 -0
- data/processor/command/info_subcmd/registers.rb +72 -0
- data/processor/command/info_subcmd/registers_subcmd/dfp.rb +38 -0
- data/processor/command/info_subcmd/registers_subcmd/helper.rb +40 -0
- data/processor/command/info_subcmd/registers_subcmd/lfp.rb +54 -0
- data/processor/command/info_subcmd/registers_subcmd/pc.rb +44 -0
- data/processor/command/info_subcmd/registers_subcmd/sp.rb +75 -0
- data/processor/command/info_subcmd/return.rb +40 -0
- data/processor/command/info_subcmd/thread.rb +106 -0
- data/processor/command/irb.rb +106 -0
- data/processor/command/kill.rb +58 -0
- data/processor/command/list.rb +327 -0
- data/processor/command/macro.rb +65 -0
- data/processor/command/next.rb +89 -0
- data/processor/command/nocache.rb +33 -0
- data/processor/command/print.rb +37 -0
- data/processor/command/ps.rb +40 -0
- data/processor/command/quit.rb +62 -0
- data/processor/command/raise.rb +47 -0
- data/processor/command/reload.rb +28 -0
- data/processor/command/reload_subcmd/command.rb +34 -0
- data/processor/command/restart.rb +57 -0
- data/processor/command/save.rb +60 -0
- data/processor/command/set.rb +47 -0
- data/processor/command/set_subcmd/auto.rb +27 -0
- data/processor/command/set_subcmd/auto_subcmd/eval.rb +67 -0
- data/processor/command/set_subcmd/auto_subcmd/irb.rb +49 -0
- data/processor/command/set_subcmd/auto_subcmd/list.rb +51 -0
- data/processor/command/set_subcmd/basename.rb +39 -0
- data/processor/command/set_subcmd/debug.rb +27 -0
- data/processor/command/set_subcmd/debug_subcmd/dbgr.rb +49 -0
- data/processor/command/set_subcmd/debug_subcmd/except.rb +35 -0
- data/processor/command/set_subcmd/debug_subcmd/macro.rb +35 -0
- data/processor/command/set_subcmd/debug_subcmd/skip.rb +35 -0
- data/processor/command/set_subcmd/debug_subcmd/stack.rb +45 -0
- data/processor/command/set_subcmd/different.rb +67 -0
- data/processor/command/set_subcmd/events.rb +71 -0
- data/processor/command/set_subcmd/max.rb +35 -0
- data/processor/command/set_subcmd/max_subcmd/list.rb +50 -0
- data/processor/command/set_subcmd/max_subcmd/stack.rb +60 -0
- data/processor/command/set_subcmd/max_subcmd/string.rb +53 -0
- data/processor/command/set_subcmd/max_subcmd/width.rb +50 -0
- data/processor/command/set_subcmd/return.rb +66 -0
- data/processor/command/set_subcmd/sp.rb +62 -0
- data/processor/command/set_subcmd/substitute.rb +25 -0
- data/processor/command/set_subcmd/substitute_subcmd/eval.rb +98 -0
- data/processor/command/set_subcmd/substitute_subcmd/path.rb +55 -0
- data/processor/command/set_subcmd/substitute_subcmd/string.rb +72 -0
- data/processor/command/set_subcmd/timer.rb +68 -0
- data/processor/command/set_subcmd/trace.rb +43 -0
- data/processor/command/set_subcmd/trace_subcmd/buffer.rb +56 -0
- data/processor/command/set_subcmd/trace_subcmd/print.rb +54 -0
- data/processor/command/set_subcmd/trace_subcmd/var.rb +61 -0
- data/processor/command/show.rb +27 -0
- data/processor/command/show_subcmd/alias.rb +50 -0
- data/processor/command/show_subcmd/args.rb +50 -0
- data/processor/command/show_subcmd/auto.rb +27 -0
- data/processor/command/show_subcmd/auto_subcmd/eval.rb +38 -0
- data/processor/command/show_subcmd/auto_subcmd/irb.rb +34 -0
- data/processor/command/show_subcmd/auto_subcmd/list.rb +36 -0
- data/processor/command/show_subcmd/basename.rb +28 -0
- data/processor/command/show_subcmd/debug.rb +27 -0
- data/processor/command/show_subcmd/debug_subcmd/dbgr.rb +31 -0
- data/processor/command/show_subcmd/debug_subcmd/except.rb +33 -0
- data/processor/command/show_subcmd/debug_subcmd/macro.rb +32 -0
- data/processor/command/show_subcmd/debug_subcmd/skip.rb +33 -0
- data/processor/command/show_subcmd/debug_subcmd/stack.rb +32 -0
- data/processor/command/show_subcmd/different.rb +37 -0
- data/processor/command/show_subcmd/events.rb +40 -0
- data/processor/command/show_subcmd/macro.rb +45 -0
- data/processor/command/show_subcmd/max.rb +31 -0
- data/processor/command/show_subcmd/max_subcmd/list.rb +39 -0
- data/processor/command/show_subcmd/max_subcmd/stack.rb +35 -0
- data/processor/command/show_subcmd/max_subcmd/string.rb +41 -0
- data/processor/command/show_subcmd/max_subcmd/width.rb +36 -0
- data/processor/command/show_subcmd/trace.rb +29 -0
- data/processor/command/show_subcmd/trace_subcmd/buffer.rb +84 -0
- data/processor/command/show_subcmd/trace_subcmd/print.rb +38 -0
- data/processor/command/source.rb +74 -0
- data/processor/command/step.rb +139 -0
- data/processor/command/stepi.rb +63 -0
- data/processor/command/unalias.rb +44 -0
- data/processor/command/undisplay.rb +63 -0
- data/processor/command/up.rb +92 -0
- data/processor/default.rb +45 -0
- data/processor/display.rb +17 -0
- data/processor/eval.rb +88 -0
- data/processor/eventbuf.rb +131 -0
- data/processor/frame.rb +230 -0
- data/processor/help.rb +72 -0
- data/processor/hook.rb +128 -0
- data/processor/load_cmds.rb +102 -0
- data/processor/location.rb +126 -0
- data/processor/main.rb +364 -0
- data/processor/mock.rb +100 -0
- data/processor/msg.rb +26 -0
- data/processor/running.rb +170 -0
- data/processor/subcmd.rb +159 -0
- data/processor/validate.rb +395 -0
- data/test/example/fname with blank.rb +1 -0
- data/test/example/gcd-xx.rb +18 -0
- data/test/example/gcd.rb +19 -0
- data/test/example/gcd1.rb +24 -0
- data/test/example/null.rb +1 -0
- data/test/example/thread1.rb +3 -0
- data/test/functional/fn_helper.rb +119 -0
- data/test/functional/test-break.rb +87 -0
- data/test/functional/test-condition.rb +59 -0
- data/test/functional/test-debugger-call-bug.rb +31 -0
- data/test/functional/test-delete.rb +71 -0
- data/test/functional/test-finish.rb +44 -0
- data/test/functional/test-immediate-step-bug.rb +35 -0
- data/test/functional/test-next.rb +77 -0
- data/test/functional/test-raise.rb +73 -0
- data/test/functional/test-return.rb +100 -0
- data/test/functional/test-step.rb +274 -0
- data/test/functional/test-stepbug.rb +40 -0
- data/test/functional/test-trace-var.rb +40 -0
- data/test/functional/tmp/b1.rb +5 -0
- data/test/functional/tmp/s1.rb +9 -0
- data/test/functional/tmp/t2.rb +6 -0
- data/test/integration/file-diff.rb +88 -0
- data/test/integration/helper.rb +52 -0
- data/test/integration/test-fname-with-blank.rb +11 -0
- data/test/integration/test-quit.rb +11 -0
- data/test/integration/try-test-enable.rb +11 -0
- data/test/unit/cmd-helper.rb +44 -0
- data/test/unit/test-app-brkpt.rb +30 -0
- data/test/unit/test-app-brkptmgr.rb +56 -0
- data/test/unit/test-app-disassemble.rb +60 -0
- data/test/unit/test-app-file.rb +46 -0
- data/test/unit/test-app-frame.rb +49 -0
- data/test/unit/test-app-options.rb +60 -0
- data/test/unit/test-app-run.rb +19 -0
- data/test/unit/test-app-thread.rb +25 -0
- data/test/unit/test-app-util.rb +17 -0
- data/test/unit/test-base-subcmd.rb +59 -0
- data/test/unit/test-bin-trepan.rb +48 -0
- data/test/unit/test-cmd-alias.rb +50 -0
- data/test/unit/test-cmd-break.rb +80 -0
- data/test/unit/test-cmd-endisable.rb +59 -0
- data/test/unit/test-cmd-help.rb +100 -0
- data/test/unit/test-cmd-kill.rb +47 -0
- data/test/unit/test-cmd-quit.rb +26 -0
- data/test/unit/test-cmd-step.rb +45 -0
- data/test/unit/test-intf-user.rb +45 -0
- data/test/unit/test-io-input.rb +26 -0
- data/test/unit/test-proc-eval.rb +26 -0
- data/test/unit/test-proc-frame.rb +77 -0
- data/test/unit/test-proc-help.rb +15 -0
- data/test/unit/test-proc-hook.rb +29 -0
- data/test/unit/test-proc-load_cmds.rb +40 -0
- data/test/unit/test-proc-main.rb +99 -0
- data/test/unit/test-proc-validate.rb +90 -0
- data/test/unit/test-subcmd-help.rb +48 -0
- metadata +358 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
|
|
2
|
+
require_relative '../app/core'
|
|
3
|
+
class Trepan
|
|
4
|
+
class CmdProcessor
|
|
5
|
+
|
|
6
|
+
attr_accessor :stop_condition # String or nil. When not nil
|
|
7
|
+
# this has to eval non-nil
|
|
8
|
+
# in order to stop.
|
|
9
|
+
attr_accessor :stop_events # Set or nil. If not nil, only
|
|
10
|
+
# events in this set will be
|
|
11
|
+
# considered for stopping. This is
|
|
12
|
+
# like core.step_events (which
|
|
13
|
+
# could be used instead), but it is
|
|
14
|
+
# a set of event names rather than
|
|
15
|
+
# a bitmask and it is intended to
|
|
16
|
+
# be more temporarily changed via
|
|
17
|
+
# "step>" or "step!" commands.
|
|
18
|
+
attr_accessor :to_method
|
|
19
|
+
|
|
20
|
+
# Does whatever needs to be done to set to continue program
|
|
21
|
+
# execution.
|
|
22
|
+
# FIXME: turn line_number into a condition.
|
|
23
|
+
def continue
|
|
24
|
+
@next_level = 32000 # I'm guessing the stack size can't
|
|
25
|
+
# ever reach this
|
|
26
|
+
@next_thread = nil
|
|
27
|
+
@core.step_count = -1 # No more event stepping
|
|
28
|
+
@leave_cmd_loop = true # Break out of the processor command loop.
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Does whatever needs to be done to set to "next" program
|
|
32
|
+
# execution.
|
|
33
|
+
def finish(level_count=0, opts={})
|
|
34
|
+
step(0, opts)
|
|
35
|
+
@next_level = @frame.stack_size - level_count
|
|
36
|
+
@next_thread = Thread.current
|
|
37
|
+
@stop_events = Set.new(%w(return))
|
|
38
|
+
|
|
39
|
+
# Try high-speed (run-time-assisted) method
|
|
40
|
+
@frame.trace_off = true # No more tracing in this frame
|
|
41
|
+
@frame.return_stop = true # don't need to
|
|
42
|
+
end
|
|
43
|
+
# Does whatever needs to be done to set to "next" program
|
|
44
|
+
# execution.
|
|
45
|
+
def next(step_count=1, opts={})
|
|
46
|
+
step(step_count, opts)
|
|
47
|
+
@next_level = @top_frame.stack_size
|
|
48
|
+
@next_thread = Thread.current
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Does whatever needs to be done to set to step program
|
|
52
|
+
# execution.
|
|
53
|
+
def step(step_count=1, opts={}, condition=nil)
|
|
54
|
+
continue
|
|
55
|
+
@core.step_count = step_count
|
|
56
|
+
@different_pos = opts[:different_pos] if
|
|
57
|
+
opts.keys.member?(:different_pos)
|
|
58
|
+
@stop_condition = condition
|
|
59
|
+
@stop_events = opts[:stop_events] if
|
|
60
|
+
opts.keys.member?(:stop_events)
|
|
61
|
+
@to_method = opts[:to_method]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def quit(cmd='quit')
|
|
65
|
+
@next_level = 32000 # I'm guessing the stack size can't
|
|
66
|
+
# ever reach this
|
|
67
|
+
@next_thread = nil
|
|
68
|
+
@core.step_count = -1 # No more event stepping
|
|
69
|
+
@leave_cmd_loop = true # Break out of the processor command loop.
|
|
70
|
+
@settings[:autoirb] = false
|
|
71
|
+
@cmdloop_prehooks.delete_by_name('autoirb')
|
|
72
|
+
@commands['quit'].run([cmd])
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def parse_next_step_suffix(step_cmd)
|
|
76
|
+
opts = {}
|
|
77
|
+
case step_cmd[-1..-1]
|
|
78
|
+
when '-'
|
|
79
|
+
opts[:different_pos] = false
|
|
80
|
+
when '+'
|
|
81
|
+
opts[:different_pos] = 'nostack'
|
|
82
|
+
when '='
|
|
83
|
+
opts[:different_pos] = true
|
|
84
|
+
when '!'
|
|
85
|
+
opts[:stop_events] = Set.new(%w(raise))
|
|
86
|
+
when '<'
|
|
87
|
+
opts[:stop_events] = Set.new(%w(c-return return))
|
|
88
|
+
when '>'
|
|
89
|
+
opts[:stop_events] = Set.new(%w(c-call call))
|
|
90
|
+
if step_cmd.size > 1 && step_cmd[-2..-2] == '<'
|
|
91
|
+
opts[:stop_events] = Set.new(%w(c-call c-return call return))
|
|
92
|
+
else
|
|
93
|
+
opts[:stop_events] = Set.new(%w(c-call call))
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
return opts
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def running_initialize
|
|
100
|
+
@stop_condition = nil
|
|
101
|
+
@stop_events = nil
|
|
102
|
+
@to_method = nil
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def stepping_skip?
|
|
106
|
+
|
|
107
|
+
return true if @core.step_count < 0
|
|
108
|
+
|
|
109
|
+
if @settings[:'debugskip']
|
|
110
|
+
msg "diff: #{@different_pos}, event : #{@event}, #{@stop_events.inspect}"
|
|
111
|
+
msg "step_count : #{@core.step_count}"
|
|
112
|
+
msg "next_level : #{@next_level}, ssize : #{@stack_size}"
|
|
113
|
+
msg "next_thread : #{@next_thread}, thread: #{Thread.current}"
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
return true if
|
|
117
|
+
!frame || (@next_level < @frame.stack_size &&
|
|
118
|
+
Thread.current == @next_thread)
|
|
119
|
+
|
|
120
|
+
new_pos = [@frame.source_container, frame_line,
|
|
121
|
+
@stack_size, @current_thread, @event, @frame.pc_offset]
|
|
122
|
+
|
|
123
|
+
skip_val = @stop_events && !@stop_events.member?(@event)
|
|
124
|
+
|
|
125
|
+
# If the last stop was a breakpoint, don't stop again if we are at
|
|
126
|
+
# the same location with a line event.
|
|
127
|
+
skip_val |= (@last_pos[4] == 'brkpt' &&
|
|
128
|
+
@event == 'line' &&
|
|
129
|
+
@frame.pc_offset == @last_pos[5])
|
|
130
|
+
|
|
131
|
+
if @settings[:'debugskip']
|
|
132
|
+
puts "skip: #{skip_val.inspect}, last: #{@last_pos}, new: #{new_pos}"
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
@last_pos[2] = new_pos[2] if 'nostack' == @different_pos
|
|
136
|
+
unless skip_val
|
|
137
|
+
condition_met =
|
|
138
|
+
if @stop_condition
|
|
139
|
+
puts 'stop_cond' if @settings[:'debugskip']
|
|
140
|
+
debug_eval_no_errmsg(@stop_condition)
|
|
141
|
+
elsif @to_method
|
|
142
|
+
puts "method #{@frame.method} #{@to_method}" if
|
|
143
|
+
@settings[:'debugskip']
|
|
144
|
+
@frame.method == @to_method
|
|
145
|
+
else
|
|
146
|
+
puts 'uncond' if @settings[:'debugskip']
|
|
147
|
+
true
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
msg("condition_met: #{condition_met}, last: #{@last_pos}, " +
|
|
151
|
+
"new: #{new_pos}, different #{@different_pos.inspect}") if
|
|
152
|
+
@settings[:'debugskip']
|
|
153
|
+
skip_val = ((@last_pos[0..3] == new_pos[0..3] && @different_pos) ||
|
|
154
|
+
!condition_met)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
@last_pos = new_pos if !@stop_events || @stop_events.member?(@event)
|
|
158
|
+
|
|
159
|
+
unless skip_val
|
|
160
|
+
# Set up the default values for the
|
|
161
|
+
# next time we consider skipping.
|
|
162
|
+
@different_pos = @settings[:different]
|
|
163
|
+
@stop_events = nil
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
return skip_val
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
end
|
|
170
|
+
end
|
data/processor/subcmd.rb
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
|
|
2
|
+
# gdb-like subcommand processing.
|
|
3
|
+
|
|
4
|
+
class Trepan
|
|
5
|
+
class Subcmd
|
|
6
|
+
|
|
7
|
+
attr_reader :subcmds
|
|
8
|
+
def initialize(cmd)
|
|
9
|
+
@cmd = cmd
|
|
10
|
+
@subcmds = {}
|
|
11
|
+
@cmdlist = []
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Find subcmd in self.subcmds
|
|
15
|
+
def lookup(subcmd_prefix, use_regexp=true)
|
|
16
|
+
compare = if use_regexp
|
|
17
|
+
lambda{|name| name.to_s =~ /^#{subcmd_prefix}/}
|
|
18
|
+
else
|
|
19
|
+
lambda{|name| 0 == name.to_s.index(subcmd_prefix)}
|
|
20
|
+
end
|
|
21
|
+
@subcmds.each do |subcmd_name, subcmd|
|
|
22
|
+
if compare.call(subcmd_name) &&
|
|
23
|
+
subcmd_prefix.size >= subcmd.class.const_get(:MIN_ABBREV)
|
|
24
|
+
return subcmd
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
return nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Show short help for a subcommand.
|
|
31
|
+
def short_help(subcmd_cb, subcmd_name, label=false)
|
|
32
|
+
entry = self.lookup(subcmd_name)
|
|
33
|
+
if entry
|
|
34
|
+
if label
|
|
35
|
+
prefix = entry.name
|
|
36
|
+
else
|
|
37
|
+
prefix = ''
|
|
38
|
+
end
|
|
39
|
+
if entry.respond_to?(:short_help)
|
|
40
|
+
prefix += ' -- ' if prefix
|
|
41
|
+
@proc.msg(prefix + entry.short_help)
|
|
42
|
+
end
|
|
43
|
+
else
|
|
44
|
+
@proc.undefined_subcmd("help", subcmd_name)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Add subcmd to the available subcommands for this object.
|
|
49
|
+
# It will have the supplied docstring, and subcmd_cb will be called
|
|
50
|
+
# when we want to run the command. min_len is the minimum length
|
|
51
|
+
# allowed to abbreviate the command. in_list indicates with the
|
|
52
|
+
# show command will be run when giving a list of all sub commands
|
|
53
|
+
# of this object. Some commands have long output like "show commands"
|
|
54
|
+
# so we might not want to show that.
|
|
55
|
+
def add(subcmd_cb, subcmd_name=nil)
|
|
56
|
+
subcmd_name ||= subcmd_cb.name
|
|
57
|
+
@subcmds[subcmd_name] = subcmd_cb
|
|
58
|
+
|
|
59
|
+
# We keep a list of subcommands to assist command completion
|
|
60
|
+
@cmdlist << subcmd_name
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Run subcmd_name with args using obj for the environent
|
|
64
|
+
def run( subcmd_name, arg)
|
|
65
|
+
entry=lookup(subcmd_name)
|
|
66
|
+
if entry
|
|
67
|
+
entry['callback'].send(arg)
|
|
68
|
+
else
|
|
69
|
+
@proc.undefined_cmd(entry.__class__.name, subcmd_name)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# help for subcommands
|
|
74
|
+
# Note: format of help is compatible with ddd.
|
|
75
|
+
def help(*args)
|
|
76
|
+
|
|
77
|
+
msg args
|
|
78
|
+
subcmd_prefix = args[0]
|
|
79
|
+
if not subcmd_prefix or subcmd_prefix.size == 0
|
|
80
|
+
@proc.msg(self.doc)
|
|
81
|
+
@proc.msg("\nList of %s subcommands:\n" % [@name])
|
|
82
|
+
@list.each do |subcmd_name|
|
|
83
|
+
subcmd_helper(subcmd_name, obj, true, true)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
entry = lookup(subcmd_prefix)
|
|
87
|
+
if entry and entry.respond_to? :help
|
|
88
|
+
entry.help(args)
|
|
89
|
+
else
|
|
90
|
+
@proc.errmsg("Unknown 'help %s' subcommand %s" %
|
|
91
|
+
[@name, subcmd_prefix])
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def list
|
|
97
|
+
@subcmds.keys.sort
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Error message when a subcommand doesn't exist.
|
|
101
|
+
def undefined_subcmd(cmd, subcmd)
|
|
102
|
+
@proc.errmsg('Undefined "%s" command: "%s". Try "help".' %
|
|
103
|
+
[cmd, subcmd])
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# When invoked as main program, invoke the debugger on a script
|
|
109
|
+
if __FILE__ == $0
|
|
110
|
+
|
|
111
|
+
require_relative 'mock'
|
|
112
|
+
require_relative 'command/base/cmd'
|
|
113
|
+
|
|
114
|
+
class Trepan::TestCommand < Trepan::Command
|
|
115
|
+
|
|
116
|
+
HELP = 'Help string string for testing'
|
|
117
|
+
CATEGORY = 'data'
|
|
118
|
+
MIN_ARGS = 0
|
|
119
|
+
MAX_ARGS = 5
|
|
120
|
+
NAME_ALIASES = %w(test)
|
|
121
|
+
|
|
122
|
+
def initialize(proc); @proc = proc end
|
|
123
|
+
|
|
124
|
+
def run(args); puts 'test command run' end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
class TestTestingSubcommand
|
|
128
|
+
HELP = 'Help string for test testing subcommand'
|
|
129
|
+
|
|
130
|
+
def initialize; @name = 'testing' end
|
|
131
|
+
|
|
132
|
+
SHORT_HELP = 'This is short help for test testing'
|
|
133
|
+
MIN_ABREV = 4
|
|
134
|
+
IN_LIST = true
|
|
135
|
+
def run(args); puts 'test testing run' end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
d = MockDebugger::MockDebugger.new
|
|
139
|
+
testcmd = Trepan::TestCommand.new(nil)
|
|
140
|
+
# testcmd.debugger = d
|
|
141
|
+
testcmd.proc = d.core.processor
|
|
142
|
+
# testcmdMgr = Subcmd.new('test', testcmd)
|
|
143
|
+
# testsub = TestTestingSubcommand.new
|
|
144
|
+
# testcmdMgr.add(testsub)
|
|
145
|
+
|
|
146
|
+
# %w(tes test testing testing1).each do |prefix|
|
|
147
|
+
# x = testcmdMgr.lookup(prefix)
|
|
148
|
+
# puts x ? x.name : 'Non'
|
|
149
|
+
# end
|
|
150
|
+
|
|
151
|
+
# testcmdMgr.short_help(testcmd, 'testing')
|
|
152
|
+
# testcmdMgr.short_help(testcmd, 'test', true)
|
|
153
|
+
# testcmdMgr.short_help(testcmd, 'tes')
|
|
154
|
+
# puts testcmdMgr.list()
|
|
155
|
+
# testsub2 = TestTestingSubcommand.new
|
|
156
|
+
# testsub2.name = 'foobar'
|
|
157
|
+
# testcmdMgr.add(testsub2)
|
|
158
|
+
# puts testcmdMgr.list()
|
|
159
|
+
end
|