VBoxTarget.cpp
Go to the documentation of this file.
1 #include "StdAfx.h"
2 #include "VBoxTarget.h"
3 #include "registers-i386.h"
4 
5 using namespace GDBServerFoundation;
6 using namespace VBoxGDB;
7 
8 
10  : m_pClient(pClient)
11  , m_bOwn(own)
12 {
13  pClient->RequestStopAsync();
14  pClient->WaitForStop();
15 }
16 
18 {
19  if (m_bOwn)
20  delete m_pClient;
21 }
22 
23 GDBServerFoundation::GDBStatus VBoxGDB::VBoxTarget32::ReadTargetRegisters( int threadID, RegisterSetContainer &registers )
24 {
25  std::map<BazisLib::DynamicStringA, ULONGLONG> rawRegs = m_pClient->ReadRegisters();
26  if (rawRegs.empty())
27  return kGDBUnknownError;
28 
29  for (size_t i = 0; i < i386::RegisterList.RegisterCount; i++)
30  {
31  std::map<BazisLib::DynamicStringA, ULONGLONG>::iterator it = rawRegs.find(i386::RegisterList.Registers[i].RegisterName);
32  if (it == rawRegs.end())
33  continue;
34  registers[i386::RegisterList.Registers[i].RegisterIndex] = RegisterValue((unsigned)it->second, i386::RegisterList.Registers[i].SizeInBits / 8);
35  }
36 
37  return kGDBSuccess;
38 }
39 
40 GDBServerFoundation::GDBStatus VBoxGDB::VBoxTarget32::WriteTargetRegisters( int threadID, const RegisterSetContainer &registers )
41 {
42  for (size_t i = 0; i < i386::RegisterList.RegisterCount; i++)
43  {
44  if (registers[i].Valid)
45  if (!m_pClient->WriteRegister(i386::RegisterList.Registers[i].RegisterName, registers[i].ToUInt32()))
46  return kGDBUnknownError;
47  }
48 
49  return kGDBSuccess;
50 }
51 
52 GDBServerFoundation::GDBStatus VBoxGDB::VBoxTarget32::ReadTargetMemory( ULONGLONG Address, void *pBuffer, size_t *pSizeInBytes )
53 {
54  if (!Address)
55  return kGDBUnknownError;
56  if (!m_pClient->ReadMemory(Address, pBuffer, pSizeInBytes))
57  return kGDBUnknownError;
58  return kGDBSuccess;
59 }
60 
61 GDBServerFoundation::GDBStatus VBoxGDB::VBoxTarget32::WriteTargetMemory( ULONGLONG Address, const void *pBuffer, size_t sizeInBytes )
62 {
63  if (!Address)
64  return kGDBUnknownError;
65  if (!m_pClient->WriteMemory(Address, pBuffer, sizeInBytes))
66  return kGDBUnknownError;
67  return kGDBSuccess;
68 }
69 
70 GDBServerFoundation::GDBStatus VBoxGDB::VBoxTarget32::GetLastStopRecord( TargetStopRecord *pRec )
71 {
72  pRec->ThreadID = 0;
73  pRec->Reason = kSignalReceived;
74  pRec->Extension.SignalNumber = SIGTRAP;
75  return kGDBSuccess;
76 }
77 
78 GDBServerFoundation::GDBStatus VBoxGDB::VBoxTarget32::ResumeAndWait( int threadID )
79 {
80  if (!m_pClient->ContinueAndWait())
81  return kGDBUnknownError;
82  return kGDBSuccess;
83 }
84 
85 GDBServerFoundation::GDBStatus VBoxGDB::VBoxTarget32::Step( int threadID )
86 {
87  if (!m_pClient->StepAndWait())
88  return kGDBUnknownError;
89  return kGDBSuccess;
90 }
91 
92 GDBServerFoundation::GDBStatus VBoxGDB::VBoxTarget32::SendBreakInRequestAsync()
93 {
94  m_pClient->RequestStopAsync();
95  return kGDBSuccess;
96 }
97 
98 const PlatformRegisterList * VBoxGDB::VBoxTarget32::GetRegisterList()
99 {
101 }
102 
103 GDBServerFoundation::GDBStatus VBoxGDB::VBoxTarget32::ExecuteRemoteCommand( const std::string &command, std::string &output )
104 {
105  std::vector<BazisLib::DynamicStringA> result = m_pClient->ExecuteCommand(command.c_str());
106  for (size_t i = 0; i < result.size(); i++)
107  {
108  output += result[i].c_str();
109  output += "\n";
110  }
111  return kGDBSuccess;
112 }
113 
114 GDBServerFoundation::GDBStatus VBoxGDB::VBoxTarget32::CreateBreakpoint( BreakpointType type, ULONGLONG Address, unsigned kind, OUT INT_PTR *pCookie )
115 {
116  int bpID;
117  switch(type)
118  {
119  case bptSoftwareBreakpoint:
120  bpID = m_pClient->CreateBreakpoint(Address);
121  if (bpID == -1)
122  return kGDBUnknownError;
123  *pCookie = bpID;
124  return kGDBSuccess;
125  default:
126  return kGDBNotSupported;
127  }
128 }
129 
130 GDBServerFoundation::GDBStatus VBoxGDB::VBoxTarget32::RemoveBreakpoint( BreakpointType type, ULONGLONG Address, INT_PTR Cookie )
131 {
132  switch(type)
133  {
134  case bptSoftwareBreakpoint:
135  if (!m_pClient->RemoveBreakpoint(Cookie))
136  return kGDBUnknownError;
137  return kGDBSuccess;
138  default:
139  return kGDBNotSupported;
140  }
141 }
142 
144 {
145  m_pClient->Disconnect();
146 }
147