Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Plugins / Process / MacOSX-Kernel / ProcessKDP.h
blob3c12fd4074499a95a5de1dec1eec85bd76228b6c
1 //===-- ProcessKDP.h --------------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_MACOSX_KERNEL_PROCESSKDP_H
10 #define LLDB_SOURCE_PLUGINS_PROCESS_MACOSX_KERNEL_PROCESSKDP_H
12 #include <list>
13 #include <vector>
15 #include "lldb/Core/ThreadSafeValue.h"
16 #include "lldb/Host/HostThread.h"
17 #include "lldb/Target/Process.h"
18 #include "lldb/Target/Thread.h"
19 #include "lldb/Utility/ArchSpec.h"
20 #include "lldb/Utility/Broadcaster.h"
21 #include "lldb/Utility/ConstString.h"
22 #include "lldb/Utility/Status.h"
23 #include "lldb/Utility/StreamString.h"
24 #include "lldb/Utility/StringList.h"
26 #include "CommunicationKDP.h"
28 class ThreadKDP;
30 class ProcessKDP : public lldb_private::Process {
31 public:
32 // Constructors and Destructors
33 static lldb::ProcessSP
34 CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
35 const lldb_private::FileSpec *crash_file_path,
36 bool can_connect);
38 static void Initialize();
40 static void DebuggerInitialize(lldb_private::Debugger &debugger);
42 static void Terminate();
44 static llvm::StringRef GetPluginNameStatic() { return "kdp-remote"; }
46 static llvm::StringRef GetPluginDescriptionStatic();
48 // Constructors and Destructors
49 ProcessKDP(lldb::TargetSP target_sp, lldb::ListenerSP listener);
51 ~ProcessKDP() override;
53 // Check if a given Process
54 bool CanDebug(lldb::TargetSP target_sp,
55 bool plugin_specified_by_name) override;
56 lldb_private::CommandObject *GetPluginCommandObject() override;
58 // Creating a new process, or attaching to an existing one
59 lldb_private::Status DoWillLaunch(lldb_private::Module *module) override;
61 lldb_private::Status
62 DoLaunch(lldb_private::Module *exe_module,
63 lldb_private::ProcessLaunchInfo &launch_info) override;
65 lldb_private::Status DoWillAttachToProcessWithID(lldb::pid_t pid) override;
67 lldb_private::Status
68 DoWillAttachToProcessWithName(const char *process_name,
69 bool wait_for_launch) override;
71 lldb_private::Status DoConnectRemote(llvm::StringRef remote_url) override;
73 lldb_private::Status DoAttachToProcessWithID(
74 lldb::pid_t pid,
75 const lldb_private::ProcessAttachInfo &attach_info) override;
77 lldb_private::Status DoAttachToProcessWithName(
78 const char *process_name,
79 const lldb_private::ProcessAttachInfo &attach_info) override;
81 void DidAttach(lldb_private::ArchSpec &process_arch) override;
83 lldb::addr_t GetImageInfoAddress() override;
85 lldb_private::DynamicLoader *GetDynamicLoader() override;
87 // PluginInterface protocol
88 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
90 // Process Control
91 lldb_private::Status WillResume() override;
93 lldb_private::Status DoResume() override;
95 lldb_private::Status DoHalt(bool &caused_stop) override;
97 lldb_private::Status DoDetach(bool keep_stopped) override;
99 lldb_private::Status DoSignal(int signal) override;
101 lldb_private::Status DoDestroy() override;
103 void RefreshStateAfterStop() override;
105 // Process Queries
106 bool IsAlive() override;
108 // Process Memory
109 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
110 lldb_private::Status &error) override;
112 size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size,
113 lldb_private::Status &error) override;
115 lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
116 lldb_private::Status &error) override;
118 lldb_private::Status DoDeallocateMemory(lldb::addr_t ptr) override;
120 // Process Breakpoints
121 lldb_private::Status
122 EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
124 lldb_private::Status
125 DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
127 // Process Watchpoints
128 lldb_private::Status EnableWatchpoint(lldb_private::Watchpoint *wp,
129 bool notify = true) override;
131 lldb_private::Status DisableWatchpoint(lldb_private::Watchpoint *wp,
132 bool notify = true) override;
134 CommunicationKDP &GetCommunication() { return m_comm; }
136 protected:
137 friend class ThreadKDP;
138 friend class CommunicationKDP;
140 // Accessors
141 bool IsRunning(lldb::StateType state) {
142 return state == lldb::eStateRunning || IsStepping(state);
145 bool IsStepping(lldb::StateType state) {
146 return state == lldb::eStateStepping;
149 bool CanResume(lldb::StateType state) { return state == lldb::eStateStopped; }
151 bool HasExited(lldb::StateType state) { return state == lldb::eStateExited; }
153 bool GetHostArchitecture(lldb_private::ArchSpec &arch);
155 bool ProcessIDIsValid() const;
157 void Clear();
159 bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list,
160 lldb_private::ThreadList &new_thread_list) override;
162 enum {
163 eBroadcastBitAsyncContinue = (1 << 0),
164 eBroadcastBitAsyncThreadShouldExit = (1 << 1)
167 lldb::ThreadSP GetKernelThread();
169 /// Broadcaster event bits definitions.
170 CommunicationKDP m_comm;
171 lldb_private::Broadcaster m_async_broadcaster;
172 lldb_private::HostThread m_async_thread;
173 llvm::StringRef m_dyld_plugin_name;
174 lldb::addr_t m_kernel_load_addr;
175 lldb::CommandObjectSP m_command_sp;
176 lldb::ThreadWP m_kernel_thread_wp;
178 bool StartAsyncThread();
180 void StopAsyncThread();
182 void *AsyncThread();
184 private:
185 // For ProcessKDP only
187 ProcessKDP(const ProcessKDP &) = delete;
188 const ProcessKDP &operator=(const ProcessKDP &) = delete;
191 #endif // LLDB_SOURCE_PLUGINS_PROCESS_MACOSX_KERNEL_PROCESSKDP_H