1 //===-- ProcessKDP.h --------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_ProcessKDP_h_ 11 #define liblldb_ProcessKDP_h_ 12 13 // C Includes 14 15 // C++ Includes 16 #include <list> 17 #include <vector> 18 19 // Other libraries and framework includes 20 #include "lldb/Core/Broadcaster.h" 21 #include "lldb/Core/ThreadSafeValue.h" 22 #include "lldb/Host/HostThread.h" 23 #include "lldb/Target/Process.h" 24 #include "lldb/Target/Thread.h" 25 #include "lldb/Utility/ArchSpec.h" 26 #include "lldb/Utility/ConstString.h" 27 #include "lldb/Utility/Status.h" 28 #include "lldb/Utility/StreamString.h" 29 #include "lldb/Utility/StringList.h" 30 31 #include "CommunicationKDP.h" 32 33 class ThreadKDP; 34 35 class ProcessKDP : public lldb_private::Process { 36 public: 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); 43 44 static void Initialize(); 45 46 static void DebuggerInitialize(lldb_private::Debugger &debugger); 47 48 static void Terminate(); 49 50 static lldb_private::ConstString GetPluginNameStatic(); 51 52 static const char *GetPluginDescriptionStatic(); 53 54 //------------------------------------------------------------------ 55 // Constructors and Destructors 56 //------------------------------------------------------------------ 57 ProcessKDP(lldb::TargetSP target_sp, lldb::ListenerSP listener); 58 59 ~ProcessKDP() override; 60 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; 67 68 //------------------------------------------------------------------ 69 // Creating a new process, or attaching to an existing one 70 //------------------------------------------------------------------ 71 lldb_private::Status WillLaunch(lldb_private::Module *module) override; 72 73 lldb_private::Status 74 DoLaunch(lldb_private::Module *exe_module, 75 lldb_private::ProcessLaunchInfo &launch_info) override; 76 77 lldb_private::Status WillAttachToProcessWithID(lldb::pid_t pid) override; 78 79 lldb_private::Status 80 WillAttachToProcessWithName(const char *process_name, 81 bool wait_for_launch) override; 82 83 lldb_private::Status DoConnectRemote(lldb_private::Stream *strm, 84 llvm::StringRef remote_url) override; 85 86 lldb_private::Status DoAttachToProcessWithID( 87 lldb::pid_t pid, 88 const lldb_private::ProcessAttachInfo &attach_info) override; 89 90 lldb_private::Status DoAttachToProcessWithName( 91 const char *process_name, 92 const lldb_private::ProcessAttachInfo &attach_info) override; 93 94 void DidAttach(lldb_private::ArchSpec &process_arch) override; 95 96 lldb::addr_t GetImageInfoAddress() override; 97 98 lldb_private::DynamicLoader *GetDynamicLoader() override; 99 100 //------------------------------------------------------------------ 101 // PluginInterface protocol 102 //------------------------------------------------------------------ 103 lldb_private::ConstString GetPluginName() override; 104 105 uint32_t GetPluginVersion() override; 106 107 //------------------------------------------------------------------ 108 // Process Control 109 //------------------------------------------------------------------ 110 lldb_private::Status WillResume() override; 111 112 lldb_private::Status DoResume() override; 113 114 lldb_private::Status DoHalt(bool &caused_stop) override; 115 116 lldb_private::Status DoDetach(bool keep_stopped) override; 117 118 lldb_private::Status DoSignal(int signal) override; 119 120 lldb_private::Status DoDestroy() override; 121 122 void RefreshStateAfterStop() override; 123 124 //------------------------------------------------------------------ 125 // Process Queries 126 //------------------------------------------------------------------ 127 bool IsAlive() override; 128 129 //------------------------------------------------------------------ 130 // Process Memory 131 //------------------------------------------------------------------ 132 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, 133 lldb_private::Status &error) override; 134 135 size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size, 136 lldb_private::Status &error) override; 137 138 lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions, 139 lldb_private::Status &error) override; 140 141 lldb_private::Status DoDeallocateMemory(lldb::addr_t ptr) override; 142 143 //---------------------------------------------------------------------- 144 // Process Breakpoints 145 //---------------------------------------------------------------------- 146 lldb_private::Status 147 EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override; 148 149 lldb_private::Status 150 DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override; 151 152 //---------------------------------------------------------------------- 153 // Process Watchpoints 154 //---------------------------------------------------------------------- 155 lldb_private::Status EnableWatchpoint(lldb_private::Watchpoint *wp, 156 bool notify = true) override; 157 158 lldb_private::Status DisableWatchpoint(lldb_private::Watchpoint *wp, 159 bool notify = true) override; 160 161 CommunicationKDP &GetCommunication() { return m_comm; } 162 163 protected: 164 friend class ThreadKDP; 165 friend class CommunicationKDP; 166 167 //---------------------------------------------------------------------- 168 // Accessors 169 //---------------------------------------------------------------------- 170 bool IsRunning(lldb::StateType state) { 171 return state == lldb::eStateRunning || IsStepping(state); 172 } 173 174 bool IsStepping(lldb::StateType state) { 175 return state == lldb::eStateStepping; 176 } 177 178 bool CanResume(lldb::StateType state) { return state == lldb::eStateStopped; } 179 180 bool HasExited(lldb::StateType state) { return state == lldb::eStateExited; } 181 182 bool GetHostArchitecture(lldb_private::ArchSpec &arch); 183 184 bool ProcessIDIsValid() const; 185 186 void Clear(); 187 188 bool UpdateThreadList(lldb_private::ThreadList &old_thread_list, 189 lldb_private::ThreadList &new_thread_list) override; 190 191 enum { 192 eBroadcastBitAsyncContinue = (1 << 0), 193 eBroadcastBitAsyncThreadShouldExit = (1 << 1) 194 }; 195 196 lldb::ThreadSP GetKernelThread(); 197 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; 208 209 bool StartAsyncThread(); 210 211 void StopAsyncThread(); 212 213 static void *AsyncThread(void *arg); 214 215 private: 216 //------------------------------------------------------------------ 217 // For ProcessKDP only 218 //------------------------------------------------------------------ 219 220 DISALLOW_COPY_AND_ASSIGN(ProcessKDP); 221 }; 222 223 #endif // liblldb_ProcessKDP_h_ 224