views:

216

answers:

2

Hi,

I'm trying to debug a really large c++/c program in Visual Studio. Changing value of one parameter changes the result dramatically. I want to record a call stacks for both runs and diff them.

Does anybody know how to dump a call stack to a file in VS without setting breakpoints and using Select ALL/Copy in the window?

Thanks.

+1  A: 

Take a look at this codeproject example which uses the StackWalk64 API.

Dolphin
I've found another solution for my problem. But this seams promising.
Bogdan Kanivets
Care to tell what your solution is then? :)I really hate searching for an issue, finding a guy asking the very same question and then replying his own question with stuff like "oh nevermind, I found a solution"...
Jan
+1  A: 

You can use System.Diagnostics.StackTrace to get a string representation of the current call stack and write that to a file. For example:

private static writeStack(string file)
{
    StackTrace trace = new StackTrace(true); // the "true" param here allows you to get the file name, etc.
    using (StreamWriter writer = new StreamWriter(file))
    {
    for (int i = 0; i < trace.FrameCount; i++)
        {
         StackFrame frame = trace.GetFrame(i);
         writer.WriteLine("{0}\t{1}\t{2}", frame.GetFileName(), frame.GetFileLineNumber(), frame.GetMethod());
        }
    }
}

Then, whenever you want to write the current stack, just call writeStack(somePath).

fatcat1111