GP-4139 Improve demanglers function signature source type applied.

Renamed rustcall to __rustcall.  Minor fix to legacy rust demangling for
namespaces.
This commit is contained in:
ghidra1 2023-12-11 19:17:44 -05:00
parent ed46dde304
commit d4c854ddbc
18 changed files with 140 additions and 103 deletions

View file

@ -67,8 +67,8 @@ class CallingConventionDBAdapterV0 extends CallingConventionDBAdapter {
String tableName = tablePrefix + CALLING_CONVENTION_TABLE_NAME;
if (create) {
// No additional indexed fields.
callingConventionTable = handle.createTable(tableName,
V0_CALLING_CONVENTION_SCHEMA, new int[] {});
callingConventionTable =
handle.createTable(tableName, V0_CALLING_CONVENTION_SCHEMA, new int[] {});
}
else {
callingConventionTable = handle.getTable(tableName);
@ -138,7 +138,7 @@ class CallingConventionDBAdapterV0 extends CallingConventionDBAdapter {
@Override
byte getCallingConventionId(String name, Consumer<String> conventionAdded) throws IOException {
if (name == null || name.equals(CompilerSpec.CALLING_CONVENTION_unknown)) {
if (CompilerSpec.isUnknownCallingConvention(name)) {
return UNKNOWN_CALLING_CONVENTION_ID;
}
else if (name.equals(CompilerSpec.CALLING_CONVENTION_default)) {

View file

@ -4008,7 +4008,7 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
public byte getCallingConventionID(String name, boolean restrictive)
throws InvalidInputException, IOException {
if (name == null || CompilerSpec.CALLING_CONVENTION_unknown.equals(name)) {
if (CompilerSpec.isUnknownCallingConvention(name)) {
return UNKNOWN_CALLING_CONVENTION_ID;
}
if (CompilerSpec.CALLING_CONVENTION_default.equals(name)) {

View file

@ -178,8 +178,7 @@ public class FunctionDefinitionDataType extends GenericDataType implements Funct
@Override
public void setCallingConvention(String conventionName) throws InvalidInputException {
if (conventionName == null ||
CompilerSpec.CALLING_CONVENTION_unknown.equals(conventionName)) {
if (CompilerSpec.isUnknownCallingConvention(conventionName)) {
this.callingConventionName = CompilerSpec.CALLING_CONVENTION_unknown;
return;
}
@ -365,8 +364,7 @@ public class FunctionDefinitionDataType extends GenericDataType implements Funct
if ((signature.getName().equals(this.name)) && (compareComment(signature)) &&
(DataTypeUtilities.isSameOrEquivalentDataType(signature.getReturnType(),
this.returnType)) &&
(hasVarArgs == signature.hasVarArgs()) &&
(hasNoReturn == signature.hasNoReturn()) &&
(hasVarArgs == signature.hasVarArgs()) && (hasNoReturn == signature.hasNoReturn()) &&
callingConventionName.equals(signature.getCallingConventionName())) {
ParameterDefinition[] args = signature.getArguments();
if (args.length == this.params.length) {

View file

@ -1089,7 +1089,7 @@ public class BasicCompilerSpec implements CompilerSpec {
@Override
public PrototypeModel matchConvention(String conventionName) {
if (conventionName == null || CALLING_CONVENTION_unknown.equals(conventionName) ||
if (CompilerSpec.isUnknownCallingConvention(conventionName) ||
CALLING_CONVENTION_default.equals(conventionName)) {
return defaultModel;
}

View file

@ -18,6 +18,8 @@ package ghidra.program.model.lang;
import java.io.IOException;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.data.DataOrganization;
@ -48,6 +50,7 @@ public interface CompilerSpec {
public final static String CALLING_CONVENTION_stdcall = "__stdcall";
public final static String CALLING_CONVENTION_fastcall = "__fastcall";
public final static String CALLING_CONVENTION_vectorcall = "__vectorcall";
public final static String CALLING_CONVENTION_rustcall = "__rustcall";
/**
* Labels for PrototypeModels that are used by default for various analysis/evaluation
@ -59,6 +62,19 @@ public interface CompilerSpec {
EVAL_CALLED // A PrototypeModel used to evaluate a "called" function
}
/**
* Determine if the specified calling convention name is treated as the unknown calling
* convention (blank or {code "unknown"}). Other unrecognized names will return false.
* This static method does not assume any specific compiler specification.
*
* @param callingConventionName calling convention name or null
* @return true if specified name is blank or {code "unknown"}
*/
public static boolean isUnknownCallingConvention(String callingConventionName) {
return StringUtils.isBlank(callingConventionName) ||
CompilerSpec.CALLING_CONVENTION_unknown.equals(callingConventionName);
}
/**
* Get the Language this compiler spec is based on. Note that
* compiler specs may be reused across multiple languages in the