debug_agent.lua 746 B

12345678910111213141516171819202122232425262728293031323334353637
  1. local skynet = require "skynet"
  2. local debugchannel = require "skynet.debugchannel"
  3. local CMD = {}
  4. local channel
  5. function CMD.start(address, fd)
  6. assert(channel == nil, "start more than once")
  7. skynet.error(string.format("Attach to :%08x", address))
  8. local handle
  9. channel, handle = debugchannel.create()
  10. local ok, err = pcall(skynet.call, address, "debug", "REMOTEDEBUG", fd, handle)
  11. if not ok then
  12. skynet.ret(skynet.pack(false, "Debugger attach failed"))
  13. else
  14. -- todo hook
  15. skynet.ret(skynet.pack(true))
  16. end
  17. skynet.exit()
  18. end
  19. function CMD.cmd(cmdline)
  20. channel:write(cmdline)
  21. end
  22. function CMD.ping()
  23. skynet.ret()
  24. end
  25. skynet.start(function()
  26. skynet.dispatch("lua", function(_,_,cmd,...)
  27. local f = CMD[cmd]
  28. f(...)
  29. end)
  30. end)