如何在visual studio调试中禁用在函数中添加保护字节? [英] How to disable adding guard bytes in a function in visual studio debug?

查看:137
本文介绍了如何在visual studio调试中禁用在函数中添加保护字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

Visual studio在局部变量之前和之后添加保护字节来检测缓冲区溢出,非常有用,但是我想对一些使用了很多次的简单和简短函数禁用它。例如,在此函数中

  int  get_first_char( char  * buf, size_t  len)
{
return len> ; 0 ? buf [ 0 ]: - 1 ;
}

这个函数只是一个例子,请不要讨论它的用处。

我希望visual studio在调试模式下不要添加保护字节调用此函数时堆栈。

有没有办法做到这一点?



编辑:在发布模式下构建不添加保护字节。我想仅在调试模式下禁用一些简单函数的保护字节,因为如果多次调用这些函数,在调试模式下测试我的应用程序会显着减慢。



提前谢谢

mr.abzadeh

解决方案

在VS 2010中,打开项目属性页面,转到C / C ++ - >代码生成。有一个名为缓冲区安全检查(/ GS)的选项可能正是您所说的。您可以在那里禁用它,或在命令行中添加/ GS-以禁用它。



PS:/ GS上的帮助页面提供了更多信息,除其他外,编译器不扩展缓冲区的特定情况,例如: G。当函数的第一行是内联汇编时,或者当它是关键字 naked



  __ declspec  naked  int  func(formal_parameters){} 



在帮助页面中查看 naked 以获取更多信息。


我能想到的唯一解决方案是在Release模式下构建它。您仍然可以通过这种方式进行调试,但它会进行一些Debug构建不会优化(例如,您可能无法始终在声明变量的行上命中断点,因为可能会删除该变量)。

我倾向于认为如果激活该选项是全局的。这就是它适用于所有内存分配。



您是否为性能做了大量内存分配?



另外,你确定阴谋与保护字节有关吗?


Hello everyone
Visual studio adds guard bytes before and after local variables to detect buffer overruns, very usefull, but I want to disable it for some simple and short functions which are used so many times. for example, In this function

int get_first_char( char * buf, size_t len )
{
  return len > 0 ? buf[0] : -1;
}

this function is only an example, please do not discuss it''s usefullness.
I want visual studio in debug mode not to add guard bytes to stack when this function is called.
Is there any way to do this?

EDIT: building in release mode does not add guard bytes. I want to disable guard bytes for some simple functions only in debug mode, because testing my application in debug mode slows down significantly if that functions are called so many times.

thanks in advance
mr.abzadeh

解决方案

In VS 2010, open the project property pages, go to C/C++ -> Code Generation. There is an option called "Buffer Security Check" (/GS) which may be what you''re talking about. You can disable it right there, or add "/GS-" on the command line to disable it.

P.S.: the help page on /GS offers additional information, among other things specific circumstances under which the compiler does not extend the buffers, e. g. when the first line of a function is inline assembly, or when it hs the keyword naked:

__declspec( naked ) int func( formal_parameters ) {}


Check out naked in the help pages for more info.


The only solution I could think of is to build it in Release mode. You can still debug it that way, but it will make some optimizations that Debug builds do not (for example, you may not always be able to hit break points on lines that declare variables, because the variable may be eliminated).


I tend to believe that the option is global if activated. That is it will apply to all memory allocations.

Are you doing a lot of memory allocation for performance to be a problem?

Also, are you sure that the penality is related to guard bytes ?


这篇关于如何在visual studio调试中禁用在函数中添加保护字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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