This took me full days to find, so I am posting this for future reference.
I am developing C on a docker image. I am using clion.
My code is compiled in debug mode, and runs fine in run mode, but when trying to debug, the process exits immediately with the very informative
Process finished with exit code 1
When switching the debugger from
to
Trying to debug still exits, but yields a popup in clion
'A packet returned error 8'
The same code debugs fine on a local computer.
The docker run
command is
RUN_CMD="docker run --group-add ${DOCKER_GROUP_ID} \
--env HOME=${HOME} \
--env="DISPLAY" \
--entrypoint /bin/bash \
--interactive \
--net "host" \
--rm \
--tty \
--user=${USER_ID}:${GROUP_ID} \
--volume ${HOME}:${HOME} \
--volume /mnt:/mnt \
$(cat ${HOME}/personal-uv-docker-flags) \
-v "${HOME}/.Xauthority:${HOME}/.Xauthority:rw" \
--volume /var/run/docker.sock:/var/run/docker.sock \
--workdir ${HOME} \
${IMAGE} $(${DIR}/impl/known-tools.py cmd-line ${TOOL})"
How to debug C on docker?
CodePudding user response:
Eventually, I found this comment which led me to this blog post, in which I learned C debugging is disallowed on docker by default.
The arguments --cap-add=SYS_PTRACE and --security-opt seccomp=unconfined are required for C memory profiling and debugging in Docker.
I added
--cap-add=SYS_PTRACE --security-opt seccomp=unconfined
to the docker run
command, and the debugger was able to connect.