14ad5def9SAdrian McCarthy //===-- LocalDebugDelegate.h ------------------------------------*- C++ -*-===// 24ad5def9SAdrian McCarthy // 3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 64ad5def9SAdrian McCarthy // 74ad5def9SAdrian McCarthy //===----------------------------------------------------------------------===// 84ad5def9SAdrian McCarthy 94ad5def9SAdrian McCarthy #ifndef liblldb_Plugins_Process_Windows_LocalDebugDelegate_H_ 104ad5def9SAdrian McCarthy #define liblldb_Plugins_Process_Windows_LocalDebugDelegate_H_ 114ad5def9SAdrian McCarthy 124ad5def9SAdrian McCarthy #include <memory> 134ad5def9SAdrian McCarthy 144ad5def9SAdrian McCarthy #include "IDebugDelegate.h" 154ad5def9SAdrian McCarthy 164ad5def9SAdrian McCarthy #include "lldb/lldb-forward.h" 174ad5def9SAdrian McCarthy 184ad5def9SAdrian McCarthy namespace lldb_private { 194ad5def9SAdrian McCarthy 204ad5def9SAdrian McCarthy class ProcessWindows; 214ad5def9SAdrian McCarthy typedef std::shared_ptr<ProcessWindows> ProcessWindowsSP; 224ad5def9SAdrian McCarthy 234ad5def9SAdrian McCarthy // LocalDebugDelegate 244ad5def9SAdrian McCarthy // 254ad5def9SAdrian McCarthy // LocalDebugDelegate creates a connection between a ProcessWindows and the 264ad5def9SAdrian McCarthy // debug driver. This serves to decouple ProcessWindows from the debug 274ad5def9SAdrian McCarthy // driver. It would be possible to get a similar decoupling by just having 284ad5def9SAdrian McCarthy // ProcessWindows implement this interface directly. There are two reasons 294ad5def9SAdrian McCarthy // why we don't do this: 304ad5def9SAdrian McCarthy // 314ad5def9SAdrian McCarthy // 1) In the future when we add support for local debugging through LLGS, and we 324ad5def9SAdrian McCarthy // go through the Native*Protocol interface, it is likely we will need the 334ad5def9SAdrian McCarthy // additional flexibility provided by this sort of adapter pattern. 344ad5def9SAdrian McCarthy // 2) LLDB holds a shared_ptr to the ProcessWindows, and our driver thread 354ad5def9SAdrian McCarthy // needs access to it as well. To avoid a race condition, we want to make 364ad5def9SAdrian McCarthy // sure that we're also holding onto a shared_ptr. 374ad5def9SAdrian McCarthy // lldb_private::Process supports enable_shared_from_this, but that gives us 384ad5def9SAdrian McCarthy // a ProcessSP (which is exactly what we are trying to decouple from the 394ad5def9SAdrian McCarthy // driver), so this adapter serves as a way to transparently hold the 404ad5def9SAdrian McCarthy // ProcessSP while still keeping it decoupled from the driver. 414ad5def9SAdrian McCarthy class LocalDebugDelegate : public IDebugDelegate { 424ad5def9SAdrian McCarthy public: 434ad5def9SAdrian McCarthy explicit LocalDebugDelegate(lldb::ProcessWP process); 444ad5def9SAdrian McCarthy 454ad5def9SAdrian McCarthy void OnExitProcess(uint32_t exit_code) override; 464ad5def9SAdrian McCarthy void OnDebuggerConnected(lldb::addr_t image_base) override; 474ad5def9SAdrian McCarthy ExceptionResult OnDebugException(bool first_chance, 484ad5def9SAdrian McCarthy const ExceptionRecord &record) override; 494ad5def9SAdrian McCarthy void OnCreateThread(const HostThread &thread) override; 504ad5def9SAdrian McCarthy void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override; 514ad5def9SAdrian McCarthy void OnLoadDll(const lldb_private::ModuleSpec &module_spec, 524ad5def9SAdrian McCarthy lldb::addr_t module_addr) override; 534ad5def9SAdrian McCarthy void OnUnloadDll(lldb::addr_t module_addr) override; 544ad5def9SAdrian McCarthy void OnDebugString(const std::string &message) override; 5597206d57SZachary Turner void OnDebuggerError(const Status &error, uint32_t type) override; 564ad5def9SAdrian McCarthy 574ad5def9SAdrian McCarthy private: 584ad5def9SAdrian McCarthy ProcessWindowsSP GetProcessPointer(); 594ad5def9SAdrian McCarthy 604ad5def9SAdrian McCarthy lldb::ProcessWP m_process; 614ad5def9SAdrian McCarthy }; 624ad5def9SAdrian McCarthy } 634ad5def9SAdrian McCarthy 644ad5def9SAdrian McCarthy #endif 65