1 //===-- LocalDebugDelegate.h ------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_Plugins_Process_Windows_LocalDebugDelegate_H_ 11 #define liblldb_Plugins_Process_Windows_LocalDebugDelegate_H_ 12 13 #include <memory> 14 15 #include "IDebugDelegate.h" 16 17 #include "lldb/lldb-forward.h" 18 19 namespace lldb_private { 20 21 class ProcessWindows; 22 typedef std::shared_ptr<ProcessWindows> ProcessWindowsSP; 23 24 //---------------------------------------------------------------------- 25 // LocalDebugDelegate 26 // 27 // LocalDebugDelegate creates a connection between a ProcessWindows and the 28 // debug driver. This serves to decouple ProcessWindows from the debug 29 // driver. It would be possible to get a similar decoupling by just having 30 // ProcessWindows implement this interface directly. There are two reasons 31 // why we don't do this: 32 // 33 // 1) In the future when we add support for local debugging through LLGS, and we 34 // go through the Native*Protocol interface, it is likely we will need the 35 // additional flexibility provided by this sort of adapter pattern. 36 // 2) LLDB holds a shared_ptr to the ProcessWindows, and our driver thread 37 // needs access to it as well. To avoid a race condition, we want to make 38 // sure that we're also holding onto a shared_ptr. 39 // lldb_private::Process supports enable_shared_from_this, but that gives us 40 // a ProcessSP (which is exactly what we are trying to decouple from the 41 // driver), so this adapter serves as a way to transparently hold the 42 // ProcessSP while still keeping it decoupled from the driver. 43 //---------------------------------------------------------------------- 44 class LocalDebugDelegate : public IDebugDelegate { 45 public: 46 explicit LocalDebugDelegate(lldb::ProcessWP process); 47 48 void OnExitProcess(uint32_t exit_code) override; 49 void OnDebuggerConnected(lldb::addr_t image_base) override; 50 ExceptionResult OnDebugException(bool first_chance, 51 const ExceptionRecord &record) override; 52 void OnCreateThread(const HostThread &thread) override; 53 void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override; 54 void OnLoadDll(const lldb_private::ModuleSpec &module_spec, 55 lldb::addr_t module_addr) override; 56 void OnUnloadDll(lldb::addr_t module_addr) override; 57 void OnDebugString(const std::string &message) override; 58 void OnDebuggerError(const Status &error, uint32_t type) override; 59 60 private: 61 ProcessWindowsSP GetProcessPointer(); 62 63 lldb::ProcessWP m_process; 64 }; 65 } 66 67 #endif 68