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
@@ -0,0 +1,101 @@
|
|
1
|
+
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
|
2
|
+
# For recording hook events in a buffer for review later. Make use of
|
3
|
+
# Trace::Buffer for this prupose.
|
4
|
+
|
5
|
+
require 'rubygems'; require 'require_relative'
|
6
|
+
require 'linecache'
|
7
|
+
require_relative '../app/eventbuffer'
|
8
|
+
require_relative 'virtual'
|
9
|
+
|
10
|
+
class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor
|
11
|
+
|
12
|
+
attr_reader :eventbuf
|
13
|
+
attr_reader :event_tracefilter
|
14
|
+
|
15
|
+
def eventbuf_initialize(size=100)
|
16
|
+
@eventbuf = Trace::EventBuffer.new(size)
|
17
|
+
# @event_tracefilter = Trace::Filter.new
|
18
|
+
end
|
19
|
+
|
20
|
+
# def event_processor(event, frame, arg=nil)
|
21
|
+
# @eventbuf.append(event, frame, arg)
|
22
|
+
# end
|
23
|
+
|
24
|
+
# Print event buffer entries from FROM up to TO try to stay within
|
25
|
+
# WIDTH. We show source lines only the first time they are
|
26
|
+
# encountered. Also we use separators to indicate points that the
|
27
|
+
# debugger has stopped at.
|
28
|
+
def eventbuf_print(from=nil, to=nil, width=80)
|
29
|
+
sep = '-' * ((width - 7) / 2)
|
30
|
+
last_container, last_location = nil, nil
|
31
|
+
if from == nil || !@eventbuf.marks[-1]
|
32
|
+
mark_index = 0
|
33
|
+
else
|
34
|
+
mark_index = @eventbuf.marks.size-1
|
35
|
+
translated_from = @eventbuf.zero_pos + from
|
36
|
+
@eventbuf.marks.each_with_index do
|
37
|
+
|m, i|
|
38
|
+
if m > translated_from
|
39
|
+
mark_index = [0, i-1].max
|
40
|
+
break
|
41
|
+
elsif m == translated_from
|
42
|
+
mark_index = i
|
43
|
+
break
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
nextmark = @eventbuf.marks[mark_index]
|
49
|
+
@eventbuf.each_with_index(from, to) do |e, i|
|
50
|
+
if nextmark
|
51
|
+
if nextmark == i
|
52
|
+
msg "#{sep} %5d #{sep}" % (mark_index - @eventbuf.marks.size)
|
53
|
+
mark_index += 1 if mark_index < @eventbuf.marks.size - 1
|
54
|
+
nextmark = @eventbuf.marks[mark_index]
|
55
|
+
elsif nextmark < i
|
56
|
+
mark_index += 1 if mark_index < @eventbuf.marks.size - 1
|
57
|
+
nextmark = @eventbuf.marks[mark_index]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
last_container, last_location, mess =
|
61
|
+
format_eventbuf_entry(e, last_container, last_location) if e
|
62
|
+
msg mess
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Show event buffer entry. If the location is the same as the previous
|
67
|
+
# location we don't show the duplicated location information.
|
68
|
+
def format_eventbuf_entry(item, last_container, last_location)
|
69
|
+
mess = format_location(item.event, item.frame, 0)
|
70
|
+
return nil, nil, mess
|
71
|
+
end
|
72
|
+
|
73
|
+
# FIXME: multiple hook mechanism needs work.
|
74
|
+
# def start_capture
|
75
|
+
# @event_tracefilter.add_trace_func(method(:event_processor).to_proc,
|
76
|
+
# Trace::DEFAULT_EVENT_MASK)
|
77
|
+
# end
|
78
|
+
|
79
|
+
# def stop_capture
|
80
|
+
# @event_tracefilter.set_trace_func(nil)
|
81
|
+
# end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
if __FILE__ == $0
|
86
|
+
# Demo it.
|
87
|
+
cmdproc = Trepan::CmdProcessor.new([])
|
88
|
+
cmdproc.eventbuf_initialize(5)
|
89
|
+
|
90
|
+
def cmdproc.msg(mess)
|
91
|
+
puts mess
|
92
|
+
end
|
93
|
+
# cmdproc.start_capture
|
94
|
+
# z=5
|
95
|
+
# z.times do |i|
|
96
|
+
# x = i
|
97
|
+
# y = x+2
|
98
|
+
# end
|
99
|
+
# cmdproc.stop_capture
|
100
|
+
cmdproc.eventbuf_print
|
101
|
+
end
|
data/processor/frame.rb
ADDED
@@ -0,0 +1,265 @@
|
|
1
|
+
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
|
2
|
+
require 'rubygems'; require 'require_relative'
|
3
|
+
require_relative '../app/complete'
|
4
|
+
require_relative '../app/frame'
|
5
|
+
require_relative '../app/util'
|
6
|
+
require_relative 'virtual'
|
7
|
+
class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor
|
8
|
+
|
9
|
+
include Trepan::Util
|
10
|
+
attr_reader :current_thread
|
11
|
+
|
12
|
+
# ThreadFrame, current frame
|
13
|
+
attr_accessor :frame
|
14
|
+
|
15
|
+
# frame index in a "backtrace" command
|
16
|
+
attr_accessor :frame_index
|
17
|
+
attr_reader :hide_level
|
18
|
+
|
19
|
+
# Hash[thread_id] -> FixNum, the level of the last frame to
|
20
|
+
# show. If we called the debugger directly, then there is
|
21
|
+
# generally a portion of a backtrace we don't want to show. We
|
22
|
+
# don't need to store this for all threads, just those we want to
|
23
|
+
# hide frame on. A value of 1 means to hide just the oldest
|
24
|
+
# level. The default or showing all levels is 0.
|
25
|
+
attr_accessor :hidelevels
|
26
|
+
|
27
|
+
# Hash[container] -> file container. This gives us a way to map non-file
|
28
|
+
# container objects to a file container for display.
|
29
|
+
attr_accessor :remap_container
|
30
|
+
|
31
|
+
attr_accessor :stack_size
|
32
|
+
|
33
|
+
# top frame of current thread.
|
34
|
+
attr_accessor :top_frame
|
35
|
+
# attr_reader :threads2frames # Hash[thread_id] -> top_frame
|
36
|
+
|
37
|
+
|
38
|
+
def adjust_frame(frame_num, absolute_pos)
|
39
|
+
frame, frame_num = get_frame(frame_num, absolute_pos)
|
40
|
+
if frame
|
41
|
+
@frame = @dbgr.frame(frame_num)
|
42
|
+
@frame_index = frame_num
|
43
|
+
unless @settings[:traceprint]
|
44
|
+
msg "--> #%d %s" % [frame_num,
|
45
|
+
@frame.describe(:show_ip => false,
|
46
|
+
:basename =>settings[:basename])]
|
47
|
+
print_location
|
48
|
+
end
|
49
|
+
@line_no = @frame.line
|
50
|
+
@frame
|
51
|
+
else
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def frame_low_high(direction)
|
57
|
+
if direction
|
58
|
+
low, high = [ @frame_index * -direction,
|
59
|
+
(@stack_size - 1 - @frame_index) * direction ]
|
60
|
+
low, high = [high, low] if direction < 0
|
61
|
+
[low, high]
|
62
|
+
else
|
63
|
+
[-@stack_size, @stack_size-1]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def frame_complete(prefix, direction)
|
68
|
+
low, high = frame_low_high(direction)
|
69
|
+
ary = (low..high).map{|i| i.to_s}
|
70
|
+
Trepan::Complete.complete_token(ary, prefix)
|
71
|
+
end
|
72
|
+
|
73
|
+
# def frame_container(frame, canonicalize=true)
|
74
|
+
# container =
|
75
|
+
# if @remap_container.member?(frame.source_container)
|
76
|
+
# @remap_container[frame.source_container]
|
77
|
+
# elsif frame.iseq && @remap_iseq.member?(frame.iseq.sha1)
|
78
|
+
# @remap_iseq[frame.iseq.sha1]
|
79
|
+
# else
|
80
|
+
# frame.source_container
|
81
|
+
# end
|
82
|
+
|
83
|
+
# container[1] = canonic_file(container[1]) if canonicalize
|
84
|
+
# container
|
85
|
+
# end
|
86
|
+
|
87
|
+
# Initializes the thread and frame variables: @frame, @top_frame,
|
88
|
+
# @frame_index, @current_thread, and @threads2frames
|
89
|
+
def frame_setup
|
90
|
+
@frame_index = 0
|
91
|
+
@frame = @top_frame = @dbgr.current_frame
|
92
|
+
@current_thread = @dbgr.debugee_thread
|
93
|
+
@line_no = @frame.line
|
94
|
+
|
95
|
+
@threads2frames ||= {}
|
96
|
+
@threads2frames[@current_thread] = @top_frame
|
97
|
+
set_hide_level
|
98
|
+
end
|
99
|
+
|
100
|
+
# Remove access to thread and frame variables
|
101
|
+
def frame_teardown
|
102
|
+
@top_frame = @frame = @frame_index = @current_thread = nil
|
103
|
+
@threads2frames = {}
|
104
|
+
end
|
105
|
+
|
106
|
+
def frame_initialize
|
107
|
+
@remap_container = {}
|
108
|
+
@remap_iseq = {}
|
109
|
+
@hidelevels = Hash.new(nil)
|
110
|
+
@hide_level = 0
|
111
|
+
end
|
112
|
+
|
113
|
+
def get_frame(frame_num, absolute_pos)
|
114
|
+
if absolute_pos
|
115
|
+
frame_num += @stack_size if frame_num < 0
|
116
|
+
else
|
117
|
+
frame_num += @frame_index
|
118
|
+
end
|
119
|
+
|
120
|
+
if frame_num < 0
|
121
|
+
errmsg('Adjusting would put us beyond the newest frame.')
|
122
|
+
return [nil, nil]
|
123
|
+
elsif frame_num >= @stack_size
|
124
|
+
errmsg('Adjusting would put us beyond the oldest frame.')
|
125
|
+
return [nil, nil]
|
126
|
+
end
|
127
|
+
|
128
|
+
[frame, frame_num]
|
129
|
+
end
|
130
|
+
|
131
|
+
def parent_frame
|
132
|
+
frame = @dbgr.frame(@frame.number + 1)
|
133
|
+
unless frame
|
134
|
+
errmsg "Unable to find parent frame at level #{@frame.number+1}"
|
135
|
+
return nil
|
136
|
+
end
|
137
|
+
frame
|
138
|
+
end
|
139
|
+
|
140
|
+
def print_stack_trace(frame=top_frame, opts={})
|
141
|
+
last_frame = nil
|
142
|
+
# TODO: handle indirect recursion.
|
143
|
+
direct_recursion_count = 0
|
144
|
+
count = opts[:count]
|
145
|
+
verbose = opts[:verbose]
|
146
|
+
|
147
|
+
dbgr.each_frame(frame) do |frame|
|
148
|
+
if count and frame.number >= count
|
149
|
+
msg "(More stack frames follow...)" if count != stack_size
|
150
|
+
return
|
151
|
+
end
|
152
|
+
if frame.location_equal(last_frame)
|
153
|
+
direct_recursion_count += 1
|
154
|
+
else
|
155
|
+
if direct_recursion_count > 0
|
156
|
+
msg("... above line repeated #{direct_recursion_count} times")
|
157
|
+
direct_recursion_count = 0
|
158
|
+
end
|
159
|
+
prefix = (frame == @frame) ? '-->' : ' '
|
160
|
+
|
161
|
+
### FIXME: Move into a method.
|
162
|
+
msg "%s #%d %s" % [prefix, frame.number,
|
163
|
+
frame.describe(:show_ip => verbose,
|
164
|
+
:basename => settings[:basename])]
|
165
|
+
if verbose
|
166
|
+
frame.local_variables.each do |local|
|
167
|
+
msg " #{local} = #{frame.run(local.to_s).inspect}"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
### End FIXME
|
171
|
+
|
172
|
+
end
|
173
|
+
last_frame = frame
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def set_hide_level
|
178
|
+
max_stack_size = @dbgr.vm_locations.size
|
179
|
+
@hide_level =
|
180
|
+
if !@settings[:hidelevel] || @settings[:hidelevel] < 0
|
181
|
+
@settings[:hidelevel] = @hidelevels[@current_thread] =
|
182
|
+
find_main_script(@dbgr.vm_locations) || max_stack_size
|
183
|
+
else
|
184
|
+
@settings[:hidelevel]
|
185
|
+
end
|
186
|
+
@stack_size = if @hide_level >= max_stack_size
|
187
|
+
max_stack_size else max_stack_size - @hide_level
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# def get_nonsync_frame(tf)
|
192
|
+
# if (tf.stack_size > 10)
|
193
|
+
# check_frames = (0..5).map{|i| tf.prev(i).method}
|
194
|
+
# if check_frames ==
|
195
|
+
# %w(synchronize event_processor IFUNC call trace_hook IFUNC)
|
196
|
+
# return tf.prev(6)
|
197
|
+
# end
|
198
|
+
# end
|
199
|
+
# tf
|
200
|
+
# end
|
201
|
+
|
202
|
+
# def get_frame_from_thread(th)
|
203
|
+
# if th == Thread.current
|
204
|
+
# @threads2frames[th]
|
205
|
+
# else
|
206
|
+
# # FIXME: Check to see if we are blocked on entry to debugger.
|
207
|
+
# # If so, walk back frames.
|
208
|
+
# tf = get_nonsync_frame(th.threadframe)
|
209
|
+
# @threads2frames = tf
|
210
|
+
# end
|
211
|
+
# end
|
212
|
+
|
213
|
+
# # The dance we have to do to set debugger frame state to
|
214
|
+
# # `frame', which is in the thread with id `thread_id'. We may
|
215
|
+
# # need to the hide initial debugger frames.
|
216
|
+
# def find_and_set_debugged_frame(th, position)
|
217
|
+
|
218
|
+
# thread = threading._active[thread_id]
|
219
|
+
# thread_name = thread.getName()
|
220
|
+
# if (!@settings['dbg_pydbgr'] &&
|
221
|
+
# thread_name == Mthread.current_thread_name())
|
222
|
+
# # The frame we came in on ('current_thread_name') is
|
223
|
+
# # the same as the one we want to switch to. In this case
|
224
|
+
# # we need to some debugger frames are in this stack so
|
225
|
+
# # we need to remove them.
|
226
|
+
# newframe = Mthread.find_debugged_frame(frame)
|
227
|
+
# frame = newframe unless newframe
|
228
|
+
# end
|
229
|
+
# ## FIXME: else: we might be blocked on other threads which are
|
230
|
+
# # about to go into the debugger it not for the fact this one got there
|
231
|
+
# # first. Possibly in the future we want
|
232
|
+
# # to hide the blocks into threading of that locking code as well.
|
233
|
+
|
234
|
+
# # Set stack to new frame
|
235
|
+
# @frame, @curindex = Mcmdproc.get_stack(frame, nil, self.proc)
|
236
|
+
# @proc.stack, @proc.curindex = self.stack, self.curindex
|
237
|
+
|
238
|
+
# # @frame_thread_name = thread_name
|
239
|
+
# end
|
240
|
+
end
|
241
|
+
|
242
|
+
if __FILE__ == $0
|
243
|
+
# Demo it.
|
244
|
+
class Trepan::CmdProcessor
|
245
|
+
def print_location
|
246
|
+
puts "frame location: #{frame.file} #{frame.line}"
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
require_relative './mock'
|
251
|
+
dbgr, cmd = MockDebugger::setup('exit', false)
|
252
|
+
# require_relative '../lib/trepanning'
|
253
|
+
# Trepan.start(:set_restart => true)
|
254
|
+
proc = cmd.proc
|
255
|
+
0.upto(proc.stack_size-1) { |i| proc.adjust_frame(i, true) }
|
256
|
+
puts '*' * 10
|
257
|
+
proc.adjust_frame(-1, true)
|
258
|
+
proc.adjust_frame(0, true)
|
259
|
+
puts '*' * 10
|
260
|
+
proc.stack_size.times { proc.adjust_frame(1, false) }
|
261
|
+
puts '*' * 10
|
262
|
+
proc.adjust_frame(proc.stack_size-1, true)
|
263
|
+
proc.stack_size.times { proc.adjust_frame(-1, false) }
|
264
|
+
|
265
|
+
end
|
data/processor/help.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
|
2
|
+
|
3
|
+
class Trepan
|
4
|
+
# class SubHelp
|
5
|
+
# def initialize(name, dir)
|
6
|
+
# @name = name
|
7
|
+
# @dir = dir
|
8
|
+
# load_sub_help_files(dir)
|
9
|
+
# end
|
10
|
+
|
11
|
+
# def load_sub_help_files(dir)
|
12
|
+
# Dir.glob(dir, '*.txt').each do |txt|
|
13
|
+
# basename = File.basename(txt, '.txt')
|
14
|
+
# @list << basename
|
15
|
+
# end
|
16
|
+
# end if File.directory?(dir)
|
17
|
+
|
18
|
+
# def summary_help
|
19
|
+
# section "List of #{@name} help"
|
20
|
+
# msg @list
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
|
24
|
+
module Help
|
25
|
+
|
26
|
+
def abbrev_stringify(name, min_abbrev)
|
27
|
+
"(#{name[0..min_abbrev-1]})#{name[min_abbrev..-1]}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def summary_help(subcmd)
|
31
|
+
# Set class constant SHORT_HELP to be the first line of HELP
|
32
|
+
# unless it has been defined in the class already.
|
33
|
+
# The below was the simplest way I could find to do this since
|
34
|
+
# we are the super class but want to set the subclass's constant.
|
35
|
+
# defined? didn't seem to work here.
|
36
|
+
c = subcmd.class.constants
|
37
|
+
if c.member?('HELP') and !c.member?('SHORT_HELP')
|
38
|
+
short_help = subcmd.class.const_get('HELP').split("\n")[0].chomp('.')
|
39
|
+
subcmd.class.const_set(:SHORT_HELP, short_help)
|
40
|
+
end
|
41
|
+
|
42
|
+
' %-12s -- %s' %
|
43
|
+
[abbrev_stringify(obj_const(subcmd, :NAME),
|
44
|
+
obj_const(subcmd, :MIN_ABBREV)),
|
45
|
+
obj_const(subcmd, :SHORT_HELP)]
|
46
|
+
end
|
47
|
+
|
48
|
+
# We were given cmd without a subcommand; cmd is something
|
49
|
+
# like "show", "info" or "set". Generally this means list
|
50
|
+
# all of the subcommands.
|
51
|
+
def summary_list(name, subcmds)
|
52
|
+
section "List of #{name} commands (with minimum abbreviation in parenthesis):"
|
53
|
+
subcmds.list.each do |subcmd_name|
|
54
|
+
# Some commands have lots of output.
|
55
|
+
# they are excluded here because 'in_list' is false.
|
56
|
+
msg summary_help(subcmds.subcmds[subcmd_name])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
# Error message when subcommand asked for but doesn't exist
|
62
|
+
def undefined_subcmd(cmd, subcmd)
|
63
|
+
ambig = settings[:abbrev] ? 'or ambiguous ' : ''
|
64
|
+
errmsg(['Undefined %s"%s" subcommand: "%s". ' % [ambig, cmd, subcmd],
|
65
|
+
'Try "help %s *".' % cmd])
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
if __FILE__ == $0
|
72
|
+
class TestClass
|
73
|
+
include Trepan::Help
|
74
|
+
HELP = 'TestClass HELP.
|
75
|
+
|
76
|
+
Long description goes here.'
|
77
|
+
MIN_ABBREV = 1
|
78
|
+
NAME = File.basename(__FILE__)
|
79
|
+
def obj_const(obj, name)
|
80
|
+
obj.class.const_get(name)
|
81
|
+
end
|
82
|
+
def msg(mess)
|
83
|
+
puts mess
|
84
|
+
end
|
85
|
+
def errmsg(mess)
|
86
|
+
puts "***#{mess}"
|
87
|
+
end
|
88
|
+
def initialize
|
89
|
+
puts summary_help(self)
|
90
|
+
undefined_subcmd('foo', 'bar')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
TestClass.new
|
94
|
+
end
|
data/processor/hook.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
|
2
|
+
require 'rubygems'; require 'require_relative'
|
3
|
+
require_relative 'virtual'
|
4
|
+
|
5
|
+
class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor
|
6
|
+
# Command processor hooks.
|
7
|
+
attr_reader :autodis_hook
|
8
|
+
attr_reader :autoirb_hook
|
9
|
+
attr_reader :autolist_hook
|
10
|
+
attr_reader :debug_dbgr_hook
|
11
|
+
attr_reader :display_hook
|
12
|
+
attr_reader :timer_hook
|
13
|
+
attr_reader :trace_hook
|
14
|
+
attr_reader :tracebuf_hook
|
15
|
+
attr_reader :unconditional_prehooks
|
16
|
+
attr_reader :cmdloop_posthooks
|
17
|
+
attr_reader :cmdloop_prehooks
|
18
|
+
|
19
|
+
# Used to time how long a debugger action takes
|
20
|
+
attr_accessor :time_last
|
21
|
+
|
22
|
+
class Hook
|
23
|
+
attr_accessor :list
|
24
|
+
|
25
|
+
def initialize(list=[])
|
26
|
+
@list = list
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete_by_name(delete_name)
|
30
|
+
@list.delete_if {|hook_name, priority, hook| hook_name == delete_name}
|
31
|
+
end
|
32
|
+
|
33
|
+
def empty?
|
34
|
+
@list.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
def insert(priority, name, hook)
|
38
|
+
insert_loc = @list.size # at end
|
39
|
+
@list.each_with_index do |entry, index|
|
40
|
+
n, p, h = entry
|
41
|
+
if priority > p
|
42
|
+
insert_loc = index
|
43
|
+
break
|
44
|
+
end
|
45
|
+
end
|
46
|
+
@list.insert(insert_loc, [name, priority, hook])
|
47
|
+
end
|
48
|
+
|
49
|
+
def insert_if_new(priority, name, hook)
|
50
|
+
insert(priority, name, hook) unless
|
51
|
+
@list.find {|try_name, try_priority, try_hook| try_name == name}
|
52
|
+
end
|
53
|
+
|
54
|
+
# Run each function in `hooks' with args
|
55
|
+
def run(*args)
|
56
|
+
@list.each do |name, priority, hook|
|
57
|
+
hook.call(name, *args)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Could add delete_at and delete if necessary.
|
62
|
+
end
|
63
|
+
|
64
|
+
def hook_initialize(commands)
|
65
|
+
@cmdloop_posthooks = Hook.new
|
66
|
+
@cmdloop_prehooks = Hook.new
|
67
|
+
@unconditional_prehooks = Hook.new
|
68
|
+
|
69
|
+
irb_cmd = commands['shell']
|
70
|
+
@autoirb_hook = ['autoirb',
|
71
|
+
Proc.new{|*args| irb_cmd.run(['shell']) if irb_cmd}]
|
72
|
+
|
73
|
+
@debug_dbgr_hook = ['dbgdbgr',
|
74
|
+
Proc.new{|*args|
|
75
|
+
if settings[:debugdbgr]
|
76
|
+
$trepan_cmdproc = self
|
77
|
+
$trepan_frame = @frame
|
78
|
+
else
|
79
|
+
$trepan_cmdproc = nil
|
80
|
+
$trepan_frame = nil
|
81
|
+
end}]
|
82
|
+
|
83
|
+
display_cmd = commands['display']
|
84
|
+
@display_hook = ['display',
|
85
|
+
Proc.new{|*args| display_cmd.run(['display']) if display_cmd}]
|
86
|
+
|
87
|
+
# FIXME: generalize for any command run
|
88
|
+
dis_cmd = commands['disassemble']
|
89
|
+
@autodis_hook = ['autodis',
|
90
|
+
Proc.new{|*args| dis_cmd.run(['disassemble']) if dis_cmd}]
|
91
|
+
|
92
|
+
list_cmd = commands['list']
|
93
|
+
@autolist_hook = ['autolist',
|
94
|
+
Proc.new{|*args| list_cmd.run(['list']) if list_cmd}]
|
95
|
+
|
96
|
+
@timer_hook = ['timer',
|
97
|
+
Proc.new{|*args|
|
98
|
+
now = Time.now
|
99
|
+
msg("%g seconds" %
|
100
|
+
(now - @time_last)) if @time_last
|
101
|
+
@time_last = now
|
102
|
+
}]
|
103
|
+
@timer_posthook = ['timer', Proc.new{|*args| @time_last = Time.now}]
|
104
|
+
@trace_hook = ['trace',
|
105
|
+
Proc.new{|*args| print_location}]
|
106
|
+
@tracebuf_hook = ['tracebuffer',
|
107
|
+
Proc.new{|*args| @eventbuf.append(@event, @frame,
|
108
|
+
nil)}]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
if __FILE__ == $0
|
113
|
+
# Demo it.
|
114
|
+
hooks = Trepan::CmdProcessor::Hook.new
|
115
|
+
hooks.run(5)
|
116
|
+
hook1 = Proc.new {|name, a| puts "#{name} called with #{a}"}
|
117
|
+
hooks = Trepan::CmdProcessor::Hook.new()
|
118
|
+
hooks.insert(-1, 'hook1', hook1)
|
119
|
+
p hooks.list
|
120
|
+
hooks.insert_if_new(-1, 'hook1', hook1)
|
121
|
+
puts '-' * 30
|
122
|
+
p hooks.list
|
123
|
+
hooks.run(10)
|
124
|
+
puts '-' * 30
|
125
|
+
hooks.insert(-1, 'hook2', hook1)
|
126
|
+
hooks.run(20)
|
127
|
+
puts '-' * 30
|
128
|
+
hooks.delete_by_name('hook2')
|
129
|
+
hooks.run(30)
|
130
|
+
puts '-' * 30
|
131
|
+
hooks.delete_by_name('hook1')
|
132
|
+
hooks.run(30)
|
133
|
+
puts '-' * 30
|
134
|
+
end
|