简体   繁体   English

如何知道ac程序的堆栈溢出?

[英]how to know a c program's stack overflows?

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 : 我在c中模拟了一个问题(3d Ising模型)但是当问题大小变大时程序停止并出现以下错误:

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? 如果是因为堆栈溢出,有没有办法解决这个问题而不改变程序设计?

i am using Clion IDE. 我正在使用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);
        }
    }
}

Use the GDB Debugger and look at the Call Stack. 使用GDB调试器并查看调用堆栈。

gdb main
r
bt

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

相关问题 如何在C程序中找到(全部)整数溢出? - How to find (all) integer overflows in a C program? 程序由于意志力而使调用堆栈溢出 - Program overflows call stack by sheer force of will 经过一定程度的有意溢出和最高自动清除后,C语言中的多堆栈程序显示了错误的元素 - Multiple stack program in C Language shows incorrect element after a certain amount of intentional overflows and toppermost autoremovals 如何在C程序中修复钩子(堆栈的还原) - How to fix a Hook in a C program (stack's restoration) Garwick的用于处理堆栈溢出的算法? - Garwick's algorithm for dealing with stack overflows? 对于 C 程序过程,我如何知道 memory 中数据、堆栈和堆的起始地址及其大小? - How can I know the starting address of data,stack and heap, and their sizes in memory for a C program process? 桌面操作系统上的C编译器使用多少个内存页来检测堆栈溢出? - How many memory pages do C compilers on desktop OSes use to detect stack overflows? 调用堆栈溢出时如何打印调用堆栈? - How to print call stack when call stack overflows? 如何使C程序的堆栈可执行? - How to make the stack of a C program executable? 如何读取C程序的堆栈段? - How to read the stack segment of a C program?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM