Visual Studio调试迭代器 [英] Visual Studio debug iterators

查看:342
本文介绍了Visual Studio调试迭代器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

_SECURE_SCL _ HAS_ITERATOR_DEBUGGING
是否可以打开/关闭范围检查并保留二进制兼容性?



2008和2010版本之间有什么区别?

解决方案

Stephan Lavavej提供了有关此 _SECURE_SCL _HAS_ITERATOR_DEBUGGING



http://blogs.msdn.com/b/vcblog/archive/2007/08/10/the-future-of-the-c-language.aspx < a>


迭代器调试,由
_HAS_ITERATOR_DEBUGGING启用,执行强大的正确性验证。
迭代器检查,由
_SECURE_SCL启用,执行最小检查,作为安全的最后一行
防御。例如,_SECURE_SCL
将通过向量迭代器终止触发
a堆溢出的程序。



所有这一切都由MSDN解释
文档。这个
背后的故事很有趣。
_HAS_ITERATOR_DEBUGGING功能是由Dinkumware提供的,
公司授权他们最多的
胜利的实现
标准库包含在
Visual Studio中。 Microsoft提供了_SECURE_SCL
功能
,以提高在Windows上运行的
程序的安全性。为了执行它们的检查,
_HAS_ITERATOR_DEBUGGING和_SECURE_SCL使迭代器包含额外的数据成员,例如
指向其父容器的指针。
_HAS_ITERATOR_DEBUGGING,因为默认情况下在调试模式下启用它(和
在发布模式下不可用),
构建单一链接列表,允许
容器引用它们的所有
迭代器。这是昂贵的
性能,但性能是
在调试模式下不重要,这个
可以进行优异的检查。



_SECURE_SCL ,因为它在发布模式中默认启用,力图
施加最小的性能损失。
因此,当它被启用时,
虽然迭代器有指针返回
到它们的容器,容器不
有指向它们的迭代器的指针。
(更新迭代器列表对于发布模式来说太过耗费
。)


在VS 2010中,在发布模式中,默认情况下不再启用 _SECURE_SCL (上面摘录自2007年)。



如此错误报告中所述( http:// connect。 microsoft.com/VisualStudio/feedback/details/334315/has-iterator-debugging-0-causes-crash ), _SECURE_SCL _HAS_ITERATOR_DEBUGGING 会影响ABI:


_SECURE_SCL和_HAS_ITERATOR_DEBUGGING明显改变STL的行为和
表示容器和
迭代器。 VC9(Visual Studio 2008)
表示STL
容器和迭代器更多
强烈依赖_SECURE_SCL和
_HAS_ITERATOR_DEBUGGING(这是为了修复一个一致性错误)。



因为这些宏改变了STL对象的
表示,当
从$ b $更改这些宏时,
必须遵守某些规则b默认值。我在这里描述规则:
http://blogs.msdn.com/vcblog/archive/2007/08/10/the-future-of-the-c-language.aspx#4617984 总而言之,宏必须是
在每个二进制文件(EXE或
DLL)内一致,此外,
将STL对象传递给对方的二进制文件必须
具有一致的宏设置。您的
示例涉及一个EXE和DLL

之间传递一个向量,因此EXE和DLL需要
具有相同的_SECURE_SCL和
_HAS_ITERATOR_DEBUGGING设置。 p>

这些规则适用于VC8,VC9和所有
未来版本。你的代码发生在
与VC8(Visual Studio 2005),
工作,但如果更多
复杂的事情会失败。



What is the relation between _SECURE_SCL and _HAS_ITERATOR_DEBUGGING. Is it possible to turn on/off range checking and preserve binary compatibility?

Any difference between 2008 and 2010 versions?

解决方案

Stephan Lavavej has provided some detail on this _SECURE_SCL and _HAS_ITERATOR_DEBUGGING:

From http://blogs.msdn.com/b/vcblog/archive/2007/08/10/the-future-of-the-c-language.aspx

Iterator debugging, enabled by _HAS_ITERATOR_DEBUGGING, performs powerful correctness verification. Iterator checking, enabled by _SECURE_SCL, performs minimal checks that serve as a last line of security defense. For example, _SECURE_SCL will terminate a program that triggers a heap overrun with a vector iterator.

All that is explained by MSDN documentation. The story behind this is interesting. The _HAS_ITERATOR_DEBUGGING functionality was provided by Dinkumware, the company that licenses their most triumphant implementation of the Standard Library for inclusion in Visual Studio. The _SECURE_SCL functionality was added by Microsoft, in order to improve the security of programs running on Windows. In order to perform their checks, both _HAS_ITERATOR_DEBUGGING and _SECURE_SCL make iterators contain additional data members, such as pointers to their parent containers. _HAS_ITERATOR_DEBUGGING, because it is enabled by default in debug mode (and not obtainable in release mode), also builds singly linked lists that allow containers to refer to all of their iterators. This is expensive performance-wise, but performance is not critical in debug mode, and this enables excellent checks.

_SECURE_SCL, because it is enabled by default in release mode, strives to impose minimal performance penalties. Therefore, when it is enabled, although iterators have pointers back to their containers, containers don't have pointers to their iterators. (Updating "iterator lists" is too time-consuming for release mode.)

Note that starting in VS 2010, _SECURE_SCL is no longer enabled by default in release mode (the above excerpt is from 2007).

As described in this bug report (http://connect.microsoft.com/VisualStudio/feedback/details/334315/has-iterator-debugging-0-causes-crash), both _SECURE_SCL and _HAS_ITERATOR_DEBUGGING affect the ABI:

_SECURE_SCL and _HAS_ITERATOR_DEBUGGING significantly change the behavior and representations of STL containers and iterators. VC9 (Visual Studio 2008) made the representations of STL containers and iterators even more strongly dependent on _SECURE_SCL and _HAS_ITERATOR_DEBUGGING (this was done to fix a conformance bug).

Because these macros change the representations of STL objects, you must observe certain rules when changing these macros from their defaults. I described the rules here: http://blogs.msdn.com/vcblog/archive/2007/08/10/the-future-of-the-c-language.aspx#4617984 To summarize, the macros must be consistent within each binary (EXE or DLL), and furthermore, binaries that pass STL objects to each other must have consistent macro settings. Your example involves an EXE and DLL passing a vector between themselves, so the EXE and DLL need to have the same _SECURE_SCL and _HAS_ITERATOR_DEBUGGING settings.

These rules apply to VC8, VC9, and all future versions. Your code happened to work with VC8 (Visual Studio 2005), but would fail if it did more complicated things.

这篇关于Visual Studio调试迭代器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆