GP-1633/GP-2308 Added ProgramArchitecture to datatype managers.

Refactored ProjectDataTypeManager to extend StandaloneDataTypeManager.
Added actions to datatype tree to allow setting archive architecture.
Added use of storage translators when switching architectures.  Allow
FunctionDefinition to accept arbitrary calling convention
names and many other misc changes.
This commit is contained in:
ghidra1 2021-12-27 17:01:32 -05:00
parent 75a185aa9e
commit a4776892bd
248 changed files with 6282 additions and 2935 deletions

View file

@ -20,8 +20,11 @@ import ghidra.app.util.bin.format.pdb2.pdbreader.PdbException;
import ghidra.app.util.bin.format.pdb2.pdbreader.RecordNumber;
import ghidra.app.util.bin.format.pdb2.pdbreader.type.AbstractMsType;
import ghidra.app.util.bin.format.pdb2.pdbreader.type.CallingConvention;
import ghidra.program.model.data.*;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.FunctionDefinitionDataType;
import ghidra.program.model.lang.CompilerSpec;
import ghidra.util.exception.CancelledException;
import ghidra.util.exception.InvalidInputException;
/**
* Applier for certain function types.
@ -226,9 +229,9 @@ public abstract class AbstractFunctionTypeApplier extends MsTypeApplier {
private void setCallingConvention(DefaultPdbApplicator applicator,
CallingConvention callingConvention, boolean hasThisPointer) {
GenericCallingConvention convention;
String convention;
if (hasThisPointer) {
convention = GenericCallingConvention.thiscall;
convention = CompilerSpec.CALLING_CONVENTION_thiscall;
}
else {
// Since we are a member function, we will always assume a _thiscall...
@ -236,24 +239,30 @@ public abstract class AbstractFunctionTypeApplier extends MsTypeApplier {
switch (callingConvention) {
// TODO: figure all of these out.
case THISCALL: // "this" passed in register (we have not yet seen this)
convention = GenericCallingConvention.thiscall; // Is this correct if in reg?
convention = CompilerSpec.CALLING_CONVENTION_thiscall; // Is this correct if in reg?
break;
case NEAR_C: // we have seen this one
convention = GenericCallingConvention.cdecl;
convention = CompilerSpec.CALLING_CONVENTION_cdecl;
break;
case NEAR_VECTOR: // we have seen this one
convention = GenericCallingConvention.vectorcall;
convention = CompilerSpec.CALLING_CONVENTION_vectorcall;
break;
default:
// applicator.getLog().appendMsg(
// "TODO: calling convention not implemented for value " + callingConventionVal +
// " in " + funcName);
//convention = GenericCallingConvention.cdecl;
convention = GenericCallingConvention.cdecl;
convention = CompilerSpec.CALLING_CONVENTION_cdecl;
break;
}
}
functionDefinition.setGenericCallingConvention(convention);
try {
functionDefinition.setCallingConvention(convention);
}
catch (InvalidInputException e) {
applicator.appendLogMsg("Failed to set calling convention `" + convention + "` for " +
functionDefinition.getName());
}
}
}

View file

@ -25,8 +25,10 @@ import ghidra.app.util.bin.format.pdb2.pdbreader.type.*;
import ghidra.app.util.pdb.pdbapplicator.SymbolGroup.AbstractMsSymbolIterator;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.*;
import ghidra.program.model.lang.CompilerSpec;
import ghidra.util.Msg;
import ghidra.util.exception.CancelledException;
import ghidra.util.exception.InvalidInputException;
import ghidra.util.task.TaskMonitor;
import mdemangler.*;
import mdemangler.object.MDObjectCPP;
@ -498,7 +500,7 @@ public class PdbResearch {
//==============================================================================================
//==============================================================================================
static void studyDataTypeConflicts(DefaultPdbApplicator applicator, TaskMonitor monitor)
throws CancelledException {
throws CancelledException, InvalidInputException {
DataTypeConflictHandler handler =
DataTypeConflictHandler.REPLACE_EMPTY_STRUCTS_OR_RENAME_AND_ADD_HANDLER;
DataTypeManager dtm = applicator.getDataTypeManager();
@ -510,7 +512,7 @@ public class PdbResearch {
FunctionDefinitionDataType fn1 =
new FunctionDefinitionDataType(CategoryPath.ROOT, "____fn1____", dtm);
fn1.setReturnType(pointer1);
fn1.setGenericCallingConvention(GenericCallingConvention.cdecl);
fn1.setCallingConvention(CompilerSpec.CALLING_CONVENTION_cdecl);
fn1.setArguments(new ParameterDefinition[0]);
Composite internalStruct1 = createComposite(dtm, "____internal____");
@ -526,7 +528,7 @@ public class PdbResearch {
FunctionDefinitionDataType fn2 =
new FunctionDefinitionDataType(CategoryPath.ROOT, "____fn2____", dtm);
fn2.setReturnType(pointer2);
fn2.setGenericCallingConvention(GenericCallingConvention.cdecl);
fn2.setCallingConvention(CompilerSpec.CALLING_CONVENTION_cdecl);
fn2.setArguments(new ParameterDefinition[0]);
Composite internalStruct2 = createComposite(dtm, "____internal____");

View file

@ -25,6 +25,7 @@ import ghidra.program.database.ProgramBuilder;
import ghidra.program.database.ProgramDB;
import ghidra.program.database.data.DataTypeManagerDB;
import ghidra.program.model.data.*;
import ghidra.program.model.lang.CompilerSpec;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.util.Msg;
import ghidra.util.exception.CancelledException;
@ -66,7 +67,7 @@ public class ConflictHandlerTest2 extends AbstractGhidraHeadedIntegrationTest {
}
@Test
public void testDataTypeConflicts() {
public void testDataTypeConflicts() throws Exception {
DataTypeConflictHandler handler =
DataTypeConflictHandler.REPLACE_EMPTY_STRUCTS_OR_RENAME_AND_ADD_HANDLER;
@ -77,7 +78,7 @@ public class ConflictHandlerTest2 extends AbstractGhidraHeadedIntegrationTest {
FunctionDefinitionDataType fn1 =
new FunctionDefinitionDataType(CategoryPath.ROOT, "fn1", dtm);
fn1.setReturnType(pointer1);
fn1.setGenericCallingConvention(GenericCallingConvention.cdecl);
fn1.setCallingConvention(CompilerSpec.CALLING_CONVENTION_cdecl);
fn1.setArguments(new ParameterDefinition[0]);
Composite internalStruct1 = createComposite(dtm, "inner");
@ -93,7 +94,7 @@ public class ConflictHandlerTest2 extends AbstractGhidraHeadedIntegrationTest {
FunctionDefinitionDataType fn2 =
new FunctionDefinitionDataType(CategoryPath.ROOT, "fn2", dtm);
fn2.setReturnType(pointer2);
fn2.setGenericCallingConvention(GenericCallingConvention.cdecl);
fn2.setCallingConvention(CompilerSpec.CALLING_CONVENTION_cdecl);
fn2.setArguments(new ParameterDefinition[0]);
Composite internalStruct2 = createComposite(dtm, "inner");