martomo / SublimeTextXdebug

Xdebug debugger client for Sublime Text
MIT License
564 stars 89 forks source link

Fix bug: Bad call to watch_expression() in SocketHandler.execute() #134

Open michaelhogg opened 9 years ago

michaelhogg commented 9 years ago

A command (such as run) is sent to the debugger engine on line 197:

S.SESSION.send(command)

The engine could respond with status="stopping". From the DBGP docs:

This 'stopping' state is entered after all execution is complete. For most debugger engine implementations, only a 'stop' command can be accepted at this point

watch_expression() sends an eval command to the engine for each watch expression. If the engine's state is stopping, then it'll probably respond to the eval commands with:

error code 5: command is not available

So it's wrong to call watch_expression() here without checking the engine's state.

watch_expression() should only be called if the engine's state is break, and in fact the code does this on line 249.

mike-code commented 8 years ago

Hi. Is your fix in any way related to this issue? https://github.com/martomo/SublimeTextXdebug/issues/155

michaelhogg commented 8 years ago

@Mike-NetCode: It looks like it could be related.

Looking at @hollusion's Xdebug log in that issue:

<- step_out -i 14
-> <response xmlns="urn:debugger_protocol_v1"
             xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
             command="step_out"
             transaction_id="14"
             status="stopping"
             reason="ok">
    </response>

<- eval -i 15 -- JHJ1bGVz
-> <response xmlns="urn:debugger_protocol_v1"
             xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
             command="eval"
             transaction_id="15">
        <error code="5">
            <message>
                <![CDATA[
                    command is not available
                ]]>
            </message>
        </error>
    </response>

The engine responded to transaction 14 with status="stopping".

An eval command was then sent in transaction 15 with data "$rules" (Base64-encoded as "JHJ1bGVz") which looks like a request to evaluate a watch expression. Since the engine had stopped, it responded with error code 5: command is not available.

ryanpcmcquen commented 5 years ago

I've merged your fixes into my fork: https://github.com/ryanpcmcquen/SublimeTextXdebugPlus

Which I am attempting to get into Package Control: https://github.com/wbond/package_control_channel/pull/7658