GP-1949 corrected memory map cache update for block removals

This commit is contained in:
ghidra1
2022-05-03 09:40:22 -04:00
parent bfe3dcfb95
commit 5be1971ecf
5 changed files with 17 additions and 8 deletions

View File

@@ -571,7 +571,7 @@ public class MemoryBlockDB implements MemoryBlock {
for (SubMemoryBlock subBlock : subBlocks) { for (SubMemoryBlock subBlock : subBlocks) {
subBlock.delete(); subBlock.delete();
} }
adapter.deleteMemoryBlock(getID()); adapter.deleteMemoryBlock(this);
invalidate(); invalidate();
} }
@@ -670,7 +670,7 @@ public class MemoryBlockDB implements MemoryBlock {
subBlocks.addAll(memBlock2.subBlocks); subBlocks.addAll(memBlock2.subBlocks);
possiblyMergeSubBlocks(n - 1, n); possiblyMergeSubBlocks(n - 1, n);
sequenceSubBlocks(); sequenceSubBlocks();
adapter.deleteMemoryBlock(memBlock2.id); adapter.deleteMemoryBlock(memBlock2);
adapter.updateBlockRecord(record); adapter.updateBlockRecord(record);
} }

View File

@@ -228,10 +228,10 @@ abstract class MemoryMapDBAdapter {
/** /**
* Deletes the given memory block. * Deletes the given memory block.
* @param key the key for the memory block record * @param block the memory block to be deleted
* @throws IOException if a database IO error occurs. * @throws IOException if a database IO error occurs.
*/ */
abstract void deleteMemoryBlock(long key) throws IOException; abstract void deleteMemoryBlock(MemoryBlockDB block) throws IOException;
/** /**
* Updates the memory block record. * Updates the memory block record.

View File

@@ -210,7 +210,7 @@ class MemoryMapDBAdapterV0 extends MemoryMapDBAdapter {
} }
@Override @Override
void deleteMemoryBlock(long key) throws IOException { void deleteMemoryBlock(MemoryBlockDB block) throws IOException {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@@ -169,7 +169,7 @@ class MemoryMapDBAdapterV2 extends MemoryMapDBAdapter {
} }
@Override @Override
void deleteMemoryBlock(long key) throws IOException { void deleteMemoryBlock(MemoryBlockDB block) throws IOException {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@@ -153,6 +153,14 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
memoryBlocks.add(-insertionIndex - 1, newBlock); memoryBlocks.add(-insertionIndex - 1, newBlock);
} }
private void removeCachedBlock(MemoryBlockDB deletedBlock) {
int index = Collections.binarySearch(memoryBlocks, deletedBlock);
if (index < 0) { // should not find direct hit
return;
}
memoryBlocks.remove(index);
}
@Override @Override
MemoryBlockDB createInitializedBlock(String name, Address startAddr, InputStream is, MemoryBlockDB createInitializedBlock(String name, Address startAddr, InputStream is,
long length, int permissions) throws AddressOverflowException, IOException { long length, int permissions) throws AddressOverflowException, IOException {
@@ -319,8 +327,9 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
} }
@Override @Override
void deleteMemoryBlock(long key) throws IOException { void deleteMemoryBlock(MemoryBlockDB block) throws IOException {
memBlockTable.deleteRecord(key); removeCachedBlock(block);
memBlockTable.deleteRecord(block.getID());
} }
@Override @Override