mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GP-1237: Added unit test and fixed issues.
This commit is contained in:
@@ -48,7 +48,7 @@ public interface DebuggerMappingOpinion extends ExtensionPoint {
|
||||
}
|
||||
catch (Throwable t) {
|
||||
Msg.error(DebuggerMappingOpinion.class,
|
||||
"Problem querying opinion " + opinion + " for recording/mapping offers");
|
||||
"Problem querying opinion " + opinion + " for recording/mapping offers: ", t);
|
||||
}
|
||||
}
|
||||
result.sort(HIGHEST_CONFIDENCE_FIRST);
|
||||
@@ -69,6 +69,10 @@ public interface DebuggerMappingOpinion extends ExtensionPoint {
|
||||
DebuggerObjectModel model = process.getModel();
|
||||
List<String> pathToEnv =
|
||||
model.getRootSchema().searchForSuitable(TargetEnvironment.class, process.getPath());
|
||||
if (pathToEnv == null) {
|
||||
Msg.error(this, "Could not find path to environment");
|
||||
return Set.of();
|
||||
}
|
||||
TargetEnvironment env = (TargetEnvironment) model.getModelObject(pathToEnv);
|
||||
return offersForEnv(env, process);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package ghidra.app.plugin.core.debug.platform.gdb;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import ghidra.app.plugin.core.debug.mapping.DebuggerMappingOffer;
|
||||
import ghidra.app.plugin.core.debug.mapping.DebuggerMappingOpinion;
|
||||
import ghidra.app.plugin.core.debug.platform.gdb.DefaultGdbDebuggerMappingOpinion.GdbDefaultOffer;
|
||||
import ghidra.dbg.model.TestDebuggerObjectModel;
|
||||
import ghidra.dbg.model.TestTargetProcess;
|
||||
import ghidra.program.model.lang.LanguageID;
|
||||
import ghidra.test.AbstractGhidraHeadlessIntegrationTest;
|
||||
|
||||
public class DefaultGdbDebuggerMappingOpinionTest extends AbstractGhidraHeadlessIntegrationTest {
|
||||
@Test
|
||||
public void testQueryOpinionsIncludesLdefsBased() {
|
||||
TestDebuggerObjectModel model = new TestDebuggerObjectModel();
|
||||
|
||||
// TODO: A good number of names are definitely missing from ldefs :(
|
||||
model.session.environment.changeAttributes(List.of(), Map.ofEntries(
|
||||
Map.entry("_debugger", "gdb"),
|
||||
Map.entry("_arch", "armv5t"),
|
||||
Map.entry("_endian", "little")),
|
||||
"Testing");
|
||||
|
||||
TestTargetProcess process = model.addProcess(1234);
|
||||
|
||||
List<DebuggerMappingOffer> offers = DebuggerMappingOpinion.queryOpinions(process);
|
||||
assertFalse(offers.isEmpty());
|
||||
Set<DebuggerMappingOffer> ldefsOnes = offers.stream()
|
||||
.filter(o -> o.getClass().equals(GdbDefaultOffer.class))
|
||||
.collect(Collectors.toSet());
|
||||
assertFalse(ldefsOnes.isEmpty());
|
||||
Set<LanguageID> ids =
|
||||
ldefsOnes.stream().map(o -> o.getTraceLanguageID()).collect(Collectors.toSet());
|
||||
assertTrue(ids.contains(new LanguageID("ARM:LE:32:v5t")));
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
<attribute schema="ANY" />
|
||||
</schema>
|
||||
<schema name="Environment" elementResync="NEVER" attributeResync="NEVER">
|
||||
<interface name="Environment" />
|
||||
<element schema="VOID" />
|
||||
<attribute name="_modified" schema="BOOL" hidden="yes" />
|
||||
<attribute name="_display" schema="STRING" hidden="yes" />
|
||||
|
||||
Reference in New Issue
Block a user