| 1 | //===-- GDBRemote.h ----------------------------------------------*- C++-*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLDB_UTILITY_GDBREMOTE_H |
| 10 | #define LLDB_UTILITY_GDBREMOTE_H |
| 11 | |
| 12 | #include "lldb/Utility/FileSpec.h" |
| 13 | #include "lldb/Utility/StreamString.h" |
| 14 | #include "lldb/lldb-enumerations.h" |
| 15 | #include "lldb/lldb-public.h" |
| 16 | #include "llvm/Support/raw_ostream.h" |
| 17 | |
| 18 | #include <cstddef> |
| 19 | #include <cstdint> |
| 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
| 23 | namespace lldb_private { |
| 24 | |
| 25 | class StreamGDBRemote : public StreamString { |
| 26 | public: |
| 27 | StreamGDBRemote(); |
| 28 | |
| 29 | StreamGDBRemote(uint32_t flags, uint32_t addr_size, |
| 30 | lldb::ByteOrder byte_order); |
| 31 | |
| 32 | ~StreamGDBRemote() override; |
| 33 | |
| 34 | /// Output a block of data to the stream performing GDB-remote escaping. |
| 35 | /// |
| 36 | /// \param[in] s |
| 37 | /// A block of data. |
| 38 | /// |
| 39 | /// \param[in] src_len |
| 40 | /// The amount of data to write. |
| 41 | /// |
| 42 | /// \return |
| 43 | /// Number of bytes written. |
| 44 | // TODO: Convert this function to take ArrayRef<uint8_t> |
| 45 | int PutEscapedBytes(const void *s, size_t src_len); |
| 46 | }; |
| 47 | |
| 48 | /// GDB remote packet as used by the GDB remote communication history. Packets |
| 49 | /// can be serialized to file. |
| 50 | struct GDBRemotePacket { |
| 51 | |
| 52 | enum Type { ePacketTypeInvalid = 0, ePacketTypeSend, ePacketTypeRecv }; |
| 53 | |
| 54 | GDBRemotePacket() = default; |
| 55 | |
| 56 | void Clear() { |
| 57 | packet.data.clear(); |
| 58 | type = ePacketTypeInvalid; |
| 59 | bytes_transmitted = 0; |
| 60 | packet_idx = 0; |
| 61 | tid = LLDB_INVALID_THREAD_ID; |
| 62 | } |
| 63 | |
| 64 | struct BinaryData { |
| 65 | std::string data; |
| 66 | }; |
| 67 | |
| 68 | void Dump(Stream &strm) const; |
| 69 | |
| 70 | BinaryData packet; |
| 71 | Type type = ePacketTypeInvalid; |
| 72 | uint32_t bytes_transmitted = 0; |
| 73 | uint32_t packet_idx = 0; |
| 74 | lldb::tid_t tid = LLDB_INVALID_THREAD_ID; |
| 75 | |
| 76 | private: |
| 77 | llvm::StringRef GetTypeStr() const; |
| 78 | }; |
| 79 | |
| 80 | } // namespace lldb_private |
| 81 | |
| 82 | #endif // LLDB_UTILITY_GDBREMOTE_H |
| 83 | |