Skip to content

Commit

Permalink
implement step granularity (#1169)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Wang <waan@microsoft.com>
  • Loading branch information
Trass3r and WardenGnaw authored Jul 19, 2021
1 parent 25998a1 commit 9f78a8f
Showing 1 changed file with 53 additions and 37 deletions.
90 changes: 53 additions & 37 deletions src/OpenDebugAD7/AD7DebugSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -618,32 +618,46 @@ private void SetAllExceptions(enum_EXCEPTION_STATE state)
}
}

private void StepInternal(int threadId, enum_STEPKIND stepKind, enum_STEPUNIT stepUnit, string errorMessage)
private void StepInternal(int threadId, enum_STEPKIND stepKind, SteppingGranularity granularity, string errorMessage)
{
// If we are already running ignore additional step requests
if (m_isStopped)
if (!m_isStopped)
return;

IDebugThread2 thread = null;
lock (m_threads)
{
IDebugThread2 thread = null;
lock (m_threads)
if (!m_threads.TryGetValue(threadId, out thread))
{
if (!m_threads.TryGetValue(threadId, out thread))
{
throw new AD7Exception(errorMessage);
}
throw new AD7Exception(errorMessage);
}
}

BeforeContinue();
ErrorBuilder builder = new ErrorBuilder(() => errorMessage);
m_isStepping = true;
try
{
builder.CheckHR(m_program.Step(thread, stepKind, stepUnit));
}
catch (AD7Exception)
{
m_isStopped = true;
throw;
}
BeforeContinue();
ErrorBuilder builder = new ErrorBuilder(() => errorMessage);
m_isStepping = true;

enum_STEPUNIT stepUnit = enum_STEPUNIT.STEP_STATEMENT;
switch (granularity)
{
case SteppingGranularity.Statement:
default:
break;
case SteppingGranularity.Line:
stepUnit = enum_STEPUNIT.STEP_LINE;
break;
case SteppingGranularity.Instruction:
stepUnit = enum_STEPUNIT.STEP_INSTRUCTION;
break;
}
try
{
builder.CheckHR(m_program.Step(thread, stepKind, stepUnit));
}
catch (AD7Exception)
{
m_isStopped = true;
throw;
}
}

Expand Down Expand Up @@ -810,6 +824,7 @@ protected override void HandleInitializeRequestAsync(IRequestResponder<Initializ
SupportsGotoTargetsRequest = true,
SupportsDisassembleRequest = true,
SupportsValueFormattingOptions = true,
SupportsSteppingGranularity = true,
};

responder.SetResponse(initializeResponse);
Expand Down Expand Up @@ -1247,19 +1262,6 @@ protected override void HandleConfigurationDoneRequestAsync(IRequestResponder<Co
responder.SetResponse(new ConfigurationDoneResponse());
}

protected override void HandleNextRequestAsync(IRequestResponder<NextArguments> responder)
{
try
{
StepInternal(responder.Arguments.ThreadId, enum_STEPKIND.STEP_OVER, enum_STEPUNIT.STEP_STATEMENT, AD7Resources.Error_Scenario_Step_Next);
responder.SetResponse(new NextResponse());
}
catch (AD7Exception e)
{
responder.SetError(new ProtocolException(e.Message));
}
}

protected override void HandleContinueRequestAsync(IRequestResponder<ContinueArguments, ContinueResponse> responder)
{
int threadId = responder.Arguments.ThreadId;
Expand Down Expand Up @@ -1301,12 +1303,25 @@ protected override void HandleContinueRequestAsync(IRequestResponder<ContinueArg

protected override void HandleStepInRequestAsync(IRequestResponder<StepInArguments> responder)
{
StepInResponse response = new StepInResponse();
try
{
var granularity = responder.Arguments.Granularity.GetValueOrDefault();
StepInternal(responder.Arguments.ThreadId, enum_STEPKIND.STEP_INTO, granularity, AD7Resources.Error_Scenario_Step_In);
responder.SetResponse(new StepInResponse());
}
catch (AD7Exception e)
{
responder.SetError(new ProtocolException(e.Message));
}
}

protected override void HandleNextRequestAsync(IRequestResponder<NextArguments> responder)
{
try
{
StepInternal(responder.Arguments.ThreadId, enum_STEPKIND.STEP_INTO, enum_STEPUNIT.STEP_STATEMENT, AD7Resources.Error_Scenario_Step_In);
responder.SetResponse(response);
var granularity = responder.Arguments.Granularity.GetValueOrDefault();
StepInternal(responder.Arguments.ThreadId, enum_STEPKIND.STEP_OVER, granularity, AD7Resources.Error_Scenario_Step_Next);
responder.SetResponse(new NextResponse());
}
catch (AD7Exception e)
{
Expand All @@ -1318,7 +1333,8 @@ protected override void HandleStepOutRequestAsync(IRequestResponder<StepOutArgum
{
try
{
StepInternal(responder.Arguments.ThreadId, enum_STEPKIND.STEP_OUT, enum_STEPUNIT.STEP_STATEMENT, AD7Resources.Error_Scenario_Step_Out);
var granularity = responder.Arguments.Granularity.GetValueOrDefault();
StepInternal(responder.Arguments.ThreadId, enum_STEPKIND.STEP_OUT, granularity, AD7Resources.Error_Scenario_Step_Out);
responder.SetResponse(new StepOutResponse());
}
catch (AD7Exception e)
Expand Down

0 comments on commit 9f78a8f

Please sign in to comment.