1 // Copyright 2020 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_TOOLS_V8WINDBG_TEST_DEBUG_CALLBACKS_H_ 6 #define V8_TOOLS_V8WINDBG_TEST_DEBUG_CALLBACKS_H_ 7 8 #if !defined(UNICODE) || !defined(_UNICODE) 9 #error Unicode not defined 10 #endif 11 12 #include <DbgEng.h> 13 #include <DbgModel.h> 14 #include <Windows.h> 15 #include <crtdbg.h> 16 #include <pathcch.h> 17 #include <wrl/client.h> 18 19 #include <string> 20 21 namespace WRL = Microsoft::WRL; 22 23 namespace v8 { 24 namespace internal { 25 namespace v8windbg_test { 26 27 class MyOutput : public IDebugOutputCallbacks { 28 public: 29 MyOutput(WRL::ComPtr<IDebugClient5> p_client); 30 ~MyOutput(); 31 MyOutput(const MyOutput&) = delete; 32 MyOutput& operator=(const MyOutput&) = delete; 33 34 // Inherited via IDebugOutputCallbacks 35 HRESULT __stdcall QueryInterface(REFIID InterfaceId, 36 PVOID* Interface) override; 37 ULONG __stdcall AddRef(void) override; 38 ULONG __stdcall Release(void) override; 39 HRESULT __stdcall Output(ULONG Mask, PCSTR Text) override; 40 GetLog()41 const std::string& GetLog() const { return log_; } ClearLog()42 void ClearLog() { log_.clear(); } 43 44 private: 45 WRL::ComPtr<IDebugClient5> p_client_; 46 std::string log_; 47 }; 48 49 // For return values, see: 50 // https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debug-status-xxx 51 class MyCallback : public IDebugEventCallbacks { 52 public: 53 // Inherited via IDebugEventCallbacks 54 HRESULT __stdcall QueryInterface(REFIID InterfaceId, 55 PVOID* Interface) override; 56 ULONG __stdcall AddRef(void) override; 57 ULONG __stdcall Release(void) override; 58 HRESULT __stdcall GetInterestMask(PULONG Mask) override; 59 HRESULT __stdcall Breakpoint(PDEBUG_BREAKPOINT Bp) override; 60 HRESULT __stdcall Exception(PEXCEPTION_RECORD64 Exception, 61 ULONG FirstChance) override; 62 HRESULT __stdcall CreateThread(ULONG64 Handle, ULONG64 DataOffset, 63 ULONG64 StartOffset) override; 64 HRESULT __stdcall ExitThread(ULONG ExitCode) override; 65 HRESULT __stdcall ExitProcess(ULONG ExitCode) override; 66 HRESULT __stdcall LoadModule(ULONG64 ImageFileHandle, ULONG64 BaseOffset, 67 ULONG ModuleSize, PCSTR ModuleName, 68 PCSTR ImageName, ULONG CheckSum, 69 ULONG TimeDateStamp) override; 70 HRESULT __stdcall UnloadModule(PCSTR ImageBaseName, 71 ULONG64 BaseOffset) override; 72 HRESULT __stdcall SystemError(ULONG Error, ULONG Level) override; 73 HRESULT __stdcall SessionStatus(ULONG Status) override; 74 HRESULT __stdcall ChangeDebuggeeState(ULONG Flags, ULONG64 Argument) override; 75 HRESULT __stdcall ChangeEngineState(ULONG Flags, ULONG64 Argument) override; 76 HRESULT __stdcall ChangeSymbolState(ULONG Flags, ULONG64 Argument) override; 77 HRESULT __stdcall CreateProcessW(ULONG64 ImageFileHandle, ULONG64 Handle, 78 ULONG64 BaseOffset, ULONG ModuleSize, 79 PCSTR ModuleName, PCSTR ImageName, 80 ULONG CheckSum, ULONG TimeDateStamp, 81 ULONG64 InitialThreadHandle, 82 ULONG64 ThreadDataOffset, 83 ULONG64 StartOffset) override; 84 }; 85 86 } // namespace v8windbg_test 87 } // namespace internal 88 } // namespace v8 89 90 #endif // V8_TOOLS_V8WINDBG_TEST_DEBUG_CALLBACKS_H_ 91