Skip to content

Commit c4b9a8a

Browse files
Copilotxusheng6
andcommitted
Create separate TTDCoverageRenderLayer for user-controlled visibility
Co-authored-by: xusheng6 <[email protected]>
1 parent 5f4c46c commit c4b9a8a

File tree

3 files changed

+136
-29
lines changed

3 files changed

+136
-29
lines changed

ui/renderlayer.cpp

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
*/
1616

1717
#include "renderlayer.h"
18+
#include "ttdcoveragerenderlayer.h"
1819
#include "debuggerapi.h"
1920

2021
using namespace BinaryNinja;
@@ -35,7 +36,6 @@ void DebuggerRenderLayer::ApplyToBlock(Ref<BasicBlock> block, std::vector<Disass
3536

3637
uint64_t ipAddr = controller->IP();
3738
bool paused = controller->GetTargetStatus() == DebugAdapterPausedStatus;
38-
bool isTTD = controller->IsTTD();
3939

4040
for (auto& line : lines)
4141
{
@@ -45,7 +45,6 @@ void DebuggerRenderLayer::ApplyToBlock(Ref<BasicBlock> block, std::vector<Disass
4545

4646
bool hasPC = (line.addr == ipAddr) && paused;
4747
bool hasBreakpoint = controller->ContainsBreakpoint(line.addr);
48-
bool isExecuted = isTTD ? controller->IsInstructionExecuted(line.addr) : false;
4948

5049
if (hasPC && hasBreakpoint)
5150
{
@@ -128,18 +127,6 @@ void DebuggerRenderLayer::ApplyToBlock(Ref<BasicBlock> block, std::vector<Disass
128127
line.highlight.b = 0;
129128
line.highlight.alpha = 255;
130129
}
131-
else if (isExecuted)
132-
{
133-
// Highlight executed instructions with a green color
134-
line.highlight.style = StandardHighlightColor;
135-
line.highlight.color = GreenHighlightColor;
136-
line.highlight.mixColor = NoHighlightColor;
137-
line.highlight.mix = 0;
138-
line.highlight.r = 0;
139-
line.highlight.g = 0;
140-
line.highlight.b = 0;
141-
line.highlight.alpha = 64; // Light highlight
142-
}
143130
}
144131
}
145132

@@ -153,14 +140,12 @@ void DebuggerRenderLayer::ApplyToHighLevelILBody(Ref<Function> function, std::ve
153140

154141
uint64_t ipAddr = controller->IP();
155142
bool paused = controller->GetTargetStatus() == DebugAdapterPausedStatus;
156-
bool isTTD = controller->IsTTD();
157143

158144
for (auto& linearLine : lines)
159145
{
160146
DisassemblyTextLine& line = linearLine.contents;
161147
bool hasPC = (line.addr == ipAddr) && paused;
162148
bool hasBreakpoint = controller->ContainsBreakpoint(line.addr);
163-
bool isExecuted = isTTD ? controller->IsInstructionExecuted(line.addr) : false;
164149

165150
if (hasPC && hasBreakpoint)
166151
{
@@ -243,24 +228,15 @@ void DebuggerRenderLayer::ApplyToHighLevelILBody(Ref<Function> function, std::ve
243228
line.highlight.b = 0;
244229
line.highlight.alpha = 255;
245230
}
246-
else if (isExecuted)
247-
{
248-
// Highlight executed instructions with a green color
249-
line.highlight.style = StandardHighlightColor;
250-
line.highlight.color = GreenHighlightColor;
251-
line.highlight.mixColor = NoHighlightColor;
252-
line.highlight.mix = 0;
253-
line.highlight.r = 0;
254-
line.highlight.g = 0;
255-
line.highlight.b = 0;
256-
line.highlight.alpha = 64; // Light highlight
257-
}
258231
}
259232
}
260233

261234

262235
void RegisterRenderLayers()
263236
{
264237
static DebuggerRenderLayer* g_debuggerRenderLayer = new DebuggerRenderLayer();
238+
static TTDCoverageRenderLayer* g_ttdCoverageRenderLayer = new TTDCoverageRenderLayer();
239+
265240
RenderLayer::Register(g_debuggerRenderLayer, BNRenderLayerDefaultEnableState::AlwaysEnabledRenderLayerDefaultEnableState);
266-
}
241+
RenderLayer::Register(g_ttdCoverageRenderLayer, BNRenderLayerDefaultEnableState::DisabledRenderLayerDefaultEnableState);
242+
}

ui/ttdcoveragerenderlayer.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
Copyright 2020-2025 Vector 35 Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#include "ttdcoveragerenderlayer.h"
18+
#include "debuggerapi.h"
19+
20+
using namespace BinaryNinja;
21+
using namespace BinaryNinjaDebuggerAPI;
22+
23+
TTDCoverageRenderLayer::TTDCoverageRenderLayer(): RenderLayer("TTD Coverage")
24+
{
25+
26+
}
27+
28+
29+
void TTDCoverageRenderLayer::ApplyToBlock(Ref<BasicBlock> block, std::vector<DisassemblyTextLine>& lines)
30+
{
31+
Ref<BinaryView> bv = block->GetFunction()->GetView();
32+
DbgRef<DebuggerController> controller = DebuggerController::GetController(bv);
33+
if (!controller)
34+
return;
35+
36+
// Only apply TTD coverage highlighting if this is a TTD session
37+
if (!controller->IsTTD())
38+
return;
39+
40+
for (auto& line : lines)
41+
{
42+
// Do not highlight empty lines or comments
43+
if (line.tokens.empty() || (line.tokens[0].type == CommentToken))
44+
continue;
45+
46+
// Check if this instruction was executed during the TTD trace
47+
bool isExecuted = controller->IsInstructionExecuted(line.addr);
48+
49+
if (isExecuted)
50+
{
51+
// Highlight executed instructions with a green color
52+
line.highlight.style = StandardHighlightColor;
53+
line.highlight.color = GreenHighlightColor;
54+
line.highlight.mixColor = NoHighlightColor;
55+
line.highlight.mix = 0;
56+
line.highlight.r = 0;
57+
line.highlight.g = 0;
58+
line.highlight.b = 0;
59+
line.highlight.alpha = 64; // Light highlight
60+
}
61+
}
62+
}
63+
64+
65+
void TTDCoverageRenderLayer::ApplyToHighLevelILBody(Ref<Function> function, std::vector<LinearDisassemblyLine>& lines)
66+
{
67+
Ref<BinaryView> bv = function->GetView();
68+
DbgRef<DebuggerController> controller = DebuggerController::GetController(bv);
69+
if (!controller)
70+
return;
71+
72+
// Only apply TTD coverage highlighting if this is a TTD session
73+
if (!controller->IsTTD())
74+
return;
75+
76+
for (auto& linearLine : lines)
77+
{
78+
DisassemblyTextLine& line = linearLine.contents;
79+
80+
// Do not highlight empty lines or comments
81+
if (line.tokens.empty() || (line.tokens[0].type == CommentToken))
82+
continue;
83+
84+
// Check if this instruction was executed during the TTD trace
85+
bool isExecuted = controller->IsInstructionExecuted(line.addr);
86+
87+
if (isExecuted)
88+
{
89+
// Highlight executed instructions with a green color
90+
line.highlight.style = StandardHighlightColor;
91+
line.highlight.color = GreenHighlightColor;
92+
line.highlight.mixColor = NoHighlightColor;
93+
line.highlight.mix = 0;
94+
line.highlight.r = 0;
95+
line.highlight.g = 0;
96+
line.highlight.b = 0;
97+
line.highlight.alpha = 64; // Light highlight
98+
}
99+
}
100+
}

ui/ttdcoveragerenderlayer.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2020-2025 Vector 35 Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include "binaryninjaapi.h"
20+
21+
using namespace BinaryNinja;
22+
23+
24+
class TTDCoverageRenderLayer : public RenderLayer
25+
{
26+
public:
27+
TTDCoverageRenderLayer();
28+
29+
void ApplyToBlock(Ref<BasicBlock> block, std::vector<DisassemblyTextLine>& lines) override;
30+
void ApplyToHighLevelILBody(Ref<Function> function, std::vector<LinearDisassemblyLine> &lines) override;
31+
};

0 commit comments

Comments
 (0)