Merge remote-tracking branch 'origin/GP-3666_Dan_fixGdbLoadLibraryNPEs' into patch

This commit is contained in:
Ryan Kurtz 2023-08-09 13:09:22 -04:00
commit e54c14e9e2
12 changed files with 9 additions and 110 deletions

View File

@ -75,11 +75,7 @@ public class DbgModelTargetModuleContainerImpl extends DbgModelTargetObjectImpl
//modulesByName.remove(name);
module = getTargetModule(name);
}
TargetThread eventThread =
(TargetThread) getModel().getModelObject(getManager().getEventThread());
changeElements(List.of(), List.of(module), Map.of(), "Loaded");
broadcast().event(getProxy(), eventThread, TargetEventType.MODULE_LOADED,
"Library " + name + " loaded", List.of(module));
}
@Override
@ -87,10 +83,6 @@ public class DbgModelTargetModuleContainerImpl extends DbgModelTargetObjectImpl
public void libraryUnloaded(String name) {
DbgModelTargetModule targetModule = getTargetModule(name);
if (targetModule != null) {
TargetThread eventThread =
(TargetThread) getModel().getModelObject(getManager().getEventThread());
broadcast().event(getProxy(), eventThread, TargetEventType.MODULE_UNLOADED,
"Library " + name + " unloaded", List.of(targetModule));
DbgModelImpl impl = (DbgModelImpl) model;
impl.deleteModelObject(targetModule.getDbgModule());
}

View File

@ -181,9 +181,8 @@ public class DbgModel2TargetRootImpl extends DbgModel2DefaultTargetModelRoot
public void objectSelected(Object object) {
List<String> objPath = findObject(object);
model.fetchModelObject(objPath, RefreshBehavior.REFRESH_WHEN_ABSENT).thenAccept(obj ->
update(obj)
);
model.fetchModelObject(objPath, RefreshBehavior.REFRESH_WHEN_ABSENT)
.thenAccept(obj -> update(obj));
}
@Override
@ -241,11 +240,6 @@ public class DbgModel2TargetRootImpl extends DbgModel2DefaultTargetModelRoot
if (mod == null) {
return;
}
getObject(getManager().getEventThread()).thenAccept(t -> {
TargetThread eventThread = (TargetThread) t;
broadcast().event(getProxy(), eventThread, TargetEventType.MODULE_LOADED,
"Library " + info.getModuleName() + " loaded", List.of(mod));
});
getObject(getManager().getEventProcess()).thenAccept(p -> {
DbgModelTargetProcess eventProcess = (DbgModelTargetProcess) p;
DbgModel2TargetObjectImpl memory =
@ -262,11 +256,6 @@ public class DbgModel2TargetRootImpl extends DbgModel2DefaultTargetModelRoot
if (mod == null) {
return;
}
getObject(getManager().getEventThread()).thenAccept(t -> {
TargetThread eventThread = (TargetThread) t;
broadcast().event(getProxy(), eventThread, TargetEventType.MODULE_UNLOADED,
"Library " + info.getModuleName() + " unloaded", List.of(mod));
});
getObject(getManager().getEventProcess()).thenAccept(p -> {
DbgModelTargetProcess eventProcess = (DbgModelTargetProcess) p;
DbgModel2TargetObjectImpl memory =
@ -604,7 +593,7 @@ public class DbgModel2TargetRootImpl extends DbgModel2DefaultTargetModelRoot
stateful.fetchAttributes(RefreshBehavior.REFRESH_ALWAYS);
}
}
private TargetEventType getEventType(DbgState state, DbgCause cause, DbgReason reason) {
switch (state) {
case RUNNING:

View File

@ -69,12 +69,7 @@ public class FridaModelTargetKernelModuleContainerImpl extends FridaModelTargetO
Msg.error(this, "Module " + info.getModuleName(index) + " not found!");
return;
}
FridaThread thread = getManager().getCurrentThread();
TargetThread eventThread =
(TargetThread) getModel().getModelObject(thread);
changeElements(List.of(), List.of(targetModule), Map.of(), "Loaded");
broadcast().event(getProxy(), eventThread, TargetEventType.MODULE_LOADED,
"Library " + info.getModuleName(index) + " loaded", List.of(targetModule));
}
@Override
@ -91,11 +86,6 @@ public class FridaModelTargetKernelModuleContainerImpl extends FridaModelTargetO
FridaCause cause) {
FridaModelTargetModule targetModule = getTargetModule(info.getModule(index));
if (targetModule != null) {
FridaThread thread = getManager().getCurrentThread();
TargetThread eventThread =
(TargetThread) getModel().getModelObject(thread);
broadcast().event(getProxy(), eventThread, TargetEventType.MODULE_UNLOADED,
"Library " + info.getModuleName(index) + " unloaded", List.of(targetModule));
FridaModelImpl impl = (FridaModelImpl) model;
impl.deleteModelObject(targetModule.getModule());
}

View File

@ -87,12 +87,7 @@ public class FridaModelTargetModuleContainerImpl extends FridaModelTargetObjectI
Msg.error(this, "Module " + info.getModuleName(index) + " not found!");
return;
}
FridaThread thread = getManager().getCurrentThread();
TargetThread eventThread =
(TargetThread) getModel().getModelObject(thread);
changeElements(List.of(), List.of(targetModule), Map.of(), "Loaded");
broadcast().event(getProxy(), eventThread, TargetEventType.MODULE_LOADED,
"Library " + info.getModuleName(index) + " loaded", List.of(targetModule));
}
@Override
@ -109,11 +104,6 @@ public class FridaModelTargetModuleContainerImpl extends FridaModelTargetObjectI
FridaCause cause) {
FridaModelTargetModule targetModule = getTargetModule(info.getModule(index));
if (targetModule != null) {
FridaThread thread = getManager().getCurrentThread();
TargetThread eventThread =
(TargetThread) getModel().getModelObject(thread);
broadcast().event(getProxy(), eventThread, TargetEventType.MODULE_UNLOADED,
"Library " + info.getModuleName(index) + " unloaded", List.of(targetModule));
FridaModelImpl impl = (FridaModelImpl) model;
impl.deleteModelObject(targetModule.getModule());
}

View File

@ -107,17 +107,12 @@ public class GdbModelTargetInferiorContainer
@Override
public void libraryLoaded(GdbInferior inf, String name, GdbCause cause) {
GdbModelTargetInferior inferior = getTargetInferior(inf);
GdbModelTargetModule module = inferior.modules.libraryLoaded(name);
broadcast().event(parent, null, TargetEventType.MODULE_LOADED,
"Library " + name + " loaded", List.of(module));
inferior.modules.libraryLoaded(name);
}
@Override
public void libraryUnloaded(GdbInferior inf, String name, GdbCause cause) {
GdbModelTargetInferior inferior = getTargetInferior(inf);
GdbModelTargetModule module = inferior.modules.getTargetModuleIfPresent(name);
broadcast().event(parent, null, TargetEventType.MODULE_UNLOADED,
"Library " + name + " unloaded", List.of(module));
inferior.modules.libraryUnloaded(name);
}

View File

@ -53,7 +53,11 @@ public class GdbModelTargetModuleContainer
@Internal
public GdbModelTargetModule libraryLoaded(String name) {
GdbModule mod = Objects.requireNonNull(inferior.getKnownModules().get(name));
GdbModule mod = inferior.getKnownModules().get(name);
if (mod == null) {
// We'll catch it the next time around.
return null;
}
GdbModelTargetModule module = getTargetModule(mod);
changeElements(List.of(), List.of(module), "Loaded");
return module;

View File

@ -69,12 +69,7 @@ public class LldbModelTargetModuleContainerImpl extends LldbModelTargetObjectImp
System.err.println("Module " + info.getModuleName(index) + " not found!");
return;
}
SBThread thread = getManager().getEventThread();
TargetThread eventThread =
(TargetThread) getModel().getModelObject(thread);
changeElements(List.of(), List.of(targetModule), Map.of(), "Loaded");
broadcast().event(getProxy(), eventThread, TargetEventType.MODULE_LOADED,
"Library " + info.getModuleName(index) + " loaded", List.of(targetModule));
}
@Override
@ -82,11 +77,6 @@ public class LldbModelTargetModuleContainerImpl extends LldbModelTargetObjectImp
public void libraryUnloaded(DebugModuleInfo info, int index) {
LldbModelTargetModule targetModule = getTargetModule(info.getModule(index));
if (targetModule != null) {
SBThread thread = getManager().getEventThread();
TargetThread eventThread =
(TargetThread) getModel().getModelObject(thread);
broadcast().event(getProxy(), eventThread, TargetEventType.MODULE_UNLOADED,
"Library " + info.getModuleName(index) + " unloaded", List.of(targetModule));
LldbModelImpl impl = (LldbModelImpl) model;
impl.deleteModelObject(targetModule.getModule());
}

View File

@ -234,10 +234,6 @@ public enum GadpValueUtils {
return TargetEventType.THREAD_CREATED;
case EV_THREAD_EXITED:
return TargetEventType.THREAD_EXITED;
case EV_MODULE_LOADED:
return TargetEventType.MODULE_LOADED;
case EV_MODULE_UNLOADED:
return TargetEventType.MODULE_UNLOADED;
case EV_BREAKPOINT_HIT:
return TargetEventType.BREAKPOINT_HIT;
case EV_STEP_COMPLETED:
@ -264,10 +260,6 @@ public enum GadpValueUtils {
return Gadp.TargetEventType.EV_THREAD_CREATED;
case THREAD_EXITED:
return Gadp.TargetEventType.EV_THREAD_EXITED;
case MODULE_LOADED:
return Gadp.TargetEventType.EV_MODULE_LOADED;
case MODULE_UNLOADED:
return Gadp.TargetEventType.EV_MODULE_UNLOADED;
case BREAKPOINT_HIT:
return Gadp.TargetEventType.EV_BREAKPOINT_HIT;
case STEP_COMPLETED:

View File

@ -484,8 +484,6 @@ enum TargetEventType {
EV_PROCESS_EXITED = 3;
EV_THREAD_CREATED = 4;
EV_THREAD_EXITED = 5;
EV_MODULE_LOADED = 6;
EV_MODULE_UNLOADED = 7;
EV_BREAKPOINT_HIT = 8;
EV_STEP_COMPLETED = 9;
EV_EXCEPTION = 10;

View File

@ -34,11 +34,9 @@ import ghidra.program.model.address.*;
import ghidra.trace.model.Trace;
import ghidra.trace.model.memory.TraceMemoryManager;
import ghidra.trace.model.memory.TraceMemoryState;
import ghidra.trace.model.modules.TraceModule;
import ghidra.util.Msg;
import ghidra.util.TimedMsg;
import ghidra.util.datastruct.PrivatelyQueuedListener;
import ghidra.util.exception.DuplicateNameException;
public class TraceEventListener extends AnnotatedDebuggerAttributeListener {
@ -143,28 +141,6 @@ public class TraceEventListener extends AnnotatedDebuggerAttributeListener {
ManagedThreadRecorder rec = recorder.getThreadRecorder(eventThread);
recorder.createSnapshot(description, rec == null ? null : rec.getTraceThread(), null);
ignoreInvalidation = false;
if (type == TargetEventType.MODULE_LOADED) {
long snap = recorder.getSnap();
Object p0 = parameters.get(0);
if (!(p0 instanceof TargetModule)) {
return;
}
TargetModule mod = (TargetModule) p0;
String modPath = mod.getJoinedPath(".");
recorder.parTx.execute("Adjust module load: " + modPath, () -> {
TraceModule traceModule = recorder.getTraceModule(mod);
if (traceModule == null) {
return;
}
try {
traceModule.setLoadedSnap(snap);
}
catch (DuplicateNameException e) {
Msg.error(this, "Could not set module loaded snap", e);
}
}, modPath);
}
}
@AttributeCallback(TargetExecutionStateful.STATE_ATTRIBUTE_NAME)

View File

@ -64,17 +64,6 @@ public interface TargetEventScope extends TargetObject {
* A target thread in this session has exited
*/
THREAD_EXITED(false),
/**
* A new module has been loaded by this session
*
* <p>
* The new module must be passed as a parameter.
*/
MODULE_LOADED(false),
/**
* A module has been unloaded by this session
*/
MODULE_UNLOADED(false),
/**
* The session has stopped, because one if its targets was trapped by a breakpoint
*

View File

@ -203,12 +203,6 @@ public class EventValidator
case THREAD_EXITED:
validateDestroyed(type.name(), TargetThread.class, threads, parameters);
break;
case MODULE_LOADED:
validateCreated(type.name(), TargetModule.class, modules, parameters);
break;
case MODULE_UNLOADED:
validateDestroyed(type.name(), TargetModule.class, modules, parameters);
break;
case STOPPED:
case RUNNING:
case BREAKPOINT_HIT: