27

I have a StackOverFlow occurring somewhere in my application - and I'm trying to figure out ways to track it down.

My event logs show a crash every day or so with the following information:

Faulting application name: MyApp.exe, version: 1.0.0.0, time stamp: 0x522e8317

Faulting module name: clr.dll, version: 4.0.30319.18047, time stamp: 0x515530ce

Exception code: 0xc00000fd

Fault offset: 0x000000000000c657

Faulting process id: 0x117fc

Faulting application start time: 0x01ceadf607b184d2

Faulting application path: C:\Users\Administrator\Desktop\MyApp.exe

Faulting module path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll

Report Id: d52424aa-1a16-11e3-bc4b-002590a4ec55

I read that 0xc00000fd is a stack overflow, but I am unsure on where it could be occurring (very large codebase), and how to track it down. Any ideas?

9
  • 3
    do you have any other - application level - logging? Commented Sep 10, 2013 at 14:40
  • My first guesses would be some condition that's causing an infinite loop or a significant amount of recursion. Commented Sep 10, 2013 at 14:41
  • It would probably be a pain, but you could try and manually go through each for, while, and any other loop to make sure that they eventually exit. Commented Sep 10, 2013 at 15:07
  • 2
    Regarding the loop comments: infinite loops would more than likely never cause a stack overflow. Recursion is almost certainly the cause. Commented Sep 10, 2013 at 15:13
  • 3
    Using WinDbg + SOS is the easiest way to know what is going on for sure. Setup ADPlus to take a minidump when your process crashes, and examine the dump to see what's going on. Commented Sep 10, 2013 at 15:41

2 Answers 2

20

This is typically something I use WinDbg to track down, otherwise it's just a guessing game. Here's a quick walkthrough that should set you in the right direction.

WinDbg is a debugger for Windows, good for debugging managed and unmanaged code. It's also great for examining crash dumps. Let's start with an example program.

class Program
{
    static void Main(string[] args)
    {
        IWillStackOverflow(0);
    }

    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
    static int IWillStackOverflow(int i)
    {
        return IWillStackOverflow(i + 1);
    }
}

This is a pretty contrived example, but let's roll with it. It does indeed stack overflow, and nor does it provide a stacktrace. This is where WinDbg comes in. First you need to install it, which is part of the Debugging Tools in the Windows SDK. There are two versions, the x64 and x86. You'll want to run the one that matches the bitness of your application.

In WinDbg, use File -> Open Executable and run your executable with WinDbg attached. The debugger will break as soon as your application loads, you can use the g command to Go and use your application until you get a StackOverflowException. Before you do that though, make sure your symbols are correct - usually running .symfix+ will correct it, then you can go.

When you get your StackOverflowException, the debugger will break on the thread that raised the exception, and the message will be something like this:

(cc0.b00): Stack overflow - code c00000fd (first chance)

Now we can load the managed debugging extensions with this command (I am assuming you are using the .NET Framework 4.0 or 4.5 here):

.loadby sos clr

And calling !clrstack. In this example, the output is:

000000d440c76040 00007ffb282b0111 StackOverflower.Program.IWillStackOverflow(Int32) [Program.cs @ 20]
000000d440c76080 00007ffb282b0111 StackOverflower.Program.IWillStackOverflow(Int32) [Program.cs @ 20]
000000d440c760c0 00007ffb282b0111 StackOverflower.Program.IWillStackOverflow(Int32) [Program.cs @ 20]
..Repeat thousands of times..

So we have our managed stack at the time of the StackOverflowException.

If your Application doesn't StackOverflow very easily, you can configure ADPlus to take a memory dump of your application at the time of the StackOverflowException. ADPlus is another big-hammer tool, but it's effective. First you need a configuration for ADPlus, here is an example one:

<ADPlus> 
   <!-- Add log entry, log faulting thread stack and dump full on first chance StackOverflow --> 
<Exceptions> 
     <Config> 
        <!-- Use sov for stack overflow exception --> 
       <Code> sov </Code> 
       <Actions1> Log;Stack;FullDump </Actions1> 
       <!-- Depending on what you intend - either stop the debugger (Q or QQ) or continue unhandled (GN) --> 
       <ReturnAction1> GN </ReturnAction1> 
     < Config> 
  </Exceptions> 
</ADPlus>

This configuration example was originally published by user jaskis on the MSDN Forums: http://blogs.msdn.com/b/jaskis/archive/2010/08/11/cwa-ends-up-with-blank-screen-on-browser-on-iis-7.aspx Then use the command line to start your application with the configuration.


This is just an example, WinDbg is a very powerful tool, though it has a bit of a learning curve. There are a lot of good resources on the internet for getting the hang of it. Tess Ferrandez has many articles in her blog that cover WinDbg and the managed debugging extensions.

Sign up to request clarification or add additional context in comments.

4 Comments

I was hoping you would turn your comment in to an answer, I didn't really want to write this up my self either :). The only thing missing is how to set up to get a minidump of the program on crash and how to load that in to WinDbg instead of running the program inside the debugger, The OP said it crashes once a day so the debugger would have to be attached for a long time for it to see it.
For further reading I found this blog posting that goes over getting your C# code to generate a dump on crash and how to open it up in WinDbg
@ScottChamberlain I added a little information about ADPlus, hopefully enough to be useful. Thanks for the feedback.
Thanks for the answer. I had to tweak the sos loading as per MSDN and made sure I ran as admin, but this all enabled me to get to the bottom of my EF SO error :-)
5

This has already been answered, but I was searching for a better answer than WinDbg on the affected machine, since this is only happening on a production server machines for me where I don't want to install WinDbg. I found this article where it refers to a downloadable tool from Microsoft that allows you to configure, on a per-exception code basis, how the system should respond to different exceptions. This will (hopefully) allow debugging on a different machine than the production machine:

This DebugDiag utility can be configured to generate a crash dump when the StackOverflowException occurs. Download it here.

4 Comments

Thanks! I was able to save a dump file from VS from the Debug menu, then analyze it with DebugDiag and found the source of the stack overflow exception in a 3rd party library.
Both links are broken.
@MustafaÖzçetin My post is 8.5 years old so I'm not too surprised that the old links no longer exist. However, I just Googled "Microsoft DebugDiag" and there are plenty of newer articles and downloads. See microsoft.com/en-us/search/explore?q=DebugDiag
Right, this not a surprise :) I am just trying to keep SO updated as soon as possible when there is a chance to provide more up to date links.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.