Skip to content

Commit

Permalink
Merge pull request #125 from mike-hunhoff:fix/upstream/123
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 617758211
Change-Id: I82e5a52383072420d2b389742c10c53b616bcff7
  • Loading branch information
copybara-github committed Mar 21, 2024
2 parents c55f264 + f71001c commit 605d9de
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public BinExport2Builder setPrependNamespace(boolean isPrepended) {
return this;
}

private Address getAddressFromLong(long offset) {
return program.getAddressFactory().getDefaultAddressSpace().getAddress(offset);
}

private long getMappedAddress(Address address) {
return address.getOffset() - addressOffset;
}
Expand Down Expand Up @@ -407,6 +411,26 @@ private void buildCallGraph() throws CancelledException {
}
}

private void buildDataReferences(Map<Long, Integer> instructionIndices) {
monitor.setMessage("Exporting data references");
monitor.setMaximum(instructionIndices.size());

int i = 0;
for (Map.Entry<Long, Integer> insnIndex : instructionIndices.entrySet()) {
monitor.setProgress(i++);

Address addr = getAddressFromLong(insnIndex.getKey());
for (Reference ref : program.getReferenceManager().getReferencesFrom(addr)) {
if (ref.isMemoryReference() && ref.getReferenceType().isData()) {
builder
.addDataReferenceBuilder()
.setInstructionIndex(insnIndex.getValue())
.setAddress(ref.getToAddress().getOffset());
}
}
}
}

private void buildSections() {
monitor.setMessage("Exporting sections");
monitor.setIndeterminate(false);
Expand Down Expand Up @@ -532,7 +556,7 @@ public BinExport2 build(TaskMonitor taskMonitor) throws CancelledException {
// TODO(cblichmann): Implement these:
// buildComments()
// buildStrings();
// buildDataReferences()
buildDataReferences(instructionIndices);
monitor.setMessage("Exporting flow graphs");
buildFlowGraphs(basicBlockIndices);
monitor.setMessage("Exporting call graph");
Expand Down

0 comments on commit 605d9de

Please sign in to comment.