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

Need mobdebug method to get current status #20

Open
johnd0e opened this issue Jun 3, 2015 · 10 comments
Open

Need mobdebug method to get current status #20

johnd0e opened this issue Jun 3, 2015 · 10 comments
Assignees

Comments

@johnd0e
Copy link

johnd0e commented Jun 3, 2015

Need mobdebug method to get current status:

  • is connected?
  • is debug on?

Discussed here: http://forum.farmanager.com/viewtopic.php?p=116950#p116950

@pkulchenko
Copy link
Owner

Agree; what do you mean by "is debug on"? I checked the discussion, but couldn't try figure out how this is going to be used. It's easy to check if there is an active connection, but I'm not sure what else may be needed.

@pkulchenko pkulchenko self-assigned this Jun 5, 2015
@johnd0e
Copy link
Author

johnd0e commented Jun 9, 2015

what do you mean by "is debug on"?

Is debug hook set or not (for current coroutine).
So after mobdebug.on() it will be true, and after mobdebug.off()false

It's easy to check if there is an active connection

You mean it's easy to implementate?
Or there is some way to check this now?

@pkulchenko
Copy link
Owner

You mean it's easy to implementate?

Yes.

Or there is some way to check this now?

No

I can probably create a function (ison or something similar) that returns true if the hook is on for the current coroutine, false if the debugging is on for some other coroutine, but not this one and nil if the debugging is off (after off for all coroutines, after done, or before start).

Does this cover all your needs? How would you use it?

@johnd0e
Copy link
Author

johnd0e commented Jun 10, 2015

How would you use it?

I want to control debugging from client side.

I can probably create a function (ison or something similar) if the hook is on for the current coroutine,

It seems that I can just use debug.gethook() for this purpose

false if the debugging is on for some other coroutine

Maybe it is even excessive.
(I want to evaluate this, how can I get it inside of mobdebug?)

and nil if the debugging is off

Yes, this is absolutely needed.
Is it the same as mobdebug's internal function isrunning?

@pkulchenko
Copy link
Owner

I can probably create a function (ison or something similar) if the hook is on for the current coroutine,
It seems that I can just use debug.gethook() for this purpose

I thought about it, but it's not that easy, as there is a difference between Lua (which has hook per thread) and LuaJIT (which has one hook for all threads), so you are going to get different results. Mobdebug hides the difference and does the right thing, but you'd need to re-implement the same logic and would need to have access to some internal structures. There was another reason, but it escapes me at the moment.

and nil if the debugging is off
Yes, this is absolutely needed.
Is it the same as mobdebug's internal function isrunning?

It may work, but notice that it checks for coro_debugger to be in both "running" and "suspended" state. This is to make it work for the code that runs inside the debugger itself (in the debugger coroutine), which may not be needed if you always run it from the client space.

(I want to evaluate this, how can I get it inside of mobdebug?)

You may try to expose isrunning and see if it works for you. I was thinking about a slightly different method, along the line of on/off calls, but with only checks instead of changes. This would give you a per-coroutine answer (but if there is no debugging, it would be the same as the result from isrunning).

@johnd0e
Copy link
Author

johnd0e commented Jun 11, 2015

Mobdebug hides the difference and does the right thing

I see special logic here: https://github.com/pkulchenko/MobDebug/blob/master/src/mobdebug.lua#l515

You may try to expose isrunning and see if it works for you

I am not sure if there is any difference (current or other coroutine ) as I use luajit

@pkulchenko
Copy link
Owner

I see special logic here: https://github.com/pkulchenko/MobDebug/blob/master/src/mobdebug.lua#l515

Yes; this logic makes it works the same way (in terms of coroutine debugging) for LuaJIT and other Lua interpreters.

I am not sure if there is any difference (current or other coroutine ) as I use luajit

There is as debug hook is going to be returned early for those coroutines that don't have debugging enabled (even under LuaJIT).

@johnd0e
Copy link
Author

johnd0e commented Jun 12, 2015

I can probably create a function (ison or something similar) that returns true if the hook is on for the current coroutine, false if the debugging is on for some other coroutine, but not this one and nil if the debugging is off (after off for all coroutines, after done, or before start).

Perhaps we need somehow to differ between "off for all coroutines" and "not connected"?

@pkulchenko
Copy link
Owner

So, it seems like we'd need 4 states: connected, connected and off everywhere, connected and on, connected and on elsewhere. You can probably check the second one by just doing debug.gethook, but you'd need a new method to check for states 3 and 4. Given this, I still think that nil/true/false is enough.

@johnd0e
Copy link
Author

johnd0e commented Jun 13, 2015

You mean that when "connected and off everywhere" debug.gethook should be not nil?
Is it right for non-luajit?

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

No branches or pull requests

2 participants