Commit ab6a3d37 authored by hjk's avatar hjk
Browse files

debugger: implementation progress in the trk manual test

parent 55d40713
This diff is collapsed.
......@@ -5,11 +5,14 @@ make || exit 1
killall -s USR1 adapter trkserver > /dev/null 2>&1
killall adapter trkserver > /dev/null 2>&1
trkservername="TRKSERVER-3";
trkservername="TRKSERVER-4";
gdbserverip=127.0.0.1
gdbserverport=2225
gdbserverport=2226
replaysource=dump.txt
fuser -n tcp -k ${gdbserverport}
rm /tmp/${trkservername}
./trkserver ${trkservername} ${replaysource} &
trkserverpid=$!
......
......@@ -59,6 +59,23 @@ using namespace trk;
// [80 02 00 7E 00 4F 5F 01 00 00 00 0F 1F 00 00 00
// 00 00 00 01 00 11 00 03 00 00 00 00 00 03 00 00...]
struct Inferior
{
Inferior();
uint pid;
uint tid;
uint codeseg;
uint dataseg;
};
Inferior::Inferior()
{
pid = 0x000008F5;
tid = 0x000008F6;
codeseg = 0x78674000;
dataseg = 0x00400000;
}
class TrkServer : public QObject
{
Q_OBJECT
......@@ -90,6 +107,7 @@ private:
QLocalServer m_server;
int m_lastSent;
QLocalSocket *m_adapterConnection;
Inferior m_inferior;
};
TrkServer::TrkServer()
......@@ -187,6 +205,39 @@ void TrkServer::handleAdapterMessage(const TrkResult &result)
writeToAdapter(0x80, result.token, data);
break;
}
case 0x10: { // Read Memory
const char *p = result.data.data();
byte option = p[0];
Q_UNUSED(option);
ushort len = extractShort(p + 1);
uint addr = extractInt(p + 3);
qDebug() << "ADDR: " << QByteArray::number(addr, 16) << " "
<< QByteArray::number(len, 16);
for (int i = 0; i != len; ++i)
appendByte(&data, i);
writeToAdapter(0x80, result.token, data);
break;
}
case 0x12: { // Read Registers
appendInt(&data, 0x00000000, BigEndian);
appendInt(&data, 0xC924FFBC, BigEndian);
appendInt(&data, 0x00000000, BigEndian);
appendInt(&data, 0x00600000, BigEndian);
appendInt(&data, 0x78677970, BigEndian);
for (int i = 5; i < registerCount - 1; ++i)
appendInt(&data, i + (i << 16), BigEndian);
appendInt(&data, 0x78676B00, BigEndian);
writeToAdapter(0x80, result.token, data);
break;
}
case 0x40: { // Create Item
appendInt(&data, m_inferior.pid, BigEndian);
appendInt(&data, m_inferior.tid, BigEndian);
appendInt(&data, m_inferior.codeseg, BigEndian);
appendInt(&data, m_inferior.dataseg, BigEndian);
writeToAdapter(0x80, result.token, data);
break;
}
default:
data[0] = 0x10; // Command not supported
writeToAdapter(0xff, result.token, data);
......
......@@ -117,7 +117,7 @@ TrkResult extractResult(QByteArray *buffer)
result.code = data.at(0);
result.token = data.at(1);
result.data = data.mid(2);
result.data = data.mid(2, data.size() - 3);
//logMessage(" REST BUF: " << stringFromArray(*buffer));
//logMessage(" CURR DATA: " << stringFromArray(data));
//QByteArray prefix = "READ BUF: ";
......@@ -127,15 +127,15 @@ TrkResult extractResult(QByteArray *buffer)
ushort extractShort(const char *data)
{
return data[0] * 256 + data[1];
return byte(data[0]) * 256 + byte(data[1]);
}
uint extractInt(const char *data)
{
uint res = data[0];
res *= 256; res += data[1];
res *= 256; res += data[2];
res *= 256; res += data[3];
uint res = byte(data[0]);
res *= 256; res += byte(data[1]);
res *= 256; res += byte(data[2]);
res *= 256; res += byte(data[3]);
return res;
}
......@@ -213,38 +213,47 @@ QString stringFromArray(const QByteArray &ba)
return str + " " + ascii;
}
QByteArray formatByte(byte b)
void appendByte(QByteArray *ba, byte b)
{
char buf[30];
qsnprintf(buf, sizeof(buf) - 1, "%x ", b);
return buf;
ba->append(b);
}
QByteArray formatShort(ushort s)
void appendShort(QByteArray *ba, ushort s, Endianness endian)
{
char buf[30];
qsnprintf(buf, sizeof(buf) - 1, "%x %x ", s / 256, s % 256);
return buf;
if (endian == BigEndian) {
ba->append(s / 256);
ba->append(s % 256);
} else {
ba->append(s % 256);
ba->append(s / 256);
}
}
QByteArray formatInt(uint i)
void appendInt(QByteArray *ba, uint i, Endianness endian)
{
char buf[30];
int b3 = i % 256; i -= b3; i /= 256;
int b2 = i % 256; i -= b2; i /= 256;
int b1 = i % 256; i -= b1; i /= 256;
int b0 = i % 256; i -= b0; i /= 256;
qsnprintf(buf, sizeof(buf) - 1, "%x %x %x %x ", b0, b1, b2, b3);
return buf;
if (endian == BigEndian) {
ba->append(b3);
ba->append(b2);
ba->append(b1);
ba->append(b0);
} else {
ba->append(b0);
ba->append(b1);
ba->append(b2);
ba->append(b3);
}
}
QByteArray formatString(const QByteArray &str)
void appendString(QByteArray *ba, const QByteArray &str, Endianness endian)
{
QByteArray ba = formatShort(str.size());
foreach (byte b, str)
ba.append(formatByte(b));
return ba;
const int n = str.size();
appendShort(ba, n, endian);
for (int i = 0; i != n; ++i)
ba->append(str.at(i));
}
QByteArray errorMessage(byte code)
......
......@@ -33,6 +33,7 @@
#include <QtCore/QByteArray>
#include <QtCore/QHash>
#include <QtCore/QString>
#include <QtCore/QVariant>
namespace trk {
......@@ -51,10 +52,17 @@ QString stringFromByte(byte c);
// produces "xx xx xx "
QString stringFromArray(const QByteArray &ba);
QByteArray formatByte(byte b);
QByteArray formatShort(ushort s);
QByteArray formatInt(uint i);
QByteArray formatString(const QByteArray &str);
enum Endianness
{
LittleEndian,
BigEndian,
TargetByteOrder = BigEndian,
};
void appendByte(QByteArray *ba, byte b);
void appendShort(QByteArray *ba, ushort s, Endianness = TargetByteOrder);
void appendInt(QByteArray *ba, uint i, Endianness = TargetByteOrder);
void appendString(QByteArray *ba, const QByteArray &str, Endianness = TargetByteOrder);
enum CodeMode
{
......@@ -62,6 +70,12 @@ enum CodeMode
ThumbMode,
};
enum TargetConstants
{
registerCount = 16,
memoryChunkSize = 256
};
struct Session
{
Session() {
......@@ -76,8 +90,11 @@ struct Session
tid = 0;
codeseg = 0;
dataseg = 0;
currentThread = 0;
}
// Trk feedback
byte cpuMajor;
byte cpuMinor;
byte bigEndian;
......@@ -90,6 +107,16 @@ struct Session
uint codeseg;
uint dataseg;
QHash<uint, uint> tokenToBreakpointIndex;
// Gdb request
uint currentThread;
};
struct SnapShot
{
uint registers[registerCount];
typedef QHash<uint, QByteArray> Memory;
Memory memory;
};
struct Breakpoint
......@@ -113,6 +140,7 @@ struct TrkResult
byte code;
byte token;
QByteArray data;
QVariant cookie;
};
// returns a QByteArray containing 0x01 0x90 <len> 0x7e encoded7d(ba) 0x7e
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment