StuBS
protocol.cc File Reference
#include "debug/gdb/stub.h"
#include "debug/gdb/state.h"
#include "machine/apic.h"
#include "machine/core.h"
#include "machine/system.h"
#include "debug/assert.h"
#include "debug/output.h"
Include dependency graph for protocol.cc:

Macros

#define token_remaining_buf   (pkt_len-(ptr_next-pkt_buf))
#define token_expect_seperator(c)
#define token_expect_integer_arg(arg)

Functions

static char getDigit (int val)
 Get the corresponding ASCII hex digit character for a value.
static bool stringCompare (const char *a, const char *b, size_t len)
 Comparison of two strings.
static size_t stringCopy (char *target, size_t target_len, const char *source, size_t source_len=-1)
 Copy string (including \0).
static size_t stringConcat (char *target, size_t target_len, const char *source, size_t source_len=-1)
 Concatenate a source string to the target buffer.
static size_t stringConcat (char *target, size_t target_len, char source)
 Concatenate a character to the target buffer.
static int getValue (char digit, int base)
 Get the corresponding value for a ASCII digit character.
static bool isPrintableChar (char ch)
 Determine if this is a printable ASCII character.
static intptr_t stringToInteger (const char *str, size_t len, int base, const char **endptr)
 Get integer value for a string representation.
static int encodeHex (char *buf, size_t buf_len, const char *data, size_t data_len)
static int encodeHex (char *buf, size_t buf_len, const State::Register data)
 Encode data to its hex-value representation in a buffer.
static int decodeHex (const char *buf, size_t buf_len, char *data, size_t data_len)
 Decode data from its hex-value representation to a buffer.
static int decodeHex (const char *buf, size_t buf_len, State::Register reg)
 Decode data from its hex-value representation to a buffer.
static int encodeBinary (char *buf, size_t buf_len, const char *data, size_t data_len)
 Encode data to its binary representation in a buffer.
static int decodeBinary (const char *buf, size_t buf_len, char *data, size_t data_len)
 Decode data from its bin-value representation to a buffer.

Constants

static const char digits [] = "0123456789abcdef"
static int8_t cpu_ops [127]
 Map operations to core.

Macro Definition Documentation

◆ token_remaining_buf

#define token_remaining_buf   (pkt_len-(ptr_next-pkt_buf))

◆ token_expect_seperator

#define token_expect_seperator ( c)
Value:
do { \
if (!ptr_next || *ptr_next != (c)) { \
goto error; \
} else { \
ptr_next += 1; \
} \
} while (0)

◆ token_expect_integer_arg

#define token_expect_integer_arg ( arg)
Value:
do { \
(arg) = stringToInteger(ptr_next, token_remaining_buf, 16, &ptr_next); \
if (!ptr_next) { \
goto error; \
} \
} while (0)
#define token_remaining_buf
static intptr_t stringToInteger(const char *str, size_t len, int base, const char **endptr)
Get integer value for a string representation.
Definition protocol.cc:163

Function Documentation

◆ getDigit()

char getDigit ( int val)
static

Get the corresponding ASCII hex digit character for a value.

Parameters
valvalue
Returns
ASCII hex digit or -1 if invalid

◆ stringCompare()

bool stringCompare ( const char * a,
const char * b,
size_t len )
static

Comparison of two strings.

Parameters
afirst string
bsecond string
lenmaximum length to compare
Returns
true if identical (up to the maximum length)

◆ stringCopy()

size_t stringCopy ( char * target,
size_t target_len,
const char * source,
size_t source_len = -1 )
static

Copy string (including \0).

Parameters
targetPointer to target buffer
target_lenMaximum length of target buffer
sourcePointer to source buffer
source_lenMaximum length of source buffer (or -1 if it should be determined by the \0 byte)
Returns
Number of copied characters (bytes)

◆ stringConcat() [1/2]

size_t stringConcat ( char * target,
size_t target_len,
const char * source,
size_t source_len = -1 )
static

Concatenate a source string to the target buffer.

Parameters
targetPointer to target buffer
target_lenMaximum length of target buffer
sourcePointer to source buffer
Returns
New length of target buffer

Concatenate a source string to the target buffer

Parameters
source_lenMaximum length of source buffer (or -1 if it should be determined by the \0 byte)

◆ stringConcat() [2/2]

size_t stringConcat ( char * target,
size_t target_len,
char source )
static

Concatenate a character to the target buffer.

Overloads singConcat(char*, size_t, const char*, size_t)

Parameters
targetPointer to target buffer
target_lenMaximum length of target buffer
sourceSource character
Returns
New length of target buffer

◆ getValue()

int getValue ( char digit,
int base )
static

Get the corresponding value for a ASCII digit character.

Parameters
digitASCII digit character
baseBase to convert (supports bases 2 to 16)
Returns
value or -1 if invalid

◆ isPrintableChar()

bool isPrintableChar ( char ch)
static

Determine if this is a printable ASCII character.

Parameters
chcharacter to check
Return values
trueprintable
falsenot printable

◆ stringToInteger()

intptr_t stringToInteger ( const char * str,
size_t len,
int base,
const char ** endptr )
static

Get integer value for a string representation.

Parameters
strString to convert. It it starts with + or - it will be signed accordingly.
lenlength of string
baseBase for the conversion. In case the value is set to 0, the base will be determined: if string starts with 0x or 0X it is hexadecimal (base 16), otherwise decimal representation (base 10).
endptrIf specified, it will point to the last non-digit in the string. If there are no digits in the string, it will be set to nullptr.
Returns
recognized integer

◆ encodeHex() [1/2]

int encodeHex ( char * buf,
size_t buf_len,
const char * data,
size_t data_len )
static

◆ encodeHex() [2/2]

int encodeHex ( char * buf,
size_t buf_len,
const State::Register data )
static

Encode data to its hex-value representation in a buffer.

Overloads encodeHex(char*, size_t, const char*, size_t)

Parameters
bufPointer to target buffer for encoded data
buf_lenSize of target buffer
dataSource register
Returns
number of bytes written to target buffer or -1 if the buffer is too small

◆ decodeHex() [1/2]

int decodeHex ( const char * buf,
size_t buf_len,
char * data,
size_t data_len )
static

Decode data from its hex-value representation to a buffer.

Parameters
bufSource buffer with encoded data
buf_lenSize of source buffer
dataTarget data buffer (raw representation)
data_lenSize if target data
Return values
0on success
`-1`if the buffer is too small

◆ decodeHex() [2/2]

int decodeHex ( const char * buf,
size_t buf_len,
State::Register reg )
static

Decode data from its hex-value representation to a buffer.

Overloads decodeHex(const char*, size_t, char*, size_t)

Parameters
bufSource buffer with encoded data
buf_lenSize of source buffer
regTarget register
Return values
0on success
`-1`if the buffer is too small

◆ encodeBinary()

int encodeBinary ( char * buf,
size_t buf_len,
const char * data,
size_t data_len )
static

Encode data to its binary representation in a buffer.

Parameters
bufPointer to target buffer for encoded data
buf_lenSize of target buffer
dataSource data buffer (raw representation)
data_lenSize if source data
Returns
number of bytes written to target buffer or -1 if the buffer is too small

◆ decodeBinary()

int decodeBinary ( const char * buf,
size_t buf_len,
char * data,
size_t data_len )
static

Decode data from its bin-value representation to a buffer.

Parameters
bufSource buffer with encoded data
buf_lenSize of source buffer
dataTarget data buffer (raw representation)
data_lenSize if target data
Returns
number of bytes decoded or -1 if the buffer is too small

Variable Documentation

◆ digits

const char digits[] = "0123456789abcdef"
static

◆ cpu_ops

int8_t cpu_ops[127]
static

Map operations to core.