Valgrind几乎对所有内容都给出了错误(警告:客户端切换堆栈?)
Valgrind gives an error for nearly everything (Warning: client switching stacks?)
我正在以某种方式破坏内存,因为我的程序在随机位置崩溃而没有出错。
我将valgrind与--leak-check=full
一起使用,与-O0 -g
一起编译,它检测到的第一个问题是int main()
中的第一行
cout << "reading file" << endl;
带有
==5089== Warning: client switching stacks? SP change: 0x7ff0004f8 --> 0x7feb7de10
==5089== to suppress, use: --max-stackframe=4728552 or greater
==5089== Invalid write of size 8
==5089== at 0x41E107: main (Dgn.cpp:2833)
==5089== Address 0x7feb7de08 is on thread 1's stack
继续
==5089== Invalid read of size 8
==5089== at 0x5DE6E10: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.18)
==5089== by 0x67AEDE4: (below main) (libc-start.c:260)
==5089== Address 0x7feb7de08 is on thread 1's stack
==5089==
==5089== Invalid write of size 8
==5089== at 0x5DBF8F2: std::ios_base::ios_base() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.18)
==5089== by 0x5E06BFF: std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(char const*, std::_Ios_Openmode) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.18)
==5089== by 0x41E131: main (Dgn.cpp:2834)
==5089== Address 0x7feb7e1e8 is on thread 1's stack
指向
ifstream config_file("file");
几乎每一行都有错误。
是什么原因造成的?
我想我的第一个堆栈失败了!
从这里
随后是许多错误消息,如"无效读/写",其中包含一条注释:"地址在线程1的堆栈上",原因很简单。你只是在堆栈上分配了太大的变量——在我的例子中,我在一个函数中有太大的数组,作为局部变量。
缩小尺寸解决了这个问题。
为了指出显而易见的问题,您还可以按照valgrind的建议,即使用--max-stackframe=4728552
更改最大堆栈帧。您直接解决了问题,但这也会抑制那些"无效读取"错误。
在Linux上,我对一个程序进行了评估,非常确信它没有超出堆栈。为了抑制这里显示的client switching stacks?
错误,我使用了:
ulimit -s unlimited
现在valgrind按要求运行!
相关文章:
- 警告处理为错误这里有什么问题
- 隐式重新解释引用时强制转换,没有警告/错误
- 我在 C++ 代码中遇到错误警告:控制到达非空函数 [-Wreturn 类型] 的末尾
- 使用 reverse_iterator 而不是const_reverse_iterator并获得讨厌的编译器警告和错误
- GCC 警告和 gcc 错误消息之间的区别
- 在 eclipse 中,将宏重定义视为错误而不是警告
- 在 GCC 中启用"differing levels of indirection"警告/错误
- 当警告为错误时使用 [[已弃用]] 属性 (-Werror)
- G++ 编译器未为未定义的方法生成错误/警告
- 常量更改而不const_cast<> 为什么没有编译器警告/错误?
- 在制作过程结束时显示警告/错误的数量
- 钻石继承方案在 G++ 中编译良好,但在 VC++/Eclipse 中产生警告/错误
- 是否有任何方法可以避免警告/错误模板实例化回溯
- 如何捕获python警告错误并'bury'它?
- OSX:ld:警告:错误符号操作:适用于核心库
- Visual Studio的C4345警告错误吗?
- Visual Studio 上的 CRT SECURE 警告/错误是怎么回事?
- 禁用单个警告错误
- 如何在MSVC中为传递给变分函数的非POD参数启用警告/错误
- 警告错误问题