Attempt 1 at remote debugging

This commit is contained in:
Yoshi Askharoun
2023-05-22 18:04:30 -05:00
parent a609530502
commit e675f23cc1
8 changed files with 99 additions and 37 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 233 B

@@ -0,0 +1,24 @@
using Gemini.Framework.Commands;
using System;
using System.ComponentModel.Composition;
using System.Windows.Input;
namespace ZuneUIXTools.Modules.Shell.Commands;
[CommandDefinition]
public class BuildAndDebugCommandDefinition : CommandDefinition
{
public const string CommandName = "Project.BuildAndDebug";
public override string Name => CommandName;
public override string Text => "Start Debugging";
public override string ToolTip => "Compiles the current UIX document, runs it, and attaches the debugger.";
public override Uri IconSource => new("pack://application:,,,/ZuneUIXTools;component/Images/Run_16x.png");
[Export]
public static CommandKeyboardShortcut KeyGesture
= new CommandKeyboardShortcut<BuildAndRunCommandDefinition>(new KeyGesture(Key.F5));
}
@@ -3,22 +3,22 @@ using System;
using System.ComponentModel.Composition;
using System.Windows.Input;
namespace ZuneUIXTools.Modules.Shell.Commands
namespace ZuneUIXTools.Modules.Shell.Commands;
[CommandDefinition]
public class BuildAndRunCommandDefinition : CommandDefinition
{
[CommandDefinition]
public class BuildAndRunCommandDefinition : CommandDefinition
{
public const string CommandName = "Project.BuildAndRun";
public const string CommandName = "Project.BuildAndRun";
public override string Name => CommandName;
public override string Name => CommandName;
public override string Text => "Build and Run";
public override string Text => "Start Without Debugging";
public override string ToolTip => "Compiles the current UIX document and runs it.";
public override string ToolTip => "Compiles the current UIX document and runs it without the debugger.";
public override Uri IconSource => new("pack://application:,,,/ZuneUIXTools;component/Images/StartWithoutDebug_16x.png");
public override Uri IconSource => new("pack://application:,,,/ZuneUIXTools;component/Images/StartWithoutDebug_16x.png");
[Export]
public static CommandKeyboardShortcut KeyGesture = new CommandKeyboardShortcut<BuildAndRunCommandDefinition>(new KeyGesture(Key.F5));
}
[Export]
public static CommandKeyboardShortcut KeyGesture
= new CommandKeyboardShortcut<BuildAndRunCommandDefinition>(new KeyGesture(Key.F5, ModifierKeys.Control));
}
@@ -1,10 +1,5 @@
using Gemini.Framework.ToolBars;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZuneUIXTools.Modules.Shell.Commands;
namespace ZuneUIXTools.Modules.Shell
@@ -18,11 +13,15 @@ namespace ZuneUIXTools.Modules.Shell
public static ToolBarItemGroupDefinition UIXFileToolBarGroup = new(UIXToolBar, 8);
[Export]
public static ToolBarItemDefinition BuildAndRunToolBarItem = new CommandToolBarItemDefinition<BuildAndRunCommandDefinition>(
public static ToolBarItemDefinition BuildAndDebugToolBarItem = new CommandToolBarItemDefinition<BuildAndDebugCommandDefinition>(
UIXFileToolBarGroup, 0, ToolBarItemDisplay.IconAndText);
[Export]
public static ToolBarItemDefinition DecompileToolBarItem = new CommandToolBarItemDefinition<DecompileCommandDefinition>(
public static ToolBarItemDefinition BuildAndRunToolBarItem = new CommandToolBarItemDefinition<BuildAndRunCommandDefinition>(
UIXFileToolBarGroup, 1);
[Export]
public static ToolBarItemDefinition DecompileToolBarItem = new CommandToolBarItemDefinition<DecompileCommandDefinition>(
UIXFileToolBarGroup, 2);
}
}
@@ -40,7 +40,7 @@ namespace ZuneUIXTools.Modules.UIX
Task ICommandHandler<DecompileCommandDefinition>.Run(Command command)
{
Thread _buildThread = new(new ThreadStart(Decompile));
Thread _buildThread = new(new ThreadStart(DecompileCode));
_buildThread.SetApartmentState(ApartmentState.STA);
_buildThread.IsBackground = true;
_buildThread.Start();
@@ -48,7 +48,7 @@ namespace ZuneUIXTools.Modules.UIX
return TaskUtility.Completed;
}
private void Decompile()
private void DecompileCode()
{
try
{
@@ -59,7 +59,7 @@ namespace ZuneUIXTools.Modules.UIX
try
{
Microsoft.Iris.Debug.Bridge bridge = new();
Microsoft.Iris.Debug.BridgeServer bridge = new();
bridge.InterpreterStep += (ctx, entry) => System.Diagnostics.Debug.WriteLine($"[UIXT] [Interpreter] [{ctx}] {entry}");
//IrisApp.Window.RequestLoad("res://ZuneShellResources!Frame.uix#Frame");
@@ -4,6 +4,8 @@ using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using CoreRemoting.Serialization.Binary;
using CoreRemoting;
using Gemini.Framework;
using Gemini.Framework.Commands;
using Gemini.Framework.Threading;
@@ -17,12 +19,14 @@ namespace ZuneUIXTools.Modules.UIXSource
{
[Export(typeof(UIXSourceEditorViewModel))]
#pragma warning disable 659
public class UIXSourceEditorViewModel : UIX.UIXEditorViewModelBase, ICommandHandler<BuildAndRunCommandDefinition>
public class UIXSourceEditorViewModel : UIX.UIXEditorViewModelBase, ICommandHandler<BuildAndRunCommandDefinition>, ICommandHandler<BuildAndDebugCommandDefinition>
#pragma warning restore 659
{
private UIXSourceEditorView _view;
private string _originalText;
public bool CanBuild => !string.IsNullOrWhiteSpace(_view.CodeEditor.Text);
protected override Task DoNew()
{
_originalText = string.Empty;
@@ -67,23 +71,43 @@ namespace ZuneUIXTools.Modules.UIXSource
&& string.Equals(FileName, other.FileName, StringComparison.InvariantCultureIgnoreCase);
}
void ICommandHandler<BuildAndRunCommandDefinition>.Update(Command command)
private void StartBuildAndRun(bool attachDebugger)
{
command.Enabled = !string.IsNullOrWhiteSpace(_view.CodeEditor.Text);
var buildThread = new Thread(BuildAndRun);
buildThread.SetApartmentState(ApartmentState.STA);
buildThread.IsBackground = true;
var debuggerThread = new Thread(() =>
{
// Create and configure new CoreRemoting client
using var client = new RemotingClient(new ClientConfig()
{
ServerHostName = "localhost",
Serializer = new BinarySerializerAdapter(),
MessageEncryption = false,
ServerPort = 9090
});
// Establish connection to server
client.Connect();
// Creates proxy for remote service
var bridge = client.CreateProxy<Microsoft.Iris.Debug.IBridge>();
// Subscribe to debugger events
bridge.DispatcherStep += message =>
Console.WriteLine($"[UIX] [Dispatcher] {message}");
});
debuggerThread.IsBackground = true;
debuggerThread.Start();
buildThread.Start(attachDebugger);
}
Task ICommandHandler<BuildAndRunCommandDefinition>.Run(Command command)
private void BuildAndRun(object parameter)
{
var _buildThread = new Thread(new ThreadStart(BuildAndRun));
_buildThread.SetApartmentState(ApartmentState.STA);
_buildThread.IsBackground = true;
_buildThread.Start();
bool attachDebugger = (bool)parameter;
return TaskUtility.Completed;
}
private void BuildAndRun()
{
string sourceFile = FilePath;
string compiledFile = Path.ChangeExtension(sourceFile, "uib");
bool isSuccess = false;
@@ -153,5 +177,21 @@ namespace ZuneUIXTools.Modules.UIXSource
//});
}
}
void ICommandHandler<BuildAndRunCommandDefinition>.Update(Command command) => command.Enabled = CanBuild;
Task ICommandHandler<BuildAndRunCommandDefinition>.Run(Command command)
{
StartBuildAndRun(false);
return TaskUtility.Completed;
}
void ICommandHandler<BuildAndDebugCommandDefinition>.Update(Command command) => command.Enabled = CanBuild;
Task ICommandHandler<BuildAndDebugCommandDefinition>.Run(Command command)
{
StartBuildAndRun(true);
return TaskUtility.Completed;
}
}
}
-1
View File
@@ -28,7 +28,6 @@
<PackageReference Include="Gemini.Modules.CodeEditor" Version="1.0.60-beta" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
<PackageReference Include="WPFHexaEditor" Version="2.1.7" />
<ProjectReference Include="..\libs\MicrosoftIris\UIX.Debug\UIX.Debug.csproj" />
<ProjectReference Include="..\libs\MicrosoftIris\UIX\UIX.csproj" />
</ItemGroup>