Skip to content

[dexter] Correctly identify stop-reason while driving VisualStudio #94754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 10, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import imp
import os
import sys
from enum import IntEnum
from pathlib import PurePath, Path
from collections import defaultdict, namedtuple

Expand Down Expand Up @@ -37,6 +38,26 @@ def _load_com_module():
VSBreakpoint = namedtuple("VSBreakpoint", "path, line, col, cond")


# Visual Studio events.
# https://learn.microsoft.com/en-us/dotnet/api/envdte.dbgeventreason?view=visualstudiosdk-2022
class DbgEvent(IntEnum):
dbgEventReasonNone = 1
dbgEventReasonGo = 2
dbgEventReasonAttachProgram = 3
dbgEventReasonDetachProgram = 4
dbgEventReasonLaunchProgram = 5
dbgEventReasonEndProgram = 6
dbgEventReasonStopDebugging = 7
dbgEventReasonStep = 8
dbgEventReasonBreakpoint = 9
dbgEventReasonExceptionThrown = 10
dbgEventReasonExceptionNotHandled = 11
dbgEventReasonUserBreak = 12
dbgEventReasonContextSwitch = 13

first = dbgEventReasonNone
last = dbgEventReasonContextSwitch

class VisualStudio(
DebuggerBase, metaclass=abc.ABCMeta
): # pylint: disable=abstract-method
Expand Down Expand Up @@ -307,6 +328,20 @@ def set_current_stack_frame(self, idx: int = 0):
)
)

def _translate_stop_reason(self, reason):
if reason == DbgEvent.dbgEventReasonNone:
return None
if reason == DbgEvent.dbgEventReasonBreakpoint:
return StopReason.BREAKPOINT
if reason == DbgEvent.dbgEventReasonStep:
return StopReason.STEP
if reason == DbgEvent.dbgEventReasonEndProgram:
return StopReason.PROGRAM_EXIT
if reason == DbgEvent.dbgEventReasonExceptionNotHandled:
return StopReason.ERROR
assert reason <= DbgEvent.last and reason >= DbgEvent.first
return StopReason.OTHER

def _get_step_info(self, watches, step_index):
thread = self._debugger.CurrentThread
stackframes = thread.StackFrames
Expand Down Expand Up @@ -347,16 +382,13 @@ def _get_step_info(self, watches, step_index):
frames[0].loc = loc
state_frames[0].location = SourceLocation(**self._location)

reason = StopReason.BREAKPOINT
if loc.path is None: # pylint: disable=no-member
reason = StopReason.STEP

stop_reason = self._translate_stop_reason(self._debugger.LastBreakReason)
program_state = ProgramState(frames=state_frames)

return StepIR(
step_index=step_index,
frames=frames,
stop_reason=reason,
stop_reason=stop_reason,
program_state=program_state,
)

Expand Down
Loading