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