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/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" 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 virtual ~ProcessKDP(); 60 61 //------------------------------------------------------------------ 62 // Check if a given Process 63 //------------------------------------------------------------------ 64 virtual bool CanDebug(lldb::TargetSP target_sp, 65 bool plugin_specified_by_name); 66 67 virtual lldb_private::CommandObject *GetPluginCommandObject(); 68 69 //------------------------------------------------------------------ 70 // Creating a new process, or attaching to an existing one 71 //------------------------------------------------------------------ 72 virtual lldb_private::Error WillLaunch(lldb_private::Module *module); 73 74 virtual lldb_private::Error 75 DoLaunch(lldb_private::Module *exe_module, 76 lldb_private::ProcessLaunchInfo &launch_info); 77 78 virtual lldb_private::Error WillAttachToProcessWithID(lldb::pid_t pid); 79 80 virtual lldb_private::Error 81 WillAttachToProcessWithName(const char *process_name, bool wait_for_launch); 82 83 virtual lldb_private::Error DoConnectRemote(lldb_private::Stream *strm, 84 const char *remote_url); 85 86 virtual lldb_private::Error 87 DoAttachToProcessWithID(lldb::pid_t pid, 88 const lldb_private::ProcessAttachInfo &attach_info); 89 90 virtual lldb_private::Error 91 DoAttachToProcessWithName(const char *process_name, 92 const lldb_private::ProcessAttachInfo &attach_info); 93 94 virtual void DidAttach(lldb_private::ArchSpec &process_arch); 95 96 lldb::addr_t GetImageInfoAddress(); 97 98 lldb_private::DynamicLoader *GetDynamicLoader(); 99 100 //------------------------------------------------------------------ 101 // PluginInterface protocol 102 //------------------------------------------------------------------ 103 virtual lldb_private::ConstString GetPluginName(); 104 105 virtual uint32_t GetPluginVersion(); 106 107 //------------------------------------------------------------------ 108 // Process Control 109 //------------------------------------------------------------------ 110 virtual lldb_private::Error WillResume(); 111 112 virtual lldb_private::Error DoResume(); 113 114 virtual lldb_private::Error DoHalt(bool &caused_stop); 115 116 virtual lldb_private::Error DoDetach(bool keep_stopped); 117 118 virtual lldb_private::Error DoSignal(int signal); 119 120 virtual lldb_private::Error DoDestroy(); 121 122 virtual void RefreshStateAfterStop(); 123 124 //------------------------------------------------------------------ 125 // Process Queries 126 //------------------------------------------------------------------ 127 virtual bool IsAlive(); 128 129 //------------------------------------------------------------------ 130 // Process Memory 131 //------------------------------------------------------------------ 132 virtual size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, 133 lldb_private::Error &error); 134 135 virtual size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size, 136 lldb_private::Error &error); 137 138 virtual lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions, 139 lldb_private::Error &error); 140 141 virtual lldb_private::Error DoDeallocateMemory(lldb::addr_t ptr); 142 143 //---------------------------------------------------------------------- 144 // Process Breakpoints 145 //---------------------------------------------------------------------- 146 virtual lldb_private::Error 147 EnableBreakpointSite(lldb_private::BreakpointSite *bp_site); 148 149 virtual lldb_private::Error 150 DisableBreakpointSite(lldb_private::BreakpointSite *bp_site); 151 152 //---------------------------------------------------------------------- 153 // Process Watchpoints 154 //---------------------------------------------------------------------- 155 virtual lldb_private::Error EnableWatchpoint(lldb_private::Watchpoint *wp, 156 bool notify = true); 157 158 virtual lldb_private::Error DisableWatchpoint(lldb_private::Watchpoint *wp, 159 bool notify = true); 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 virtual bool UpdateThreadList(lldb_private::ThreadList &old_thread_list, 189 lldb_private::ThreadList &new_thread_list); 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