rbx-trepanning 0.0.1-universal-rubinius

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. data/ChangeLog +376 -0
  2. data/LICENSE +25 -0
  3. data/NEWS +2 -0
  4. data/README.textile +28 -0
  5. data/Rakefile +165 -0
  6. data/THANKS +14 -0
  7. data/app/breakpoint.rb +218 -0
  8. data/app/breakpoint.rbc +3564 -0
  9. data/app/brkptmgr.rb +138 -0
  10. data/app/brkptmgr.rbc +2827 -0
  11. data/app/default.rb +61 -0
  12. data/app/default.rbc +1011 -0
  13. data/app/display.rb +35 -0
  14. data/app/display.rbc +968 -0
  15. data/app/frame.rb +98 -0
  16. data/app/frame.rbc +1808 -0
  17. data/app/irb.rb +112 -0
  18. data/app/irb.rbc +2111 -0
  19. data/app/iseq.rb +95 -0
  20. data/app/iseq.rbc +1801 -0
  21. data/app/method.rb +173 -0
  22. data/app/method.rbc +2492 -0
  23. data/app/mock.rb +13 -0
  24. data/app/mock.rbc +398 -0
  25. data/app/options.rb +123 -0
  26. data/app/options.rbc +2183 -0
  27. data/app/run.rb +86 -0
  28. data/app/run.rbc +1244 -0
  29. data/app/util.rb +49 -0
  30. data/app/util.rbc +1144 -0
  31. data/app/validate.rb +30 -0
  32. data/app/validate.rbc +676 -0
  33. data/bin/trepan.compiled.rbc +1043 -0
  34. data/bin/trepanx +63 -0
  35. data/bin/trepanx.compiled.rbc +985 -0
  36. data/interface/base_intf.rb +95 -0
  37. data/interface/base_intf.rbc +1742 -0
  38. data/interface/script.rb +104 -0
  39. data/interface/script.rbc +1642 -0
  40. data/interface/user.rb +91 -0
  41. data/interface/user.rbc +1418 -0
  42. data/io/base_io.rb +94 -0
  43. data/io/base_io.rbc +1404 -0
  44. data/io/input.rb +112 -0
  45. data/io/input.rbc +1979 -0
  46. data/io/null_output.rb +42 -0
  47. data/io/null_output.rbc +730 -0
  48. data/io/string_array.rb +156 -0
  49. data/io/string_array.rbc +2466 -0
  50. data/lib/trepanning.rb +398 -0
  51. data/lib/trepanning.rbc +6661 -0
  52. data/processor/breakpoint.rb +161 -0
  53. data/processor/command/alias.rb +55 -0
  54. data/processor/command/backtrace.rb +46 -0
  55. data/processor/command/base/cmd.rb +124 -0
  56. data/processor/command/base/subcmd.rb +213 -0
  57. data/processor/command/base/submgr.rb +179 -0
  58. data/processor/command/base/subsubcmd.rb +103 -0
  59. data/processor/command/base/subsubmgr.rb +184 -0
  60. data/processor/command/break.rb +100 -0
  61. data/processor/command/continue.rb +82 -0
  62. data/processor/command/delete.rb +30 -0
  63. data/processor/command/directory.rb +43 -0
  64. data/processor/command/disassemble.rb +103 -0
  65. data/processor/command/down.rb +54 -0
  66. data/processor/command/eval.rb +31 -0
  67. data/processor/command/exit.rb +58 -0
  68. data/processor/command/finish.rb +78 -0
  69. data/processor/command/frame.rb +89 -0
  70. data/processor/command/help.rb +146 -0
  71. data/processor/command/info.rb +28 -0
  72. data/processor/command/info_subcmd/breakpoints.rb +75 -0
  73. data/processor/command/info_subcmd/file.rb +153 -0
  74. data/processor/command/info_subcmd/method.rb +71 -0
  75. data/processor/command/info_subcmd/program.rb +59 -0
  76. data/processor/command/info_subcmd/variables.rb +40 -0
  77. data/processor/command/irb.rb +96 -0
  78. data/processor/command/kill.rb +70 -0
  79. data/processor/command/list.rb +296 -0
  80. data/processor/command/next.rb +66 -0
  81. data/processor/command/nexti.rb +59 -0
  82. data/processor/command/pr.rb +38 -0
  83. data/processor/command/ps.rb +40 -0
  84. data/processor/command/restart.rb +60 -0
  85. data/processor/command/set.rb +47 -0
  86. data/processor/command/set_subcmd/auto.rb +28 -0
  87. data/processor/command/set_subcmd/auto_subcmd/dis.rb +33 -0
  88. data/processor/command/set_subcmd/auto_subcmd/eval.rb +54 -0
  89. data/processor/command/set_subcmd/auto_subcmd/irb.rb +34 -0
  90. data/processor/command/set_subcmd/auto_subcmd/list.rb +34 -0
  91. data/processor/command/set_subcmd/basename.rb +26 -0
  92. data/processor/command/set_subcmd/debug.rb +27 -0
  93. data/processor/command/set_subcmd/debug_subcmd/dbgr.rb +36 -0
  94. data/processor/command/set_subcmd/debug_subcmd/skip.rb +23 -0
  95. data/processor/command/set_subcmd/debug_subcmd/step.rb +23 -0
  96. data/processor/command/set_subcmd/different.rb +60 -0
  97. data/processor/command/set_subcmd/hidelevel.rb +63 -0
  98. data/processor/command/set_subcmd/kernelstep.rb +61 -0
  99. data/processor/command/set_subcmd/max.rb +29 -0
  100. data/processor/command/set_subcmd/max_subcmd/list.rb +49 -0
  101. data/processor/command/set_subcmd/max_subcmd/stack.rb +50 -0
  102. data/processor/command/set_subcmd/max_subcmd/string.rb +54 -0
  103. data/processor/command/set_subcmd/max_subcmd/width.rb +49 -0
  104. data/processor/command/set_subcmd/substitute.rb +25 -0
  105. data/processor/command/set_subcmd/substitute_subcmd/path.rb +56 -0
  106. data/processor/command/set_subcmd/trace.rb +37 -0
  107. data/processor/command/set_subcmd/trace_subcmd/print.rb +57 -0
  108. data/processor/command/show.rb +27 -0
  109. data/processor/command/show_subcmd/alias.rb +43 -0
  110. data/processor/command/show_subcmd/args.rb +26 -0
  111. data/processor/command/show_subcmd/auto.rb +28 -0
  112. data/processor/command/show_subcmd/auto_subcmd/dis.rb +37 -0
  113. data/processor/command/show_subcmd/auto_subcmd/eval.rb +28 -0
  114. data/processor/command/show_subcmd/auto_subcmd/irb.rb +23 -0
  115. data/processor/command/show_subcmd/auto_subcmd/list.rb +22 -0
  116. data/processor/command/show_subcmd/basename.rb +22 -0
  117. data/processor/command/show_subcmd/debug.rb +27 -0
  118. data/processor/command/show_subcmd/debug_subcmd/dbgr.rb +21 -0
  119. data/processor/command/show_subcmd/debug_subcmd/skip.rb +22 -0
  120. data/processor/command/show_subcmd/debug_subcmd/step.rb +22 -0
  121. data/processor/command/show_subcmd/different.rb +27 -0
  122. data/processor/command/show_subcmd/hidelevel.rb +42 -0
  123. data/processor/command/show_subcmd/kernelstep.rb +37 -0
  124. data/processor/command/show_subcmd/max.rb +30 -0
  125. data/processor/command/show_subcmd/max_subcmd/list.rb +38 -0
  126. data/processor/command/show_subcmd/max_subcmd/stack.rb +36 -0
  127. data/processor/command/show_subcmd/max_subcmd/string.rb +42 -0
  128. data/processor/command/show_subcmd/max_subcmd/width.rb +37 -0
  129. data/processor/command/show_subcmd/trace.rb +29 -0
  130. data/processor/command/show_subcmd/trace_subcmd/print.rb +38 -0
  131. data/processor/command/source.rb +83 -0
  132. data/processor/command/step.rb +41 -0
  133. data/processor/command/tbreak.rb +19 -0
  134. data/processor/command/unalias.rb +44 -0
  135. data/processor/command/up.rb +87 -0
  136. data/processor/default.rb +56 -0
  137. data/processor/disassemble.rb +32 -0
  138. data/processor/eval.rb +96 -0
  139. data/processor/frame.rb +211 -0
  140. data/processor/help.rb +72 -0
  141. data/processor/hook.rb +133 -0
  142. data/processor/load_cmds.rb +101 -0
  143. data/processor/location.rb +128 -0
  144. data/processor/main.rb +394 -0
  145. data/processor/mock.rb +137 -0
  146. data/processor/msg.rb +28 -0
  147. data/processor/running.rb +230 -0
  148. data/processor/stepping.rb +115 -0
  149. data/processor/subcmd.rb +160 -0
  150. data/processor/validate.rb +355 -0
  151. data/test/data/enable.right +36 -0
  152. data/test/data/fname-with-blank.cmd +6 -0
  153. data/test/data/fname-with-blank.right +1 -0
  154. data/test/data/quit-Xdebug.right +3 -0
  155. data/test/data/quit.cmd +5 -0
  156. data/test/data/quit.right +0 -0
  157. data/test/example/fname with blank.rb +1 -0
  158. data/test/example/gcd-xx.rb +18 -0
  159. data/test/example/gcd.rb +19 -0
  160. data/test/example/gcd1.rb +24 -0
  161. data/test/example/null.rb +1 -0
  162. data/test/example/thread1.rb +3 -0
  163. data/test/functional/fn_helper.rb +112 -0
  164. data/test/functional/test-break-name.rb +52 -0
  165. data/test/functional/test-break.rb +51 -0
  166. data/test/functional/test-finish.rb +70 -0
  167. data/test/functional/test-fn_helper.rb +43 -0
  168. data/test/functional/test-list.rb +55 -0
  169. data/test/functional/test-next-bug.rb +49 -0
  170. data/test/functional/test-next.rb +101 -0
  171. data/test/functional/test-step.rb +272 -0
  172. data/test/functional/test-step2.rb +35 -0
  173. data/test/functional/test-tbreak.rb +41 -0
  174. data/test/integration/file-diff.rb +89 -0
  175. data/test/integration/helper.rb +78 -0
  176. data/test/integration/test-fname-with-blank.rb +12 -0
  177. data/test/integration/test-quit.rb +25 -0
  178. data/test/unit/cmd-helper.rb +46 -0
  179. data/test/unit/test-app-brkpt.rb +30 -0
  180. data/test/unit/test-app-brkptmgr.rb +51 -0
  181. data/test/unit/test-app-iseq.rb +49 -0
  182. data/test/unit/test-app-method.rb +54 -0
  183. data/test/unit/test-app-options.rb +61 -0
  184. data/test/unit/test-app-run.rb +16 -0
  185. data/test/unit/test-app-util.rb +28 -0
  186. data/test/unit/test-app-validate.rb +18 -0
  187. data/test/unit/test-base-subcmd.rb +61 -0
  188. data/test/unit/test-bin-trepanx.rb +48 -0
  189. data/test/unit/test-cmd-alias.rb +49 -0
  190. data/test/unit/test-cmd-break.rb +23 -0
  191. data/test/unit/test-cmd-exit.rb +27 -0
  192. data/test/unit/test-cmd-help.rb +101 -0
  193. data/test/unit/test-cmd-kill.rb +48 -0
  194. data/test/unit/test-intf-user.rb +46 -0
  195. data/test/unit/test-io-input.rb +27 -0
  196. data/test/unit/test-proc-eval.rb +37 -0
  197. data/test/unit/test-proc-frame.rb +79 -0
  198. data/test/unit/test-proc-help.rb +16 -0
  199. data/test/unit/test-proc-hook.rb +30 -0
  200. data/test/unit/test-proc-load_cmds.rb +41 -0
  201. data/test/unit/test-proc-location.rb +48 -0
  202. data/test/unit/test-proc-main.rb +96 -0
  203. data/test/unit/test-proc-validate.rb +91 -0
  204. data/test/unit/test-subcmd-help.rb +51 -0
  205. metadata +337 -0
@@ -0,0 +1,75 @@
1
+ require 'rubygems'; require 'require_relative'
2
+ require_relative '../base/subcmd'
3
+
4
+ class Trepan::Subcommand::InfoBreakpoints < Trepan::Subcommand
5
+ HELP = <<-EOH
6
+ info breakpoints [num1 ...] [verbose]
7
+
8
+ Show status of user-settable breakpoints. If no breakpoint numbers are
9
+ given, the show all breakpoints. Otherwise only those breakpoints
10
+ listed are shown and the order given. If VERBOSE is given, more
11
+ information provided about each breakpoint.
12
+
13
+ The "Disp" column contains one of "keep", "del", the disposition of
14
+ the breakpoint after it gets hit.
15
+
16
+ The "enb" column indicates whether the breakpoint is enabled.
17
+
18
+ The "Where" column indicates where the breakpoint is located.
19
+ EOH
20
+ MIN_ABBREV = 'br'.size
21
+ NAME = File.basename(__FILE__, '.rb')
22
+ PREFIX = %w(info breakpoints)
23
+ SHORT_HELP = 'Status of user-settable breakpoints'
24
+
25
+ def run(args)
26
+ # FIXME: Originally was
27
+ # section "Breakpoints"
28
+ # Add section?
29
+
30
+ show_all =
31
+ if args.size > 2
32
+ opts = {
33
+ :msg_on_error =>
34
+ "An '#{PREFIX.join(' ')}' argument must eval to a breakpoint between 1..#{@proc.brkpts.max}.",
35
+ :min_value => 1,
36
+ :max_value => @proc.brkpts.max
37
+ }
38
+ bp_nums = @proc.get_int_list(args[2..-1])
39
+ false
40
+ else
41
+ true
42
+ end
43
+
44
+ bpmgr = @proc.brkpts
45
+ if bpmgr.empty? && @proc.dbgr.deferred_breakpoints.empty?
46
+ msg('No breakpoints.')
47
+ else
48
+ # There's at least one
49
+ bpmgr.list.each do |bp|
50
+ msg "%3d: %s" % [bp.id, bp.describe]
51
+ end
52
+ msg('Deferred breakpoints...')
53
+ @proc.dbgr.deferred_breakpoints.each_with_index do |bp, i|
54
+ if bp
55
+ msg "%3d: %s" % [i+1, bp.describe]
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ if __FILE__ == $0
63
+ # Demo it.
64
+ require_relative '../../mock'
65
+ name = File.basename(__FILE__, '.rb')
66
+ dbgr, cmd = MockDebugger::setup('info')
67
+ subcommand = Trepan::Subcommand::InfoBreakpoints.new(cmd)
68
+
69
+ puts '-' * 20
70
+ subcommand.run(%w(info break))
71
+ puts '-' * 20
72
+ subcommand.summary_help(name)
73
+ puts
74
+ puts '-' * 20
75
+ end
@@ -0,0 +1,153 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require 'linecache'
5
+ require_relative '../base/subcmd'
6
+
7
+ class Trepan::Subcommand::InfoFile < Trepan::Subcommand
8
+ unless defined?(HELP)
9
+ DEFAULT_FILE_ARGS = %w(size sha1)
10
+
11
+ HELP =
12
+ "info file [{FILENAME|.} [all | brkpts | sha1 | size | stat]]
13
+
14
+ Show information about the current file. If no filename is given and
15
+ the program is running then the current file associated with the
16
+ current stack entry is used. Sub options which can be shown about a file are:
17
+
18
+ brkpts -- Line numbers where there are statement boundaries.
19
+ These lines can be used in breakpoint commands.
20
+ sha1 -- A SHA1 hash of the source text. This may be useful in comparing
21
+ source code.
22
+ size -- The number of lines in the file.
23
+ stat -- File.stat information
24
+
25
+ all -- All of the above information.
26
+
27
+ If no sub-options are given #{DEFAULT_FILE_ARGS.join(' ')} are assumed.
28
+ "
29
+ MIN_ABBREV = 'fi'.size # Note we have "info frame"
30
+ NAME = File.basename(__FILE__, '.rb')
31
+ NEED_STACK = false
32
+ PREFIX = %w(info file)
33
+ end
34
+
35
+ # Get file information
36
+ def run(args)
37
+ return if args.size < 2
38
+ args << '.' if 2 == args.size
39
+ filename =
40
+ if '.' == args[2]
41
+ if not @proc.frame
42
+ errmsg("No frame - no default file.")
43
+ return false
44
+ nil
45
+ else
46
+ File.expand_path(@proc.frame.file)
47
+ end
48
+ else
49
+ args[2]
50
+ end
51
+ args += DEFAULT_FILE_ARGS if args.size == 3
52
+
53
+ m = filename + ' is'
54
+ canonic_name = LineCache::map_file(filename)
55
+ if LineCache::cached?(canonic_name)
56
+ m += " cached in debugger"
57
+ if canonic_name != filename
58
+ m += (' as:' + canonic_name)
59
+ end
60
+ m += '.'
61
+ msg(m)
62
+ # elsif !(matches = find_scripts(filename)).empty?
63
+ # if (matches.size > 1)
64
+ # msg("Multiple files found:")
65
+ # matches.each { |filename| msg("\t%s" % filename) }
66
+ # return
67
+ # else
68
+ # msg('File "%s" just now cached.' % filename)
69
+ # LineCache::cache(matches[0])
70
+ # LineCache::remap_file(matches[0], filename)
71
+ # canonic_name = matches[0]
72
+ # end
73
+ else
74
+ msg(m + ' not cached in debugger.')
75
+ return
76
+ end
77
+ seen = {}
78
+ args[3..-1].each do |arg|
79
+ processed_arg = false
80
+
81
+ if %w(all size).member?(arg)
82
+ unless seen[:size]
83
+ max_line = LineCache::size(canonic_name)
84
+ msg "File has %d lines." % max_line if max_line
85
+ end
86
+ processed_arg = seen[:size] = true
87
+ end
88
+
89
+ if %w(all sha1).member?(arg)
90
+ unless seen[:sha1]
91
+ msg("SHA1 is %s." % LineCache::sha1(canonic_name))
92
+ end
93
+ processed_arg = seen[:sha1] = true
94
+ end
95
+
96
+ if %w(all brkpts).member?(arg)
97
+ unless seen[:brkpts]
98
+ msg("Possible breakpoint line numbers:")
99
+ lines = LineCache::trace_line_numbers(canonic_name)
100
+ fmt_lines = columnize_numbers(lines)
101
+ msg(fmt_lines)
102
+ end
103
+ processed_arg = seen[:brkpts] = true
104
+ end
105
+
106
+ # if %w(all iseq).member?(arg)
107
+ # unless seen[:iseq]
108
+ # if SCRIPT_ISEQS__.member?(canonic_name)
109
+ # msg("File contains instruction sequences:")
110
+ # SCRIPT_ISEQS__[canonic_name].each do |iseq|
111
+ # msg("\t %s %s" % [iseq, iseq.name.inspect])
112
+ # end
113
+ # else
114
+ # msg("Instruction sequences not recorded; there may be some, though.")
115
+ # end
116
+ # end
117
+ # processed_arg = seen[:iseq] = true
118
+ # end
119
+
120
+ if %w(all stat).member?(arg)
121
+ unless seen[:stat]
122
+ msg("Stat info:\n\t%s." % LineCache::stat(canonic_name).inspect)
123
+ end
124
+ processed_arg = seen[:stat] = true
125
+ end
126
+
127
+ if not processed_arg
128
+ errmsg("I don't understand sub-option \"%s\"." % arg)
129
+ end
130
+ end unless args.empty?
131
+ end
132
+ end
133
+
134
+ if __FILE__ == $0
135
+ require_relative '../../mock'
136
+ require_relative '../../subcmd'
137
+ name = File.basename(__FILE__, '.rb')
138
+ # FIXME: DRY the below code
139
+ dbgr, cmd = MockDebugger::setup('info')
140
+ subcommand = Trepan::Subcommand::InfoFile.new(cmd)
141
+ testcmdMgr = Trepan::Subcmd.new(subcommand)
142
+ LineCache::cache(__FILE__)
143
+
144
+ [%w(info file nothere),
145
+ %w(info file .),
146
+ %w(info file),
147
+ %w(info file file.rb),
148
+ %w(info file . all),
149
+ %w(info file . lines size sha1 sha1)].each do |args|
150
+ subcommand.run(args)
151
+ puts '-' * 40
152
+ end
153
+ end
@@ -0,0 +1,71 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative '../base/subcmd'
5
+
6
+ class Trepan::Subcommand::InfoMethod < Trepan::Subcommand
7
+ unless defined?(HELP)
8
+ HELP =
9
+ 'info [METHOD|.]
10
+
11
+ Show information about a method.
12
+
13
+ Examples:
14
+ info method
15
+ info method .
16
+ info method require_relative
17
+ '
18
+ MIN_ABBREV = 'me'.size
19
+ NAME = File.basename(__FILE__, '.rb')
20
+ NEED_STACK = true
21
+ PREFIX = %w(info method)
22
+ SHORT_HELP = 'Information about a (compiled) method'
23
+ end
24
+
25
+ def run(args)
26
+ if args.size <= 2
27
+ method_name = '.'
28
+ else
29
+ method_name = args[2]
30
+ end
31
+ if '.' == method_name
32
+ meth = @proc.frame.method
33
+ # elsif ...
34
+ # # FIXME: do something if there is more than one
35
+ else
36
+ meth = nil
37
+ end
38
+
39
+ if meth
40
+ msg("Method #{meth.name}():")
41
+ %w(arity child_methods describe
42
+ file first_line lines local_count
43
+ required_args splat stack_size total_args
44
+ ).each do |field|
45
+ msg " %-15s: %s" % [field, meth.send(field).inspect]
46
+ end
47
+ else
48
+ mess = "Can't find method"
49
+ mess += " for #{args.join(' ')}" unless args.empty?
50
+ errmsg mess
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ if __FILE__ == $0
57
+ # Demo it.
58
+
59
+ require_relative '../../mock'
60
+ require_relative '../../subcmd'
61
+ name = File.basename(__FILE__, '.rb')
62
+
63
+ # FIXME: DRY the below code
64
+ dbgr, cmd = MockDebugger::setup('info')
65
+ subcommand = Trepan::Subcommand::InfoMethod.new(cmd)
66
+ testcmdMgr = Trepan::Subcmd.new(subcommand)
67
+
68
+ subcommand.run([name])
69
+ name = File.basename(__FILE__, '.rb')
70
+ subcommand.summary_help(name)
71
+ end
@@ -0,0 +1,59 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative '../base/subcmd'
5
+
6
+ class Trepan::Subcommand::InfoProgram < Trepan::Subcommand
7
+ unless defined?(HELP)
8
+ HELP = 'Information about debugged program and its environment'
9
+ MIN_ABBREV = 'pr'.size
10
+ NAME = File.basename(__FILE__, '.rb')
11
+ NEED_STACK = true
12
+ PREFIX = %w(info program)
13
+ end
14
+
15
+ def run(args)
16
+ frame = @proc.frame
17
+ ## m = 'Program stop event: %s' % @proc.core.event
18
+ m = ''
19
+ m += "Frame index #{@proc.frame_index}, " if @proc.frame_index != 0
20
+ m +=
21
+ if frame.method
22
+ "PC offset %d of method: %s" %
23
+ [frame.next_ip, frame.method.name]
24
+ else
25
+ ## '.'
26
+ end
27
+ msg m
28
+ # if 'return' == @proc.core.event
29
+ # msg 'R=> %s' % @proc.frame.sp(1).inspect
30
+ # elsif 'raise' == @proc.core.event
31
+ # msg @proc.core.hook_arg.inspect if @proc.core.hook_arg
32
+ # end
33
+
34
+ if @proc.brkpt && @proc.brkpt.event == :Breakpoint
35
+ msg('It stopped at %sbreakpoint %d.' %
36
+ [@proc.brkpt.temp? ? 'temporary ' : '',
37
+ @proc.brkpt.id])
38
+ else
39
+ msg("Program stopped at a #{@proc.event} event.")
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ if __FILE__ == $0
46
+ # Demo it.
47
+ require_relative '../../mock'
48
+ name = File.basename(__FILE__, '.rb')
49
+
50
+ # FIXME: DRY the below code
51
+ dbgr, cmd = MockDebugger::setup('info')
52
+ subcommand = Trepan::Subcommand::InfoProgram.new(cmd)
53
+ testcmdMgr = Trepan::Subcmd.new(subcommand)
54
+
55
+ subcommand.run_show_bool
56
+ name = File.basename(__FILE__, '.rb')
57
+ subcommand.summary_help(name)
58
+ puts
59
+ end
@@ -0,0 +1,40 @@
1
+ require 'rubygems'; require 'require_relative'
2
+ require_relative '../base/subcmd'
3
+
4
+ class Trepan::Command::InfoVariables < Trepan::Subcommand
5
+ MIN_ABBREV = 'var'.size
6
+ NAME = File.basename(__FILE__, '.rb')
7
+ NEED_STACK = true
8
+ PREFIX = %w(info variables)
9
+ SHORT_HELP = 'Display the value of a variable or variables'
10
+ HELP = <<-HELP
11
+ Show debugger variables and user created variables. By default,
12
+ shows all variables.
13
+
14
+ The optional argument is which variable specifically to show the value of.
15
+ HELP
16
+
17
+ def run(args)
18
+ if args.size == 2
19
+ @proc.dbgr.variables.each do |name, val|
20
+ msg "var '#{name}' = #{val.inspect}"
21
+ end
22
+
23
+ if @proc.dbgr.user_variables > 0
24
+ section "User variables"
25
+ (0...@proc.dbgr.user_variables).each do |i|
26
+ str = "$d#{i}"
27
+ val = Rubinius::Globals[str.to_sym]
28
+ msg "var #{str} = #{val.inspect}"
29
+ end
30
+ end
31
+ else
32
+ var = args[2]
33
+ if @proc.dbgr.variables.key?(var)
34
+ msg "var '#{var}' = #{variables[var].inspect}"
35
+ else
36
+ msg "No variable set named '#{var}'"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,96 @@
1
+ # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
2
+ require 'irb'
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative 'base/cmd'
5
+ require_relative '../../app/irb'
6
+ class Trepan::Command::IRBCommand < Trepan::Command
7
+
8
+ unless defined?(HELP)
9
+ NAME = File.basename(__FILE__, '.rb')
10
+ HELP = <<-HELP
11
+ #{NAME} [-d]\tstarts an Interactive Ruby (IRB) session.
12
+
13
+ If -d is added you can get access to debugger frame the global variables
14
+ $trepanx_frame and $trepanx_cmdproc.
15
+
16
+ #{NAME} is extended with methods 'cont', 'ne', and, 'q', 'step' which
17
+ run the corresponding debugger commands 'continue', 'next', 'exit' and 'step'.
18
+
19
+ To issue a debugger command, inside #{NAME} nested inside a debugger use
20
+ 'dbgr'. For example:
21
+
22
+ dbgr %w(info program)
23
+ dbgr('info', 'program') # Same as above
24
+ dbgr 'info program' # Single quoted string also works
25
+
26
+ But arguments have to be quoted because #{NAME} will evaluate them:
27
+
28
+ dbgr info program # wrong!
29
+ dbgr info, program # wrong!
30
+ dbgr(info, program) # What I say 3 times is wrong!
31
+
32
+ Here then is a loop to query VM stack values:
33
+ (-1..1).each {|i| dbgr(\"info reg sp \#{i}\")}
34
+ HELP
35
+
36
+ CATEGORY = 'support'
37
+ MAX_ARGS = 1 # Need at most this many
38
+ SHORT_HELP = "Run #{NAME} as a command subshell"
39
+ end
40
+
41
+ # This method runs the command
42
+ def run(args) # :nodoc
43
+ add_debugging =
44
+ if args.size > 1
45
+ '-d' == args[1]
46
+ else
47
+ false
48
+ end
49
+
50
+ # unless @state.interface.kind_of?(LocalInterface)
51
+ # print "Command is available only in local mode.\n"
52
+ # throw :debug_error
53
+ # end
54
+
55
+ save_trap = trap('SIGINT') do
56
+ throw :IRB_EXIT, :cont if $trepanx_in_irb
57
+ end
58
+
59
+ $trepanx = @proc.dbgr
60
+ if add_debugging
61
+ $trepanx_cmdproc = @proc
62
+ $trepanx_frame = @proc.frame
63
+ end
64
+ $trepanx_in_irb = true
65
+ $trepanx_irb_statements = nil
66
+ $trepanx_command = nil
67
+
68
+ conf = {:BACK_TRACE_LIMIT => settings[:maxstack]}
69
+ cont = IRB.start_session(@proc.frame.binding, @proc, conf).to_s
70
+ trap('SIGINT', save_trap) # Restore old trap
71
+
72
+ back_trace_limit = IRB.CurrentContext.back_trace_limit
73
+ if settings[:maxstack] != back_trace_limit
74
+ msg("\nSetting debugger's BACK_TRACE_LIMIT (%d) to match irb's last setting (%d)" %
75
+ [settings[:maxstack], back_trace_limit])
76
+ settings[:maxstack]= IRB.CurrentContext.back_trace_limit
77
+ end
78
+
79
+ if %w(continue finish next ext step).member?(cont)
80
+ @proc.commands[cont].run([cont]) # (1, {})
81
+ else
82
+ @proc.print_location
83
+ end
84
+ ensure
85
+ $trepanx_in_irb = false
86
+ # restore old trap if any
87
+ trap('SIGINT', save_trap) if save_trap
88
+ end
89
+ end
90
+
91
+ if __FILE__ == $0
92
+ require_relative '../mock'
93
+ dbgr, cmd = MockDebugger::setup
94
+ # Get an IRB session -- the hard way :-)
95
+ cmd.run([cmd.name]) if ARGV.size > 0
96
+ end
@@ -0,0 +1,70 @@
1
+ # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
2
+ require 'rubygems'; require 'require_relative'
3
+ require_relative 'base/cmd'
4
+ class Trepan::Command::KillCommand < Trepan::Command
5
+
6
+ unless defined?(HELP)
7
+ NAME = File.basename(__FILE__, '.rb')
8
+ HELP = <<-HELP
9
+ #{NAME} [signal-number|signal-name|unconditionally]
10
+
11
+ Kill execution of program being debugged.
12
+
13
+ Equivalent of Process.kill('KILL', Process.pid). This is an unmaskable
14
+ signal. When all else fails, e.g. in thread code, use this.
15
+
16
+ If 'unconditionally' is given, no questions are asked. Otherwise, if
17
+ we are in interactive mode, we'll prompt to make sure.
18
+
19
+ Examples:
20
+
21
+ #{NAME}
22
+ #{NAME} unconditionally
23
+ #{NAME} KILL # same as above
24
+ #{NAME} kill # same as above
25
+ #{NAME} -9 # same as above
26
+ #{NAME} 9 # same as above
27
+ HELP
28
+
29
+ CATEGORY = 'running'
30
+ MAX_ARGS = 1 # Need at most this many
31
+ SHORT_HELP = 'Send this process a POSIX signal (default "9" is "kill -9")'
32
+ end
33
+
34
+ # This method runs the command
35
+ def run(args) # :nodoc
36
+ if args.size > 1
37
+ sig = Integer(args[1]) rescue args[1]
38
+ unless sig.is_a?(Integer) || Signal.list.member?(sig.upcase)
39
+ errmsg("Signal name '#{sig}' is not a signal I know about.\n")
40
+ return false
41
+ end
42
+ # FIXME: reinstate
43
+ # if 'KILL' == sig || Signal['KILL'] == sig
44
+ # @proc.intf.finalize
45
+ # end
46
+ else
47
+ if not confirm('Really kill?', false)
48
+ msg('Kill not confirmed.')
49
+ return
50
+ else
51
+ sig = 'KILL'
52
+ end
53
+ end
54
+ begin
55
+ Process.kill(sig, Process.pid)
56
+ rescue Errno::ESRCH
57
+ errmsg "Unable to send kill #{sig} to process #{Process.pid}"
58
+ end
59
+ end
60
+ end
61
+
62
+ if __FILE__ == $0
63
+ require_relative '../mock'
64
+ dbgr, cmd = MockDebugger::setup
65
+ %w(fooo 1 -1 HUP -9).each do |arg|
66
+ puts "#{cmd.name} #{arg}"
67
+ cmd.run([cmd.name, arg])
68
+ puts '=' * 40
69
+ end
70
+ end