From: <cr...@us...> - 2008-04-27 13:13:13
|
Revision: 4031 http://jnode.svn.sourceforge.net/jnode/?rev=4031&view=rev Author: crawley Date: 2008-04-27 06:13:10 -0700 (Sun, 27 Apr 2008) Log Message: ----------- Converted DebugCommand. (It doesn't work though: see issue 2592) Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.debug.xml trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.debug.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.debug.xml 2008-04-27 11:29:40 UTC (rev 4030) +++ trunk/shell/descriptors/org.jnode.shell.command.debug.xml 2008-04-27 13:13:10 UTC (rev 4031) @@ -23,6 +23,14 @@ <alias name="debug" class="org.jnode.shell.command.debug.DebugCommand"/> </extension> + <extension point="org.jnode.shell.syntaxes"> + <syntax alias="debug"> + <optional description="Run a JDWP listener to enable remote debugging"> + <option argLabel="port" shortName="p" description="The port for the debugger to connect to"/> + </optional> + </syntax> + </extension> + <extension point="org.jnode.security.permissions"> <permission class="java.lang.RuntimePermission" name="modifyThreadGroup"/> <permission class="java.lang.RuntimePermission" name="setIO"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java 2008-04-27 11:29:40 UTC (rev 4030) +++ trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java 2008-04-27 13:13:10 UTC (rev 4031) @@ -6,30 +6,40 @@ import gnu.classpath.jdwp.JNodeSocketTransport; import gnu.classpath.jdwp.Jdwp; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.argument.IntegerArgument; +import java.io.InputStream; +import java.io.PrintStream; +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.IntegerArgument; + /** - * Starts up the remote debugger under JNode. + * Starts up a JDWP remote debugger listener for this JNode instance. * * @author Levente S\u00e1ntha */ -public class DebugCommand { +public class DebugCommand extends AbstractCommand { private static final int DEFAULT_PORT = 6789; - private static boolean up = true; - static final IntegerArgument ARG_PORT = new IntegerArgument("port", "the port to listen to"); + private boolean up = true; + private final IntegerArgument ARG_PORT = + new IntegerArgument("port", Argument.OPTIONAL, "the port to listen to"); - public static Help.Info HELP_INFO = new Help.Info("debug", "Start the remote debugger server.", new Parameter(ARG_PORT, Parameter.OPTIONAL)); - - public static void main(String[] argv) throws Exception { - ParsedArguments cmdLine = HELP_INFO.parse(argv); - - int port = DEFAULT_PORT; - if(argv.length > 0) - port = ARG_PORT.getInteger(cmdLine); - + public DebugCommand() { + super("Listen for connections from a remote debugger"); + registerArguments(ARG_PORT); + } + + public static void main(String[] args) throws Exception { + new DebugCommand().execute(args); + } + + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws Exception { + int port = ARG_PORT.isSet() ? ARG_PORT.getValue() : DEFAULT_PORT; + + // FIXME - in the even of internal exceptions, JDWP writes to System.out. final String ps = "transport=dt_socket,suspend=n,address=" + port + ",server=y"; Thread t = new Thread(new Runnable() { public void run() { @@ -40,24 +50,26 @@ jdwp.waitToFinish(); jdwp.shutdown(); } - //workaround for the restricted capabilities of JDWP support in GNU Classpath. + // workaround for the restricted capabilities of JDWP support in GNU Classpath. JNodeSocketTransport.ServerSocketHolder.close(); - up = true; } }); t.start(); - while (System.in.read() != 'q') { - System.out.println("Type 'q' for exitting."); + while (in.read() != 'q') { + out.println("Type 'q' to exit"); } + // FIXME - this just stops the 'debug' command. The listener will keep running + // until the remote debugger disconnects. We should have a way to disconnect at + // this end. down(); } - public static synchronized boolean up() { + public synchronized boolean up() { return up; } - public static synchronized void down() { + public synchronized void down() { up = false; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |