From 967878c4f56cd84c1c815fa9cbd1b83b8afdeaf2 Mon Sep 17 00:00:00 2001 From: Ruby Date: Sat, 6 May 2023 03:16:38 +0900 Subject: [PATCH] work correctly with trap(Integer,...) follow up for https://github.com/ruby/debug/pull/976 --- lib/debug/session.rb | 10 ++++++++++ test/console/trap_test.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/debug/session.rb b/lib/debug/session.rb index 4e029fcbd..e9d95775c 100644 --- a/lib/debug/session.rb +++ b/lib/debug/session.rb @@ -2524,6 +2524,16 @@ def daemon(*args) module TrapInterceptor def trap sig, *command, &command_proc + sym = + case sig + when String + sig.to_sym + when Integer + Signal.signame(sig)&.to_sym + else + sig + end + case sig&.to_s&.to_sym when :INT, :SIGINT if defined?(SESSION) && SESSION.active? && SESSION.intercept_trap_sigint? diff --git a/test/console/trap_test.rb b/test/console/trap_test.rb index 4664d3757..17c4ccfa7 100644 --- a/test/console/trap_test.rb +++ b/test/console/trap_test.rb @@ -24,6 +24,32 @@ def test_sigint type 'c' end end + + def test_trap_with + debug_code %q{ + 1| trap(:INT){} # Symbol + 2| _ = 1 + }, remote: false do + type 'n' + type 'n' + end + + debug_code %q{ + 1| trap('INT'){} # String + 2| _ = 1 + }, remote: false do + type 'n' + type 'n' + end + + debug_code %q{ + 1| trap(Signal.list['INT']){} if Signal.list['INT'] # Integer + 2| _ = 1 + }, remote: false do + type 'n' + type 'n' + end + end end end