Commit 88617fd2 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

TRK: Stabilize on Windows, introduce perl script for portability

parent d0457b70
......@@ -29,6 +29,7 @@
#include "trkutils.h"
#include <QtCore/QPointer>
#include <QtCore/QCoreApplication>
#include <QtCore/QQueue>
#include <QtCore/QTimer>
......@@ -239,11 +240,12 @@ private:
void sendGdbMessage(const QByteArray &msg, const QByteArray &logNote = QByteArray());
void sendGdbMessageAfterSync(const QByteArray &msg, const QByteArray &logNote = QByteArray());
void sendGdbAckMessage();
bool sendGdbPacket(const QByteArray &packet, bool doFlush);
void logMessage(const QString &msg, bool force = false);
QTcpServer m_gdbServer;
QTcpSocket *m_gdbConnection;
QPointer<QTcpSocket> m_gdbConnection;
QString m_gdbServerName;
quint16 m_gdbServerPort;
QByteArray m_gdbReadBuffer;
......@@ -425,14 +427,28 @@ void Adapter::readFromGdb()
}
}
bool Adapter::sendGdbPacket(const QByteArray &packet, bool doFlush)
{
if (!m_gdbConnection || m_gdbConnection->state() != QAbstractSocket::ConnectedState) {
logMessage(QString::fromLatin1("Cannot write to gdb: Not connected (%1)").arg(QString::fromLatin1(packet)), true);
return false;
}
if (m_gdbConnection->write(packet) == -1) {
logMessage(QString::fromLatin1("Cannot write to gdb: %1 (%2)").arg(m_gdbConnection->errorString()).arg(QString::fromLatin1(packet)), true);
return false;
}
if (doFlush)
m_gdbConnection->flush();
return true;
}
void Adapter::sendGdbAckMessage()
{
if (!m_gdbAckMode)
return;
QByteArray packet = "+";
logMessage("gdb: <- " + packet);
m_gdbConnection->write(packet);
//m_gdbConnection->flush();
sendGdbPacket(packet, false);
}
void Adapter::sendGdbMessage(const QByteArray &msg, const QByteArray &logNote)
......@@ -453,11 +469,9 @@ void Adapter::sendGdbMessage(const QByteArray &msg, const QByteArray &logNote)
packet.append(checkSum);
int pad = qMax(0, 24 - packet.size());
logMessage("gdb: <- " + packet + QByteArray(pad, ' ') + logNote);
m_gdbConnection->write(packet);
m_gdbConnection->flush();
sendGdbPacket(packet, true);
}
void Adapter::sendGdbMessageAfterSync(const QByteArray &msg, const QByteArray &logNote)
{
QByteArray ba = msg + char(1) + logNote;
......@@ -532,7 +546,7 @@ void Adapter::handleGdbResponse(const QByteArray &response)
else if (response.startsWith("D")) {
sendGdbAckMessage();
sendGdbMessage("OK", "shutting down");
qApp->exit(1);
qApp->quit();
}
else if (response == "g") {
......
#!/usr/bin/perl -w
use strict;
use English; # gives us $OSNAME
use File::Temp;
use File::Spec;
use Cwd;
my @ADAPTER_OPTIONS = ();
my @TRKSERVEROPTIONS = ();
my $DUMP_POSTFIX ='-BigEndian.bin';
my $ENDIANESS ='big';
my $isUnix = $OSNAME eq 'linux' ? 1 : 0;
my $MAKE= $isUnix ? 'make' : 'nmake';
my $trkservername;
my $runTrkServer = 1;
my $usage=<<EOF;
Usage: run.pl -av -aq -tv -tq -l [COM]
Options:
-av Adapter verbose
-aq Adapter quiet
-tv TrkServer verbose
-tq TrkServer quiet
-l Little endian
trkserver simulator will be run unless COM is specified
EOF
# ------- Parse arguments
my $argCount = scalar(@ARGV);
for (my $i = 0; $i < $argCount; $i++) {
my $a = $ARGV[$i];
if ($a =~ /^-/) {
if ($a eq '-av') {
push(@ADAPTER_OPTIONS, '-v');
} elsif ($a eq '-aq') {
push(@ADAPTER_OPTIONS, '-q');
} elsif ($a eq '-tv') {
push(@TRKSERVEROPTIONS, '-v');
} elsif ($a eq '-tq') {
push(@TRKSERVEROPTIONS, '-q');
} elsif ($a eq '-l') {
$DUMP_POSTFIX='.bin';
$ENDIANESS='little';
push(@ADAPTER_OPTIONS, '-l');
} elsif ($a eq '-h') {
print $usage;
exit(1);
}
} else {
$trkservername = $a;
$runTrkServer = 0;
}
}
# ------- Ensure build is up to date
print "### Building\n";
system($MAKE);
die('Make failed: ' . $!) unless $? == 0;
if ($isUnix != 0) {
system('killall', '-s', 'USR1', 'adapter', 'trkserver');
system('killall', 'adapter', 'trkserver');
}
my $userid=$>;
$trkservername = ('TRKSERVER-' . $userid) unless defined $trkservername;
my $gdbserverip= '127.0.0.1';
my $gdbserverport= 2222 + $userid;
system('fuser', '-n', 'tcp', '-k', $gdbserverport) if ($isUnix);
# Who writes that?
my $tempFile = File::Spec->catfile(File::Temp::tempdir(), $trkservername);
unlink ($tempFile) if -f $tempFile;
# ------- Launch trkserver
if ($runTrkServer) {
my $MEMORYDUMP='TrkDump-78-6a-40-00' . $DUMP_POSTFIX;
my @ADDITIONAL_DUMPS=('0x00402000' . $DUMP_POSTFIX, '0x786a4000' . $DUMP_POSTFIX, '0x00600000' . $DUMP_POSTFIX);
my @TRKSERVER_ARGS;
if ($isUnix) {
push(@TRKSERVER_ARGS, File::Spec->catfile(File::Spec->curdir(), 'trkserver'));
} else {
push(@TRKSERVER_ARGS, 'cmd.exe', '/c', 'start', File::Spec->catfile(File::Spec->curdir(), 'debug', 'trkserver.exe'));
}
push(@TRKSERVER_ARGS, @TRKSERVEROPTIONS, $trkservername, $MEMORYDUMP, @ADDITIONAL_DUMPS);
print '### Executing: ', join(' ', @TRKSERVER_ARGS), "\n";
my $trkserverpid = fork();
if ($trkserverpid == 0) {
exec(@TRKSERVER_ARGS);
exit(0);
}
push(@ADAPTER_OPTIONS, '-s');
sleep(1);
}
# ------- Launch adapter
my @ADAPTER_ARGS;
if ($isUnix) {
push(@ADAPTER_ARGS, File::Spec->catfile(File::Spec->curdir(), 'adapter'));
} else {
push(@ADAPTER_ARGS, 'cmd.exe', '/c', 'start', File::Spec->catfile(File::Spec->curdir(), 'debug', 'adapter.exe'));
}
push(@ADAPTER_ARGS, @ADAPTER_OPTIONS, $trkservername, $gdbserverip . ':' . $gdbserverport);
print '### Executing: ', join(' ', @ADAPTER_ARGS), "\n";
my $adapterpid=fork();
if ($adapterpid == 0) {
exec(@ADAPTER_ARGS);
exit(0);
}
# ------- Write out .gdbinit
my $gdbInit = <<EOF;
# This is generated. Changes will be lost.
#set remote noack-packet on
set confirm off
set endian $ENDIANESS
#set debug remote 1
#target remote $gdbserverip:$gdbserverport
target extended-remote $gdbserverip:$gdbserverport
#file filebrowseapp.sym
add-symbol-file filebrowseapp.sym 0x786A4000
symbol-file filebrowseapp.sym
p E32Main
#continue
#info files
#file filebrowseapp.sym -readnow
#add-symbol-file filebrowseapp.sym 0x786A4000
EOF
my $gdbInitFile = '.gdbinit';
print '### Writing: ',$gdbInitFile, "\n";
open (GDB_INIT, '>' . $gdbInitFile) or die ('Cannot write to ' . $gdbInitFile . ' ' . $!);
print GDB_INIT $gdbInit;
close( GDB_INIT);
#!/bin/sh
ADAPTER_OPTIONS="-s"
TRKSERVEROPTIONS=""
DUMP_POSTFIX='-BigEndian.bin'
ENDIANESS='big'
while expr " $1" : " -.*" >/dev/null
do
if [ " $1" = " -av" ]
then
ADAPTER_OPTIONS="$ADAPTER_OPTIONS -v"
elif [ " $1" = " -aq" ]
then
ADAPTER_OPTIONS="$ADAPTER_OPTIONS -q"
elif [ " $1" = " -tv" ]
then
TRKSERVEROPTIONS="$TRKSERVEROPTIONS -v"
elif [ " $1" = " -tq" ]
then
TRKSERVEROPTIONS="$TRKSERVEROPTIONS -q"
elif [ " $1" = " -l" ]
then
DUMP_POSTFIX='.bin'
ENDIANESS='little'
ADAPTER_OPTIONS="$ADAPTER_OPTIONS -l"
fi
shift 1
done
make || exit 1
killall -s USR1 adapter trkserver > /dev/null 2>&1
killall adapter trkserver > /dev/null 2>&1
userid=`id -u`
trkservername="TRKSERVER-${userid}";
gdbserverip=127.0.0.1
gdbserverport=$[2222 + ${userid}]
fuser -n tcp -k ${gdbserverport}
rm /tmp/${trkservername}
MEMORYDUMP="TrkDump-78-6a-40-00$DUMP_POSTFIX"
ADDITIONAL_DUMPS="0x00402000$DUMP_POSTFIX 0x786a4000$DUMP_POSTFIX 0x00600000$DUMP_POSTFIX"
./trkserver $TRKSERVEROPTIONS ${trkservername} ${MEMORYDUMP} ${ADDITIONAL_DUMPS}&
trkserverpid=$!
sleep 1
./adapter $ADAPTER_OPTIONS ${trkservername} ${gdbserverip}:${gdbserverport} &
adapterpid=$!
echo "# This is generated. Changes will be lost.
#set remote noack-packet on
set confirm off
set endian $ENDIANESS
#set debug remote 1
#target remote ${gdbserverip}:${gdbserverport}
target extended-remote ${gdbserverip}:${gdbserverport}
#file filebrowseapp.sym
add-symbol-file filebrowseapp.sym 0x786A4000
symbol-file filebrowseapp.sym
p E32Main
#continue
#info files
#file filebrowseapp.sym -readnow
#add-symbol-file filebrowseapp.sym 0x786A4000
" > .gdbinit
#kill -s USR1 ${adapterpid}
#kill -s USR1 ${trkserverpid}
#killall arm-gdb
......@@ -2,6 +2,7 @@
TEMPLATE = app
QT = core network
win32:CONFIG+=console
HEADERS += \
trkutils.h
......
Markdown is supported
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