简体   繁体   English

如何在命令行应用程序中检测堆栈溢出。 在Mac OS上用C ++编写?

[英]How can I detect stack overflow in a command line app. written in C++ on macos?

I have an xcode project, code is in C++. 我有一个xcode项目,代码在C ++中。 I have pinpointed in a recursive function the cause of a not normal program behave, too many stuff o the stack... I wont to be sure that the problem is a stack overflow restoring bad stuff and set a trap to stack overflow. 我已经在递归函数中查明了导致程序不正常的原因,堆栈中有太多东西……我不会确定问题是堆栈溢出,恢复坏东西并设置陷阱来防止堆栈溢出。 How can I do this? 我怎样才能做到这一点?

For now I have found "-fstack-protector-all" for clang but I can't know what is happened once prog. 到目前为止,我已经为clang找到了“ -fstack-protector-all”,但是一旦编程就不知道会发生什么。 has run. 已经跑了。 Also I have found "-fsanitize=" but I don't know what write after the '='. 我也找到了“ -fsanitize =”,但是我不知道'='之后写什么。

Thanks. 谢谢。

There is no sure method to find a stack overflow. 没有确定堆栈溢出的确定方法。 The best method you can try to put some "MAGIC" value at the top of the stack and at every new method call check that this "MAGIC" value is still there, in the previous, and has not been overrun. 您可以尝试将最佳“ MAGIC”值放在堆栈的顶部,并且在每个新方法调用中,最好的方法是检查该“ MAGIC”值在以前是否仍然存在,并且没有被溢出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM