Skip to content

Commit

Permalink
handle record-started/stopped events and send updated Capabilities wh…
Browse files Browse the repository at this point in the history
…enever the process is stopped
  • Loading branch information
Trass3r committed Jun 11, 2022
1 parent 6b70195 commit 5ab37ae
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/MICore/CommandFactories/MICommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
Expand Down
12 changes: 12 additions & 0 deletions src/MICore/Debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class Debugger : ITransportCallback
public event EventHandler ThreadCreatedEvent;
public event EventHandler ThreadExitedEvent;
public event EventHandler ThreadGroupExitedEvent;
public event EventHandler RecordStartedEvent;
public event EventHandler RecordStoppedEvent;
public event EventHandler<ResultEventArgs> TelemetryEvent;
private int _exiting;
public ProcessState ProcessState { get; private set; }
Expand Down Expand Up @@ -1446,6 +1448,16 @@ private void OnNotificationOutput(string cmd)
results = _miResults.ParseResultList(cmd.Substring("thread-exited,".Length));
ThreadExitedEvent(this, new ResultEventArgs(results, 0));
}
else if (cmd.StartsWith("record-started,", StringComparison.Ordinal))
{
results = _miResults.ParseResultList(cmd.Substring("record-started,".Length));
RecordStartedEvent(this, new ResultEventArgs(results, 0));
}
else if (cmd.StartsWith("record-stopped,", StringComparison.Ordinal))
{
results = _miResults.ParseResultList(cmd.Substring("record-stopped,".Length));
RecordStoppedEvent(this, new ResultEventArgs(results, 0));
}
else if (cmd.StartsWith("telemetry,", StringComparison.Ordinal))
{
results = _miResults.ParseResultList(cmd.Substring("telemetry,".Length));
Expand Down
23 changes: 22 additions & 1 deletion src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,21 @@ public DebuggedProcess(bool bLaunched, LaunchOptions launchOptions, ISampleEngin
ThreadCache.ThreadGroupExitedEvent(result.Results.FindString("id"));
};

RecordStartedEvent += async delegate (object o, EventArgs args)
{
var result = args as ResultEventArgs;
string threadGroup = result.Results.FindString("thread-group"); // e.g. "i1"
string method = result.Results.FindString("method"); // e.g. "full"
await UpdateTargetFeatures();
};

RecordStoppedEvent += async delegate (object o, EventArgs args)
{
var result = args as ResultEventArgs;
string threadGroup = result.Results.FindString("thread-group"); // e.g. "i1"
await UpdateTargetFeatures();
};

TelemetryEvent += (object o, ResultEventArgs args) =>
{
string eventName;
Expand Down Expand Up @@ -541,6 +556,12 @@ private async Task EnsureModulesLoaded()
}
}

private async Task UpdateTargetFeatures()
{
TargetFeatures = await MICommandFactory.GetTargetFeatures();
// TODO: notify OpenDebugAD7 to run AD7DebugSession.UpdateCapabilities
}

public async Task Initialize(HostWaitLoop waitLoop, CancellationToken token)
{
bool success = false;
Expand Down Expand Up @@ -602,7 +623,7 @@ public async Task Initialize(HostWaitLoop waitLoop, CancellationToken token)
}
}
// now the exe is loaded and we can check target features
TargetFeatures = await MICommandFactory.GetTargetFeatures();
await UpdateTargetFeatures();

success = true;
}
Expand Down
42 changes: 25 additions & 17 deletions src/OpenDebugAD7/AD7DebugSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public void BeforeContinue()
m_gotoCodeContexts.Clear();
}

public void Stopped(IDebugThread2 thread)
private void Stopped(IDebugThread2 thread)
{
Debug.Assert(m_variableManager.IsEmpty(), "Why do we have variable handles?");
Debug.Assert(m_frameHandles.IsEmpty, "Why do we have frame handles?");
Expand All @@ -537,6 +537,7 @@ public void Stopped(IDebugThread2 thread)
internal void FireStoppedEvent(IDebugThread2 thread, StoppedEvent.ReasonValue reason, string text = null)
{
Stopped(thread);
UpdateCapabilities();

// Switch to another thread as engines may not expect to be called back on their event thread
ThreadPool.QueueUserWorkItem((o) =>
Expand Down Expand Up @@ -1033,6 +1034,27 @@ protected override void HandleInitializeRequestAsync(IRequestResponder<Initializ
responder.SetResponse(initializeResponse);
}

private bool m_canReverse = false;
private void UpdateCapabilities()
{
bool canReverse = ((IDebugReversibleEngineProgram160)m_engine).CanReverse() == HRConstants.S_OK;
if (canReverse == m_canReverse)
return;

m_canReverse = canReverse;
Protocol.SendEvent(new CapabilitiesEvent()
{
Capabilities = new InitializeResponse()
{
SupportsStepBack = canReverse,
ExceptionBreakpointFilters = null, // FIXME: this is just to prevent unwanted response entries
CompletionTriggerCharacters = null,
AdditionalModuleColumns = null,
SupportedChecksumAlgorithms = null,
}
});
}

protected override void HandleLaunchRequestAsync(IRequestResponder<LaunchArguments> responder)
{
const string telemetryEventName = DebuggerTelemetry.TelemetryLaunchEventName;
Expand Down Expand Up @@ -1161,13 +1183,7 @@ protected override void HandleLaunchRequestAsync(IRequestResponder<LaunchArgumen
eb.ThrowHR(hr);
}

Protocol.SendEvent(new CapabilitiesEvent()
{
Capabilities = new InitializeResponse()
{
SupportsStepBack = ((IDebugReversibleEngineProgram160)m_engine).CanReverse() == HRConstants.S_OK
}
});
UpdateCapabilities();

hr = m_engineLaunch.ResumeProcess(m_process);
if (hr < 0)
Expand Down Expand Up @@ -1364,13 +1380,7 @@ protected override void HandleAttachRequestAsync(IRequestResponder<AttachArgumen
eb.ThrowHR(hr);
}

Protocol.SendEvent(new CapabilitiesEvent()
{
Capabilities = new InitializeResponse()
{
SupportsStepBack = ((IDebugReversibleEngineProgram160)m_engine).CanReverse() == HRConstants.S_OK
}
});
UpdateCapabilities();

hr = m_engineLaunch.ResumeProcess(m_process);
if (hr < 0)
Expand Down Expand Up @@ -3501,8 +3511,6 @@ public void HandleIDebugBreakEvent2(IDebugEngine2 pEngine, IDebugProcess2 pProce

public void HandleIDebugExceptionEvent2(IDebugEngine2 pEngine, IDebugProcess2 pProcess, IDebugProgram2 pProgram, IDebugThread2 pThread, IDebugEvent2 pEvent)
{
Stopped(pThread);

IDebugExceptionEvent2 exceptionEvent = (IDebugExceptionEvent2)pEvent;

string exceptionDescription;
Expand Down
4 changes: 2 additions & 2 deletions src/OpenDebugAD7/OpenDebug/CustomProtocolObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace OpenDebug.CustomProtocolObjects
{
public class OpenDebugStoppedEvent : DebugEvent
public sealed class OpenDebugStoppedEvent : DebugEvent
{
// Summary:
// Protocol type for this event.
Expand Down Expand Up @@ -67,7 +67,7 @@ public OpenDebugStoppedEvent() : base(EventType)
public int Column { get; set; }
}

public class OpenDebugThread : Thread
public sealed class OpenDebugThread : Thread
{
public OpenDebugThread(int id, string name) : base()
{
Expand Down

0 comments on commit 5ab37ae

Please sign in to comment.