Merge remote-tracking branch 'origin/debugger'

This commit is contained in:
ghidra1 2021-05-03 17:52:52 -04:00
commit 27fbe7278d
6 changed files with 63 additions and 4 deletions

View File

@ -130,7 +130,11 @@ public class DebugControlImpl1 implements DebugControlInternal {
BitmaskSet<DebugExecute> flags) {
ULONG ctlMask = new ULONG(ctl.getBitmask());
ULONG flagMask = new ULONG(flags.getBitmask());
COMUtils.checkRC(jnaControl.Execute(ctlMask, cmd, flagMask));
HRESULT hr = jnaControl.Execute(ctlMask, cmd, flagMask);
if (hr.equals(COMUtilsExtra.E_INTERNALEXCEPTION)) {
return;
}
COMUtils.checkRC(hr);
}
@Override

View File

@ -19,9 +19,11 @@ import com.sun.jna.Native;
import com.sun.jna.WString;
import com.sun.jna.platform.win32.WinDef.ULONG;
import com.sun.jna.platform.win32.WinDef.ULONGByReference;
import com.sun.jna.platform.win32.WinNT.HRESULT;
import com.sun.jna.platform.win32.COM.COMUtils;
import com.sun.jna.ptr.PointerByReference;
import agent.dbgeng.dbgeng.COMUtilsExtra;
import agent.dbgeng.dbgeng.DebugBreakpoint;
import agent.dbgeng.dbgeng.DebugBreakpoint.BreakType;
import agent.dbgeng.dbgeng.DebugValue.DebugValueType;
@ -90,7 +92,11 @@ public class DebugControlImpl4 extends DebugControlImpl3 {
BitmaskSet<DebugExecute> flags) {
ULONG ctlMask = new ULONG(ctl.getBitmask());
ULONG flagMask = new ULONG(flags.getBitmask());
COMUtils.checkRC(jnaControl.ExecuteWide(ctlMask, new WString(cmd), flagMask));
HRESULT hr = jnaControl.ExecuteWide(ctlMask, new WString(cmd), flagMask);
if (hr.equals(COMUtilsExtra.E_INTERNALEXCEPTION)) {
return;
}
COMUtils.checkRC(hr);
}
@Override

View File

@ -20,6 +20,7 @@ import static org.junit.Assert.assertTrue;
import java.util.List;
import ghidra.async.AsyncUtils.TemperamentalRunnable;
import ghidra.dbg.target.TargetEnvironment;
import ghidra.dbg.target.TargetMethod.TargetParameterMap;
import ghidra.dbg.test.AbstractDebuggerModelAttacherTest;
@ -49,4 +50,35 @@ public abstract class AbstractModelForGdbAttacherTest extends AbstractDebuggerMo
assertEquals("little", environment.getEndian());
assertTrue(environment.getDebugger().toLowerCase().contains("gdb"));
}
// NB. Gradle/Java hangs on process clean-up if target is still attached
protected void withDetachAndForcefulDummyDestruction(TemperamentalRunnable test)
throws Throwable {
try {
test.run();
runTestDetach(getAttachSpecimen());
}
finally {
if (dummy == null) {
return;
}
dummy.process.destroy();
dummy.process.destroyForcibly();
}
}
@Override
public void testAttachByObj() throws Throwable {
withDetachAndForcefulDummyDestruction(() -> super.testAttachByObj());
}
@Override
public void testAttachByPid() throws Throwable {
withDetachAndForcefulDummyDestruction(() -> super.testAttachByPid());
}
@Override
public void testAttachByPidThenResumeInterrupt() throws Throwable {
withDetachAndForcefulDummyDestruction(() -> super.testAttachByPidThenResumeInterrupt());
}
}

View File

@ -19,6 +19,7 @@ import java.util.*;
import ghidra.dbg.DebuggerObjectModel;
import ghidra.dbg.target.*;
import ghidra.util.Msg;
import ghidra.util.classfinder.ClassSearcher;
import ghidra.util.classfinder.ExtensionPoint;
@ -29,6 +30,7 @@ public interface DebuggerMappingOpinion extends ExtensionPoint {
/**
* Query all known opinions for recording/tracing a debug session
*
* <p>
* The returned offers are ordered highest-confidence first.
*
* @param target the target to be recorded, usually a process
@ -38,8 +40,15 @@ public interface DebuggerMappingOpinion extends ExtensionPoint {
List<DebuggerMappingOffer> result = new ArrayList<>();
for (DebuggerMappingOpinion opinion : ClassSearcher
.getInstances(DebuggerMappingOpinion.class)) {
synchronized (result) {
result.addAll(opinion.getOffers(target));
try {
Set<DebuggerMappingOffer> offers = opinion.getOffers(target);
synchronized (result) {
result.addAll(offers);
}
}
catch (Throwable t) {
Msg.error(DebuggerMappingOpinion.class,
"Problem querying opinion " + opinion + " for recording/mapping offers");
}
}
result.sort(HIGHEST_CONFIDENCE_FIRST);

View File

@ -45,7 +45,11 @@ public class GdbArmDebuggerMappingOpinion implements DebuggerMappingOpinion {
}
}
@Override
public Set<DebuggerMappingOffer> offersForEnv(TargetEnvironment env, TargetProcess process) {
if (env == null) {
return Set.of();
}
if (!env.getDebugger().toLowerCase().contains("gdb")) {
return Set.of();
}

View File

@ -16,10 +16,12 @@
package ghidra.dbg.testutil;
import java.io.*;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import ghidra.framework.Application;
import ghidra.util.Msg;
public class DummyProc implements AutoCloseable {
public final Process process;
@ -65,11 +67,13 @@ public class DummyProc implements AutoCloseable {
.start();
pid = process.pid();
Msg.info(this, "Started dummy process pid = " + pid + ": " + List.of(args));
}
@Override
public void close() throws Exception {
if (!process.destroyForcibly().waitFor(1000, TimeUnit.MILLISECONDS)) {
Msg.error(this, "Could not terminate process " + pid);
throw new TimeoutException("Could not terminate process " + pid);
}
}