How to detect possible / potential stack overflow problems in a c / c++ program?

前端 未结 9 1837
滥情空心
滥情空心 2020-12-04 21:55

Is there a standard way to see how much stack space your app has and what the highest watermark for stack usage is during a run?

Also in the dreaded case of actual o

相关标签:
9条回答
  • 2020-12-04 22:31

    On Linux, the Gnu libsigsegv library includes the function stackoverflow_install_handler, which can detect (and in some cases help you recover from) stack overflow.

    0 讨论(0)
  • 2020-12-04 22:31

    Some compilers support stackavail() function, which returns the amount of remaining free space of the stack. You can use this function before calling functions in your programs that require a lot of stack space, to determine if it is safe to call them

    0 讨论(0)
  • 2020-12-04 22:38

    I would suggest you to use alternate-signal-stack if you are on linux.

    1. In this case all the signal will be handled over alternate stack.
    2. In case stack overflow occurs, system generates a SEGV signal, this can be handled over alternate stack.
    3. If you do not use it ... then you may not be able to handle the signal, and your program may crash without any handling/erro-reporting.
    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题