Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions LuaDebugAttacher_x64/LuaDebugAttacher_x64.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{4D877B09-CA72-4416-B2F9-B4E243C0D51F}</ProjectGuid>
<RootNamespace>LuaDebugAttacherx64</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions LuaDebugHelper_x64/LuaDebugHelper_x64.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
<ProjectGuid>{D0A573AC-3559-4D68-B617-0EEC056FA018}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>LuaDebugHelperx64</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions LuaDebugHelper_x86/LuaDebugHelper_x86.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
<ProjectGuid>{043C0981-A01F-46F4-A19C-FDCD72973492}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>LuaDebugHelperx86</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion LuaDkmDebugger17/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]
23 changes: 23 additions & 0 deletions LuaDkmDebuggerCommon/LuaDkmDebuggerPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public sealed class LuaDkmDebuggerPackage : AsyncPackage
public const int LuaInitializeCommandId = 0x0170;
public const int LuaShowScriptListCommandId = 0x0180;
public const int LuaEvalFuncOnHoverCommandId = 0x0190;
public const int LuaShowInternalMethodsCommandId = 0x0200;

public static readonly Guid CommandSet = new Guid("6EB675D6-C146-4843-990E-32D43B56706C");

Expand All @@ -75,6 +76,7 @@ public sealed class LuaDkmDebuggerPackage : AsyncPackage
public static bool releaseDebugLogs = false;
public static bool showHiddenFrames = false;
public static bool useSchema = false;
public static bool showInternalMethods = false;

private WritableSettingsStore configurationSettingsStore = null;

Expand Down Expand Up @@ -107,6 +109,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
releaseDebugLogs = configurationSettingsStore.GetBoolean("LuaDkmDebugger", "ReleaseDebugLogs", false);
showHiddenFrames = configurationSettingsStore.GetBoolean("LuaDkmDebugger", "ShowHiddenFrames", false);
useSchema = configurationSettingsStore.GetBoolean("LuaDkmDebugger", "UseSchema", false);
showInternalMethods = configurationSettingsStore.GetBoolean("LuaDkmDebugger", "ShowInternalMethods", false);

LuaDkmDebuggerComponent.LocalComponent.attachOnLaunch = attachOnLaunch;
LuaDkmDebuggerComponent.LocalComponent.breakOnError = breakOnError;
Expand Down Expand Up @@ -281,6 +284,26 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke

commandService.AddCommand(menuItem);
}

{
CommandID menuCommandID = new CommandID(CommandSet, LuaShowInternalMethodsCommandId);

OleMenuCommand menuItem = new OleMenuCommand((object sender, EventArgs args) =>
{
HandleToggleMenuItem(sender, args, "ShowInternalMethods", ref LuaDkmDebuggerComponent.LocalComponent.showInternalMethods, ref showInternalMethods);
}, menuCommandID);

menuItem.BeforeQueryStatus += (object sender, EventArgs args) =>
{
if (sender is OleMenuCommand command)
command.Checked = showInternalMethods;
};

menuItem.Enabled = true;
menuItem.Checked = showInternalMethods;

commandService.AddCommand(menuItem);
}
}

try
Expand Down
56 changes: 52 additions & 4 deletions LuaDkmDebuggerComponent/EvaluationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,51 @@
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Xml.Linq;

namespace LuaDkmDebuggerComponent
{
internal class EvaluationHelpers
{
public static bool IsInternalMember(string name)
{
if (name == "__index"
|| (name == "__newindex")
|| (name == "__mode")
|| (name == "__call")
|| (name == "__metatable")
|| (name == "__tostring")
|| (name == "__len")
|| (name == "__name")
|| (name == "__close")
|| (name == "__gc")
//Mathematic Operators
|| (name == "__unm")
|| (name == "__add")
|| (name == "__sub")
|| (name == "__mul")
|| (name == "__div")
|| (name == "__idiv")
|| (name == "__mod")
|| (name == "__pow")
|| (name == "__concat")
|| (name == "__mod")
//Bitwise Operators
|| (name == "__band")
|| (name == "__bor")
|| (name == "__bxor")
|| (name == "__bnot")
|| (name == "__shl")
|| (name == "__shr")
//Equivalence Comparison Operators
|| (name == "__eq")
|| (name == "__lt")
|| (name == "__le"))
return true;

return false;
}

internal static DkmEvaluationResult ExecuteRawExpression(string expression, DkmInspectionSession inspectionSession, DkmThread thread, DkmStackWalkFrame input, DkmRuntimeInstance runtimeInstance, DkmEvaluationFlags flags)
{
var compilerId = new DkmCompilerId(DkmVendorId.Microsoft, DkmLanguageId.Cpp);
Expand Down Expand Up @@ -280,10 +320,13 @@ internal static string EvaluateValueAtLuaValue(DkmProcess process, LuaValueDataB
{
var value = valueBase as LuaValueDataUserData;

type = "user_data";
string luabindClassName = null;
string toStringResult = null;

type = luabindClassName?.Length > 0 ? $"luabind class {luabindClassName} (user_data)" : "user_data";

flags |= DkmEvaluationResultFlags.ReadOnly | DkmEvaluationResultFlags.Expandable;
return $"0x{value.targetAddress:x}";
return toStringResult?.Length > 0 ? $"{toStringResult} (0x{value.targetAddress:x})" : $"0x{value.targetAddress:x}";
}

if (valueBase as LuaValueDataThread != null)
Expand Down Expand Up @@ -461,10 +504,15 @@ internal static DkmEvaluationResult GetTableChildAtIndex(DkmInspectionContext in
isIdentifierName = pos == name.Length;
}

var accessFlag = DkmEvaluationResultAccessType.None;

if (IsInternalMember(name))
accessFlag |= DkmEvaluationResultAccessType.Internal;

if (isIdentifierName)
return EvaluateDataAtLuaValue(inspectionContext, stackFrame, name, $"{fullName}.{name}", node.LoadValue(process, value.batchNodeElementData), DkmEvaluationResultFlags.None, DkmEvaluationResultAccessType.None, DkmEvaluationResultStorageType.None);
return EvaluateDataAtLuaValue(inspectionContext, stackFrame, name, $"{fullName}.{name}", node.LoadValue(process, value.batchNodeElementData), DkmEvaluationResultFlags.None, accessFlag, DkmEvaluationResultStorageType.None);

return EvaluateDataAtLuaValue(inspectionContext, stackFrame, $"\"{name}\"", $"{fullName}[\"{name}\"]", node.LoadValue(process, value.batchNodeElementData), DkmEvaluationResultFlags.None, DkmEvaluationResultAccessType.None, DkmEvaluationResultStorageType.None);
return EvaluateDataAtLuaValue(inspectionContext, stackFrame, $"\"{name}\"", $"{fullName}[\"{name}\"]", node.LoadValue(process, value.batchNodeElementData), DkmEvaluationResultFlags.None, accessFlag, DkmEvaluationResultStorageType.None);
}

index = index - nodeElementCount;
Expand Down
81 changes: 73 additions & 8 deletions LuaDkmDebuggerComponent/ExpressionEvaluation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.VisualStudio.Debugger;
using Microsoft.VisualStudio.Debugger.CallStack;
using Microsoft.VisualStudio.Debugger.Evaluation;
using System.Collections.Generic;

namespace LuaDkmDebuggerComponent
{
Expand Down Expand Up @@ -201,8 +202,8 @@ public LuaValueDataBase LookupTableMember(LuaValueDataTable tableValue, LuaTable
return result;
}

return Report($"Failed to find key '{name}' in table");
}
return Report($"Failed to find key '{name}' in table");
}

public LuaValueDataBase LookupTableElement(LuaValueDataTable table, LuaValueDataBase index)
{
Expand Down Expand Up @@ -513,9 +514,73 @@ public string TryParseIdentifier()

return null;
}
public LuaValueDataBase EvaluateCallExpressions(LuaValueDataBase value, LuaValueDataBase parentValue = null)
{
var currentValue = value;
if (TryTakeToken("("))
{
var argsStart = pos;
if (expression.LastIndexOf(")") == -1)
return Report("Failed to find ')' after '('");

if (process == null)
return Report("Can't load table - process memory is not available");

if (value is LuaValueDataTable indexMetaTableValueTable) //Usefull??
{
value = LookupTableMember(indexMetaTableValueTable, indexMetaTableValueTable.value, "__call");
}
else
{
LuaValueDataBase[] arguments = null;
if (argsStart + 1 != pos) // not a simple call like foo()
{
var savePos = pos = expression.LastIndexOf(")");
var saveExpression = expression;

var argsStr = expression.Substring(argsStart, pos - argsStart);
var argsArray = argsStr.Split(new char[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);
arguments = new LuaValueDataBase[argsArray.Length];
for (int i = 0; i < argsArray.Length; i++)
{
arguments[i] = Evaluate(argsArray[i], allowSideEffects);
}

pos = savePos + 1;
expression = saveExpression;
}

public LuaValueDataBase EvaluatePostExpressions(LuaValueDataBase value)
List<LuaValueDataBase> callArgs = new List<LuaValueDataBase> { value }; // function, (this), function args

if (parentValue != null)
callArgs.Add(parentValue);

if (arguments != null)
callArgs.AddRange(arguments);

if (value is LuaValueDataLuaFunction)
{
value = EvaluateCall(callArgs.ToArray());
}
else if (value is LuaValueDataExternalClosure)
{
value = EvaluateCall(callArgs.ToArray());
}
else
return Report("Failed to evaluate call");
}

if (value as LuaValueDataError != null)
return value;

return EvaluatePostExpressions(value, currentValue);
}

return value;
}
public LuaValueDataBase EvaluatePostExpressions(LuaValueDataBase value, LuaValueDataBase parentValue = null)
{
var currentValue = value;
if (TryTakeToken(".") || TryTakeToken(":"))
{
string name = TryParseIdentifier();
Expand Down Expand Up @@ -557,7 +622,7 @@ public LuaValueDataBase EvaluatePostExpressions(LuaValueDataBase value)
if (value as LuaValueDataError != null)
return value;

return EvaluatePostExpressions(value);
return EvaluatePostExpressions(value, parentValue);
}

if (TryTakeToken("["))
Expand All @@ -583,10 +648,10 @@ public LuaValueDataBase EvaluatePostExpressions(LuaValueDataBase value)
if (value as LuaValueDataError != null)
return value;

return EvaluatePostExpressions(value);
return EvaluatePostExpressions(value, currentValue);
}

return value;
return EvaluateCallExpressions(value, parentValue);
}

// group variable
Expand Down Expand Up @@ -1066,8 +1131,8 @@ public LuaValueDataBase Evaluate(string expression, bool allowSideEffects)

SkipSpace();

if (pos < expression.Length)
return Report(value, $"Failed to fully parse at '{expression.Substring(pos)}'");
if (this.pos < this.expression.Length)
return Report(value, $"Failed to fully parse at '{this.expression.Substring(this.pos)}'");

return value;
}
Expand Down
Loading