1 //===-- ProcessKDP.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ProcessKDP_h_
11 #define liblldb_ProcessKDP_h_
19 // Other libraries and framework includes
20 #include "lldb/Core/ArchSpec.h"
21 #include "lldb/Core/Broadcaster.h"
22 #include "lldb/Core/ConstString.h"
23 #include "lldb/Core/Error.h"
24 #include "lldb/Core/StreamString.h"
25 #include "lldb/Core/StringList.h"
26 #include "lldb/Core/ThreadSafeValue.h"
27 #include "lldb/Host/HostThread.h"
28 #include "lldb/Target/Process.h"
29 #include "lldb/Target/Thread.h"
31 #include "CommunicationKDP.h"
35 class ProcessKDP : public lldb_private::Process {
37 //------------------------------------------------------------------
38 // Constructors and Destructors
39 //------------------------------------------------------------------
40 static lldb::ProcessSP
41 CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
42 const lldb_private::FileSpec *crash_file_path);
44 static void Initialize();
46 static void DebuggerInitialize(lldb_private::Debugger &debugger);
48 static void Terminate();
50 static lldb_private::ConstString GetPluginNameStatic();
52 static const char *GetPluginDescriptionStatic();
54 //------------------------------------------------------------------
55 // Constructors and Destructors
56 //------------------------------------------------------------------
57 ProcessKDP(lldb::TargetSP target_sp, lldb::ListenerSP listener);
59 ~ProcessKDP() override;
61 //------------------------------------------------------------------
62 // Check if a given Process
63 //------------------------------------------------------------------
64 bool CanDebug(lldb::TargetSP target_sp,
65 bool plugin_specified_by_name) override;
66 lldb_private::CommandObject *GetPluginCommandObject() override;
68 //------------------------------------------------------------------
69 // Creating a new process, or attaching to an existing one
70 //------------------------------------------------------------------
71 lldb_private::Error WillLaunch(lldb_private::Module *module) override;
74 DoLaunch(lldb_private::Module *exe_module,
75 lldb_private::ProcessLaunchInfo &launch_info) override;
77 lldb_private::Error WillAttachToProcessWithID(lldb::pid_t pid) override;
80 WillAttachToProcessWithName(const char *process_name,
81 bool wait_for_launch) override;
83 lldb_private::Error DoConnectRemote(lldb_private::Stream *strm,
84 llvm::StringRef remote_url) override;
86 lldb_private::Error DoAttachToProcessWithID(
88 const lldb_private::ProcessAttachInfo &attach_info) override;
90 lldb_private::Error DoAttachToProcessWithName(
91 const char *process_name,
92 const lldb_private::ProcessAttachInfo &attach_info) override;
94 void DidAttach(lldb_private::ArchSpec &process_arch) override;
96 lldb::addr_t GetImageInfoAddress() override;
98 lldb_private::DynamicLoader *GetDynamicLoader() override;
100 //------------------------------------------------------------------
101 // PluginInterface protocol
102 //------------------------------------------------------------------
103 lldb_private::ConstString GetPluginName() override;
105 uint32_t GetPluginVersion() override;
107 //------------------------------------------------------------------
109 //------------------------------------------------------------------
110 lldb_private::Error WillResume() override;
112 lldb_private::Error DoResume() override;
114 lldb_private::Error DoHalt(bool &caused_stop) override;
116 lldb_private::Error DoDetach(bool keep_stopped) override;
118 lldb_private::Error DoSignal(int signal) override;
120 lldb_private::Error DoDestroy() override;
122 void RefreshStateAfterStop() override;
124 //------------------------------------------------------------------
126 //------------------------------------------------------------------
127 bool IsAlive() override;
129 //------------------------------------------------------------------
131 //------------------------------------------------------------------
132 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
133 lldb_private::Error &error) override;
135 size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size,
136 lldb_private::Error &error) override;
138 lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
139 lldb_private::Error &error) override;
141 lldb_private::Error DoDeallocateMemory(lldb::addr_t ptr) override;
143 //----------------------------------------------------------------------
144 // Process Breakpoints
145 //----------------------------------------------------------------------
147 EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
150 DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
152 //----------------------------------------------------------------------
153 // Process Watchpoints
154 //----------------------------------------------------------------------
155 lldb_private::Error EnableWatchpoint(lldb_private::Watchpoint *wp,
156 bool notify = true) override;
158 lldb_private::Error DisableWatchpoint(lldb_private::Watchpoint *wp,
159 bool notify = true) override;
161 CommunicationKDP &GetCommunication() { return m_comm; }
164 friend class ThreadKDP;
165 friend class CommunicationKDP;
167 //----------------------------------------------------------------------
169 //----------------------------------------------------------------------
170 bool IsRunning(lldb::StateType state) {
171 return state == lldb::eStateRunning || IsStepping(state);
174 bool IsStepping(lldb::StateType state) {
175 return state == lldb::eStateStepping;
178 bool CanResume(lldb::StateType state) { return state == lldb::eStateStopped; }
180 bool HasExited(lldb::StateType state) { return state == lldb::eStateExited; }
182 bool GetHostArchitecture(lldb_private::ArchSpec &arch);
184 bool ProcessIDIsValid() const;
188 bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
189 lldb_private::ThreadList &new_thread_list) override;
192 eBroadcastBitAsyncContinue = (1 << 0),
193 eBroadcastBitAsyncThreadShouldExit = (1 << 1)
196 lldb::ThreadSP GetKernelThread();
198 //------------------------------------------------------------------
199 /// Broadcaster event bits definitions.
200 //------------------------------------------------------------------
201 CommunicationKDP m_comm;
202 lldb_private::Broadcaster m_async_broadcaster;
203 lldb_private::HostThread m_async_thread;
204 lldb_private::ConstString m_dyld_plugin_name;
205 lldb::addr_t m_kernel_load_addr;
206 lldb::CommandObjectSP m_command_sp;
207 lldb::ThreadWP m_kernel_thread_wp;
209 bool StartAsyncThread();
211 void StopAsyncThread();
213 static void *AsyncThread(void *arg);
216 //------------------------------------------------------------------
217 // For ProcessKDP only
218 //------------------------------------------------------------------
220 DISALLOW_COPY_AND_ASSIGN(ProcessKDP);
223 #endif // liblldb_ProcessKDP_h_