c - 如何知道一个c程序的堆栈溢出?

标签 c debugging stack-overflow

我正在用 c 语言模拟一个问题(3d Ising 模型),但是当问题变大时,程序停止并出现以下错误:

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

在程序中我有一个递归函数来完成所有工作,我怀疑错误是由于堆栈溢出(在递归函数中)但我不知道如何确定。

如果是因为栈溢出,有没有办法在不改变程序设计的情况下解决这个问题?

我正在使用 Clion IDE。

/*
 * recursive function to form Wolff Cluster(= WC)
 */
void grow_Wolff_cluster(lattic* l, Wolff* wolff, site *seed){

    /*a neighbor of site seed*/
    site* neighbor;

    /*go through all neighbors of seed*/
    for (int i = 0 ; i < neighbors ; ++i) {


        neighbor = seed->neighbors[i];

        /*add to WC according to the Wolff Algorithm*/
        if(neighbor->spin == seed->spin && neighbor->WC == -1 && ((double)rand() / RAND_MAX) < add_probability)
        {
            wolff->Wolff_cluster[wolff->WC_pos] = neighbor;
            wolff->WC_pos++;                  // the number of sites that is added to WC
            neighbor->WC = 1;          // for avoiding of multiple addition of site
            neighbor->X = 0;


            ///controller_site_added_to_WC();


            /*continue growing Wolff cluster(recursion)*/
            grow_Wolff_cluster(l, wolff, neighbor);
        }
    }
}

最佳答案

使用 GDB 调试器并查看调用堆栈。

gdb main
r
bt

关于c - 如何知道一个c程序的堆栈溢出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48173404/

相关文章:

c - 无限循环和带有 : while (chars = fgetc(map) ! = EOF 的奇怪字符)

c - 在 C 中使用#define 进行字符串连接

c - 如何在自定义列表数据结构中动态存储和删除通用数据类型的自动变量?

ios instruments vm tracker IOKit 疯狂的住所大小

c# - 最大继承级别

c - 为什么strtok_s在第一次使用后返回0x00000001?

debugging - Intellij IDEA 断点停止在 JAR 中,而不是我的项目的源代码中

qt - 下级停止了,因为它触发了异常。被异常停止在线程 0 中......?

java - 由类声明子类引起的 StackOverflowError?

二维数组的 C++ Visual Studio 堆栈溢出