Skip to content

Commit

Permalink
Merge pull request #867 from puremourning/thread-state-stepover
Browse files Browse the repository at this point in the history
Fix thread state when stepping over
  • Loading branch information
mergify[bot] committed Jun 9, 2024
2 parents c37d50f + 016cd93 commit ee3bd01
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
19 changes: 8 additions & 11 deletions python3/vimspector/debug_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,27 +794,24 @@ def _DetectSessionFile( self,
@CurrentSession()
@IfConnected()
def StepOver( self, **kwargs ):
if self._stackTraceView.GetCurrentThreadId() is None:
threadId = self._stackTraceView.GetCurrentThreadId()
if threadId is None:
return

def handler( *_ ):
self._stackTraceView.OnContinued( self, { 'threadId': threadId } )
self.ClearCurrentPC()

arguments = {
'threadId': self._stackTraceView.GetCurrentThreadId(),
'threadId': threadId,
'granularity': self._CurrentSteppingGranularity(),
}
arguments.update( kwargs )

if not self._server_capabilities.get( 'supportsSteppingGranularity' ):
arguments.pop( 'granularity' )

self._connection.DoRequest( None, {
self._connection.DoRequest( handler, {
'command': 'next',
'arguments': arguments,
} )

# TODO: WHy is this different from StepInto and StepOut
self._stackTraceView.OnContinued( self )
self.ClearCurrentPC()

@CurrentSession()
@IfConnected()
def StepInto( self, **kwargs ):
Expand Down
28 changes: 15 additions & 13 deletions python3/vimspector/stack_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
class ThreadRequestState:
NO = 0
REQUESTING = 1
PENDING = 2


class Thread:
Expand Down Expand Up @@ -94,7 +93,7 @@ class Session( object ):
threads: typing.List[ Thread ]
session: "DebugSession"
requesting_threads = ThreadRequestState.NO
pending_thread_request = None
pending_thread_requests = []
sources: dict

def __init__( self, session: "DebugSession" ):
Expand Down Expand Up @@ -245,25 +244,23 @@ def LoadThreads( self,
return

if s.requesting_threads != ThreadRequestState.NO:
s.requesting_threads = ThreadRequestState.PENDING
s.pending_thread_request = ( infer_current_frame,
reason,
stopEvent )
s.pending_thread_requests.append(
( infer_current_frame, reason, stopEvent )
)
return

def consume_threads( message ):
s.requesting_threads = ThreadRequestState.NO

requesting = False
if s.requesting_threads == ThreadRequestState.PENDING:
if s.pending_thread_requests:
# We may have hit a thread event, so try again.
# Note that we do have to process this message though to ensure that our
# thread states are all correct.
s.requesting_threads = ThreadRequestState.NO
self.LoadThreads( s.session, *s.pending_thread_request )
next_request = s.pending_thread_requests.pop( 0 )
self.LoadThreads( s.session, *next_request )
requesting = True

s.requesting_threads = ThreadRequestState.NO
s.pending_thread_request = None

if not ( message.get( 'body' ) or {} ).get( 'threads' ):
# This is a protocol error. It is required to return at least one!
# But about 100% of servers break the protocol.
Expand Down Expand Up @@ -324,7 +321,12 @@ def consume_threads( message ):
def failure_handler( reason, msg ):
# Make sure we request them again if the request fails
s.requesting_threads = ThreadRequestState.NO
s.pending_thread_request = None
if s.pending_thread_requests:
# We may have hit a thread event, so try again.
# Note that we do have to process this message though to ensure that our
# thread states are all correct.
next_request = s.pending_thread_requests.pop( 0 )
self.LoadThreads( s.session, *next_request )

s.requesting_threads = ThreadRequestState.REQUESTING
debug_session.Connection().DoRequest( consume_threads, {
Expand Down
2 changes: 1 addition & 1 deletion run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ while true; do
pushd ${TESTDIR} > /dev/null
RUN="${RUN_TEST} --cmd \"${BASEDIR_CMD}\" \
--cmd 'au SwapExists * let v:swapchoice = \"e\"'\
$tt $T"
'$tt' '$T'"

if ${ASCIINEMA} rec -q --cols $SCREENCOLS --rows $SCREENROWS --overwrite --command "${RUN}" $t.cast >&3 && [ -f $t.res ]; then
echo "%PASS: $t PASSED"
Expand Down
4 changes: 2 additions & 2 deletions tests/disassembly.test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ function! Test_Disassembly_StepInGranularity_API_Direct()
"
" Step over instruction
call win_gotoid( g:vimspector_session_windows.code )
call cursor(1,1)
call vimspector#StepIOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 3, 1 )
call WaitForAssert( {->
Expand All @@ -312,7 +313,6 @@ function! Test_Disassembly_StepInGranularity_API_Direct()
" steps from code window are line steps
call win_gotoid( winid )
call vimspector#StepSOver()
call cursor(1,1)
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:buf, s:dpc, 1 )
call WaitForAssert( {->
\ vimspector#test#signs#AssertPCIsAtLineInBuffer( s:fn, 4 )
Expand All @@ -338,6 +338,7 @@ function! Test_Disassembly_StepInGranularity_API_Direct_CodeLLDB()
"
" Step over instruction
call win_gotoid( g:vimspector_session_windows.code )
call cursor(1,1)
call vimspector#StepIOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 3, v:null )
call WaitForAssert( {->
Expand All @@ -348,7 +349,6 @@ function! Test_Disassembly_StepInGranularity_API_Direct_CodeLLDB()
" steps from code window are line steps
call win_gotoid( winid )
call vimspector#StepSOver()
call cursor(1,1)
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:buf, s:dpc, 1 )
call WaitForAssert( {->
\ vimspector#test#signs#AssertPCIsAtLineInBuffer( s:fn, 4 )
Expand Down

0 comments on commit ee3bd01

Please sign in to comment.