needy_debugger 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. data/.gitignore +14 -0
  2. data/.travis.yml +8 -0
  3. data/AUTHORS +10 -0
  4. data/CHANGELOG.md +68 -0
  5. data/CONTRIBUTING.md +1 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +23 -0
  8. data/OLDER_CHANGELOG +334 -0
  9. data/OLD_CHANGELOG +5655 -0
  10. data/OLD_README +122 -0
  11. data/README.md +141 -0
  12. data/Rakefile +78 -0
  13. data/bin/rdebug +397 -0
  14. data/doc/.cvsignore +42 -0
  15. data/doc/Makefile.am +63 -0
  16. data/doc/emacs-notes.txt +38 -0
  17. data/doc/hanoi.rb +35 -0
  18. data/doc/primes.rb +28 -0
  19. data/doc/rdebug-emacs.texi +1030 -0
  20. data/doc/ruby-debug.texi +3791 -0
  21. data/doc/test-tri2.rb +18 -0
  22. data/doc/tri3.rb +8 -0
  23. data/doc/triangle.rb +12 -0
  24. data/emacs/Makefile.am +130 -0
  25. data/emacs/rdebug-annotate.el +385 -0
  26. data/emacs/rdebug-breaks.el +407 -0
  27. data/emacs/rdebug-cmd.el +92 -0
  28. data/emacs/rdebug-core.el +502 -0
  29. data/emacs/rdebug-dbg.el +62 -0
  30. data/emacs/rdebug-error.el +79 -0
  31. data/emacs/rdebug-fns.el +111 -0
  32. data/emacs/rdebug-frames.el +230 -0
  33. data/emacs/rdebug-gud.el +242 -0
  34. data/emacs/rdebug-help.el +104 -0
  35. data/emacs/rdebug-info.el +83 -0
  36. data/emacs/rdebug-layouts.el +180 -0
  37. data/emacs/rdebug-locring.el +118 -0
  38. data/emacs/rdebug-output.el +106 -0
  39. data/emacs/rdebug-regexp.el +118 -0
  40. data/emacs/rdebug-secondary.el +260 -0
  41. data/emacs/rdebug-shortkey.el +175 -0
  42. data/emacs/rdebug-source.el +568 -0
  43. data/emacs/rdebug-track.el +392 -0
  44. data/emacs/rdebug-varbuf.el +150 -0
  45. data/emacs/rdebug-vars.el +125 -0
  46. data/emacs/rdebug-watch.el +132 -0
  47. data/emacs/rdebug.el +326 -0
  48. data/emacs/test/elk-test.el +242 -0
  49. data/emacs/test/test-annotate.el +103 -0
  50. data/emacs/test/test-cmd.el +116 -0
  51. data/emacs/test/test-core.el +104 -0
  52. data/emacs/test/test-fns.el +65 -0
  53. data/emacs/test/test-frames.el +62 -0
  54. data/emacs/test/test-gud.el +35 -0
  55. data/emacs/test/test-indent.el +58 -0
  56. data/emacs/test/test-regexp.el +144 -0
  57. data/emacs/test/test-shortkey.el +61 -0
  58. data/ext/ruby_debug/192/breakpoint.c +586 -0
  59. data/ext/ruby_debug/192/ruby_debug.c +2645 -0
  60. data/ext/ruby_debug/192/ruby_debug.h +148 -0
  61. data/ext/ruby_debug/193/breakpoint.c +586 -0
  62. data/ext/ruby_debug/193/ruby_debug.c +2626 -0
  63. data/ext/ruby_debug/193/ruby_debug.h +148 -0
  64. data/ext/ruby_debug/200/breakpoint.c +586 -0
  65. data/ext/ruby_debug/200/ruby_debug.c +2692 -0
  66. data/ext/ruby_debug/200/ruby_debug.h +148 -0
  67. data/ext/ruby_debug/extconf.rb +94 -0
  68. data/lib/debugger.rb +5 -0
  69. data/lib/debugger/version.rb +5 -0
  70. data/lib/ruby-debug-base.rb +305 -0
  71. data/lib/ruby-debug.rb +177 -0
  72. data/lib/ruby-debug/command.rb +227 -0
  73. data/lib/ruby-debug/commands/breakpoints.rb +153 -0
  74. data/lib/ruby-debug/commands/catchpoint.rb +55 -0
  75. data/lib/ruby-debug/commands/condition.rb +49 -0
  76. data/lib/ruby-debug/commands/continue.rb +38 -0
  77. data/lib/ruby-debug/commands/control.rb +107 -0
  78. data/lib/ruby-debug/commands/display.rb +120 -0
  79. data/lib/ruby-debug/commands/edit.rb +48 -0
  80. data/lib/ruby-debug/commands/enable.rb +202 -0
  81. data/lib/ruby-debug/commands/eval.rb +176 -0
  82. data/lib/ruby-debug/commands/finish.rb +42 -0
  83. data/lib/ruby-debug/commands/frame.rb +301 -0
  84. data/lib/ruby-debug/commands/help.rb +56 -0
  85. data/lib/ruby-debug/commands/info.rb +467 -0
  86. data/lib/ruby-debug/commands/irb.rb +123 -0
  87. data/lib/ruby-debug/commands/jump.rb +66 -0
  88. data/lib/ruby-debug/commands/kill.rb +51 -0
  89. data/lib/ruby-debug/commands/list.rb +94 -0
  90. data/lib/ruby-debug/commands/method.rb +84 -0
  91. data/lib/ruby-debug/commands/quit.rb +50 -0
  92. data/lib/ruby-debug/commands/reload.rb +40 -0
  93. data/lib/ruby-debug/commands/save.rb +90 -0
  94. data/lib/ruby-debug/commands/set.rb +223 -0
  95. data/lib/ruby-debug/commands/show.rb +247 -0
  96. data/lib/ruby-debug/commands/skip.rb +35 -0
  97. data/lib/ruby-debug/commands/source.rb +36 -0
  98. data/lib/ruby-debug/commands/stepping.rb +81 -0
  99. data/lib/ruby-debug/commands/threads.rb +189 -0
  100. data/lib/ruby-debug/commands/tmate.rb +36 -0
  101. data/lib/ruby-debug/commands/trace.rb +57 -0
  102. data/lib/ruby-debug/commands/variables.rb +199 -0
  103. data/lib/ruby-debug/debugger.rb +5 -0
  104. data/lib/ruby-debug/helper.rb +69 -0
  105. data/lib/ruby-debug/interface.rb +232 -0
  106. data/lib/ruby-debug/processor.rb +474 -0
  107. data/man/rdebug.1 +241 -0
  108. data/needy_debugger.gemspec +31 -0
  109. data/old_scripts/Makefile.am +14 -0
  110. data/old_scripts/README.md +2 -0
  111. data/old_scripts/autogen.sh +4 -0
  112. data/old_scripts/configure.ac +12 -0
  113. data/old_scripts/rdbg.rb +33 -0
  114. data/old_scripts/runner.sh +7 -0
  115. data/old_scripts/svn2cl_usermap +3 -0
  116. data/test/.cvsignore +1 -0
  117. data/test/breakpoints_test.rb +365 -0
  118. data/test/conditions_test.rb +76 -0
  119. data/test/continue_test.rb +28 -0
  120. data/test/display_test.rb +141 -0
  121. data/test/edit_test.rb +55 -0
  122. data/test/eval_test.rb +92 -0
  123. data/test/examples/breakpoint1.rb +15 -0
  124. data/test/examples/breakpoint2.rb +7 -0
  125. data/test/examples/conditions.rb +4 -0
  126. data/test/examples/continue.rb +4 -0
  127. data/test/examples/display.rb +5 -0
  128. data/test/examples/edit.rb +3 -0
  129. data/test/examples/edit2.rb +3 -0
  130. data/test/examples/eval.rb +4 -0
  131. data/test/examples/finish.rb +20 -0
  132. data/test/examples/frame.rb +31 -0
  133. data/test/examples/help.rb +2 -0
  134. data/test/examples/info.rb +48 -0
  135. data/test/examples/info2.rb +3 -0
  136. data/test/examples/irb.rb +6 -0
  137. data/test/examples/jump.rb +14 -0
  138. data/test/examples/kill.rb +2 -0
  139. data/test/examples/list.rb +12 -0
  140. data/test/examples/method.rb +15 -0
  141. data/test/examples/post_mortem.rb +19 -0
  142. data/test/examples/quit.rb +2 -0
  143. data/test/examples/reload.rb +6 -0
  144. data/test/examples/restart.rb +6 -0
  145. data/test/examples/save.rb +3 -0
  146. data/test/examples/set.rb +3 -0
  147. data/test/examples/set_annotate.rb +12 -0
  148. data/test/examples/settings.rb +1 -0
  149. data/test/examples/show.rb +2 -0
  150. data/test/examples/source.rb +3 -0
  151. data/test/examples/stepping.rb +21 -0
  152. data/test/examples/thread.rb +32 -0
  153. data/test/examples/tmate.rb +10 -0
  154. data/test/examples/trace.rb +7 -0
  155. data/test/examples/trace_threads.rb +20 -0
  156. data/test/examples/variables.rb +26 -0
  157. data/test/finish_test.rb +48 -0
  158. data/test/frame_test.rb +140 -0
  159. data/test/help_test.rb +50 -0
  160. data/test/info_test.rb +325 -0
  161. data/test/irb_test.rb +81 -0
  162. data/test/jump_test.rb +70 -0
  163. data/test/kill_test.rb +47 -0
  164. data/test/list_test.rb +145 -0
  165. data/test/method_test.rb +70 -0
  166. data/test/post_mortem_test.rb +25 -0
  167. data/test/quit_test.rb +55 -0
  168. data/test/reload_test.rb +43 -0
  169. data/test/restart_test.rb +143 -0
  170. data/test/save_test.rb +92 -0
  171. data/test/set_test.rb +177 -0
  172. data/test/show_test.rb +292 -0
  173. data/test/source_test.rb +44 -0
  174. data/test/stepping_test.rb +118 -0
  175. data/test/support/breakpoint.rb +12 -0
  176. data/test/support/context.rb +14 -0
  177. data/test/support/matchers.rb +67 -0
  178. data/test/support/mocha_extensions.rb +71 -0
  179. data/test/support/processor.rb +7 -0
  180. data/test/support/test_dsl.rb +205 -0
  181. data/test/support/test_interface.rb +66 -0
  182. data/test/test_helper.rb +8 -0
  183. data/test/thread_test.rb +122 -0
  184. data/test/tmate_test.rb +43 -0
  185. data/test/trace_test.rb +154 -0
  186. data/test/variables_test.rb +114 -0
  187. metadata +352 -0
@@ -0,0 +1,122 @@
1
+ *************************************************************
2
+
3
+ NOTE: For Ruby 1.9 installation instructions, please see:
4
+
5
+ http://wiki.github.com/mark-moseley/ruby-debug
6
+
7
+ *************************************************************
8
+
9
+ = ruby-debug
10
+
11
+ == Overview
12
+
13
+ ruby-debug is a fast implementation of the standard debugger debug.rb.
14
+ The faster execution speed is achieved by utilizing a new hook in the
15
+ Ruby C API.
16
+
17
+ == Requirements
18
+
19
+ ruby-debug requires Ruby 1.8.4 or higher.
20
+
21
+ Unless you get the packages as a binary (Microsoft Windows binaries
22
+ are sometimes available), you'll need a C compiler and Ruby
23
+ development headers, and a Make program so the extension in
24
+ ruby-debug-base can be compiled when it is installed.
25
+
26
+ To install on Microsoft Windows, unless you run under cygwin or mingw
27
+ you'll need Microsoft Visual C++ 6.0 also known as VC6.
28
+ http://rubyforge.org/tracker/index.php?func=detail&aid=16774&group_id=1900&atid=7436
29
+ suggests why.
30
+
31
+
32
+ == Install
33
+
34
+ ruby-debug is provided as a RubyGem. To install:
35
+
36
+ <tt>gem install ruby-debug</tt>
37
+
38
+ This should also pull in <tt>ruby-debug-base</tt> as a dependency.
39
+
40
+ (If you install ruby-debug-base explicitly, you can add in the <tt>--test</tt>
41
+ option after "install" to have the regression test run before
42
+ installing.)
43
+
44
+ For Emacs support and the Reference Manual, get
45
+ <tt>ruby-debug-extra</tt>. This is not a RubyGem, you'll need a Make
46
+ program and a POSIX shell. With this installed, run:
47
+
48
+ sh ./configure
49
+ make
50
+ make test # optional, but a good idea
51
+ sudo make install
52
+
53
+
54
+ ==== Install on MS Windows
55
+
56
+ Compiling under cygwin or mingw works like it does on Unix.
57
+
58
+ * Have Microsoft Visual C++ 6.0 (VC6) installed - exactly that version.
59
+
60
+ * Set the appropriate environment variables.
61
+
62
+ * run `nmake'.
63
+
64
+ * Copy ruby_debug.so to `win32'.
65
+
66
+ * Go to the ruby_debug root.
67
+
68
+ * rake win32_gem
69
+
70
+ * The file is in named `rdebug-debug-base-0.10.0-mswin32.gem'.
71
+
72
+ == Usage
73
+
74
+ There are two ways of running ruby-debug.
75
+
76
+ === rdebug executable:
77
+
78
+ $ rdebug <your-script>
79
+
80
+ When you start your script this way, the debugger will stop at
81
+ the first line of code in the script file. So you will be able
82
+ to set up your breakpoints.
83
+
84
+ === ruby-debug API
85
+
86
+ The second way is to use the ruby-debug API to interrupt your
87
+ code execution at run time.
88
+
89
+ require 'ruby-debug' ; Debugger.start
90
+ ...
91
+ def your_method
92
+ ...
93
+ debugger
94
+ ...
95
+ end
96
+
97
+ or
98
+
99
+ require 'ruby-debug' ;
100
+ Debugger.start do
101
+ ...
102
+ debugger
103
+ end
104
+
105
+ When Kernel#debugger method is executed, the debugger is activated
106
+ and you will be able to inspect and step through your code.
107
+
108
+ == Performance
109
+
110
+ The <tt>debug.rb</tt> script that comes with the standard Ruby library uses
111
+ <tt>Kernel#set_trace_func</tt> API. Implementing the debugger in pure Ruby has
112
+ a negative impact on the speed of your program execution. This is
113
+ because the Ruby interpreter creates a Binding object each trace call,
114
+ even though it is not being used most of the time. ruby-debug moves
115
+ most of the functionality for Binding access and for breakpoint
116
+ testing to a native extension. Because this code is in C and because
117
+ and can be selectively enabled or disabled, the overhead in running
118
+ your program can be minimized.
119
+
120
+ == License
121
+
122
+ See LICENSE for license information.
@@ -0,0 +1,141 @@
1
+ ## Description
2
+ A fork of ruby-debug(19) that works on 1.9.2 and 1.9.3 and installs easily for rvm/rbenv rubies.
3
+
4
+ [![Build Status](https://travis-ci.org/cldwalker/debugger.png?branch=master)](https://travis-ci.org/cldwalker/debugger)
5
+
6
+ ## Install
7
+
8
+ $ gem install debugger
9
+
10
+ # If install fails, try passing headers path
11
+ $ gem install debugger -- --with-ruby-include=PATH_TO_HEADERS
12
+
13
+ For Windows install instructions, see OLD\_README.
14
+
15
+
16
+ ## Supported Rubies
17
+ On install, debugger tries to find your ruby's headers. If it's unable to find them and your ruby is
18
+ a patch release, it will use headers included with
19
+ [debugger-ruby_core_source](https://github.com/cldwalker/debugger-ruby_core_source). For the list
20
+ of rubies supported by debugger [see
21
+ here](https://github.com/cldwalker/debugger-ruby_core_source/tree/master/lib/debugger/ruby_core_source).
22
+ *If your ruby is not an official patch release i.e. head, dev or an rc, you are responsible for
23
+ having headers and setting them with --with-ruby-include.*
24
+
25
+ ## Usage
26
+
27
+ Wherever you need a debugger, simply:
28
+
29
+ ```ruby
30
+ require 'debugger'; debugger
31
+ ```
32
+
33
+ To use with bundler, drop in your Gemfile:
34
+
35
+ gem 'debugger'
36
+
37
+ ### Configuration
38
+
39
+ At initialization time, debugger loads config files, executing their lines
40
+ as if they were actual commands a user has typed. config files are loaded
41
+ from two locations:
42
+
43
+ * ~/.rdebugrc (~/rdebug.ini for windows)
44
+ * $PWD/.rdebugrc ($PWD/rdebug.ini for windows)
45
+
46
+ Here's a common configuration (yeah, I should make this the default):
47
+
48
+ set autolist
49
+ set autoeval
50
+ set autoreload
51
+
52
+ To see debugger's current settings, use the `set` command.
53
+
54
+ ### Using Commands
55
+
56
+ For a list of commands:
57
+
58
+ (rdb: 1) help
59
+
60
+ Most commands are described in rdebug's man page
61
+
62
+ $ gem install gem-man
63
+ $ man rdebug
64
+
65
+ ### More documentation
66
+
67
+ Some thorough documentation of debugger is found with [this bashdb
68
+ tutorial](http://bashdb.sourceforge.net/ruby-debug.html). For emacs and debugger
69
+ usage, see [another bashdb
70
+ tutorial](http://bashdb.sourceforge.net/ruby-debug/rdebug-emacs.html)
71
+
72
+ ## Reason for Fork
73
+
74
+ * ruby-debug19 maintainer isn't maintaining:
75
+ * Despite patches from ruby core, no gem release in 2+ years! - 9/1/09.
76
+ * Requests to release a known working 1.9.3 version have been ignored.
77
+ * Doesn't respond to rubyforge issues and doesn't have github issues open.
78
+ * Current install is painful. Requires either [manually downloading gems from rubyforge](
79
+ http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug) and installing with compiler flags
80
+ or [recompiling
81
+ ruby](http://blog.sj26.com/post/12146951658/updated-using-ruby-debug-on-ruby-1-9-3-p0).
82
+ * We need a decent ruby debugger for future rubies!
83
+
84
+ ## What's different from ruby-debug19
85
+
86
+ * Major
87
+ * Works on 1.9.2 and 1.9.3
88
+ * 1.9.2 points to ruby-debug-base19-0.11.25 headers
89
+ * 1.9.3 points to ruby-debug-base19-0.11.26 headers
90
+ * Install painlessly for rvm and rbenv rubies i.e. no compiler flags needed
91
+ * No downloading ruby source during install - was behavior of old ruby_core_source dependency
92
+ * Fix LocalJumpError caused by using proc in extconf.rb
93
+ * Fix where command failing at top level
94
+ * A new and improved test suite
95
+ * Passing tests are up on travis-ci
96
+ * Minor
97
+ * The gem name matches the module namespace, Debugger, and main required file, debugger.
98
+ * ruby-debug-base19 and ruby-debug19 are released as one gem
99
+ * Rake tasks have been updated
100
+ * No more $LOAD_PATH manipulation or runtime code outside of lib
101
+ * man page available via gem-man
102
+
103
+ ## Issues
104
+ Please report them [on github](http://github.com/cldwalker/debugger/issues).
105
+
106
+ ## Known Issues
107
+ * 2.0.0 support is only partially working and the test suite dies before it can finish.
108
+ * If you place a debugger call at the end of a block, debugging will start at the next step and
109
+ outside of your block. A simple work-around is to place a meaningless step (i.e. puts "STAY")
110
+ at the end of your block and before debugger.
111
+
112
+ ## Contributing
113
+ [See here](http://tagaholic.me/contributing.html) for contribution policies.
114
+ Let's keep this working for the ruby community!
115
+
116
+ ## Related projects
117
+
118
+ * [debugger-completion](https://github.com/cldwalker/debugger-completion) - autocompletion for
119
+ debugger commands and more
120
+ * [debugger-pry](https://github.com/pry/debugger-pry) - using pry within debugger
121
+ * [pry-debugger](https://github.com/nixme/pry-debugger) - using debugger within pry
122
+ * [ruby-debug-passenger](https://github.com/davejamesmiller/ruby-debug-passenger) - rake task to
123
+ restart Passenger with debugger connected
124
+ * [jruby-debug](https://github.com/jruby/jruby-debug)
125
+ * [rb-trepanning](https://github.com/rocky/rb-trepanning) - rewrite of ruby-debug that requires a
126
+ patched ruby
127
+
128
+ ## Credits
129
+
130
+ * Thanks to the original authors: Kent Sibilev and Mark Moseley
131
+ * Thanks to astashov for bringing in a new and improved test suite and various bug fixes.
132
+ * Thanks to windwiny for porting to 2.0.0
133
+ * Contributors: ericpromislow, jnimety, adammck, hipe, FooBarWidget, aghull
134
+ * Fork started on awesome @relevance fridays!
135
+
136
+ ## TODO
137
+
138
+ * Fix test/test-*.rb
139
+ * Port some of bashdb's docs
140
+ * Use ~/.debuggerrc and bin/debugger and gracefully deprecate rdebug*
141
+ * Work with others willing to tackle jruby, rubinius or windows support
@@ -0,0 +1,78 @@
1
+ # -*- Ruby -*-
2
+ require 'rubygems/package_task'
3
+ require 'rake/testtask'
4
+ require 'rake/extensiontask'
5
+
6
+ Rake::ExtensionTask.new('ruby_debug')
7
+
8
+ SO_NAME = "ruby_debug.so"
9
+
10
+ desc "Run new MiniTest tests."
11
+ task :test do
12
+ Rake::TestTask.new(:test) do |t|
13
+ t.test_files = FileList["test/*_test.rb"]
14
+ t.verbose = true
15
+ end
16
+ end
17
+
18
+ desc "Test everything - same as test."
19
+ task :check => :test
20
+
21
+ desc "Create the core ruby-debug shared library extension"
22
+ task :lib do
23
+ Dir.chdir("ext") do
24
+ system("#{Gem.ruby} extconf.rb && make")
25
+ end
26
+ end
27
+
28
+ desc "Compile Emacs code"
29
+ task :emacs => "emacs/rdebug.elc"
30
+ file "emacs/rdebug.elc" => ["emacs/elisp-comp", "emacs/rdebug.el"] do
31
+ Dir.chdir("emacs") do
32
+ system("./elisp-comp ./rdebug.el")
33
+ end
34
+ end
35
+
36
+ base_spec = eval(File.read('debugger.gemspec'), binding, 'debugger.gemspec')
37
+ # Rake task to build the default package
38
+ Gem::PackageTask.new(base_spec) do |pkg|
39
+ pkg.need_tar = true
40
+ end
41
+
42
+ # Windows specification
43
+ win_spec = base_spec.clone
44
+ win_spec.extensions = []
45
+ ## win_spec.platform = Gem::Platform::WIN32 # deprecated
46
+ win_spec.platform = 'mswin32'
47
+ win_spec.files += ["lib/#{SO_NAME}"]
48
+
49
+ desc "Create Windows Gem"
50
+ task :win32_gem do
51
+ # Copy the win32 extension the top level directory
52
+ current_dir = File.expand_path(File.dirname(__FILE__))
53
+ source = File.join(current_dir, "ext", "win32", SO_NAME)
54
+ target = File.join(current_dir, "lib", SO_NAME)
55
+ cp(source, target)
56
+
57
+ # Create the gem, then move it to pkg.
58
+ Gem::Builder.new(win_spec).build
59
+ gem_file = "#{win_spec.name}-#{win_spec.version}-#{win_spec.platform}.gem"
60
+ mv(gem_file, "pkg/#{gem_file}")
61
+
62
+ # Remove win extension from top level directory.
63
+ rm(target)
64
+ end
65
+
66
+ desc "Remove built files"
67
+ task :clean do
68
+ cd "ext" do
69
+ if File.exists?("Makefile")
70
+ sh "make clean"
71
+ rm "Makefile"
72
+ end
73
+ derived_files = Dir.glob(".o") + Dir.glob("*.so")
74
+ rm derived_files unless derived_files.empty?
75
+ end
76
+ end
77
+
78
+ task :default => :test
@@ -0,0 +1,397 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #=== Summary
4
+ #
5
+ #A command-line front-end to the Ruby debugger, <tt>debugger</tt>, the
6
+ #Fast Ruby Debugger.
7
+ #
8
+ #Command invocation:
9
+ #
10
+ # rdebug [options] [--] [script-options] ruby-script-to-debug
11
+ # rdebug [options] [script-options] [--client]
12
+ # rdebug [--version | --help]
13
+ #
14
+ #=== Options
15
+ #
16
+ #<tt>-A | --annotate</tt> <i>level</i>::
17
+ # Set gdb-style annotation to <i>level</i>, a number. Additional
18
+ # information is output automatically when program state is
19
+ # changed. This can be used by front-ends such as GNU Emacs to post
20
+ # this updated information without having to poll for it.
21
+ #
22
+ #<tt>--client</tt>::
23
+ # Connect to a remote debugger. Used with another rdebug invocation
24
+ # using <tt>--server</tt>. See also <tt>--host</tt> and
25
+ # <tt>--cport</tt> options
26
+ #
27
+ #<tt>--cport=</tt><i>port</i>::
28
+ # Use port <i>port</i> for access to debugger control.
29
+ #
30
+ #<tt>-d | --debug</tt>::
31
+ # Set $DEBUG true.
32
+ #
33
+ #<tt>--emacs</tt>::
34
+ # Activates full GNU Emacs mode. Is the equivalent of setting the
35
+ # options <tt>--emacs-basic --annotate=3 --no-stop --no-control
36
+ # --post-mortem</tt>.
37
+ #
38
+ #<tt>--emacs-basic</tt>::
39
+ # Activates GNU Emacs mode. Debugger prompts are prefaced with two
40
+ # octal 032 characters.
41
+ #
42
+ #<tt>-h | --host=</tt><i>host</i>::
43
+ # Use host name <i>host</i> for remote debugging.
44
+ #
45
+ #<tt>-I | --include</tt> <i>path</i>
46
+ # Add <i>path</i> to <tt>$LOAD_PATH</tt>
47
+ #
48
+ #<tt>-m | --post-mortem</tt>::
49
+ # Activate post-mortem mode.
50
+ #
51
+ #<tt>--no-control</tt>::
52
+ # Do not automatically start control thread.
53
+ #
54
+ #<tt>--no-stop</tt>::
55
+ # Do not stop when script is loaded.
56
+ #
57
+ #<tt>-p | --port=PORT</tt>::
58
+ # Host name used for remote debugging.
59
+ #
60
+ #<tt>-r | --require</tt><i>script</i>::
61
+ # Require the library, before executing your script.
62
+ #
63
+ #<tt>--script</tt> <i>file</i>::
64
+ # Run debugger script file <i>file</i>
65
+ #
66
+ #<tt>-x | --trace</tt>::
67
+ # Show lines before executing them.
68
+ #
69
+ #<tt>--no-quit</tt>::
70
+ # Do not quit when script terminates. Instead rerun the
71
+ # program.
72
+ #
73
+ #<tt>--version</tt>::
74
+ # Show the version number and exit.
75
+ #
76
+ #<tt>--verbose</tt>::
77
+ # Turn on verbose mode.
78
+ #
79
+ #<tt>--v</tt>::
80
+ # Print the version number, then turn on verbose mode if
81
+ # a script name is given. If no script name is given
82
+ # just exit after printing the version number.
83
+ #
84
+ #<tt>--nx</tt>::
85
+ # Don’t execute commands found in any initialization
86
+ # files, e.g. <tt>.rdebugrc</tt>.
87
+ #
88
+ #<tt>--keep-frame-binding</tt>::
89
+ # Keep frame bindings.
90
+ #
91
+ #<tt>--script=</tt><i>file</i>::
92
+ # Name of the script file to run
93
+ #
94
+ #<tt>-s | --server</tt>::
95
+ # Listen for remote connections. Another rdebug session
96
+ # accesses using the <tt>--client</tt> option. See also the
97
+ # <tt>--host</tt>, <tt>--port</tt> and <tt>--cport</tt> options
98
+ #
99
+ #<tt>-w | --wait</tt>::
100
+ # Wait for a client connection; implies <tt>-s</tt> option.
101
+ #
102
+ #<tt>--help</tt>::
103
+ # Show invocation help and exit.
104
+
105
+ require 'optparse'
106
+ require 'ostruct'
107
+ require 'debugger'
108
+
109
+ def debug_program(options)
110
+ # Make sure Ruby script syntax checks okay.
111
+ # Otherwise we get a load message that looks like rdebug has
112
+ # a problem.
113
+ output = `ruby -c "#{Debugger::PROG_SCRIPT}" 2>&1`
114
+ if $?.exitstatus != 0 and RUBY_PLATFORM !~ /mswin/
115
+ puts output
116
+ exit $?.exitstatus
117
+ end
118
+ print "\032\032starting\n" if Debugger.annotate and Debugger.annotate > 2
119
+
120
+ # Record where we are we can know if the call stack has been
121
+ # truncated or not.
122
+ Debugger.start_sentinal=caller(0)[1]
123
+
124
+ bt = Debugger.debug_load(Debugger::PROG_SCRIPT, options.stop, false)
125
+ if bt
126
+ print bt.backtrace.map{|l| "\t#{l}"}.join("\n"), "\n"
127
+ print "Uncaught exception: #{bt}\n"
128
+ end
129
+ end
130
+
131
+ # Do a shell-like path lookup for prog_script and return the results.
132
+ # If we can't find anything return prog_script.
133
+ def whence_file(prog_script)
134
+ if prog_script.index(File::SEPARATOR)
135
+ # Don't search since this name has path separator components
136
+ return prog_script
137
+ end
138
+ for dirname in ENV['PATH'].split(File::PATH_SEPARATOR) do
139
+ prog_script_try = File.join(dirname, prog_script)
140
+ return prog_script_try if File.exist?(prog_script_try)
141
+ end
142
+ # Failure
143
+ return prog_script
144
+ end
145
+
146
+ options = OpenStruct.new(
147
+ 'annotate' => Debugger.annotate,
148
+ 'client' => false,
149
+ 'control' => true,
150
+ 'cport' => Debugger::PORT + 1,
151
+ 'host' => nil,
152
+ 'quit' => true,
153
+ 'no_rewrite_program' => false,
154
+ 'stop' => true,
155
+ 'nx' => false,
156
+ 'port' => Debugger::PORT,
157
+ 'restart_script' => nil,
158
+ 'script' => nil,
159
+ 'server' => false,
160
+ 'tracing' => false,
161
+ 'verbose_long' => false,
162
+ 'wait' => false
163
+ )
164
+
165
+ def process_options(options)
166
+ program = File.basename($0)
167
+ opts = OptionParser.new do |opts|
168
+ opts.banner = <<EOB
169
+ #{program} #{Debugger::VERSION}
170
+ Usage: #{program} [options] <script.rb> -- <script.rb parameters>
171
+ EOB
172
+ opts.separator ""
173
+ opts.separator "Options:"
174
+ opts.on("-A", "--annotate LEVEL", Integer, "Set annotation level") do
175
+ |annotate|
176
+ Debugger.annotate = annotate
177
+ end
178
+ opts.on("-c", "--client", "Connect to remote debugger") do
179
+ options.client = true
180
+ end
181
+ opts.on("--cport PORT", Integer, "Port used for control commands") do
182
+ |cport|
183
+ options.cport = cport
184
+ end
185
+ opts.on("-d", "--debug", "Set $DEBUG=true") {$DEBUG = true}
186
+ opts.on("--emacs LEVEL", Integer,
187
+ "Activates full Emacs support at annotation level LEVEL") do
188
+ |level|
189
+ Debugger.annotate = level.to_i
190
+ ENV['EMACS'] = '1'
191
+ ENV['COLUMNS'] = '120' if ENV['COLUMNS'].to_i < 120
192
+ options.control = false
193
+ options.quit = false
194
+ end
195
+ opts.on('--emacs-basic', 'Activates basic Emacs mode') do
196
+ ENV['EMACS'] = '1'
197
+ end
198
+ opts.on('-h', '--host HOST', 'Host name used for remote debugging') do
199
+ |host|
200
+ options.host = host
201
+ end
202
+ opts.on('-I', '--include PATH', String, 'Add PATH to $LOAD_PATH') do |path|
203
+ $LOAD_PATH.unshift(path)
204
+ end
205
+ opts.on('--no-control', 'Do not automatically start control thread') do
206
+ options.control = false
207
+ end
208
+ opts.on('--no-quit', 'Do not quit when script finishes') do
209
+ options.quit = false
210
+ end
211
+ opts.on('--no-rewrite-program',
212
+ 'Do not set $0 to the program being debugged') do
213
+ options.no_rewrite_program = true
214
+ end
215
+ opts.on('--no-stop', 'Do not stop when script is loaded') do
216
+ options.stop = false
217
+ end
218
+ opts.on('-nx', 'Not run debugger initialization files (e.g. .rdebugrc') do
219
+ options.nx = true
220
+ end
221
+ opts.on('-p', '--port PORT', Integer, 'Port used for remote debugging') do
222
+ |port|
223
+ options.port = port
224
+ end
225
+ opts.on('-r', '--require SCRIPT', String,
226
+ 'Require the library, before executing your script') do |name|
227
+ if name == 'debug'
228
+ puts "debugger is not compatible with Ruby's 'debug' library. This option is ignored."
229
+ else
230
+ require name
231
+ end
232
+ end
233
+ opts.on('--restart-script FILE', String,
234
+ 'Name of the script file to run. Erased after read') do
235
+ |restart_script|
236
+ options.restart_script = restart_script
237
+ unless File.exists?(options.restart_script)
238
+ puts "Script file '#{options.restart_script}' is not found"
239
+ exit
240
+ end
241
+ end
242
+ opts.on('--script FILE', String, 'Name of the script file to run') do
243
+ |script|
244
+ options.script = script
245
+ unless File.exists?(options.script)
246
+ puts "Script file '#{options.script}' is not found"
247
+ exit
248
+ end
249
+ end
250
+ opts.on('-s', '--server', 'Listen for remote connections') do
251
+ options.server = true
252
+ end
253
+ opts.on('-w', '--wait', 'Wait for a client connection, implies -s option') do
254
+ options.wait = true
255
+ end
256
+ opts.on('-x', '--trace', 'Turn on line tracing') {options.tracing = true}
257
+ opts.separator ''
258
+ opts.separator 'Common options:'
259
+ opts.on_tail('--help', 'Show this message') do
260
+ puts opts
261
+ exit
262
+ end
263
+ opts.on_tail('--version',
264
+ 'Print the version') do
265
+ puts "debugger #{Debugger::VERSION}"
266
+ exit
267
+ end
268
+ opts.on('--verbose', 'Turn on verbose mode') do
269
+ $VERBOSE = true
270
+ options.verbose_long = true
271
+ end
272
+ opts.on_tail('-v',
273
+ 'Print version number, then turn on verbose mode') do
274
+ puts "debugger #{Debugger::VERSION}"
275
+ $VERBOSE = true
276
+ end
277
+ end
278
+ return opts
279
+ end
280
+
281
+ # What file is used for debugger startup commands.
282
+ unless defined?(OPTS_INITFILE)
283
+ if RUBY_PLATFORM =~ /mswin/
284
+ # Of course MS Windows has to be different
285
+ OPTS_INITFILE = 'rdbopt.ini'
286
+ HOME_DIR = (ENV['HOME'] ||
287
+ ENV['HOMEDRIVE'].to_s + ENV['HOMEPATH'].to_s).to_s
288
+ else
289
+ OPTS_INITFILE = '.rdboptrc'
290
+ HOME_DIR = ENV['HOME'].to_s
291
+ end
292
+ end
293
+ begin
294
+ initfile = File.join(HOME_DIR, OPTS_INITFILE)
295
+ eval(File.read(initfile)) if
296
+ File.exist?(initfile)
297
+ rescue
298
+ end
299
+
300
+ opts = process_options(options)
301
+ begin
302
+ if not defined? Debugger::ARGV
303
+ Debugger::ARGV = ARGV.clone
304
+ end
305
+ rdebug_path = File.expand_path($0)
306
+ if RUBY_PLATFORM =~ /mswin/
307
+ rdebug_path += '.cmd' unless rdebug_path =~ /\.cmd$/i
308
+ end
309
+ Debugger::RDEBUG_SCRIPT = rdebug_path
310
+ Debugger::RDEBUG_FILE = __FILE__
311
+ Debugger::INITIAL_DIR = Dir.pwd
312
+ opts.parse! ARGV
313
+ rescue StandardError => e
314
+ puts opts
315
+ puts
316
+ puts e.message
317
+ exit(-1)
318
+ end
319
+
320
+ if options.client
321
+ Debugger.start_client(options.host, options.port)
322
+ else
323
+ if ARGV.empty?
324
+ exit if $VERBOSE and not options.verbose_long
325
+ puts opts
326
+ puts
327
+ puts 'Must specify a script to run'
328
+ exit(-1)
329
+ end
330
+
331
+ # save script name
332
+ prog_script = ARGV.shift
333
+ prog_script = whence_file(prog_script) unless File.exist?(prog_script)
334
+ Debugger::PROG_SCRIPT = File.expand_path prog_script
335
+
336
+ # install interruption handler
337
+ trap('INT') { Debugger.interrupt_last }
338
+
339
+ # set options
340
+ Debugger.wait_connection = options.wait
341
+
342
+ if options.server
343
+ # start remote mode
344
+ Debugger.start_remote(options.host, [options.port, options.cport]) do
345
+ # load initrc script
346
+ Debugger.run_init_script(StringIO.new) unless options.nx
347
+ end
348
+ debug_program(options)
349
+ else
350
+ # Set up trace hook for debugger
351
+ Debugger.start
352
+ # start control thread
353
+ Debugger.start_control(options.host, options.cport) if options.control
354
+
355
+ # load initrc script (e.g. .rdebugrc)
356
+ Debugger.run_init_script(StringIO.new) unless options.nx
357
+
358
+ # run restore-settings startup script if specified
359
+ if options.restart_script
360
+ require 'fileutils'
361
+ Debugger.run_script(options.restart_script)
362
+ FileUtils.rm(options.restart_script)
363
+ end
364
+
365
+ # run startup script if specified
366
+ if options.script
367
+ Debugger.run_script(options.script)
368
+ end
369
+
370
+ options.stop = false if options.tracing
371
+ Debugger.tracing = options.tracing
372
+
373
+ if !options.quit
374
+ if Debugger.started?
375
+ until Debugger.stop do end
376
+ end
377
+ begin
378
+ debug_program(options)
379
+ rescue SyntaxError
380
+ puts $!.backtrace.map{|l| "\t#{l}"}.join("\n")
381
+ puts "Uncaught Syntax Error\n"
382
+ rescue
383
+ print $!.backtrace.map{|l| "\t#{l}"}.join("\n"), "\n"
384
+ print "Uncaught exception: #{$!}\n"
385
+ end
386
+ print "The program finished.\n" unless
387
+ Debugger.annotate.to_i > 1 # annotate has its own way
388
+ interface = Debugger::LocalInterface.new
389
+ # Not sure if ControlCommandProcessor is really the right
390
+ # thing to use. CommandProcessor requires a state.
391
+ processor = Debugger::ControlCommandProcessor.new(interface)
392
+ processor.process_commands
393
+ else
394
+ debug_program(options)
395
+ end
396
+ end
397
+ end