deivid-rodriguez / byebug

Debugging in Ruby 2
BSD 2-Clause "Simplified" License
3.34k stars 328 forks source link

Allow Breakpoint#hit_condition=(nil) #747

Closed firelizzard18 closed 4 years ago

firelizzard18 commented 4 years ago

Closes #739.

This MR modifies brkpt_set_hit_condition in ext/byebug/breakpoint.c to allow clearing a breakpoint's hit condition by setting it to nil. The documentation on the function indicates this should be possible, but passing nil will raise an exception, and no code path in the function will set the condition to HIT_COND_NONE.

deivid-rodriguez commented 4 years ago

Thanks @firelizzard18! Is there any user facing command to actually unset this?

deivid-rodriguez commented 4 years ago

Actually I now see from your issue and hit_condition is not really exposed and can only be used programamtically. Any ideas on how to better expose it?

In any case, this looks good!

firelizzard18 commented 4 years ago

Any ideas on how to better expose it?

ConditionCommand could be modified to support hit conditions. Possibly:

Implemented as:

case @match[:mode]
when nil, 'expr', 'expression'
  breakpoint.expr = @match[:expression]
when 'hit', 'hitcount'
  breakpoint.hit_condition = @match[:operation].to_sym
  breakpoint.hit_value = @match[:value].to_i
else
  # raise error
end
deivid-rodriguez commented 4 years ago

Since the code in the extension is already there, makes sense to add it. I like your proposal :+1:.