如何知道C程序的堆栈溢出? [英] how to know a c program's stack overflows?

查看:270
本文介绍了如何知道C程序的堆栈溢出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i am simulating a problem(3d Ising Model) in c but when the problem size gets larger the program stop and the below error appears :

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

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

in the program I have a recursive function that does all the works, i suspect that the error is because of stack overflow(in the recursive function) but i do not know how to be sure.

如果是由于堆栈溢出引起的,有什么方法可以解决此问题而无需更改程序设计?

and if it is because of stack overflow, is there any way to solve this problem without changing program design?

我正在使用Clion IDE。

i am using 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调试器并查看调用堆栈。

Use the GDB Debugger and look at the Call Stack.

gdb main
r
bt

这篇关于如何知道C程序的堆栈溢出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆