pkulchenko / MobDebug

Remote debugger for Lua.
Other
884 stars 192 forks source link

Need mobdebug method to get current status #20

Open johnd0e opened 9 years ago

johnd0e commented 9 years ago

Need mobdebug method to get current status:

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

pkulchenko commented 9 years ago

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.

johnd0e commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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