1 // Copyright 2020 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_DEBUG_WASM_GDB_SERVER_SESSION_H_ 6 #define V8_DEBUG_WASM_GDB_SERVER_SESSION_H_ 7 8 #include "src/base/macros.h" 9 10 namespace v8 { 11 namespace internal { 12 namespace wasm { 13 namespace gdb_server { 14 15 class Packet; 16 class TransportBase; 17 18 // Represents a gdb-remote debugging session. 19 class V8_EXPORT_PRIVATE Session { 20 public: 21 explicit Session(TransportBase* transport); 22 Session(const Session&) = delete; 23 Session& operator=(const Session&) = delete; 24 25 // Attempt to send a packet and optionally wait for an ACK from the receiver. 26 bool SendPacket(Packet* packet, bool expect_ack = true); 27 28 // Attempt to receive a packet. 29 bool GetPacket(Packet* packet); 30 31 // Return true if there is data to read. 32 bool IsDataAvailable() const; 33 34 // Return true if the connection is still valid. 35 bool IsConnected() const; 36 37 // Shutdown the connection. 38 void Disconnect(); 39 40 // When a debugging session is active, the GDB-remote thread can block waiting 41 // for events and it will resume execution when one of these two events arise: 42 // - A network event (a new packet arrives, or the connection is dropped) 43 // - A thread event (the execution stopped because of a trap or breakpoint). 44 void WaitForDebugStubEvent(); 45 46 // Signal that the debuggee execution stopped because of a trap or breakpoint. 47 bool SignalThreadEvent(); 48 49 // By default, when either the debugger or the GDB-stub sends a packet, 50 // the first response expected is an acknowledgment: either '+' (to indicate 51 // the packet was received correctly) or '-' (to request retransmission). 52 // When a transport is reliable, the debugger may request that acknowledgement 53 // be disabled by means of the 'QStartNoAckMode' packet. EnableAck(bool ack_enabled)54 void EnableAck(bool ack_enabled) { ack_enabled_ = ack_enabled; } 55 56 private: 57 // Read a single character from the transport. 58 bool GetChar(char* ch); 59 60 // Read the content of a packet, from a leading '$' to a trailing '#'. 61 bool GetPayload(Packet* pkt, uint8_t* checksum); 62 63 TransportBase* io_; // Transport object not owned by the Session. 64 bool connected_; // Is the connection still valid. 65 bool ack_enabled_; // If true, emit or wait for '+' from RSP stream. 66 }; 67 68 } // namespace gdb_server 69 } // namespace wasm 70 } // namespace internal 71 } // namespace v8 72 73 #endif // V8_DEBUG_WASM_GDB_SERVER_SESSION_H_ 74