che icon indicating copy to clipboard operation
che copied to clipboard

Eclipse Che - Debugging C++ code

Open MuraliVidhya opened this issue 9 years ago • 19 comments

Hi,

In Che workspace (c++ stack), i created new c++ project (basic application with some cout statements). i could run the application successfully. In order to debug - as in https://www.eclipse.org/che/docs/ide/debug/index.html#gdb, configuration is done. But the debug windows does not show anything other than breakpoints, is this a known issue ? Any support would be helpful.

Environment: Linux Che : 5.7.0

MuraliVidhya avatar Apr 06 '17 04:04 MuraliVidhya

@mvidhya86 currently, using gdb debugger required privileged mode for a workspace container.

In your che.env, uncomment the following line, set it to true and restart Che:

#CHE_DOCKER_PRIVILEGED=false

This is a Docker security limitation.

ghost avatar Apr 06 '17 04:04 ghost

Hi, I modified che.env and restarted, on click of debug, i get "Can not connect to: localhost ".

MuraliVidhya avatar Apr 06 '17 08:04 MuraliVidhya

Can you provide a screenshot?

ghost avatar Apr 06 '17 09:04 ghost

[cid:[email protected]]

Can you provide a screenshot?

MuraliVidhya avatar Apr 06 '17 09:04 MuraliVidhya

I can't see the image, sorry.

ghost avatar Apr 06 '17 09:04 ghost

@mvidhya86 attach screenshot to the issue on Github. Do not reply via email

ghost avatar Apr 06 '17 10:04 ghost

Works on my side:

image

Make sure your workspace container runs in a privileged mode (run docker inspect against it). Also, make sure you compile your binary with -g

ghost avatar Apr 06 '17 11:04 ghost

@eivantsov - In che.env - CHE_DOCKER_PRIVILEGED is set to true. After restarting the container, docker inspect --format='{{.HostConfig.Privileged}}' containerID => returns false

Also tried this one: docker run -it --privileged=true --rm -v /usr/local/codenvy/chedata:/data -v /var/run/docker.sock:/var/run/docker.sock eclipse/che start but of no luck

And inside Che - debug still gives - can not connect to localhost error

MuraliVidhya avatar Apr 10 '17 05:04 MuraliVidhya

Do you run docker inspect against a workspace container?

Can you share screenshots with your gdb debugger setup?

ghost avatar Apr 10 '17 06:04 ghost

Hi, I got the debugger working. But still have some questions here: docker run -it --rm -v /usr/local/codenvy/chedata:/data -v /var/run/docker.sock:/var/run/docker.sock eclipse/che start

and in /usr/local/codenvy/chedata/che.env => CHE_DOCKER_PRIVILEGED is set to true docker inspect dc2 |less => has CHE_DOCKER_PRIVILEGED set to true

After this, i created new workspace (c++ stack) docker ps listed new container as well and now, docker inspect e22 |less => has no variable by name - CHE_DOCKER_PRIVILEGED How do i ensure that workspace container is also in PRIVILEGED mode ? But it has privileged under hostconfig - which is set to true

With these steps, in c++ project => shows debugger with the local binary set and and Host as localhost

MuraliVidhya avatar Apr 11 '17 06:04 MuraliVidhya

There should not be any env variables injected into a workspace. When CHE_DOCKER_PRIVILEGED is set to true workspace containers are run in a privileged mode, ie when Che triggers Docker, this parameter is passed to Docker API.

ghost avatar Apr 11 '17 06:04 ghost

@eivantsov - Do we have any alternatives here, as running container in privileged mode will have security issues (as it is mentioned in blogs) and also it is not recommended for production/ci environments

MuraliVidhya avatar Apr 18 '17 05:04 MuraliVidhya

@mvidhya86 I do not have any alternatives since Docker does not offer ones for running gdb and/or gdbserver in a container

ghost avatar Apr 18 '17 06:04 ghost

@eivantsov - ok, could you confirm that debugging works fine with newer version of che 5.8.0. i did the same steps - workspace container shows Privileged as true.

Compilation with -g and in project with -Debug configuration as below: Name=remoteGDB, DebugLocalBinary checked, Host=localhost Port is blank and BinaryPath=${current.project.path}/a.out , click of Debug does not show up anything

The same steps are going fine with version 5.7.2

MuraliVidhya avatar Apr 18 '17 11:04 MuraliVidhya

@mvidhya86 can you flush your browser's local storage? This is a know issue - https://github.com/eclipse/che/issues/4582

ghost avatar Apr 18 '17 11:04 ghost

Thanks, it works fine now (after clearing browser's local storage)

MuraliVidhya avatar Apr 18 '17 12:04 MuraliVidhya

@eivantsov - remote debugging with gdbserver also needs Privileged Mode ?

Because i see: gdbserver localhost:2020 sampleproj/a.out gdbserver: linux_ptrace_test_ret_to_nx: Cannot PTRACE_TRACEME: Operation not permitted gdbserver: linux_ptrace_test_ret_to_nx: status 256 is not WIFSTOPPED!

(Note: With privileged mode - remote debugging works fine )

MuraliVidhya avatar Apr 20 '17 11:04 MuraliVidhya

@mvidhya86 yes, bpth gdb and gdbserver require privileged mode.

ghost avatar Apr 20 '17 11:04 ghost

Closing the issue.

ghost avatar Apr 26 '17 07:04 ghost