Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy stack trace from IntelliJ Idea

When the program has stopped at a breakpoint, I want to copy the current stack trace (the call stack) and paste it into a text file.

Unfortunately, the current version of IntelliJ Idea does not provide such functionality in the debugger frames window.

like image 338
18446744073709551615 Avatar asked Nov 07 '17 11:11

18446744073709551615


People also ask

How do I print current stack trace?

The printStackTrace() method of Java. lang. Throwable class used to print this Throwable along with other details like class name and line number where the exception occurred means its backtrace. This method prints a stack trace for this Throwable object on the standard error output stream.

How do I copy an object in IntelliJ?

Usage. When stopped at breakpoint while debugging, you can right click on a variable and select "Copy as JSON String". The selected variable will be serialized to JSON and get copied to your clipboard.

How do I recover stack trace?

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.


2 Answers

You can use:

  1. IDEA 2018.1 where "copy stack" action was finally introduced
  2. Export threads action from the frames view context menu
  3. Thread dump action from the left debugger toolbar
like image 148
Egor Avatar answered Sep 28 '22 10:09

Egor


The solution is to add a special watch (the green + in the Variables window of the debugger), either

new Exception("debug").getStackTrace()

or

org.apache.commons.lang.StringUtils.join(new Exception("debug").getStackTrace(),"\n")

It is possible to copy (and paste as text) the value of such watch, and this value is the stack trace.

(You should be able to use String.join() in Java 8 or TextUtils.join(delimiter, array) in Android)

like image 38
18446744073709551615 Avatar answered Sep 28 '22 09:09

18446744073709551615