-
Notifications
You must be signed in to change notification settings - Fork 212
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
Possible to create a simple interactive debugger? #304
Comments
Not yet. At one point I started writing an asynchronous concurrent debugger (like gdb) with breakpoints, but got distracted. Let me see if I can find it, then perhaps we can define a reasonable API for accessing the environment to support your use case, even if we don't add complete support for breakpoints etc. |
Wonderful, thank you |
Hey @alandonovan any update on this? |
Sorry, no progress. This feature requires that the bytecode interpreter has a single-byte BREAKPOINT instruction, plus new public APIs to
And it requires a great deal of care with respect to concurrency. I think this is probably several weeks' work for someone who understands the implementation well. |
A debugger is much more than a call to a user-defined function before and after every function call; it requires control over execution at a statement or instruction level, a means of inspecting and perhaps altering program state, and helpers for mapping between source and executable representations of the program. How would the proposed hook allow someone to step through the iterations of a loop looking at the local variables? Also, a debugger should not slow down execution when it is not in use, as adding a callback here would. |
I'm not proposing a fully-featured debugger, but a "half-cooked" way to build a naive debugging tool. |
This issue is about an interactive debugger, but I think what you're asking for is merely a call-tracing hook. That's a separate and much simpler feature, and I think it would be reasonable to add if we can come up with a good specification.
Is this interface useful? It sees the raw tuples of arguments (to all Callables, not just Starlark functions), not the cooked result of setArgs. |
That would definitely be useful for me! Still very much interested in the full debugger. Very likely too complicated for me to implement, but greatly appreciate the list of functionality that would be required. I'll take a look to see if I can figure out how it would all hook into the current implementation. |
A slight variant would be to make CallTracer be a per-Thread field, which would permit finer-grained control over which threads are traced and would avoid the concurrency issues of a global variable. But to support blanket tracing of all threads And another (orthogonal) variant would be a single-method "call decorator":
where nil is equivalent to an implementation of |
hey @adonovan , was there any attempt at implementing this? i could definitely use this. if not, I might be able to tackle it in the next few weeks. |
fyi - There's a Starlark debugger in the Java implementation: If there's a similar interface here, the debugger clients could be shared. |
There was, but I can't at this moment find my old code. The approach I took was a breakpoint-oriented debugger that would swap out a byte of bytecode for a dedicated breakpoint instruction and restore it later. The concurrency challenges of supporting single stepping are quite complex because (a) breakpoints can be added and removed from the shared code segments by any thread, and (b) every breakpoint needs an associated list of threads and conditions; synchronizing these data structures is fiddly. Overall it is not a small project. I would want to discuss a design before reviewing any code changes.
The Java implementation is completely different: it's a tree-walking interpreter. I don't think there's much to learn from it. |
Sorry for late response - i did not get notified that you replied, and I was travelling. I am not looking for real full fledged debugger, just for tracing, like @maxmcd . a CallDecorator like you suggested in #304 (comment) can be very useful for me. |
I created this builtin:
But, unsurprisingly, when it is run, the various local variables or declared global variables are not available in the interactive session.
Is implementing this kind of interactive debugger feasible with the current lib implementation?
Thanks!
The text was updated successfully, but these errors were encountered: