mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 03:53:09 +00:00
remote debugger
This commit is contained in:
@@ -48,14 +48,15 @@ local function split_cmdline(cmdline)
|
||||
return split
|
||||
end
|
||||
|
||||
local function docmd(cmdline, print)
|
||||
local function docmd(cmdline, print, fd)
|
||||
local split = split_cmdline(cmdline)
|
||||
table.insert(split, fd)
|
||||
local cmd = COMMAND[split[1]]
|
||||
local ok, list
|
||||
if cmd then
|
||||
ok, list = pcall(cmd, select(2,table.unpack(split)))
|
||||
else
|
||||
ok, list = pcall(skynet.call,".launcher","lua", table.unpack(split))
|
||||
print("Invalid command, type help for command list")
|
||||
end
|
||||
|
||||
if ok then
|
||||
@@ -82,7 +83,7 @@ local function console_main_loop(stdin, print)
|
||||
break
|
||||
end
|
||||
if cmdline ~= "" then
|
||||
docmd(cmdline, print)
|
||||
docmd(cmdline, print, stdin)
|
||||
end
|
||||
end
|
||||
socket.unlock(stdin)
|
||||
@@ -124,6 +125,7 @@ function COMMAND.help()
|
||||
logon = "logon address",
|
||||
logoff = "logoff address",
|
||||
log = "launch a new lua service with log",
|
||||
debug = "debug address : debug a lua service",
|
||||
}
|
||||
end
|
||||
|
||||
@@ -165,11 +167,31 @@ end
|
||||
|
||||
local function adjust_address(address)
|
||||
if address:sub(1,1) ~= ":" then
|
||||
address = bit32.replace( tonumber("0x" .. address), skynet.harbor(skynet.self()), 24, 8)
|
||||
address = tonumber("0x" .. address) | (skynet.harbor(skynet.self()) << 24)
|
||||
end
|
||||
return address
|
||||
end
|
||||
|
||||
function COMMAND.list()
|
||||
return skynet.call(".launcher", "lua", "LIST")
|
||||
end
|
||||
|
||||
function COMMAND.stat()
|
||||
return skynet.call(".launcher", "lua", "STAT")
|
||||
end
|
||||
|
||||
function COMMAND.mem()
|
||||
return skynet.call(".launcher", "lua", "MEM")
|
||||
end
|
||||
|
||||
function COMMAND.kill(address)
|
||||
return skynet.call(".launcher", "lua", "KILL", address)
|
||||
end
|
||||
|
||||
function COMMAND.gc()
|
||||
return skynet.call(".launcher", "lua", "GC")
|
||||
end
|
||||
|
||||
function COMMAND.exit(address)
|
||||
skynet.send(adjust_address(address), "debug", "EXIT")
|
||||
end
|
||||
@@ -195,6 +217,26 @@ function COMMAND.info(address)
|
||||
return skynet.call(address,"debug","INFO")
|
||||
end
|
||||
|
||||
function COMMAND.debug(address, fd)
|
||||
address = adjust_address(address)
|
||||
local agent = skynet.newservice "debug_agent"
|
||||
local stop
|
||||
skynet.fork(function()
|
||||
repeat
|
||||
local cmdline = socket.readline(fd, "\n")
|
||||
if not cmdline then
|
||||
skynet.send(agent, "lua", "cmd", "cont")
|
||||
break
|
||||
end
|
||||
if cmdline ~= "" then
|
||||
skynet.send(agent, "lua", "cmd", cmdline)
|
||||
end
|
||||
until stop or cmdline == "cont"
|
||||
end)
|
||||
skynet.call(agent, "lua", "start", address, fd)
|
||||
stop = true
|
||||
end
|
||||
|
||||
function COMMAND.logon(address)
|
||||
address = adjust_address(address)
|
||||
core.command("LOGON", skynet.address(address))
|
||||
|
||||
Reference in New Issue
Block a user