Stack traces when stack overflow

bearophile bearophileHUGS at lycos.com
Wed Jun 1 16:00:27 PDT 2011


This crashes at runtime because of a stack overflow, without stack frame or error message (DMD 2.053), no stack trace, or line number are shown:


int foo(int n) {
    return n ? foo(n - 1) : 1;
}
void main() {
    foo(100_000);
}


If you aren't running a debugger then receiving a nude crash is not so nice, because in a larger program there are many functions that may be the cause of such stack overflow. So is it possible to add some stack protection code (in non-release mode only, if necessary) to receive a stack trace in this case?

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list