|
10 | 10 | import imp
|
11 | 11 | import os
|
12 | 12 | import sys
|
| 13 | +from enum import IntEnum |
13 | 14 | from pathlib import PurePath, Path
|
14 | 15 | from collections import defaultdict, namedtuple
|
15 | 16 |
|
@@ -37,6 +38,26 @@ def _load_com_module():
|
37 | 38 | VSBreakpoint = namedtuple("VSBreakpoint", "path, line, col, cond")
|
38 | 39 |
|
39 | 40 |
|
| 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 | + |
40 | 61 | class VisualStudio(
|
41 | 62 | DebuggerBase, metaclass=abc.ABCMeta
|
42 | 63 | ): # pylint: disable=abstract-method
|
@@ -307,6 +328,20 @@ def set_current_stack_frame(self, idx: int = 0):
|
307 | 328 | )
|
308 | 329 | )
|
309 | 330 |
|
| 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 | + |
310 | 345 | def _get_step_info(self, watches, step_index):
|
311 | 346 | thread = self._debugger.CurrentThread
|
312 | 347 | stackframes = thread.StackFrames
|
@@ -347,16 +382,13 @@ def _get_step_info(self, watches, step_index):
|
347 | 382 | frames[0].loc = loc
|
348 | 383 | state_frames[0].location = SourceLocation(**self._location)
|
349 | 384 |
|
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) |
354 | 386 | program_state = ProgramState(frames=state_frames)
|
355 | 387 |
|
356 | 388 | return StepIR(
|
357 | 389 | step_index=step_index,
|
358 | 390 | frames=frames,
|
359 |
| - stop_reason=reason, |
| 391 | + stop_reason=stop_reason, |
360 | 392 | program_state=program_state,
|
361 | 393 | )
|
362 | 394 |
|
|
0 commit comments