Skip to content

Commit

Permalink
Provide stack frame info for finalizers and tail-called functions in …
Browse files Browse the repository at this point in the history
…Lua 5.2/5.3
  • Loading branch information
WheretIB committed May 23, 2020
1 parent f25c3f9 commit 1267332
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions LuaDkmDebuggerComponent/LocalComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,30 +484,6 @@ DkmStackWalkFrame GetLuaFunctionStackWalkFrame(ulong callInfoAddress, LuaFunctio
continue;
}

// Lua is dynamic so function names are implicit, and we have a fun way of getting them

// Check for finalizer
if (currCallInfoData.CheckCallStatusFinalizer())
{
luaFrames.Add(DkmStackWalkFrame.Create(stackContext.Thread, input.InstructionAddress, input.FrameBase, input.FrameSize, luaFrameFlags, $"__gc", input.Registers, input.Annotations));

luaFrameFlags &= ~DkmStackWalkFrameFlags.TopFrame;

currCallInfoAddress = currCallInfoData.previousAddress;
continue;
}

// Can't get function name for tail call
if (currCallInfoData.CheckCallStatusTailCall())
{
luaFrames.Add(DkmStackWalkFrame.Create(stackContext.Thread, input.InstructionAddress, input.FrameBase, input.FrameSize, luaFrameFlags, $"[name unavailable - tail call]", input.Registers, input.Annotations));

luaFrameFlags &= ~DkmStackWalkFrameFlags.TopFrame;

currCallInfoAddress = currCallInfoData.previousAddress;
continue;
}

// Now we need to know what the previous call info used to call us
if (currCallInfoData.previousAddress == 0)
break;
Expand All @@ -520,7 +496,15 @@ DkmStackWalkFrame GetLuaFunctionStackWalkFrame(ulong callInfoAddress, LuaFunctio
string currFunctionName = "[name unavailable]";

// Can't get function name if previous call status is not 'Lua'
if (!prevCallInfoData.CheckCallStatusLua())
if (currCallInfoData.CheckCallStatusFinalizer())
{
currFunctionName = "__gc";
}
else if (currCallInfoData.CheckCallStatusTailCall())
{
currFunctionName = $"[name unavailable - tail call]";
}
else if (!prevCallInfoData.CheckCallStatusLua())
{
currFunctionName = $"[name unavailable - not called from Lua]";
}
Expand Down

0 comments on commit 1267332

Please sign in to comment.