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