Skip to content

Commit e27b57e

Browse files
committed
Propogate REPL binding locals back to original binding
1 parent 84e3fab commit e27b57e

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

lib/debug/thread_client.rb

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,24 +352,35 @@ def eval_binding
352352
[:raised_exception, "_raised"],
353353
[:return_value, "_return"],
354354
]
355+
SPECIAL_LOCAL_VAR_NAMES = SPECIAL_LOCAL_VARS.map { |_, n| n }
355356

356357
def frame_eval src, re_raise: false
357358
@success_last_eval = false
358359

359-
b = eval_binding
360+
# the binding of original program
361+
original_binding = eval_binding
362+
# the binding used by debugger REPL that can have special locals
363+
repl_binding = eval_binding.dup
360364

361-
special_local_variables current_frame, binding: b do |name, var|
362-
b.local_variable_set(name, var) if /\%/ !~ name
365+
special_local_variables current_frame, binding: repl_binding do |name, var|
366+
repl_binding.local_variable_set(name, var) if /\%/ !~ name
363367
end
364368

365-
result = if b
366-
f, _l = b.source_location
367-
b.eval(src, "(rdbg)/#{f}")
369+
result = if repl_binding
370+
f, _l = repl_binding.source_location
371+
repl_binding.eval(src, "(rdbg)/#{f}")
368372
else
369373
frame_self = current_frame.self
370374
instance_eval_for_cmethod(frame_self, src)
371375
end
372376
@success_last_eval = true
377+
378+
# write non-special local variables back to the original binding
379+
repl_binding.local_variables.each do |var|
380+
next if SPECIAL_LOCAL_VAR_NAMES.include?(var)
381+
original_binding.local_variable_set(var, repl_binding.local_variable_get(var))
382+
end
383+
373384
result
374385

375386
rescue Exception => e

0 commit comments

Comments
 (0)