VBoxClient.h
Go to the documentation of this file.
1 #pragma once
2 #include <bzsnet/BufferedSocket.h>
3 #include <bzscore/buffer.h>
4 #include <bzscore/string.h>
5 #include <map>
6 #include <vector>
7 #include <string>
8 #include <hash_map>
9 
10 #define USE_REG_WORKAROUND_DLL
11 
12 namespace VBoxGDB
13 {
15 
22  class VBoxClient
23  {
24  private:
25  BazisLib::Network::TCPSocketEx m_Socket;
26  BazisLib::DynamicStringA m_Buffer;
27  size_t m_BufferAllocationSize;
28  bool m_b64Bit;
29  int m_CPUCount;
30  int m_BreakpointIDOfLastStopEvent; //-1 if not a breakpoint
31 
32  typedef std::hash_map<int, ULONGLONG> BreakpointAddressMap;
33  BreakpointAddressMap m_BreakpointMap;
34 
35  BazisLib::BasicBuffer m_LastBlockReadBuffer;
36  ULONGLONG m_LastBlockReadAddr; //-1LL if not valid
37 
38  BazisLib::Network::InternetAddress m_TargetAddr;
39 
40  public:
42 
45  VBoxClient(const BazisLib::Network::InternetAddress &addr);
46  ~VBoxClient();
47 
49  bool Initialize();
50 
51  private:
52  bool RecvTillCommandPrompt();
53  bool ReadMemoryBlockAligned(ULONGLONG address, BazisLib::BasicBuffer &buffer); //The read size is determined by VirtualBox; address should be aligned to 4 bytes
54  void AdjustPCAfterBreakpoint(int breakpointNumber);
55  ULONGLONG GetCurrentPC();
56 
57  public:
58  std::vector<BazisLib::DynamicStringA> ExecuteCommand(const char *pCommand);
59 
60  public:
62  std::map<BazisLib::DynamicStringA, ULONGLONG> ReadRegisters();
64  bool WriteRegister(const char *pName, ULONGLONG value);
66  bool ReadRegister(const char *pName, ULONGLONG *pValue);
67 
69  bool WaitForStop();
70 
72  void RequestStopAsync();
73 
75 
81  void Disconnect();
82 
84 
93  bool ReadMemory(ULONGLONG address, void *pData, size_t *pLength, bool allowCaching = true);
94 
96  bool WriteMemory(ULONGLONG address, const void *pData, size_t length);
97 
99  bool StepAndWait();
100 
102  bool ContinueAndWait();
103 
105 
110  bool IsSuccessfulReply(const std::vector<BazisLib::DynamicStringA> &reply, bool report = true);
111 
113 
118  int CreateBreakpoint(ULONGLONG addr);
119 
121  bool RemoveBreakpoint(int idx);
122 
123 
124  protected:
126 
129  virtual void ReportError(const char *pErrorDescription);
130  };
131 }