[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- StringExtractorGDBRemote.cpp --------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-03-21 00:14:00 +08:00
|
|
|
#include "lldb/Utility/StringExtractorGDBRemote.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2021-05-26 18:19:37 +08:00
|
|
|
#include <cctype>
|
|
|
|
#include <cstring>
|
2017-04-07 02:12:24 +08:00
|
|
|
|
2021-03-30 19:25:06 +08:00
|
|
|
constexpr lldb::pid_t StringExtractorGDBRemote::AllProcesses;
|
|
|
|
constexpr lldb::tid_t StringExtractorGDBRemote::AllThreads;
|
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
StringExtractorGDBRemote::ResponseType
|
|
|
|
StringExtractorGDBRemote::GetResponseType() const {
|
|
|
|
if (m_packet.empty())
|
|
|
|
return eUnsupported;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
switch (m_packet[0]) {
|
2011-03-22 12:00:09 +08:00
|
|
|
case 'E':
|
2017-07-12 19:15:34 +08:00
|
|
|
if (isxdigit(m_packet[1]) && isxdigit(m_packet[2])) {
|
|
|
|
if (m_packet.size() == 3)
|
|
|
|
return eError;
|
|
|
|
llvm::StringRef packet_ref(m_packet);
|
|
|
|
if (packet_ref[3] == ';') {
|
|
|
|
auto err_string = packet_ref.substr(4);
|
|
|
|
for (auto e : err_string)
|
|
|
|
if (!isxdigit(e))
|
|
|
|
return eResponse;
|
|
|
|
return eError;
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case 'O':
|
|
|
|
if (m_packet.size() == 2 && m_packet[1] == 'K')
|
|
|
|
return eOK;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case '+':
|
|
|
|
if (m_packet.size() == 1)
|
|
|
|
return eAck;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case '-':
|
|
|
|
if (m_packet.size() == 1)
|
|
|
|
return eNack;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return eResponse;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
StringExtractorGDBRemote::ServerPacketType
|
2010-06-09 00:52:24 +08:00
|
|
|
StringExtractorGDBRemote::GetServerPacketType() const {
|
2011-04-12 13:54:46 +08:00
|
|
|
#define PACKET_MATCHES(s) \
|
|
|
|
((packet_size == (sizeof(s) - 1)) && (strcmp((packet_cstr), (s)) == 0))
|
|
|
|
#define PACKET_STARTS_WITH(s) \
|
|
|
|
((packet_size >= (sizeof(s) - 1)) && \
|
|
|
|
::strncmp(packet_cstr, s, (sizeof(s) - 1)) == 0)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
// Empty is not a supported packet...
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_packet.empty())
|
|
|
|
return eServerPacketType_invalid;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
const size_t packet_size = m_packet.size();
|
2011-03-22 12:00:09 +08:00
|
|
|
const char *packet_cstr = m_packet.c_str();
|
|
|
|
switch (m_packet[0]) {
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-05-13 17:18:18 +08:00
|
|
|
case '%':
|
|
|
|
return eServerPacketType_notify;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-03-23 08:09:55 +08:00
|
|
|
case '\x03':
|
2011-04-12 13:54:46 +08:00
|
|
|
if (packet_size == 1)
|
2010-06-09 00:52:24 +08:00
|
|
|
return eServerPacketType_interrupt;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
case '-':
|
2011-04-12 13:54:46 +08:00
|
|
|
if (packet_size == 1)
|
|
|
|
return eServerPacketType_nack;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
case '+':
|
2011-04-12 13:54:46 +08:00
|
|
|
if (packet_size == 1)
|
|
|
|
return eServerPacketType_ack;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
case 'A':
|
|
|
|
return eServerPacketType_A;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-03-24 12:28:38 +08:00
|
|
|
case 'Q':
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
switch (packet_cstr[1]) {
|
|
|
|
case 'E':
|
2013-12-06 03:25:45 +08:00
|
|
|
if (PACKET_STARTS_WITH("QEnvironment:"))
|
|
|
|
return eServerPacketType_QEnvironment;
|
|
|
|
if (PACKET_STARTS_WITH("QEnvironmentHexEncoded:"))
|
|
|
|
return eServerPacketType_QEnvironmentHexEncoded;
|
2017-07-12 19:15:34 +08:00
|
|
|
if (PACKET_STARTS_WITH("QEnableErrorStrings"))
|
|
|
|
return eServerPacketType_QEnableErrorStrings;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2017-02-24 17:29:14 +08:00
|
|
|
case 'P':
|
|
|
|
if (PACKET_STARTS_WITH("QPassSignals:"))
|
|
|
|
return eServerPacketType_QPassSignals;
|
2017-07-22 04:20:25 +08:00
|
|
|
break;
|
2017-02-24 17:29:14 +08:00
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
case 'S':
|
2010-06-09 00:52:24 +08:00
|
|
|
if (PACKET_MATCHES("QStartNoAckMode"))
|
|
|
|
return eServerPacketType_QStartNoAckMode;
|
|
|
|
if (PACKET_STARTS_WITH("QSaveRegisterState"))
|
2013-12-06 03:25:45 +08:00
|
|
|
return eServerPacketType_QSaveRegisterState;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (PACKET_STARTS_WITH("QSetDisableASLR:"))
|
2013-12-06 03:25:45 +08:00
|
|
|
return eServerPacketType_QSetDisableASLR;
|
2014-06-25 10:32:56 +08:00
|
|
|
if (PACKET_STARTS_WITH("QSetDetachOnError:"))
|
2010-06-09 00:52:24 +08:00
|
|
|
return eServerPacketType_QSetDetachOnError;
|
2013-12-06 03:25:45 +08:00
|
|
|
if (PACKET_STARTS_WITH("QSetSTDIN:"))
|
2010-06-09 00:52:24 +08:00
|
|
|
return eServerPacketType_QSetSTDIN;
|
2013-12-06 03:25:45 +08:00
|
|
|
if (PACKET_STARTS_WITH("QSetSTDOUT:"))
|
2010-06-09 00:52:24 +08:00
|
|
|
return eServerPacketType_QSetSTDOUT;
|
|
|
|
if (PACKET_STARTS_WITH("QSetSTDERR:"))
|
2013-12-06 03:25:45 +08:00
|
|
|
return eServerPacketType_QSetSTDERR;
|
|
|
|
if (PACKET_STARTS_WITH("QSetWorkingDir:"))
|
|
|
|
return eServerPacketType_QSetWorkingDir;
|
|
|
|
if (PACKET_STARTS_WITH("QSetLogging:"))
|
|
|
|
return eServerPacketType_QSetLogging;
|
2022-05-12 06:10:16 +08:00
|
|
|
if (PACKET_STARTS_WITH("QSetIgnoredExceptions"))
|
|
|
|
return eServerPacketType_QSetIgnoredExceptions;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (PACKET_STARTS_WITH("QSetMaxPacketSize:"))
|
|
|
|
return eServerPacketType_QSetMaxPacketSize;
|
|
|
|
if (PACKET_STARTS_WITH("QSetMaxPayloadSize:"))
|
|
|
|
return eServerPacketType_QSetMaxPayloadSize;
|
|
|
|
if (PACKET_STARTS_WITH("QSetEnableAsyncProfiling;"))
|
|
|
|
return eServerPacketType_QSetEnableAsyncProfiling;
|
2013-12-06 03:25:45 +08:00
|
|
|
if (PACKET_STARTS_WITH("QSyncThreadState:"))
|
|
|
|
return eServerPacketType_QSyncThreadState;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2013-08-27 07:57:52 +08:00
|
|
|
case 'L':
|
2013-12-06 03:25:45 +08:00
|
|
|
if (PACKET_STARTS_WITH("QLaunchArch:"))
|
|
|
|
return eServerPacketType_QLaunchArch;
|
|
|
|
if (PACKET_MATCHES("QListThreadsInStopReply"))
|
|
|
|
return eServerPacketType_QListThreadsInStopReply;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2021-03-31 21:02:34 +08:00
|
|
|
case 'M':
|
|
|
|
if (PACKET_STARTS_WITH("QMemTags"))
|
|
|
|
return eServerPacketType_QMemTags;
|
|
|
|
break;
|
|
|
|
|
2022-04-12 22:21:09 +08:00
|
|
|
case 'N':
|
|
|
|
if (PACKET_STARTS_WITH("QNonStop:"))
|
|
|
|
return eServerPacketType_QNonStop;
|
|
|
|
break;
|
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'R':
|
|
|
|
if (PACKET_STARTS_WITH("QRestoreRegisterState:"))
|
|
|
|
return eServerPacketType_QRestoreRegisterState;
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'T':
|
|
|
|
if (PACKET_MATCHES("QThreadSuffixSupported"))
|
|
|
|
return eServerPacketType_QThreadSuffixSupported;
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
case 'q':
|
2011-04-12 13:54:46 +08:00
|
|
|
switch (packet_cstr[1]) {
|
|
|
|
case 's':
|
|
|
|
if (PACKET_MATCHES("qsProcessInfo"))
|
2010-06-09 00:52:24 +08:00
|
|
|
return eServerPacketType_qsProcessInfo;
|
2013-12-06 03:25:45 +08:00
|
|
|
if (PACKET_MATCHES("qsThreadInfo"))
|
|
|
|
return eServerPacketType_qsThreadInfo;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2015-06-19 04:43:56 +08:00
|
|
|
case 'f':
|
2011-04-12 13:54:46 +08:00
|
|
|
if (PACKET_STARTS_WITH("qfProcessInfo"))
|
|
|
|
return eServerPacketType_qfProcessInfo;
|
2013-12-06 03:25:45 +08:00
|
|
|
if (PACKET_STARTS_WITH("qfThreadInfo"))
|
|
|
|
return eServerPacketType_qfThreadInfo;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
case 'C':
|
|
|
|
if (packet_size == 2)
|
|
|
|
return eServerPacketType_qC;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
case 'E':
|
|
|
|
if (PACKET_STARTS_WITH("qEcho:"))
|
|
|
|
return eServerPacketType_qEcho;
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
case 'F':
|
2011-04-12 13:54:46 +08:00
|
|
|
if (PACKET_STARTS_WITH("qFileLoadAddress:"))
|
2011-03-22 12:00:09 +08:00
|
|
|
return eServerPacketType_qFileLoadAddress;
|
2011-04-12 13:54:46 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-05-13 17:18:18 +08:00
|
|
|
case 'G':
|
2011-04-12 13:54:46 +08:00
|
|
|
if (PACKET_STARTS_WITH("qGroupName:"))
|
|
|
|
return eServerPacketType_qGroupName;
|
2013-11-21 05:07:01 +08:00
|
|
|
if (PACKET_MATCHES("qGetWorkingDir"))
|
|
|
|
return eServerPacketType_qGetWorkingDir;
|
2015-05-13 17:18:18 +08:00
|
|
|
if (PACKET_MATCHES("qGetPid"))
|
|
|
|
return eServerPacketType_qGetPid;
|
2011-04-12 13:54:46 +08:00
|
|
|
if (PACKET_STARTS_WITH("qGetProfileData;"))
|
2013-12-06 03:25:45 +08:00
|
|
|
return eServerPacketType_qGetProfileData;
|
|
|
|
if (PACKET_MATCHES("qGDBServerVersion"))
|
2011-04-12 13:54:46 +08:00
|
|
|
return eServerPacketType_qGDBServerVersion;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
case 'H':
|
|
|
|
if (PACKET_MATCHES("qHostInfo"))
|
|
|
|
return eServerPacketType_qHostInfo;
|
2011-03-23 08:09:55 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
case 'K':
|
2011-04-12 13:54:46 +08:00
|
|
|
if (PACKET_STARTS_WITH("qKillSpawnedProcess"))
|
|
|
|
return eServerPacketType_qKillSpawnedProcess;
|
2011-03-22 12:00:09 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
case 'L':
|
2011-04-12 13:54:46 +08:00
|
|
|
if (PACKET_STARTS_WITH("qLaunchGDBServer"))
|
2013-08-27 07:57:52 +08:00
|
|
|
return eServerPacketType_qLaunchGDBServer;
|
2011-04-12 13:54:46 +08:00
|
|
|
if (PACKET_MATCHES("qLaunchSuccess"))
|
|
|
|
return eServerPacketType_qLaunchSuccess;
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
case 'M':
|
2013-12-06 03:25:45 +08:00
|
|
|
if (PACKET_STARTS_WITH("qMemoryRegionInfo:"))
|
|
|
|
return eServerPacketType_qMemoryRegionInfo;
|
|
|
|
if (PACKET_MATCHES("qMemoryRegionInfo"))
|
|
|
|
return eServerPacketType_qMemoryRegionInfoSupported;
|
2015-02-26 06:15:44 +08:00
|
|
|
if (PACKET_STARTS_WITH("qModuleInfo:"))
|
|
|
|
return eServerPacketType_qModuleInfo;
|
2021-02-19 23:57:59 +08:00
|
|
|
if (PACKET_STARTS_WITH("qMemTags:"))
|
|
|
|
return eServerPacketType_qMemTags;
|
2011-03-22 12:00:09 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
case 'P':
|
2013-11-21 05:07:01 +08:00
|
|
|
if (PACKET_STARTS_WITH("qProcessInfoPID:"))
|
|
|
|
return eServerPacketType_qProcessInfoPID;
|
2013-12-06 03:25:45 +08:00
|
|
|
if (PACKET_STARTS_WITH("qPlatform_shell:"))
|
|
|
|
return eServerPacketType_qPlatform_shell;
|
2013-11-21 05:07:01 +08:00
|
|
|
if (PACKET_STARTS_WITH("qPlatform_mkdir:"))
|
|
|
|
return eServerPacketType_qPlatform_mkdir;
|
|
|
|
if (PACKET_STARTS_WITH("qPlatform_chmod:"))
|
|
|
|
return eServerPacketType_qPlatform_chmod;
|
2013-12-06 03:25:45 +08:00
|
|
|
if (PACKET_MATCHES("qProcessInfo"))
|
2011-04-12 13:54:46 +08:00
|
|
|
return eServerPacketType_qProcessInfo;
|
2020-08-24 23:34:32 +08:00
|
|
|
if (PACKET_STARTS_WITH("qPathComplete:"))
|
|
|
|
return eServerPacketType_qPathComplete;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2015-07-14 09:09:28 +08:00
|
|
|
|
2011-03-24 12:28:38 +08:00
|
|
|
case 'Q':
|
2013-12-06 03:25:45 +08:00
|
|
|
if (PACKET_MATCHES("qQueryGDBServer"))
|
|
|
|
return eServerPacketType_qQueryGDBServer;
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-08-27 07:57:52 +08:00
|
|
|
case 'R':
|
2013-12-06 03:25:45 +08:00
|
|
|
if (PACKET_STARTS_WITH("qRcmd,"))
|
|
|
|
return eServerPacketType_qRcmd;
|
|
|
|
if (PACKET_STARTS_WITH("qRegisterInfo"))
|
|
|
|
return eServerPacketType_qRegisterInfo;
|
2011-04-12 13:54:46 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
case 'S':
|
2021-04-26 19:47:02 +08:00
|
|
|
if (PACKET_STARTS_WITH("qSaveCore"))
|
|
|
|
return eServerPacketType_qLLDBSaveCore;
|
2015-05-29 08:15:15 +08:00
|
|
|
if (PACKET_STARTS_WITH("qSpeedTest:"))
|
2015-06-19 04:43:56 +08:00
|
|
|
return eServerPacketType_qSpeedTest;
|
2011-04-12 13:54:46 +08:00
|
|
|
if (PACKET_MATCHES("qShlibInfoAddr"))
|
|
|
|
return eServerPacketType_qShlibInfoAddr;
|
|
|
|
if (PACKET_MATCHES("qStepPacketSupported"))
|
2013-12-06 03:25:45 +08:00
|
|
|
return eServerPacketType_qStepPacketSupported;
|
|
|
|
if (PACKET_STARTS_WITH("qSupported"))
|
2013-11-21 05:07:01 +08:00
|
|
|
return eServerPacketType_qSupported;
|
2013-12-06 03:25:45 +08:00
|
|
|
if (PACKET_MATCHES("qSyncThreadStateSupported"))
|
|
|
|
return eServerPacketType_qSyncThreadStateSupported;
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'T':
|
|
|
|
if (PACKET_STARTS_WITH("qThreadExtraInfo,"))
|
|
|
|
return eServerPacketType_qThreadExtraInfo;
|
|
|
|
if (PACKET_STARTS_WITH("qThreadStopInfo"))
|
2015-07-16 22:14:35 +08:00
|
|
|
return eServerPacketType_qThreadStopInfo;
|
2016-02-26 09:20:20 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-08-27 07:57:52 +08:00
|
|
|
case 'U':
|
2013-11-21 05:07:01 +08:00
|
|
|
if (PACKET_STARTS_WITH("qUserName:"))
|
2013-12-06 03:25:45 +08:00
|
|
|
return eServerPacketType_qUserName;
|
2013-08-27 07:57:52 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'V':
|
|
|
|
if (PACKET_MATCHES("qVAttachOrWaitSupported"))
|
|
|
|
return eServerPacketType_qVAttachOrWaitSupported;
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'W':
|
|
|
|
if (PACKET_STARTS_WITH("qWatchpointSupportInfo:"))
|
|
|
|
return eServerPacketType_qWatchpointSupportInfo;
|
|
|
|
if (PACKET_MATCHES("qWatchpointSupportInfo"))
|
|
|
|
return eServerPacketType_qWatchpointSupportInfoSupported;
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-14 20:59:37 +08:00
|
|
|
case 'X':
|
Create a generic handler for Xfer packets
Summary:
This is the first of a few patches I have to improve the performance of dynamic module loading on Android.
In this first diff I'll describe the context of my main motivation and will then link to it in the other diffs to avoid repeating myself.
## Motivation
I have a few scenarios where opening a specific feature on an Android app takes around 40s when lldb is attached to it. The reason for that is because 40 modules are dynamicly loaded at that point in time and each one of them is taking ~1s.
## The problem
To learn about new modules we have a breakpoint on a linker function that is called twice whenever a module is loaded. One time just before it's loaded (so lldb can check which modules are loaded) and another right after it's loaded (so lldb can check again which ones are loaded and calculate the diference).
It's figuring out which modules are loaded that is taking quite some time. This is currently done by traversing the linked list of loaded shared libraries that the linker maintains in memory. Each item in the linked list requires its own `x` packet sent to the gdb server (this is android so the network also plays a part). In my scenario there are 400+ loaded libraries and even though we read 0x800 worth of bytes at a time we still make ~180 requests that end up taking 150-200ms.
We also do this twice, once before the module is loaded (state = eAdd) and another right after (state = eConsistent) which easly adds up to ~400ms per module.
## A solution
**Implement `xfer:libraries-svr4` in lldb-server:**
I noticed in the code that loads the new modules that it had support for the `xfer:libraries-svr4` packet (added ~4 years ago to support the ds2 debug server) but we didn't support it in lldb-server. This single packet returns an xml list of all the loaded modules by the process. The advantage is that there's no more need to make 180 requests to read the linked list. Additionally this new requests takes around 10ms.
**More efficient usage of the `xfer:libraries-svr4` packet in lldb:**
When `xfer:libraries-svr4` is available the Process class has a `LoadModules` function that requests this packet and then loads or unloads modules based on the current list of loaded modules by the process.
This is the function that is used by the DYLDRendezvous class to get the list of loaded modules before and after the module is loaded. However, this is really not needed since the LoadModules function already loaded or unloaded the modules accordingly. I changed this strategy to call LoadModules only once (after the process has loaded the module).
**Bugs**
I found a few issues in lldb while implementing this and have submitted independent patches for them.
I tried to devide this into multiple logical patches to make it easier to review and discuss.
## Tests
I wanted to put these set of diffs up before having all the tests up and running to start having them reviewed from a techical point of view. I'm also having some trouble making the tests running on linux so I need more time to make that happen.
# This diff
The `xfer` packages follow the same protocol, they are requested with `xfer:<object>:<read|write>:<annex>:<offset,length>` and a return that starts with `l` or `m` depending if the offset and length covers the entire data or not. Before implementing the `xfer:libraries-svr4` I refactored the `xfer:auxv` to generically handle xfer packets so we can easly add new ones.
The overall structure of the function ends up being:
* Parse the packet into its components: object, offset etc.
* Depending on the object do its own logic to generate the data.
* Return the data based on its size, the requested offset and length.
Reviewers: clayborg, xiaobai, labath
Reviewed By: labath
Subscribers: mgorny, krytarowski, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D62499
llvm-svn: 362982
2019-06-11 04:59:58 +08:00
|
|
|
if (PACKET_STARTS_WITH("qXfer:"))
|
|
|
|
return eServerPacketType_qXfer;
|
2013-12-06 03:25:45 +08:00
|
|
|
break;
|
2011-03-22 12:00:09 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2015-07-14 09:09:28 +08:00
|
|
|
case 'j':
|
2016-09-08 18:07:04 +08:00
|
|
|
if (PACKET_STARTS_WITH("jModulesInfo:"))
|
|
|
|
return eServerPacketType_jModulesInfo;
|
2015-07-27 09:32:58 +08:00
|
|
|
if (PACKET_MATCHES("jSignalsInfo"))
|
|
|
|
return eServerPacketType_jSignalsInfo;
|
2015-07-16 22:14:35 +08:00
|
|
|
if (PACKET_MATCHES("jThreadsInfo"))
|
2013-12-06 03:25:45 +08:00
|
|
|
return eServerPacketType_jThreadsInfo;
|
2020-11-10 05:36:26 +08:00
|
|
|
|
|
|
|
if (PACKET_MATCHES("jLLDBTraceSupported"))
|
|
|
|
return eServerPacketType_jLLDBTraceSupported;
|
|
|
|
if (PACKET_STARTS_WITH("jLLDBTraceStop:"))
|
|
|
|
return eServerPacketType_jLLDBTraceStop;
|
|
|
|
if (PACKET_STARTS_WITH("jLLDBTraceStart:"))
|
|
|
|
return eServerPacketType_jLLDBTraceStart;
|
|
|
|
if (PACKET_STARTS_WITH("jLLDBTraceGetState:"))
|
|
|
|
return eServerPacketType_jLLDBTraceGetState;
|
|
|
|
if (PACKET_STARTS_WITH("jLLDBTraceGetBinaryData:"))
|
|
|
|
return eServerPacketType_jLLDBTraceGetBinaryData;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'v':
|
2013-11-21 05:07:01 +08:00
|
|
|
if (PACKET_STARTS_WITH("vFile:")) {
|
2011-03-22 12:00:09 +08:00
|
|
|
if (PACKET_STARTS_WITH("vFile:open:"))
|
2013-11-21 05:07:01 +08:00
|
|
|
return eServerPacketType_vFile_open;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:close:"))
|
|
|
|
return eServerPacketType_vFile_close;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:pread"))
|
2011-03-22 12:00:09 +08:00
|
|
|
return eServerPacketType_vFile_pread;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:pwrite"))
|
2013-11-21 05:07:01 +08:00
|
|
|
return eServerPacketType_vFile_pwrite;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:size"))
|
|
|
|
return eServerPacketType_vFile_size;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:exists"))
|
|
|
|
return eServerPacketType_vFile_exists;
|
2021-08-11 00:36:11 +08:00
|
|
|
else if (PACKET_STARTS_WITH("vFile:fstat"))
|
|
|
|
return eServerPacketType_vFile_fstat;
|
2013-11-21 05:07:01 +08:00
|
|
|
else if (PACKET_STARTS_WITH("vFile:stat"))
|
|
|
|
return eServerPacketType_vFile_stat;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:mode"))
|
|
|
|
return eServerPacketType_vFile_mode;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:MD5"))
|
|
|
|
return eServerPacketType_vFile_md5;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:symlink"))
|
|
|
|
return eServerPacketType_vFile_symlink;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:unlink"))
|
2011-03-22 12:00:09 +08:00
|
|
|
return eServerPacketType_vFile_unlink;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
} else {
|
2013-12-06 03:25:45 +08:00
|
|
|
if (PACKET_STARTS_WITH("vAttach;"))
|
|
|
|
return eServerPacketType_vAttach;
|
|
|
|
if (PACKET_STARTS_WITH("vAttachWait;"))
|
|
|
|
return eServerPacketType_vAttachWait;
|
|
|
|
if (PACKET_STARTS_WITH("vAttachOrWait;"))
|
|
|
|
return eServerPacketType_vAttachOrWait;
|
2011-03-22 12:00:09 +08:00
|
|
|
if (PACKET_STARTS_WITH("vAttachName;"))
|
2013-12-06 03:25:45 +08:00
|
|
|
return eServerPacketType_vAttachName;
|
2011-03-22 12:00:09 +08:00
|
|
|
if (PACKET_STARTS_WITH("vCont;"))
|
2013-12-06 03:25:45 +08:00
|
|
|
return eServerPacketType_vCont;
|
|
|
|
if (PACKET_MATCHES("vCont?"))
|
|
|
|
return eServerPacketType_vCont_actions;
|
2022-06-12 14:55:41 +08:00
|
|
|
if (PACKET_STARTS_WITH("vKill;"))
|
|
|
|
return eServerPacketType_vKill;
|
2021-08-12 04:58:11 +08:00
|
|
|
if (PACKET_STARTS_WITH("vRun;"))
|
|
|
|
return eServerPacketType_vRun;
|
2022-04-12 22:21:09 +08:00
|
|
|
if (PACKET_MATCHES("vStopped"))
|
|
|
|
return eServerPacketType_vStopped;
|
|
|
|
if (PACKET_MATCHES("vCtrlC"))
|
|
|
|
return eServerPacketType_vCtrlC;
|
|
|
|
break;
|
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2013-12-06 03:25:45 +08:00
|
|
|
case '_':
|
|
|
|
switch (packet_cstr[1]) {
|
|
|
|
case 'M':
|
|
|
|
return eServerPacketType__M;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'm':
|
|
|
|
return eServerPacketType__m;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case '?':
|
|
|
|
if (packet_size == 1)
|
|
|
|
return eServerPacketType_stop_reason;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'c':
|
|
|
|
return eServerPacketType_c;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'C':
|
|
|
|
return eServerPacketType_C;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'D':
|
2021-04-13 23:32:23 +08:00
|
|
|
return eServerPacketType_D;
|
2011-03-22 12:00:09 +08:00
|
|
|
|
|
|
|
case 'g':
|
2019-05-30 15:25:22 +08:00
|
|
|
return eServerPacketType_g;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'G':
|
2011-03-22 12:00:09 +08:00
|
|
|
return eServerPacketType_G;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'H':
|
|
|
|
return eServerPacketType_H;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-02-07 02:32:57 +08:00
|
|
|
case 'I':
|
|
|
|
return eServerPacketType_I;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'k':
|
2011-03-22 12:00:09 +08:00
|
|
|
if (packet_size == 1)
|
|
|
|
return eServerPacketType_k;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'm':
|
|
|
|
return eServerPacketType_m;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'M':
|
|
|
|
return eServerPacketType_M;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'p':
|
|
|
|
return eServerPacketType_p;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'P':
|
|
|
|
return eServerPacketType_P;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 's':
|
|
|
|
if (packet_size == 1)
|
|
|
|
return eServerPacketType_s;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'S':
|
|
|
|
return eServerPacketType_S;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-14 20:59:37 +08:00
|
|
|
case 'x':
|
|
|
|
return eServerPacketType_x;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-14 20:59:37 +08:00
|
|
|
case 'X':
|
|
|
|
return eServerPacketType_X;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'T':
|
|
|
|
return eServerPacketType_T;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'z':
|
2011-03-22 12:00:09 +08:00
|
|
|
if (packet_cstr[1] >= '0' && packet_cstr[1] <= '4')
|
2013-12-06 03:25:45 +08:00
|
|
|
return eServerPacketType_z;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2013-12-06 03:25:45 +08:00
|
|
|
case 'Z':
|
|
|
|
if (packet_cstr[1] >= '0' && packet_cstr[1] <= '4')
|
|
|
|
return eServerPacketType_Z;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-12-06 03:25:45 +08:00
|
|
|
return eServerPacketType_unimplemented;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
bool StringExtractorGDBRemote::IsOKResponse() const {
|
|
|
|
return GetResponseType() == eOK;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
bool StringExtractorGDBRemote::IsUnsupportedResponse() const {
|
|
|
|
return GetResponseType() == eUnsupported;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
bool StringExtractorGDBRemote::IsNormalResponse() const {
|
|
|
|
return GetResponseType() == eResponse;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
bool StringExtractorGDBRemote::IsErrorResponse() const {
|
2017-07-12 19:15:34 +08:00
|
|
|
return GetResponseType() == eError && isxdigit(m_packet[1]) &&
|
|
|
|
isxdigit(m_packet[2]);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t StringExtractorGDBRemote::GetError() {
|
2011-03-22 12:00:09 +08:00
|
|
|
if (GetResponseType() == eError) {
|
2010-06-09 00:52:24 +08:00
|
|
|
SetFilePos(1);
|
|
|
|
return GetHexU8(255);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2013-08-27 07:57:52 +08:00
|
|
|
|
2017-07-12 19:15:34 +08:00
|
|
|
lldb_private::Status StringExtractorGDBRemote::GetStatus() {
|
|
|
|
lldb_private::Status error;
|
|
|
|
if (GetResponseType() == eError) {
|
|
|
|
SetFilePos(1);
|
|
|
|
uint8_t errc = GetHexU8(255);
|
|
|
|
error.SetError(errc, lldb::eErrorTypeGeneric);
|
|
|
|
|
2017-07-12 19:54:17 +08:00
|
|
|
error.SetErrorStringWithFormat("Error %u", errc);
|
|
|
|
std::string error_messg;
|
|
|
|
if (GetChar() == ';') {
|
2017-07-12 19:15:34 +08:00
|
|
|
GetHexByteString(error_messg);
|
2017-07-12 19:54:17 +08:00
|
|
|
error.SetErrorString(error_messg);
|
|
|
|
}
|
2017-07-12 19:15:34 +08:00
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2013-08-27 07:57:52 +08:00
|
|
|
size_t StringExtractorGDBRemote::GetEscapedBinaryData(std::string &str) {
|
2014-09-18 08:20:51 +08:00
|
|
|
// Just get the data bytes in the string as
|
2018-05-01 00:49:04 +08:00
|
|
|
// GDBRemoteCommunication::CheckForPacket() already removes any 0x7d escaped
|
|
|
|
// characters. If any 0x7d characters are left in the packet, then they are
|
|
|
|
// supposed to be there...
|
2013-08-27 07:57:52 +08:00
|
|
|
str.clear();
|
2014-09-18 08:20:51 +08:00
|
|
|
const size_t bytes_left = GetBytesLeft();
|
|
|
|
if (bytes_left > 0) {
|
|
|
|
str.assign(m_packet, m_index, bytes_left);
|
|
|
|
m_index += bytes_left;
|
2013-08-27 07:57:52 +08:00
|
|
|
}
|
|
|
|
return str.size();
|
|
|
|
}
|
|
|
|
|
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:
rnb_err_t
RNBRemote::HandlePacket_stop_process (const char *p)
{
if (!DNBProcessInterrupt(m_ctx.ProcessID()))
HandlePacket_last_signal (NULL);
return rnb_success;
}
In the call to DNBProcessInterrupt we did:
nub_bool_t
DNBProcessInterrupt(nub_process_t pid)
{
MachProcessSP procSP;
if (GetProcessSP (pid, procSP))
return procSP->Interrupt();
return false;
}
This 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.
To fix this I did the following:
1 - 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
2 - 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
3 - Added response validators to StringExtractorGDBRemote so that we can verify some responses to some packets.
4 - 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.
5 - 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.
6 - 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()
7 - 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.
The issue was showing up when our IDE would attempt to set a breakpoint while the process is running and this would happen:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (incorrect extra stop reply packet)
--> c
<-- OK (response from z0 packet)
Now all packet traffic was off by one response. Since we now have a validator on the response for "z" packets, we do this:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (Ignore this because this can't be the response to z0 packets)
<-- OK -- (we are back on track as this is a valid response to z0)
...
As time goes on we should add more packet validators.
<rdar://problem/22859505>
llvm-svn: 265086
2016-04-01 08:41:29 +08:00
|
|
|
static bool
|
|
|
|
OKErrorNotSupportedResponseValidator(void *,
|
|
|
|
const StringExtractorGDBRemote &response) {
|
|
|
|
switch (response.GetResponseType()) {
|
|
|
|
case StringExtractorGDBRemote::eOK:
|
|
|
|
case StringExtractorGDBRemote::eError:
|
|
|
|
case StringExtractorGDBRemote::eUnsupported:
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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:
rnb_err_t
RNBRemote::HandlePacket_stop_process (const char *p)
{
if (!DNBProcessInterrupt(m_ctx.ProcessID()))
HandlePacket_last_signal (NULL);
return rnb_success;
}
In the call to DNBProcessInterrupt we did:
nub_bool_t
DNBProcessInterrupt(nub_process_t pid)
{
MachProcessSP procSP;
if (GetProcessSP (pid, procSP))
return procSP->Interrupt();
return false;
}
This 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.
To fix this I did the following:
1 - 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
2 - 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
3 - Added response validators to StringExtractorGDBRemote so that we can verify some responses to some packets.
4 - 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.
5 - 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.
6 - 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()
7 - 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.
The issue was showing up when our IDE would attempt to set a breakpoint while the process is running and this would happen:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (incorrect extra stop reply packet)
--> c
<-- OK (response from z0 packet)
Now all packet traffic was off by one response. Since we now have a validator on the response for "z" packets, we do this:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (Ignore this because this can't be the response to z0 packets)
<-- OK -- (we are back on track as this is a valid response to z0)
...
As time goes on we should add more packet validators.
<rdar://problem/22859505>
llvm-svn: 265086
2016-04-01 08:41:29 +08:00
|
|
|
case StringExtractorGDBRemote::eAck:
|
|
|
|
case StringExtractorGDBRemote::eNack:
|
|
|
|
case StringExtractorGDBRemote::eResponse:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool JSONResponseValidator(void *,
|
|
|
|
const StringExtractorGDBRemote &response) {
|
|
|
|
switch (response.GetResponseType()) {
|
|
|
|
case StringExtractorGDBRemote::eUnsupported:
|
|
|
|
case StringExtractorGDBRemote::eError:
|
|
|
|
return true; // Accept unsupported or EXX as valid responses
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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:
rnb_err_t
RNBRemote::HandlePacket_stop_process (const char *p)
{
if (!DNBProcessInterrupt(m_ctx.ProcessID()))
HandlePacket_last_signal (NULL);
return rnb_success;
}
In the call to DNBProcessInterrupt we did:
nub_bool_t
DNBProcessInterrupt(nub_process_t pid)
{
MachProcessSP procSP;
if (GetProcessSP (pid, procSP))
return procSP->Interrupt();
return false;
}
This 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.
To fix this I did the following:
1 - 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
2 - 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
3 - Added response validators to StringExtractorGDBRemote so that we can verify some responses to some packets.
4 - 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.
5 - 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.
6 - 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()
7 - 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.
The issue was showing up when our IDE would attempt to set a breakpoint while the process is running and this would happen:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (incorrect extra stop reply packet)
--> c
<-- OK (response from z0 packet)
Now all packet traffic was off by one response. Since we now have a validator on the response for "z" packets, we do this:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (Ignore this because this can't be the response to z0 packets)
<-- OK -- (we are back on track as this is a valid response to z0)
...
As time goes on we should add more packet validators.
<rdar://problem/22859505>
llvm-svn: 265086
2016-04-01 08:41:29 +08:00
|
|
|
case StringExtractorGDBRemote::eOK:
|
|
|
|
case StringExtractorGDBRemote::eAck:
|
|
|
|
case StringExtractorGDBRemote::eNack:
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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:
rnb_err_t
RNBRemote::HandlePacket_stop_process (const char *p)
{
if (!DNBProcessInterrupt(m_ctx.ProcessID()))
HandlePacket_last_signal (NULL);
return rnb_success;
}
In the call to DNBProcessInterrupt we did:
nub_bool_t
DNBProcessInterrupt(nub_process_t pid)
{
MachProcessSP procSP;
if (GetProcessSP (pid, procSP))
return procSP->Interrupt();
return false;
}
This 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.
To fix this I did the following:
1 - 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
2 - 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
3 - Added response validators to StringExtractorGDBRemote so that we can verify some responses to some packets.
4 - 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.
5 - 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.
6 - 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()
7 - 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.
The issue was showing up when our IDE would attempt to set a breakpoint while the process is running and this would happen:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (incorrect extra stop reply packet)
--> c
<-- OK (response from z0 packet)
Now all packet traffic was off by one response. Since we now have a validator on the response for "z" packets, we do this:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (Ignore this because this can't be the response to z0 packets)
<-- OK -- (we are back on track as this is a valid response to z0)
...
As time goes on we should add more packet validators.
<rdar://problem/22859505>
llvm-svn: 265086
2016-04-01 08:41:29 +08:00
|
|
|
case StringExtractorGDBRemote::eResponse:
|
|
|
|
// JSON that is returned in from JSON query packets is currently always
|
2018-05-01 00:49:04 +08:00
|
|
|
// either a dictionary which starts with a '{', or an array which starts
|
|
|
|
// with a '['. This is a quick validator to just make sure the response
|
|
|
|
// could be valid JSON without having to validate all of the
|
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:
rnb_err_t
RNBRemote::HandlePacket_stop_process (const char *p)
{
if (!DNBProcessInterrupt(m_ctx.ProcessID()))
HandlePacket_last_signal (NULL);
return rnb_success;
}
In the call to DNBProcessInterrupt we did:
nub_bool_t
DNBProcessInterrupt(nub_process_t pid)
{
MachProcessSP procSP;
if (GetProcessSP (pid, procSP))
return procSP->Interrupt();
return false;
}
This 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.
To fix this I did the following:
1 - 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
2 - 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
3 - Added response validators to StringExtractorGDBRemote so that we can verify some responses to some packets.
4 - 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.
5 - 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.
6 - 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()
7 - 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.
The issue was showing up when our IDE would attempt to set a breakpoint while the process is running and this would happen:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (incorrect extra stop reply packet)
--> c
<-- OK (response from z0 packet)
Now all packet traffic was off by one response. Since we now have a validator on the response for "z" packets, we do this:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (Ignore this because this can't be the response to z0 packets)
<-- OK -- (we are back on track as this is a valid response to z0)
...
As time goes on we should add more packet validators.
<rdar://problem/22859505>
llvm-svn: 265086
2016-04-01 08:41:29 +08:00
|
|
|
// JSON content.
|
|
|
|
switch (response.GetStringRef()[0]) {
|
|
|
|
case '{':
|
|
|
|
return true;
|
|
|
|
case '[':
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
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:
rnb_err_t
RNBRemote::HandlePacket_stop_process (const char *p)
{
if (!DNBProcessInterrupt(m_ctx.ProcessID()))
HandlePacket_last_signal (NULL);
return rnb_success;
}
In the call to DNBProcessInterrupt we did:
nub_bool_t
DNBProcessInterrupt(nub_process_t pid)
{
MachProcessSP procSP;
if (GetProcessSP (pid, procSP))
return procSP->Interrupt();
return false;
}
This 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.
To fix this I did the following:
1 - 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
2 - 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
3 - Added response validators to StringExtractorGDBRemote so that we can verify some responses to some packets.
4 - 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.
5 - 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.
6 - 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()
7 - 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.
The issue was showing up when our IDE would attempt to set a breakpoint while the process is running and this would happen:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (incorrect extra stop reply packet)
--> c
<-- OK (response from z0 packet)
Now all packet traffic was off by one response. Since we now have a validator on the response for "z" packets, we do this:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (Ignore this because this can't be the response to z0 packets)
<-- OK -- (we are back on track as this is a valid response to z0)
...
As time goes on we should add more packet validators.
<rdar://problem/22859505>
llvm-svn: 265086
2016-04-01 08:41:29 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ASCIIHexBytesResponseValidator(void *,
|
|
|
|
const StringExtractorGDBRemote &response) {
|
|
|
|
switch (response.GetResponseType()) {
|
|
|
|
case StringExtractorGDBRemote::eUnsupported:
|
|
|
|
case StringExtractorGDBRemote::eError:
|
|
|
|
return true; // Accept unsupported or EXX as valid responses
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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:
rnb_err_t
RNBRemote::HandlePacket_stop_process (const char *p)
{
if (!DNBProcessInterrupt(m_ctx.ProcessID()))
HandlePacket_last_signal (NULL);
return rnb_success;
}
In the call to DNBProcessInterrupt we did:
nub_bool_t
DNBProcessInterrupt(nub_process_t pid)
{
MachProcessSP procSP;
if (GetProcessSP (pid, procSP))
return procSP->Interrupt();
return false;
}
This 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.
To fix this I did the following:
1 - 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
2 - 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
3 - Added response validators to StringExtractorGDBRemote so that we can verify some responses to some packets.
4 - 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.
5 - 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.
6 - 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()
7 - 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.
The issue was showing up when our IDE would attempt to set a breakpoint while the process is running and this would happen:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (incorrect extra stop reply packet)
--> c
<-- OK (response from z0 packet)
Now all packet traffic was off by one response. Since we now have a validator on the response for "z" packets, we do this:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (Ignore this because this can't be the response to z0 packets)
<-- OK -- (we are back on track as this is a valid response to z0)
...
As time goes on we should add more packet validators.
<rdar://problem/22859505>
llvm-svn: 265086
2016-04-01 08:41:29 +08:00
|
|
|
case StringExtractorGDBRemote::eOK:
|
|
|
|
case StringExtractorGDBRemote::eAck:
|
|
|
|
case StringExtractorGDBRemote::eNack:
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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:
rnb_err_t
RNBRemote::HandlePacket_stop_process (const char *p)
{
if (!DNBProcessInterrupt(m_ctx.ProcessID()))
HandlePacket_last_signal (NULL);
return rnb_success;
}
In the call to DNBProcessInterrupt we did:
nub_bool_t
DNBProcessInterrupt(nub_process_t pid)
{
MachProcessSP procSP;
if (GetProcessSP (pid, procSP))
return procSP->Interrupt();
return false;
}
This 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.
To fix this I did the following:
1 - 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
2 - 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
3 - Added response validators to StringExtractorGDBRemote so that we can verify some responses to some packets.
4 - 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.
5 - 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.
6 - 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()
7 - 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.
The issue was showing up when our IDE would attempt to set a breakpoint while the process is running and this would happen:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (incorrect extra stop reply packet)
--> c
<-- OK (response from z0 packet)
Now all packet traffic was off by one response. Since we now have a validator on the response for "z" packets, we do this:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (Ignore this because this can't be the response to z0 packets)
<-- OK -- (we are back on track as this is a valid response to z0)
...
As time goes on we should add more packet validators.
<rdar://problem/22859505>
llvm-svn: 265086
2016-04-01 08:41:29 +08:00
|
|
|
case StringExtractorGDBRemote::eResponse: {
|
|
|
|
uint32_t valid_count = 0;
|
|
|
|
for (const char ch : response.GetStringRef()) {
|
|
|
|
if (!isxdigit(ch)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (++valid_count >= 16)
|
|
|
|
break; // Don't validate all the characters in case the packet is very
|
|
|
|
// large
|
|
|
|
}
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
} break;
|
|
|
|
}
|
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:
rnb_err_t
RNBRemote::HandlePacket_stop_process (const char *p)
{
if (!DNBProcessInterrupt(m_ctx.ProcessID()))
HandlePacket_last_signal (NULL);
return rnb_success;
}
In the call to DNBProcessInterrupt we did:
nub_bool_t
DNBProcessInterrupt(nub_process_t pid)
{
MachProcessSP procSP;
if (GetProcessSP (pid, procSP))
return procSP->Interrupt();
return false;
}
This 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.
To fix this I did the following:
1 - 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
2 - 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
3 - Added response validators to StringExtractorGDBRemote so that we can verify some responses to some packets.
4 - 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.
5 - 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.
6 - 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()
7 - 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.
The issue was showing up when our IDE would attempt to set a breakpoint while the process is running and this would happen:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (incorrect extra stop reply packet)
--> c
<-- OK (response from z0 packet)
Now all packet traffic was off by one response. Since we now have a validator on the response for "z" packets, we do this:
--> \x03
<-- $T<stop reply 1>
--> z0,AAAAA,BB (set breakpoint)
<-- $T<stop reply 1> (Ignore this because this can't be the response to z0 packets)
<-- OK -- (we are back on track as this is a valid response to z0)
...
As time goes on we should add more packet validators.
<rdar://problem/22859505>
llvm-svn: 265086
2016-04-01 08:41:29 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StringExtractorGDBRemote::CopyResponseValidator(
|
|
|
|
const StringExtractorGDBRemote &rhs) {
|
|
|
|
m_validator = rhs.m_validator;
|
|
|
|
m_validator_baton = rhs.m_validator_baton;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StringExtractorGDBRemote::SetResponseValidator(
|
|
|
|
ResponseValidatorCallback callback, void *baton) {
|
|
|
|
m_validator = callback;
|
|
|
|
m_validator_baton = baton;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StringExtractorGDBRemote::SetResponseValidatorToOKErrorNotSupported() {
|
|
|
|
m_validator = OKErrorNotSupportedResponseValidator;
|
|
|
|
m_validator_baton = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StringExtractorGDBRemote::SetResponseValidatorToASCIIHexBytes() {
|
|
|
|
m_validator = ASCIIHexBytesResponseValidator;
|
|
|
|
m_validator_baton = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StringExtractorGDBRemote::SetResponseValidatorToJSON() {
|
|
|
|
m_validator = JSONResponseValidator;
|
|
|
|
m_validator_baton = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StringExtractorGDBRemote::ValidateResponse() const {
|
|
|
|
// If we have a validator callback, try to validate the callback
|
|
|
|
if (m_validator)
|
|
|
|
return m_validator(m_validator_baton, *this);
|
|
|
|
else
|
|
|
|
return true; // No validator, so response is valid
|
|
|
|
}
|
2021-03-30 19:25:06 +08:00
|
|
|
|
|
|
|
llvm::Optional<std::pair<lldb::pid_t, lldb::tid_t>>
|
|
|
|
StringExtractorGDBRemote::GetPidTid(lldb::pid_t default_pid) {
|
|
|
|
llvm::StringRef view = llvm::StringRef(m_packet).substr(m_index);
|
|
|
|
size_t initial_length = view.size();
|
2022-06-15 22:48:48 +08:00
|
|
|
lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
|
2021-03-30 19:25:06 +08:00
|
|
|
lldb::tid_t tid;
|
|
|
|
|
|
|
|
if (view.consume_front("p")) {
|
|
|
|
// process identifier
|
|
|
|
if (view.consume_front("-1")) {
|
|
|
|
// -1 is a special case
|
|
|
|
pid = AllProcesses;
|
|
|
|
} else if (view.consumeInteger(16, pid) || pid == 0) {
|
|
|
|
// not a valid hex integer OR unsupported pid 0
|
|
|
|
m_index = UINT64_MAX;
|
|
|
|
return llvm::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
// "." must follow if we expect TID too; otherwise, we assume -1
|
|
|
|
if (!view.consume_front(".")) {
|
|
|
|
// update m_index
|
|
|
|
m_index += initial_length - view.size();
|
|
|
|
|
|
|
|
return {{pid, AllThreads}};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// thread identifier
|
|
|
|
if (view.consume_front("-1")) {
|
|
|
|
// -1 is a special case
|
|
|
|
tid = AllThreads;
|
|
|
|
} else if (view.consumeInteger(16, tid) || tid == 0 || pid == AllProcesses) {
|
|
|
|
// not a valid hex integer OR tid 0 OR pid -1 + a specific tid
|
|
|
|
m_index = UINT64_MAX;
|
|
|
|
return llvm::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update m_index
|
|
|
|
m_index += initial_length - view.size();
|
|
|
|
|
2022-06-15 22:48:48 +08:00
|
|
|
return {{pid != LLDB_INVALID_PROCESS_ID ? pid : default_pid, tid}};
|
2021-03-30 19:25:06 +08:00
|
|
|
}
|