-
Notifications
You must be signed in to change notification settings - Fork 383
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
Debugger #297
Debugger #297
Conversation
@nwidger , currently one of the big questions is whether we can fix the The current problem with
Given the above two and the complexity I envision, I really do want @dop251 to confirm or deny if there is any interest on their side to help or even merge something that will make For the record I did try to:
|
@mostafa I wonder if it might not be a good idea to have Debugger.Breakpoints return a struct type for each breakpoint. I could totally see wanting to, say, add the ability to temporarily disable a breakpoint without actually deleting it, or to include a count indicating how many times a breakpoint has been hit. The current signature of the method would make future extensions like that difficult without breaking the API, which I assume isn't something we'd want to do. I still also think that if it's not too difficult a Debugger method to get the current call stack would probably be good to include in an MVP like this. At least when I've used gdb in the past, |
@mstoykov I agree that getting some feedback/guidance from @dop251 sooner rather than later is probably a good idea. At this point finding out whether he has any interest in merging a debugger API in the first place, and also how willing he'd be for more internal changes to make the debugger interface more useful would probably be a good idea. I don't have any specific feedback regarding the current issues with On a separate topic, has any thought been given to activating the debugger when an exception/panic occurs? I believe in some JS debuggers this is an option that can be toggled on/off. At least for JS exceptions, you may not want the debugger to activate for every exception, but I'd assume the debugger should probably activate if a Go panic is otherwise going to make the debugger itself explode. For example, I this most people would want the debugger to activate when it hits line 5 of this script: function test(val) {
return val + 1;
}
console.log(test(0));
console.log(tes(1));
console.log(test(2)); But instead a just get a nasty panic causing the debugger to terminate:
Perhaps a new |
|
Sorry, I haven't got the chance to review the code yet, but I would merge it assuming good maintainability and minimum performance impact when debugging is not enabled. As for resolving variables, I think there is an easier approach: variable names are kept at runtime when (and only when) there is a possibility of a dynamic lookup (i.e. lookup by name that is not known at compile time). This can happen when at least one nested scope has a direct While there definitely should be a debug mode for compiling, there is a problem that a The use of sourcemaps looks strange to me, there should be no need for that. If you could give me some examples where is skips lines I could take a look. |
I did try just making compiler.isDynamic() return true, but apparently, I either tested something for which this wasn't enough or tested But one of our tests now works 🎉 , so this seems like it will work at least for some of the cases, and it probably works even better if I do what you suggested instead of changing the function ;). Thanks @dop251 Unfortunately, this has a (small) downside that you need to enable debug mode in the very begging and compile your source code with debug mode, which might mean that it will be less useful, but definitely a lot better than not working at all :). I will try to get this change made and fix |
@dop251 @mstoykov |
Current problems from my "integration" with k6:
A lot of the above seem to me like things that proper use of sourcemaps is already fixing somewhat and the debugger(and probably also goja) needs to get a bit better support for them. And as I want to actually get sourcemap support in k6 and 80% of the work is done, I will likely try to see if I can fix some of them or at least diagnose them more accurately. For the rest I think this is due to the hackish nature of some of the things that were done in order to get something working and likely with a bit more understanding of goja it will be possible to stabilize them. Things that I definitely think should be dropped from this PoC are:
I also think that likely Next and StepIn have some (subtle) bug that makes them behave as said above. Thank you @mostafa for starting the work on this. Also thanks to @nwidger for the suggestions and review and of course thanks to @dop251 for goja as a whole and the help so far to get this working. 🎉 |
It makes sense, but it will be a breaking change and as I mention above there are still things to change so the API is definitely not final. I guess we can add a variadic parameter on the current ones without breaking changes 🤔 |
@mstoykov Yes sorry I should been a little clearer, I meant changing the signatures to look something like: type CompileOption func(*compileOptions)
func WithDebugMode() CompileOption
func Compile(name, src string, strict bool, options ...CompileOption) (*Program, error)
func CompileAST(prg *js_ast.Program, strict bool, options ...CompileOption) (*Program, error)
func MustCompile(name, src string, strict bool, options ...CompileOption) *Program which I believe for the majority of people would not be a breaking change. |
Thanks @mstoykov for taking time and fixing lots of my erroneous Go code. You know I am a Python developer by nature. 😉 Thanks @nwidger for your great feedback, comments and suggestions along the way. I tried your proposed changes as parser options and it didn't turn well. Probably @mstoykov and I could have a look after we find and fix deeper issues we currently have. @dop251 |
Arguments to exec command are now separated by semicolon, so each new argument is executed if separated by space in REPL. For example: debug[0]> e console.log(1) console.log(2) < 1 < 2
…he variables, otherwise it'll resort to the value stack
…ence to vm struct
Remove compiler's debugMode flag
Rename isBreakpoint to breakpoint Replace vm.run with vm.debug
Now there is an AttachDebugger method and a Detach method on the debugger, completely removing the debugger from the Runtime. Also WaitForActivity was renamed to Continue, and in order to be more useful to use directly handles the channel communication entirely internally.
* Rename and rework the attaching and detaching of a debugger Now there is an AttachDebugger method and a Detach method on the debugger, completely removing the debugger from the Runtime. Also WaitForActivity was renamed to Continue, and in order to be more useful to use directly handles the channel communication entirely internally. * Fix debugger.Filename
* Remove the second time break on parent function. * Add test case for "removing the second time break on parent function" * Fix typo Co-authored-by: Mostafa Moradian <mostafamoradian0@gmail.com>
The changes in this PR is outdated, and the whole project is in limbo. So, let's close this PR until we have time to fix it. |
Description
As you probably have read the issue #294, this PR adds support for a debugger and exposes some APIs. The PR adds a bare minimum debugger that can control execution and wait for the commands from any frontend, like goja_debugger as a CLI frontend, and possibly DAP and other possible frontends.
Currently these commands, interfaces and utility functions are implemented:
Tests
Currently only three tests are written and clearly more tests are needed. These tests actually show failures in different parts, from failing to report correct line number to local variable retrieval issue in
exec
andprint
commands. Other tests will be added.The ultimate "E2E" test is the CLI frontend: goja_debugger.
Discussion
dbg.vm.stack[dbg.vm.sb+dbg.vm.args+n]
returns the correct value on the stack, but it isn't mapped to anything, which is understandable in terms of optimizations. How can we figure out then
from thevarName
?vm.prg.src.Position(vm.prg.sourceOffset(vm.pc)).Line
sometime report the incorrect line, mostly the next line instead of the current line?Contributors