Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

c++ - Visual Studio doesn't break on assert violation

I'm debugging a CMake target in Visual Studio 2019 for a project which is managed by CMake and built using MinGW.

However, when an assertion fails the debugger simply quits without giving me a call stack or letting me inspect the current state of the program. (Normal breakpoints do suspend execution as expected.)

breakpoints_work

I've enabled Break When Thrown for all C++ Exceptions in Debug > Windows > Exception Settings, but to no avail.

How can I make Visual Studio break execution when an assertion fails?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is possible that the NDEBUG macro is enabled in your project and that stops VS from breaking on assertion failure.

From cppreference

If NDEBUG is defined as a macro name at the point in the source code where is included, then assert does nothing.

If NDEBUG is not defined, then assert checks if its argument (which must have scalar type) compares equal to zero. If it does, assert outputs implementation-specific diagnostic information on the standard error output and calls std::abort. The diagnostic information is required to include the text of expression, as well as the values of the standard macros FILE, LINE, and the standard variable func (since C++11).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...