| Path: | bin/rdebug |
| Last Update: | Wed Jun 02 23:23:19 -0400 2010 |
A command-line front-end to the Ruby debugger, ruby-debug, the Fast Ruby Debugger.
Command invocation:
rdebug [options] [--] [script-options] ruby-script-to-debug rdebug [options] [script-options] [--client] rdebug [--version | --help]
| -A | —annotate level: | Set gdb-style annotation to level, a number. Additional information is output automatically when program state is changed. This can be used by front-ends such as GNU Emacs to post this updated information without having to poll for it. |
| —client: | Connect to a remote debugger. Used with another rdebug invocation using —server. See also —host and —cport options |
| —cport=port: | Use port port for access to debugger control. |
| -d | —debug: | Set $DEBUG true. |
| —emacs: | Activates full GNU Emacs mode. Is the equivalent of setting the options —emacs-basic —annotate=3 —no-stop —no-control —post-mortem. |
| —emacs-basic: | Activates GNU Emacs mode. Debugger prompts are prefaced with two octal 032 characters. |
| -h | —host=host: | Use host name host for remote debugging. |
-I | —include path
Add <i>path</i> to <tt>$LOAD_PATH</tt>
| -m | —post-mortem: | Activate post-mortem mode. |
| —no-control: | Do not automatically start control thread. |
| —no-stop: | Do not stop when script is loaded. |
| -p | —port=PORT: | Host name used for remote debugging. |
| -r | —requirescript: | Require the library, before executing your script. |
| —script file: | Run debugger script file file |
| -x | —trace: | Show lines before executing them. |
| —no-quit: | Do not quit when script terminates. Instead rerun the program. |
| —version: | Show the version number and exit. |
| —verbose: | Turn on verbose mode. |
| —v: | Print the version number, then turn on verbose mode if a script name is given. If no script name is given |
just exit after printing the version number.
| —nx: | Don’t execute commands found in any initialization files, e.g. .rdebugrc. |
| —keep-frame-binding: | Keep frame bindings. |
| —script=file: | Name of the script file to run |
| -s | —server: | Listen for remote connections. Another rdebug session accesses using the —client option. See also the —host, —port and —cport options |
| -w | —wait: | Wait for a client connection; implies -s option. |
| —help: | Show invocation help and exit. |
| OPTS_INITFILE | = | 'rdbopt.ini' | Of course MS Windows has to be different | |
| HOME_DIR | = | (ENV['HOME'] || ENV['HOMEDRIVE'].to_s + ENV['HOMEPATH'].to_s).to_s | ||
| OPTS_INITFILE | = | '.rdboptrc' | ||
| HOME_DIR | = | ENV['HOME'].to_s | ||
| ARGV | = | ARGV.clone | ||
| RDEBUG_SCRIPT | = | rdebug_path | ||
| RDEBUG_FILE | = | __FILE__ | ||
| INITIAL_DIR | = | Dir.pwd | ||
| PROG_SCRIPT | = | File.expand_path prog_script |
# File bin/rdebug, line 111
111: def debug_program(options)
112: # Make sure Ruby script syntax checks okay.
113: # Otherwise we get a load message that looks like rdebug has
114: # a problem.
115: output = `ruby -c #{Debugger::PROG_SCRIPT.inspect} 2>&1`
116: if $?.exitstatus != 0 and RUBY_PLATFORM !~ /mswin/
117: puts output
118: exit $?.exitstatus
119: end
120: print "\032\032starting\n" if Debugger.annotate and Debugger.annotate > 2
121:
122: # Record where we are we can know if the call stack has been
123: # truncated or not.
124: Debugger.start_sentinal=caller(0)[1]
125:
126: bt = Debugger.debug_load(Debugger::PROG_SCRIPT, options.stop, false)
127: if bt
128: if options.post_mortem
129: Debugger.handle_post_mortem(bt)
130: else
131: print bt.backtrace.map{|l| "\t#{l}"}.join("\n"), "\n"
132: print "Uncaught exception: #{bt}\n"
133: end
134: end
135: end
# File bin/rdebug, line 173
173: def process_options(options)
174: program = File.basename($0)
175: opts = OptionParser.new do |opts|
176: opts.banner = "\#{program} \#{Debugger::VERSION}\nUsage: \#{program} [options] <script.rb> -- <script.rb parameters>\n"
177: opts.separator ""
178: opts.separator "Options:"
179: opts.on("-A", "--annotate LEVEL", Integer, "Set annotation level") do
180: |annotate|
181: Debugger.annotate = annotate
182: end
183: opts.on("-c", "--client", "Connect to remote debugger") do
184: options.client = true
185: end
186: opts.on("--cport PORT", Integer, "Port used for control commands") do
187: |cport|
188: options.cport = cport
189: end
190: opts.on("-d", "--debug", "Set $DEBUG=true") {$DEBUG = true}
191: opts.on("--emacs LEVEL", Integer,
192: "Activates full Emacs support at annotation level LEVEL") do
193: |level|
194: Debugger.annotate = level.to_i
195: ENV['EMACS'] = '1'
196: ENV['COLUMNS'] = '120' if ENV['COLUMNS'].to_i < 120
197: options.control = false
198: options.quit = false
199: options.post_mortem = true
200: end
201: opts.on('--emacs-basic', 'Activates basic Emacs mode') do
202: ENV['EMACS'] = '1'
203: end
204: opts.on('-h', '--host HOST', 'Host name used for remote debugging') do
205: |host|
206: options.host = host
207: end
208: opts.on('-I', '--include PATH', String, 'Add PATH to $LOAD_PATH') do |path|
209: $LOAD_PATH.unshift(path)
210: end
211: opts.on('--keep-frame-binding', 'Keep frame bindings') do
212: options.frame_bind = true
213: end
214: opts.on('-m', '--post-mortem', 'Activate post-mortem mode') do
215: options.post_mortem = true
216: end
217: opts.on('--no-control', 'Do not automatically start control thread') do
218: options.control = false
219: end
220: opts.on('--no-quit', 'Do not quit when script finishes') do
221: options.quit = false
222: end
223: opts.on('--no-rewrite-program',
224: 'Do not set $0 to the program being debugged') do
225: options.no_rewrite_program = true
226: end
227: opts.on('--no-stop', 'Do not stop when script is loaded') do
228: options.stop = false
229: end
230: opts.on('-nx', 'Not run debugger initialization files (e.g. .rdebugrc') do
231: options.nx = true
232: end
233: opts.on('-p', '--port PORT', Integer, 'Port used for remote debugging') do
234: |port|
235: options.port = port
236: end
237: opts.on('-r', '--require SCRIPT', String,
238: 'Require the library, before executing your script') do |name|
239: if name == 'debug'
240: puts "ruby-debug is not compatible with Ruby's 'debug' library. This option is ignored."
241: else
242: require name
243: end
244: end
245: opts.on('--restart-script FILE', String,
246: 'Name of the script file to run. Erased after read') do
247: |restart_script|
248: options.restart_script = restart_script
249: unless File.exists?(options.restart_script)
250: puts "Script file '#{options.restart_script}' is not found"
251: exit
252: end
253: end
254: opts.on('--script FILE', String, 'Name of the script file to run') do
255: |script|
256: options.script = script
257: unless File.exists?(options.script)
258: puts "Script file '#{options.script}' is not found"
259: exit
260: end
261: end
262: opts.on('-s', '--server', 'Listen for remote connections') do
263: options.server = true
264: end
265: opts.on('-w', '--wait', 'Wait for a client connection, implies -s option') do
266: options.wait = true
267: end
268: opts.on('-x', '--trace', 'Turn on line tracing') {options.tracing = true}
269: opts.separator ''
270: opts.separator 'Common options:'
271: opts.on_tail('--help', 'Show this message') do
272: puts opts
273: exit
274: end
275: opts.on_tail('--version',
276: 'Print the version') do
277: puts "ruby-debug #{Debugger::VERSION}"
278: exit
279: end
280: opts.on('--verbose', 'Turn on verbose mode') do
281: $VERBOSE = true
282: options.verbose_long = true
283: end
284: opts.on_tail('-v',
285: 'Print version number, then turn on verbose mode') do
286: puts "ruby-debug #{Debugger::VERSION}"
287: $VERBOSE = true
288: end
289: end
290: return opts
291: end
Do a shell-like path lookup for prog_script and return the results. If we can‘t find anything return prog_script.
# File bin/rdebug, line 139
139: def whence_file(prog_script)
140: if prog_script.index(File::SEPARATOR)
141: # Don't search since this name has path separator components
142: return prog_script
143: end
144: for dirname in ENV['PATH'].split(File::PATH_SEPARATOR) do
145: prog_script_try = File.join(dirname, prog_script)
146: return prog_script_try if File.exist?(prog_script_try)
147: end
148: # Failure
149: return prog_script
150: end