Determine if a program is running in debug mode
ruby, ruby-debug
Solution
This is what I did:
I put the following code in an (rails) action and did a diff on the outputs both in debug and non-debug modes:
puts ENV.to_hash.to_yaml
I noticed that one of the differences is in `ENV['RUBYLIB']` (there's also `IDE_PROCESS_DISPATCHER`, `DEBUGGER_STORED_RUBYLIB`, `RUBYOPT`, `and DEBUGGER_HOST`)
So here's how you'd check:
if ENV['RUBYLIB'] =~ /ruby-debug-ide/
puts 'in debug mode'
else
puts 'not in debug mode'
end
Problem
I use RubyMine to write and debug my Ruby 2.0 code. It uses ruby-debug-ide for that purpose. I want to know if a program is running in debug mode. I know there is the Ruby `$DEBUG` global variable, but as far as I understand ruby-debug-ide didn't change it, because it didn't use the `-d` ruby flag. If I debug my file using Rubymine the command executed looks like this: ``` /home/user/.rvm/rubies/ruby-2.0.0-p353/bin/ruby -e at_exit{sleep(1)};$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /home/user/.rvm/gems/ruby-2.0.0-p353/gems/ruby-debug-ide-0.4.22/bin/rdebug-ide --disable-int-handler --port 37737 --dispatcher-port 47992 -- /home/user/file.rb ``` I tried to use `ARGV` or `$0`, to determine if the command line contains the string `'rdebug-ide'` but `ARGV` is an empty array and `$0` is just `'/home/user/file.rb'`, how can I get the full command line executed by RubyMine?