Skip to content

Commit

Permalink
[core/debugging] Avoid losing debugging context on some (most ?) plat…
Browse files Browse the repository at this point in the history
…forms
  • Loading branch information
hgy29 committed Jan 3, 2024
1 parent 96fc4a3 commit f6439e9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
18 changes: 13 additions & 5 deletions luabinding/debugging.cpp
Expand Up @@ -93,6 +93,12 @@ void LuaDebugging::serializeValue(ByteBuffer &buffer,lua_State *L,int n,int nref
#include "lstate.h"
#endif

void LuaDebugging::reinitDebugger()
{
if (debuggerMode)
setupBreakMode(debuggerMode);
}

void LuaDebugging::setupBreakMode(int m) {
//Modes used by the studio:
//0x00: stop debugger, i.e resume without any breakpoints
Expand All @@ -102,6 +108,12 @@ void LuaDebugging::setupBreakMode(int m) {
//0x84: resume, i.e break at next line matching a breakpoint
debuggerMode=m;
LuaApplication::debuggerBreak=m;
#ifndef LUA_IS_LUAU
LuaApplication::debuggerHook=LuaDebugging::debuggerHook;
#else
L->global->cb.debugstep=LuaDebugging::debuggerHook;
#endif

#ifndef LUA_IS_LUAU
if (debuggerMode&DBG_MASKSUB)
{
Expand Down Expand Up @@ -191,6 +203,7 @@ void LuaDebugging::studioCommandInternal(const std::vector<char> &data,lua_State
LuaApplication::debuggerBreak=0;
debuggerMode=0;
LuaApplication::debuggerHook=NULL;
LuaDebugging::breakedL=NULL;
lastLine=-1;
if (L&&profiling&&(data[0]==gptStop)) {
LuaApplication::Core_profilerReport(L);
Expand Down Expand Up @@ -244,11 +257,6 @@ void LuaDebugging::studioCommandInternal(const std::vector<char> &data,lua_State
case gptSetBreakpoints: {
ByteBuffer buffer(&data[2], data.size()-2);
setupBreakMode(data[1]);
#ifndef LUA_IS_LUAU
LuaApplication::debuggerHook=LuaDebugging::debuggerHook;
#else
L->global->cb.debugstep=LuaDebugging::debuggerHook;
#endif
int numBreakpoints;
buffer >> numBreakpoints;
LuaApplication::breakpoints.clear();
Expand Down
1 change: 1 addition & 0 deletions luabinding/debugging.h
Expand Up @@ -37,6 +37,7 @@ class LuaDebugging {
#else
static void debuggerHook(void *context,lua_State *L,lua_Debug *ar);
#endif
static void reinitDebugger();
};

#endif /* LUABINDING_DEBUGGING_H_ */
3 changes: 2 additions & 1 deletion luabinding/luaapplication.cpp
Expand Up @@ -2430,7 +2430,8 @@ void LuaApplication::initialize()
lua_sethook(L, yieldHook, (LuaApplication::debuggerBreak&DBG_MASKLUA), 1);
#endif
globalLuaState=L;


LuaDebugging::reinitDebugger();
Core_profilerReset(L);
if (LuaDebugging::profiling)
Core_profilerStart(L);
Expand Down

1 comment on commit f6439e9

@troysandal
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, looking forward to this making it in next month.

Please sign in to comment.