Ghidra is a software reverse engineering (SRE) framework
GP-1417_emteere code review changes
emteere28676b4ec032
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/CodeManager.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/CodeManager.javaindex 8b5e7ff45e..3087be53eb 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/CodeManager.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/CodeManager.java@@ -2825,31 +2825,37 @@ public class CodeManager implements ErrorHandler, ManagerDB {}Address getDefinedAddressAfter(Address address) {- DBRecord dataRec = null;- DBRecord instRec = null;+ lock.acquire();try {- dataRec = dataAdapter.getRecordAfter(address);- instRec = instAdapter.getRecordAfter(address);- }- catch (IOException e) {- program.dbError(e);- return null;- }- if (dataRec == null && instRec == null) {- return null;- }- if (dataRec == null) {- return addrMap.decodeAddress(instRec.getKey());- }- if (instRec == null) {- return addrMap.decodeAddress(dataRec.getKey());+ DBRecord dataRec = null;+ DBRecord instRec = null;+ try {+ dataRec = dataAdapter.getRecordAfter(address);+ instRec = instAdapter.getRecordAfter(address);+ }+ catch (IOException e) {+ program.dbError(e);+ return null;+ }+ if (dataRec == null && instRec == null) {+ return null;+ }+ if (dataRec == null) {+ return addrMap.decodeAddress(instRec.getKey());+ }+ if (instRec == null) {+ return addrMap.decodeAddress(dataRec.getKey());+ }+ Address dataAddr = addrMap.decodeAddress(dataRec.getKey());+ Address instAddr = addrMap.decodeAddress(instRec.getKey());+ if (dataAddr.compareTo(instAddr) < 0) {+ return dataAddr;+ }+ return instAddr;}- Address dataAddr = addrMap.decodeAddress(dataRec.getKey());- Address instAddr = addrMap.decodeAddress(instRec.getKey());- if (dataAddr.compareTo(instAddr) < 0) {- return dataAddr;+ finally {+ lock.release();}- return instAddr;}///////////////////////////////////////////////////////////////////@@ -3117,12 +3123,16 @@ public class CodeManager implements ErrorHandler, ManagerDB {}int getLength(Address addr) {+ lock.acquire();try {return lengthMgr.getInt(addr);}catch (NoValueException e) {return -1;}+ finally {+ lock.release();+ }}private InstructionDB getInstructionDB(long addr) throws IOException {diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/DataDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/DataDB.javaindex 959b44323b..6c28bc0a40 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/DataDB.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/DataDB.java@@ -119,25 +119,26 @@ class DataDB extends CodeUnitDB implements Data {baseDataType = getBaseDataType(dataType);defaultSettings = dataType.getDefaultSettings();length = -1; // set to compute lazily later+ bytes = null;return false;}@Overridepublic int getLength() {if (length == -1) {- lock.acquire();- try {- computeLength();- }- finally {- lock.release();- }+ computeLength();}return length;}private void computeLength() {length = dataType.getLength();++ // undefined will never change their size+ if (dataType instanceof Undefined) {+ return;+ }+if (length < 1) {length = codeMgr.getLength(address);}@@ -181,14 +182,17 @@ class DataDB extends CodeUnitDB implements Data {}}- bytes = null;-// if this is not a component where the size could change and// the length restricted by the following instruction/data item, assume// the createData method stopped fixed code units that won't fit from being added- if (!(baseDataType instanceof Composite || baseDataType instanceof ArrayDataType)) {- return;- }+ //+ // TODO: If the data organization for a program changes, for example a long was 32-bits+ // and is changed to 64-bits, that could cause an issue.+ // If the data organization changing could be detected, this could be done.+ //+ // if (!(baseDataType instanceof Composite || baseDataType instanceof ArrayDataType)) {+ // return;+ // }// This is potentially expensive! So only do if necessary// see if the datatype length is restricted by a following codeunit@@ -196,7 +200,6 @@ class DataDB extends CodeUnitDB implements Data {if ((nextAddr != null) && nextAddr.compareTo(endAddress) <= 0) {length = (int) nextAddr.subtract(address);}- bytes = null;}@Override