簡體   English   中英

遠程LLDB調試-Docker容器

[英]Remote LLDB debugging - Docker container

我正在嘗試使用LLDB 4.0.1設置遠程調試。 有一個帶有Arch Linux的docker(17.06.0-ce)容器。 Docker容器設置為特權模式 ,因此現在可以在容器中啟動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) 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) 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,但是無法附加/創建進程。

在主機上運行的命令(容器中的lldb服務器= 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 (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 arch設置?

似乎,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) 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) 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命令。

同時需要平台端口(在您的情況下為1234)和gdbserver端口(默認情況下隨機生成)。 您可以通過lldb-server選項--gdbserver-port強制執行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) _

這可能是因為服務器看不到主機上的任何進程。 它仍然包裝在自己的PID名稱空間中。 啟動LLDB服務器時,請使用主機pid名稱空間

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

希望這將使您的容器能夠看到所有主機進程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM