vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

cpptools crashes when gcc is not in $PATH of Docker container

Open fefe982 opened this issue 6 years ago • 3 comments

Type: General

Describe the bug

  • OS and Version: Win10
  • VS Code Version: 1.45.0(user setup)
  • C/C++ Extension Version: 0.28.0
  • Other extensions you installed (and if the issue persists after disabling them): Local: Remote - Containers 0.117.1 Remote -SSH 0.51.0 Remote - Development 0.20.0 On Dev container: CMake CMake Tools I removed every other extension in dev container and the problem persists (I cannot recall the versions installed now)
  • A clear and concise description of what the bug is. cpptools crashes on open.

To Reproduce Please include code sample and task.json files. Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context I am using Remote - Containers to work on a custom image based on centos-7, with devtoolset-9. No other gcc installed. So by default, gcc is not in PATH, but in /opt/rh/devtoolset-9/root/usr/bin. I added CC and CXX env to point to gcc and g++ though.

The setting worked very well before 0.28.0. After upgrading to 0.28.0, cpptoos crashes on start, and the extensions cannot work. I got 5 core files every time when I open the Dev Container in VS code.

I examined the core file with gdb .vscode-server/extensions/ms-vscode.cpptools-0.28.0/bin/cpptools core.3178, and get the following:

(gdb) bt
#0  0x00000000006ed526 in vscode::message_handler::cpptools_queryCompilerDefaults() ()
#1  0x00000000006cfe3b in vscode::message_handler::dispatch(vscode::vscode_client_message&&, vscode::vscode_server_message&, vscode::message_handler::msg_proc_thread_token) ()
#2  0x00000000006cc5a1 in vscode::message_handler::handle_message(vscode::vscode_client_message&&, vscode::message_handler::msg_proc_thread_token) ()
#3  0x0000000000714ed7 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<vscode::message_handler::main_loop()::$_3> > >::_M_run() ()
#4  0x0000000000dbb960 in execute_native_thread_routine ()
#5  0x00007f6109107e65 in start_thread () from /lib64/libpthread.so.0
#6  0x00007f6108e3088d in hcreate_r () from /lib64/libc.so.6
#7  0x0000000000000000 in ?? ()

The function name cpptools_queryCompilerDefaults reminds me that my gcc/g++ is not in PATH, and may be it is trying to find my compiler but cannot.

After modifying my .devcontainer.json and put /opt/rh/devtoolset-9/root/usr/bin in $PATH with containerEnv, the extension works again.

fefe982 avatar May 13 '20 15:05 fefe982

@fefe982 Can you provide the language server logs when reproducing the issue? Instructions to enable and get the logs are at https://code.visualstudio.com/docs/cpp/enable-logging-cpp#_enable-logging-for-the-language-server.

The logs should show the full compiler path the extension is trying to execute.

And just to clarify, this was not an issues in 0.27.1 and even before setting the following?

After modifying my .devcontainer.json and put /opt/rh/devtoolset-9/root/usr/bin in $PATH with containerEnv, the extension works again.

And by $PATH, do you mean the $PATH in the Windows environment or in the container or in the container .devcontainer.json like the one defined at https://code.visualstudio.com/docs/remote/containers#_variables-in-devcontainerjson?

michelleangela avatar May 13 '20 23:05 michelleangela

I enabled the language server logs, and only got

Custom configuration provider 'CMake Tools' registered

fro C/C++ (I reinstalled CMake Tools 1.3.1 and CMake 0.0.17 after I made the extension work by modifying PATH).

I cannot find the C/C++ in the dropdown box for OUTPUT when CMake Tools is disabled.

For cpptools, I got:

[Error - 9:38:23 AM] Connection to server got closed. Server will not be restarted.

And I noticed that if there is no cpp files open in the foreground (e.g. when I have the settings editor open), there is only one core file generated. But when I switch to a cpp file, more cores would appear.

There is no issue with 0.27.1 . I tried to revert the extension to 0.27.1 after I found that the extension is not working, and 0.27.1 worked fine.

by $PATH, I mean the PATH in my contaner, which I manipulated through .devcontainer.json.

And in case it may be relevent, my .devcontainer.json is:

{
    "image": "build_env",
    "workspaceMount": "source=/path/USERNAME/PROJECT,target=/opt/app-root/src/PROJECT,type=bind",
    "workspaceFolder": "/opt/app-root/src/PROJECT",
    "remoteUser": "USERNAME",
    "mounts": [
        "source=/path/USERNAME/dev_env/PROJECT/home,target=/home/USERNAME/,type=bind",
        "source=/path/USERNAME/.ssh,target=/home/USERNAME/.ssh,type=bind,readonly"
    ],
    "appPort": ["0.0.0.0:8088:8088"],
    "runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],
    "containerEnv": {
        "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
        "ENV": "/opt/app-root/etc/scl_enable",
        "BASH_ENV": "/opt/app-root/etc/scl_enable",
        "PROMPT_COMMAND": "source /opt/app-root/etc/scl_enable",
        "CC": "/opt/rh/devtoolset-9/root/usr/bin/gcc",
        "CXX": "/opt/rh/devtoolset-9/root/usr/bin/g++"
    }
}

The extension would work when I change the PATH line to "PATH": "/opt/rh/devtoolset-9/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

The Dockerfile for build_env is :

RUN yum install -y devtoolset-9-gdb devtoolset-9-valgrind && \
    yum install -y https://centos7.iuscommunity.org/ius-release.rpm && \
    yum install -y git2u

RUN ln -s cmake3 /bin/cmake

COPY ./root/ /

ADD https://github.com/protocolbuffers/protobuf/releases/download/v3.11.4/protobuf-cpp-3.11.4.tar.gz /opt/app-root/src/

RUN cd /opt/app-root/src/ && \
    tar -xzvf protobuf-cpp-3.11.4.tar.gz && \
    cd protobuf-3.11.4 && \
    source /opt/app-root/etc/scl_enable && \
    ./configure --disable-shared && make -j && make install && make distclean

ADD https://github.com/gflags/gflags/archive/v2.2.2.tar.gz /opt/app-root/src/gflags-v2.2.2.tar.gz

RUN cd /opt/app-root/src/ && \
    tar -xzvf gflags-v2.2.2.tar.gz && \
    cd gflags-2.2.2 && \
    mkdir build && cd build && \
    source /opt/app-root/etc/scl_enable && \
    cmake -D BUILD_SHARED_LIBS=0 .. && \
    make -j && make install && rm -rf *

ADD https://github.com/apache/incubator-brpc/archive/0.9.7.tar.gz /opt/app-root/src/brpc-0.9.7.tar.gz

RUN cd /opt/app-root/src/ && \
    tar -xzvf brpc-0.9.7.tar.gz && \
    cd incubator-brpc-0.9.7 && \
    source /opt/app-root/etc/scl_enable && \
    ./config_brpc.sh --headers="/usr/local/include/ /usr/include" --libs="/usr/lib64 /usr/local/lib /usr/local/bin" && \
    make -j libbrpc.a output/include && \
    mv output/include/* /usr/local/include && \
    mv libbrpc.a /usr/local/lib

ARG USERNAME=xxxx
ARG USER_UID=1003
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
    && yum install -y sudo \
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
    && chmod 0440 /etc/sudoers.d/$USERNAME

ENV TZ=Asia/Shanghai

USER $USERNAME

CMD ["/bin/bash", "-c", "#(noop)"]

The ./root/ directory mentioned in the dockfiler contains only one file ./root/opt/app-root/etc/scl_enable, which is copied and modified from devtoolset-container :

# IMPORTANT: Do not add more content to this file unless you know what you are
#            doing. This file is sourced everytime the shell session is opened.
#
# This will make scl collection binaries work out of box.
unset BASH_ENV PROMPT_COMMAND ENV
source scl_source enable devtoolset-9

fefe982 avatar May 14 '20 02:05 fefe982

Fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/0.28.1 .

sean-mcmanus avatar May 21 '20 01:05 sean-mcmanus