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.
Files changed (312) hide show
  1. data/.gitignore +7 -0
  2. data/ChangeLog +2967 -0
  3. data/LICENSE +25 -0
  4. data/Makefile +13 -0
  5. data/NEWS +105 -0
  6. data/README.textile +34 -0
  7. data/Rakefile +244 -0
  8. data/THANKS +14 -0
  9. data/app/.gitignore +2 -0
  10. data/app/breakpoint.rb +242 -0
  11. data/app/brkptmgr.rb +153 -0
  12. data/app/client.rb +71 -0
  13. data/app/cmd_parse.kpeg +242 -0
  14. data/app/cmd_parse.rb +209 -0
  15. data/app/cmd_parser.rb +2083 -0
  16. data/app/complete.rb +79 -0
  17. data/app/condition.rb +22 -0
  18. data/app/default.rb +71 -0
  19. data/app/display.rb +186 -0
  20. data/app/eventbuffer.rb +147 -0
  21. data/app/file.rb +24 -0
  22. data/app/frame.rb +120 -0
  23. data/app/irb.rb +113 -0
  24. data/app/iseq.rb +188 -0
  25. data/app/method.rb +178 -0
  26. data/app/mock.rb +13 -0
  27. data/app/options.rb +154 -0
  28. data/app/rbx-llvm.rb +163 -0
  29. data/app/run.rb +92 -0
  30. data/app/util.rb +99 -0
  31. data/app/validate.rb +30 -0
  32. data/bin/.gitignore +2 -0
  33. data/bin/trepanx +69 -0
  34. data/data/.gitignore +2 -0
  35. data/data/irbrc +41 -0
  36. data/interface/.gitignore +2 -0
  37. data/interface/client.rb +84 -0
  38. data/interface/comcodes.rb +20 -0
  39. data/interface/script.rb +112 -0
  40. data/interface/server.rb +147 -0
  41. data/interface/user.rb +158 -0
  42. data/interface.rb +109 -0
  43. data/io/.gitignore +3 -0
  44. data/io/input.rb +151 -0
  45. data/io/null_output.rb +46 -0
  46. data/io/string_array.rb +155 -0
  47. data/io/tcpclient.rb +129 -0
  48. data/io/tcpfns.rb +33 -0
  49. data/io/tcpserver.rb +141 -0
  50. data/io.rb +148 -0
  51. data/lib/.gitignore +2 -0
  52. data/lib/trepanning.rb +467 -0
  53. data/processor/.gitignore +3 -0
  54. data/processor/Makefile +7 -0
  55. data/processor/breakpoint.rb +167 -0
  56. data/processor/command/.gitignore +2 -0
  57. data/processor/command/alias.rb +65 -0
  58. data/processor/command/backtrace.rb +68 -0
  59. data/processor/command/base/.gitignore +2 -0
  60. data/processor/command/base/subcmd.rb +226 -0
  61. data/processor/command/base/submgr.rb +185 -0
  62. data/processor/command/base/subsubcmd.rb +125 -0
  63. data/processor/command/base/subsubmgr.rb +196 -0
  64. data/processor/command/break.rb +78 -0
  65. data/processor/command/complete.rb +39 -0
  66. data/processor/command/condition.rb +64 -0
  67. data/processor/command/continue.rb +61 -0
  68. data/processor/command/delete.rb +44 -0
  69. data/processor/command/directory.rb +51 -0
  70. data/processor/command/disable.rb +71 -0
  71. data/processor/command/disassemble.rb +180 -0
  72. data/processor/command/display.rb +84 -0
  73. data/processor/command/down.rb +54 -0
  74. data/processor/command/edit.rb +74 -0
  75. data/processor/command/enable.rb +43 -0
  76. data/processor/command/eval.rb +93 -0
  77. data/processor/command/exit.rb +83 -0
  78. data/processor/command/finish.rb +80 -0
  79. data/processor/command/frame.rb +93 -0
  80. data/processor/command/help/.gitignore +1 -0
  81. data/processor/command/help/README +10 -0
  82. data/processor/command/help/command.txt +58 -0
  83. data/processor/command/help/examples.txt +16 -0
  84. data/processor/command/help/filename.txt +40 -0
  85. data/processor/command/help/location.txt +37 -0
  86. data/processor/command/help/suffixes.txt +17 -0
  87. data/processor/command/help.rb +228 -0
  88. data/processor/command/info.rb +30 -0
  89. data/processor/command/info_subcmd/.gitignore +3 -0
  90. data/processor/command/info_subcmd/breakpoints.rb +103 -0
  91. data/processor/command/info_subcmd/files.rb +219 -0
  92. data/processor/command/info_subcmd/frame.rb +68 -0
  93. data/processor/command/info_subcmd/line.rb +75 -0
  94. data/processor/command/info_subcmd/locals.rb +22 -0
  95. data/processor/command/info_subcmd/macro.rb +62 -0
  96. data/processor/command/info_subcmd/method.rb +71 -0
  97. data/processor/command/info_subcmd/program.rb +51 -0
  98. data/processor/command/info_subcmd/ruby.rb +64 -0
  99. data/processor/command/info_subcmd/source.rb +75 -0
  100. data/processor/command/info_subcmd/stack.rb +25 -0
  101. data/processor/command/info_subcmd/variables.rb +35 -0
  102. data/processor/command/info_subcmd/variables_subcmd/.gitignore +2 -0
  103. data/processor/command/info_subcmd/variables_subcmd/class.rb +42 -0
  104. data/processor/command/info_subcmd/variables_subcmd/constant.rb +42 -0
  105. data/processor/command/info_subcmd/variables_subcmd/globals.rb +69 -0
  106. data/processor/command/info_subcmd/variables_subcmd/instance.rb +42 -0
  107. data/processor/command/info_subcmd/variables_subcmd/locals.rb +80 -0
  108. data/processor/command/kill.rb +79 -0
  109. data/processor/command/list.rb +234 -0
  110. data/processor/command/macro.rb +86 -0
  111. data/processor/command/next.rb +67 -0
  112. data/processor/command/nexti.rb +59 -0
  113. data/processor/command/parsetree.rb +51 -0
  114. data/processor/command/pr.rb +37 -0
  115. data/processor/command/ps.rb +40 -0
  116. data/processor/command/restart.rb +60 -0
  117. data/processor/command/save.rb +58 -0
  118. data/processor/command/server.rb +72 -0
  119. data/processor/command/set.rb +47 -0
  120. data/processor/command/set_subcmd/.gitignore +2 -0
  121. data/processor/command/set_subcmd/abbrev.rb +25 -0
  122. data/processor/command/set_subcmd/auto.rb +33 -0
  123. data/processor/command/set_subcmd/auto_subcmd/.gitignore +2 -0
  124. data/processor/command/set_subcmd/auto_subcmd/dis.rb +33 -0
  125. data/processor/command/set_subcmd/auto_subcmd/eval.rb +53 -0
  126. data/processor/command/set_subcmd/auto_subcmd/irb.rb +33 -0
  127. data/processor/command/set_subcmd/auto_subcmd/list.rb +33 -0
  128. data/processor/command/set_subcmd/basename.rb +25 -0
  129. data/processor/command/set_subcmd/confirm.rb +24 -0
  130. data/processor/command/set_subcmd/debug.rb +26 -0
  131. data/processor/command/set_subcmd/debug_subcmd/.gitignore +2 -0
  132. data/processor/command/set_subcmd/debug_subcmd/dbgr.rb +36 -0
  133. data/processor/command/set_subcmd/debug_subcmd/skip.rb +23 -0
  134. data/processor/command/set_subcmd/debug_subcmd/step.rb +23 -0
  135. data/processor/command/set_subcmd/different.rb +61 -0
  136. data/processor/command/set_subcmd/hidelevel.rb +62 -0
  137. data/processor/command/set_subcmd/highlight.rb +39 -0
  138. data/processor/command/set_subcmd/kernelstep.rb +60 -0
  139. data/processor/command/set_subcmd/max.rb +26 -0
  140. data/processor/command/set_subcmd/max_subcmd/.gitignore +2 -0
  141. data/processor/command/set_subcmd/max_subcmd/list.rb +49 -0
  142. data/processor/command/set_subcmd/max_subcmd/stack.rb +50 -0
  143. data/processor/command/set_subcmd/max_subcmd/string.rb +76 -0
  144. data/processor/command/set_subcmd/max_subcmd/width.rb +49 -0
  145. data/processor/command/set_subcmd/reload.rb +42 -0
  146. data/processor/command/set_subcmd/substitute.rb +24 -0
  147. data/processor/command/set_subcmd/substitute_subcmd/.gitignore +3 -0
  148. data/processor/command/set_subcmd/substitute_subcmd/path.rb +56 -0
  149. data/processor/command/set_subcmd/timer.rb +58 -0
  150. data/processor/command/set_subcmd/trace.rb +37 -0
  151. data/processor/command/set_subcmd/trace_subcmd/.gitignore +2 -0
  152. data/processor/command/set_subcmd/trace_subcmd/buffer.rb +42 -0
  153. data/processor/command/set_subcmd/trace_subcmd/print.rb +41 -0
  154. data/processor/command/shell.rb +131 -0
  155. data/processor/command/show.rb +39 -0
  156. data/processor/command/show_subcmd/.gitignore +3 -0
  157. data/processor/command/show_subcmd/abbrev.rb +20 -0
  158. data/processor/command/show_subcmd/aliases.rb +46 -0
  159. data/processor/command/show_subcmd/args.rb +25 -0
  160. data/processor/command/show_subcmd/auto.rb +28 -0
  161. data/processor/command/show_subcmd/auto_subcmd/.gitignore +3 -0
  162. data/processor/command/show_subcmd/auto_subcmd/dis.rb +37 -0
  163. data/processor/command/show_subcmd/auto_subcmd/eval.rb +24 -0
  164. data/processor/command/show_subcmd/auto_subcmd/irb.rb +23 -0
  165. data/processor/command/show_subcmd/auto_subcmd/list.rb +22 -0
  166. data/processor/command/show_subcmd/basename.rb +20 -0
  167. data/processor/command/show_subcmd/confirm.rb +18 -0
  168. data/processor/command/show_subcmd/debug.rb +26 -0
  169. data/processor/command/show_subcmd/debug_subcmd/.gitignore +3 -0
  170. data/processor/command/show_subcmd/debug_subcmd/dbgr.rb +21 -0
  171. data/processor/command/show_subcmd/debug_subcmd/skip.rb +22 -0
  172. data/processor/command/show_subcmd/debug_subcmd/step.rb +22 -0
  173. data/processor/command/show_subcmd/different.rb +26 -0
  174. data/processor/command/show_subcmd/directories.rb +22 -0
  175. data/processor/command/show_subcmd/hidelevel.rb +41 -0
  176. data/processor/command/show_subcmd/highlight.rb +25 -0
  177. data/processor/command/show_subcmd/kernelstep.rb +34 -0
  178. data/processor/command/show_subcmd/max.rb +27 -0
  179. data/processor/command/show_subcmd/max_subcmd/.gitignore +2 -0
  180. data/processor/command/show_subcmd/max_subcmd/list.rb +38 -0
  181. data/processor/command/show_subcmd/max_subcmd/stack.rb +36 -0
  182. data/processor/command/show_subcmd/max_subcmd/string.rb +42 -0
  183. data/processor/command/show_subcmd/max_subcmd/width.rb +37 -0
  184. data/processor/command/show_subcmd/reload.rb +18 -0
  185. data/processor/command/show_subcmd/timer.rb +18 -0
  186. data/processor/command/show_subcmd/trace.rb +27 -0
  187. data/processor/command/show_subcmd/trace_subcmd/.gitignore +2 -0
  188. data/processor/command/show_subcmd/trace_subcmd/buffer.rb +64 -0
  189. data/processor/command/show_subcmd/trace_subcmd/print.rb +23 -0
  190. data/processor/command/show_subcmd/version.rb +23 -0
  191. data/processor/command/source.rb +133 -0
  192. data/processor/command/step.rb +97 -0
  193. data/processor/command/tbreak.rb +20 -0
  194. data/processor/command/unalias.rb +49 -0
  195. data/processor/command/undisplay.rb +63 -0
  196. data/processor/command/up.rb +89 -0
  197. data/processor/command.rb +173 -0
  198. data/processor/default.rb +64 -0
  199. data/processor/disassemble.rb +59 -0
  200. data/processor/display.rb +53 -0
  201. data/processor/eval.rb +97 -0
  202. data/processor/eventbuf.rb +101 -0
  203. data/processor/frame.rb +265 -0
  204. data/processor/help.rb +94 -0
  205. data/processor/hook.rb +134 -0
  206. data/processor/list.rb +123 -0
  207. data/processor/load_cmds.rb +253 -0
  208. data/processor/location.rb +228 -0
  209. data/processor/mock.rb +138 -0
  210. data/processor/msg.rb +74 -0
  211. data/processor/running.rb +244 -0
  212. data/processor/stepping.rb +135 -0
  213. data/processor/subcmd.rb +136 -0
  214. data/processor/validate.rb +379 -0
  215. data/processor/virtual.rb +33 -0
  216. data/processor.rb +404 -0
  217. data/rbx-trepanning.gemspec +39 -0
  218. data/sample/.gitignore +2 -0
  219. data/sample/list-terminal-colors.rb +139 -0
  220. data/sample/rocky-dot-trepanxrc +14 -0
  221. data/sample/rocky-trepanx-colors.rb +46 -0
  222. data/test/data/.gitignore +1 -0
  223. data/test/data/enable.right +36 -0
  224. data/test/data/fname-with-blank.cmd +6 -0
  225. data/test/data/fname-with-blank.right +6 -0
  226. data/test/data/inline-call.cmd +6 -0
  227. data/test/data/inline-call.right +14 -0
  228. data/test/data/quit-Xdebug.right +3 -0
  229. data/test/data/quit.cmd +5 -0
  230. data/test/data/quit.right +3 -0
  231. data/test/data/quit2.cmd +6 -0
  232. data/test/data/quit2.right +3 -0
  233. data/test/example/.gitignore +2 -0
  234. data/test/example/debugger-stop.rb +16 -0
  235. data/test/example/factorial.rb +10 -0
  236. data/test/example/fname with blank.rb +1 -0
  237. data/test/example/gcd-server.rb +22 -0
  238. data/test/example/gcd.rb +19 -0
  239. data/test/example/goto2goto.rb +11 -0
  240. data/test/example/inline-call.rb +23 -0
  241. data/test/example/null.rb +1 -0
  242. data/test/example/thread1.rb +3 -0
  243. data/test/functional/.gitignore +3 -0
  244. data/test/functional/fn_helper.rb +112 -0
  245. data/test/functional/test-break-name.rb +52 -0
  246. data/test/functional/test-break.rb +85 -0
  247. data/test/functional/test-eval.rb +115 -0
  248. data/test/functional/test-finish.rb +70 -0
  249. data/test/functional/test-fn_helper.rb +43 -0
  250. data/test/functional/test-list.rb +56 -0
  251. data/test/functional/test-next-bug.rb +49 -0
  252. data/test/functional/test-next.rb +101 -0
  253. data/test/functional/test-recursive-bt.rb +94 -0
  254. data/test/functional/test-step.rb +272 -0
  255. data/test/functional/test-step2.rb +35 -0
  256. data/test/functional/test-tbreak.rb +41 -0
  257. data/test/integration/.gitignore +3 -0
  258. data/test/integration/file-diff.rb +89 -0
  259. data/test/integration/helper.rb +81 -0
  260. data/test/integration/test-fname-with-blank.rb +16 -0
  261. data/test/integration/test-inline-call.rb +20 -0
  262. data/test/integration/test-quit.rb +47 -0
  263. data/test/unit/.gitignore +3 -0
  264. data/test/unit/cmd-helper.rb +50 -0
  265. data/test/unit/mock-helper.rb +10 -0
  266. data/test/unit/test-app-brkpt.rb +31 -0
  267. data/test/unit/test-app-brkptmgr.rb +51 -0
  268. data/test/unit/test-app-cmd_parse.rb +97 -0
  269. data/test/unit/test-app-cmd_parser.rb +23 -0
  270. data/test/unit/test-app-complete.rb +39 -0
  271. data/test/unit/test-app-condition.rb +18 -0
  272. data/test/unit/test-app-display.rb +22 -0
  273. data/test/unit/test-app-iseq.rb +64 -0
  274. data/test/unit/test-app-method.rb +54 -0
  275. data/test/unit/test-app-options.rb +94 -0
  276. data/test/unit/test-app-run.rb +14 -0
  277. data/test/unit/test-app-util.rb +44 -0
  278. data/test/unit/test-app-validate.rb +18 -0
  279. data/test/unit/test-base-cmd.rb +45 -0
  280. data/test/unit/test-base-subcmd.rb +57 -0
  281. data/test/unit/test-base-submgr.rb +24 -0
  282. data/test/unit/test-base-subsubcmd.rb +17 -0
  283. data/test/unit/test-bin-trepanx.rb +48 -0
  284. data/test/unit/test-cmd-alias.rb +48 -0
  285. data/test/unit/test-cmd-break.rb +66 -0
  286. data/test/unit/test-cmd-edit.rb +34 -0
  287. data/test/unit/test-cmd-exit.rb +27 -0
  288. data/test/unit/test-cmd-finish.rb +31 -0
  289. data/test/unit/test-cmd-help.rb +104 -0
  290. data/test/unit/test-cmd-kill.rb +54 -0
  291. data/test/unit/test-cmd-parse_list_cmd.rb +36 -0
  292. data/test/unit/test-cmd-source.rb +34 -0
  293. data/test/unit/test-cmd-step.rb +29 -0
  294. data/test/unit/test-command.rb +45 -0
  295. data/test/unit/test-completion.rb +48 -0
  296. data/test/unit/test-intf-user.rb +46 -0
  297. data/test/unit/test-io-input.rb +27 -0
  298. data/test/unit/test-io-tcp.rb +33 -0
  299. data/test/unit/test-io-tcpclient.rb +54 -0
  300. data/test/unit/test-io-tcpfns.rb +17 -0
  301. data/test/unit/test-io-tcpserver.rb +50 -0
  302. data/test/unit/test-proc-eval.rb +35 -0
  303. data/test/unit/test-proc-frame.rb +81 -0
  304. data/test/unit/test-proc-help.rb +16 -0
  305. data/test/unit/test-proc-hook.rb +30 -0
  306. data/test/unit/test-proc-list.rb +55 -0
  307. data/test/unit/test-proc-load_cmds.rb +51 -0
  308. data/test/unit/test-proc-location.rb +67 -0
  309. data/test/unit/test-proc-main.rb +95 -0
  310. data/test/unit/test-proc-validate.rb +139 -0
  311. data/test/unit/test-subcmd-help.rb +43 -0
  312. metadata +545 -0
@@ -0,0 +1,219 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require 'linecache'
5
+ require 'columnize'
6
+ require_relative '../base/subcmd'
7
+ require_relative '../../../app/complete'
8
+
9
+ class Trepan::Subcommand::InfoFiles < Trepan::Subcommand
10
+ unless defined?(HELP)
11
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
12
+ DEFAULT_FILE_ARGS = %w(size mtime sha1 cm)
13
+
14
+ HELP = <<-EOH
15
+ #{CMD} [{FILENAME|.|*} [all|ctime|brkpts|mtime|sha1|size|stat]]
16
+
17
+ Show information about the current file. If no filename is given and
18
+ the program is running, then the current file associated with the
19
+ current stack entry is used. Giving . has the same effect.
20
+
21
+ Given * gives a list of all files we know about.
22
+
23
+ Sub options which can be shown about a file are:
24
+
25
+ brkpts -- Line numbers where there are statement boundaries.
26
+ These lines can be used in breakpoint commands.
27
+ cm -- Top-level compiled method found for this file
28
+ ctime -- File creation time
29
+ mtime -- File modification time
30
+ sha1 -- A SHA1 hash of the source text. This may be useful in comparing
31
+ source code.
32
+ size -- The number of lines in the file.
33
+ stat -- File.stat information
34
+
35
+ all -- All of the above information.
36
+
37
+ If no sub-options are given, "#{DEFAULT_FILE_ARGS.join(' ')}" are assumed.
38
+
39
+ Examples:
40
+
41
+ #{CMD} # Show #{DEFAULT_FILE_ARGS.join(' ')} information about current file
42
+ #{CMD} . # same as above
43
+ #{CMD} brkpts # show the number of lines in the current file
44
+ #{CMD} brkpts size # same as above but also list breakpoint line numbers
45
+ #{CMD} * # Give a list of files we know about
46
+ EOH
47
+ MIN_ABBREV = 'fi'.size # Note we have "info frame"
48
+ NEED_STACK = false
49
+ end
50
+
51
+ # completion %w(all brkpts cm sha1 size stat)
52
+
53
+ include Trepanning
54
+
55
+ def file_list
56
+ (LineCache.cached_files +
57
+ LineCache.class_variable_get('@@file2file_remap').keys).uniq
58
+ end
59
+
60
+ def complete(prefix)
61
+ completions = ['.'] + file_list
62
+ Trepan::Complete.complete_token(completions, prefix)
63
+ end
64
+
65
+ # Get file information
66
+ def run(args)
67
+ return if args.size < 2
68
+ args << '.' if 2 == args.size
69
+ if '*' == args[2]
70
+ section 'Canonic Files names cached:'
71
+ primary = LineCache.class_variable_get('@@file_cache')
72
+ remap = LineCache.class_variable_get('@@file2file_remap')
73
+ msg columnize_commands(remap.keys.uniq.sort)
74
+ names = remap.keys - primary.keys
75
+ unless names.empty?
76
+ section 'Non-canonic names cached:'
77
+ msg columnize_commands(names.sort)
78
+ end
79
+ return
80
+ end
81
+ filename =
82
+ if '.' == args[2]
83
+ if not @proc.frame
84
+ errmsg("No frame - no default file.")
85
+ return false
86
+ nil
87
+ else
88
+ frame_file = @proc.frame.file
89
+ LineCache::map_file(frame_file) || File.expand_path(frame_file)
90
+ end
91
+ else
92
+ args[2]
93
+ end
94
+ args += DEFAULT_FILE_ARGS if args.size == 3
95
+
96
+ m = filename
97
+ canonic_name = @proc.canonic_file(filename)
98
+ canonic_name = LineCache::map_file(canonic_name) || canonic_name
99
+ if LineCache::cached?(canonic_name)
100
+ m += " is cached in debugger"
101
+ if canonic_name != filename
102
+ m += (" as:\n " + canonic_name)
103
+ end
104
+ m += '.'
105
+ msg(m)
106
+ # elsif !(matches = find_scripts(filename)).empty?
107
+ # if (matches.size > 1)
108
+ # msg("Multiple files found:")
109
+ # matches.each { |filename| msg("\t%s" % filename) }
110
+ # return
111
+ # else
112
+ # msg('File "%s" just now cached.' % filename)
113
+ # LineCache::cache(matches[0])
114
+ # LineCache::remap_file(matches[0], filename)
115
+ # canonic_name = matches[0]
116
+ # end
117
+ else
118
+ matches = file_list.select{|try| try.end_with?(filename)}
119
+ if (matches.size > 1)
120
+ msg("Multiple files found ending filename string:")
121
+ matches.sort.each { |match_file| msg "\t%s" % match_file }
122
+ return
123
+ elsif 1 == matches.size
124
+ canonic_name = LineCache::map_file(matches[0])
125
+ m += " matched debugger cache file:\n " + canonic_name
126
+ msg m
127
+ else
128
+ msg(m + ' is not cached in debugger.')
129
+ return
130
+ end
131
+ end
132
+ seen = {}
133
+ args[3..-1].each do |arg|
134
+ processed_arg = false
135
+
136
+ if %w(all size).member?(arg)
137
+ unless seen[:size]
138
+ max_line = LineCache::size(canonic_name)
139
+ msg "File has %d lines." % max_line if max_line
140
+ end
141
+ processed_arg = seen[:size] = true
142
+ end
143
+
144
+ if %w(all sha1).member?(arg)
145
+ unless seen[:sha1]
146
+ msg("SHA1 is %s." % LineCache::sha1(canonic_name))
147
+ end
148
+ processed_arg = seen[:sha1] = true
149
+ end
150
+
151
+ if %w(all brkpts).member?(arg)
152
+ unless seen[:brkpts]
153
+ msg("Possible breakpoint line numbers:")
154
+ lines = LineCache.trace_line_numbers(canonic_name)
155
+ fmt_lines = columnize_numbers(lines)
156
+ msg(fmt_lines)
157
+ end
158
+ processed_arg = seen[:brkpts] = true
159
+ end
160
+
161
+ if %w(all ctime).member?(arg)
162
+ unless seen[:ctime]
163
+ msg("create time:\t%s." %
164
+ LineCache::stat(canonic_name).ctime.to_s)
165
+ end
166
+ processed_arg = seen[:ctime] = true
167
+ end
168
+
169
+ if %w(all cm).member?(arg)
170
+ unless seen[:cm]
171
+ if cm = LineCache.compiled_method(canonic_name)
172
+ msg("File has compiled method: #{cm}")
173
+ else
174
+ msg("Compiled method not recorded; there may be some, though.")
175
+ end
176
+ end
177
+ processed_arg = seen[:cm] = true
178
+ end
179
+
180
+ if %w(all mtime).member?(arg)
181
+ unless seen[:mtime]
182
+ msg("modify time:\t%s." %
183
+ LineCache::stat(canonic_name).mtime.to_s)
184
+ end
185
+ processed_arg = seen[:mtime] = true
186
+ end
187
+
188
+ if %w(all stat).member?(arg)
189
+ unless seen[:stat]
190
+ msg("Stat info:\n\t%s." % LineCache::stat(canonic_name).inspect)
191
+ end
192
+ processed_arg = seen[:stat] = true
193
+ end
194
+
195
+ if not processed_arg
196
+ errmsg("I don't understand sub-option \"%s\"." % arg)
197
+ end
198
+ end unless args.empty?
199
+ end
200
+ end
201
+
202
+ if __FILE__ == $0
203
+ require_relative '../../mock'
204
+ cmd = MockDebugger::sub_setup(Trepan::Subcommand::InfoFiles, false)
205
+ LineCache::cache(__FILE__)
206
+ LineCache::cache('../../mock.rb')
207
+
208
+ [%w(info file nothere),
209
+ %w(info file .),
210
+ %w(info file *),
211
+ %w(info file),
212
+ %W(info file #{__FILE__}),
213
+ %W(info file #{__FILE__} all),
214
+ %W(info file #{__FILE__} brkpts bad size sha1 sha1)].each do |args|
215
+ cmd.run(args)
216
+ puts '-' * 40
217
+ end
218
+ p cmd.complete('')
219
+ end
@@ -0,0 +1,68 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rubygems'; require 'require_relative'
3
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
4
+ require_relative '../base/subcmd'
5
+
6
+ class Trepan::Subcommand::InfoFrame < Trepan::Subcommand
7
+ unless defined?(HELP)
8
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
9
+ HELP = <<-EOH
10
+ #{CMD}
11
+
12
+ Show information about the selected frame. The fields we list are:
13
+
14
+ * A source container and name (e.g. "file" or "string" and the value)
15
+ * The actual number of arguments passed in
16
+ * The 'arity' or permissible number of arguments passed it. -1 indicates
17
+ variable number
18
+ * The frame "type", e.g. TOP, METHOD, BLOCK, EVAL, CFUNC etc.
19
+ * The return value if the frame is at a return point
20
+ * The PC offset we are currently at; May be omitted of no instruction
21
+ sequence
22
+
23
+ A backtrace shows roughly the same information in a more compact form.
24
+
25
+ Example form inside File.basename('foo')
26
+
27
+ Frame basename
28
+ file : /tmp/c-func.rb # actually location of caller
29
+ line : 2 # inherited from caller
30
+ argc : 1 # One out argument supplied: 'foo'
31
+ arity : -1 # Variable number of args, can have up to 2 arguments.
32
+ type : CFUNC (A C function)
33
+
34
+
35
+ See also: backtrace
36
+ EOH
37
+ MIN_ABBREV = 'fr'.size # Note we have "info file"
38
+ MIN_ARGS = 0
39
+ MAX_ARGS = 0
40
+ NEED_STACK = true
41
+ SHORT_HELP = 'Show information about the selected frame'
42
+ end
43
+
44
+ def run(args)
45
+ frame = @proc.frame
46
+ loc = frame.vm_location
47
+ section "Frame %2d: #{frame.method.name}" % frame.number
48
+ msg " in : #{loc.describe_receiver}#{loc.name}"
49
+ msg " file : %s" % loc.method.active_path
50
+ msg " line : %s" % frame.line
51
+ # msg " argc : %d" % frame.argc
52
+ msg " arity : %d" % frame.method.arity
53
+ # msg " type : %s" % frame.type
54
+ msg " offset: %d" % frame.ip
55
+ # if %w(return c-return).member?(@proc.event)
56
+ # ret_val = Trepan::Frame.value_returned(@proc.frame, @proc.event)
57
+ # msg " Return: %s" % ret_val
58
+ # end
59
+ end
60
+
61
+ end
62
+
63
+ if __FILE__ == $0
64
+ # Demo it.
65
+ require_relative '../../mock'
66
+ cmd = MockDebugger::sub_setup(Trepan::Subcommand::InfoFrame, false)
67
+ cmd.run(cmd.prefix)
68
+ end
@@ -0,0 +1,75 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative '../base/subcmd'
5
+ require_relative '../../../app/iseq'
6
+
7
+
8
+ class Trepan::Subcommand::InfoLine < Trepan::Subcommand
9
+ unless defined?(HELP)
10
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
11
+ HELP = <<-EOH
12
+ #{CMD} [LINE-NUMBER]
13
+
14
+ Show bytecode offset for LINE-NUMBER. If no LINE-NUMBER is given,
15
+ then we use the current line that we are stopped in.
16
+
17
+ Examples:
18
+ #{CMD}
19
+ #{CMD} 10
20
+ EOH
21
+ MIN_ABBREV = 'li'.size
22
+ NEED_STACK = true
23
+ SHORT_HELP = 'Byte code offsets for source code line'
24
+ end
25
+
26
+ include Trepan::ISeq
27
+
28
+ def run(args)
29
+ frame = @proc.frame
30
+ vm_location = frame.vm_location
31
+ cm = frame.method
32
+ filename = cm.file
33
+ lines = cm.lines
34
+ tail_code = false
35
+ if args.size == 2
36
+ line_no = vm_location.line
37
+ if line_no == 0
38
+ tail_code = true
39
+ line_no = frame.line
40
+ end
41
+ else
42
+ lineno_str = args[2]
43
+ opts = {
44
+ :msg_on_error =>
45
+ "The 'info line' line number must be an integer. Got: %s" % lineno_str,
46
+ :min_value => lines.at(1),
47
+ :max_value => lines.at(lines.size-2)
48
+ }
49
+ line_no = @proc.get_an_int(lineno_str, opts)
50
+ return false unless line_no
51
+ end
52
+ ranges, prefix =
53
+ if tail_code
54
+ [ip_ranges_for_ip(lines, frame.next_ip), 'Tail code preceding line']
55
+ else
56
+ [ip_ranges_for_line(lines, line_no), 'Line']
57
+ end
58
+ if ranges.empty?
59
+ msg "%s %s of %s:\n\tno bytecode offsets" % [prefix, line_no, filename]
60
+ else
61
+ msg "%s %s of %s:" % [prefix, line_no, filename]
62
+ ranges.each do |tuple|
63
+ msg "\t starts at offset %d and ends before offset %d" % tuple
64
+ end
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ if __FILE__ == $0
71
+ # Demo it.
72
+ require_relative '../../mock'
73
+ cmd = MockDebugger::sub_setup(Trepan::Subcommand::InfoLine, false)
74
+ cmd.run(cmd.prefix)
75
+ end
@@ -0,0 +1,22 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative '../base/subcmd'
5
+
6
+ class Trepan::Subcommand::InfoLocals < Trepan::Subcommand
7
+ unless defined?(HELP)
8
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
9
+ HELP = 'Same thing as "info locals"'
10
+ NEED_LOCALS = true
11
+ end
12
+
13
+ def run(args)
14
+ @proc.commands['info'].run(%w(info variables locals))
15
+ end
16
+ end
17
+
18
+ if __FILE__ == $0
19
+ # Demo it.
20
+ require_relative '../../mock'
21
+ # ???
22
+ end
@@ -0,0 +1,62 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative '../base/subcmd'
5
+ require_relative '../../../app/complete'
6
+
7
+ class Trepan::Subcommand::InfoMacro < Trepan::Subcommand
8
+ unless defined?(HELP)
9
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
10
+ HELP = <<-HELP
11
+ #{CMD}
12
+ #{CMD} *
13
+ #{CMD} MACRO1 [MACRO2 ..]
14
+
15
+ In the first form a list of the existing macro names are shown
16
+ in column format.
17
+
18
+ In the second form, all macro names and their definitions are show.
19
+
20
+ In the last form the only definitions of the given macro names is shown.
21
+ HELP
22
+ SHORT_HELP = "Info defined macros"
23
+ MIN_ABBREV = 'mac'.size
24
+ end
25
+
26
+ def complete(prefix)
27
+ Trepan::Complete.complete_token(@proc.macros.keys + %w(*), prefix)
28
+ end
29
+
30
+ def run(args)
31
+ if args.size > 2
32
+ macro_names =
33
+ if args.size == 3 && '*' == args[2]
34
+ @proc.macros.keys
35
+ else
36
+ args[2..-1]
37
+ end
38
+ macro_names.each do |macro_name|
39
+ if @proc.macros.member?(macro_name)
40
+ section "#{macro_name}:"
41
+ string = @proc.macros[macro_name][1]
42
+ msg " #{@proc.ruby_format(string)}", {:unlimited => true}
43
+ else
44
+ errmsg "%s is not a defined macro" % macro_name
45
+ end
46
+ end
47
+ elsif @proc.macros.empty?
48
+ msg "No macros defined."
49
+ else
50
+ msg columnize_commands(@proc.macros.keys.sort)
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ if __FILE__ == $0
57
+ # Demo it.
58
+ $0 = __FILE__ + 'notagain' # So we don't run this agin
59
+ require_relative '../../mock'
60
+ cmd = MockDebugger::sub_setup(Trepan::Subcommand::InfoMacro)
61
+ cmd.run(cmd.prefix + %w(u foo))
62
+ end
@@ -0,0 +1,71 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 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
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
9
+ HELP = <<-EOH
10
+ #{PREFIX.join(' ')} [METHOD|.]
11
+
12
+ Show information about a method.
13
+
14
+ Examples:
15
+ #{PREFIX.join(' ')}
16
+ #{PREFIX.join(' ')} .
17
+ #{PREFIX.join(' ')} require_relative
18
+ EOH
19
+
20
+ MIN_ABBREV = 'me'.size
21
+ NEED_STACK = true
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,51 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 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
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
9
+ HELP = 'Information about debugged program and its environment'
10
+ MIN_ARGS = 0
11
+ MAX_ARGS = 0
12
+ MIN_ABBREV = 'pr'.size
13
+ NEED_STACK = true
14
+ end
15
+
16
+ def run(args)
17
+ frame = @proc.frame
18
+ ## m = 'Program stop event: %s' % @proc.core.event
19
+ m = ''
20
+ m += "Frame index #{@proc.frame_index}, " if @proc.frame_index != 0
21
+ m +=
22
+ if frame.method
23
+ "PC offset %d of method: %s" %
24
+ [frame.next_ip, frame.method.name]
25
+ else
26
+ ## '.'
27
+ end
28
+ msg m
29
+ # if 'return' == @proc.core.event
30
+ # msg 'R=> %s' % @proc.frame.sp(1).inspect
31
+ # elsif 'raise' == @proc.core.event
32
+ # msg @proc.core.hook_arg.inspect if @proc.core.hook_arg
33
+ # end
34
+
35
+ if @proc.brkpt && @proc.brkpt.event == :Breakpoint
36
+ msg('It stopped at %sbreakpoint %d.' %
37
+ [@proc.brkpt.temp? ? 'temporary ' : '',
38
+ @proc.brkpt.id])
39
+ else
40
+ msg("Program stopped at a #{@proc.event} event.")
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ if __FILE__ == $0
47
+ # Demo it.
48
+ require_relative '../../mock'
49
+ cmd = MockDebugger::sub_setup(Trepan::Subcommand::InfoProgram, false)
50
+ cmd.run(cmd.prefix)
51
+ end
@@ -0,0 +1,64 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative '../base/subcmd'
5
+
6
+ class Trepan::Subcommand::InfoRuby < Trepan::Subcommand
7
+ unless defined?(HELP)
8
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
9
+ HELP = <<-EOH
10
+ #{CMD} [-v|--verbose|-no-verbose]
11
+
12
+ Show Ruby version information such as you'd get from
13
+ "rbx -v" (which is really just the value of RUBY_RELEASE_DATE),
14
+ or from "rbx -vv".
15
+
16
+ See also constants: RUBY_DESCRIPITON, RUBY_VERSION, and RUBY_RELEASE_DATE."
17
+ EOH
18
+ MIN_ABBREV = 'ru'.size
19
+ NEED_STACK = false
20
+ MIN_ARGS = 0
21
+ MAX_ARGS = 0
22
+ SHORT_HELP = 'Ruby version information'
23
+ end
24
+
25
+ def parse_options(args) # :nodoc
26
+ options = {}
27
+ parser = OptionParser.new do |opts|
28
+ opts.on("-v",
29
+ "--[no-]verbose", "show additional version information") do
30
+ |v|
31
+ options[:verbose] = v
32
+ end
33
+ end
34
+ parser.parse(args)
35
+ return options
36
+ end
37
+
38
+ def run(args)
39
+ options = parse_options(args[2..-1])
40
+ msg RUBY_DESCRIPTION
41
+ if options[:verbose]
42
+ msg "Options:"
43
+ msg " Interpreter type: #{Rubinius::INTERPRETER}"
44
+ if jit = Rubinius::JIT
45
+ msg " JIT enabled: #{jit.join(', ')}"
46
+ else
47
+ msg " JIT disabled"
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ if __FILE__ == $0
55
+ # Demo it.
56
+ $0 = __FILE__ + 'notagain' # So we don't run this again
57
+ require_relative '../../mock'
58
+ cmd = MockDebugger::sub_setup(Trepan::Subcommand::InfoRuby, false)
59
+ cmd.run(cmd.prefix)
60
+ %w(-v --verbose --no-verbose).each do |opt|
61
+ puts '-' * 10 + " #{opt}"
62
+ cmd.run(cmd.prefix + [opt])
63
+ end
64
+ end