blob: f0b68b2505ca8999f9984fa612f0645c04862aea [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ProcessGDBRemote.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_ProcessGDBRemote_h_
11#define liblldb_ProcessGDBRemote_h_
12
13// C Includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014// C++ Includes
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000015#include <atomic>
16#include <map>
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +000017#include <mutex>
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000018#include <string>
Greg Clayton71fc2a32011-02-12 06:28:37 +000019#include <vector>
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/Core/Broadcaster.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000022#include "lldb/Core/LoadedModuleInfoList.h"
Pavel Labath2f1fbae2016-09-08 10:07:04 +000023#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Core/ThreadSafeValue.h"
Zachary Turner39de3112014-09-09 20:54:56 +000025#include "lldb/Host/HostThread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Target/Process.h"
27#include "lldb/Target/Thread.h"
Pavel Labath5f19b902017-11-13 16:16:33 +000028#include "lldb/Utility/ArchSpec.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000029#include "lldb/Utility/ConstString.h"
Zachary Turner97206d52017-05-12 04:51:55 +000030#include "lldb/Utility/Status.h"
Ravitheja Addepallye714c4f2017-05-26 11:46:27 +000031#include "lldb/Utility/StreamGDBRemote.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000032#include "lldb/Utility/StreamString.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000033#include "lldb/Utility/StringExtractor.h"
Zachary Turner573ab902017-03-21 18:25:04 +000034#include "lldb/Utility/StringList.h"
Pavel Labathf2a8bcc2017-06-27 10:45:31 +000035#include "lldb/Utility/StructuredData.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000036#include "lldb/lldb-private-forward.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037
Greg Clayton576d8832011-03-22 04:00:09 +000038#include "GDBRemoteCommunicationClient.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "GDBRemoteRegisterContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040
Pavel Labath2f1fbae2016-09-08 10:07:04 +000041#include "llvm/ADT/DenseMap.h"
42
Tamas Berghammerdb264a62015-03-31 09:52:22 +000043namespace lldb_private {
44namespace process_gdb_remote {
45
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046class ThreadGDBRemote;
47
Kate Stoneb9c1b512016-09-06 20:57:50 +000048class ProcessGDBRemote : public Process,
49 private GDBRemoteClientBase::ContinueDelegate {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000051 ProcessGDBRemote(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000052
Kate Stoneb9c1b512016-09-06 20:57:50 +000053 ~ProcessGDBRemote() override;
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000054
Kate Stoneb9c1b512016-09-06 20:57:50 +000055 static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
56 lldb::ListenerSP listener_sp,
57 const FileSpec *crash_file_path);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
Kate Stoneb9c1b512016-09-06 20:57:50 +000059 static void Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060
Kate Stoneb9c1b512016-09-06 20:57:50 +000061 static void DebuggerInitialize(Debugger &debugger);
Greg Clayton7f982402013-07-15 22:54:20 +000062
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 static void Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064
Kate Stoneb9c1b512016-09-06 20:57:50 +000065 static ConstString GetPluginNameStatic();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
Kate Stoneb9c1b512016-09-06 20:57:50 +000067 static const char *GetPluginDescriptionStatic();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068
Kate Stoneb9c1b512016-09-06 20:57:50 +000069 //------------------------------------------------------------------
70 // Check if a given Process
71 //------------------------------------------------------------------
72 bool CanDebug(lldb::TargetSP target_sp,
73 bool plugin_specified_by_name) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000074
Kate Stoneb9c1b512016-09-06 20:57:50 +000075 CommandObject *GetPluginCommandObject() override;
Jim Ingham5aee1622010-08-09 23:31:02 +000076
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 //------------------------------------------------------------------
78 // Creating a new process, or attaching to an existing one
79 //------------------------------------------------------------------
Zachary Turner97206d52017-05-12 04:51:55 +000080 Status WillLaunch(Module *module) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000081
Zachary Turner97206d52017-05-12 04:51:55 +000082 Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000083
Kate Stoneb9c1b512016-09-06 20:57:50 +000084 void DidLaunch() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085
Zachary Turner97206d52017-05-12 04:51:55 +000086 Status WillAttachToProcessWithID(lldb::pid_t pid) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087
Zachary Turner97206d52017-05-12 04:51:55 +000088 Status WillAttachToProcessWithName(const char *process_name,
89 bool wait_for_launch) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000090
Zachary Turner97206d52017-05-12 04:51:55 +000091 Status DoConnectRemote(Stream *strm, llvm::StringRef remote_url) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092
Zachary Turner97206d52017-05-12 04:51:55 +000093 Status WillLaunchOrAttach();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094
Zachary Turner97206d52017-05-12 04:51:55 +000095 Status DoAttachToProcessWithID(lldb::pid_t pid,
96 const ProcessAttachInfo &attach_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097
Zachary Turner97206d52017-05-12 04:51:55 +000098 Status
Kate Stoneb9c1b512016-09-06 20:57:50 +000099 DoAttachToProcessWithName(const char *process_name,
100 const ProcessAttachInfo &attach_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101
Kate Stoneb9c1b512016-09-06 20:57:50 +0000102 void DidAttach(ArchSpec &process_arch) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104 //------------------------------------------------------------------
105 // PluginInterface protocol
106 //------------------------------------------------------------------
107 ConstString GetPluginName() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108
Kate Stoneb9c1b512016-09-06 20:57:50 +0000109 uint32_t GetPluginVersion() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110
Kate Stoneb9c1b512016-09-06 20:57:50 +0000111 //------------------------------------------------------------------
112 // Process Control
113 //------------------------------------------------------------------
Zachary Turner97206d52017-05-12 04:51:55 +0000114 Status WillResume() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115
Zachary Turner97206d52017-05-12 04:51:55 +0000116 Status DoResume() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000117
Zachary Turner97206d52017-05-12 04:51:55 +0000118 Status DoHalt(bool &caused_stop) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119
Zachary Turner97206d52017-05-12 04:51:55 +0000120 Status DoDetach(bool keep_stopped) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000121
Kate Stoneb9c1b512016-09-06 20:57:50 +0000122 bool DetachRequiresHalt() override { return true; }
Chaoren Linc963a222015-09-01 16:58:45 +0000123
Zachary Turner97206d52017-05-12 04:51:55 +0000124 Status DoSignal(int signal) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000125
Zachary Turner97206d52017-05-12 04:51:55 +0000126 Status DoDestroy() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000127
Kate Stoneb9c1b512016-09-06 20:57:50 +0000128 void RefreshStateAfterStop() override;
Greg Clayton2e309072015-07-17 23:42:28 +0000129
Kate Stoneb9c1b512016-09-06 20:57:50 +0000130 void SetUnixSignals(const lldb::UnixSignalsSP &signals_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000131
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132 //------------------------------------------------------------------
133 // Process Queries
134 //------------------------------------------------------------------
135 bool IsAlive() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136
Kate Stoneb9c1b512016-09-06 20:57:50 +0000137 lldb::addr_t GetImageInfoAddress() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000138
Kate Stoneb9c1b512016-09-06 20:57:50 +0000139 void WillPublicStop() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000140
Kate Stoneb9c1b512016-09-06 20:57:50 +0000141 //------------------------------------------------------------------
142 // Process Memory
143 //------------------------------------------------------------------
144 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
Zachary Turner97206d52017-05-12 04:51:55 +0000145 Status &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146
Pavel Labath16064d32018-03-20 11:56:24 +0000147 Status
148 WriteObjectFile(std::vector<ObjectFile::LoadableData> entries) override;
149
Kate Stoneb9c1b512016-09-06 20:57:50 +0000150 size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size,
Zachary Turner97206d52017-05-12 04:51:55 +0000151 Status &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000152
Kate Stoneb9c1b512016-09-06 20:57:50 +0000153 lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
Zachary Turner97206d52017-05-12 04:51:55 +0000154 Status &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000155
Zachary Turner97206d52017-05-12 04:51:55 +0000156 Status GetMemoryRegionInfo(lldb::addr_t load_addr,
157 MemoryRegionInfo &region_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158
Zachary Turner97206d52017-05-12 04:51:55 +0000159 Status DoDeallocateMemory(lldb::addr_t ptr) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160
Kate Stoneb9c1b512016-09-06 20:57:50 +0000161 //------------------------------------------------------------------
162 // Process STDIO
163 //------------------------------------------------------------------
Zachary Turner97206d52017-05-12 04:51:55 +0000164 size_t PutSTDIN(const char *buf, size_t buf_size, Status &error) override;
Jim Ingham1c823b42011-01-22 01:33:44 +0000165
Kate Stoneb9c1b512016-09-06 20:57:50 +0000166 //----------------------------------------------------------------------
167 // Process Breakpoints
168 //----------------------------------------------------------------------
Zachary Turner97206d52017-05-12 04:51:55 +0000169 Status EnableBreakpointSite(BreakpointSite *bp_site) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000170
Zachary Turner97206d52017-05-12 04:51:55 +0000171 Status DisableBreakpointSite(BreakpointSite *bp_site) override;
Jason Molendaa3329782014-03-29 18:54:20 +0000172
Kate Stoneb9c1b512016-09-06 20:57:50 +0000173 //----------------------------------------------------------------------
174 // Process Watchpoints
175 //----------------------------------------------------------------------
Zachary Turner97206d52017-05-12 04:51:55 +0000176 Status EnableWatchpoint(Watchpoint *wp, bool notify = true) override;
Greg Claytonfbb76342013-11-20 21:07:01 +0000177
Zachary Turner97206d52017-05-12 04:51:55 +0000178 Status DisableWatchpoint(Watchpoint *wp, bool notify = true) override;
Jason Molenda6076bf42014-05-06 04:34:52 +0000179
Zachary Turner97206d52017-05-12 04:51:55 +0000180 Status GetWatchpointSupportInfo(uint32_t &num) override;
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +0000181
Ravitheja Addepallye714c4f2017-05-26 11:46:27 +0000182 lldb::user_id_t StartTrace(const TraceOptions &options,
183 Status &error) override;
184
185 Status StopTrace(lldb::user_id_t uid, lldb::tid_t thread_id) override;
186
187 Status GetData(lldb::user_id_t uid, lldb::tid_t thread_id,
188 llvm::MutableArrayRef<uint8_t> &buffer,
189 size_t offset = 0) override;
190
191 Status GetMetaData(lldb::user_id_t uid, lldb::tid_t thread_id,
192 llvm::MutableArrayRef<uint8_t> &buffer,
193 size_t offset = 0) override;
194
195 Status GetTraceConfig(lldb::user_id_t uid, TraceOptions &options) override;
196
Zachary Turner97206d52017-05-12 04:51:55 +0000197 Status GetWatchpointSupportInfo(uint32_t &num, bool &after) override;
Jim Ingham13c30d22015-11-05 22:33:17 +0000198
Kate Stoneb9c1b512016-09-06 20:57:50 +0000199 bool StartNoticingNewThreads() override;
Stephane Sezer87b0fe02016-01-12 19:02:41 +0000200
Kate Stoneb9c1b512016-09-06 20:57:50 +0000201 bool StopNoticingNewThreads() override;
Tamas Berghammer783bfc82015-06-18 20:43:56 +0000202
Kate Stoneb9c1b512016-09-06 20:57:50 +0000203 GDBRemoteCommunicationClient &GetGDBRemote() { return m_gdb_comm; }
Colin Rileyc3c95b22015-04-16 15:51:33 +0000204
Zachary Turner97206d52017-05-12 04:51:55 +0000205 Status SendEventData(const char *data) override;
Greg Clayton0b90be12015-06-23 21:27:50 +0000206
Kate Stoneb9c1b512016-09-06 20:57:50 +0000207 //----------------------------------------------------------------------
208 // Override DidExit so we can disconnect from the remote GDB server
209 //----------------------------------------------------------------------
210 void DidExit() override;
Jason Molenda20ee21b2015-07-10 23:15:22 +0000211
Kate Stoneb9c1b512016-09-06 20:57:50 +0000212 void SetUserSpecifiedMaxMemoryTransferSize(uint64_t user_specified_max);
Todd Fiala75930012016-08-19 04:21:48 +0000213
Kate Stoneb9c1b512016-09-06 20:57:50 +0000214 bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
215 ModuleSpec &module_spec) override;
Jason Molenda9ab5dc22016-07-21 08:30:55 +0000216
Pavel Labath2f1fbae2016-09-08 10:07:04 +0000217 void PrefetchModuleSpecs(llvm::ArrayRef<FileSpec> module_file_specs,
218 const llvm::Triple &triple) override;
219
Kate Stoneb9c1b512016-09-06 20:57:50 +0000220 bool GetHostOSVersion(uint32_t &major, uint32_t &minor,
221 uint32_t &update) override;
Jason Molenda9ab5dc22016-07-21 08:30:55 +0000222
Kate Stoneb9c1b512016-09-06 20:57:50 +0000223 size_t LoadModules(LoadedModuleInfoList &module_list) override;
Jason Molenda9ab5dc22016-07-21 08:30:55 +0000224
Kate Stoneb9c1b512016-09-06 20:57:50 +0000225 size_t LoadModules() override;
Jason Molenda37397352016-07-22 00:17:55 +0000226
Zachary Turner97206d52017-05-12 04:51:55 +0000227 Status GetFileLoadAddress(const FileSpec &file, bool &is_loaded,
228 lldb::addr_t &load_addr) override;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000229
230 void ModulesDidLoad(ModuleList &module_list) override;
231
232 StructuredData::ObjectSP
233 GetLoadedDynamicLibrariesInfos(lldb::addr_t image_list_address,
234 lldb::addr_t image_count) override;
235
Zachary Turner97206d52017-05-12 04:51:55 +0000236 Status
Kate Stoneb9c1b512016-09-06 20:57:50 +0000237 ConfigureStructuredData(const ConstString &type_name,
238 const StructuredData::ObjectSP &config_sp) override;
239
240 StructuredData::ObjectSP GetLoadedDynamicLibrariesInfos() override;
241
242 StructuredData::ObjectSP GetLoadedDynamicLibrariesInfos(
243 const std::vector<lldb::addr_t> &load_addresses) override;
244
245 StructuredData::ObjectSP
246 GetLoadedDynamicLibrariesInfos_sender(StructuredData::ObjectSP args);
247
248 StructuredData::ObjectSP GetSharedCacheInfo() override;
249
250 std::string HarmonizeThreadIdsForProfileData(
251 StringExtractorGDBRemote &inputStringExtractor);
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000252
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000253protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000254 friend class ThreadGDBRemote;
255 friend class GDBRemoteCommunicationClient;
256 friend class GDBRemoteRegisterContext;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000257
Kate Stoneb9c1b512016-09-06 20:57:50 +0000258 //------------------------------------------------------------------
259 /// Broadcaster event bits definitions.
260 //------------------------------------------------------------------
261 enum {
262 eBroadcastBitAsyncContinue = (1 << 0),
263 eBroadcastBitAsyncThreadShouldExit = (1 << 1),
264 eBroadcastBitAsyncThreadDidExit = (1 << 2)
265 };
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000266
Kate Stoneb9c1b512016-09-06 20:57:50 +0000267 GDBRemoteCommunicationClient m_gdb_comm;
268 std::atomic<lldb::pid_t> m_debugserver_pid;
269 std::vector<StringExtractorGDBRemote> m_stop_packet_stack; // The stop packet
270 // stack replaces
271 // the last stop
272 // packet variable
273 std::recursive_mutex m_last_stop_packet_mutex;
274 GDBRemoteDynamicRegisterInfo m_register_info;
275 Broadcaster m_async_broadcaster;
276 lldb::ListenerSP m_async_listener_sp;
277 HostThread m_async_thread;
278 std::recursive_mutex m_async_thread_state_mutex;
279 typedef std::vector<lldb::tid_t> tid_collection;
280 typedef std::vector<std::pair<lldb::tid_t, int>> tid_sig_collection;
281 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
282 typedef std::map<uint32_t, std::string> ExpeditedRegisterMap;
283 tid_collection m_thread_ids; // Thread IDs for all threads. This list gets
284 // updated after stopping
285 std::vector<lldb::addr_t> m_thread_pcs; // PC values for all the threads.
286 StructuredData::ObjectSP m_jstopinfo_sp; // Stop info only for any threads
287 // that have valid stop infos
288 StructuredData::ObjectSP m_jthreadsinfo_sp; // Full stop info, expedited
289 // registers and memory for all
290 // threads if "jThreadsInfo"
291 // packet is supported
292 tid_collection m_continue_c_tids; // 'c' for continue
293 tid_sig_collection m_continue_C_tids; // 'C' for continue with signal
294 tid_collection m_continue_s_tids; // 's' for step
295 tid_sig_collection m_continue_S_tids; // 'S' for step with signal
296 uint64_t m_max_memory_size; // The maximum number of bytes to read/write when
297 // reading and writing memory
298 uint64_t m_remote_stub_max_memory_size; // The maximum memory size the remote
299 // gdb stub can handle
300 MMapMap m_addr_to_mmap_size;
301 lldb::BreakpointSP m_thread_create_bp_sp;
302 bool m_waiting_for_attach;
303 bool m_destroy_tried_resuming;
304 lldb::CommandObjectSP m_command_sp;
305 int64_t m_breakpoint_pc_offset;
306 lldb::tid_t m_initial_tid; // The initial thread ID, given by stub on attach
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000307
Pavel Labath16064d32018-03-20 11:56:24 +0000308 bool m_allow_flash_writes;
309 using FlashRangeVector = lldb_private::RangeVector<lldb::addr_t, size_t>;
310 using FlashRange = FlashRangeVector::Entry;
311 FlashRangeVector m_erased_flash_ranges;
312
Kate Stoneb9c1b512016-09-06 20:57:50 +0000313 //----------------------------------------------------------------------
314 // Accessors
315 //----------------------------------------------------------------------
316 bool IsRunning(lldb::StateType state) {
317 return state == lldb::eStateRunning || IsStepping(state);
318 }
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000319
Kate Stoneb9c1b512016-09-06 20:57:50 +0000320 bool IsStepping(lldb::StateType state) {
321 return state == lldb::eStateStepping;
322 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000323
Kate Stoneb9c1b512016-09-06 20:57:50 +0000324 bool CanResume(lldb::StateType state) { return state == lldb::eStateStopped; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000325
Kate Stoneb9c1b512016-09-06 20:57:50 +0000326 bool HasExited(lldb::StateType state) { return state == lldb::eStateExited; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000327
Kate Stoneb9c1b512016-09-06 20:57:50 +0000328 bool ProcessIDIsValid() const;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000329
Kate Stoneb9c1b512016-09-06 20:57:50 +0000330 void Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000331
Kate Stoneb9c1b512016-09-06 20:57:50 +0000332 bool UpdateThreadList(ThreadList &old_thread_list,
333 ThreadList &new_thread_list) override;
Oleksiy Vyalovafd6ce42015-11-23 19:32:24 +0000334
Zachary Turner97206d52017-05-12 04:51:55 +0000335 Status EstablishConnectionIfNeeded(const ProcessInfo &process_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336
Zachary Turner97206d52017-05-12 04:51:55 +0000337 Status LaunchAndConnectToDebugserver(const ProcessInfo &process_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000338
Kate Stoneb9c1b512016-09-06 20:57:50 +0000339 void KillDebugserverProcess();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000340
Kate Stoneb9c1b512016-09-06 20:57:50 +0000341 void BuildDynamicRegisterInfo(bool force);
Jason Molendad1fae142012-09-29 08:03:33 +0000342
Kate Stoneb9c1b512016-09-06 20:57:50 +0000343 void SetLastStopPacket(const StringExtractorGDBRemote &response);
Greg Claytonef8180a2013-10-15 00:14:28 +0000344
Kate Stoneb9c1b512016-09-06 20:57:50 +0000345 bool ParsePythonTargetDefinition(const FileSpec &target_definition_fspec);
Steve Pucci03904ac2014-03-04 23:18:46 +0000346
Kate Stoneb9c1b512016-09-06 20:57:50 +0000347 const lldb::DataBufferSP GetAuxvData() override;
Jason Molenda705b1802014-06-13 02:37:02 +0000348
Kate Stoneb9c1b512016-09-06 20:57:50 +0000349 StructuredData::ObjectSP GetExtendedInfoForThread(lldb::tid_t tid);
Jason Molenda6076bf42014-05-06 04:34:52 +0000350
Kate Stoneb9c1b512016-09-06 20:57:50 +0000351 void GetMaxMemorySize();
Greg Clayton358cf1e2015-06-25 21:46:34 +0000352
Kate Stoneb9c1b512016-09-06 20:57:50 +0000353 bool CalculateThreadStopInfo(ThreadGDBRemote *thread);
Jason Molenda545304d2015-12-18 00:45:35 +0000354
Kate Stoneb9c1b512016-09-06 20:57:50 +0000355 size_t UpdateThreadPCsFromStopReplyThreadsValue(std::string &value);
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000356
Kate Stoneb9c1b512016-09-06 20:57:50 +0000357 size_t UpdateThreadIDsFromStopReplyThreadsValue(std::string &value);
Ewan Crawford76df2882015-06-23 12:32:06 +0000358
Kate Stoneb9c1b512016-09-06 20:57:50 +0000359 bool HandleNotifyPacket(StringExtractorGDBRemote &packet);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000360
Kate Stoneb9c1b512016-09-06 20:57:50 +0000361 bool StartAsyncThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000362
Kate Stoneb9c1b512016-09-06 20:57:50 +0000363 void StopAsyncThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000364
Kate Stoneb9c1b512016-09-06 20:57:50 +0000365 static lldb::thread_result_t AsyncThread(void *arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000366
Kate Stoneb9c1b512016-09-06 20:57:50 +0000367 static bool
368 MonitorDebugserverProcess(std::weak_ptr<ProcessGDBRemote> process_wp,
369 lldb::pid_t pid, bool exited, int signo,
370 int exit_status);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000371
Kate Stoneb9c1b512016-09-06 20:57:50 +0000372 lldb::StateType SetThreadStopInfo(StringExtractor &stop_packet);
Greg Clayton2e309072015-07-17 23:42:28 +0000373
Kate Stoneb9c1b512016-09-06 20:57:50 +0000374 bool
375 GetThreadStopInfoFromJSON(ThreadGDBRemote *thread,
376 const StructuredData::ObjectSP &thread_infos_sp);
Greg Clayton358cf1e2015-06-25 21:46:34 +0000377
Kate Stoneb9c1b512016-09-06 20:57:50 +0000378 lldb::ThreadSP SetThreadStopInfo(StructuredData::Dictionary *thread_dict);
Greg Clayton358cf1e2015-06-25 21:46:34 +0000379
Kate Stoneb9c1b512016-09-06 20:57:50 +0000380 lldb::ThreadSP
381 SetThreadStopInfo(lldb::tid_t tid,
382 ExpeditedRegisterMap &expedited_register_map, uint8_t signo,
383 const std::string &thread_name, const std::string &reason,
384 const std::string &description, uint32_t exc_type,
385 const std::vector<lldb::addr_t> &exc_data,
386 lldb::addr_t thread_dispatch_qaddr, bool queue_vars_valid,
387 lldb_private::LazyBool associated_with_libdispatch_queue,
388 lldb::addr_t dispatch_queue_t, std::string &queue_name,
389 lldb::QueueKind queue_kind, uint64_t queue_serial);
Ewan Crawford78baa192015-05-13 09:18:18 +0000390
Kate Stoneb9c1b512016-09-06 20:57:50 +0000391 void HandleStopReplySequence();
Greg Clayton9e920902012-04-10 02:25:43 +0000392
Kate Stoneb9c1b512016-09-06 20:57:50 +0000393 void ClearThreadIDList();
Greg Clayton9e920902012-04-10 02:25:43 +0000394
Kate Stoneb9c1b512016-09-06 20:57:50 +0000395 bool UpdateThreadIDList();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396
Kate Stoneb9c1b512016-09-06 20:57:50 +0000397 void DidLaunchOrAttach(ArchSpec &process_arch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000398
Zachary Turner97206d52017-05-12 04:51:55 +0000399 Status ConnectToDebugserver(llvm::StringRef host_port);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400
Kate Stoneb9c1b512016-09-06 20:57:50 +0000401 const char *GetDispatchQueueNameForThread(lldb::addr_t thread_dispatch_qaddr,
402 std::string &dispatch_queue_name);
Jason Molenda5e8534e2012-10-03 01:29:34 +0000403
Kate Stoneb9c1b512016-09-06 20:57:50 +0000404 DynamicLoader *GetDynamicLoader() override;
Aidan Doddsc0c83852015-05-08 09:36:31 +0000405
Kate Stoneb9c1b512016-09-06 20:57:50 +0000406 // Query remote GDBServer for register information
407 bool GetGDBServerRegisterInfo(ArchSpec &arch);
Aidan Doddsc0c83852015-05-08 09:36:31 +0000408
Kate Stoneb9c1b512016-09-06 20:57:50 +0000409 // Query remote GDBServer for a detailed loaded library list
Zachary Turner97206d52017-05-12 04:51:55 +0000410 Status GetLoadedModuleList(LoadedModuleInfoList &);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000411
412 lldb::ModuleSP LoadModuleAtAddress(const FileSpec &file,
413 lldb::addr_t link_map,
414 lldb::addr_t base_addr,
415 bool value_is_offset);
Aidan Doddsc0c83852015-05-08 09:36:31 +0000416
Zachary Turner97206d52017-05-12 04:51:55 +0000417 Status UpdateAutomaticSignalFiltering() override;
Eugene Zemtsov7993cc52017-03-07 21:34:40 +0000418
Pavel Labath16064d32018-03-20 11:56:24 +0000419 Status FlashErase(lldb::addr_t addr, size_t size);
420
421 Status FlashDone();
422
423 bool HasErased(FlashRange range);
424
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000426 //------------------------------------------------------------------
427 // For ProcessGDBRemote only
428 //------------------------------------------------------------------
429 std::string m_partial_profile_data;
430 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
Eugene Zemtsov7993cc52017-03-07 21:34:40 +0000431 uint64_t m_last_signals_version = 0;
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000432
Kate Stoneb9c1b512016-09-06 20:57:50 +0000433 static bool NewThreadNotifyBreakpointHit(void *baton,
434 StoppointCallbackContext *context,
435 lldb::user_id_t break_id,
436 lldb::user_id_t break_loc_id);
Jim Ingham1c823b42011-01-22 01:33:44 +0000437
Kate Stoneb9c1b512016-09-06 20:57:50 +0000438 //------------------------------------------------------------------
439 // ContinueDelegate interface
440 //------------------------------------------------------------------
441 void HandleAsyncStdout(llvm::StringRef out) override;
442 void HandleAsyncMisc(llvm::StringRef data) override;
443 void HandleStopReply() override;
Todd Fialafcdb1af2016-09-10 00:06:29 +0000444 void HandleAsyncStructuredDataPacket(llvm::StringRef data) override;
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000445
Pavel Labathe0a5b572017-01-20 14:17:16 +0000446 void SetThreadPc(const lldb::ThreadSP &thread_sp, uint64_t index);
Pavel Labath2f1fbae2016-09-08 10:07:04 +0000447 using ModuleCacheKey = std::pair<std::string, std::string>;
448 // KeyInfo for the cached module spec DenseMap.
449 // The invariant is that all real keys will have the file and architecture
450 // set.
451 // The empty key has an empty file and an empty arch.
452 // The tombstone key has an invalid arch and an empty file.
453 // The comparison and hash functions take the file name and architecture
454 // triple into account.
455 struct ModuleCacheInfo {
456 static ModuleCacheKey getEmptyKey() { return ModuleCacheKey(); }
457
458 static ModuleCacheKey getTombstoneKey() { return ModuleCacheKey("", "T"); }
459
460 static unsigned getHashValue(const ModuleCacheKey &key) {
461 return llvm::hash_combine(key.first, key.second);
462 }
463
464 static bool isEqual(const ModuleCacheKey &LHS, const ModuleCacheKey &RHS) {
465 return LHS == RHS;
466 }
467 };
468
469 llvm::DenseMap<ModuleCacheKey, ModuleSpec, ModuleCacheInfo>
470 m_cached_module_specs;
471
Kate Stoneb9c1b512016-09-06 20:57:50 +0000472 DISALLOW_COPY_AND_ASSIGN(ProcessGDBRemote);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000473};
474
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000475} // namespace process_gdb_remote
476} // namespace lldb_private
477
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000478#endif // liblldb_ProcessGDBRemote_h_