Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if a program is running in debug mode

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?

like image 644
ShockwaveNN Avatar asked Feb 26 '14 11:02

ShockwaveNN


2 Answers

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
like image 138
Abdo Avatar answered Oct 23 '22 23:10

Abdo


You need the global variable $LOAD_PATH.

a = $LOAD_PATH
a.each do |current_path|
    puts 'Debug mode' if current_path.include?('rb/gems')
end

$LOAD_PATH has this line "/home/username/RubyMine-6.0.2/rb/gems" if I use debug mode.

like image 44
Flamine Avatar answered Oct 23 '22 23:10

Flamine