[lldb] [server] Support for multiprocess extension

Add a minimal support for the multiprocess extension in lldb-server.
The server indicates support for it via qSupported, and accepts
thread-ids containing a PID.  However, it still does not support
debugging more than one inferior, so any other PID value results
in an error.

Differential Revision: https://reviews.llvm.org/D98482
This commit is contained in:
Michał Górny
2021-03-30 13:25:06 +02:00
parent af7e1f07ac
commit 6c1a8039de
11 changed files with 431 additions and 10 deletions

View File

@@ -11,6 +11,9 @@
#include <ctype.h>
#include <string.h>
constexpr lldb::pid_t StringExtractorGDBRemote::AllProcesses;
constexpr lldb::tid_t StringExtractorGDBRemote::AllThreads;
StringExtractorGDBRemote::ResponseType
StringExtractorGDBRemote::GetResponseType() const {
if (m_packet.empty())
@@ -606,3 +609,46 @@ bool StringExtractorGDBRemote::ValidateResponse() const {
else
return true; // No validator, so response is valid
}
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();
lldb::pid_t pid = default_pid;
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();
return {{pid, tid}};
}