• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23   // Attempt to send a packet and optionally wait for an ACK from the receiver.
24   bool SendPacket(Packet* packet, bool expect_ack = true);
25 
26   // Attempt to receive a packet.
27   bool GetPacket(Packet* packet);
28 
29   // Return true if there is data to read.
30   bool IsDataAvailable() const;
31 
32   // Return true if the connection is still valid.
33   bool IsConnected() const;
34 
35   // Shutdown the connection.
36   void Disconnect();
37 
38   // When a debugging session is active, the GDB-remote thread can block waiting
39   // for events and it will resume execution when one of these two events arise:
40   // - A network event (a new packet arrives, or the connection is dropped)
41   // - A thread event (the execution stopped because of a trap or breakpoint).
42   void WaitForDebugStubEvent();
43 
44   // Signal that the debuggee execution stopped because of a trap or breakpoint.
45   bool SignalThreadEvent();
46 
47   // By default, when either the debugger or the GDB-stub sends a packet,
48   // the first response expected is an acknowledgment: either '+' (to indicate
49   // the packet was received correctly) or '-' (to request retransmission).
50   // When a transport is reliable, the debugger may request that acknowledgement
51   // be disabled by means of the 'QStartNoAckMode' packet.
EnableAck(bool ack_enabled)52   void EnableAck(bool ack_enabled) { ack_enabled_ = ack_enabled; }
53 
54  private:
55   // Read a single character from the transport.
56   bool GetChar(char* ch);
57 
58   // Read the content of a packet, from a leading '$' to a trailing '#'.
59   bool GetPayload(Packet* pkt, uint8_t* checksum);
60 
61   TransportBase* io_;  // Transport object not owned by the Session.
62   bool connected_;     // Is the connection still valid.
63   bool ack_enabled_;   // If true, emit or wait for '+' from RSP stream.
64 
65   DISALLOW_COPY_AND_ASSIGN(Session);
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