{"id":19573,"date":"2009-01-07T10:00:00","date_gmt":"2009-01-07T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/01\/07\/when-debugging-a-stack-overflow-you-want-to-focus-on-the-repeating-recursive-part\/"},"modified":"2009-01-07T10:00:00","modified_gmt":"2009-01-07T10:00:00","slug":"when-debugging-a-stack-overflow-you-want-to-focus-on-the-repeating-recursive-part","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090107-00\/?p=19573","title":{"rendered":"When debugging a stack overflow, you want to focus on the repeating recursive part"},"content":{"rendered":"<p><P>\nWhen your program breaks into the debugger with a stack overflow,\nyou will get a ridiculously huge stack trace because your program\nhas gone into some sort of recursive death.\n(This is not a statement of metaphysical certitude,\nbut it is true with very high probability.)\nBut the place where the program crashed is usually not interesting at all.\nHere&#8217;s a sample stack trace.\n(Warning: Ridiculously long stack traces ahead because\nstack traces from stack overflows are always ridiculously long.\nApologies to my blind readership.)\n<\/P>\n<PRE>\nntdll!RtlpAllocateHeap+0x394f2\nntdll!RtlAllocateHeap+0x151\nntdll!RtlFormatCurrentUserKeyPath+0xfa\nADVAPI32!BaseRegTranslateToUserClassKey+0xaf\nADVAPI32!BaseRegOpenClassKeyFromLocation+0xc0\nADVAPI32!BaseRegGetUserAndMachineClass+0x102\nADVAPI32!LocalBaseRegQueryValue+0xeb\nADVAPI32!RegQueryValueExW+0xef\nSHLWAPI!_SHRegQueryValueW+0xfc\nSHLWAPI!SHRegGetValueW+0xca\nPROGRAM!GetPathFromRegistry+0x3d\nPROGRAM!CPluginFinder::GetProviderDLL+0x79\nPROGRAM!CPluginFinder::InitializeProvider+0x22\nPROGRAM!CPluginFinder::Initialize+0xad\nPROGRAM!LookupPluginInfo+0x49\nPROGRAM!CPluginInfo::Create+0x1d4\nPROGRAM!TList&lt;CPluginInfo&gt;::GetInfo+0x6d\nPROGRAM!CPluginInfo::GetInfoTable+0x5d\nPROGRAM!TList&lt;CPluginInfo&gt;::Enumerate+0x83\nPROGRAM!CPluginRepository::GetGUID+0xc0\nPROGRAM!CPrivateNodeInfo::GetPluginInfo+0xdf\nPROGRAM!CPrivateNodeInfo::LoadPlugin+0x7a\nPROGRAM!CPrivateNode::GetChild+0x2e3\nPROGRAM!CPrivateNode::FindChild+0x2be\nPROGRAM!CPrivateNode::FindItem+0x190\nPROGRAM!CPrivateNode::FindChild+0x289\nPROGRAM!CPrivateNode::FindItem+0x190\nPROGRAM!CLocalNode::FindItem+0xca\nPROGRAM!CCompoundTreeNode::FindItem+0x70\nPROGRAM!CCompoundTreeNode::FindChild+0xaf\nPROGRAM!CCompoundTreeNode::FindItem+0x55\nPROGRAM!FindTreeItem+0x78\nPROGRAM!CToolbarCommand::Initialize+0x6c\nPROGRAM!CompoundMenu_InitMenu+0x1d2\nPROGRAM!CItemMenu::InitMenu+0x4e0\nPROGRAM!InvokeViaContextMenu+0xce\nPROGRAM!CCustomizableToolbar::TrySimpleCommand+0x23e\nPROGRAM!CCustomizableToolbar::OnCommand+0x102\nPROGRAM!CToolbar::OnAction+0x97\nPROGRAM!CToolbarSite::SendToToolbar+0x66\nPROGRAM!CToolbarSite::OnAction+0x1ff\nPROGRAM!CToolbarSite::HandleMessage+0xaa\nPROGRAM!CSite::HandleMessage+0x61\nPROGRAM!CMainWindow::WindowProc+0xc92\nPROGRAM!CWindow::WindowProc+0x91\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CReBar::_WndProc+0x1b5\ncomctl32!CReBar::s_WndProc+0x4a\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CToolbar::TBOnLButtonUp+0x181\ncomctl32!CToolbar::ToolbarWndProc+0xed1\ncomctl32!CToolbar::s_ToolbarWndProc+0xd6\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!CallWindowProcAorW+0xdb\nUSER32!CallWindowProcW+0x18\ncomctl32!CallOriginalWndProc+0x1d\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!DefSubclassProc+0x7c\nPROGRAM!DefSubclassProc+0x56\nPROGRAM!CToolbar::WindowProc+0x142\nPROGRAM!CCustomizableToolbar::WindowProc+0xb3\nPROGRAM!CWindowSubclass::SubclassWndProc+0xeb\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!MasterSubclassProc+0xe1\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!DispatchMessageWorker+0x389\nPROGRAM!MsgWaitForCompletion+0xe0\nPROGRAM!AsyncFinishCall+0x22\nPROGRAM!SynchronousCallService+0x48a\nPROGRAM!GetItemDescriptionFromServer+0x49c\nPROGRAM!CTreeItem::GetDescriptionFromServer+0x15f\nPROGRAM!CTreeItem::TryGetDescriptionFromServer+0x127\nPROGRAM!CTreeItem::GetDescriptionWorker+0x198\nPROGRAM!CTreeItem::GetDescription+0x188\nPROGRAM!CTreeItemWrapper::GetDescriptionWorker+0x90\nPROGRAM!CTreeItemWrapper::GetDescription+0x20b\nPROGRAM!CItemPropertiesMenu::RefreshProperties+0xf2\nPROGRAM!CItemPropertiesMenu::Execute+0xe7\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!CCompoundMenu::ExecuteDirect+0x308\nPROGRAM!CCompoundMenu::Execute+0xf4\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!InvokeViaContextMenu+0x11c\nPROGRAM!CCustomizableToolbar::TrySimpleCommand+0x23e\nPROGRAM!CCustomizableToolbar::OnCommand+0x102\nPROGRAM!CToolbar::OnAction+0x97\nPROGRAM!CToolbarSite::SendToToolbar+0x66\nPROGRAM!CToolbarSite::OnAction+0x1ff\nPROGRAM!CToolbarSite::HandleMessage+0xaa\nPROGRAM!CSite::HandleMessage+0x61\nPROGRAM!CMainWindow::WindowProc+0xc92\nPROGRAM!CWindow::WindowProc+0x91\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CReBar::_WndProc+0x1b5\ncomctl32!CReBar::s_WndProc+0x4a\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CToolbar::TBOnLButtonUp+0x181\ncomctl32!CToolbar::ToolbarWndProc+0xed1\ncomctl32!CToolbar::s_ToolbarWndProc+0xd6\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!CallWindowProcAorW+0xdb\nUSER32!CallWindowProcW+0x18\ncomctl32!CallOriginalWndProc+0x1d\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!DefSubclassProc+0x7c\nPROGRAM!DefSubclassProc+0x56\nPROGRAM!CToolbar::WindowProc+0x142\nPROGRAM!CCustomizableToolbar::WindowProc+0xb3\nPROGRAM!CWindowSubclass::SubclassWndProc+0xeb\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!MasterSubclassProc+0xe1\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!DispatchMessageWorker+0x389\nPROGRAM!MsgWaitForCompletion+0xe0\nPROGRAM!AsyncFinishCall+0x22\nPROGRAM!SynchronousCallService+0x48a\nPROGRAM!GetItemDescriptionFromServer+0x49c\nPROGRAM!CTreeItem::GetDescriptionFromServer+0x15f\nPROGRAM!CTreeItem::TryGetDescriptionFromServer+0x127\nPROGRAM!CTreeItem::GetDescriptionWorker+0x198\nPROGRAM!CTreeItem::GetDescription+0x188\nPROGRAM!CTreeItemWrapper::GetDescriptionWorker+0x90\nPROGRAM!CTreeItemWrapper::GetDescription+0x20b\nPROGRAM!CItemPropertiesMenu::RefreshProperties+0xf2\nPROGRAM!CItemPropertiesMenu::Execute+0xe7\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!CCompoundMenu::ExecuteDirect+0x308\nPROGRAM!CCompoundMenu::Execute+0xf4\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!InvokeViaContextMenu+0x11c\nPROGRAM!CCustomizableToolbar::TrySimpleCommand+0x23e\nPROGRAM!CCustomizableToolbar::OnCommand+0x102\nPROGRAM!CToolbar::OnAction+0x97\nPROGRAM!CToolbarSite::SendToToolbar+0x66\nPROGRAM!CToolbarSite::OnAction+0x1ff\nPROGRAM!CToolbarSite::HandleMessage+0xaa\nPROGRAM!CSite::HandleMessage+0x61\nPROGRAM!CMainWindow::WindowProc+0xc92\nPROGRAM!CWindow::WindowProc+0x91\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CReBar::_WndProc+0x1b5\ncomctl32!CReBar::s_WndProc+0x4a\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CToolbar::TBOnLButtonUp+0x181\ncomctl32!CToolbar::ToolbarWndProc+0xed1\ncomctl32!CToolbar::s_ToolbarWndProc+0xd6\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!CallWindowProcAorW+0xdb\nUSER32!CallWindowProcW+0x18\ncomctl32!CallOriginalWndProc+0x1d\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!DefSubclassProc+0x7c\nPROGRAM!DefSubclassProc+0x56\nPROGRAM!CToolbar::WindowProc+0x142\nPROGRAM!CCustomizableToolbar::WindowProc+0xb3\nPROGRAM!CWindowSubclass::SubclassWndProc+0xeb\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!MasterSubclassProc+0xe1\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!DispatchMessageWorker+0x389\nPROGRAM!MsgWaitForCompletion+0xe0\nPROGRAM!AsyncFinishCall+0x22\nPROGRAM!SynchronousCallService+0x48a\nPROGRAM!GetItemDescriptionFromServer+0x49c\nPROGRAM!CTreeItem::GetDescriptionFromServer+0x15f\nPROGRAM!CTreeItem::TryGetDescriptionFromServer+0x127\nPROGRAM!CTreeItem::GetDescriptionWorker+0x198\nPROGRAM!CTreeItem::GetDescription+0x188\nPROGRAM!CTreeItemWrapper::GetDescriptionWorker+0x90\nPROGRAM!CTreeItemWrapper::GetDescription+0x20b\nPROGRAM!CItemPropertiesMenu::RefreshProperties+0xf2\nPROGRAM!CItemPropertiesMenu::Execute+0xe7\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!CCompoundMenu::ExecuteDirect+0x308\nPROGRAM!CCompoundMenu::Execute+0xf4\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!InvokeViaContextMenu+0x11c\nPROGRAM!CCustomizableToolbar::TrySimpleCommand+0x23e\nPROGRAM!CCustomizableToolbar::OnCommand+0x102\nPROGRAM!CToolbar::OnAction+0x97\nPROGRAM!CToolbarSite::SendToToolbar+0x66\nPROGRAM!CToolbarSite::OnAction+0x1ff\nPROGRAM!CToolbarSite::HandleMessage+0xaa\nPROGRAM!CSite::HandleMessage+0x61\nPROGRAM!CMainWindow::WindowProc+0xc92\nPROGRAM!CWindow::WindowProc+0x91\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CReBar::_WndProc+0x1b5\ncomctl32!CReBar::s_WndProc+0x4a\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CToolbar::TBOnLButtonUp+0x181\ncomctl32!CToolbar::ToolbarWndProc+0xed1\ncomctl32!CToolbar::s_ToolbarWndProc+0xd6\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!CallWindowProcAorW+0xdb\nUSER32!CallWindowProcW+0x18\ncomctl32!CallOriginalWndProc+0x1d\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!DefSubclassProc+0x7c\nPROGRAM!DefSubclassProc+0x56\nPROGRAM!CToolbar::WindowProc+0x142\nPROGRAM!CCustomizableToolbar::WindowProc+0xb3\nPROGRAM!CWindowSubclass::SubclassWndProc+0xeb\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!MasterSubclassProc+0xe1\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!DispatchMessageWorker+0x389\nPROGRAM!MsgWaitForCompletion+0xe0\nPROGRAM!AsyncFinishCall+0x22\nPROGRAM!SynchronousCallService+0x48a\nPROGRAM!GetItemDescriptionFromServer+0x49c\nPROGRAM!CTreeItem::GetDescriptionFromServer+0x15f\nPROGRAM!CTreeItem::TryGetDescriptionFromServer+0x127\nPROGRAM!CTreeItem::GetDescriptionWorker+0x198\nPROGRAM!CTreeItem::GetDescription+0x188\nPROGRAM!CTreeItemWrapper::GetDescriptionWorker+0x90\nPROGRAM!CTreeItemWrapper::GetDescription+0x20b\nPROGRAM!CItemPropertiesMenu::RefreshProperties+0xf2\nPROGRAM!CItemPropertiesMenu::Execute+0xe7\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!CCompoundMenu::ExecuteDirect+0x308\nPROGRAM!CCompoundMenu::Execute+0xf4\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!InvokeViaContextMenu+0x11c\nPROGRAM!CCustomizableToolbar::TrySimpleCommand+0x23e\nPROGRAM!CCustomizableToolbar::OnCommand+0x102\nPROGRAM!CToolbar::OnAction+0x97\n<\/PRE>\n<P>\nIf you go hunting through your defect tracking database trying to\nsee whether this is a known issue or not,\na search for the top functions on the stack is unlikely to find\nanything interesting.\nThat&#8217;s because stack overflows tend to happen at a random point\nin the recursion;\neach stack overflow looks superficially different from every other one\neven if they are the same stack overflow.\n<\/P>\n<P>\nSuppose you&#8217;re singing the song\n<A HREF=\"http:\/\/en.wikipedia.org\/wiki\/Fr%C3%A8re_Jacques\">\n<I>Fr&egrave;re Jacques<\/I><\/A>,\nexcept that you sing each verse a few tones higher than the previous one.\nEventually, you will reach the top of your singing range,\nand precisely where that happens depends on where your vocal limit\nlines up against the melody.\nIn the melody, the first three notes are each a new &#8220;record high&#8221;\n(<I>i.e.<\/I>, the notes are higher than any other note sung so far),\nand new record highs appear in the three notes of the third measure,\nand a final record high in the second note of the fifth measure.\n<\/P>\n<P>\nIf the melody represented a program&#8217;s stack usage,\na stack overflow could possibly occur at any of those five locations\nin the program&#8217;s execution.\nIn other words, the same underlying runaway recursion\n(musically represented by an ever-higher rendition of the melody)\ncan manifest itself in five different ways.\nThe &#8220;recursion&#8221; in this analogy was rather quick, just eight bars\nbefore the loop repeated.\nIn real life, the loop can be quite long, leading to dozens of\npotential points where the stack overflow can manifest itself.\n<\/P>\n<P>\nIf you are faced with a stack overflow, then, you want to ignore\nthe top of the stack, since that&#8217;s just focusing on the specific note\nthat exceeded your vocal range.\nYou really want to find the entire melody, since that&#8217;s what&#8217;s\ncommon to all the stack overflows with the same root cause.\n<\/P>\n<P>\nTo do this, look for the part of the stack trace that repeats itself.\nThat&#8217;s the pattern that is causing the problem, the <I>stack overflow\nmelody<\/I>, you might say.\n(And if you do say it, everybody will look at you funny since it&#8217;s\njust a dumb analogy I made up on the spot.)\nLet&#8217;s take another look at that stack trace above.\n<\/P>\n<PRE>\n<DIV STYLE=\"padding-left: 1em\">ntdll!RtlpAllocateHeap+0x394f2\nntdll!RtlAllocateHeap+0x151\nntdll!RtlFormatCurrentUserKeyPath+0xfa\nADVAPI32!BaseRegTranslateToUserClassKey+0xaf\nADVAPI32!BaseRegOpenClassKeyFromLocation+0xc0\nADVAPI32!BaseRegGetUserAndMachineClass+0x102\nADVAPI32!LocalBaseRegQueryValue+0xeb\nADVAPI32!RegQueryValueExW+0xef\nSHLWAPI!_SHRegQueryValueW+0xfc\nSHLWAPI!SHRegGetValueW+0xca\nPROGRAM!GetPathFromRegistry+0x3d\nPROGRAM!CPluginFinder::GetProviderDLL+0x79\nPROGRAM!CPluginFinder::InitializeProvider+0x22\nPROGRAM!CPluginFinder::Initialize+0xad\nPROGRAM!LookupPluginInfo+0x49\nPROGRAM!CPluginInfo::Create+0x1d4\nPROGRAM!TList&lt;CPluginInfo&gt;::GetInfo+0x6d\nPROGRAM!CPluginInfo::GetInfoTable+0x5d\nPROGRAM!TList&lt;CPluginInfo&gt;::Enumerate+0x83\nPROGRAM!CPluginRepository::GetGUID+0xc0\nPROGRAM!CPrivateNodeInfo::GetPluginInfo+0xdf\nPROGRAM!CPrivateNodeInfo::LoadPlugin+0x7a\nPROGRAM!CPrivateNode::GetChild+0x2e3\nPROGRAM!CPrivateNode::FindChild+0x2be\nPROGRAM!CPrivateNode::FindItem+0x190\nPROGRAM!CPrivateNode::FindChild+0x289\nPROGRAM!CPrivateNode::FindItem+0x190\nPROGRAM!CLocalNode::FindItem+0xca\nPROGRAM!CCompoundTreeNode::FindItem+0x70\nPROGRAM!CCompoundTreeNode::FindChild+0xaf\nPROGRAM!CCompoundTreeNode::FindItem+0x55\nPROGRAM!FindTreeItem+0x78\nPROGRAM!CToolbarCommand::Initialize+0x6c\nPROGRAM!CompoundMenu_InitMenu+0x1d2\nPROGRAM!CItemMenu::InitMenu+0x4e0\nPROGRAM!InvokeViaContextMenu+0xce\nPROGRAM!CCustomizableToolbar::TrySimpleCommand+0x23e\nPROGRAM!CCustomizableToolbar::OnCommand+0x102<\/DIV>\n<DIV STYLE=\"background:#AACCFF;border: solid black .75pt;padding: 1em\">PROGRAM!CToolbar::OnAction+0x97\nPROGRAM!CToolbarSite::SendToToolbar+0x66\nPROGRAM!CToolbarSite::OnAction+0x1ff\nPROGRAM!CToolbarSite::HandleMessage+0xaa\nPROGRAM!CSite::HandleMessage+0x61\nPROGRAM!CMainWindow::WindowProc+0xc92\nPROGRAM!CWindow::WindowProc+0x91\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CReBar::_WndProc+0x1b5\ncomctl32!CReBar::s_WndProc+0x4a\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CToolbar::TBOnLButtonUp+0x181\ncomctl32!CToolbar::ToolbarWndProc+0xed1\ncomctl32!CToolbar::s_ToolbarWndProc+0xd6\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!CallWindowProcAorW+0xdb\nUSER32!CallWindowProcW+0x18\ncomctl32!CallOriginalWndProc+0x1d\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!DefSubclassProc+0x7c\nPROGRAM!DefSubclassProc+0x56\nPROGRAM!CToolbar::WindowProc+0x142\nPROGRAM!CCustomizableToolbar::WindowProc+0xb3\nPROGRAM!CWindowSubclass::SubclassWndProc+0xeb\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!MasterSubclassProc+0xe1\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!DispatchMessageWorker+0x389\nPROGRAM!MsgWaitForCompletion+0xe0\nPROGRAM!AsyncFinishCall+0x22\nPROGRAM!SynchronousCallService+0x48a\nPROGRAM!GetItemDescriptionFromServer+0x49c\nPROGRAM!CTreeItem::GetDescriptionFromServer+0x15f\nPROGRAM!CTreeItem::TryGetDescriptionFromServer+0x127\nPROGRAM!CTreeItem::GetDescriptionWorker+0x198\nPROGRAM!CTreeItem::GetDescription+0x188\nPROGRAM!CTreeItemWrapper::GetDescriptionWorker+0x90\nPROGRAM!CTreeItemWrapper::GetDescription+0x20b\nPROGRAM!CItemPropertiesMenu::RefreshProperties+0xf2\nPROGRAM!CItemPropertiesMenu::Execute+0xe7\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!CCompoundMenu::ExecuteDirect+0x308\nPROGRAM!CCompoundMenu::Execute+0xf4\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!InvokeViaContextMenu+0x11c\nPROGRAM!CCustomizableToolbar::TrySimpleCommand+0x23e\nPROGRAM!CCustomizableToolbar::OnCommand+0x102<\/DIV>\n<DIV STYLE=\"background:#CC99DD;border: solid black .75pt;padding: 1em\">PROGRAM!CToolbar::OnAction+0x97\nPROGRAM!CToolbarSite::SendToToolbar+0x66\nPROGRAM!CToolbarSite::OnAction+0x1ff\nPROGRAM!CToolbarSite::HandleMessage+0xaa\nPROGRAM!CSite::HandleMessage+0x61\nPROGRAM!CMainWindow::WindowProc+0xc92\nPROGRAM!CWindow::WindowProc+0x91\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CReBar::_WndProc+0x1b5\ncomctl32!CReBar::s_WndProc+0x4a\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CToolbar::TBOnLButtonUp+0x181\ncomctl32!CToolbar::ToolbarWndProc+0xed1\ncomctl32!CToolbar::s_ToolbarWndProc+0xd6\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!CallWindowProcAorW+0xdb\nUSER32!CallWindowProcW+0x18\ncomctl32!CallOriginalWndProc+0x1d\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!DefSubclassProc+0x7c\nPROGRAM!DefSubclassProc+0x56\nPROGRAM!CToolbar::WindowProc+0x142\nPROGRAM!CCustomizableToolbar::WindowProc+0xb3\nPROGRAM!CWindowSubclass::SubclassWndProc+0xeb\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!MasterSubclassProc+0xe1\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!DispatchMessageWorker+0x389\nPROGRAM!MsgWaitForCompletion+0xe0\nPROGRAM!AsyncFinishCall+0x22\nPROGRAM!SynchronousCallService+0x48a\nPROGRAM!GetItemDescriptionFromServer+0x49c\nPROGRAM!CTreeItem::GetDescriptionFromServer+0x15f\nPROGRAM!CTreeItem::TryGetDescriptionFromServer+0x127\nPROGRAM!CTreeItem::GetDescriptionWorker+0x198\nPROGRAM!CTreeItem::GetDescription+0x188\nPROGRAM!CTreeItemWrapper::GetDescriptionWorker+0x90\nPROGRAM!CTreeItemWrapper::GetDescription+0x20b\nPROGRAM!CItemPropertiesMenu::RefreshProperties+0xf2\nPROGRAM!CItemPropertiesMenu::Execute+0xe7\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!CCompoundMenu::ExecuteDirect+0x308\nPROGRAM!CCompoundMenu::Execute+0xf4\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!InvokeViaContextMenu+0x11c\nPROGRAM!CCustomizableToolbar::TrySimpleCommand+0x23e\nPROGRAM!CCustomizableToolbar::OnCommand+0x102<\/DIV>\n<DIV STYLE=\"background:#C0C0C0;border: solid black .75pt;padding: 1em\">PROGRAM!CToolbar::OnAction+0x97\nPROGRAM!CToolbarSite::SendToToolbar+0x66\nPROGRAM!CToolbarSite::OnAction+0x1ff\nPROGRAM!CToolbarSite::HandleMessage+0xaa\nPROGRAM!CSite::HandleMessage+0x61\nPROGRAM!CMainWindow::WindowProc+0xc92\nPROGRAM!CWindow::WindowProc+0x91\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CReBar::_WndProc+0x1b5\ncomctl32!CReBar::s_WndProc+0x4a\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CToolbar::TBOnLButtonUp+0x181\ncomctl32!CToolbar::ToolbarWndProc+0xed1\ncomctl32!CToolbar::s_ToolbarWndProc+0xd6\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!CallWindowProcAorW+0xdb\nUSER32!CallWindowProcW+0x18\ncomctl32!CallOriginalWndProc+0x1d\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!DefSubclassProc+0x7c\nPROGRAM!DefSubclassProc+0x56\nPROGRAM!CToolbar::WindowProc+0x142\nPROGRAM!CCustomizableToolbar::WindowProc+0xb3\nPROGRAM!CWindowSubclass::SubclassWndProc+0xeb\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!MasterSubclassProc+0xe1\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!DispatchMessageWorker+0x389\nPROGRAM!MsgWaitForCompletion+0xe0\nPROGRAM!AsyncFinishCall+0x22\nPROGRAM!SynchronousCallService+0x48a\nPROGRAM!GetItemDescriptionFromServer+0x49c\nPROGRAM!CTreeItem::GetDescriptionFromServer+0x15f\nPROGRAM!CTreeItem::TryGetDescriptionFromServer+0x127\nPROGRAM!CTreeItem::GetDescriptionWorker+0x198\nPROGRAM!CTreeItem::GetDescription+0x188\nPROGRAM!CTreeItemWrapper::GetDescriptionWorker+0x90\nPROGRAM!CTreeItemWrapper::GetDescription+0x20b\nPROGRAM!CItemPropertiesMenu::RefreshProperties+0xf2\nPROGRAM!CItemPropertiesMenu::Execute+0xe7\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!CCompoundMenu::ExecuteDirect+0x308\nPROGRAM!CCompoundMenu::Execute+0xf4\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!InvokeViaContextMenu+0x11c\nPROGRAM!CCustomizableToolbar::TrySimpleCommand+0x23e\nPROGRAM!CCustomizableToolbar::OnCommand+0x102<\/DIV>\n<DIV STYLE=\"background:#FF99AA;border: solid black .75pt;padding: 1em\">PROGRAM!CToolbar::OnAction+0x97\nPROGRAM!CToolbarSite::SendToToolbar+0x66\nPROGRAM!CToolbarSite::OnAction+0x1ff\nPROGRAM!CToolbarSite::HandleMessage+0xaa\nPROGRAM!CSite::HandleMessage+0x61\nPROGRAM!CMainWindow::WindowProc+0xc92\nPROGRAM!CWindow::WindowProc+0x91\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CReBar::_WndProc+0x1b5\ncomctl32!CReBar::s_WndProc+0x4a\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CToolbar::TBOnLButtonUp+0x181\ncomctl32!CToolbar::ToolbarWndProc+0xed1\ncomctl32!CToolbar::s_ToolbarWndProc+0xd6\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!CallWindowProcAorW+0xdb\nUSER32!CallWindowProcW+0x18\ncomctl32!CallOriginalWndProc+0x1d\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!DefSubclassProc+0x7c\nPROGRAM!DefSubclassProc+0x56\nPROGRAM!CToolbar::WindowProc+0x142\nPROGRAM!CCustomizableToolbar::WindowProc+0xb3\nPROGRAM!CWindowSubclass::SubclassWndProc+0xeb\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!MasterSubclassProc+0xe1\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!DispatchMessageWorker+0x389\nPROGRAM!MsgWaitForCompletion+0xe0\nPROGRAM!AsyncFinishCall+0x22\nPROGRAM!SynchronousCallService+0x48a\nPROGRAM!GetItemDescriptionFromServer+0x49c\nPROGRAM!CTreeItem::GetDescriptionFromServer+0x15f\nPROGRAM!CTreeItem::TryGetDescriptionFromServer+0x127\nPROGRAM!CTreeItem::GetDescriptionWorker+0x198\nPROGRAM!CTreeItem::GetDescription+0x188\nPROGRAM!CTreeItemWrapper::GetDescriptionWorker+0x90\nPROGRAM!CTreeItemWrapper::GetDescription+0x20b\nPROGRAM!CItemPropertiesMenu::RefreshProperties+0xf2\nPROGRAM!CItemPropertiesMenu::Execute+0xe7\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!CCompoundMenu::ExecuteDirect+0x308\nPROGRAM!CCompoundMenu::Execute+0xf4\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!InvokeViaContextMenu+0x11c\nPROGRAM!CCustomizableToolbar::TrySimpleCommand+0x23e\nPROGRAM!CCustomizableToolbar::OnCommand+0x102<\/DIV>\n<DIV STYLE=\"padding-left: 1em\">PROGRAM!CToolbar::OnAction+0x97<\/DIV>\n<\/PRE>\n<P>\nOnce you get past the initial turmoil,\nthe stack trace settles down into a nice repeating pattern\nconsisting of the same 53 functions over and over again.\nIdentifying the start of the repeating pattern isn&#8217;t important,\nbecause the starting point will be different for each crash,\nin the same way that the precise note which exceeds your singing\nrange varies from crash to crash.\nWhen I go looking for the repeating pattern, I ignore the first\nhundred or so functions in the stack trace.\nThat usually takes me well past the momentary weirdness at the top\nof the stack and dumps me straight into the repeating part.\n<\/P>\n<P>\nOnce you&#8217;ve identified the repeating part, pick a function from it\nthat is somewhat unusual and search for it in your defect database.\nIn our example, <CODE>SendMessageW<\/CODE> would probably be\na bad choice, since sending a message is a pretty common operation\nin most Windows programs.\nI would go with <CODE>CTreeItem::GetDescriptionFromServer<\/CODE>.\n<\/P>\n<P>\nIt so happens that a query for all defects that involve the function\n<CODE>CTreeItem::GetDescriptionFromServer<\/CODE>\nturned up the following stack trace:\n<\/P>\n<PRE>\n<DIV STYLE=\"padding-left: 1em\">ntdll!RtlpAllocateHeap+0x33\nntdll!RtlAllocateHeap+0x151\nntdll!RtlDebugAllocateHeap+0xcd\nntdll!RtlpAllocateHeap+0x39592\nntdll!RtlAllocateHeap+0x151\nPROGRAM!CopyString+0x24\nPROGRAM!CopyDirectoryName+0x11\nPROGRAM!GetItemLongPath+0xe\nPROGRAM!CPrivateNode::GetSourceLongPath+0x6d\nPROGRAM!CPrivateNode::GetSourcePath+0x57\nPROGRAM!CPrivateNode::GetSource+0x123\nPROGRAM!GetDownloadSource+0x23\nPROGRAM!GetCustomizedButtonSource+0xcc\nPROGRAM!CCustomizableToolbar::IsWarningNeeded+0x69\nPROGRAM!CCustomizableToolbar::TrySimpleCommand+0x1b6\nPROGRAM!CCustomizableToolbar::OnCommand+0x102<\/DIV>\n<DIV STYLE=\"background:#AACCFF;border: solid black .75pt;padding: 1em\">PROGRAM!CToolbar::OnAction+0x97\nPROGRAM!CToolbarSite::SendToToolbar+0x66\nPROGRAM!CToolbarSite::OnAction+0x1ff\nPROGRAM!CToolbarSite::HandleMessage+0xaa\nPROGRAM!CSite::HandleMessage+0x61\nPROGRAM!CMainWindow::WindowProc+0xc92\nPROGRAM!CWindow::WindowProc+0x91\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CReBar::_WndProc+0x1b5\ncomctl32!CReBar::s_WndProc+0x4a\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!SendMessageWorker+0x64a\nUSER32!SendMessageW+0x5b\ncomctl32!CToolbar::TBOnLButtonUp+0x181\ncomctl32!CToolbar::ToolbarWndProc+0xed1\ncomctl32!CToolbar::s_ToolbarWndProc+0xd6\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!CallWindowProcAorW+0xdb\nUSER32!CallWindowProcW+0x18\ncomctl32!CallOriginalWndProc+0x1d\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!DefSubclassProc+0x7c\nPROGRAM!DefSubclassProc+0x56\nPROGRAM!CToolbar::WindowProc+0x142\nPROGRAM!CCustomizableToolbar::WindowProc+0xb3\nPROGRAM!CWindowSubclass::SubclassWndProc+0xeb\ncomctl32!CallNextSubclassProc+0x8d\ncomctl32!MasterSubclassProc+0xe1\nUSER32!UserCallWinProcCheckWow+0x1ad\nUSER32!DispatchMessageWorker+0x389\nPROGRAM!MsgWaitForCompletion+0xe0\nPROGRAM!AsyncFinishCall+0x22\nPROGRAM!SynchronousCallService+0x48a\nPROGRAM!GetItemDescriptionFromServer+0x49c\nPROGRAM!CTreeItem::GetDescriptionFromServer+0x15f\nPROGRAM!CTreeItem::TryGetDescriptionFromServer+0x127\nPROGRAM!CTreeItem::GetDescriptionWorker+0x198\nPROGRAM!CTreeItem::GetDescription+0x188\nPROGRAM!CTreeItemWrapper::GetDescriptionWorker+0x90\nPROGRAM!CTreeItemWrapper::GetDescription+0x20b\nPROGRAM!CItemPropertiesMenu::RefreshProperties+0xf2\nPROGRAM!CItemPropertiesMenu::Execute+0xe7\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!CCompoundMenu::ExecuteDirect+0x308\nPROGRAM!CCompoundMenu::Execute+0xf4\nPROGRAM!CompoundMenu_DispatchCommand+0x108\nPROGRAM!CItemMenu::Execute+0x29c\nPROGRAM!InvokeViaContextMenu+0x11c\nPROGRAM!CCustomizableToolbar::TrySimpleCommand+0x23e\nPROGRAM!CCustomizableToolbar::OnCommand+0x102<\/DIV>\n<DIV STYLE=\"padding-left: 1em\">PROGRAM!CToolbar::OnAction+0x97<\/DIV>\n<\/PRE>\n<P>\nYup, there&#8217;s that recurring 53-function cycle again.\nThe initial part of the stack trace is different, of course,\nbut the important part is right there.\nThis is another manifestation of the same underlying bug.\n<\/P>\n<P>\nMoral of the story:\nWhen studying a stack overflow,\nthe stragglers at the top of the stack are the least important\nfunctions.\nYou really want the meaty bit in the middle.\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When your program breaks into the debugger with a stack overflow, you will get a ridiculously huge stack trace because your program has gone into some sort of recursive death. (This is not a statement of metaphysical certitude, but it is true with very high probability.) But the place where the program crashed is usually [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-19573","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>When your program breaks into the debugger with a stack overflow, you will get a ridiculously huge stack trace because your program has gone into some sort of recursive death. (This is not a statement of metaphysical certitude, but it is true with very high probability.) But the place where the program crashed is usually [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/19573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=19573"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/19573\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=19573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=19573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=19573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}