Skip to content

Commit

Permalink
Separate stack walk contexts for different requests from Visual Studi…
Browse files Browse the repository at this point in the history
…o to fix jumping frames in call stack window
  • Loading branch information
WheretIB committed May 23, 2020
1 parent 1267332 commit 3a0cf07
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
48 changes: 22 additions & 26 deletions LuaDkmDebuggerComponent/LocalComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ internal class LuaLocalProcessData : DkmDataItem
public string workingDirectory = null;

public LuaDebugConfiguration configuration;
}

internal class LuaStackContextData : DkmDataItem
{
// Stack walk data for multiple switches between Lua and C++
public bool seenLuaFrame = false;
public int skipFrames = 0; // How many Lua frames to skip
Expand Down Expand Up @@ -165,16 +168,7 @@ DkmStackWalkFrame[] IDkmCallStackFilter.FilterNextFrame(DkmStackContext stackCon
{
// null input frame indicates the end of the call stack
if (input == null)
{
var processData = DebugHelpers.GetOrCreateDataItem<LuaLocalProcessData>(stackContext.InspectionSession.Process);

// Reset stack walk frame position
processData.seenLuaFrame = false;
processData.skipFrames = 0;
processData.seenFrames = 0;

return null;
}

if (input.InstructionAddress == null)
return new DkmStackWalkFrame[1] { input };
Expand All @@ -185,6 +179,8 @@ DkmStackWalkFrame[] IDkmCallStackFilter.FilterNextFrame(DkmStackContext stackCon
if (input.BasicSymbolInfo == null)
return new DkmStackWalkFrame[1] { input };

var stackContextData = DebugHelpers.GetOrCreateDataItem<LuaStackContextData>(stackContext);

if (input.BasicSymbolInfo.MethodName == "luaV_execute")
{
var process = stackContext.InspectionSession.Process;
Expand Down Expand Up @@ -390,9 +386,9 @@ DkmStackWalkFrame GetLuaFunctionStackWalkFrame(ulong callInfoAddress, LuaFunctio
if (prevCallInfoData.func == null)
break;

if (processData.skipFrames != 0)
if (stackContextData.skipFrames != 0)
{
processData.skipFrames--;
stackContextData.skipFrames--;

currCallInfoAddress = currCallInfoAddress - (DebugHelpers.Is64Bit(process) ? 40ul : 24ul);
continue;
Expand Down Expand Up @@ -431,8 +427,8 @@ DkmStackWalkFrame GetLuaFunctionStackWalkFrame(ulong callInfoAddress, LuaFunctio

if (currCallLuaFunction.value.isC_5_1 == 0)
{
processData.seenLuaFrame = true;
processData.seenFrames++;
stackContextData.seenLuaFrame = true;
stackContextData.seenFrames++;

var frame = GetLuaFunctionStackWalkFrame(currCallInfoAddress, currCallInfoData, currCallLuaFunction, currFunctionName);

Expand All @@ -445,10 +441,10 @@ DkmStackWalkFrame GetLuaFunctionStackWalkFrame(ulong callInfoAddress, LuaFunctio
}
else
{
if (processData.seenLuaFrame)
if (stackContextData.seenLuaFrame)
{
processData.seenLuaFrame = false;
processData.skipFrames = processData.seenFrames;
stackContextData.seenLuaFrame = false;
stackContextData.skipFrames = stackContextData.seenFrames;
break;
}

Expand Down Expand Up @@ -476,9 +472,9 @@ DkmStackWalkFrame GetLuaFunctionStackWalkFrame(ulong callInfoAddress, LuaFunctio

if (currCallInfoData.func.baseType == LuaBaseType.Function)
{
if (processData.skipFrames != 0)
if (stackContextData.skipFrames != 0)
{
processData.skipFrames--;
stackContextData.skipFrames--;

currCallInfoAddress = currCallInfoData.previousAddress;
continue;
Expand Down Expand Up @@ -529,8 +525,8 @@ DkmStackWalkFrame GetLuaFunctionStackWalkFrame(ulong callInfoAddress, LuaFunctio
if (currCallLuaFunction == null)
break;

processData.seenLuaFrame = true;
processData.seenFrames++;
stackContextData.seenLuaFrame = true;
stackContextData.seenFrames++;

var frame = GetLuaFunctionStackWalkFrame(currCallInfoAddress.Value, currCallInfoData, currCallLuaFunction, currFunctionName);

Expand All @@ -543,10 +539,10 @@ DkmStackWalkFrame GetLuaFunctionStackWalkFrame(ulong callInfoAddress, LuaFunctio
}
else if (currCallInfoData.func.extendedType == LuaExtendedType.ExternalFunction)
{
if (processData.seenLuaFrame)
if (stackContextData.seenLuaFrame)
{
processData.seenLuaFrame = false;
processData.skipFrames = processData.seenFrames;
stackContextData.seenLuaFrame = false;
stackContextData.skipFrames = stackContextData.seenFrames;
break;
}

Expand All @@ -556,10 +552,10 @@ DkmStackWalkFrame GetLuaFunctionStackWalkFrame(ulong callInfoAddress, LuaFunctio
}
else if (currCallInfoData.func.extendedType == LuaExtendedType.ExternalClosure)
{
if (processData.seenLuaFrame)
if (stackContextData.seenLuaFrame)
{
processData.seenLuaFrame = false;
processData.skipFrames = processData.seenFrames;
stackContextData.seenLuaFrame = false;
stackContextData.skipFrames = stackContextData.seenFrames;
break;
}

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ Add `ScriptPaths` key with an array of additional search paths.
### Known Issues:
* This extension will always add Lua module to the application (can be seen in 'Modules' section of the debugger) even when debugging applications with no Lua code (check notes in RemoteComponent.cs)
* Lua 5.2 is assumed to be compiled with LUA_NANTRICK in x86 (deafult configuration)
* When Lua stack frames are separated by C/C++ frames, stepping might display two top Lua call stack blocks in reverse order, double click any frame for Visual Studio to refresh with correct order

0 comments on commit 3a0cf07

Please sign in to comment.