[lldb/Reproducers] Support multiple GDB remotes
When running the test suite with always capture on, a handful of tests are failing because they have multiple targets and therefore multiple GDB remote connections. The current reproducer infrastructure is capable of dealing with that. This patch reworks the GDB remote provider to support multiple GDB remote connections, similar to how the reproducers support shadowing multiple command interpreter inputs. The provider now keeps a list of packet recorders which deal with a single GDB remote connection. During replay we rely on the order of creation to match the number of packets to the GDB remote connection. Differential revision: https://reviews.llvm.org/D71105
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace lldb;
|
||||
using namespace lldb_private::repro;
|
||||
using namespace lldb_private;
|
||||
using namespace llvm;
|
||||
|
||||
@@ -45,12 +46,6 @@ int StreamGDBRemote::PutEscapedBytes(const void *s, size_t src_len) {
|
||||
return bytes_written;
|
||||
}
|
||||
|
||||
void GDBRemotePacket::Serialize(raw_ostream &strm) const {
|
||||
yaml::Output yout(strm);
|
||||
yout << const_cast<GDBRemotePacket &>(*this);
|
||||
strm.flush();
|
||||
}
|
||||
|
||||
llvm::StringRef GDBRemotePacket::GetTypeStr() const {
|
||||
switch (type) {
|
||||
case GDBRemotePacket::ePacketTypeSend:
|
||||
@@ -103,3 +98,66 @@ yaml::MappingTraits<GDBRemotePacket>::validate(IO &io,
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void GDBRemoteProvider::Keep() {
|
||||
std::vector<std::string> files;
|
||||
for (auto &recorder : m_packet_recorders) {
|
||||
files.push_back(recorder->GetFilename().GetPath());
|
||||
}
|
||||
|
||||
FileSpec file = GetRoot().CopyByAppendingPathComponent(Info::file);
|
||||
std::error_code ec;
|
||||
llvm::raw_fd_ostream os(file.GetPath(), ec, llvm::sys::fs::OF_Text);
|
||||
if (ec)
|
||||
return;
|
||||
yaml::Output yout(os);
|
||||
yout << files;
|
||||
}
|
||||
|
||||
void GDBRemoteProvider::Discard() { m_packet_recorders.clear(); }
|
||||
|
||||
llvm::Expected<std::unique_ptr<PacketRecorder>>
|
||||
PacketRecorder::Create(const FileSpec &filename) {
|
||||
std::error_code ec;
|
||||
auto recorder = std::make_unique<PacketRecorder>(std::move(filename), ec);
|
||||
if (ec)
|
||||
return llvm::errorCodeToError(ec);
|
||||
return std::move(recorder);
|
||||
}
|
||||
|
||||
PacketRecorder *GDBRemoteProvider::GetNewPacketRecorder() {
|
||||
std::size_t i = m_packet_recorders.size() + 1;
|
||||
std::string filename = (llvm::Twine(Info::name) + llvm::Twine("-") +
|
||||
llvm::Twine(i) + llvm::Twine(".yaml"))
|
||||
.str();
|
||||
auto recorder_or_error =
|
||||
PacketRecorder::Create(GetRoot().CopyByAppendingPathComponent(filename));
|
||||
if (!recorder_or_error) {
|
||||
llvm::consumeError(recorder_or_error.takeError());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
m_packet_recorders.push_back(std::move(*recorder_or_error));
|
||||
return m_packet_recorders.back().get();
|
||||
}
|
||||
|
||||
void PacketRecorder::Record(const GDBRemotePacket &packet) {
|
||||
if (!m_record)
|
||||
return;
|
||||
yaml::Output yout(m_os);
|
||||
yout << const_cast<GDBRemotePacket &>(packet);
|
||||
m_os.flush();
|
||||
}
|
||||
|
||||
llvm::raw_ostream *GDBRemoteProvider::GetHistoryStream() {
|
||||
FileSpec history_file = GetRoot().CopyByAppendingPathComponent(Info::file);
|
||||
|
||||
std::error_code EC;
|
||||
m_stream_up = std::make_unique<raw_fd_ostream>(history_file.GetPath(), EC,
|
||||
sys::fs::OpenFlags::OF_Text);
|
||||
return m_stream_up.get();
|
||||
}
|
||||
|
||||
char GDBRemoteProvider::ID = 0;
|
||||
const char *GDBRemoteProvider::Info::file = "gdb-remote.yaml";
|
||||
const char *GDBRemoteProvider::Info::name = "gdb-remote";
|
||||
|
||||
Reference in New Issue
Block a user