krjw
krjw

Reputation: 4450

Why does Visual Studio Code catch an exception in the very beginning of my main?

I am using Visual Studio Code 1.33.0 with a custom build arm-linux-gnueabi linaro c++ cross-compiler for the rpi3 based on the gcc 7.3.1. I am debugging the remotely attached rpi3 with gdbserver. I use opencv and pipe a X11 window through ssh.

I am on Mac OS 10.14.4

Visual Studio Code pauses debugging right here:Exception has occured

After pressing f5 or continue again it opens the X11 Window and everything works fine. So it doesn't crash nor quits.

Has someone experienced this behavior before?

EDIT4:

I think this is tied to the following problem: https://github.com/Microsoft/vscode-cpptools/issues/763#issuecomment-305001194

EDIT3:

Exception is not caused by piping through the window.

EDIT2:

This works without an exception on Windows 10 with Visual Studio 2017 Community, same setup, same project, same compiler (linaro 7.3.1) and VisualGDB

EDIT: This is what the Callstack looks like. I am not executing any code before main. There are just some global static constexpr.

Callstack and variables

Upvotes: 0

Views: 1468

Answers (1)

metal
metal

Reputation: 6332

Update: As @rustyx noted in the comments, the sort of problem I describe here probably would not produce the symptom in the OP because the program does continue. Most likely it is a problem in the toolchain / inter-device debugging.

I'd suggest trying GDB by itself and see if you get the same results or more info.


This can happen if you have initialized some global or static variable before main(), and that initialization causes an exception. See Matt Godbolt's talk at CppCon 2018 "The Bits Between the Bits: How We Get to main()".

Consider this:

int main() {}

// Initialized before main
static const auto x = []( auto i ) { if( i == 0 ) throw; return i; }( 0 );

Upvotes: 3

Related Questions