Skip to content

Commit

Permalink
Handle silent debug helper injection failures (for example when debug…
Browse files Browse the repository at this point in the history
…ging UWP applications)
  • Loading branch information
WheretIB committed Jun 1, 2020
1 parent 82f8c33 commit b154f21
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion LuaDkmDebuggerComponent/LocalComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.Debugger;
using Microsoft.VisualStudio.Debugger.Breakpoints;
using Microsoft.VisualStudio.Debugger.CallStack;
using Microsoft.VisualStudio.Debugger.ComponentInterfaces;
using Microsoft.VisualStudio.Debugger.CustomRuntimes;
Expand Down Expand Up @@ -43,6 +44,7 @@ internal class LuaLocalProcessData : DkmDataItem

public bool helperInjectRequested = false;
public bool helperInjected = false;
public bool helperDetected = false;
public bool helperInitializationWaitActive = false;
public bool helperInitializationWaitUsed = false;
public bool helperInitialized = false;
Expand Down Expand Up @@ -1695,6 +1697,8 @@ void IDkmModuleInstanceLoadNotification.OnModuleInstanceLoad(DkmModuleInstance m
{
log.Debug("Found Lua debugger helper library");

processData.helperDetected = true;

var variableAddress = nativeModuleInstance.FindExportName("luaHelperIsInitialized", IgnoreDataExports: false);

if (variableAddress != null)
Expand Down Expand Up @@ -1812,6 +1816,12 @@ void IDkmModuleInstanceLoadNotification.OnModuleInstanceLoad(DkmModuleInstance m
processData.helperFailed = true;
}
}
else
{
log.Error("Failed to find 'luaHelperIsInitialized' in debug helper library");

processData.helperFailed = true;
}

if (processData.helperInitializationWaitUsed && !processData.helperInitializationWaitActive)
{
Expand Down Expand Up @@ -1972,7 +1982,7 @@ DkmCustomMessage IDkmCustomMessageCallbackReceiver.SendHigher(DkmCustomMessage c
{
log.Debug("Detected Lua initialization");

if (processData.helperInjected && !processData.helperInitialized && !processData.helperFailed && !processData.helperInitializationWaitUsed)
if (processData.helperInjected && processData.helperDetected && !processData.helperInitialized && !processData.helperFailed && !processData.helperInitializationWaitUsed)
{
log.Debug("Helper was injected but hasn't been initialized, suspening thread");

Expand All @@ -1983,6 +1993,26 @@ DkmCustomMessage IDkmCustomMessageCallbackReceiver.SendHigher(DkmCustomMessage c
processData.helperInitializionSuspensionThread = thread;
processData.helperInitializationWaitUsed = true;
}
else if (!processData.helperInjected)
{
log.Warning("Helper hasn't been injected");
}
else if (!processData.helperDetected)
{
log.Warning("Helper hasn't been detected");
}
else if (processData.helperInitialized)
{
log.Debug("Helper already initialized, no need to suspend Lua");
}
else if (processData.helperFailed)
{
log.Warning("Helper initialization has failed");
}
else if (processData.helperInitializationWaitUsed)
{
log.Debug("Lua is already suspended for helper");
}
}
else if (data.breakpointId == processData.breakpointLuaThreadCreate)
{
Expand Down

0 comments on commit b154f21

Please sign in to comment.