Skip to content

Commit 3c73b18

Browse files
author
Your Name
committed
Performance and fidelity improvements
1 parent d3c3ca8 commit 3c73b18

File tree

6 files changed

+71
-191
lines changed

6 files changed

+71
-191
lines changed

lightkeeper/src/main/java/lightkeeper/controller/Controller.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package lightkeeper.controller;
22

3-
import java.awt.Color;
43
import java.io.File;
54
import java.io.IOException;
65
import java.util.List;

lightkeeper/src/main/java/lightkeeper/controller/DisassemblyController.java

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package lightkeeper.controller;
22

3-
import java.awt.Color;
43
import java.math.BigInteger;
4+
import java.util.Collection;
55

66
import docking.widgets.fieldpanel.LayoutModel;
77
import docking.widgets.fieldpanel.listener.IndexMapper;
88
import docking.widgets.fieldpanel.listener.LayoutModelListener;
99
import generic.theme.GColor;
10-
import ghidra.app.decompiler.ClangLine;
1110
import ghidra.app.decompiler.ClangToken;
1211
import ghidra.app.decompiler.component.DecompilerPanel;
1312
import ghidra.app.decompiler.component.DecompilerUtils;
1413
import ghidra.app.plugin.core.decompile.DecompilerActionContext;
1514
import ghidra.app.plugin.core.decompile.DecompilerProvider;
16-
import ghidra.program.model.address.AddressRange;
1715
import ghidra.util.exception.CancelledException;
1816
import ghidra.util.task.Task;
1917
import ghidra.util.task.TaskLauncher;
@@ -59,31 +57,9 @@ public void dataChanged(BigInteger start, BigInteger end) {
5957
}
6058
}
6159

62-
public void updateCoverage(TaskMonitor monitor, DecompilerPanel dpanel) throws CancelledException {
63-
var api = plugin.getApi();
64-
if (api == null) {
65-
return;
66-
}
67-
68-
var program = api.getCurrentProgram();
69-
70-
for (ClangLine line : dpanel.getLines()) {
71-
for (ClangToken token : line.getAllTokens()) {
72-
monitor.checkCancelled();
73-
var address = DecompilerUtils.getClosestAddress(program, token);
74-
if (address == null) {
75-
continue;
76-
}
77-
for (AddressRange range : model.getModelData()) {
78-
monitor.checkCancelled();
79-
if (!range.contains(address)) {
80-
continue;
81-
}
82-
83-
token.setHighlight(this.color);
84-
}
85-
}
86-
}
60+
public void updateCoverage(TaskMonitor monitor, DecompilerPanel dpanel) {
61+
Collection<ClangToken> tokens = DecompilerUtils.getTokens(dpanel.getLayoutController().getRoot(), model.getModelData());
62+
tokens.stream().forEach(t -> t.setHighlight(this.color));
8763
}
8864

8965
public void updateCoverageTask(DecompilerPanel dpanel) {

lightkeeper/src/main/java/lightkeeper/model/coverage/CoverageModel.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import ghidra.program.model.address.AddressOverflowException;
1515
import ghidra.program.model.address.AddressRange;
1616
import ghidra.program.model.address.AddressRangeImpl;
17+
import ghidra.program.model.address.AddressSet;
1718
import ghidra.util.exception.CancelledException;
1819
import ghidra.util.task.TaskMonitor;
1920
import lightkeeper.LightKeeperPlugin;
@@ -22,10 +23,10 @@
2223
import lightkeeper.io.module.ModuleEntry;
2324
import lightkeeper.model.AbstractCoverageModel;
2425

25-
public class CoverageModel extends AbstractCoverageModel<DynamoRioFile, Set<AddressRange>> {
26+
public class CoverageModel extends AbstractCoverageModel<DynamoRioFile, AddressSet> {
2627
protected List<CoverageListRow> rows = new ArrayList<>();
2728
protected Map<DynamoRioFile, HashSet<AddressRange>> map = new HashMap<>();
28-
protected Set<AddressRange> ranges = new HashSet<>();
29+
protected AddressSet ranges = new AddressSet();
2930

3031
public CoverageModel(LightKeeperPlugin plugin) {
3132
super(plugin);
@@ -35,7 +36,7 @@ public CoverageModel(LightKeeperPlugin plugin) {
3536
public void clear(TaskMonitor monitor) throws CancelledException {
3637
rows = new ArrayList<>();
3738
map = new HashMap<>();
38-
ranges = new HashSet<>();
39+
ranges = new AddressSet();
3940
notifyUpdate(monitor);
4041
}
4142

@@ -93,7 +94,7 @@ protected Set<Integer> getSelectedModuleIds(List<ModuleEntry> selectedModules) {
9394
@Override
9495
public void update(TaskMonitor monitor) throws CancelledException, IOException {
9596
try {
96-
ranges = new HashSet<>();
97+
ranges = new AddressSet();
9798
for (CoverageListRow row : rows) {
9899
var state = row.getState();
99100
if (state == CoverageListState.IGNORED) {
@@ -140,7 +141,7 @@ public void update(TaskMonitor monitor) throws CancelledException, IOException {
140141
.map(r -> map.get(r.file)).flatMap(HashSet::stream).collect(Collectors.toSet());
141142

142143
added.removeAll(subtracted);
143-
ranges = added;
144+
added.stream().forEach(r -> ranges.add(r));
144145

145146
notifyUpdate(monitor);
146147
} catch (AddressOverflowException e) {
@@ -153,7 +154,7 @@ public List<CoverageListRow> getFileData() {
153154
}
154155

155156
@Override
156-
public Set<AddressRange> getModelData() {
157+
public AddressSet getModelData() {
157158
return ranges;
158159
}
159160
}

lightkeeper/src/main/java/lightkeeper/model/instruction/CoverageInstructionModel.java

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,51 @@
11
package lightkeeper.model.instruction;
22

3-
import java.util.HashSet;
4-
import java.util.Set;
5-
6-
import ghidra.program.model.address.AddressRange;
73
import ghidra.program.model.address.AddressRangeImpl;
4+
import ghidra.program.model.address.AddressSet;
85
import ghidra.util.exception.CancelledException;
96
import ghidra.util.task.TaskMonitor;
107
import lightkeeper.LightKeeperPlugin;
118
import lightkeeper.model.AbstractCoverageModel;
129
import lightkeeper.model.ICoverageModelListener;
1310
import lightkeeper.model.coverage.CoverageModel;
1411

15-
public class CoverageInstructionModel extends AbstractCoverageModel<Set<AddressRange>, Set<AddressRange>>
12+
public class CoverageInstructionModel extends AbstractCoverageModel<AddressSet, AddressSet>
1613
implements ICoverageModelListener {
1714
protected CoverageModel coverage;
18-
protected Set<AddressRange> modelRanges;
19-
protected Set<AddressRange> hits = new HashSet<>();
15+
protected AddressSet modelRanges;
16+
protected AddressSet hits = new AddressSet();
2017

2118
public CoverageInstructionModel(LightKeeperPlugin plugin, CoverageModel coverage) {
2219
super(plugin);
2320
this.coverage = coverage;
2421
}
2522

2623
@Override
27-
public void load(Set<AddressRange> ranges) {
24+
public void load(AddressSet ranges) {
2825
modelRanges = ranges;
2926
}
3027

3128
@Override
3229
public void update(TaskMonitor monitor) throws CancelledException {
33-
hits = new HashSet<>();
30+
hits = new AddressSet();
3431
if (modelRanges == null) {
3532
return;
3633
}
3734

38-
var api = plugin.getApi();
39-
var listing = api.getCurrentProgram().getListing();
40-
41-
for (AddressRange range : modelRanges) {
42-
monitor.checkCancelled();
43-
var iterator = listing.getInstructions(range.getMinAddress(), true);
44-
while (iterator.hasNext()) {
45-
var instruction = iterator.next();
46-
47-
if (instruction.getMaxAddress().compareTo(range.getMaxAddress()) > 0) {
48-
break;
49-
}
50-
51-
var instructionStart = instruction.getAddress();
52-
long length = instruction.getLength();
53-
if (length > 0) {
54-
length--;
55-
}
56-
var instructionEnd = instructionStart.add(length);
57-
AddressRange instructionRange = new AddressRangeImpl(instructionStart, instructionEnd);
58-
hits.add(instructionRange);
59-
}
60-
}
35+
var instructions = plugin.getApi().getCurrentProgram().getListing().getInstructions(modelRanges, true);
36+
instructions.forEach(i -> hits.add(new AddressRangeImpl(i.getMinAddress(), i.getMaxAddress())));
6137
notifyUpdate(monitor);
6238
}
6339

6440
@Override
6541
public void clear(TaskMonitor monitor) throws CancelledException {
6642
modelRanges = null;
67-
hits = new HashSet<>();
43+
hits = new AddressSet();
6844
notifyUpdate(monitor);
6945
}
7046

7147
@Override
72-
public Set<AddressRange> getModelData() {
48+
public AddressSet getModelData() {
7349
return hits;
7450
}
7551

0 commit comments

Comments
 (0)