Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As mentioned in answers to your previous post, there are essentially three ways to get a Stack Overflow error.</p> <ol> <li><p>Infinite recursion. This is quite easy to nail down - just check all your recursive functions, if they work correctly and will always terminate in some circumstances.</p></li> <li><p>Allocating huge variables on stack. That's actually connected to the first problem - the recursion stack overflow occurs, because there is no space on the stack for local variables of another recursive call. It's also easy to nail down - you would have to use many (or few, but big) statically alocated arrays (of size known at compile time) or structures to cause the problem.</p></li> <li><p>Bufer overrun. That's the worst nightmare to track down, because the actual problem can occur long after its cause.</p></li> </ol> <p>I would suggest trying to nail down the problem in the following ways.</p> <ul> <li>Comment out as much code as you can, while the problem still occurs. If you're lucky, you will comment out the place, which actually causes the problem. Otherwise you will have a lot less code to analyse.</li> <li>Use WinDbg (available in the platform SDK) to get the detailed call stack at the moment of crash. You may add the following entry to the system registry to force the operating system to collect partial or full process memory dump to a file, such that you may try to perform post-mortem analysis:</li> </ul> <p><code><pre> Windows Registry Editor Version 5.00</p> <p>[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\YourAppName.exe] "DumpFolder"=hex(2):63,00,3a,00,5c,00,44,00,75,00,6d,00,70,00,73,00,00,00 "DumpType"=dword:00000002 "DumpCount"=dword:0000000F </pre></code></p> <p>This change makes full dump to a c:\dumps folder each time application crashes.</p> <p><code><pre> Windows Registry Editor Version 5.00</p> <p>[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\YourAppName.exe] "DumpFolder"=hex(2):63,00,3a,00,5c,00,44,00,75,00,6d,00,70,00,73,00,00,00 "DumpType"=dword:00000001 "DumpCount"=dword:000000FF </pre></code></p> <p>This change makes small dump (~40 Mb) to a c:\dumps folder each time application crashes.</p> <ul> <li><p>Use the Application Verifier tool to track down potential buffer overruns, which may damage the return address stored on the stack. </p></li> <li><p>Add guards to some vital fields of your structures and classes, ie:</p></li> </ul> <p><code><pre> const char * sentry1 = "0123456789"; void * vitalField; const char * sentry2 = "0123456789"; </pre></code></p> <p>Use them especially on the beginnings and ends of your classes, structures and methods. Use the debug mode to ensure, that optimizer won't optimize them out (as unused).</p> <p>After the crash, collect the memory dump and try to check, if all of your guards stand unchanged (that may be difficult, but not impossible).</p> <ul> <li>Finally, you may do a very detailed code review to make sure, that no buffer overruns occur.</li> </ul> <p><hr> <b>Edit:</b></p> <p>You can make WinDbg dump testing a little more automatic in the following way:</p> <ul> <li>Set the following environment variable:</li> </ul> <p><code><pre>_NT_SYMBOL_PATH=symsrv*symsrv.dll*c:\symbols*http://msdl.microsoft.com/download/symbols</pre></code></p> <p>It will be used by WinDbg, Visual Studio and Process Explorer</p> <ul> <li>Create the following file in the WinDbg directory:</li> </ul> <p>commands.txt <code><pre>.sympath+. .reload kb</pre></code></p> <ul> <li>Add the following entry to your registry (check, whether your system is 32- or 64-bit and make changes, if necessary):</li> </ul> <p><code><pre>Windows Registry Editor Version 5.00</p> <p>[HKEY_CLASSES_ROOT.dmp] @="Debugger.Dump"</p> <p>[HKEY_CLASSES_ROOT\Debugger.Dump]</p> <p>[HKEY_CLASSES_ROOT\Debugger.Dump\Shell]</p> <p>[HKEY_CLASSES_ROOT\Debugger.Dump\Shell\Debug_Without_Remote] @="WinDbg This Dump"</p> <p>[HKEY_CLASSES_ROOT\Debugger.Dump\Shell\Debug_Without_Remote\Command] @=&quot;\&quot;C:\Program Files\Debugging Tools for Windows (x64)\windbg\&quot; -z \&quot;%1\&quot; -QY -c \&quot;$&lt;C:\Program Files\Debugging Tools for Windows (x64)\commands.txt\&quot;&quot;</code></pre></p> <p>Good luck :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload