There seem to be no support for tracepoints in Eclipse (JDT) debug mode.
This is really a bummer, since you may sometime want to print a lot of debug infomation without cluttering your code with hardcoded println that you are likely to forget later on.
I found a simple workaround for that and wanted to share with SO.
Breakpoints To define a breakpoint in your source code, right-click in the left margin in the Java editor and select Toggle Breakpoint. Alternatively, you can double-click on this position. The Breakpoints view allows you to delete and deactivate Breakpoints and modify their properties.
Open Debug Configuration -> Debugger -> Enable Reverse Debugging at startup . Than you can press shift+F5 or shift+F6 for step back like F5 or F6 for step forward.
There are two ways to debug a class file. The first way is to set the decompiler preference, and to realign the line number. The second way is to check the debug mode in the decompiler menu bar. When your Eclipse workspace is in debug perspective, the debug mode becomes the default.
Eclipse supports conditional breakpoints.
All you have to do, is provide it with a boolean expression, and it'll be happy. In this case, a static method that also prints useful stuff as a side effect is fine.
public class TracePointUtils {
static private Logger logger = org.slf4j.LoggerFactory.getLogger(TracePointUtils.class);
/** Produce a WARN message in SL4J logger */
public static boolean trace(String msg, Object ... args) {
logger.warn(format(msg, args));
// Do not stop
return false;
}
}
Here, I use SL4J as a logger, but a plain println would be fine.
Then, add a breakpoint in your code, and call this static method as the condition:
Et voila, you can enjoy nice traces in your console.
Just for the record, Eclipse Oxygen provides support for tracepoints:
http://www.eclipse.org/oxygen/noteworthy/#conditional-watchpoint
Clicking around in the menu seems tedious, I think it's best to create a key mapping for the Toggle Tracepoint
command.
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