Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/spy/TcpipSpy.java')
-rw-r--r--org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/spy/TcpipSpy.java130
1 files changed, 71 insertions, 59 deletions
diff --git a/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/spy/TcpipSpy.java b/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/spy/TcpipSpy.java
index f8df6bef1..0c21c62a8 100644
--- a/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/spy/TcpipSpy.java
+++ b/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/spy/TcpipSpy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.jdi.internal.spy;
-
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
@@ -26,33 +25,33 @@ import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
-import com.ibm.icu.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
+import com.ibm.icu.text.MessageFormat;
+
/**
- * This class can be used to spy all JDWP packets. It should be configured 'in between' the debugger
- * application and the VM (or J9 debug proxy).
- * Its parameters are:
- * 1) The port number to which the debugger application connects;
- * 2) The name of the host on which the VM or proxy waits for a JDWP connection;
- * 3) The port number on which the VM or proxy waits for a JDWP connection;
- * 4) The file where the trace is written to.
- *
+ * This class can be used to spy all JDWP packets. It should be configured 'in
+ * between' the debugger application and the VM (or J9 debug proxy). Its
+ * parameters are: 1) The port number to which the debugger application
+ * connects; 2) The name of the host on which the VM or proxy waits for a JDWP
+ * connection; 3) The port number on which the VM or proxy waits for a JDWP
+ * connection; 4) The file where the trace is written to.
+ *
* Note that if this program is used for tracing JDWP activity of Leapfrog, the
- * 'debug remote program' option must be used, and the J9 proxy must first be started up by hand
- * on the port to which Leapfrog will connect.
- * The J9 proxy that is started up by Leapfrog is not used and will return immediately.
+ * 'debug remote program' option must be used, and the J9 proxy must first be
+ * started up by hand on the port to which Leapfrog will connect. The J9 proxy
+ * that is started up by Leapfrog is not used and will return immediately.
*/
public class TcpipSpy extends Thread {
- private static final byte[] handshakeBytes= "JDWP-Handshake".getBytes(); //$NON-NLS-1$
+ private static final byte[] handshakeBytes = "JDWP-Handshake".getBytes(); //$NON-NLS-1$
private boolean fVMtoDebugger;
private DataInputStream fDataIn;
private DataOutputStream fDataOut;
- private static VerbosePacketStream out= new VerbosePacketStream(System.out);
- private static Map fPackets= new HashMap();
+ private static VerbosePacketStream out = new VerbosePacketStream(System.out);
+ private static Map<Integer, JdwpConversation> fPackets = new HashMap<Integer, JdwpConversation>();
private static int fFieldIDSize;
private static int fMethodIDSize;
@@ -62,66 +61,74 @@ public class TcpipSpy extends Thread {
private static boolean fHasSizes;
public TcpipSpy(boolean VMtoDebugger, InputStream in, OutputStream out) {
- fVMtoDebugger= VMtoDebugger;
- fDataIn= new DataInputStream(new BufferedInputStream(in));
- fDataOut= new DataOutputStream(new BufferedOutputStream(out));
- fHasSizes= false;
+ fVMtoDebugger = VMtoDebugger;
+ fDataIn = new DataInputStream(new BufferedInputStream(in));
+ fDataOut = new DataOutputStream(new BufferedOutputStream(out));
+ fHasSizes = false;
}
public static void main(String[] args) {
- int inPort= 0;
- String serverHost= null;
- int outPort= 0;
- String outputFile= null;
+ int inPort = 0;
+ String serverHost = null;
+ int outPort = 0;
+ String outputFile = null;
try {
- inPort= Integer.parseInt(args[0]);
- serverHost= args[1];
- outPort= Integer.parseInt(args[2]);
+ inPort = Integer.parseInt(args[0]);
+ serverHost = args[1];
+ outPort = Integer.parseInt(args[2]);
if (args.length > 3) {
- outputFile= args[3];
+ outputFile = args[3];
}
} catch (Exception e) {
- out.println("usage: TcpipSpy <client port> <server host> <server port> [<output file>]"); //$NON-NLS-1$
+ out.println("usage: TcpipSpy <client port> <server host> <server port> [<output file>]"); //$NON-NLS-1$
System.exit(-1);
}
if (outputFile != null) {
- File file= new File(outputFile);
- out.println(MessageFormat.format("Writing output to {0}", new String[] {file.getAbsolutePath()})); //$NON-NLS-1$
+ File file = new File(outputFile);
+ out.println(MessageFormat
+ .format("Writing output to {0}", new Object[] { file.getAbsolutePath() })); //$NON-NLS-1$
try {
- out= new VerbosePacketStream(new BufferedOutputStream(new FileOutputStream(file)));
+ out = new VerbosePacketStream(new BufferedOutputStream(
+ new FileOutputStream(file)));
} catch (FileNotFoundException e) {
- out.println(MessageFormat.format("Could not open {0}. Using stdout instead", new String[] {file.getAbsolutePath()})); //$NON-NLS-1$
+ out.println(MessageFormat
+ .format("Could not open {0}. Using stdout instead", new Object[] { file.getAbsolutePath() })); //$NON-NLS-1$
}
}
out.println();
try {
- ServerSocket serverSock= new ServerSocket(inPort);
- Socket inSock= serverSock.accept();
- Socket outSock= new Socket(InetAddress.getByName(serverHost), outPort);
- new TcpipSpy(false, inSock.getInputStream(), outSock.getOutputStream()).start();
- new TcpipSpy(true, outSock.getInputStream(), inSock.getOutputStream()).start();
+ ServerSocket serverSock = new ServerSocket(inPort);
+ Socket inSock = serverSock.accept();
+ Socket outSock = new Socket(InetAddress.getByName(serverHost),
+ outPort);
+ new TcpipSpy(false, inSock.getInputStream(),
+ outSock.getOutputStream()).start();
+ new TcpipSpy(true, outSock.getInputStream(),
+ inSock.getOutputStream()).start();
} catch (Exception e) {
out.println(e);
}
}
+ @Override
public void run() {
try {
// Skip handshake.
int handshakeLength;
- handshakeLength= handshakeBytes.length;
+ handshakeLength = handshakeBytes.length;
while (handshakeLength-- > 0) {
- int b= fDataIn.read();
+ int b = fDataIn.read();
fDataOut.write(b);
}
fDataOut.flush();
// Print all packages.
while (true) {
- JdwpPacket p= JdwpPacket.read(fDataIn);
- // we need to store conversation only for command send by the debugger,
+ JdwpPacket p = JdwpPacket.read(fDataIn);
+ // we need to store conversation only for command send by the
+ // debugger,
// as there is no answer from the debugger to VM commands.
if (!(fVMtoDebugger && (p.getFlags() & JdwpPacket.FLAG_REPLY_PACKET) == 0)) {
store(p);
@@ -134,7 +141,8 @@ public class TcpipSpy extends Thread {
} catch (EOFException e) {
} catch (SocketException e) {
} catch (IOException e) {
- out.println(MessageFormat.format("Caught exception: {0}", new String[] {e.toString()})); //$NON-NLS-1$
+ out.println(MessageFormat.format(
+ "Caught exception: {0}", new Object[] { e.toString() })); //$NON-NLS-1$
e.printStackTrace(out);
} finally {
try {
@@ -147,17 +155,19 @@ public class TcpipSpy extends Thread {
}
public static JdwpCommandPacket getCommand(int id) {
- JdwpConversation conversation= (JdwpConversation) fPackets.get(new Integer(id));
+ JdwpConversation conversation = fPackets
+ .get(new Integer(id));
if (conversation != null)
return conversation.getCommand();
return null;
}
protected static void store(JdwpPacket packet) {
- int id= packet.getId();
- JdwpConversation conversation= (JdwpConversation) fPackets.get(new Integer(id));
+ int id = packet.getId();
+ JdwpConversation conversation = fPackets
+ .get(new Integer(id));
if (conversation == null) {
- conversation= new JdwpConversation(id);
+ conversation = new JdwpConversation(id);
fPackets.put(new Integer(id), conversation);
}
@@ -168,14 +178,16 @@ public class TcpipSpy extends Thread {
}
}
- public static int getCommand(JdwpPacket packet) throws UnableToParseDataException {
- JdwpCommandPacket command= null;
+ public static int getCommand(JdwpPacket packet)
+ throws UnableToParseDataException {
+ JdwpCommandPacket command = null;
if (packet instanceof JdwpCommandPacket) {
- command= (JdwpCommandPacket) packet;
+ command = (JdwpCommandPacket) packet;
} else {
- command= getCommand(packet.getId());
+ command = getCommand(packet.getId());
if (command == null) {
- throw new UnableToParseDataException("This packet is marked as reply, but there is no command with the same id.", null); //$NON-NLS-1$
+ throw new UnableToParseDataException(
+ "This packet is marked as reply, but there is no command with the same id.", null); //$NON-NLS-1$
}
}
return command.getCommand();
@@ -186,11 +198,11 @@ public class TcpipSpy extends Thread {
}
public static void setHasSizes(boolean value) {
- fHasSizes= value;
+ fHasSizes = value;
}
public static void setFieldIDSize(int fieldIDSize) {
- fFieldIDSize= fieldIDSize;
+ fFieldIDSize = fieldIDSize;
}
public static int getFieldIDSize() {
@@ -198,7 +210,7 @@ public class TcpipSpy extends Thread {
}
public static void setMethodIDSize(int methodIDSize) {
- fMethodIDSize= methodIDSize;
+ fMethodIDSize = methodIDSize;
}
public static int getMethodIDSize() {
@@ -206,7 +218,7 @@ public class TcpipSpy extends Thread {
}
public static void setObjectIDSize(int objectIDSize) {
- fObjectIDSize= objectIDSize;
+ fObjectIDSize = objectIDSize;
}
public static int getObjectIDSize() {
@@ -214,7 +226,7 @@ public class TcpipSpy extends Thread {
}
public static void setReferenceTypeIDSize(int referenceTypeIDSize) {
- fReferenceTypeIDSize= referenceTypeIDSize;
+ fReferenceTypeIDSize = referenceTypeIDSize;
}
public static int getReferenceTypeIDSize() {
@@ -222,7 +234,7 @@ public class TcpipSpy extends Thread {
}
public static void setFrameIDSize(int frameIDSize) {
- fFrameIDSize= frameIDSize;
+ fFrameIDSize = frameIDSize;
}
public static int getFrameIDSize() {

Back to the top