pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.61k stars 520 forks source link

IDE does not catch Lua exceptions during remote debugging #467

Closed inn0minatus closed 9 years ago

inn0minatus commented 9 years ago

Hi, I have a custom C++ engine and using luabind to integrate Lua 5.2. Everything works with breakpoints and watches when using remote debugging but IDE does not catch crashes in Lua code. I see standard Windows error dialogue when app crashes. Could you please help with this? (Used decoda previously)

madmaxoft commented 9 years ago

ZBS cannot catch hard crashes, simply because the debugger is entirely implemented in Lua, and once the interpreter crashes, the debugger is no longer available. (Unlike Decoda, which uses memory manipulation in the debugged process to inject itself into the native Lua executable code)

It is possible to make the interpreter break when there is a problem in the Lua code (such as dereferencing a nil as a table etc) if your interpreter uses lua_xpcall to call the script. We have managed to get this working with MCServer. The interpreter installs an error handler function that calls a Lua function injected into the code by the ZBS integration package: ZBS package: https://github.com/pkulchenko/ZeroBranePackage/blob/master/mcserver.lua#L67-L73 C++ interpreter's error handler: https://github.com/mc-server/MCServer/blob/master/src/Bindings/LuaState.cpp#L1380-L1396 C++ interpreter's handler installation:

  1. https://github.com/mc-server/MCServer/blob/master/src/Bindings/LuaState.cpp#L270
  2. https://github.com/mc-server/MCServer/blob/master/src/Bindings/LuaState.cpp#L1368-L1374

Note that the ZBS package needs to jump through hoops to actually get the breakpoint working.

pkulchenko commented 9 years ago

@Neovet, Mattes is absolutely correct; what's he described is probably the best you can do at this point (and it's probably not possible to do more with the Lua-level debugger).

inn0minatus commented 9 years ago

Such a quick response, thank you!