From 023e2a0737ec5e88b5980543bcf718f9fdd9ca8a Mon Sep 17 00:00:00 2001
From: Paolo Greppi <paolo.greppi@unige.it>
Date: Tue, 3 Apr 2012 14:55:56 +0200
Subject: [PATCH] patch GdbInjector, add a couple of asserts

---
 hooqInjector/GdbInjector.cpp      |   43 +++++++++++++++++++------------------
 hooqInjector/RemoteConnection.cpp |    2 +
 hooqInjector/RemotePlayback.cpp   |    1 +
 3 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/hooqInjector/GdbInjector.cpp b/hooqInjector/GdbInjector.cpp
index a390601..68fc458 100644
--- a/hooqInjector/GdbInjector.cpp
+++ b/hooqInjector/GdbInjector.cpp
@@ -92,27 +92,28 @@ void GdbInjector::startProcess()
 	Q_ASSERT(m_gdb->state() == QProcess::Running);
 	Q_ASSERT(m_gdb->isWritable());
 	m_gdbStream.setDevice(m_gdb);
-	m_gdbStream << "set auto-solib-add off" << endl; // avoid loading symbols for shared libraries
-	                                                 // that we do not need to interact with from GDB
-	m_gdbStream << "break _start" << endl; // C entry point - after main libraries have been loaded
-	m_gdbStream << "set args" << argumentsString << endl;
-	m_gdbStream << "run" << endl; // run until we hit it, and therefore Qt shared libraries are loaded
-	m_gdbStream << "sharedlibrary libdl" << endl; // load the libdl library so that we can call __dlopen()
-	m_gdbStream << "sharedlibrary libc" << endl;  // load the libc library so that we can call __dlopen()
-	m_gdbStream << "sharedlibrary libQtCore" << endl; // load QtCore for breaking on QCoreApplication::exec()
-	m_gdbStream << "break QCoreApplication::exec()" << endl; // now, we can set this breakpoint...
-	m_gdbStream << "continue" << endl;
-
-	// Newer systems
-	m_gdbStream << QString("call dlopen(\"%1\", %2)").arg(libraryPath()).arg(QString::number(RTLD_NOW)) << endl; // load our library
-	// Older systems
-	m_gdbStream << QString("call __dlopen(\"%1\", %2)").arg(libraryPath()).arg(QString::number(RTLD_NOW)) << endl; // load our library
-
-	m_gdbStream << "sharedlibrary injectedHooq" << endl; // load the hooq injector library so that we can call startHooq()
-	m_gdbStream << "call startHooq()" << endl; // install our plugin (which required QCoreApplication setup)
-	m_gdbStream << "continue" << endl; // run the app
-	m_gdbStream << "backtrace" << endl; // just in case (use with --spam)
-	m_gdbStream << "quit" << endl; // after the application has exited, quit gdb
+        m_gdbStream << "set breakpoint pending on" << endl;
+        m_gdbStream << "set auto-solib-add off" << endl; // avoid loading symbols for shared libraries
+                                                         // that we do not need to interact with from GDB
+        m_gdbStream << "break _start" << endl; // C entry point - after main libraries have been loaded
+        m_gdbStream << "set args" << argumentsString << endl;
+        m_gdbStream << "run" << endl; // run until we hit it, and therefore Qt shared libraries are loaded
+        m_gdbStream << "sharedlibrary libdl" << endl; // load the libdl library so that we can call __dlopen()
+        m_gdbStream << "sharedlibrary libc" << endl;  // load the libc library so that we can call __dlopen()
+        //m_gdbStream << QString("call dlopen(\"/usr/lib64/libQtCore.so.4\",%1)").arg(QString::number(RTLD_NOW)) << endl;
+        // Newer systems
+        m_gdbStream << QString("call dlopen(\"%1\", %2)").arg(libraryPath()).arg(QString::number(RTLD_NOW)) << endl; // load our library
+        // Older systems
+        m_gdbStream << QString("call __dlopen(\"%1\", %2)").arg(libraryPath()).arg(QString::number(RTLD_NOW)) << endl; // load our library
+        m_gdbStream << "sharedlibrary libQtCore" << endl; // load QtCore for breaking on QCoreApplication::exec()
+        m_gdbStream << "sharedlibrary libQtGui" << endl; // load QtCore for breaking on QCoreApplication::exec()
+        m_gdbStream << "break QCoreApplication::exec" << endl; // now, we can set this breakpoint...
+        m_gdbStream << "continue" << endl;
+        m_gdbStream << "sharedlibrary injectedHooq" << endl; // load the hooq injector library so that we can call startHooq()
+        m_gdbStream << "call startHooq()" << endl; // install our plugin (which required QCoreApplication setup)
+        m_gdbStream << "continue" << endl; // run the app
+        m_gdbStream << "backtrace" << endl; // just in case (use with --spam)
+        m_gdbStream << "quit" << endl; // after the application has exited, quit gdb
 }
 
 void GdbInjector::attach(Q_PID processId)
diff --git a/hooqInjector/RemoteConnection.cpp b/hooqInjector/RemoteConnection.cpp
index 93fccb6..d3c443e 100644
--- a/hooqInjector/RemoteConnection.cpp
+++ b/hooqInjector/RemoteConnection.cpp
@@ -63,6 +63,8 @@ void RemoteConnection::start(const QString& application, const QStringList& argu
 
 void RemoteConnection::acceptConnection()
 {
+        Q_ASSERT(m_localServer != NULL);
+        Q_ASSERT(m_localServer->hasPendingConnections()); 
 	emit connected(m_localServer->nextPendingConnection());
 }
 
diff --git a/hooqInjector/RemotePlayback.cpp b/hooqInjector/RemotePlayback.cpp
index dc61b24..ac82aca 100644
--- a/hooqInjector/RemotePlayback.cpp
+++ b/hooqInjector/RemotePlayback.cpp
@@ -52,6 +52,7 @@ void RemotePlayback::startPlayback(QTcpSocket* socket)
 {
 	delete m_socket;
 	m_socket = socket;
+        Q_ASSERT(m_socket!= NULL);
 	Q_ASSERT(m_socket->state() == QTcpSocket::ConnectedState && m_socket->isWritable() && m_socket->isOpen());
 	m_socket->write("PLAY\n");
 	m_socket->write(m_log->readAll());
-- 
1.7.9.1

