7

So far I was able to understand following about docker:

  1. You can use it to containerise your application - sandboxing.

  2. You can use it as a build container, by "bind mounting" your source code directory and using build tools inside container to build it.

I am using docker for second use-case.

Question:

I am having a project with mixed C and C++ components, which I want to develop entirely inside docker container, as it requires lots of environment configuration and has old library dependencies, and I don't want to pollute environment of my development (host) machine.

I am able to build it inside docker using "gcc" but I am not able to figure out how to debug it.

I tried debugging it with gdbserver over a network port and attaching it's process inside Eclipse CDT (on host), but it don't maps back to my source-code rather it displays assembly code.

I would like to have it map back to my source-code for easy debugging. Can someone please suggest me appropriate workflow or point me in right direction ?

Blaze
  • 1,642
  • 2
  • 22
  • 20
  • Related: https://stackoverflow.com/questions/4038760/how-to-set-up-the-eclipse-for-remote-c-debugging-with-gdbserver/45608937 – πάντα ῥεῖ Mar 10 '19 at 07:52
  • 2
    @Someprogrammerdude taken your suggestion into account - hope it gives better visibility – Blaze Mar 10 '19 at 07:54
  • @πάνταῥεῖ tried that, but it lands into an assembly code - it isn't normal, is it ? – Blaze Mar 10 '19 at 07:56
  • 5
    Assuming you build with debug information enabled (using the GCC `-g` flag), then is the paths to the source files the same in your Docker environment and your host environment? – Some programmer dude Mar 10 '19 at 08:00
  • @Someprogrammerdude, yes the path is same. Basically, I am bind-mounting from my host, which necessarily copy my host-directory, which contains all the source, to docker container. – Blaze Mar 10 '19 at 13:06
  • I think the process that I am adopting is somewhat malicious. Currently, I "make" inside docker and then initiate "gdbserver :5000 " command and then I attach to the gdbserver port from (outside) host using eclipse. I wonder how will eclipse map the gdbserver process, running in docker, to source file. Any suggestions ? – Blaze Mar 10 '19 at 13:11
  • 2
    Except the path seen by the container is NOT the path as seen by the host unless you happened to mount them in precisely the same place. Have a look at gdb's options to change the source-path https://sourceware.org/gdb/onlinedocs/gdb/Source-Path.html – marko Mar 10 '19 at 23:17
  • I ended up moving my workflow outside of docker as the development inside docker, though possible, is very iterative. Even outside docker with Eclipse CDT I was facing issue - that of debugger jumping to assembly. Since then, I moved to KDevelop and I am very happy with it's first citizen CMake support. – Blaze Jul 11 '19 at 11:38
  • 1
    I've not tested it (thus leaving it as comment for now), but Visual Code has built-in support for development (including debugging) inside containers: https://code.visualstudio.com/docs/remote/containers – R2RT Jul 15 '19 at 09:57

1 Answers1

-2

GDB is a debugger for Linux that can debug both c and c++

all you need to do is compile with the -g option gdb ./filename

gcc -o test test.c -g

gdb ./test
AVIK DUTTA
  • 736
  • 6
  • 23
  • Care to answer why this was down rated ? This actually worked perfect in docker where heavy weight IDE like Eclipse are not best option. – Blaze Jul 11 '19 at 11:34
  • @Blaze I have downvoted, since I assumed using raw `gdb` is always an option, but I would not name it "easy debugging". Especially given the fact in your question you seek for IDE-level debugging. Also, for when you use `gdb`, the Docker part of question is quite irrelevant (as everything happens inside Docker container). – R2RT Jul 15 '19 at 09:54