Skip to content

Commit f0d1ef3

Browse files
committed
Fix for Lua 5.1 frame filter now that we separate Lua function into two types (Lua/C)
1 parent 7067349 commit f0d1ef3

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

LuaDkmDebuggerComponent/LocalComponent.cs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -677,22 +677,23 @@ DkmStackWalkFrame GetLuaFunctionStackWalkFrame(ulong callInfoAddress, LuaFunctio
677677
break;
678678

679679
var currCallLuaFunction = currCallInfoData.func as LuaValueDataLuaFunction;
680+
var currCallExternalClosure = currCallInfoData.func as LuaValueDataExternalClosure;
680681

681-
Debug.Assert(currCallLuaFunction != null);
682+
Debug.Assert(currCallLuaFunction != null || currCallExternalClosure != null);
682683

683-
if (currCallLuaFunction == null)
684+
if (currCallLuaFunction == null && currCallExternalClosure == null)
684685
break;
685686

686687
var prevCallLuaFunction = prevCallInfoData.func as LuaValueDataLuaFunction;
687688

688689
string currFunctionName = "[name unavailable]";
689690

690691
// Can't get function name if calling function is unknown because of a tail call or if call was not from Lua
691-
if (currCallLuaFunction.value.isC_5_1 == 0 && currCallInfoData.tailCallCount_5_1 > 0)
692+
if (currCallInfoData.tailCallCount_5_1 > 0)
692693
{
693694
currFunctionName = $"[name unavailable - tail call]";
694695
}
695-
else if (prevCallLuaFunction != null && prevCallLuaFunction.value.isC_5_1 != 0)
696+
else if (prevCallLuaFunction == null)
696697
{
697698
currFunctionName = $"[name unavailable - not called from Lua]";
698699
}
@@ -705,21 +706,39 @@ DkmStackWalkFrame GetLuaFunctionStackWalkFrame(ulong callInfoAddress, LuaFunctio
705706
stateSymbols = processData.symbolStore.FetchOrCreate(stateAddress.Value);
706707
}
707708

708-
string functionName = stateSymbols.FetchFunctionName(currCallLuaFunction.value.functionAddress);
709-
710-
if (functionName == null)
709+
if (currCallLuaFunction != null)
711710
{
712-
functionName = GetLuaFunctionName(currCallInfoAddress, prevCallInfoDataAddress, currCallLuaFunction.targetAddress);
711+
string functionName = stateSymbols.FetchFunctionName(currCallLuaFunction.value.functionAddress);
712+
713+
if (functionName == null)
714+
{
715+
functionName = GetLuaFunctionName(currCallInfoAddress, prevCallInfoDataAddress, currCallLuaFunction.targetAddress);
716+
717+
if (functionName != null)
718+
stateSymbols.AddFunctionName(currCallLuaFunction.value.functionAddress, functionName);
719+
}
713720

714721
if (functionName != null)
715-
stateSymbols.AddFunctionName(currCallLuaFunction.value.functionAddress, functionName);
722+
currFunctionName = functionName;
716723
}
724+
else if (currCallExternalClosure != null)
725+
{
726+
string functionName = stateSymbols.FetchFunctionName(currCallExternalClosure.value.functionAddress);
717727

718-
if (functionName != null)
719-
currFunctionName = functionName;
728+
if (functionName == null)
729+
{
730+
functionName = GetLuaFunctionName(currCallInfoAddress, prevCallInfoDataAddress, currCallExternalClosure.targetAddress);
731+
732+
if (functionName != null)
733+
stateSymbols.AddFunctionName(currCallExternalClosure.value.functionAddress, functionName);
734+
}
735+
736+
if (functionName != null)
737+
currFunctionName = functionName;
738+
}
720739
}
721740

722-
if (currCallLuaFunction.value.isC_5_1 == 0)
741+
if (currCallLuaFunction != null)
723742
{
724743
stackContextData.seenLuaFrame = true;
725744
stackContextData.seenFrames++;
@@ -744,7 +763,7 @@ DkmStackWalkFrame GetLuaFunctionStackWalkFrame(ulong callInfoAddress, LuaFunctio
744763

745764
stackContextData.seenFrames++;
746765

747-
luaFrames.Add(DkmStackWalkFrame.Create(stackContext.Thread, input.InstructionAddress, input.FrameBase, input.FrameSize, luaFrameFlags, $"[{currFunctionName} C function]", input.Registers, input.Annotations));
766+
luaFrames.Add(DkmStackWalkFrame.Create(stackContext.Thread, input.InstructionAddress, input.FrameBase, input.FrameSize, luaFrameFlags, $"[{currFunctionName} C closure]", input.Registers, input.Annotations));
748767

749768
luaFrameFlags &= ~DkmStackWalkFrameFlags.TopFrame;
750769
}

0 commit comments

Comments
 (0)