summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Keller <rainer.keller@digia.com>2013-10-17 16:47:33 +0200
committerRainer Keller <rainer.keller@digia.com>2013-10-17 17:45:15 +0300
commitc7ff23c24a2ee2daf412efb6c4b80a3dd125db6d (patch)
tree6be68857e13f2b50696ed4b4bc4f3c58c3a0220c
parent0e15c6823e88b43d7415908f4f1621f8e33e4ea2 (diff)
Analyze binary if start failsv1.0.0-RC5v1.0.0-RC4v1.0.0
In case the binary does not start successfully some checks are done to find out what may be wrong. Change-Id: I01e466482b2847068227d9469b9d99dc33f7f9eb Reviewed-by: Rainer Keller <rainer.keller@digia.com>
-rw-r--r--process.cpp55
-rw-r--r--process.h1
2 files changed, 53 insertions, 3 deletions
diff --git a/process.cpp b/process.cpp
index 990f5ba..21cfb55 100644
--- a/process.cpp
+++ b/process.cpp
@@ -7,6 +7,7 @@
#include <sys/socket.h>
#include <signal.h>
#include <fcntl.h>
+#include <QFileInfo>
static int pipefd[2];
@@ -15,6 +16,53 @@ static void signalhandler(int)
write(pipefd[1], " ", 1);
}
+static bool analyzeBinary(const QString &binary)
+{
+ QFileInfo fi(binary);
+ if (!fi.exists()) {
+ printf("Binary does not exist.\n");
+ return false;
+ }
+ if (!fi.isFile()) {
+ printf("Binary is not a file.\n");
+ return false;
+ }
+ if (!fi.isReadable()) {
+ printf("Binary is not readable.\n");
+ return false;
+ }
+ if (!fi.isExecutable()) {
+ printf("Binary is not executable.\n");
+ return false;
+ }
+
+ if (fi.size() < 4) {
+ printf("Binary is smaller than 4 bytes.\n");
+ return false;
+ }
+
+ QFile f(binary);
+ if (!f.open(QFile::ReadOnly)) {
+ printf("Could not open binary to analyze.\n");
+ return false;
+ }
+
+ QByteArray elfHeader = f.read(4);
+ f.close();
+
+ if (elfHeader.size() < 4) {
+ printf("Failed to read ELF header.\n");
+ return false;
+ }
+
+ if (elfHeader != QByteArray::fromHex("7f454C46")) { // 0x7f ELF
+ printf("Binary is not an ELF file.\n");
+ return false;
+ }
+
+ return true;
+}
+
Process::Process()
: QObject(0)
, mProcess(new QProcess(this))
@@ -81,6 +129,7 @@ void Process::error(QProcess::ProcessError error)
switch (error) {
case QProcess::FailedToStart:
printf("Failed to start\n");
+ analyzeBinary(mBinary);
break;
case QProcess::Crashed:
printf("Crashed\n");
@@ -125,10 +174,10 @@ void Process::startup(QStringList args)
args.append(mConfig.args);
mProcess->setProcessEnvironment(pe);
- QString binary = args.first();
+ mBinary = args.first();
args.removeFirst();
- qDebug() << binary << args;
- mProcess->start(binary, args);
+ qDebug() << mBinary << args;
+ mProcess->start(mBinary, args);
}
void Process::start(const QStringList &args)
diff --git a/process.h b/process.h
index 767cc95..3ce5d96 100644
--- a/process.h
+++ b/process.h
@@ -49,4 +49,5 @@ private:
int mDebuggee;
bool mDebug;
Config mConfig;
+ QString mBinary;
};