Skip to content
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

Debug hooks #69

Closed
bitwalker opened this issue May 3, 2016 · 4 comments
Closed

Debug hooks #69

bitwalker opened this issue May 3, 2016 · 4 comments
Labels

Comments

@bitwalker
Copy link

Hi! Awesome work on this! I've been prototyping a project which uses gopher-lua to run user-defined scripts in a sandbox, and everything has been going pretty smoothly so far, however I would like to implement some resource constraints on scripts which are run, and based on previous experience, the way this is done is with debug hooks. Is there a specific reason why they are not exposed in gopher-lua? Is it possible to add them? I see that the shopify/go-lua project does implement them, but they are missing other things that gopher-lua has, and as far as I can tell, is not particularly active. Rather than cut over to using shopify/go-lua, I'm wondering if it's feasible to implement the debug hooks in gopher-lua, and wanted to get some background on why they were omitted before I started working on anything.

Thanks!

@yuin
Copy link
Owner

yuin commented May 3, 2016

Hi.
Currently, Go is not suitable for implementing fast scripting language for some reasons.
Debug hooks can easily be implemented in GopherLua, but cause a little performance degradation and are not quite so common(Sandboxing is one of the few exceptions).
Even if debug hooks are implemented as an option, it will need extra 'if' statements in heavy paths on the VM.
So I omitted it to improve performance for common users who do not need debug hooks.

@bitwalker
Copy link
Author

That makes sense to me 👍 . I may fork and add the hooks, just for the project I'm working on. Would you be able to point me in the right direction on where those should be implemented? I'll be diving in some time today to try and get that done, but it will be the first time I've dived in to the gopher-lua source beyond surface level, and some guidance would be a huge help. Feel free to close this issue either way :)

@yuin
Copy link
Owner

yuin commented May 3, 2016

Just off the top of my head...

  1. struct LState will hold debug functions as fields.
  2. struct LState will hold a counter for counting function calls
  3. You will need to check whether interpreter is about to start the execution of a new line of code and execute hook functions near
    cf.Pc++
    (The line hook)
  4. You will need to count instructions and execute hook functions near
    cf.Pc++
    (The count hook)
  5. You will need to execute hook functions near
    func(L *LState, inst uint32, baseframe *callFrame) int { //OP_CALL
    , L531 and L593(The call hook and The return hook)

I hope that it will be helpful for you.

@bitwalker
Copy link
Author

That's a great start, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants