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) {
subBlock.delete();
}
adapter.deleteMemoryBlock(getID());
adapter.deleteMemoryBlock(this);
invalidate();
}
@ -670,7 +670,7 @@ public class MemoryBlockDB implements MemoryBlock {
subBlocks.addAll(memBlock2.subBlocks);
possiblyMergeSubBlocks(n - 1, n);
sequenceSubBlocks();
adapter.deleteMemoryBlock(memBlock2.id);
adapter.deleteMemoryBlock(memBlock2);
adapter.updateBlockRecord(record);
}

View File

@ -228,10 +228,10 @@ abstract class MemoryMapDBAdapter {
/**
* 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.
*/
abstract void deleteMemoryBlock(long key) throws IOException;
abstract void deleteMemoryBlock(MemoryBlockDB block) throws IOException;
/**
* Updates the memory block record.

View File

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

View File

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

View File

@ -153,6 +153,14 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
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
MemoryBlockDB createInitializedBlock(String name, Address startAddr, InputStream is,
long length, int permissions) throws AddressOverflowException, IOException {
@ -319,8 +327,9 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
}
@Override
void deleteMemoryBlock(long key) throws IOException {
memBlockTable.deleteRecord(key);
void deleteMemoryBlock(MemoryBlockDB block) throws IOException {
removeCachedBlock(block);
memBlockTable.deleteRecord(block.getID());
}
@Override