如何在发布模式下调试?

2023-07-01C/C++开发问题
1

本文介绍了如何在发布模式下调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我必须调试一个 C++ 项目,但由于一个依赖项无法在调试模式下编译,而且我目前还无法解决该问题,我想尝试在发布模式下调试该项目.

I have to debug a c++ project, but as one dependency doesn't compile in debug mode and I haven't been able to fix that issue so far, I'd like to try to debug the project in release mode.

目前应用程序由于空指针而崩溃,但我没有导致错误的代码.由于断点显然在发布模式下被忽略,我想知道找到错误的最佳方法是什么.

Currently the application crashes due to a null pointer, but I haven't the code that's causing the error. As break points apparently are ignored in release-mode, I'd like to know what's the best way find the error.

推荐答案

在 VS 中,右键单击您的项目,选择属性".

In VS, right click your project, chose "Properties".

  1. 单击 C/C++ 节点.将调试信息格式设置为 C7 兼容 (/Z7) 或程序数据库 (/Zi).

  1. Click the C/C++ node. Set Debug Information Format to C7 compatible (/Z7) or Program Database (/Zi).

展开链接器并单击常规节点.将启用增量链接设置为否 (/INCREMENTAL:NO).

Expand Linker and click the General node. Set Enable Incremental Linking to No (/INCREMENTAL:NO).

选择调试节点.将生成调试信息设置为是 (/DEBUG).

Select the Debugging node. Set Generate Debug Info to Yes (/DEBUG).

选择优化节点.将引用设置为是 (/OPT:REF).

Select the Optimization node. Set References to Yes (/OPT:REF).

如果指定了/OPT:REF,则/OPT:ICF 默认开启.

if /OPT:REF is specified, /OPT:ICF is on by default.

这是直接从微软的文档中撕下来的:

That's ripped directly from Microsoft's documentation:

  • 如何:调试发布版本
  • OPT 优化

我一直这样做,几乎不再在调试模式下调试了.如您所知,发布版本中发生的许多错误可能不会发生在调试版本中(几乎可以肯定是调用 UB 引起的错误).

I do this all of the time and pretty much never debug in debug mode anymore. As you know, many errors that occur in a release build may not occur in a debug build (almost certainly the errors that arise from invoking UB).

此外,我从事一个项目,该项目使用大量图像处理并对大图像执行大量压缩/解压缩.使用缓慢的调试版本是不切实际的.

Also, I work on a project which uses a ton of image processing and performs a lot of compression/decompression of large images. Using a slow debug build is simply impractical.

这篇关于如何在发布模式下调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6