New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the watch command #49
Comments
Could you show the example? I agree it should stop also
Maybe this request is, "I want to watch the change of an ivar of THIS object". So it needs to specify two parameters, "Object" and "Ivar name". I'm planning to introduce Another topic of "watch" command is, should we keep the binding of the frame. |
if the change happens at the last line if the program, it doesn't stop there. that's why the tests need an extra line at the end debug/test/debug/watch_test.rb Lines 8 to 14 in f44de3a
yeah this feature sounds good 👍 but syntax-wise I'd go for
from a user's perspective, if the breakpoint is already inside an object's method, I'd expect class Foo
def initialize
@var = 0
binding.bp(command: "watch @var")
end
def bar
@var = 10
end
end
f = Foo.new
f.bar I know this could be hard to implement and may not a be priority right now. but I believe it provides a better user experience. |
or only allow for ivar (or gvar) like |
so only:
but no |
no The difference is, allow any expression or not. |
maybe we can preserve |
Maybe we need a scenario to design this feature. |
@ko1 do you mean I don't think I'd use as of for example, tracking down what changes a class Student
attr_accessor :name
def initialize(name)
@name = name
end
end
# somewhere else
student = Student.new("John")
SomeService.perform(student) without the debugger, it'd take several steps:
but with debugger & class Student
attr_accessor :name
def initialize(name)
@name = name
binding.bp(command: "watch @name ;; c")
end
end then it'll stop at the places where and it's even more convenient than invoking |
btw I think debug/lib/debug/thread_client.rb Lines 248 to 265 in 9d7b88a
|
How about general scenario other than ivars?
The lifetime of local variables are enough small, so I think it is not so important for lvars (if we make a Proc, the lifetime is not limited to the scope though). |
@ko1 this is generally the case, but I have some real-world examples for the use of The code below comes from a library I use at work and have debugged before: As you can see, the (although I should note that And here's another example from the same library: https://github.com/cerebris/jsonapi-resources/blob/release-0-9/lib/jsonapi/resource.rb#L1246, which has an even longer method and more local assignments. Although these cases are not common, they're where this debugger can help the most. |
Regarding other
|
But for the debug purpose, it is acceptable...? |
I'm afraid that people ask me to make it fast. |
For |
I see. Given the performance penalty I think it's reasonable to drop it.
I guess the support will come in Ruby 3.1? In that case, will we keep 2 implementations in the debugger? One for 3.1+ and the other for 2.6~3.0 |
Another idea is, shows a warning message "it will make your program super slow" for adding watch points, and doesn't show it ivar on 3.1 with TP optimization. |
For watch points, Yes. |
@ko1 cool sounds good 👍 I think my PR has improved the ivar case then. |
Close this ticket and discuss more features in another issue/PR. |
Description copied from #41:
I found several things when playing with the
watch
command:line
events to detect the change instead of thereturn
events (I'm not sure why though). This causes the program to always stop a line after the change. So in tests we need to add an extra line after the changed line. Otherwise it doesn't stop.watch @name
and users need to usewatch obj.name
instead. I think we should improve this.The text was updated successfully, but these errors were encountered: