在我的 C++ 项目中,我遇到了一个非常奇怪的问题。当我删除 某个日志语句 (cout
) 时,它会崩溃并显示退出代码 11。
This answer指向一个解释退出代码 11(实际上是 EAGAIN
)的源代码,其中包含以下语句:
The system lacked the necessary resources to create another thread, or the system-imposed limit on the total number of threads in a process PTHREAD_THREADS_MAX would be exceeded.
但我很确定不要在我的代码中创建任何额外的线程(至少不要明确地创建)。那么为什么会出现错误,为什么当我使用日志语句时错误消失了?
作为引用,我将发布代码,但它当然完全脱离了上下文,基本上唯一相关的行是带有日志语句的行。
PayloadRegionMapper(string mappingTechniqueName, string configPath = "")
: payload(PAYLOAD), config(Config(configPath)) {
cout << "construct PayloadRegionMapper" << endl; // if commented out, my program crashes....
frames = generateFrames();
setMappingTechnique(mappingTechniqueName);
}
最佳答案
使用调试器运行程序,然后在崩溃发生后回溯。 使用 bt 和 frame 命令,您可以了解程序在崩溃情况下的行为。
gdb <executable>
.....<crash happened>
bt
<It will give you the stack frame >
frame <frame number>
Then look for the values and memory area there.
关于c++ - 为什么我的 C++ 程序在删除 cout 语句时崩溃并返回代码 11?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29802614/