运行时数组边界与G ++检查 [英] Runtime array bounds checking with g++

查看:129
本文介绍了运行时数组边界与G ++检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法做数组边界与g ++的检查? Valgrind的不能检测栈上分配的数组溢出。此外,参数-fbounds检查只为GCC(根据实施<一个href=\"http://www.lrde.epita.fr/~akim/ccmp/doc/bounds-checking.html\">http://www.lrde.epita.fr/~akim/ccmp/doc/bounds-checking.html).理想情况下,源$ C ​​$ C不应该以任何方式修改。

Is there any way to do array bounds checking with g++? Valgrind can't detect overflows on arrays allocated on the stack. Additionally, the argument -fbounds-checking is only implemented for gcc (according to http://www.lrde.epita.fr/~akim/ccmp/doc/bounds-checking.html). Ideally, the source code shouldn't be modified in any way.

推荐答案

有一个工具 - 实验 - 所谓Ptrcheck,做检查堆栈数组边界溢出。用下面的选项运行Valgrind的:

There is a tool - experimental - called Ptrcheck that does check stack array bound overrun. Run Valgrind with the following option:

--tool=exp-ptrcheck

下面是Ptrcheck一些信息: http://valgrind.org/docs/manual /sg-manual.html

Here is some information on Ptrcheck: http://valgrind.org/docs/manual/sg-manual.html

编辑:这个工具是现在被称为SGCheck,并且可以使用运行 - 工具= EXP-sgcheck

edit: this tool is now known as SGCheck, and can be run using --tool=exp-sgcheck

需要注意的是限制的:

平台:堆栈/全局检查将不能正常PowerPC上,ARM工作
  或S390X平台,只有在x86和AMD64目标。这是因为
  堆栈和全局检查需要跟踪函数调用和退出
  可靠,而且也没有明显的方式做到这一点上使用链接的ABI
  注册函数返回。

Platforms: the stack/global checks won't work properly on PowerPC, ARM or S390X platforms, only on X86 and AMD64 targets. That's because the stack and global checking requires tracking function calls and exits reliably, and there's no obvious way to do it on ABIs that use a link register for function returns.

这篇关于运行时数组边界与G ++检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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