diff --git a/compile/common/package_json.lua b/compile/common/package_json.lua index e1a3783b..9b141f22 100644 --- a/compile/common/package_json.lua +++ b/compile/common/package_json.lua @@ -226,6 +226,11 @@ attributes.common = { markdownDescription = "Automatically stop after thread entry.", type = "boolean", }, + keepSessionAlive = { + default = false, + markdownDescription = "Keep the debug session alive when the current debugged Lua VM is closed and later recreated in the same process.", + type = "boolean", + }, address = { markdownDescription = [[ Debugger address. diff --git a/extension/script/backend/bootstrap.lua b/extension/script/backend/bootstrap.lua index 45ab5b87..c6844990 100644 --- a/extension/script/backend/bootstrap.lua +++ b/extension/script/backend/bootstrap.lua @@ -2,6 +2,11 @@ local thread = require "bee.thread" local channel = require "bee.channel" local m = {} +local keepSessionAlive = false + +function m.setKeepSessionAlive(enabled) + keepSessionAlive = not not enabled +end local function hasMaster() return channel.query "DbgMaster" ~= nil @@ -31,6 +36,9 @@ local function initMaster(rootpath, address) address )) ExitGuard = setmetatable({}, {__gc=function() + if keepSessionAlive then + return + end chan:push(nil, "EXIT") thread.wait(mt) channel.destroy("DbgMaster") diff --git a/extension/script/backend/master/resolve_config.lua b/extension/script/backend/master/resolve_config.lua index 4f666609..2e5ce7bf 100644 --- a/extension/script/backend/master/resolve_config.lua +++ b/extension/script/backend/master/resolve_config.lua @@ -22,6 +22,9 @@ local function resolve_config(config) if type(config.stopOnThreadEntry) ~= "boolean" then config.stopOnThreadEntry = false end + if type(config.keepSessionAlive) ~= "boolean" then + config.keepSessionAlive = false + end if type(config.luaVersion) ~= "string" then config.luaVersion = "lua54" end diff --git a/extension/script/backend/worker.lua b/extension/script/backend/worker.lua index 4dc6e353..014453bf 100644 --- a/extension/script/backend/worker.lua +++ b/extension/script/backend/worker.lua @@ -13,6 +13,7 @@ local thread = require 'bee.thread' local fs = require 'backend.worker.filesystem' local log = require 'common.log' local channel = require "bee.channel" +local bootstrap = require 'backend.bootstrap' local initialized = false local suspend = false @@ -113,6 +114,7 @@ local function cleanFrame() end function CMD.initializing(pkg) + bootstrap.setKeepSessionAlive(pkg.config.keepSessionAlive) luaver.init() ev.emit('initializing', pkg.config) end