Merge remote-tracking branch 'origin/GP-839_ghidra1_AddressMapImpl' into patch

This commit is contained in:
ghidra1 2021-04-07 09:16:06 -04:00
commit 8513a93ad0
2 changed files with 17 additions and 8 deletions

View File

@ -15,10 +15,10 @@
*/
package ghidra.program.model.address;
import ghidra.util.UniversalIdGenerator;
import java.util.*;
import ghidra.util.UniversalIdGenerator;
/**
* <code>AddressMapImpl</code> provides a stand-alone AddressMap.
* An AddressMapImpl instance should only be used to decode keys which it has generated.
@ -94,6 +94,7 @@ public class AddressMapImpl {
* start of a key range.
*/
private Comparator<Object> addressInsertionKeyRangeComparator = new Comparator<Object>() {
@Override
public int compare(Object keyRangeObj, Object addrObj) {
KeyRange range = (KeyRange) keyRangeObj;
Address addr = (Address) addrObj;
@ -158,7 +159,7 @@ public class AddressMapImpl {
}
void checkAddressSpace(AddressSpace addrSpace) {
String name = addrSpace.getName().toUpperCase();
String name = addrSpace.getName();
AddressSpace existingSpace = spaceMap.get(name);
if (existingSpace == null) {
spaceMap.put(name, addrSpace);
@ -245,10 +246,12 @@ public class AddressMapImpl {
private void addKeyRanges(List<KeyRange> keyRangeList, Address start, Address end) {
int index = Arrays.binarySearch(sortedBaseStartAddrs, start);
if (index < 0)
if (index < 0) {
index = -index - 2;
if (index < 0)
}
if (index < 0) {
index++;
}
while (index < sortedBaseStartAddrs.length &&
end.compareTo(sortedBaseStartAddrs[index]) >= 0) {
Address addr1 = max(start, sortedBaseStartAddrs[index]);
@ -309,7 +312,7 @@ public class AddressMapImpl {
}
for (AddressSpace space : remapSpaces.values()) {
spaceMap.put(space.getName().toUpperCase(), space);
spaceMap.put(space.getName(), space);
}
for (int i = 0; i < baseAddrs.length; i++) {

View File

@ -15,7 +15,7 @@
*/
package ghidra.program.model.address;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import org.junit.*;
@ -26,6 +26,7 @@ public class AddressMapImplTest extends AbstractGenericTest {
AddressSpace sp16;
AddressSpace sp32;
AddressSpace sp64;
AddressSpace ov64;
AddressSpace regSpace;
AddressSpace stackSpace;
SegmentedAddressSpace segSpace1;
@ -42,6 +43,8 @@ public class AddressMapImplTest extends AbstractGenericTest {
sp32 = new GenericAddressSpace("THREE", 32, AddressSpace.TYPE_RAM, 2);
sp64 = new GenericAddressSpace("FOUR", 64, AddressSpace.TYPE_RAM, 2);
ov64 = new OverlayAddressSpace("four", sp64, 100, 0x1000, 0x1fff);
segSpace1 = new SegmentedAddressSpace("SegSpaceOne", 3);
segSpace2 = new SegmentedAddressSpace("SegSpaceTwo", 4);
@ -50,7 +53,7 @@ public class AddressMapImplTest extends AbstractGenericTest {
map = new AddressMapImpl();
addrs = new Address[29];
addrs = new Address[31];
addrs[0] = sp8.getAddress(0);
addrs[1] = sp8.getAddress(0x0ff);
addrs[2] = sp16.getAddress(0);
@ -84,6 +87,9 @@ public class AddressMapImplTest extends AbstractGenericTest {
addrs[27] = stackSpace.getAddress(0);
addrs[28] = stackSpace.getAddress(0x80000000);
addrs[29] = ov64.getAddress(0x1100);
addrs[30] = ov64.getAddress(0x2000);
}
@Test