mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-30 16:47:43 +08:00
Merge remote-tracking branch 'origin/GP-2904_dev747368_dwarf_this_fix_patch' into patch
This commit is contained in:
+10
-2
@@ -347,16 +347,24 @@ public class DWARFFunctionImporter {
|
|||||||
private void updateFunctionSignatureWithFormalParams(Function gfunc, List<Parameter> params,
|
private void updateFunctionSignatureWithFormalParams(Function gfunc, List<Parameter> params,
|
||||||
DataType returnType, boolean varArgs, DIEAggregate diea) {
|
DataType returnType, boolean varArgs, DIEAggregate diea) {
|
||||||
try {
|
try {
|
||||||
|
String callingConventionName = null;
|
||||||
ReturnParameterImpl returnVar = new ReturnParameterImpl(returnType, currentProgram);
|
ReturnParameterImpl returnVar = new ReturnParameterImpl(returnType, currentProgram);
|
||||||
try {
|
try {
|
||||||
|
if (!params.isEmpty() && Function.THIS_PARAM_NAME.equals(params.get(0).getName())) {
|
||||||
|
// this handles the common / simple case. More nuanced cases where the param
|
||||||
|
// didn't have the correct "this" name, but were marked with DW_AT_object_pointer
|
||||||
|
// or DW_AT_artifical won't be handled by this.
|
||||||
|
callingConventionName = GenericCallingConvention.thiscall.getDeclarationName();
|
||||||
|
}
|
||||||
|
|
||||||
gfunc.setVarArgs(varArgs);
|
gfunc.setVarArgs(varArgs);
|
||||||
gfunc.updateFunction(null, returnVar, params,
|
gfunc.updateFunction(callingConventionName, returnVar, params,
|
||||||
FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS, true, SourceType.IMPORTED);
|
FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS, true, SourceType.IMPORTED);
|
||||||
}
|
}
|
||||||
catch (DuplicateNameException e) {
|
catch (DuplicateNameException e) {
|
||||||
// try again after adjusting param names
|
// try again after adjusting param names
|
||||||
setUniqueParameterNames(gfunc, params);
|
setUniqueParameterNames(gfunc, params);
|
||||||
gfunc.updateFunction(null, returnVar, params,
|
gfunc.updateFunction(callingConventionName, returnVar, params,
|
||||||
FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS, true, SourceType.IMPORTED);
|
FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS, true, SourceType.IMPORTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-1
@@ -17,9 +17,10 @@ package ghidra.app.util.bin.format.dwarf4.next;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import ghidra.app.util.NamespaceUtils;
|
import ghidra.app.util.NamespaceUtils;
|
||||||
@@ -27,6 +28,7 @@ import ghidra.app.util.bin.format.dwarf4.*;
|
|||||||
import ghidra.app.util.bin.format.dwarf4.encoding.DWARFSourceLanguage;
|
import ghidra.app.util.bin.format.dwarf4.encoding.DWARFSourceLanguage;
|
||||||
import ghidra.app.util.bin.format.dwarf4.expression.DWARFExpressionOpCodes;
|
import ghidra.app.util.bin.format.dwarf4.expression.DWARFExpressionOpCodes;
|
||||||
import ghidra.program.model.data.*;
|
import ghidra.program.model.data.*;
|
||||||
|
import ghidra.program.model.lang.CompilerSpec;
|
||||||
import ghidra.program.model.listing.*;
|
import ghidra.program.model.listing.*;
|
||||||
import ghidra.program.model.symbol.Namespace;
|
import ghidra.program.model.symbol.Namespace;
|
||||||
import ghidra.util.exception.CancelledException;
|
import ghidra.util.exception.CancelledException;
|
||||||
@@ -157,4 +159,26 @@ public class DWARFFunctionImporterTest extends DWARFTestBase {
|
|||||||
Structure nestedStructDT2 = VariableUtilities.findExistingClassStruct(fooFunc);
|
Structure nestedStructDT2 = VariableUtilities.findExistingClassStruct(fooFunc);
|
||||||
assertTrue(nestedStructDT1 == nestedStructDT2);
|
assertTrue(nestedStructDT1 == nestedStructDT2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testThisParam()
|
||||||
|
throws CancelledException, IOException, DWARFException {
|
||||||
|
|
||||||
|
DebugInfoEntry intDIE = addInt(cu);
|
||||||
|
DebugInfoEntry ptrDIE = addPtr(intDIE, cu);
|
||||||
|
DebugInfoEntry fooDIE = newSubprogram("foo", intDIE, 0x410, 10).create(cu);
|
||||||
|
newFormalParam(fooDIE, "this", ptrDIE,
|
||||||
|
DWARFExpressionOpCodes.DW_OP_implicit_value /* requires this to be non supported location opcode to trigger formal_param_only mode*/,
|
||||||
|
0x6c).create(cu);
|
||||||
|
|
||||||
|
importFunctions();
|
||||||
|
|
||||||
|
Function fooFunc = program.getListing().getFunctionAt(addr(0x410));
|
||||||
|
assertNotNull(fooFunc);
|
||||||
|
|
||||||
|
assertEquals("foo", fooFunc.getName());
|
||||||
|
Parameter[] fooParams = fooFunc.getParameters();
|
||||||
|
assertEquals(fooParams.length, 1);
|
||||||
|
assertEquals(CompilerSpec.CALLING_CONVENTION_thiscall, fooFunc.getCallingConventionName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user