From 535f69b56d8c1f3179020058afd4580d5d2184b8 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 13 Nov 2014 09:19:07 -0600 Subject: [PATCH 1/2] Append to RUBYOPT for debugger compatibility MSP-11147 When using Rubymine's debugger, the tests would run and say there were no tests and no break points would be hit. It was determined that this was due the Rubymine's debugger injecting itself into RUBYOPTS and only working if it's first in RUBYOPT, which means that 'metasploit:framework:spec:threads:suite' must inject '-Ilib -rmetasploit/framework/spec/threads/logger' at the end of RUBOPT instead of the beginning. --- lib/metasploit/framework/spec/threads/suite.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/metasploit/framework/spec/threads/suite.rb b/lib/metasploit/framework/spec/threads/suite.rb index 132624847d..2a4b81ced3 100644 --- a/lib/metasploit/framework/spec/threads/suite.rb +++ b/lib/metasploit/framework/spec/threads/suite.rb @@ -118,7 +118,8 @@ module Metasploit threads_logger_pathname = parent_pathname.join('logger') load_pathname = parent_pathname.parent.parent.parent.parent.expand_path - ENV['RUBYOPT'] = "-I#{load_pathname} -r#{threads_logger_pathname} #{ENV['RUBYOPT']}" + # Must append to RUBYOPT or Rubymine debugger will not work + ENV['RUBYOPT'] = "#{ENV['RUBYOPT']} -I#{load_pathname} -r#{threads_logger_pathname}" end Rake::Task.define_task(spec: 'metasploit:framework:spec:threads:suite') From b17b263cc73f08abcc04b6b3ab9d202a9306256a Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 13 Nov 2014 09:49:08 -0600 Subject: [PATCH 2/2] Ignore debugger threads MSP-11147 When using the debugger, it adds a thread that should be allowed and not go towards the count. --- lib/metasploit/framework/spec/threads/suite.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/metasploit/framework/spec/threads/suite.rb b/lib/metasploit/framework/spec/threads/suite.rb index 2a4b81ced3..99ef3a636a 100644 --- a/lib/metasploit/framework/spec/threads/suite.rb +++ b/lib/metasploit/framework/spec/threads/suite.rb @@ -31,7 +31,7 @@ module Metasploit unless @configured RSpec.configure do |config| config.before(:suite) do - thread_count = Thread.list.count + thread_count = Metasploit::Framework::Spec::Threads::Suite.non_debugger_thread_list.count # check with if first so that error message can be constructed lazily if thread_count > EXPECTED_THREAD_COUNT_AROUND_SUITE @@ -68,7 +68,7 @@ module Metasploit f.puts 'after(:suite)' end - thread_list = Thread.list + thread_list = Metasploit::Framework::Spec::Threads::Suite.non_debugger_thread_list thread_uuids = thread_list.map { |thread| thread[Metasploit::Framework::Spec::Threads::Suite::UUID_THREAD_LOCAL_VARIABLE] @@ -195,6 +195,15 @@ module Metasploit lines_by_thread_uuid end + + # @return + def self.non_debugger_thread_list + Thread.list.reject { |thread| + # don't do `is_a? Debugger::DebugThread` because it requires Debugger::DebugThread to be loaded, which it + # won't when not debugging. + thread.class.name == 'Debugger::DebugThread' + } + end end end end