远程 LLDB 调试 - Docker 容器

Remote LLDB debugging - Docker container

我正在尝试使用 LLDB 4.0.1 设置远程调试。 有一个带有 Arch linux 的 docker (17.06.0-ce) 容器。 Docker容器设置在privileged mode,所以现在可以在容器中启动LLDB。 容器包含 core_service 这是 Rust 可执行文件。

容器内的命令运行 (lldb) target create target/debug/core_service Current executable set to 'target/debug/core_service' (x86_64). (lldb) process launch Process 182 launched: '/srv/core_service/target/debug/core_service' (x86_64)

远程调试存在问题,lldb-server 在 lldb-server platform --server --listen 0.0.0.0:1234 容器内启动。 我可以从主机 lldb 连接到容器 lldb-server,但我不能 attach/create 进程。

主机上的命令 运行(容器中的 lldb-server = localhost:1234) (lldb) platform select remote-linux Platform: remote-linux Connected: no (lldb) platform connect connect://localhost:1234 Platform: remote-linux Triple: x86_64-*-linux-gnu OS Version: 4.12.4 (4.12.4-1-ARCH) Kernel: #1 SMP PREEMPT Fri Jul 28 18:54:18 UTC 2017 Hostname: 099bd76c07c9 Connected: yes WorkingDir: /srv/core_service (lldb) target create target/debug/core_service Current executable set to 'target/debug/core_service' (x86_64). (lldb) process launch error: connect remote failed (Connection refused) error: process launch failed: Connection refused

我该如何解决?是否有任何 docker、arch linux 设置会导致此错误?

docker 容器中的 lldb-server 权限似乎有问题。

主机上的命令运行(容器中的 lldb 服务器) (lldb) platform shell ps -A PID TTY TIME CMD 1 ? 00:00:00 bash 9 ? 00:00:00 nginx 10 ? 00:00:00 nginx 11 ? 00:00:00 lldb-server 25 ? 00:00:00 core_service 59 ? 00:00:00 lldb-server 68 ? 00:00:00 ps (lldb) platform shell kill -9 25 (lldb) platform process launch target/debug/core_service error: connect remote failed (Connection refused) error: Connection refused (lldb) platform process launch anything error: connect remote failed (Connection refused) error: Connection refused 但我不知道它会是什么。 lldb-server 在容器中作为 root 运行,我可以使用 lldb 执行 shell 命令。

这可能是因为服务器看不到主机上的任何进程。它仍然包裹在自己的PID名称space中。启动 LLDB 服务器时,使用主机 pid 名称 space

docker run --pid=host --privileged <yourimage>

希望这能让您的容器看到所有主机进程

需要 platform 端口(在您的情况下为 1234)和 gdbserver 端口(默认情况下随机生成)。您可以通过 lldb-server 选项 --gdbserver-port.[=12 强制执行 gdbserver 端口=]

在 Fedora 29 上测试x86_64:

docker run --privileged -p 5000:5000 -p 5001:5001 fedora bash -c 'dnf -y install lldb;lldb-server platform --server --listen 0.0.0.0:5000 --gdbserver-port 5001'

echo 'int main(){}' >main.c;gcc -g -o main main.c;lldb -o 'platform select remote-linux' -o 'platform connect connect://localhost:5000' -o "target create ./main" -o 'b main' -o 'process launch'

(lldb) process launch
Process 45 stopped
* thread #1, name = 'main', stop reason = breakpoint 1.1
    frame #0: 0x000000000040110f main`main at main.c:1
-> 1    int main(){}

Process 45 launched: '/root/main' (x86_64)
(lldb) _