diff options
Diffstat (limited to 'lldb/source/Utility/GDBRemote.cpp')
-rw-r--r-- | lldb/source/Utility/GDBRemote.cpp | 73 |
1 files changed, 64 insertions, 9 deletions
diff --git a/lldb/source/Utility/GDBRemote.cpp b/lldb/source/Utility/GDBRemote.cpp index 85c4bc69a8d1..f267d00fc97e 100644 --- a/lldb/source/Utility/GDBRemote.cpp +++ b/lldb/source/Utility/GDBRemote.cpp @@ -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: @@ -98,8 +93,68 @@ void yaml::MappingTraits<GDBRemotePacket>::mapping(IO &io, StringRef yaml::MappingTraits<GDBRemotePacket>::validate(IO &io, GDBRemotePacket &Packet) { - if (Packet.bytes_transmitted != Packet.packet.data.size()) - return "BinaryData size doesn't match bytes transmitted"; - 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"; |