| 177 | } |
| 178 | |
| 179 | bool DbgEngAdapter::ConnectToDebugServerInternal(const std::string& connectionString) |
| 180 | { |
| 181 | auto handle = GetModuleHandleA("dbgeng.dll"); |
| 182 | if (handle == nullptr) |
| 183 | false; |
| 184 | |
| 185 | // HRESULT DebugCreate( |
| 186 | // [in] REFIID InterfaceId, |
| 187 | // [out] PVOID *Interface |
| 188 | // ); |
| 189 | typedef HRESULT(__stdcall * pfunDebugCreate)(REFIID, PVOID*); |
| 190 | auto DebugCreate = (pfunDebugCreate)GetProcAddress(handle, "DebugCreate"); |
| 191 | if (DebugCreate == nullptr) |
| 192 | return false; |
| 193 | |
| 194 | if (const auto result = DebugCreate(__uuidof(IDebugClient7), reinterpret_cast<void**>(&this->m_debugClient)); |
| 195 | result != S_OK) |
| 196 | throw std::runtime_error("Failed to create IDebugClient7"); |
| 197 | |
| 198 | QUERY_DEBUG_INTERFACE(IDebugControl7, &this->m_debugControl); |
| 199 | QUERY_DEBUG_INTERFACE(IDebugDataSpaces, &this->m_debugDataSpaces); |
| 200 | QUERY_DEBUG_INTERFACE(IDebugRegisters, &this->m_debugRegisters); |
| 201 | QUERY_DEBUG_INTERFACE(IDebugSymbols3, &this->m_debugSymbols); |
| 202 | QUERY_DEBUG_INTERFACE(IDebugSystemObjects, &this->m_debugSystemObjects); |
| 203 | |
| 204 | constexpr size_t CONNECTION_MAX_TRY = 300; |
| 205 | for (size_t i = 0; i < CONNECTION_MAX_TRY; i++) |
| 206 | { |
| 207 | auto result = m_debugClient->ConnectProcessServer(connectionString.c_str(), &m_server); |
| 208 | if (result == S_OK) |
| 209 | { |
| 210 | m_connectedToDebugServer = true; |
| 211 | return true; |
| 212 | } |
| 213 | |
| 214 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 215 | } |
| 216 | |
| 217 | return false; |
| 218 | } |
| 219 | |
| 220 | bool DbgEngAdapter::Start() |
| 221 | { |
nothing calls this directly
no outgoing calls
no test coverage detected