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