1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

and one more time

This commit is contained in:
Aditya Sanghi 2012-04-24 21:56:41 -05:00
parent 67ede88055
commit d6c831c198
7 changed files with 17 additions and 24 deletions

View file

@ -1,8 +1,8 @@
module Kernel module Kernel
unless respond_to?(:debugger) unless respond_to?(:debugger)
# Starts a debugging session if a debugger has been loaded (call rails server --debugger to do load it). # Starts a debugging session if the +debugger+ gem has been loaded (call rails server --debugger to do load it).
def debugger def debugger
message = "\n***** Debugger requested, but was not available (ensure debugger is listed in Gemfile/installed as gem): Start server with --debugger to enable *****\n" message = "\n***** Debugger requested, but was not available (ensure the debugger gem is listed in Gemfile/installed as gem): Start server with --debugger to enable *****\n"
defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message) defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message)
end end
alias breakpoint debugger unless respond_to?(:breakpoint) alias breakpoint debugger unless respond_to?(:breakpoint)

View file

@ -86,8 +86,8 @@ programming in general.
Debugger support is available through the debugger command when you start your Debugger support is available through the debugger command when you start your
Mongrel or WEBrick server with --debugger. This means that you can break out of Mongrel or WEBrick server with --debugger. This means that you can break out of
execution at any point in the code, investigate and change the model, and then, execution at any point in the code, investigate and change the model, and then,
resume execution! You need to install a debugger to run the server in debugging resume execution! You need to install the 'debugger' gem to run the server in debugging
mode. With gems, use <tt>gem install debugger</tt>. Example: mode. Add gem 'debugger' to your Gemfile and run <tt>bundle</tt> to install it. Example:
class WeblogController < ActionController::Base class WeblogController < ActionController::Base
def index def index

View file

@ -191,7 +191,7 @@ Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localh
Adding extra logging like this makes it easy to search for unexpected or unusual behavior in your logs. If you add extra logging, be sure to make sensible use of log levels, to avoid filling your production logs with useless trivia. Adding extra logging like this makes it easy to search for unexpected or unusual behavior in your logs. If you add extra logging, be sure to make sensible use of log levels, to avoid filling your production logs with useless trivia.
h3. Debugging with +debugger+ gem h3. Debugging with the +debugger+ gem
When your code is behaving in unexpected ways, you can try printing to logs or the console to diagnose the problem. Unfortunately, there are times when this sort of error tracking is not effective in finding the root cause of a problem. When you actually need to journey into your running source code, the debugger is your best companion. When your code is behaving in unexpected ways, you can try printing to logs or the console to diagnose the problem. Unfortunately, there are times when this sort of error tracking is not effective in finding the root cause of a problem. When you actually need to journey into your running source code, the debugger is your best companion.
@ -199,19 +199,13 @@ The debugger can also help you if you want to learn about the Rails source code
h4. Setup h4. Setup
The debugger used by Rails, +debugger+, comes as a gem. To install it, just run: Rails uses the +debugger+ gem to set breakpoints and step through live code. To install it, just run:
<shell> <shell>
$ gem install debugger $ gem install debugger
</shell> </shell>
TIP: If you are using Ruby 1.9, you can install a compatible version of +ruby-debug+ by running +gem install debugger+ Rails has had built-in support for debugging since Rails 2.0. Inside any Rails application you can invoke the debugger by calling the +debugger+ method.
In case you want to download a particular version or get the source code, refer to the "project's page on rubyforge":http://rubyforge.org/projects/ruby-debug/.
Rails has had built-in support for ruby-debug since Rails 2.0. Inside any Rails application you can invoke the debugger by calling the +debugger+ method.
+ruby-debug19+ gem has been replaced by the +debugger+ gem due to multiple issues on Ruby 1.9.3.
Here's an example: Here's an example:
@ -272,7 +266,7 @@ continue edit frame method putl set tmate where
TIP: To view the help menu for any command use +help &lt;command-name&gt;+ in active debug mode. For example: _+help var+_ TIP: To view the help menu for any command use +help &lt;command-name&gt;+ in active debug mode. For example: _+help var+_
The next command to learn is one of the most useful: +list+. You can also abbreviate the debugging commands by supplying just enough letters to distinguish them from other commands, so you can also use +l+ for the +list+ command. The next command to learn is one of the most useful: +list+. You can abbreviate any debugging command by supplying just enough letters to distinguish them from other commands, so you can also use +l+ for the +list+ command.
This command shows you where you are in the code by printing 10 lines centered around the current line; the current line in this particular case is line 6 and is marked by +=>+. This command shows you where you are in the code by printing 10 lines centered around the current line; the current line in this particular case is line 6 and is marked by +=>+.
@ -487,7 +481,7 @@ class Author < ActiveRecord::Base
end end
</ruby> </ruby>
TIP: You can use a debugger while using +rails console+. Just remember to +require "debugger"+ before calling the +debugger+ method. TIP: You can use the debugger while using +rails console+. Just remember to +require "debugger"+ before calling the +debugger+ method.
<shell> <shell>
$ rails console $ rails console
@ -605,7 +599,7 @@ A simple quit tries to terminate all threads in effect. Therefore your server wi
h4. Settings h4. Settings
There are some settings that can be configured in the +debugger+ gem to make it easier to debug your code. Here are a few of the available options: The +debugger+ gem can automatically show the code you're stepping through and reload it when you change it in an editor. Here are a few of the available options:
* +set reload+: Reload source code when changed. * +set reload+: Reload source code when changed.
* +set autolist+: Execute +list+ command on every breakpoint. * +set autolist+: Execute +list+ command on every breakpoint.
@ -614,7 +608,7 @@ There are some settings that can be configured in the +debugger+ gem to make it
You can see the full list by using +help set+. Use +help set _subcommand_+ to learn about a particular +set+ command. You can see the full list by using +help set+. Use +help set _subcommand_+ to learn about a particular +set+ command.
TIP: You can include any number of these configuration lines inside a +.rdebugrc+ file in your HOME directory. +debugger+ gem will read this file every time it is loaded and configure itself accordingly. TIP: You can save these settings in an +.rdebugrc+ file in your home directory. The debugger reads these global settings when it starts.
Here's a good start for an +.rdebugrc+: Here's a good start for an +.rdebugrc+:
@ -708,7 +702,6 @@ h3. References
* "debugger Homepage":http://github.com/cldwalker/debugger * "debugger Homepage":http://github.com/cldwalker/debugger
* "Article: Debugging a Rails application with ruby-debug":http://www.sitepoint.com/article/debug-rails-app-ruby-debug/ * "Article: Debugging a Rails application with ruby-debug":http://www.sitepoint.com/article/debug-rails-app-ruby-debug/
* "ruby-debug Basics screencast":http://brian.maybeyoureinsane.net/blog/2007/05/07/ruby-debug-basics-screencast/ * "ruby-debug Basics screencast":http://brian.maybeyoureinsane.net/blog/2007/05/07/ruby-debug-basics-screencast/
* "Ryan Bates' ruby-debug screencast":http://railscasts.com/episodes/54-debugging-with-ruby-debug
* "Ryan Bates' debugging ruby (revised) screencast":http://railscasts.com/episodes/54-debugging-ruby-revised * "Ryan Bates' debugging ruby (revised) screencast":http://railscasts.com/episodes/54-debugging-ruby-revised
* "Ryan Bates' stack trace screencast":http://railscasts.com/episodes/24-the-stack-trace * "Ryan Bates' stack trace screencast":http://railscasts.com/episodes/24-the-stack-trace
* "Ryan Bates' logger screencast":http://railscasts.com/episodes/56-the-logger * "Ryan Bates' logger screencast":http://railscasts.com/episodes/56-the-logger

View file

@ -27,7 +27,7 @@ module Rails
opt.on("-e", "--environment=name", String, opt.on("-e", "--environment=name", String,
"Specifies the environment to run this console under (test/development/production).", "Specifies the environment to run this console under (test/development/production).",
"Default: development") { |v| options[:environment] = v.strip } "Default: development") { |v| options[:environment] = v.strip }
opt.on("--debugger", 'Enable ruby debugging for the console.') { |v| options[:debugger] = v } opt.on("--debugger", 'Enable the debugger.') { |v| options[:debugger] = v }
opt.parse!(arguments) opt.parse!(arguments)
end end
@ -76,7 +76,7 @@ module Rails
require 'debugger' require 'debugger'
puts "=> Debugger enabled" puts "=> Debugger enabled"
rescue Exception rescue Exception
puts "You need to install a debugger to run the console in debugging mode. With gems, use 'gem install debugger'" puts "You're missing the 'debugger' gem. Add it to your Gemfile, bundle, and try again."
exit exit
end end
end end

View file

@ -17,7 +17,7 @@ module Rails
opts.on("-c", "--config=file", String, opts.on("-c", "--config=file", String,
"Use custom rackup configuration file") { |v| options[:config] = v } "Use custom rackup configuration file") { |v| options[:config] = v }
opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:daemonize] = true } opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:daemonize] = true }
opts.on("-u", "--debugger", "Enable ruby debugging for the server.") { options[:debugger] = true } opts.on("-u", "--debugger", "Enable the debugger") { options[:debugger] = true }
opts.on("-e", "--environment=name", String, opts.on("-e", "--environment=name", String,
"Specifies the environment to run this server under (test/development/production).", "Specifies the environment to run this server under (test/development/production).",
"Default: development") { |v| options[:environment] = v } "Default: development") { |v| options[:environment] = v }

View file

@ -86,8 +86,8 @@ programming in general.
Debugger support is available through the debugger command when you start your Debugger support is available through the debugger command when you start your
Mongrel or WEBrick server with --debugger. This means that you can break out of Mongrel or WEBrick server with --debugger. This means that you can break out of
execution at any point in the code, investigate and change the model, and then, execution at any point in the code, investigate and change the model, and then,
resume execution! You need to install a debugger to run the server in debugging resume execution! You need to install the 'debugger' gem to run the server in debugging
mode. With gems, use <tt>gem install debugger</tt>. Example: mode. Add gem 'debugger' to your Gemfile and run <tt>bundle</tt> to install it. Example:
class WeblogController < ActionController::Base class WeblogController < ActionController::Base
def index def index

View file

@ -12,7 +12,7 @@ module Rails
::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings) ::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings)
puts "=> Debugger enabled" puts "=> Debugger enabled"
rescue LoadError rescue LoadError
puts "You need to install a debugger to run the server in debugging mode. With gems, use 'gem install debugger'" puts "You're missing the 'debugger' gem. Add it to your Gemfile, bundle, and try again."
exit exit
end end