Skip to content

Commit

Permalink
Fix linux process inject (#308)
Browse files Browse the repository at this point in the history
* fix lua-debug export

* fix linux attach inject

---------

Co-authored-by: fesil <[email protected]>
  • Loading branch information
fesily and fesil authored Dec 11, 2024
1 parent a6a380e commit 7b0a4b6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
1 change: 1 addition & 0 deletions compile/common/lua-debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ lm:executable "lua-debug" {
},
linux = {
crt = "static",
ldflags = "-rdynamic"
},
netbsd = {
crt = "static",
Expand Down
19 changes: 9 additions & 10 deletions compile/common/package_json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions compile/linux/runtime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 6 additions & 7 deletions extension/script/frontend/process_inject.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions extension/script/frontend/proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7b0a4b6

Please sign in to comment.