{"push_id":1046353359,"size":1,"distinct_size":1,"ref":"refs/heads/master","head":"a03dbed49da4b210dc17eedda0ac4924d3d21479","before":"dc4376e29e763a95ba3eb0aae2f550595afbf183","commits":[{"sha":"a03dbed49da4b210dc17eedda0ac4924d3d21479","author":{"email":"145cd9ce43438a13beb2c4f51a87276bf83881e7@apple.com","name":"Greg Clayton"},"message":"Fixed an issue that could cause debugserver to return two stop reply packets ($T packets) for one \\x03 interrupt. The problem was that when a \\x03 byte is sent to debugserver while the process is running, and up calling:\n\nrnb_err_t\nRNBRemote::HandlePacket_stop_process (const char *p)\n{\n    if (!DNBProcessInterrupt(m_ctx.ProcessID()))\n        HandlePacket_last_signal (NULL);\n    return rnb_success;\n}\n\nIn the call to DNBProcessInterrupt we did:\n\nnub_bool_t\nDNBProcessInterrupt(nub_process_t pid)\n{\n    MachProcessSP procSP;\n    if (GetProcessSP (pid, procSP))\n        return procSP->Interrupt();\n    return false;\n}\n\nThis would always return false. It would cause HandlePacket_stop_process to always call \"HandlePacket_last_signal (NULL);\" which would send an extra stop reply packet _if_ the process is stopped. On a machine with enough cores, it would call DNBProcessInterrupt(...) and then HandlePacket_last_signal(NULL) so quickly that it will never send out an extra stop reply packet. But if the machine is slow enough or doesn't have enough cores, it could cause the call to HandlePacket_last_signal() to actually succeed and send an extra stop reply packet. This would cause problems up in GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse() where it would get the first stop reply packet and then possibly return or execute an async packet. If it returned, then the next packet that was sent will get the second stop reply as its response. If it executes an async packet, the async packet will get the wrong response.\n\nTo fix this I did the following:\n1 - in debugserver, I fixed \"bool MachProcess::Interrupt()\" to return true if it sends the signal so we avoid sending the stop reply twice on slower machines\n2 - Added a log line to RNBRemote::HandlePacket_stop_process() to say if we ever send an extra stop reply so we will see this in the darwin console output if this does happen\n3 - Added response validators to StringExtractorGDBRemote so that we can verify some responses to some packets. \n4 - Added validators to packets that often follow stop reply packets like the \"m\" packet for memory reads, JSON packets since \"jThreadsInfo\" is often sent immediately following a stop reply.\n5 - Modified GDBRemoteCommunicationClient::SendPacketAndWaitForResponseNoLock() to validate responses. Any \"StringExtractorGDBRemote &response\" that contains a valid response verifier will verify the response and keep looking for correct responses up to 3 times. This will help us get back on track if we do get extra stop replies. If a StringExtractorGDBRemote does not have a response validator, it will accept any packet in response.\n6 - In GDBRemoteCommunicationClient::SendPacketAndWaitForResponse we copy the response validator from the \"response\" argument over into m_async_response so that if we send the packet by interrupting the running process, we can validate the response we actually get in GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse()\n7 - Modified GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse() to always check for an extra stop reply packet for 100ms when the process is interrupted. We were already doing this because we might interrupt a process with a \\x03 packet, yet the process was in the process of stopping due to another reason. This race condition could cause an extra stop reply packet because the GDB remote protocol says if a \\x03 packet is sent while the process is stopped, we should send a stop reply packet back. Now we always check for an extra stop reply packet when we manually interrupt a process.\n\nThe issue was showing up when our IDE would attempt to set a breakpoint while the process is running and this would happen:\n\n--> \\x03\n<-- $T<stop reply 1>\n--> z0,AAAAA,BB (set breakpoint)\n<-- $T<stop reply 1> (incorrect extra stop reply packet)\n--> c\n<-- OK (response from z0 packet)\n\nNow all packet traffic was off by one response. Since we now have a validator on the response for \"z\" packets, we do this:\n\n--> \\x03\n<-- $T<stop reply 1>\n--> z0,AAAAA,BB (set breakpoint)\n<-- $T<stop reply 1> (Ignore this because this can't be the response to z0 packets)\n<-- OK -- (we are back on track as this is a valid response to z0)\n...\n\nAs time goes on we should add more packet validators.\n\n<rdar://problem/22859505>\n\n\n\n\ngit-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@265086 91177308-0d34-0410-b5e6-96231b3b80d8","distinct":true,"url":"https://api.github.com/repos/llvm-project/lldb/commits/a03dbed49da4b210dc17eedda0ac4924d3d21479"}]}