From: <cap...@us...> - 2007-04-22 10:26:02
|
Revision: 80 http://svn.sourceforge.net/pearcolator/?rev=80&view=rev Author: captain5050 Date: 2007-04-22 03:26:02 -0700 (Sun, 22 Apr 2007) Log Message: ----------- A couple of improvements to the GDB stub to enable it to walk past protocol errors on x86 Modified Paths: -------------- src/org/binarytranslator/generic/execution/GdbController.java Modified: src/org/binarytranslator/generic/execution/GdbController.java =================================================================== --- src/org/binarytranslator/generic/execution/GdbController.java 2007-04-21 19:44:59 UTC (rev 79) +++ src/org/binarytranslator/generic/execution/GdbController.java 2007-04-22 10:26:02 UTC (rev 80) @@ -74,7 +74,7 @@ /** * The stream to read from the socket */ - private final InputStream in; + private final PushbackInputStream in; /** * The stream to read from the socket @@ -92,6 +92,11 @@ private final GdbTarget target; /** + * If we get an unexpected packet should we fail or try to ignore it? + */ + private final boolean ignoreProtocolErrors = true; + + /** * Thread to continue or step, a value of -1 means all threads, 0 means any * thread. */ @@ -167,7 +172,7 @@ try { ServerSocket connectionSocket = new ServerSocket(port); socket = connectionSocket.accept(); - in = socket.getInputStream(); + in = new PushbackInputStream(socket.getInputStream()); out = socket.getOutputStream(); buffer = new byte[256]; getACK(); @@ -235,7 +240,12 @@ private void getACK() throws IOException { int command = in.read(); if (command != ACK) { - throw new IOException("Acknowledge expected but got " + (char) command); + if (ignoreProtocolErrors) { + in.unread(command); + report("Acknowledge expected but got \"" + (char) command + "\""); + } else { + throw new IOException("Acknowledge expected but got \"" + (char) command + "\""); + } } } @@ -254,11 +264,21 @@ private int readPacket() throws IOException { // Read the packet start int index = 0; - buffer[index] = (byte) in.read(); - if (buffer[index] != START) { - throw new IOException("Expected the start of a packet ($) but got " - + (char) buffer[index]); - } + boolean foundStart = false; + do { + buffer[index] = (byte) in.read(); + if (buffer[index] == START) { + foundStart = true; + } else { + if (!ignoreProtocolErrors) { + throw new IOException("Expected the start of a packet \"$\" but got \"" + + (char) buffer[index] + "\""); + } else { + report("Expected the start of a packet \"$\" but got \"" + + (char) buffer[index] + "\""); + } + } + } while(!foundStart); // Read the data int csum = 0; do { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |