Skip to content
Merged
Changes from 2 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 @@ -307,6 +307,30 @@ def set_current_stack_frame(self, idx: int = 0):
)
)

def _translate_stop_reason(self, reason):
# https://learn.microsoft.com/en-us/dotnet/api/envdte.dbgeventreason?view=visualstudiosdk-2022
if reason == 1: # dbgEventReasonNone
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can those magic values (1, 9, 8, ...) be replace for some named constants?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find a way to get them out of the DTE interface. I could name the constants myself, but I'm not sure that really adds anything over what I've got here since they're only used in this one place. wdyt?

Copy link
Member

@CarlosAlbertoEnciso CarlosAlbertoEnciso Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be something like:

dbgEventReasonNone = 1
dbgEventReasonGo = 2
...
if reason == dbgEventReasonNone: 
...

Basically is the same code, but I think it is easy to read.
Otherwise LGTM.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have strong opinions, but in general even if it's only going to be used once I think it's probably better to have something like class VSDebugEventReason(IntEnum): with the correct values added to it.

return None
if reason == 9: # dbgEventReasonBreakpoint
return StopReason.BREAKPOINT
if reason == 8: # dbgEventReasonStep
return StopReason.STEP
if reason == 6: # dbgEventReasonEndProgram
return StopReason.PROGRAM_EXIT
if reason == 11: # dbgEventReasonExceptionNotHandled
return StopReason.ERROR
# Others:
# dbgEventReasonNone = 1
# dbgEventReasonGo = 2
# dbgEventReasonAttachProgram = 3
# dbgEventReasonDetachProgram = 4
# dbgEventReasonLaunchProgram = 5
# dbgEventReasonStopDebugging = 7
# dbgEventReasonExceptionThrown = 10
# dbgEventReasonUserBreak = 12
# dbgEventReasonContextSwitch = 13
return StopReason.OTHER

def _get_step_info(self, watches, step_index):
thread = self._debugger.CurrentThread
stackframes = thread.StackFrames
Expand Down Expand Up @@ -347,16 +371,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