Merge remote-tracking branch 'origin/GP-4084_dev747368_dwarf_global_vars'

This commit is contained in:
ghidra1
2023-12-01 16:53:59 -05:00
2 changed files with 32 additions and 23 deletions
@@ -346,14 +346,21 @@ public class DWARFFunctionImporter {
SymbolTable symbolTable = currentProgram.getSymbolTable(); SymbolTable symbolTable = currentProgram.getSymbolTable();
Symbol labelSym = null; Symbol labelSym = null;
if (!currentProgram.getMemory().contains(address)) {
if (!globalVar.isZeroByte()) {
Msg.error(this, "Invalid location for global variable %s:%s @%s".formatted(name,
dataType.getName(), address));
}
return;
}
if (globalVar.isZeroByte() || !variablesProcesesed.contains(address)) { if (globalVar.isZeroByte() || !variablesProcesesed.contains(address)) {
try { try {
labelSym = symbolTable.createLabel(address, name, namespace, SourceType.IMPORTED); labelSym = symbolTable.createLabel(address, name, namespace, SourceType.IMPORTED);
} }
catch (InvalidInputException e) { catch (InvalidInputException e) {
Msg.error(this, Msg.error(this, "Error creating label for global variable %s/%s at %s"
String.format("Error creating label for global variable %s/%s at %s", .formatted(namespace, name, address));
namespace, name, address));
return; return;
} }
} }
@@ -362,8 +369,8 @@ public class DWARFFunctionImporter {
// because this is a zero-length data type (ie. array[0]), // because this is a zero-length data type (ie. array[0]),
// don't create a variable at the location since it will prevent other elements // don't create a variable at the location since it will prevent other elements
// from occupying the same offset // from occupying the same offset
appendComment(address, CodeUnit.PRE_COMMENT, String.format( appendComment(address, CodeUnit.PRE_COMMENT,
"Zero length variable: %s: %s", name, dataType.getDisplayName()), "\n"); "Zero length variable: %s: %s".formatted(name, dataType.getDisplayName()), "\n");
return; return;
} }
@@ -378,19 +385,20 @@ public class DWARFFunctionImporter {
setExternalEntryPoint(true, address); setExternalEntryPoint(true, address);
} }
try { if (dataType instanceof Dynamic || dataType instanceof FactoryDataType) {
if (dataType instanceof Dynamic || dataType instanceof FactoryDataType) { appendComment(address, CodeUnit.EOL_COMMENT,
appendComment(address, CodeUnit.EOL_COMMENT, "Unsupported dynamic data type: " + dataType, "\n");
"Unsupported dynamic data type: " + dataType, "\n"); dataType = Undefined.getUndefinedDataType(1);
dataType = Undefined.getUndefinedDataType(1); }
} DWARFDataInstanceHelper dih = new DWARFDataInstanceHelper(currentProgram);
DWARFDataInstanceHelper dih = new DWARFDataInstanceHelper(currentProgram); if (!dih.isDataTypeCompatibleWithAddress(dataType, address)) {
if (!dih.isDataTypeCompatibleWithAddress(dataType, address)) { appendComment(address, CodeUnit.EOL_COMMENT,
appendComment(address, CodeUnit.EOL_COMMENT, String.format( "Could not place DWARF static variable %s: %s @%s because existing data type conflicts."
"Could not place DWARF static variable %s: %s @%s because existing data type conflicts.", .formatted(name, dataType.getName(), address),
globalVar.name.getName(), dataType.getName(), address), "\n"); "\n");
} }
else { else {
try {
Data varData = DataUtilities.createData(currentProgram, address, dataType, -1, Data varData = DataUtilities.createData(currentProgram, address, dataType, -1,
ClearDataMode.CLEAR_ALL_CONFLICT_DATA); ClearDataMode.CLEAR_ALL_CONFLICT_DATA);
if (varData != null && globalVar.sourceInfo != null) { if (varData != null && globalVar.sourceInfo != null) {
@@ -398,12 +406,13 @@ public class DWARFFunctionImporter {
globalVar.sourceInfo.getFilename()); globalVar.sourceInfo.getFilename());
} }
variablesProcesesed.add(address); variablesProcesesed.add(address);
importSummary.globalVarsAdded++;
}
catch (CodeUnitInsertionException e) {
Msg.error(this, "Error creating global variable %s:%s @%s: %s".formatted(name,
dataType.getName(), address, e.getMessage()));
} }
} }
catch (CodeUnitInsertionException e) {
Msg.error(this, "Error creating data object at " + address, e);
}
importSummary.globalVarsAdded++;
if (globalVar.sourceInfo != null) { if (globalVar.sourceInfo != null) {
appendComment(address, CodeUnit.EOL_COMMENT, globalVar.sourceInfo.getDescriptionStr(), appendComment(address, CodeUnit.EOL_COMMENT, globalVar.sourceInfo.getDescriptionStr(),
@@ -403,7 +403,7 @@ public class DWARFVariable {
} }
else if (exprEvaluator.getRawLastRegister() == -1 && res != 0) { else if (exprEvaluator.getRawLastRegister() == -1 && res != 0) {
// static global variable location // static global variable location
setRamStorage(res); setRamStorage(res + prog.getProgramBaseAddressFixup());
} }
else { else {
Msg.error(this, Msg.error(this,