Skip to content

Commit 75fc20f

Browse files
xusheng6claude
andauthored
Fix #984: Refresh view after TTD coverage analysis completes (#986)
* Fix #984: Refresh view after TTD coverage analysis completes - Pass UIContext to TTDAnalysisDialog for proper view access - Add refreshViewAndEnableRenderLayer() method to refresh view - Call refresh after analysis completes and after loading results - Verify TTD Coverage render layer is registered This makes coverage highlights visible immediately after analysis, assuming the user has the TTD Coverage render layer enabled. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Make TTD Coverage render layer always enabled with fast path - Change render layer registration to AlwaysEnabled instead of DisabledByDefault - Add early return check: if GetExecutedInstructionCount() == 0, return immediately - This makes the layer have zero overhead when there's no coverage data - Simplify refreshViewAndEnableRenderLayer() method With these changes: - Users don't need to manually enable the render layer - Coverage is visible immediately after analysis completes - No performance impact when coverage data is not loaded - Works across all views (linear, graph, etc.) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Various fixes --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 02692b5 commit 75fc20f

5 files changed

Lines changed: 39 additions & 5 deletions

File tree

ui/renderlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,5 +405,5 @@ void RegisterRenderLayers()
405405
static TTDCoverageRenderLayer* g_ttdCoverageRenderLayer = new TTDCoverageRenderLayer();
406406

407407
RenderLayer::Register(g_debuggerRenderLayer, BNRenderLayerDefaultEnableState::AlwaysEnabledRenderLayerDefaultEnableState);
408-
RenderLayer::Register(g_ttdCoverageRenderLayer, BNRenderLayerDefaultEnableState::DisabledByDefaultRenderLayerDefaultEnableState);
408+
RenderLayer::Register(g_ttdCoverageRenderLayer, BNRenderLayerDefaultEnableState::EnabledByDefaultRenderLayerDefaultEnableState);
409409
}

ui/ttdanalysisdialog.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ limitations under the License.
2222
#include <QJsonDocument>
2323
#include <QJsonObject>
2424
#include <QApplication>
25+
#include "uicontext.h"
26+
#include "linearview.h"
2527

2628
TTDAnalysisWorker::TTDAnalysisWorker(DbgRef<DebuggerController> controller, TTDAnalysisType type, QObject* parent)
2729
: QThread(parent), m_controller(controller), m_analysisType(type), m_useRange(false), m_startAddress(0), m_endAddress(0)
@@ -91,8 +93,8 @@ void TTDAnalysisWorker::run()
9193
emit analysisCompleted(success, message, resultCount);
9294
}
9395

94-
TTDAnalysisDialog::TTDAnalysisDialog(BinaryViewRef data, QWidget* parent)
95-
: QDialog(parent), m_data(data), m_currentWorker(nullptr)
96+
TTDAnalysisDialog::TTDAnalysisDialog(UIContext* context, BinaryViewRef data, QWidget* parent)
97+
: QDialog(parent), m_context(context), m_data(data), m_currentWorker(nullptr)
9698
{
9799
m_controller = DebuggerController::GetController(data);
98100

@@ -550,6 +552,11 @@ void TTDAnalysisDialog::onAnalysisCompleted(bool success, const QString& message
550552
{
551553
QMessageBox::warning(this, "Analysis Failed", message);
552554
}
555+
else
556+
{
557+
// Refresh the view to make coverage visible immediately
558+
refreshView();
559+
}
553560
}
554561

555562
void TTDAnalysisDialog::onSaveResults()
@@ -591,6 +598,9 @@ void TTDAnalysisDialog::onLoadResults()
591598

592599
populateAnalysisList();
593600
QMessageBox::information(this, "Load Results", "Analysis results loaded successfully");
601+
602+
// Refresh the view to show the loaded coverage
603+
refreshView();
594604
}
595605
else
596606
{
@@ -774,3 +784,15 @@ bool TTDAnalysisDialog::loadAnalysisResults(TTDAnalysisResult& result)
774784

775785
return true;
776786
}
787+
788+
void TTDAnalysisDialog::refreshView()
789+
{
790+
// Use the stored UI context to refresh the view
791+
if (!m_context)
792+
return;
793+
794+
// Refresh the current view contents to show the coverage immediately
795+
// The TTD Coverage render layer is always enabled and will automatically
796+
// display coverage highlights when coverage data is available
797+
m_context->refreshCurrentViewContents();
798+
}

ui/ttdanalysisdialog.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ limitations under the License.
3434
#include <QThread>
3535
#include <QMutex>
3636
#include "binaryninjaapi.h"
37+
#include "uicontext.h"
38+
#include "viewframe.h"
3739
#include "debuggerapi.h"
3840
#include <uitypes.h>
3941

@@ -94,7 +96,7 @@ class TTDAnalysisDialog : public QDialog
9496
Q_OBJECT
9597

9698
public:
97-
TTDAnalysisDialog(BinaryViewRef data, QWidget* parent = nullptr);
99+
TTDAnalysisDialog(UIContext* context, BinaryViewRef data, QWidget* parent = nullptr);
98100
~TTDAnalysisDialog();
99101

100102
private slots:
@@ -115,7 +117,9 @@ private slots:
115117
QString getDefaultCachePath(TTDAnalysisType type);
116118
bool saveAnalysisResults(const TTDAnalysisResult& result);
117119
bool loadAnalysisResults(TTDAnalysisResult& result);
120+
void refreshView();
118121

122+
UIContext* m_context;
119123
BinaryViewRef m_data;
120124
DbgRef<DebuggerController> m_controller;
121125

ui/ttdcoveragerenderlayer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ void TTDCoverageRenderLayer::ApplyToBlock(Ref<BasicBlock> block, std::vector<Dis
3737
if (!controller->IsTTD())
3838
return;
3939

40+
// Quick check: if no coverage data has been loaded, return immediately
41+
if (controller->GetExecutedInstructionCount() == 0)
42+
return;
43+
4044
for (auto& line : lines)
4145
{
4246
// Do not highlight empty lines or comments
@@ -76,6 +80,10 @@ void TTDCoverageRenderLayer::ApplyToHighLevelILBody(Ref<Function> function, std:
7680
if (!controller->IsTTD())
7781
return;
7882

83+
// Quick check: if no coverage data has been loaded, return immediately
84+
if (controller->GetExecutedInstructionCount() == 0)
85+
return;
86+
7987
for (auto& linearLine : lines)
8088
{
8189
DisassemblyTextLine& line = linearLine.contents;

ui/ui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ void GlobalDebuggerUI::SetupMenu(UIContext* context)
14221422
if (!controller || !controller->IsTTD())
14231423
return;
14241424

1425-
auto dialog = new TTDAnalysisDialog(ctxt.binaryView, nullptr);
1425+
auto dialog = new TTDAnalysisDialog(ctxt.context, ctxt.binaryView, nullptr);
14261426
dialog->show();
14271427
dialog->raise();
14281428
dialog->activateWindow();

0 commit comments

Comments
 (0)