Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get stacktrace of all threads

Tags:

c#

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!

like image 328
Maanu Avatar asked May 03 '11 06:05

Maanu


People also ask

How do you get a StackTrace?

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.

How do you print StackTrace?

Just use new Throwable(). printStackTrace() method and it will print complete stack trace from where a method is called, into the console.

How can I get the current stack trace in Java?

You can use Thread. currentThread(). getStackTrace() . That returns an array of StackTraceElement s that represent the current stack trace of a program.


2 Answers

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/

like image 144
abhilash Avatar answered Oct 22 '22 17:10

abhilash


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));
    }
}
like image 29
Alois Kraus Avatar answered Oct 22 '22 17:10

Alois Kraus