Make AnalThread interruptable (Fix )

This commit is contained in:
Florian Märkl 2018-03-09 13:57:57 +01:00
parent d3e48cdae1
commit 051b95c69d
4 changed files with 39 additions and 3 deletions

View File

@ -9,7 +9,8 @@ AnalThread::AnalThread(OptionsDialog *parent) :
QThread(parent), QThread(parent),
level(2), level(2),
main(nullptr), main(nullptr),
core(CutterCore::getInstance()) core(CutterCore::getInstance()),
interrupted(false)
{ {
} }
@ -31,6 +32,17 @@ void AnalThread::start(MainWindow *main, int level, QList<QString> advanced)
QThread::start(); QThread::start();
} }
void AnalThread::interruptAndWait()
{
interrupted = true;
while(isRunning())
{
r_cons_singleton()->breaked = true;
r_sys_usleep(10000);
}
}
// run() will be called when a thread starts // run() will be called when a thread starts
void AnalThread::run() void AnalThread::run()
{ {
@ -40,6 +52,8 @@ void AnalThread::run()
ut64 loadaddr = 0LL; ut64 loadaddr = 0LL;
ut64 mapaddr = 0LL; ut64 mapaddr = 0LL;
interrupted = false;
// //
// Advanced Options // Advanced Options
// //
@ -106,7 +120,7 @@ void AnalThread::run()
} }
core->setBBSize(optionsDialog->getSelectedBBSize()); core->setBBSize(optionsDialog->getSelectedBBSize());
// use prj.simple as default as long as regular projects are broken // use prj.simple as default as long as regular projects are broken
core->setConfig("prj.simple", true); core->setConfig("prj.simple", true);

View File

@ -15,6 +15,9 @@ public:
~AnalThread(); ~AnalThread();
void start(MainWindow *main, int level, QList<QString> advanced); void start(MainWindow *main, int level, QList<QString> advanced);
void interruptAndWait();
bool isInterrupted() { return interrupted; }
protected: protected:
void run(); void run();
@ -29,6 +32,8 @@ private:
QList<QString> advanced; QList<QString> advanced;
MainWindow *main; MainWindow *main;
CutterCore *core; CutterCore *core;
bool interrupted;
}; };
#endif // ANALTHREAD_H #endif // ANALTHREAD_H

View File

@ -262,6 +262,12 @@ void OptionsDialog::on_okButton_clicked()
void OptionsDialog::anal_finished() void OptionsDialog::anal_finished()
{ {
if (analThread.isInterrupted())
{
done(0);
return;
}
ui->statusLabel->setText(tr("Loading interface")); ui->statusLabel->setText(tr("Loading interface"));
main->addOutput(tr(" > Analysis finished")); main->addOutput(tr(" > Analysis finished"));
@ -269,6 +275,15 @@ void OptionsDialog::anal_finished()
done(0); done(0);
} }
void OptionsDialog::closeEvent(QCloseEvent *event)
{
if (analThread.isRunning())
{
analThread.interruptAndWait();
}
event->accept();
}
QString OptionsDialog::analysisDescription(int level) QString OptionsDialog::analysisDescription(int level)
{ {
//TODO: replace this with meaningful descriptions //TODO: replace this with meaningful descriptions
@ -362,7 +377,6 @@ void OptionsDialog::on_pdbSelectButton_clicked()
void OptionsDialog::reject() void OptionsDialog::reject()
{ {
delete main;
done(0); done(0);
NewFileDialog *n = new NewFileDialog(nullptr); NewFileDialog *n = new NewFileDialog(nullptr);
n->show(); n->show();

View File

@ -40,6 +40,9 @@ private slots:
void anal_finished(); void anal_finished();
protected:
void closeEvent(QCloseEvent *event) override;
private: private:
AnalThread analThread; AnalThread analThread;
MainWindow *main; MainWindow *main;