GP-4150 add option to ignore DWARF func param storage info

Add option to DWARF analyzer to ignore storage locations specified for
function parameters.
(the info provided by DWARF info will often not be directly at the func
entry point and requires future dev effort to walk the parameter info
backwards to get it)

Add option to DWARF analyzer to set the default calling convention of
functions created via the analyzer.
This commit is contained in:
dev747368 2024-08-23 20:00:59 +00:00
parent db28b29dab
commit de80c63e63
6 changed files with 74 additions and 12 deletions

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -196,6 +196,14 @@ public class DWARFFunctionImporter {
dfunc.runFixups();
String defaultCC = prog.getImportOptions().getDefaultCC();
if (defaultCC != null && defaultCC.isBlank()) {
defaultCC = null;
}
if (dfunc.callingConventionName == null && defaultCC != null) {
dfunc.callingConventionName = defaultCC;
}
decorateFunctionWithDWARFInfo(dfunc, origFuncDef);
if (dfunc.signatureCommitMode != CommitMode.SKIP) {

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -70,6 +70,14 @@ public class DWARFImportOptions {
private static final String OPTION_IMPORT_LOCAL_VARS_DESC =
"Import local variable information from DWARF and attempt to create Ghidra local variables.";
private static final String OPTION_IGNORE_PARAM_STORAGE = "Ignore Parameter Storage Info";
private static final String OPTION_IGNORE_PARAM_STORAGE_DESC =
"Ignore any function parameter storage info specifed, allow automatic layout.";
private static final String OPTION_DEFAULT_CC = "Default Calling Convention";
private static final String OPTION_DEFAULT_CC_DESC =
"Name of default calling convention to assign to functions (e.g. __cdecl, __stdcall, etc), or leave blank.";
//==================================================================================================
// Old Option Names - Should stick around for multiple major versions after 10.2
//==================================================================================================
@ -104,6 +112,8 @@ public class DWARFImportOptions {
private boolean importLocalVariables = true;
private boolean useBookmarks = true;
private boolean outputSourceLineInfo = false;
private boolean ignoreParamStorage = false;
private String defaultCC = "";
/**
* Create new instance
@ -374,6 +384,22 @@ public class DWARFImportOptions {
this.outputSourceLineInfo = outputSourceLineInfo;
}
public boolean isIgnoreParamStorage() {
return ignoreParamStorage;
}
public void setIgnoreParamStorage(boolean ignoreParamStorage) {
this.ignoreParamStorage = ignoreParamStorage;
}
public String getDefaultCC() {
return defaultCC;
}
public void setDefaultCC(String defaultCC) {
this.defaultCC = defaultCC;
}
/**
* See {@link Analyzer#registerOptions(Options, ghidra.program.model.listing.Program)}
*
@ -409,6 +435,11 @@ public class DWARFImportOptions {
options.registerOption(OPTION_SOURCE_LINEINFO, isOutputSourceLineInfo(), null,
OPTION_SOURCE_LINEINFO_DESC);
options.registerOption(OPTION_IGNORE_PARAM_STORAGE, isIgnoreParamStorage(), null,
OPTION_IGNORE_PARAM_STORAGE_DESC);
options.registerOption(OPTION_DEFAULT_CC, getDefaultCC(), null, OPTION_DEFAULT_CC_DESC);
}
/**
@ -433,6 +464,9 @@ public class DWARFImportOptions {
options.getBoolean(OPTION_IMPORT_LOCAL_VARS, isImportLocalVariables()));
setOutputSourceLineInfo(
options.getBoolean(OPTION_SOURCE_LINEINFO, isOutputSourceLineInfo()));
setIgnoreParamStorage(
options.getBoolean(OPTION_IGNORE_PARAM_STORAGE, isIgnoreParamStorage()));
setDefaultCC(options.getString(OPTION_DEFAULT_CC, getDefaultCC()));
}
}

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -16,8 +16,8 @@
package ghidra.app.util.bin.format.dwarf.funcfixup;
import ghidra.app.util.bin.format.dwarf.DWARFFunction;
import ghidra.app.util.bin.format.dwarf.DWARFVariable;
import ghidra.app.util.bin.format.dwarf.DWARFFunction.CommitMode;
import ghidra.app.util.bin.format.dwarf.DWARFVariable;
import ghidra.util.classfinder.ExtensionPointProperties;
/**
@ -32,6 +32,14 @@ public class StorageVerificationDWARFFunctionFixup implements DWARFFunctionFixup
@Override
public void fixupDWARFFunction(DWARFFunction dfunc) {
boolean ignoreStorage = dfunc.getProgram().getImportOptions().isIgnoreParamStorage() ||
dfunc.getProgram().getRegisterMappings().isUseFormalParameterStorage();
boolean isEmptySignature = dfunc.params.isEmpty() && dfunc.retval.isVoidType();
if (ignoreStorage || isEmptySignature) {
dfunc.signatureCommitMode = CommitMode.FORMAL;
return;
}
boolean storageIsGood = true;
for (DWARFVariable param : dfunc.params) {
if (param.isMissingStorage() && !param.isZeroByte()) {

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -68,7 +68,7 @@ public class GolangDWARFFunctionFixup implements DWARFFunctionFixup {
return false;
}
// sanity check: gofuncs always have a void return type in dwarf
if (!dfunc.retval.type.isEquivalent(VoidDataType.dataType)) {
if (!dfunc.retval.isVoidType()) {
return false;
}
return true;

View File

@ -8,5 +8,11 @@
<register_mapping dwarf="17" ghidra="cpsr"/>
</register_mappings>
<call_frame_cfa value="0"/>
<use_formal_parameter_storage/>
<!--
In the past, this flag has been present in this file but was not correctly implemented in
the DWARF analyzer. The DWARF analyzer now respects this flag, and also has the
"Ignore Parameter Storage Info" toggle option to enable the same feature.
This flag is being left disabled to match recent DWARF analyzer behavior.
<use_formal_parameter_storage/>
-->
</dwarf>

View File

@ -10,5 +10,11 @@
<register_mapping dwarf="64" ghidra="s0" auto_count="32"/> <!-- s0..s31 -->
</register_mappings>
<call_frame_cfa value="0"/>
<use_formal_parameter_storage/>
<!--
In the past, this flag has been present in this file but was not correctly implemented in
the DWARF analyzer. The DWARF analyzer now respects this flag, and also has the
"Ignore Parameter Storage Info" toggle option to enable the same feature.
This flag is being left disabled to match recent DWARF analyzer behavior.
<use_formal_parameter_storage/>
-->
</dwarf>