Skip to content

Commit

Permalink
support reset no_sigint_hook config
Browse files Browse the repository at this point in the history
```ruby
require 'debug'       # no_sigint_hook: true
require 'debug/start' # no_sigint_hook: false
```

In this case SIGINT should be a breakpoint but it was not enabled.
  • Loading branch information
ko1 committed Dec 2, 2022
1 parent 882d595 commit d32b157
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
6 changes: 6 additions & 0 deletions lib/debug/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ def update conf
if_updated old_conf, conf, :sigdump_sig do |old_sig, new_sig|
setup_sigdump old_sig, new_sig
end

if_updated old_conf, conf, :no_sigint_hook do |old, new|
if defined?(SESSION)
SESSION.set_no_sigint_hook old, new
end
end
end

private def if_updated old_conf, new_conf, key
Expand Down
25 changes: 15 additions & 10 deletions lib/debug/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,28 @@ def remote?
false
end

def activate session, on_fork: false
unless CONFIG[:no_sigint_hook]
prev_handler = trap(:SIGINT){
if session.active?
ThreadClient.current.on_trap :SIGINT
end
}
session.intercept_trap_sigint_start prev_handler
end
def activate_sigint
prev_handler = trap(:SIGINT){
if SESSION.active?
ThreadClient.current.on_trap :SIGINT
end
}
SESSION.intercept_trap_sigint_start prev_handler
end

def deactivate
def deactivate_sigint
if SESSION.intercept_trap_sigint?
prev = SESSION.intercept_trap_sigint_end
trap(:SIGINT, prev)
end
end

def activate session, on_fork: false
activate_sigint unless CONFIG[:no_sigint_hook]
end

def deactivate
deactivate_sigint
@console.deactivate
end

Expand Down
11 changes: 11 additions & 0 deletions lib/debug/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,17 @@ def postmortem=(is_enable)
end
end

def set_no_sigint_hook old, new
return unless old != new
return unless @ui.respond_to? :activate_sigint

if old # no -> yes
@ui.activate_sigint
else
@ui.deactivate_sigint
end
end

def save_int_trap cmd
prev, @intercepted_sigint_cmd = @intercepted_sigint_cmd, cmd
prev
Expand Down
2 changes: 1 addition & 1 deletion lib/debug/start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

require_relative 'session'
return unless defined?(DEBUGGER__)
DEBUGGER__.start
DEBUGGER__.start no_sigint_hook: false

0 comments on commit d32b157

Please sign in to comment.