Keep graph priority if the graph is empty (#734)

This commit is contained in:
xarkes 2018-09-30 19:46:36 +02:00 committed by GitHub
parent 1c69d62f4e
commit c3d029e5aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 15 deletions

View File

@ -1229,6 +1229,16 @@ QString CutterCore::getSimpleGraph(QString function)
return dot; return dot;
} }
void CutterCore::setGraphEmpty(bool empty)
{
emptyGraph = empty;
}
bool CutterCore::isGraphEmpty()
{
return emptyGraph;
}
void CutterCore::getOpcodes() void CutterCore::getOpcodes()
{ {
QString opcodes = cmd("?O"); QString opcodes = cmd("?O");

View File

@ -538,6 +538,8 @@ public:
QJsonDocument getFileVersionInfo(); QJsonDocument getFileVersionInfo();
QStringList getStats(); QStringList getStats();
QString getSimpleGraph(QString function); QString getSimpleGraph(QString function);
void setGraphEmpty(bool empty);
bool isGraphEmpty();
void getOpcodes(); void getOpcodes();
QList<QString> opcodes; QList<QString> opcodes;
@ -661,6 +663,8 @@ private:
RVA offsetPriorDebugging = RVA_INVALID; RVA offsetPriorDebugging = RVA_INVALID;
QErrorMessage msgBox; QErrorMessage msgBox;
bool emptyGraph = false;
QList<CutterPlugin*> plugins; QList<CutterPlugin*> plugins;
}; };

View File

@ -19,8 +19,7 @@ void CutterSeekableWidget::seek(RVA addr)
{ {
if (isInSyncWithCore) { if (isInSyncWithCore) {
Core()->seek(addr); Core()->seek(addr);
} } else {
else {
prevIdenpendentOffset = independentOffset; prevIdenpendentOffset = independentOffset;
independentOffset = addr; independentOffset = addr;
emit seekChanged(addr); emit seekChanged(addr);
@ -32,8 +31,7 @@ RVA CutterSeekableWidget::getOffset()
RVA addr; RVA addr;
if (isInSyncWithCore) { if (isInSyncWithCore) {
addr = Core()->getOffset(); addr = Core()->getOffset();
} } else {
else {
addr = independentOffset; addr = independentOffset;
} }
return addr; return addr;

View File

@ -168,10 +168,7 @@ void DisassemblerGraphView::loadCurrentGraph()
bool emptyGraph = functions.isEmpty(); bool emptyGraph = functions.isEmpty();
if (emptyGraph) { if (emptyGraph) {
// If there's no function to print, just move to disassembly and add a message // If there's no function to print, just add a message
if (Core()->getMemoryWidgetPriority() == CutterCore::MemoryWidgetType::Graph) {
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Disassembly);
}
if (!emptyText) { if (!emptyText) {
QVBoxLayout *layout = new QVBoxLayout(this); QVBoxLayout *layout = new QVBoxLayout(this);
emptyText = new QLabel(this); emptyText = new QLabel(this);
@ -184,6 +181,8 @@ void DisassemblerGraphView::loadCurrentGraph()
} else if (emptyText) { } else if (emptyText) {
emptyText->setVisible(false); emptyText->setVisible(false);
} }
// Refresh global "empty graph" variable so other widget know there is nothing to show here
Core()->setGraphEmpty(emptyGraph);
Analysis anal; Analysis anal;
anal.ready = true; anal.ready = true;
@ -707,7 +706,7 @@ void DisassemblerGraphView::seekInstruction(bool previous_instr)
continue; continue;
} }
// Found the instructon. Check if a next one exists // Found the instruction. Check if a next one exists
if (!previous_instr && (i < db->instrs.size() - 1)) { if (!previous_instr && (i < db->instrs.size() - 1)) {
seekable->seek(db->instrs[i + 1].addr); seekable->seek(db->instrs[i + 1].addr);
} else if (previous_instr && (i > 0)) { } else if (previous_instr && (i > 0)) {

View File

@ -108,7 +108,7 @@ class DisassemblerGraphView : public GraphView
public: public:
DisassemblerGraphView(QWidget *parent); DisassemblerGraphView(QWidget *parent);
~DisassemblerGraphView(); ~DisassemblerGraphView() override;
std::unordered_map<ut64, DisassemblyBlock> disassembly_blocks; std::unordered_map<ut64, DisassemblyBlock> disassembly_blocks;
virtual void drawBlock(QPainter &p, GraphView::GraphBlock &block) override; virtual void drawBlock(QPainter &p, GraphView::GraphBlock &block) override;
virtual void blockClicked(GraphView::GraphBlock &block, QMouseEvent *event, QPoint pos) override; virtual void blockClicked(GraphView::GraphBlock &block, QMouseEvent *event, QPoint pos) override;
@ -122,7 +122,7 @@ public:
void loadCurrentGraph(); void loadCurrentGraph();
QString windowTitle; QString windowTitle;
// bool navigate(ut64 addr); bool isGraphEmpty();
public slots: public slots:
void refreshView(); void refreshView();
@ -160,6 +160,7 @@ private:
int charHeight; int charHeight;
int charOffset; int charOffset;
int baseline; int baseline;
bool emptyGraph;
DisassemblyContextMenu *mMenu; DisassemblyContextMenu *mMenu;

View File

@ -125,7 +125,8 @@ DisassemblyWidget::DisassemblyWidget(MainWindow *main, QAction *action)
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot())); connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) { connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) {
if (visibility) { bool emptyGraph = (Core()->getMemoryWidgetPriority() == CutterCore::MemoryWidgetType::Graph && Core()->isGraphEmpty());
if (visibility && !emptyGraph) {
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Disassembly); Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Disassembly);
} }
}); });
@ -623,7 +624,8 @@ void DisassemblyWidget::on_seekChanged(RVA offset)
void DisassemblyWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type) void DisassemblyWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type)
{ {
if (type == CutterCore::MemoryWidgetType::Disassembly) { bool emptyGraph = (type == CutterCore::MemoryWidgetType::Graph && Core()->isGraphEmpty());
if (type == CutterCore::MemoryWidgetType::Disassembly || emptyGraph) {
raise(); raise();
setFocus(); setFocus();
} }

View File

@ -18,7 +18,8 @@ GraphWidget::GraphWidget(MainWindow *main, QAction *action) :
connect(Core(), &CutterCore::raisePrioritizedMemoryWidget, connect(Core(), &CutterCore::raisePrioritizedMemoryWidget,
this, [ = ](CutterCore::MemoryWidgetType type) { this, [ = ](CutterCore::MemoryWidgetType type) {
if (type == CutterCore::MemoryWidgetType::Graph) { bool emptyGraph = (type == CutterCore::MemoryWidgetType::Graph && Core()->isGraphEmpty());
if (type == CutterCore::MemoryWidgetType::Graph && !emptyGraph) {
this->raise(); this->raise();
this->graphView->setFocus(); this->graphView->setFocus();
} }