com.cmpware.gdb
Class RSP

java.lang.Object
  extended by com.cmpware.gdb.RSP
Direct Known Subclasses:
FIF

public class RSP
extends java.lang.Object

This class implements a basic GDB Remote Serial Protocol (RSP) interface. See the GDB documentation for more information on this protocol.

Copyright (c) 2007 Cmpware, Inc. All Rights Reserved.

Author:
SAG

Field Summary
static java.lang.String copyright
          Copyright string
static boolean DEBUG
          The debug flag
protected  java.io.InputStream in
          The input stream for the socket
protected  java.io.OutputStream out
          The input stream for the socket
protected  java.net.Socket socket
          The socket
 
Constructor Summary
RSP()
           
 
Method Summary
 java.lang.String checksum(java.lang.String s)
          This method returns the two byte hexadecimal checksum based on the input string.
 int connect(java.lang.String server, int port)
          This method connects to the GDB compatible server.
 void disconnect()
          This method disconnects from the server.
 boolean isError(java.lang.String s)
          This method returns true if the string representing a packet is an error string.
 boolean isOk(java.lang.String s)
          This method returns true if the string representing a packet is a 'OK' string.
 boolean isPacket(java.lang.String s)
          This method returns true if the string is a complete packet and false otherwise.
static void main(java.lang.String[] args)
          This main program is used for testing.
 java.lang.String recv()
          This method receives a string from the target.
 java.lang.String recvPacket()
          This method receives a complete packet.
 void send(java.lang.String s)
          This method sends raw data over the socket connection.
 void sendPacket(java.lang.String s)
          This method sends a gdb server commands.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG
The debug flag

See Also:
Constant Field Values

copyright

public static final java.lang.String copyright
Copyright string

See Also:
Constant Field Values

socket

protected java.net.Socket socket
The socket


in

protected java.io.InputStream in
The input stream for the socket


out

protected java.io.OutputStream out
The input stream for the socket

Constructor Detail

RSP

public RSP()
Method Detail

main

public static void main(java.lang.String[] args)
This main program is used for testing.


connect

public int connect(java.lang.String server,
                   int port)
This method connects to the GDB compatible server.

Parameters:
server - the server name.
port - the server port.
Returns:
a zero is returned upon success and an error code upon failure.

sendPacket

public void sendPacket(java.lang.String s)
                throws java.io.IOException
This method sends a gdb server commands. It builds the packet by prepending a "$" byte, appending a "#" byte and adding the two byte checksum in hexadecimal.

Parameters:
s - The command to be sent.
Throws:
an - IOException is thrown if the write could not complete.
java.io.IOException

recvPacket

public java.lang.String recvPacket()
                            throws java.io.IOException
This method receives a complete packet. Note that this method currently loops while receiving partial packets. This method relys on exception to break out of this loop if an error occurs.

Returns:
this method returns a complete packet.
Throws:
java.io.IOException - this method throws an IOException if there are errors reading the socket.

send

public void send(java.lang.String s)
          throws java.io.IOException
This method sends raw data over the socket connection.

Parameters:
s - The data to be sent.
Throws:
an - IOException is thrown if the write could not complete.
java.io.IOException

recv

public java.lang.String recv()
                      throws java.io.IOException
This method receives a string from the target. If no data is available an empty string ("") is returned.

Returns:
This method receives a string from the target. If no data is available an empty string ("") is returned.
Throws:
an - IOException is thrown if the socket read could not complete.
java.io.IOException

disconnect

public void disconnect()
This method disconnects from the server.


isPacket

public boolean isPacket(java.lang.String s)
This method returns true if the string is a complete packet and false otherwise. Currently this only supports the subset of packets used by this class. NOte that this is used before the packet header and footer are removed.

Parameters:
s - The packet.
Returns:
This method returns true if the string is a complete packet and false otherwise.

isOk

public boolean isOk(java.lang.String s)
This method returns true if the string representing a packet is a 'OK' string.

Parameters:
s - The packet.
Returns:
This method returns true if the string representing a packet is a 'OK' string.

isError

public boolean isError(java.lang.String s)
This method returns true if the string representing a packet is an error string.

Parameters:
s - The packet.
Returns:
This method returns true if the string representing a packet is an error string.

checksum

public java.lang.String checksum(java.lang.String s)
This method returns the two byte hexadecimal checksum based on the input string.

Parameters:
s - the input string
Returns:
This method returns the two byte hexadecimal checksum based on the input string.