Class: EnvUtil::Debugger
- Inherits:
-
Object
- Object
- EnvUtil::Debugger
- Defined in:
- lib/envutil.rb
Constant Summary collapse
- PRECOMMAND =
sudo -n: --non-interactive
(%[sudo -n] if /darwin/ =~ RUBY_PLATFORM)
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #dump(pid, timeout: 60, reprieve: timeout&.div(4)) ⇒ Object
-
#initialize(name, &block) ⇒ Debugger
constructor
A new instance of Debugger.
- #spawn(*args, **opts) ⇒ Object
- #start(pid, *args) ⇒ Object
- #usable? ⇒ Boolean
Constructor Details
#initialize(name, &block) ⇒ Debugger
Returns a new instance of Debugger.
99 100 101 102 |
# File 'lib/envutil.rb', line 99 def initialize(name, &block) @name = name instance_eval(&block) end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
93 94 95 |
# File 'lib/envutil.rb', line 93 def name @name end |
Class Method Details
.register(name, &block) ⇒ Object
95 96 97 |
# File 'lib/envutil.rb', line 95 def self.register(name, &block) @list << new(name, &block) end |
.search ⇒ Object
151 152 153 154 155 156 |
# File 'lib/envutil.rb', line 151 def self.search # Cache the result even when no debugger is available, not to probe # unusable debuggers repeatedly. return @debugger if defined?(@debugger) @debugger = @list.find(&:usable?) end |
Instance Method Details
#dump(pid, timeout: 60, reprieve: timeout&.div(4)) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/envutil.rb', line 108 def dump(pid, timeout: 60, reprieve: timeout&.div(4)) dpid = start(pid, *command_file(File.join(__dir__, "dump.#{name}")), out: :err) rescue Errno::ENOENT return else return unless dpid [[timeout, :TERM], [reprieve, :KILL]].find do |t, sig| begin return EnvUtil.timeout(t) {Process.wait(dpid)} rescue Timeout::Error Process.kill(sig, dpid) end end true end |
#spawn(*args, **opts) ⇒ Object
127 128 129 |
# File 'lib/envutil.rb', line 127 def spawn(*args, **opts) super(*PRECOMMAND, *args, **opts) end |
#start(pid, *args) ⇒ Object
106 |
# File 'lib/envutil.rb', line 106 def start(pid, *args) end |
#usable? ⇒ Boolean
104 |
# File 'lib/envutil.rb', line 104 def usable?; false; end |