Skip to content

Commit 832b91f

Browse files
authored
[dexter] Correctly identify stop-reason while driving VisualStudio (#94754)
Prior to this patch VisualStudio._get_step_info incorrectly identifies the reason the debugger has stopped. e.g., stepping through a program would be reported as a StopReason.Breakpoint rather than StopReason.Step. Fix. No test added as there are no VisualStudio tests (tested locally).
1 parent e4790ce commit 832b91f

File tree

1 file changed

+37
-5
lines changed
  • cross-project-tests/debuginfo-tests/dexter/dex/debugger/visualstudio

1 file changed

+37
-5
lines changed

cross-project-tests/debuginfo-tests/dexter/dex/debugger/visualstudio/VisualStudio.py

+37-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import imp
1111
import os
1212
import sys
13+
from enum import IntEnum
1314
from pathlib import PurePath, Path
1415
from collections import defaultdict, namedtuple
1516

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

3940

41+
# Visual Studio events.
42+
# https://learn.microsoft.com/en-us/dotnet/api/envdte.dbgeventreason?view=visualstudiosdk-2022
43+
class DbgEvent(IntEnum):
44+
dbgEventReasonNone = 1
45+
dbgEventReasonGo = 2
46+
dbgEventReasonAttachProgram = 3
47+
dbgEventReasonDetachProgram = 4
48+
dbgEventReasonLaunchProgram = 5
49+
dbgEventReasonEndProgram = 6
50+
dbgEventReasonStopDebugging = 7
51+
dbgEventReasonStep = 8
52+
dbgEventReasonBreakpoint = 9
53+
dbgEventReasonExceptionThrown = 10
54+
dbgEventReasonExceptionNotHandled = 11
55+
dbgEventReasonUserBreak = 12
56+
dbgEventReasonContextSwitch = 13
57+
58+
first = dbgEventReasonNone
59+
last = dbgEventReasonContextSwitch
60+
4061
class VisualStudio(
4162
DebuggerBase, metaclass=abc.ABCMeta
4263
): # pylint: disable=abstract-method
@@ -307,6 +328,20 @@ def set_current_stack_frame(self, idx: int = 0):
307328
)
308329
)
309330

331+
def _translate_stop_reason(self, reason):
332+
if reason == DbgEvent.dbgEventReasonNone:
333+
return None
334+
if reason == DbgEvent.dbgEventReasonBreakpoint:
335+
return StopReason.BREAKPOINT
336+
if reason == DbgEvent.dbgEventReasonStep:
337+
return StopReason.STEP
338+
if reason == DbgEvent.dbgEventReasonEndProgram:
339+
return StopReason.PROGRAM_EXIT
340+
if reason == DbgEvent.dbgEventReasonExceptionNotHandled:
341+
return StopReason.ERROR
342+
assert reason <= DbgEvent.last and reason >= DbgEvent.first
343+
return StopReason.OTHER
344+
310345
def _get_step_info(self, watches, step_index):
311346
thread = self._debugger.CurrentThread
312347
stackframes = thread.StackFrames
@@ -347,16 +382,13 @@ def _get_step_info(self, watches, step_index):
347382
frames[0].loc = loc
348383
state_frames[0].location = SourceLocation(**self._location)
349384

350-
reason = StopReason.BREAKPOINT
351-
if loc.path is None: # pylint: disable=no-member
352-
reason = StopReason.STEP
353-
385+
stop_reason = self._translate_stop_reason(self._debugger.LastBreakReason)
354386
program_state = ProgramState(frames=state_frames)
355387

356388
return StepIR(
357389
step_index=step_index,
358390
frames=frames,
359-
stop_reason=reason,
391+
stop_reason=stop_reason,
360392
program_state=program_state,
361393
)
362394

0 commit comments

Comments
 (0)