Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

xna

Recently, I am regularly encountering errors of type

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

This happens in a game (that I developed) with a quite large code base (C# / XNA). But typically the error occurs only after several minutes of gameplay (and not in every run).

The problem is that unfortunately, the Visual Studio debugger seems to not be able to further localize the problem and just lets me inspect the assembler code without reference to my source lines. How could one debug such an error? I guess tools like Valgrind are not available in C#. Is there maybe a better debugger that can show me where the problem is localized in the source code?

The call stack available when applying the steps in the suggested answer below. It is:

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 
like image 945
ares_games Avatar asked Jan 07 '13 13:01

ares_games


1 Answers

If the crash is happening with ntdll.dll, you'd need the symbols for it, but I think the more likely possibility is that you are passing some weird junk in that is causing it to crash. Are you making an Windows API calls that might be crashing it?

Another possibility, which was mentioned by another user here is that you could be making a recursive call somewhere that is running out the stack. This would be especially problematic if the calls are being made to unmanaged pieces of code:

  • Are there any logic conditions that might cause an infinite loop?
  • Are there any constructors that make unintentional recursive calls?
  • Are there any recursive methods in your code that might be stuck?

Also, a couple of things you may want to try before you go down the road for looking for an alternative way to debug:

  1. Ensure that the project is built in debug
  2. Check Visual Studio settings to be sure that it is halting on all exceptions
  3. Turn off the "just my code" setting if it is available in your project settings (does this even show up in C# projects?)
  4. Switch on mixed mode debug/unmanaged debugging
  5. Ensure that symbols are being generated and stored in the correct location (*.pdb)
  6. Failing all of that, you can poke around in the System event viewer and look for any weird errors
like image 136
Ray Avatar answered Oct 03 '22 01:10

Ray