go - fork /执行 : operation not permitted Ubuntu 20. 04

标签 go ubuntu ubuntu-20.04 delve

当尝试调试 go 应用程序时,我收到以下类似的错误消息。
我最初尝试使用以下 vscode launch.json 调试简单的 golang 程序:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${workspaceFolder}"
        }
    ]
}

我得到的是:

could not launch process: fork/exec /tmp/__debug_bin1874603807: operation not permitted

设置“debugAdapter”:“legacy”会导致类似的结果:

could not launch process: fork/exec /home/user/test/__debug_bin: operation not permitted

从命令行启动 dlv 具有相同的输出:

user@my-machine:~/test$ /home/user/go/bin/dlv debug could not launch process: fork/exec /home/user/test/__debug_bin: operation not permitted

我已经测试过,允许从/tmp 运行文件;我尝试在 /etc/sysctl.d/10-ptrace.conf 中设置 kernel.yama.ptrace_scope = 0 因为我能找到的所有关于此错误的信息都与 ptrace 有关(https://github.com/go-delve/delve/issues/515)。

还值得一提的是,该命令以 root 身份运行:

user@my-machine:~/test$ su root
Password: 
root@my-machine:/home/user/test# export PATH=$PATH:/usr/local/go/bin
root@my-machine:/home/user/test# go version
go version go1.17.6 linux/amd64
root@my-machine:/home/user/test# ../go/bin/dlv debug
Type 'help' for list of commands.
(dlv) quit

通过删除 dlv 二进制文件重新安装 dlv 并运行 go install github.com/go-delve/delve/cmd/dlv@latest 没有帮助。我有一个全新的 Ubuntu Server 20.04 安装。

如何修复调试?

最佳答案

我发现设置 kernel.yama.ptrace_scope = 0 由于某种原因不起作用,但是 echo 0 >/proc/sys/kernel/yama/ptrace_scope 帮助了

关于go - fork /执行 : operation not permitted Ubuntu 20. 04,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70941103/

相关文章:

asp.net - 在 ubuntu 服务器上部署 asp.net 核心应用程序时,nginx 存在重定向问题

java - 如何在 Ubuntu/Lubuntu 20.04 中安装 libgfortran3?

docker - 在Windows中移至WSL 2后向Docker容器分配内存

go - 使用 channel 时出现问题 : all goroutines are asleep - deadlock

javascript - 如何修复 UnhandledPromiseRejectionWarning : TypeError?

sockets - ReadFromUDP 不阻塞

bash - 将 xterm 重定向到 headless 机器的后台

influxdb - Influx CLI 快把我逼疯了,无法打开 CLI

docker - main.go :11:8: package aerospike_shared is not in GOROOT (/usr/local/go/src/aerospike_shared)

templates - 如何在没有范围操作的情况下按键获取 map 值(htm/文本模板)?戈朗