How to debug System.StackOverflowException without reference to source code?

Recently, I regularly encounter errors like

"An unhandled exception of type 'System.StackOverflowException' occurred in the Unknown module."

This happens in a game (which I developed) with a fairly large code base (C # / XNA). But usually an error occurs only after a few minutes of gameplay (and not in every run).

The problem is that, unfortunately, the Visual Studio debugger does not seem to be able to localize the problem and just allows me to check the assembler code without reference to my source lines. How can I debug such an error? I think tools like Valgrind are not available in C #. Maybe the best debugger can show me where the problem is localized in the source code?

The call stack is available by applying the steps in the proposed answer below. It:

ntdll.dll!_NtWaitForSingleObject@12 () + 0x15 bytes ntdll.dll!_NtWaitForSingleObject@12 () + 0x15 bytes KernelBase.dll!_WaitForSingleObjectEx@12 () + 0xcb bytes kernel32.dll!_WaitForSingleObjectExImplementation@12 () + 0x43 bytes clr.dll!CLREvent::CreateManualEvent() - 0x15f3bb bytes clr.dll!CLREvent::CreateManualEvent() - 0x15f37a bytes clr.dll!CLREvent::WaitEx() + 0x47 bytes clr.dll!CLREvent::Wait() + 0x19 bytes clr.dll!Thread::WaitSuspendEventsHelper() + 0xa8 bytes clr.dll!Thread::WaitSuspendEvents() + 0x17 bytes clr.dll!Thread::RareEnablePreemptiveGC() + 0x181977 bytes clr.dll!Thread::RareDisablePreemptiveGC() + 0x38e3 bytes clr.dll!Debugger::SendException() + 0x12b bytes clr.dll!Debugger::LastChanceManagedException() + 0x19f bytes clr.dll!NotifyDebuggerLastChance() + 0x79 bytes clr.dll!WatsonLastChance() + 0x166 bytes clr.dll!EEPolicy::HandleFatalStackOverflow() + 0x189 bytes clr.dll!EEPolicy::HandleStackOverflow() + 0xd8 bytes clr.dll!_COMPlusFrameHandler() + 0xff302 bytes ntdll.dll!ExecuteHandler2@20 () + 0x26 bytes ntdll.dll!ExecuteHandler@20 () + 0x24 bytes ntdll.dll!_RtlDispatchException@8 () + 0xd3 bytes ntdll.dll!_KiUserExceptionDispatcher@8 () + 0xf bytes clr.dll!SystemNative::ArrayCopy() + 0x19 bytes mscorlib.ni.dll!6ed326a2() Frames below may be incorrect and/or missing, no symbols loaded for mscorlib.ni.dll 
+7
source share
2 answers

If ntdll.dll crashed, you need characters for it, but I think it is most likely that you are passing some strange garbage causing it to crash. Are you calling Windows API calls that may be crashing?

Another possibility that another user was talking about is that you can make a recursive call somewhere where the stack ends. This would be especially problematic if unmanaged code fragments were called:

  • Are there any logical conditions that can cause an infinite loop?
  • Are there any constructors that make unintended recursive calls?
  • Are there any recursive methods in your code?

In addition, there are a few things you can try before you go down the path of finding an alternative way to debug:

  • Make sure the project is built in debugging
  • Check your Visual Studio settings to make sure it is stopped in all exceptions
  • Disable the option "only my code" if it is available in the settings of your project (does this even appear in C # projects?)
  • Enabling Mixed Mode Debugging / Unmanaged Debugging
  • Make sure the characters are created and saved in the right place (* .pdb)
  • Otherwise, you can navigate the system event viewer and look for any strange errors.
+4
source

StackOverflowException usually StackOverflowException by some method that invokes itself endlessly.

The fact that this happens after a while makes me even more adamant: you are faced with infinite recursion.

An extremely simple example of this behavior would be the following:

 void SomeMethod() { SomeMethod(); // StackOverflowException } 
+2
source

All Articles