session.h 2.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_DEBUG_WASM_GDB_SERVER_SESSION_H_
#define V8_DEBUG_WASM_GDB_SERVER_SESSION_H_

#include "src/base/macros.h"

namespace v8 {
namespace internal {
namespace wasm {
namespace gdb_server {

15 16
class Packet;
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
  Session(const Session&) = delete;
  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 32 33

  // Return true if there is data to read.
  bool IsDataAvailable() const;

34
  // Return true if the connection is still valid.
35 36 37 38 39 40 41 42 43 44 45 46 47 48
  bool IsConnected() const;

  // Shutdown the connection.
  void Disconnect();

  // When a debugging session is active, the GDB-remote thread can block waiting
  // for events and it will resume execution when one of these two events arise:
  // - A network event (a new packet arrives, or the connection is dropped)
  // - A thread event (the execution stopped because of a trap or breakpoint).
  void WaitForDebugStubEvent();

  // Signal that the debuggee execution stopped because of a trap or breakpoint.
  bool SignalThreadEvent();

49 50 51 52 53 54 55
  // By default, when either the debugger or the GDB-stub sends a packet,
  // the first response expected is an acknowledgment: either '+' (to indicate
  // the packet was received correctly) or '-' (to request retransmission).
  // When a transport is reliable, the debugger may request that acknowledgement
  // be disabled by means of the 'QStartNoAckMode' packet.
  void EnableAck(bool ack_enabled) { ack_enabled_ = ack_enabled; }

56
 private:
57
  // Read a single character from the transport.
58 59
  bool GetChar(char* ch);

60 61 62 63 64 65
  // Read the content of a packet, from a leading '$' to a trailing '#'.
  bool GetPayload(Packet* pkt, uint8_t* checksum);

  TransportBase* io_;  // Transport object not owned by the Session.
  bool connected_;     // Is the connection still valid.
  bool ack_enabled_;   // If true, emit or wait for '+' from RSP stream.
66 67 68 69 70 71 72 73
};

}  // namespace gdb_server
}  // namespace wasm
}  // namespace internal
}  // namespace v8

#endif  // V8_DEBUG_WASM_GDB_SERVER_SESSION_H_