I would like to log the stack trace of all threads in my c# application (UI). I can get the stack trace of all managed threads using WinDbg with the following commands.
.loadby sos mscorwks
~* e !clrstack
Is there any other easy methods to get the callstack of all threads in my c# application? This is because I want to get the callstack when the application is running in the customer machine and the customer is not a technical person
Please help me.
Thanks!
You can obtain a stack trace from a thread – by calling the getStackTrace method on that Thread instance. This invocation returns an array of StackTraceElement, from which details about stack frames of the thread can be extracted.
Just use new Throwable(). printStackTrace() method and it will print complete stack trace from where a method is called, into the console.
You can use Thread. currentThread(). getStackTrace() . That returns an array of StackTraceElement s that represent the current stack trace of a program.
Here's a suggestion try to grab a user dump of application using either Adplus+WinDbg or DebugDiag. And do a postmortem debugging using the userdump
Here's a good article about capturing user dumps automatically on process crashes
Good Reads Tess Fernandez's blog on msdn
http://debuggingblog.com/wp/2008/10/31/beginner-guide-to-windbg-part-1/
Yes you can do it in a live process as well if you do deploy Windbg to the customer machine as well and then use WMemoryProfiler to execute a debugger command. It sounds strange but you can actually debug yourself with a debugger automaticaly.
See here:
private static void SelfDebug()
{
using (var debugger = new MdbEng())
{
string[] output = debugger.Execute("~*e!ClrStack");
Console.WriteLine(String.Join(Environment.NewLine, output));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With