如何使用 debug free 停止 Visual Studio

发布于 2024-12-10 14:57:29 字数 289 浏览 0 评论 0原文

我的应用程序需要释放一个非常大的哈希表,并且在调试模式下速度非常慢,慢到我无法实际使用它......但在发布模式下我根本没有调试符号.. 我需要调试可执行文件并了解我应该能够将其与 crt 库的发行版本链接。 我通过更改“代码生成”选项以使用“多线程 dll”而不是“多线程调试 dll”来完成此操作,但是当我在哈希表自由例程中放置断点并遵循它进行实际的自由调用时,它是使用调试 dll 中的函数。

我还能尝试什么吗?使用发布配置并尝试让它为我实际需要调试的东西生成符号是一个更好的选择吗?

(顺便说一句,与 2010 年相比)

My application needs to free a very large hash table, and it is incredibly slow in debug mode, so slow that I can not realistically work with it...but in release mode I have no debug symbols at all..
I need to debug the executable and understand I should be able to get it to link with release versions of the crt libraries.
I have done this by changing my "code generation" options to use "multithreaded dll" rather than "multithreaded debug dll", however when I put a breakpoint in my hash table free routine and follow it through to the actual free call, it is using a function in a debug dll.

Anything else I can try? Is it a better option to work with the release configuration and try and get that to generate symbols for the stuff I actually need to debug?

(vs 2010 btw)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

未央 2024-12-17 14:57:29

尽管使用发布 CRT 并打开了所有优化,您仍然可以拥有调试符号。事实上,这就是 Visual C++ 在发布配置中的默认设置(请参阅项目属性/配置属性/C/C++/常规/调试信息格式;以及链接器/调试/生成调试信息)。请注意,优化的代码可能更难调试 - 指令的顺序可能会改变,并且某些部分可能会被完全优化掉,从而在单步执行代码时导致一些意外的行为。

顺便说一句,要关闭调试 CRT,仅将“多线程调试 DLL (/MDd)”更改为“多线程 DLL (/MD)”是不够的,还需要删除 _DEBUG< /code> 来自预处理器定义。

话虽这么说,您遇到的缓慢可能根本不是您的程序的结果 - 这可能是调试器工件(即为了在调试器 UI 中显示大型数据结构而读取它们的缓慢)。请尝试在调试器之外运行您的程序(调试或发布配置 - 这并不重要),看看这是否会产生影响。

如果是这样,并且您不能仅出于调试目的而缩小哈希表,则必须求助于“printf 调试”(即手动插入诊断)或尝试远程调试。

You can have debug symbols despite using release CRT and having all the optimizations turned-on. In fact this is what Visual C++ defaults to in Release configuration (see the Project Properties / Configuration Properties / C/C++ / General / Debug Information Format; and Linker / Debugging / Generate Debug Info). Please note that optimized code might be harder to debug - order of instructions may be changed and some pieces may be optimized-away entirely, causing some unexpected behavior when stepping through the code.

BTW, to turn-off the debug CRT, it is not enough to just change "Multi-threaded Debug DLL (/MDd)" to "Multi-threaded DLL (/MD)", you also need to remove _DEBUG from Preprocessor Definitions.

That being said, the slowness you are experiencing may not be the consequence of your program at all - this may a debugger artifact (i.e. the slowness of reading large data structures for the purpose of displaying them in debugger UI). Please try running your program (Debug or Release configuration - it does not matter much) outside debugger and see if this makes a difference.

If so, and you can't make your hash table smaller just for the purpose of debugging, you'll have to either resort to "printf debugging" (i.e. manually insert diagnostics) or possibly try the remote debugging.

反差帅 2024-12-17 14:57:29

将其添加到 stdafx.h 的开头或将其定义为调试版本的预处理器宏:

#define _SECURE_SCL 0

它将导致发生以下情况,使您的代码在调试模式下运行得更快:

所有标准迭代器均未选中(迭代器可以超越容器边界,导致未定义的行为)。
对于具有检查形式的标准函数,将使用函数的未检查形式(参见下面的列表)。

如果输出迭代器是经过检查的迭代器:

  • 您将在调用标准函数(例如 std::copy)时检查行为。
  • 您将在调用已检查函数(例如 stdext::checked_copy)时获得已检查行为。
  • 您将在调用未经检查的函数(例如 stdext::unchecked_copy)时获得经过检查的行为。

如果输出迭代器是未经检查的迭代器:

  • 调用标准函数(例如 std::copy)时,您将获得未经检查的行为。
  • 调用已检查函数(例如 stdext::checked_copy)将导致编译器警告。
  • 调用未经检查的函数(例如 stdext::unchecked_copy)时,您将获得未经检查的行为。

您可以在 MSDN 的检查迭代器部分了解有关此行为的更多信息。通常,您希望在调试构建时打开已检查的迭代器,但某些应用程序会在短时间内执行大量操作,这可能会造成麻烦。

Add this at the start of stdafx.h or define it as a pre-processor macro for your debug build:

#define _SECURE_SCL 0

It will cause the following to happen, making your code run faster in debug mode:

All standard iterators are unchecked (iterators can move beyond the container boundaries, leading to undefined behavior).
The unchecked form of a function will be used, for standard functions with checked forms (see list below).

If an output iterator is a checked iterator:

  • You will get checked behavior on calls to the standard function (std::copy, for example).
  • You will get checked behavior on calls to a checked function (stdext::checked_copy, for example).
  • You will get checked behavior on calls to an unchecked function (stdext::unchecked_copy, for example).

If an output iterator is an unchecked iterator:

  • You will get unchecked behavior on calls to the standard function (std::copy, for example).
  • Calls to a checked function (stdext::checked_copy, for example) will result in compiler warnings.
  • You will get unchecked behavior on calls to an unchecked function (stdext::unchecked_copy, for example).

You can read more about this behavior in the Checked Iterators section of MSDN. Normally, you want checked iterators to be turned on for Debug builds, but there are certain applications that perform a lof of operations in a short period of time where they can become a nuisance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文