简体   繁体   English

当我删除cout语句时,为什么我的C ++程序会因退出代码11而崩溃?

[英]Why does my C++ program crash with exit code 11 when I remove a cout statement?

In my C++ project, I encounter a very strange issue. 在我的C ++项目中,我遇到了一个非常奇怪的问题。 It crashes with exit code 11 when I remove a certain log statement ( cout ). 当我删除某个日志语句( cout )时,它会与退出代码11崩溃。

This answer points to a source that explains exit code 11 (actually EAGAIN ) with the following statement: 这个答案指向一个使用以下语句解释退出代码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. 系统缺少创建另一个线程所需的资源,或者系统对进程PTHREAD_THREADS_MAX中线程总数的限制将被超出。

But I am pretty sure don't create any additional threads in my code (at least not explicitly). 但我很确定不要在我的代码中创建任何其他线程(至少没有明确)。 So why does the error occur and why does it go away when I use the log statement? 那么为什么会出现错误以及为什么当我使用log语句时它会消失呢?

For reference, I will post the code but it's of course completely out of context and basically the only relevant line is the one with the log statement. 作为参考,我将发布代码,但它当然完全脱离上下文,基本上唯一相关的行是带有log语句的行。

 PayloadRegionMapper(string mappingTechniqueName, string configPath = "")
    : payload(PAYLOAD), config(Config(configPath)) {

    cout << "construct PayloadRegionMapper" << endl; // if commented out, my program crashes....

    frames = generateFrames();
    setMappingTechnique(mappingTechniqueName);
}

Run the program using a debugger and then backtrace once the crash happens. 使用调试器运行程序,然后在崩溃发生后回溯。 Using the bt and frame command you can get an idea about the behaviour of the program during the crashing situation. 使用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. 

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

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