Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compile/common/package_json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions extension/script/backend/bootstrap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ local thread = require "bee.thread"
local channel = require "bee.channel"

local m = {}
local keepSessionAlive = false
Comment thread
fesily marked this conversation as resolved.

function m.setKeepSessionAlive(enabled)
keepSessionAlive = not not enabled
end

local function hasMaster()
return channel.query "DbgMaster" ~= nil
Expand Down Expand Up @@ -31,6 +36,9 @@ local function initMaster(rootpath, address)
address
))
ExitGuard = setmetatable({}, {__gc=function()
if keepSessionAlive then
return
end
Comment on lines +39 to +41
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

When keepSessionAlive is enabled, the ExitGuard returns early, which correctly keeps the master thread alive across VM restarts. However, since ExitGuard is only created in initMaster (when the master is first started), subsequent debug sessions that attach to the existing master will not have an ExitGuard of their own.

This means that if a user later sets keepSessionAlive to false in a subsequent session, the master thread will still not be cleaned up when that session ends, as there is no guard in the new VM to trigger the exit logic. This results in the master thread persisting until the host process terminates. Consider if m.attach should also register a cleanup guard.

chan:push(nil, "EXIT")
thread.wait(mt)
channel.destroy("DbgMaster")
Expand Down
3 changes: 3 additions & 0 deletions extension/script/backend/master/resolve_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions extension/script/backend/worker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading