|
| 1 | += ruby-debug |
| 2 | + |
| 3 | +== Overview |
| 4 | + |
| 5 | +ruby-debug is a fast implementation of the standard debugger debug.rb. |
| 6 | +The faster execution speed is achieved by utilizing a new hook in the |
| 7 | +Ruby C API. |
| 8 | + |
| 9 | +== Requirements |
| 10 | + |
| 11 | +ruby-debug requires Ruby 1.8.4 or higher. |
| 12 | + |
| 13 | +Unless you get the packages as a binary (Microsoft Windows binaries |
| 14 | +are sometimes available), you'll need a C compiler and Ruby |
| 15 | +development headers, and a Make program so the extension in |
| 16 | +ruby-debug-base can be compiled when it is installed. |
| 17 | + |
| 18 | +To install on Microsoft Windows, unless you run under cygwin or mingw |
| 19 | +you'll need Microsoft Visual C++ 6.0 also known as VC6. |
| 20 | +http://rubyforge.org/tracker/index.php?func=detail&aid=16774&group_id=1900&atid=7436 |
| 21 | +suggests why. |
| 22 | + |
| 23 | + |
| 24 | +== Install |
| 25 | + |
| 26 | +ruby-debug is provided as a RubyGem. To install: |
| 27 | + |
| 28 | +<tt>gem install ruby-debug</tt> |
| 29 | + |
| 30 | +This should also pull in <tt>ruby-debug-base</tt> as a dependency. |
| 31 | + |
| 32 | +(If you install ruby-debug-base explicitly, you can add in the <tt>--test</tt> |
| 33 | +option after "install" to have the regression test run before |
| 34 | +installing.) |
| 35 | + |
| 36 | +For Emacs support and the Reference Manual, get |
| 37 | +<tt>ruby-debug-extra</tt>. This is not a RubyGem, you'll need a Make |
| 38 | +program and a POSIX shell. With this installed, run: |
| 39 | + |
| 40 | + sh ./configure |
| 41 | + make |
| 42 | + make test # optional, but a good idea |
| 43 | + sudo make install |
| 44 | + |
| 45 | + |
| 46 | +==== Install on MS Windows |
| 47 | + |
| 48 | +Compiling under cygwin or mingw works like it does on Unix. |
| 49 | + |
| 50 | +* Have Microsoft Visual C++ 6.0 (VC6) installed - exactly that version. |
| 51 | + |
| 52 | +* Set the appropriate environment variables. |
| 53 | + |
| 54 | +* run `nmake'. |
| 55 | + |
| 56 | +* Copy ruby_debug.so to `win32'. |
| 57 | + |
| 58 | +* Go to the ruby_debug root. |
| 59 | + |
| 60 | +* rake win32_gem |
| 61 | + |
| 62 | +* The file is in named `rdebug-debug-base-0.10.0-mswin32.gem'. |
| 63 | + |
| 64 | +== Usage |
| 65 | + |
| 66 | +There are two ways of running ruby-debug. |
| 67 | + |
| 68 | +=== rdebug executable: |
| 69 | + |
| 70 | +$ rdebug <your-script> |
| 71 | + |
| 72 | +When you start your script this way, the debugger will stop at |
| 73 | +the first line of code in the script file. So you will be able |
| 74 | +to set up your breakpoints. |
| 75 | + |
| 76 | +=== ruby-debug API |
| 77 | + |
| 78 | +The second way is to use the ruby-debug API to interrupt your |
| 79 | +code execution at run time. |
| 80 | + |
| 81 | + require 'ruby-debug' ; Debugger.start |
| 82 | + ... |
| 83 | + def your_method |
| 84 | + ... |
| 85 | + debugger |
| 86 | + ... |
| 87 | + end |
| 88 | + |
| 89 | +or |
| 90 | + |
| 91 | + require 'ruby-debug' ; |
| 92 | + Debugger.start do |
| 93 | + ... |
| 94 | + debugger |
| 95 | + end |
| 96 | + |
| 97 | +When Kernel#debugger method is executed, the debugger is activated |
| 98 | +and you will be able to inspect and step through your code. |
| 99 | + |
| 100 | +== Performance |
| 101 | + |
| 102 | +The <tt>debug.rb</tt> script that comes with the standard Ruby library uses |
| 103 | +<tt>Kernel#set_trace_func</tt> API. Implementing the debugger in pure Ruby has |
| 104 | +a negative impact on the speed of your program execution. This is |
| 105 | +because the Ruby interpreter creates a Binding object each trace call, |
| 106 | +even though it is not being used most of the time. ruby-debug moves |
| 107 | +most of the functionality for Binding access and for breakpoint |
| 108 | +testing to a native extension. Because this code is in C and because |
| 109 | +and can be selectively enabled or disabled, the overhead in running |
| 110 | +your program can be minimized. |
| 111 | + |
| 112 | +== License |
| 113 | + |
| 114 | +See LICENSE for license information. |
0 commit comments