From 8f4d9ff4bd4c1c5bf6a010324dd295586308b496 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 12 Jun 2009 18:00:19 +0200 Subject: tidy things up --- examples/debuggee/debuggee.pro | 7 +++ examples/debuggee/example.qs | 17 ++++++++ examples/debuggee/foo.qs | 5 +++ examples/debuggee/main.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++ examples/debugger/debugger.pro | 7 +++ examples/debugger/main.cpp | 47 ++++++++++++++++++++ examples/examples.pro | 3 ++ 7 files changed, 184 insertions(+) create mode 100644 examples/debuggee/debuggee.pro create mode 100644 examples/debuggee/example.qs create mode 100644 examples/debuggee/foo.qs create mode 100644 examples/debuggee/main.cpp create mode 100644 examples/debugger/debugger.pro create mode 100644 examples/debugger/main.cpp create mode 100644 examples/examples.pro (limited to 'examples') diff --git a/examples/debuggee/debuggee.pro b/examples/debuggee/debuggee.pro new file mode 100644 index 0000000..5e9e631 --- /dev/null +++ b/examples/debuggee/debuggee.pro @@ -0,0 +1,7 @@ +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . +QT += network script scripttools +include(../../src/debuggerconnector.pri) +SOURCES += main.cpp diff --git a/examples/debuggee/example.qs b/examples/debuggee/example.qs new file mode 100644 index 0000000..1b545b6 --- /dev/null +++ b/examples/debuggee/example.qs @@ -0,0 +1,17 @@ +function bar() { + var x = 1; + var y = 2; + return x + y + test(x, y); +} + +function foo(a, b, c) { + var i = a + bar(); + var j = b - bar(); + var k = c * bar(); + return Math.cos(i) + Math.sin(j) - Math.atan(k); +} + +var first = foo(1, 2, 3); +var second = foo(4, 5, 6); +print("first was:", first, ", and second was:", second); + diff --git a/examples/debuggee/foo.qs b/examples/debuggee/foo.qs new file mode 100644 index 0000000..c7d511a --- /dev/null +++ b/examples/debuggee/foo.qs @@ -0,0 +1,5 @@ +function test(a, b) { + var c = a * b; + var d = Math.sin(c); + return d + 2; +} diff --git a/examples/debuggee/main.cpp b/examples/debuggee/main.cpp new file mode 100644 index 0000000..9167f54 --- /dev/null +++ b/examples/debuggee/main.cpp @@ -0,0 +1,98 @@ +#include +#include + +class MyObject : public QObject +{ + Q_OBJECT +public: + MyObject(const QHostAddress &addr, quint16 port, bool connect, QObject *parent = 0); +private slots: + void connected(); + void disconnected(); +private: + QScriptEngine *m_engine; + QScriptDebuggerConnector *m_connector; +}; + +MyObject::MyObject(const QHostAddress &addr, quint16 port, bool connect, QObject *parent) + : QObject(parent) +{ + m_engine = new QScriptEngine(this); + m_connector = new QScriptDebuggerConnector(this); + QObject::connect(m_connector, SIGNAL(connected()), this, SLOT(connected()), Qt::QueuedConnection); + QObject::connect(m_connector, SIGNAL(disconnected()), this, SLOT(disconnected()), Qt::QueuedConnection); + m_connector->setEngine(m_engine); + if (connect) { + qDebug("attempting to connect to debugger at %s:%d", qPrintable(addr.toString()), port); + m_connector->connectToDebugger(addr, port); + } else { + if (m_connector->listen(addr, port)) + qDebug("waiting for debugger to connect at %s:%d", qPrintable(addr.toString()), port); + else { + qWarning("Failed to listen!"); + QCoreApplication::quit(); + } + } +} + +void MyObject::connected() +{ + qDebug("connected!!"); + QStringList fileNames; + QString path = QDir::currentPath(); + fileNames << (path + QDir::separator() + "foo.qs") + << (path + QDir::separator() + "example.qs"); + for (int i = 0; i < fileNames.size(); ++i) { + QString fn = fileNames.at(i); + QFile file(fn); + file.open(QIODevice::ReadOnly); + QString program = file.readAll(); + qDebug("calling evaluate"); + m_engine->evaluate(program, fn); + qDebug("evaluate done"); + } + m_connector->disconnectFromDebugger(); +} + +void MyObject::disconnected() +{ + qDebug("disconnected"); + QCoreApplication::quit(); +} + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + QHostAddress addr(QHostAddress::LocalHost); + quint16 port = 2000; + bool connect = false; + for (int i = 1; i < argc; ++i) { + QString arg(argv[i]); + arg = arg.trimmed(); + if(arg.startsWith("--")) { + QString opt; + QString val; + int split = arg.indexOf("="); + if(split > 0) { + opt = arg.mid(2).left(split-2); + val = arg.mid(split + 1).trimmed(); + } else { + opt = arg.mid(2); + } + if (opt == QLatin1String("address")) + addr.setAddress(val); + else if (opt == QLatin1String("port")) + port = val.toUShort(); + else if (opt == QLatin1String("connect")) + connect = true; + else if (opt == QLatin1String("help")) { + fprintf(stdout, "Usage: debuggee --address=ADDR --port=NUM [--connect]\n"); + return(0); + } + } + } + MyObject obj(addr, port, connect); + return app.exec(); +} + +#include "main.moc" diff --git a/examples/debugger/debugger.pro b/examples/debugger/debugger.pro new file mode 100644 index 0000000..bbb289b --- /dev/null +++ b/examples/debugger/debugger.pro @@ -0,0 +1,7 @@ +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . +QT += script scripttools network +include(../../src/remotetargetdebugger.pri) +SOURCES += main.cpp diff --git a/examples/debugger/main.cpp b/examples/debugger/main.cpp new file mode 100644 index 0000000..3d21995 --- /dev/null +++ b/examples/debugger/main.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include "qscriptremotetargetdebugger.h" + +void qScriptDebugRegisterMetaTypes(); + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + QHostAddress addr(QHostAddress::LocalHost); + quint16 port = 2000; + bool listen = false; + for (int i = 1; i < argc; ++i) { + QString arg(argv[i]); + arg = arg.trimmed(); + if(arg.startsWith("--")) { + QString opt; + QString val; + int split = arg.indexOf("="); + if(split > 0) { + opt = arg.mid(2).left(split-2); + val = arg.mid(split + 1).trimmed(); + } else { + opt = arg.mid(2); + } + if (opt == QLatin1String("address")) + addr.setAddress(val); + else if (opt == QLatin1String("port")) + port = val.toUShort(); + else if (opt == QLatin1String("listen")) + listen = true; + else if (opt == QLatin1String("help")) { + fprintf(stdout, "Usage: remote --address=ADDR --port=NUM [--listen]\n"); + return(-1); + } + } + } + + qScriptDebugRegisterMetaTypes(); + QScriptRemoteTargetDebugger debugger; + qDebug("attaching to %s:%d", qPrintable(addr.toString()), port); + debugger.attachTo(addr, port); + + return app.exec(); +} diff --git a/examples/examples.pro b/examples/examples.pro new file mode 100644 index 0000000..043eba0 --- /dev/null +++ b/examples/examples.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = debugger \ + debuggee -- cgit v1.2.3