Skip to content

Commit 9c893a1

Browse files
committed
Show process ID in prompt for independent worker sessions
When the well-known lock is active, include program name and PID in the debugger prompt so it's clear which worker has control: (rdbg@test_foo.rb#12345) Also applies to IRB console integration: irb:rdbg@test_foo.rb#12345(main):001:0> This makes process switches obvious when control moves between workers on continue.
1 parent 2d0a1fb commit 9c893a1

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/debug/irb_integration.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def activate_irb_integration
2121
irb = IRB::Irb.new(workspace)
2222
IRB.conf[:MAIN_CONTEXT] = irb.context
2323
IRB::Debug.setup(irb)
24+
if (pi = SESSION.process_info)
25+
irb.context.irb_name = "irb:rdbg@#{pi}"
26+
end
2427
IRB::Context.prepend(IrbPatch)
2528
end
2629
end

lib/debug/session.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@ def wait_command_loop
493493
def prompt
494494
if @postmortem
495495
'(rdbg:postmortem) '
496-
elsif @process_group.multi?
497-
"(rdbg@#{process_info}) "
496+
elsif (pi = process_info)
497+
"(rdbg@#{pi}) "
498498
else
499499
'(rdbg) '
500500
end
@@ -2085,7 +2085,7 @@ def intercept_trap_sigint_end
20852085
end
20862086

20872087
def process_info
2088-
if @process_group.multi?
2088+
if @process_group.multi? || @process_group.wk_locked?
20892089
"#{$0}\##{Process.pid}"
20902090
end
20912091
end
@@ -2155,6 +2155,10 @@ def wk_lock
21552155
@wk_lock_file&.flock(File::LOCK_EX)
21562156
end
21572157

2158+
def wk_locked?
2159+
!multi? && @wk_lock_file
2160+
end
2161+
21582162
def unlock_wk_lock
21592163
return if multi?
21602164
@wk_lock_file&.flock(File::LOCK_UN)

0 commit comments

Comments
 (0)