From 7b0a4b670e5b4d032a3dc209975659fd41d248d4 Mon Sep 17 00:00:00 2001 From: fesily Date: Wed, 11 Dec 2024 13:00:10 +0800 Subject: [PATCH] Fix linux process inject (#308) * fix lua-debug export * fix linux attach inject --------- Co-authored-by: fesil <285451120@qq.com> --- compile/common/lua-debug.lua | 1 + compile/common/package_json.lua | 19 +++++++++---------- compile/linux/runtime.lua | 1 + extension/script/frontend/process_inject.lua | 13 ++++++------- extension/script/frontend/proxy.lua | 4 ---- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/compile/common/lua-debug.lua b/compile/common/lua-debug.lua index 40e7348d..9a14a34e 100644 --- a/compile/common/lua-debug.lua +++ b/compile/common/lua-debug.lua @@ -33,6 +33,7 @@ lm:executable "lua-debug" { }, linux = { crt = "static", + ldflags = "-rdynamic" }, netbsd = { crt = "static", diff --git a/compile/common/package_json.lua b/compile/common/package_json.lua index 50c1dafa..d62a0315 100644 --- a/compile/common/package_json.lua +++ b/compile/common/package_json.lua @@ -270,23 +270,22 @@ else end attributes.attach = { -} - -if OS == "win32" or OS == "darwin" then - attributes.attach.processId = { + processId = { default = "${command:pickProcess}", markdownDescription = "Id of process to attach to.", type = "string", - } - attributes.attach.processName = { + }, + processName = { default = "lua.exe", markdownDescription = "Name of process to attach to.", type = "string", } - json.contributes.debuggers[1].variables = { - pickProcess = "extension.lua-debug.pickProcess", - } -end +} + +json.contributes.debuggers[1].variables = { + pickProcess = "extension.lua-debug.pickProcess", +} + attributes.launch = { luaexe = { diff --git a/compile/linux/runtime.lua b/compile/linux/runtime.lua index 519f3e57..ab0448d7 100644 --- a/compile/linux/runtime.lua +++ b/compile/linux/runtime.lua @@ -4,6 +4,7 @@ require "compile.common.runtime" require "compile.common.launcher" lm:lua_dll 'launcher' { + bindir = "publish/bin/", export_luaopen = "off", deps = { "launcher_source", diff --git a/extension/script/frontend/process_inject.lua b/extension/script/frontend/process_inject.lua index 9ca1ce37..ecdd15b8 100644 --- a/extension/script/frontend/process_inject.lua +++ b/extension/script/frontend/process_inject.lua @@ -51,8 +51,9 @@ function _M.gdb_inject(pid, entry, injectdll, gdb_path) local launcher = { "-ex", - -- 6 = RTDL_NOW|RTDL_LOCAL - ('print (void*)dlopen("%s", 6)'):format(injectdll), + -- 6 = RTDL_NOW|RTDL_LOCAL macos + -- 2 = RTDL_NOW linux + ('print (void*)dlopen("%s", %d)'):format(injectdll, platform_os == macos and 6 or 2), "-ex", ('call ((void(*)())&%s)()'):format(entry), "-ex", @@ -93,8 +94,9 @@ function _M.lldb_inject(pid, entry, injectdll, lldb_path) local launcher = { "-o", - -- 6 = RTDL_NOW|RTDL_LOCAL - ('expression (void*)dlopen("%s", 6)'):format(injectdll), + -- 6 = RTDL_NOW|RTDL_LOCAL macos + -- 2 = RTDL_NOW linux + ('expression (void*)dlopen("%s", %d)'):format(injectdll, platform_os == macos and 6 or 2), "-o", ('expression ((void(*)())&%s)()'):format(entry), "-o", @@ -153,9 +155,6 @@ function _M.windows_inject(process, entry) end function _M.inject(process, entry, args) - if platform_os ~= windows and platform_os ~= macos then - return false, "unsupported inject" - end if platform_os ~= windows and type(process) == "userdata" then process = process:get_id() end diff --git a/extension/script/frontend/proxy.lua b/extension/script/frontend/proxy.lua index 637986af..d56a5939 100644 --- a/extension/script/frontend/proxy.lua +++ b/extension/script/frontend/proxy.lua @@ -80,10 +80,6 @@ end local function proxy_attach(pkg) local args = pkg.arguments platform_os.init(args) - if platform_os() ~= "windows" and platform_os() ~= "macos" then - attach_tcp(pkg, args) - return - end if args.processId then local processId = tonumber(args.processId) local ok, errmsg = attach_process(pkg, processId)