6

Setup is a docker container running ubuntu 16.04, clang/lldb 6.0. I want to be able to remote debug an application, for now via another terminal instead of an IDE.

My docker file

FROM ubuntu:16.04
RUN apt update
RUN apt install -y curl git nano cmake build-essential xz-utils
RUN apt install -y clang-6.0 lldb-6.0
EXPOSE 2000
CMD [ "/bin/bash" ]

I spin my container as follows

docker run --privileged --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -it -v ~/Developer:/Developer -p 2000:2000 --name cpp-dev ubuntu-clang-dev

Debugging from within the container works

I can successfully compile and debug my program with clang++ and lldb when inside the container.

How I start my lldb-server

lldb-server-6.0 platform --server --listen *:2000

Now, from a separate terminal I do:

> lldb
> platform select remote-linux
> platform connect connect://localhost:2000
> target create test
> b main     (which returns breakpoint main at main.cpp:5)
> process launch

Errors: (lldb) process launch error: connect remote failed (Failed to connect port) error: process launch failed: Failed to connect port

What am I doing wrong?

2 Answers 2

5

I found it myself.

LLDB-server listens on port 2000 for incoming connections. Upon receiving such a request it spawns a separate 'lldb g : '. This secret port is not open to the outside world from my vm.

The easiest trick that works for me is to just have the container run on the same network as the host. Hence, once I start my container with:

docker run --privileged --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -it -v ~/Developer:/Developer **--network host** --name cpp-dev ubuntu-clang-dev

it all works fine and I can run the lldb from the host as advertised.

Sign up to request clarification or add additional context in comments.

Comments

2

You can specify the ports used by LLDB-server as such:

lldb-server platform --listen "*:31166" --server --min-gdbserver-port 31200 --max-gdbserver-port 31300

And of course you need to expose those ports in your Dockerfile:

EXPOSE 31166
EXPOSE 31200-31300

And also when you run the container:

docker run --privileged --name vapor-server -p 8080:8080 -p 31166:31166 -p 31200-31300:31200-31300 vapor-image

Please note you need to run the docker as privileged (--privileged option), otherwise attaching the debugger will fail with an Operation not Permitted error.

2 Comments

how do you know you need to reserve 100 ports for gdb? why not 10? 1000?
It’s been a while since I worked on this, but if I remember correctly the number of ports you'll need in the range depends on how many simultaneous debug connections you plan to handle. Typically, a modest number of ports should be sufficient. Consider the number of developers you want to allow connecting and debugging concurrently, and allow for some buffer for unexpected extra connections.