GDBServer.h
Go to the documentation of this file.
1 #pragma once
2 #include <bzsnet/server.h>
3 #include <bzscore/status.h>
4 #include <bzsnet/BufferedSocket.h>
5 #include "IGDBStub.h"
6 #include "BreakInSocket.h"
7 
8 namespace GDBServerFoundation
9 {
11 
24  class GDBServer : private BazisLib::Network::BasicTCPServer
25  {
26  private:
27  virtual void ConnectionHandler(BazisLib::Network::TCPSocket &socket, const BazisLib::Network::InternetAddress &addr) override;
28 
29  private:
30  IGDBStubFactory *m_pFactory;
31  bool m_bOwnFactory;
32 
33  private:
35  bool FindPacketStart(BreakInSocket::SocketWrapper &socket, bool expectingACK, IBreakInTarget *pTarget);
36 
37  void HandleGDBPacketAndSendReply(IGDBStub *pStub, const char *pPacketBody, size_t packetBodyLength, BreakInSocket &socket, bool *ackEnabled);
38 
39  static size_t UnescapePacket(const void *pPacket, size_t escapedSize, void *pTarget);
40 
42  StubResponse QStartNoAckMode(bool *ackEnabled);
43 
44  public:
46 
50  GDBServer(IGDBStubFactory *pFactory, bool own = true)
51  : m_pFactory(pFactory)
52  , m_bOwnFactory(own)
53  {
54  }
55 
57  BazisLib::ActionStatus Start(unsigned port);
58 
61  {
62  return BasicTCPServer::WaitForTermination();
63  }
64 
67  {
68  return Stop(false);
69  }
70 
71  protected:
72  void OnPacketError(const BazisLib::String &msg)
73  {
74  if (m_pFactory)
75  m_pFactory->OnProtocolError(msg.c_str());
76  }
77  };
78 }