diff options
Diffstat (limited to 'source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h')
-rw-r--r-- | source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h | 126 |
1 files changed, 103 insertions, 23 deletions
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h index ee2f327..7379bb3 100644 --- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h +++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h @@ -14,6 +14,7 @@ // C++ Includes #include <list> #include <string> +#include <queue> // Other libraries and framework includes // Project includes @@ -27,6 +28,9 @@ #include "Utility/StringExtractorGDBRemote.h" +namespace lldb_private { +namespace process_gdb_remote { + typedef enum { eStoppointInvalid = -1, @@ -37,16 +41,33 @@ typedef enum eWatchpointReadWrite } GDBStoppointType; +enum class CompressionType +{ + None = 0, // no compression + ZlibDeflate, // zlib's deflate compression scheme, requires zlib or Apple's libcompression + LZFSE, // an Apple compression scheme, requires Apple's libcompression + LZ4, // lz compression - called "lz4 raw" in libcompression terms, compat with https://code.google.com/p/lz4/ + LZMA, // Lempel–Ziv–Markov chain algorithm +}; + class ProcessGDBRemote; -class GDBRemoteCommunication : public lldb_private::Communication +class GDBRemoteCommunication : public Communication { public: enum { - eBroadcastBitRunPacketSent = kLoUserBroadcastBit + eBroadcastBitRunPacketSent = kLoUserBroadcastBit, + eBroadcastBitGdbReadThreadGotNotify = kLoUserBroadcastBit << 1 // Sent when we received a notify packet. }; - + + enum class PacketType + { + Invalid = 0, + Standard, + Notify + }; + enum class PacketResult { Success = 0, // Success @@ -59,12 +80,25 @@ public: ErrorDisconnected, // We were disconnected ErrorNoSequenceLock // We couldn't get the sequence lock for a multi-packet request }; + + // Class to change the timeout for a given scope and restore it to the original value when the + // created ScopedTimeout object got out of scope + class ScopedTimeout + { + public: + ScopedTimeout (GDBRemoteCommunication& gdb_comm, uint32_t timeout); + ~ScopedTimeout (); + + private: + GDBRemoteCommunication& m_gdb_comm; + uint32_t m_saved_timeout; + }; + //------------------------------------------------------------------ // Constructors and Destructors //------------------------------------------------------------------ GDBRemoteCommunication(const char *comm_name, - const char *listener_name, - bool is_platform); + const char *listener_name); virtual ~GDBRemoteCommunication(); @@ -83,9 +117,9 @@ public: size_t payload_length); bool - GetSequenceMutex (lldb_private::Mutex::Locker& locker, const char *failure_message = NULL); + GetSequenceMutex (Mutex::Locker& locker, const char *failure_message = NULL); - bool + PacketType CheckForPacket (const uint8_t *src, size_t src_len, StringExtractorGDBRemote &packet); @@ -126,20 +160,20 @@ public: uint32_t GetPacketTimeoutInMicroSeconds () const { - return m_packet_timeout * lldb_private::TimeValue::MicroSecPerSec; + return m_packet_timeout * TimeValue::MicroSecPerSec; } //------------------------------------------------------------------ // Start a debugserver instance on the current host using the // supplied connection URL. //------------------------------------------------------------------ - lldb_private::Error + Error StartDebugserverProcess (const char *hostname, uint16_t in_port, // If set to zero, then out_port will contain the bound port on exit - lldb_private::ProcessLaunchInfo &launch_info, + ProcessLaunchInfo &launch_info, uint16_t &out_port); void - DumpHistory(lldb_private::Stream &strm); + DumpHistory(Stream &strm); protected: @@ -196,10 +230,10 @@ protected: uint32_t bytes_transmitted); void - Dump (lldb_private::Stream &strm) const; + Dump (Stream &strm) const; void - Dump (lldb_private::Log *log) const; + Dump (Log *log) const; bool DidDumpToLog () const @@ -257,33 +291,59 @@ protected: size_t payload_length); PacketResult + ReadPacket (StringExtractorGDBRemote &response, uint32_t timeout_usec, bool sync_on_timeout); + + // Pop a packet from the queue in a thread safe manner + PacketResult + PopPacketFromQueue (StringExtractorGDBRemote &response, uint32_t timeout_usec); + + PacketResult WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtractorGDBRemote &response, - uint32_t timeout_usec); + uint32_t timeout_usec, + bool sync_on_timeout); + + bool + WaitForNotRunningPrivate (const TimeValue *timeout_ptr); + + bool + CompressionIsEnabled () + { + return m_compression_type != CompressionType::None; + } + // If compression is enabled, decompress the packet in m_bytes and update + // m_bytes with the uncompressed version. + // Returns 'true' packet was decompressed and m_bytes is the now-decompressed text. + // Returns 'false' if unable to decompress or if the checksum was invalid. + // + // NB: Once the packet has been decompressed, checksum cannot be computed based + // on m_bytes. The checksum was for the compressed packet. bool - WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr); + DecompressPacket (); //------------------------------------------------------------------ // Classes that inherit from GDBRemoteCommunication can see and modify these //------------------------------------------------------------------ uint32_t m_packet_timeout; + uint32_t m_echo_number; + LazyBool m_supports_qEcho; #ifdef ENABLE_MUTEX_ERROR_CHECKING - lldb_private::TrackingMutex m_sequence_mutex; + TrackingMutex m_sequence_mutex; #else - lldb_private::Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time + Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time #endif - lldb_private::Predicate<bool> m_public_is_running; - lldb_private::Predicate<bool> m_private_is_running; + Predicate<bool> m_public_is_running; + Predicate<bool> m_private_is_running; History m_history; bool m_send_acks; bool m_is_platform; // Set to true if this class represents a platform, // false if this class represents a debug session for // a single process + CompressionType m_compression_type; - lldb_private::Error - StartListenThread (const char *hostname = "127.0.0.1", - uint16_t port = 0); + Error + StartListenThread (const char *hostname = "127.0.0.1", uint16_t port = 0); bool JoinListenThread (); @@ -291,8 +351,25 @@ protected: static lldb::thread_result_t ListenThread (lldb::thread_arg_t arg); + // GDB-Remote read thread + // . this thread constantly tries to read from the communication + // class and stores all packets received in a queue. The usual + // threads read requests simply pop packets off the queue in the + // usual order. + // This setup allows us to intercept and handle async packets, such + // as the notify packet. + + // This method is defined as part of communication.h + // when the read thread gets any bytes it will pass them on to this function + virtual void AppendBytesToCache (const uint8_t * bytes, size_t len, bool broadcast, lldb::ConnectionStatus status); + private: - lldb_private::HostThread m_listen_thread; + + std::queue<StringExtractorGDBRemote> m_packet_queue; // The packet queue + lldb_private::Mutex m_packet_queue_mutex; // Mutex for accessing queue + Condition m_condition_queue_not_empty; // Condition variable to wait for packets + + HostThread m_listen_thread; std::string m_listen_url; //------------------------------------------------------------------ @@ -301,4 +378,7 @@ private: DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunication); }; +} // namespace process_gdb_remote +} // namespace lldb_private + #endif // liblldb_GDBRemoteCommunication_h_ |