我不知道有什么好的工具,但作为最后手段可以包括在应用程序中的一些代码来检查它,类似于以下内容:
__thread void* stack_start;
__thread long stack_max_size = 0L;
void check_stack_size() {
// address of 'nowhere' approximates end of stack
char nowhere;
void* stack_end = (void*)&nowhere;
// may want to double check stack grows downward on your platform
long stack_size = (long)stack_start - (long)stack_end;
// update max_stack_size for this thread
if (stack_size > stack_max_size)
stack_max_size = stack_size;
}
的check_stack_size()函数将有一些功能被称为是是最深嵌套的。
然后在线程您可以输出stack_max_size某处最后一条语句。
的stack_start变量将会在你的线程开始进行初始化:
void thread_proc() {
char nowhere;
stack_start = (void*)&nowhere;
// do stuff including calls to check_stack_size()
// in deeply nested functions
// output stack_max_size here
}