May 6, 2011

Test for java debugger

Here's a trick to determine if the debugger is running. Not 100% sure that this will always work but seems to work from eclipse.
http://www.rgagnon.com/javadetails/java-detect-if-running-in-debug-mode.html

String inputArgs = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().toString();
boolean debug = inputArgs.indexOf("-agentlib:jdwp") > 0 || inputArgs.indexOf("Xrunjdwp") > 0;

No comments: