开发者

recording call stack in Visual Studio

I'm trying to debu开发者_开发问答g 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.


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).


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜