我不知道有什麼好的工具,但作爲最後手段可以包括在應用程序中的一些代碼來檢查它,類似於以下內容:
__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
}