diff options
| author | Eric Christopher <echristo@gmail.com> | 2019-12-10 15:04:02 -0800 |
|---|---|---|
| committer | Eric Christopher <echristo@gmail.com> | 2019-12-10 15:04:45 -0800 |
| commit | 1d41d1bcdfd70cf8f77bb32e2617392395c299a4 (patch) | |
| tree | de9be5c61d0c9efde2ae04ebc507c7f3b770da8c /lldb/include | |
| parent | f4a7d5659df7cb56c1baa34a39e9fe2639472741 (diff) | |
| download | bcm5719-llvm-1d41d1bcdfd70cf8f77bb32e2617392395c299a4.tar.gz bcm5719-llvm-1d41d1bcdfd70cf8f77bb32e2617392395c299a4.zip | |
Revert "Temporarily revert [lldb] e81268d - [lldb/Reproducers] Support multiple GDB remotes"
On multiple retry this issue won't duplicate - will revisit with author if
duplication works again.
This reverts commit c9e0b354e2749ce7ab553974692cb35c8651a869.
Diffstat (limited to 'lldb/include')
| -rw-r--r-- | lldb/include/lldb/Utility/GDBRemote.h | 43 | ||||
| -rw-r--r-- | lldb/include/lldb/Utility/Reproducer.h | 105 |
2 files changed, 101 insertions, 47 deletions
diff --git a/lldb/include/lldb/Utility/GDBRemote.h b/lldb/include/lldb/Utility/GDBRemote.h index b4adeb36852..21b2c8cd73c 100644 --- a/lldb/include/lldb/Utility/GDBRemote.h +++ b/lldb/include/lldb/Utility/GDBRemote.h @@ -9,6 +9,8 @@ #ifndef liblldb_GDBRemote_h_ #define liblldb_GDBRemote_h_ +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Reproducer.h" #include "lldb/Utility/StreamString.h" #include "lldb/lldb-enumerations.h" #include "lldb/lldb-public.h" @@ -69,7 +71,6 @@ struct GDBRemotePacket { std::string data; }; - void Serialize(llvm::raw_ostream &strm) const; void Dump(Stream &strm) const; BinaryData packet; @@ -82,6 +83,46 @@ private: llvm::StringRef GetTypeStr() const; }; +namespace repro { +class PacketRecorder : public AbstractRecorder { +public: + PacketRecorder(const FileSpec &filename, std::error_code &ec) + : AbstractRecorder(filename, ec) {} + + static llvm::Expected<std::unique_ptr<PacketRecorder>> + Create(const FileSpec &filename); + + void Record(const GDBRemotePacket &packet); +}; + +class GDBRemoteProvider : public repro::Provider<GDBRemoteProvider> { +public: + struct Info { + static const char *name; + static const char *file; + }; + + GDBRemoteProvider(const FileSpec &directory) : Provider(directory) {} + + llvm::raw_ostream *GetHistoryStream(); + PacketRecorder *GetNewPacketRecorder(); + + void SetCallback(std::function<void()> callback) { + m_callback = std::move(callback); + } + + void Keep() override; + void Discard() override; + + static char ID; + +private: + std::function<void()> m_callback; + std::unique_ptr<llvm::raw_fd_ostream> m_stream_up; + std::vector<std::unique_ptr<PacketRecorder>> m_packet_recorders; +}; + +} // namespace repro } // namespace lldb_private LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(lldb_private::GDBRemotePacket) diff --git a/lldb/include/lldb/Utility/Reproducer.h b/lldb/include/lldb/Utility/Reproducer.h index ddb1f45a721..0d23fe8571f 100644 --- a/lldb/include/lldb/Utility/Reproducer.h +++ b/lldb/include/lldb/Utility/Reproducer.h @@ -153,24 +153,13 @@ public: static char ID; }; -class DataRecorder { -public: - DataRecorder(const FileSpec &filename, std::error_code &ec) +class AbstractRecorder { +protected: + AbstractRecorder(const FileSpec &filename, std::error_code &ec) : m_filename(filename.GetFilename().GetStringRef()), m_os(filename.GetPath(), ec, llvm::sys::fs::OF_Text), m_record(true) {} - static llvm::Expected<std::unique_ptr<DataRecorder>> - Create(const FileSpec &filename); - - template <typename T> void Record(const T &t, bool newline = false) { - if (!m_record) - return; - m_os << t; - if (newline) - m_os << '\n'; - m_os.flush(); - } - +public: const FileSpec &GetFilename() { return m_filename; } void Stop() { @@ -180,10 +169,30 @@ public: private: FileSpec m_filename; + +protected: llvm::raw_fd_ostream m_os; bool m_record; }; +class DataRecorder : public AbstractRecorder { +public: + DataRecorder(const FileSpec &filename, std::error_code &ec) + : AbstractRecorder(filename, ec) {} + + static llvm::Expected<std::unique_ptr<DataRecorder>> + Create(const FileSpec &filename); + + template <typename T> void Record(const T &t, bool newline = false) { + if (!m_record) + return; + m_os << t; + if (newline) + m_os << '\n'; + m_os.flush(); + } +}; + class CommandProvider : public Provider<CommandProvider> { public: struct Info { @@ -204,32 +213,6 @@ private: std::vector<std::unique_ptr<DataRecorder>> m_data_recorders; }; -class ProcessGDBRemoteProvider - : public repro::Provider<ProcessGDBRemoteProvider> { -public: - struct Info { - static const char *name; - static const char *file; - }; - - ProcessGDBRemoteProvider(const FileSpec &directory) : Provider(directory) {} - - llvm::raw_ostream *GetHistoryStream(); - - void SetCallback(std::function<void()> callback) { - m_callback = std::move(callback); - } - - void Keep() override { m_callback(); } - void Discard() override { m_callback(); } - - static char ID; - -private: - std::function<void()> m_callback; - std::unique_ptr<llvm::raw_fd_ostream> m_stream_up; -}; - /// The generator is responsible for the logic needed to generate a /// reproducer. For doing so it relies on providers, who serialize data that /// is necessary for reproducing a failure. @@ -359,13 +342,43 @@ private: mutable std::mutex m_mutex; }; -/// Helper class for replaying commands through the reproducer. -class CommandLoader { +template <typename T> class MultiLoader { public: - CommandLoader(std::vector<std::string> files) : m_files(files) {} + MultiLoader(std::vector<std::string> files) : m_files(files) {} + + static std::unique_ptr<MultiLoader> Create(Loader *loader) { + if (!loader) + return {}; + + FileSpec file = loader->GetFile<typename T::Info>(); + if (!file) + return {}; + + auto error_or_file = llvm::MemoryBuffer::getFile(file.GetPath()); + if (auto err = error_or_file.getError()) + return {}; - static std::unique_ptr<CommandLoader> Create(Loader *loader); - llvm::Optional<std::string> GetNextFile(); + std::vector<std::string> files; + llvm::yaml::Input yin((*error_or_file)->getBuffer()); + yin >> files; + + if (auto err = yin.error()) + return {}; + + for (auto &file : files) { + FileSpec absolute_path = + loader->GetRoot().CopyByAppendingPathComponent(file); + file = absolute_path.GetPath(); + } + + return std::make_unique<MultiLoader<T>>(std::move(files)); + } + + llvm::Optional<std::string> GetNextFile() { + if (m_index >= m_files.size()) + return {}; + return m_files[m_index++]; + } private: std::vector<std::string> m_files; |

