microsoft / vscode-dev-containers

NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!
https://aka.ms/vscode-remote
MIT License
4.71k stars 1.41k forks source link

Cannot debug a c++ program: "Program received signal SIGSEGV, Segmentation fault." #827

Open tomatac opened 3 years ago

tomatac commented 3 years ago

Steps to Reproduce:

  1. run the debugger to the first line of code of the main program (simple printf ())
  2. get a fault: Program received signal SIGSEGV, Segmentation fault. __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:65
  3. it happens for multiple programs that used to work
  4. if I run gdb, from the terminal, inside vs code, debugging is normal

Do you have any suggestions to troubleshoot this issue?

Chuxel commented 3 years ago

Interesting. Does this happen if you open up the https://github.com/microsoft/vscode-remote-try-cpp repository? (Or you can use the "Try a Sample" command and select C++).

This does not seem to reproduce for me on Ubuntu 20.04 using the Try a Sample method (nor on Windows + WSL2 w/ Ubuntu 20.04). I'd suggest raising a question about it with the C++ extension team at https://github.com/microsoft/vscode-cpptools/issues

tomatac commented 3 years ago

I will try the hello world setup that you suggested. Is there any logs I can look at or any other troubleshooting techniques that I should try?

Chuxel commented 3 years ago

The C++ extension folks will have the experience there to help out. I unfortunately can't transfer the issue, but you can reference this one highlighting that it does not seem to be with the container image since gdb itself works as expected. https://github.com/microsoft/vscode-cpptools/issues

It's also possible you're running out of memory if this is a low end device. I know the C++ team recommends the 4GB RPis for working with ARM since 1-2GB tends too be too little to load a program of any size. But the fact you're seeing it with a hello world application probably says its something else. They can also tell you if it looks like it might be a known issue. You also should not use an external terminal since that is not supported (you can add "externalConsole": false in your launch.json), but I wouldn't expect the error you mention there.

tomatac commented 3 years ago

Thank you for your suggestions @Chuxel This is interesting! If I open "vscode-remote-try-cpp" repo, debugging works ok. Now, I copied the Dockerfile, devcontainer.json, launch.json and tasksjson from "vscode-remote-try-cpp" into my project, rebuilt the container and I am still getting the error! I tried running as root and as vscode user. I get the same error. gdb works ok if I ran it from inside the VS Code terminal in the container.

It is interesting that when I choose the debug option I can see some Launch options from my old configuration, when my launch.json has only one configuration "Build Main" copied from the vscode-remote-try-cpp". image

Is VS Code cashing some data that can affect debugging in the container?

I will also open an issue on "vscode-cpptools" as you suggested but it looks it may have something to do with the environment of this particular project/container or maybe a new VS Code version. And as I mentioned before debugging used to work in this project.