Log SharpDbg logs

This commit is contained in:
Matt Parker
2026-01-21 00:50:06 +10:00
parent b3647ef215
commit e27d80b732
2 changed files with 11 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
using System.Diagnostics;
using Ardalis.GuardClauses;
using Microsoft.Extensions.Logging;
using SharpDbg.InMemory;
using SharpIDE.Application.Features.Run;
@@ -7,12 +8,15 @@ namespace SharpIDE.Application.Features.Debugging;
public static class DebuggerProcessStreamHelper
{
public static (Stream Input, Stream Output, bool IsNetCoreDbg) NewDebuggerProcessStreamsForInfo(DebuggerExecutableInfo? debuggerExecutableInfoNullable)
public static (Stream Input, Stream Output, bool IsNetCoreDbg) NewDebuggerProcessStreamsForInfo(DebuggerExecutableInfo? debuggerExecutableInfoNullable, ILogger<DebuggingService> logger)
{
if (debuggerExecutableInfoNullable is not {} debuggerExecutableInfo) throw new ArgumentNullException(nameof(debuggerExecutableInfoNullable), "Debugger executable info cannot be null.");
if (debuggerExecutableInfo.UseInMemorySharpDbg)
{
var (input, output) = SharpDbgInMemory.NewDebugAdapterStreams();
var (input, output) = SharpDbgInMemory.NewDebugAdapterStreams(s =>
{
logger.LogInformation("SharpDbgInMemory: {Message}", s);
});
return (input, output, false);
}
var debuggerExecutablePath = debuggerExecutableInfo.DebuggerExecutablePath;

View File

@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using Ardalis.GuardClauses;
using Microsoft.Diagnostics.NETCore.Client;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol;
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages;
using Newtonsoft.Json.Linq;
@@ -13,17 +14,19 @@ using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
namespace SharpIDE.Application.Features.Debugging;
#pragma warning disable VSTHRD101
public class DebuggingService
public class DebuggingService(ILogger<DebuggingService> logger)
{
private readonly ConcurrentDictionary<DebuggerSessionId, DebugProtocolHost> _debugProtocolHosts = [];
private readonly ILogger<DebuggingService> _logger = logger;
/// <returns>The debugging session ID</returns>
public async Task<DebuggerSessionId> Attach(int debuggeeProcessId, DebuggerExecutableInfo? debuggerExecutableInfo, Dictionary<SharpIdeFile, List<Breakpoint>> breakpointsByFile, SharpIdeProjectModel project, CancellationToken cancellationToken = default)
{
Guard.Against.NegativeOrZero(debuggeeProcessId, nameof(debuggeeProcessId), "Process ID must be a positive integer.");
await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding);
var (inputStream, outputStream, isNetCoreDbg) = DebuggerProcessStreamHelper.NewDebuggerProcessStreamsForInfo(debuggerExecutableInfo);
var (inputStream, outputStream, isNetCoreDbg) = DebuggerProcessStreamHelper.NewDebuggerProcessStreamsForInfo(debuggerExecutableInfo, _logger);
var debugProtocolHost = new DebugProtocolHost(inputStream, outputStream, false);
var initializedEventTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);