blob: aa9aff5549f3eca9349cf6ebe811bc301c3badc9 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ProcessGDBRemote.h --------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef liblldb_ProcessGDBRemote_h_
10#define liblldb_ProcessGDBRemote_h_
11
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000012#include <atomic>
13#include <map>
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +000014#include <mutex>
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000015#include <string>
Greg Clayton71fc2a32011-02-12 06:28:37 +000016#include <vector>
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017
Kate Stoneb9c1b512016-09-06 20:57:50 +000018#include "lldb/Core/LoadedModuleInfoList.h"
Pavel Labath2f1fbae2016-09-08 10:07:04 +000019#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/ThreadSafeValue.h"
Zachary Turner39de3112014-09-09 20:54:56 +000021#include "lldb/Host/HostThread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Target/Process.h"
23#include "lldb/Target/Thread.h"
Pavel Labath5f19b902017-11-13 16:16:33 +000024#include "lldb/Utility/ArchSpec.h"
Pavel Labath181b8232018-12-14 15:59:49 +000025#include "lldb/Utility/Broadcaster.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000026#include "lldb/Utility/ConstString.h"
Zachary Turner97206d52017-05-12 04:51:55 +000027#include "lldb/Utility/Status.h"
Ravitheja Addepallye714c4f2017-05-26 11:46:27 +000028#include "lldb/Utility/StreamGDBRemote.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000029#include "lldb/Utility/StreamString.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000030#include "lldb/Utility/StringExtractor.h"
Zachary Turner573ab902017-03-21 18:25:04 +000031#include "lldb/Utility/StringList.h"
Pavel Labathf2a8bcc2017-06-27 10:45:31 +000032#include "lldb/Utility/StructuredData.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000033#include "lldb/lldb-private-forward.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034
Greg Clayton576d8832011-03-22 04:00:09 +000035#include "GDBRemoteCommunicationClient.h"
Jonas Devlieghere9e046f02018-11-13 19:18:16 +000036#include "GDBRemoteCommunicationReplayServer.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037#include "GDBRemoteRegisterContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038
Pavel Labath2f1fbae2016-09-08 10:07:04 +000039#include "llvm/ADT/DenseMap.h"
40
Tamas Berghammerdb264a62015-03-31 09:52:22 +000041namespace lldb_private {
Jonas Devlieghere9e046f02018-11-13 19:18:16 +000042namespace repro {
43class Loader;
44}
Tamas Berghammerdb264a62015-03-31 09:52:22 +000045namespace process_gdb_remote {
46
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047class ThreadGDBRemote;
48
Kate Stoneb9c1b512016-09-06 20:57:50 +000049class ProcessGDBRemote : public Process,
50 private GDBRemoteClientBase::ContinueDelegate {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000052 ProcessGDBRemote(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000053
Kate Stoneb9c1b512016-09-06 20:57:50 +000054 ~ProcessGDBRemote() override;
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000055
Kate Stoneb9c1b512016-09-06 20:57:50 +000056 static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
57 lldb::ListenerSP listener_sp,
58 const FileSpec *crash_file_path);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059
Kate Stoneb9c1b512016-09-06 20:57:50 +000060 static void Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
Kate Stoneb9c1b512016-09-06 20:57:50 +000062 static void DebuggerInitialize(Debugger &debugger);
Greg Clayton7f982402013-07-15 22:54:20 +000063
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 static void Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065
Kate Stoneb9c1b512016-09-06 20:57:50 +000066 static ConstString GetPluginNameStatic();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067
Kate Stoneb9c1b512016-09-06 20:57:50 +000068 static const char *GetPluginDescriptionStatic();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069
Kate Stoneb9c1b512016-09-06 20:57:50 +000070 //------------------------------------------------------------------
71 // Check if a given Process
72 //------------------------------------------------------------------
73 bool CanDebug(lldb::TargetSP target_sp,
74 bool plugin_specified_by_name) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075
Kate Stoneb9c1b512016-09-06 20:57:50 +000076 CommandObject *GetPluginCommandObject() override;
Jim Ingham5aee1622010-08-09 23:31:02 +000077
Kate Stoneb9c1b512016-09-06 20:57:50 +000078 //------------------------------------------------------------------
79 // Creating a new process, or attaching to an existing one
80 //------------------------------------------------------------------
Zachary Turner97206d52017-05-12 04:51:55 +000081 Status WillLaunch(Module *module) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082
Zachary Turner97206d52017-05-12 04:51:55 +000083 Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 void DidLaunch() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086
Zachary Turner97206d52017-05-12 04:51:55 +000087 Status WillAttachToProcessWithID(lldb::pid_t pid) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088
Zachary Turner97206d52017-05-12 04:51:55 +000089 Status WillAttachToProcessWithName(const char *process_name,
90 bool wait_for_launch) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091
Zachary Turner97206d52017-05-12 04:51:55 +000092 Status DoConnectRemote(Stream *strm, llvm::StringRef remote_url) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093
Zachary Turner97206d52017-05-12 04:51:55 +000094 Status WillLaunchOrAttach();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000095
Zachary Turner97206d52017-05-12 04:51:55 +000096 Status DoAttachToProcessWithID(lldb::pid_t pid,
97 const ProcessAttachInfo &attach_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000098
Zachary Turner97206d52017-05-12 04:51:55 +000099 Status
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100 DoAttachToProcessWithName(const char *process_name,
101 const ProcessAttachInfo &attach_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102
Kate Stoneb9c1b512016-09-06 20:57:50 +0000103 void DidAttach(ArchSpec &process_arch) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000104
Kate Stoneb9c1b512016-09-06 20:57:50 +0000105 //------------------------------------------------------------------
106 // PluginInterface protocol
107 //------------------------------------------------------------------
108 ConstString GetPluginName() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109
Kate Stoneb9c1b512016-09-06 20:57:50 +0000110 uint32_t GetPluginVersion() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111
Kate Stoneb9c1b512016-09-06 20:57:50 +0000112 //------------------------------------------------------------------
113 // Process Control
114 //------------------------------------------------------------------
Zachary Turner97206d52017-05-12 04:51:55 +0000115 Status WillResume() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116
Zachary Turner97206d52017-05-12 04:51:55 +0000117 Status DoResume() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118
Zachary Turner97206d52017-05-12 04:51:55 +0000119 Status DoHalt(bool &caused_stop) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000120
Zachary Turner97206d52017-05-12 04:51:55 +0000121 Status DoDetach(bool keep_stopped) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000122
Kate Stoneb9c1b512016-09-06 20:57:50 +0000123 bool DetachRequiresHalt() override { return true; }
Chaoren Linc963a222015-09-01 16:58:45 +0000124
Zachary Turner97206d52017-05-12 04:51:55 +0000125 Status DoSignal(int signal) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126
Zachary Turner97206d52017-05-12 04:51:55 +0000127 Status DoDestroy() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000128
Kate Stoneb9c1b512016-09-06 20:57:50 +0000129 void RefreshStateAfterStop() override;
Greg Clayton2e309072015-07-17 23:42:28 +0000130
Kate Stoneb9c1b512016-09-06 20:57:50 +0000131 void SetUnixSignals(const lldb::UnixSignalsSP &signals_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000132
Kate Stoneb9c1b512016-09-06 20:57:50 +0000133 //------------------------------------------------------------------
134 // Process Queries
135 //------------------------------------------------------------------
136 bool IsAlive() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000137
Kate Stoneb9c1b512016-09-06 20:57:50 +0000138 lldb::addr_t GetImageInfoAddress() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000139
Kate Stoneb9c1b512016-09-06 20:57:50 +0000140 void WillPublicStop() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000141
Kate Stoneb9c1b512016-09-06 20:57:50 +0000142 //------------------------------------------------------------------
143 // Process Memory
144 //------------------------------------------------------------------
145 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
Zachary Turner97206d52017-05-12 04:51:55 +0000146 Status &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147
Pavel Labath16064d32018-03-20 11:56:24 +0000148 Status
149 WriteObjectFile(std::vector<ObjectFile::LoadableData> entries) override;
150
Kate Stoneb9c1b512016-09-06 20:57:50 +0000151 size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size,
Zachary Turner97206d52017-05-12 04:51:55 +0000152 Status &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000153
Kate Stoneb9c1b512016-09-06 20:57:50 +0000154 lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
Zachary Turner97206d52017-05-12 04:51:55 +0000155 Status &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156
Zachary Turner97206d52017-05-12 04:51:55 +0000157 Status GetMemoryRegionInfo(lldb::addr_t load_addr,
158 MemoryRegionInfo &region_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159
Zachary Turner97206d52017-05-12 04:51:55 +0000160 Status DoDeallocateMemory(lldb::addr_t ptr) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161
Kate Stoneb9c1b512016-09-06 20:57:50 +0000162 //------------------------------------------------------------------
163 // Process STDIO
164 //------------------------------------------------------------------
Zachary Turner97206d52017-05-12 04:51:55 +0000165 size_t PutSTDIN(const char *buf, size_t buf_size, Status &error) override;
Jim Ingham1c823b42011-01-22 01:33:44 +0000166
Kate Stoneb9c1b512016-09-06 20:57:50 +0000167 //----------------------------------------------------------------------
168 // Process Breakpoints
169 //----------------------------------------------------------------------
Zachary Turner97206d52017-05-12 04:51:55 +0000170 Status EnableBreakpointSite(BreakpointSite *bp_site) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000171
Zachary Turner97206d52017-05-12 04:51:55 +0000172 Status DisableBreakpointSite(BreakpointSite *bp_site) override;
Jason Molendaa3329782014-03-29 18:54:20 +0000173
Kate Stoneb9c1b512016-09-06 20:57:50 +0000174 //----------------------------------------------------------------------
175 // Process Watchpoints
176 //----------------------------------------------------------------------
Zachary Turner97206d52017-05-12 04:51:55 +0000177 Status EnableWatchpoint(Watchpoint *wp, bool notify = true) override;
Greg Claytonfbb76342013-11-20 21:07:01 +0000178
Zachary Turner97206d52017-05-12 04:51:55 +0000179 Status DisableWatchpoint(Watchpoint *wp, bool notify = true) override;
Jason Molenda6076bf42014-05-06 04:34:52 +0000180
Zachary Turner97206d52017-05-12 04:51:55 +0000181 Status GetWatchpointSupportInfo(uint32_t &num) override;
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +0000182
Ravitheja Addepallye714c4f2017-05-26 11:46:27 +0000183 lldb::user_id_t StartTrace(const TraceOptions &options,
184 Status &error) override;
185
186 Status StopTrace(lldb::user_id_t uid, lldb::tid_t thread_id) override;
187
188 Status GetData(lldb::user_id_t uid, lldb::tid_t thread_id,
189 llvm::MutableArrayRef<uint8_t> &buffer,
190 size_t offset = 0) override;
191
192 Status GetMetaData(lldb::user_id_t uid, lldb::tid_t thread_id,
193 llvm::MutableArrayRef<uint8_t> &buffer,
194 size_t offset = 0) override;
195
196 Status GetTraceConfig(lldb::user_id_t uid, TraceOptions &options) override;
197
Zachary Turner97206d52017-05-12 04:51:55 +0000198 Status GetWatchpointSupportInfo(uint32_t &num, bool &after) override;
Jim Ingham13c30d22015-11-05 22:33:17 +0000199
Kate Stoneb9c1b512016-09-06 20:57:50 +0000200 bool StartNoticingNewThreads() override;
Stephane Sezer87b0fe02016-01-12 19:02:41 +0000201
Kate Stoneb9c1b512016-09-06 20:57:50 +0000202 bool StopNoticingNewThreads() override;
Tamas Berghammer783bfc82015-06-18 20:43:56 +0000203
Kate Stoneb9c1b512016-09-06 20:57:50 +0000204 GDBRemoteCommunicationClient &GetGDBRemote() { return m_gdb_comm; }
Colin Rileyc3c95b22015-04-16 15:51:33 +0000205
Zachary Turner97206d52017-05-12 04:51:55 +0000206 Status SendEventData(const char *data) override;
Greg Clayton0b90be12015-06-23 21:27:50 +0000207
Kate Stoneb9c1b512016-09-06 20:57:50 +0000208 //----------------------------------------------------------------------
209 // Override DidExit so we can disconnect from the remote GDB server
210 //----------------------------------------------------------------------
211 void DidExit() override;
Jason Molenda20ee21b2015-07-10 23:15:22 +0000212
Kate Stoneb9c1b512016-09-06 20:57:50 +0000213 void SetUserSpecifiedMaxMemoryTransferSize(uint64_t user_specified_max);
Todd Fiala75930012016-08-19 04:21:48 +0000214
Kate Stoneb9c1b512016-09-06 20:57:50 +0000215 bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
216 ModuleSpec &module_spec) override;
Jason Molenda9ab5dc22016-07-21 08:30:55 +0000217
Pavel Labath2f1fbae2016-09-08 10:07:04 +0000218 void PrefetchModuleSpecs(llvm::ArrayRef<FileSpec> module_file_specs,
219 const llvm::Triple &triple) override;
220
Pavel Labath2272c482018-06-18 15:02:23 +0000221 llvm::VersionTuple GetHostOSVersion() 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;
Jonas Devlieghere9e046f02018-11-13 19:18:16 +0000268 GDBRemoteCommunicationReplayServer m_gdb_replay_server;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000269 std::atomic<lldb::pid_t> m_debugserver_pid;
270 std::vector<StringExtractorGDBRemote> m_stop_packet_stack; // The stop packet
271 // stack replaces
272 // the last stop
273 // packet variable
274 std::recursive_mutex m_last_stop_packet_mutex;
275 GDBRemoteDynamicRegisterInfo m_register_info;
276 Broadcaster m_async_broadcaster;
277 lldb::ListenerSP m_async_listener_sp;
278 HostThread m_async_thread;
279 std::recursive_mutex m_async_thread_state_mutex;
280 typedef std::vector<lldb::tid_t> tid_collection;
281 typedef std::vector<std::pair<lldb::tid_t, int>> tid_sig_collection;
282 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
283 typedef std::map<uint32_t, std::string> ExpeditedRegisterMap;
284 tid_collection m_thread_ids; // Thread IDs for all threads. This list gets
285 // updated after stopping
286 std::vector<lldb::addr_t> m_thread_pcs; // PC values for all the threads.
287 StructuredData::ObjectSP m_jstopinfo_sp; // Stop info only for any threads
288 // that have valid stop infos
289 StructuredData::ObjectSP m_jthreadsinfo_sp; // Full stop info, expedited
290 // registers and memory for all
291 // threads if "jThreadsInfo"
292 // packet is supported
293 tid_collection m_continue_c_tids; // 'c' for continue
294 tid_sig_collection m_continue_C_tids; // 'C' for continue with signal
295 tid_collection m_continue_s_tids; // 's' for step
296 tid_sig_collection m_continue_S_tids; // 'S' for step with signal
297 uint64_t m_max_memory_size; // The maximum number of bytes to read/write when
298 // reading and writing memory
299 uint64_t m_remote_stub_max_memory_size; // The maximum memory size the remote
300 // gdb stub can handle
301 MMapMap m_addr_to_mmap_size;
302 lldb::BreakpointSP m_thread_create_bp_sp;
303 bool m_waiting_for_attach;
304 bool m_destroy_tried_resuming;
305 lldb::CommandObjectSP m_command_sp;
306 int64_t m_breakpoint_pc_offset;
307 lldb::tid_t m_initial_tid; // The initial thread ID, given by stub on attach
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000308
Jonas Devlieghere9e046f02018-11-13 19:18:16 +0000309 bool m_replay_mode;
Pavel Labath16064d32018-03-20 11:56:24 +0000310 bool m_allow_flash_writes;
311 using FlashRangeVector = lldb_private::RangeVector<lldb::addr_t, size_t>;
312 using FlashRange = FlashRangeVector::Entry;
313 FlashRangeVector m_erased_flash_ranges;
314
Kate Stoneb9c1b512016-09-06 20:57:50 +0000315 //----------------------------------------------------------------------
316 // Accessors
317 //----------------------------------------------------------------------
318 bool IsRunning(lldb::StateType state) {
319 return state == lldb::eStateRunning || IsStepping(state);
320 }
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000321
Kate Stoneb9c1b512016-09-06 20:57:50 +0000322 bool IsStepping(lldb::StateType state) {
323 return state == lldb::eStateStepping;
324 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000325
Kate Stoneb9c1b512016-09-06 20:57:50 +0000326 bool CanResume(lldb::StateType state) { return state == lldb::eStateStopped; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000327
Kate Stoneb9c1b512016-09-06 20:57:50 +0000328 bool HasExited(lldb::StateType state) { return state == lldb::eStateExited; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000329
Kate Stoneb9c1b512016-09-06 20:57:50 +0000330 bool ProcessIDIsValid() const;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000331
Kate Stoneb9c1b512016-09-06 20:57:50 +0000332 void Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333
Kate Stoneb9c1b512016-09-06 20:57:50 +0000334 bool UpdateThreadList(ThreadList &old_thread_list,
335 ThreadList &new_thread_list) override;
Oleksiy Vyalovafd6ce42015-11-23 19:32:24 +0000336
Jonas Devlieghere9e046f02018-11-13 19:18:16 +0000337 Status ConnectToReplayServer(repro::Loader *loader);
338
Zachary Turner97206d52017-05-12 04:51:55 +0000339 Status EstablishConnectionIfNeeded(const ProcessInfo &process_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000340
Zachary Turner97206d52017-05-12 04:51:55 +0000341 Status LaunchAndConnectToDebugserver(const ProcessInfo &process_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000342
Kate Stoneb9c1b512016-09-06 20:57:50 +0000343 void KillDebugserverProcess();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344
Kate Stoneb9c1b512016-09-06 20:57:50 +0000345 void BuildDynamicRegisterInfo(bool force);
Jason Molendad1fae142012-09-29 08:03:33 +0000346
Kate Stoneb9c1b512016-09-06 20:57:50 +0000347 void SetLastStopPacket(const StringExtractorGDBRemote &response);
Greg Claytonef8180a2013-10-15 00:14:28 +0000348
Kate Stoneb9c1b512016-09-06 20:57:50 +0000349 bool ParsePythonTargetDefinition(const FileSpec &target_definition_fspec);
Steve Pucci03904ac2014-03-04 23:18:46 +0000350
Kate Stoneb9c1b512016-09-06 20:57:50 +0000351 const lldb::DataBufferSP GetAuxvData() override;
Jason Molenda705b1802014-06-13 02:37:02 +0000352
Kate Stoneb9c1b512016-09-06 20:57:50 +0000353 StructuredData::ObjectSP GetExtendedInfoForThread(lldb::tid_t tid);
Jason Molenda6076bf42014-05-06 04:34:52 +0000354
Kate Stoneb9c1b512016-09-06 20:57:50 +0000355 void GetMaxMemorySize();
Greg Clayton358cf1e2015-06-25 21:46:34 +0000356
Kate Stoneb9c1b512016-09-06 20:57:50 +0000357 bool CalculateThreadStopInfo(ThreadGDBRemote *thread);
Jason Molenda545304d2015-12-18 00:45:35 +0000358
Kate Stoneb9c1b512016-09-06 20:57:50 +0000359 size_t UpdateThreadPCsFromStopReplyThreadsValue(std::string &value);
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000360
Kate Stoneb9c1b512016-09-06 20:57:50 +0000361 size_t UpdateThreadIDsFromStopReplyThreadsValue(std::string &value);
Ewan Crawford76df2882015-06-23 12:32:06 +0000362
Kate Stoneb9c1b512016-09-06 20:57:50 +0000363 bool HandleNotifyPacket(StringExtractorGDBRemote &packet);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000364
Kate Stoneb9c1b512016-09-06 20:57:50 +0000365 bool StartAsyncThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000366
Kate Stoneb9c1b512016-09-06 20:57:50 +0000367 void StopAsyncThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368
Kate Stoneb9c1b512016-09-06 20:57:50 +0000369 static lldb::thread_result_t AsyncThread(void *arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370
Kate Stoneb9c1b512016-09-06 20:57:50 +0000371 static bool
372 MonitorDebugserverProcess(std::weak_ptr<ProcessGDBRemote> process_wp,
373 lldb::pid_t pid, bool exited, int signo,
374 int exit_status);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375
Kate Stoneb9c1b512016-09-06 20:57:50 +0000376 lldb::StateType SetThreadStopInfo(StringExtractor &stop_packet);
Greg Clayton2e309072015-07-17 23:42:28 +0000377
Kate Stoneb9c1b512016-09-06 20:57:50 +0000378 bool
379 GetThreadStopInfoFromJSON(ThreadGDBRemote *thread,
380 const StructuredData::ObjectSP &thread_infos_sp);
Greg Clayton358cf1e2015-06-25 21:46:34 +0000381
Kate Stoneb9c1b512016-09-06 20:57:50 +0000382 lldb::ThreadSP SetThreadStopInfo(StructuredData::Dictionary *thread_dict);
Greg Clayton358cf1e2015-06-25 21:46:34 +0000383
Kate Stoneb9c1b512016-09-06 20:57:50 +0000384 lldb::ThreadSP
385 SetThreadStopInfo(lldb::tid_t tid,
386 ExpeditedRegisterMap &expedited_register_map, uint8_t signo,
387 const std::string &thread_name, const std::string &reason,
388 const std::string &description, uint32_t exc_type,
389 const std::vector<lldb::addr_t> &exc_data,
390 lldb::addr_t thread_dispatch_qaddr, bool queue_vars_valid,
391 lldb_private::LazyBool associated_with_libdispatch_queue,
392 lldb::addr_t dispatch_queue_t, std::string &queue_name,
393 lldb::QueueKind queue_kind, uint64_t queue_serial);
Ewan Crawford78baa192015-05-13 09:18:18 +0000394
Kate Stoneb9c1b512016-09-06 20:57:50 +0000395 void HandleStopReplySequence();
Greg Clayton9e920902012-04-10 02:25:43 +0000396
Kate Stoneb9c1b512016-09-06 20:57:50 +0000397 void ClearThreadIDList();
Greg Clayton9e920902012-04-10 02:25:43 +0000398
Kate Stoneb9c1b512016-09-06 20:57:50 +0000399 bool UpdateThreadIDList();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400
Kate Stoneb9c1b512016-09-06 20:57:50 +0000401 void DidLaunchOrAttach(ArchSpec &process_arch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000402
Zachary Turner97206d52017-05-12 04:51:55 +0000403 Status ConnectToDebugserver(llvm::StringRef host_port);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000404
Kate Stoneb9c1b512016-09-06 20:57:50 +0000405 const char *GetDispatchQueueNameForThread(lldb::addr_t thread_dispatch_qaddr,
406 std::string &dispatch_queue_name);
Jason Molenda5e8534e2012-10-03 01:29:34 +0000407
Kate Stoneb9c1b512016-09-06 20:57:50 +0000408 DynamicLoader *GetDynamicLoader() override;
Aidan Doddsc0c83852015-05-08 09:36:31 +0000409
Kate Stoneb9c1b512016-09-06 20:57:50 +0000410 // Query remote GDBServer for register information
411 bool GetGDBServerRegisterInfo(ArchSpec &arch);
Aidan Doddsc0c83852015-05-08 09:36:31 +0000412
Kate Stoneb9c1b512016-09-06 20:57:50 +0000413 // Query remote GDBServer for a detailed loaded library list
Zachary Turner97206d52017-05-12 04:51:55 +0000414 Status GetLoadedModuleList(LoadedModuleInfoList &);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000415
416 lldb::ModuleSP LoadModuleAtAddress(const FileSpec &file,
417 lldb::addr_t link_map,
418 lldb::addr_t base_addr,
419 bool value_is_offset);
Aidan Doddsc0c83852015-05-08 09:36:31 +0000420
Zachary Turner97206d52017-05-12 04:51:55 +0000421 Status UpdateAutomaticSignalFiltering() override;
Eugene Zemtsov7993cc52017-03-07 21:34:40 +0000422
Pavel Labath16064d32018-03-20 11:56:24 +0000423 Status FlashErase(lldb::addr_t addr, size_t size);
424
425 Status FlashDone();
426
427 bool HasErased(FlashRange range);
428
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000430 //------------------------------------------------------------------
431 // For ProcessGDBRemote only
432 //------------------------------------------------------------------
433 std::string m_partial_profile_data;
434 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
Eugene Zemtsov7993cc52017-03-07 21:34:40 +0000435 uint64_t m_last_signals_version = 0;
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000436
Kate Stoneb9c1b512016-09-06 20:57:50 +0000437 static bool NewThreadNotifyBreakpointHit(void *baton,
438 StoppointCallbackContext *context,
439 lldb::user_id_t break_id,
440 lldb::user_id_t break_loc_id);
Jim Ingham1c823b42011-01-22 01:33:44 +0000441
Kate Stoneb9c1b512016-09-06 20:57:50 +0000442 //------------------------------------------------------------------
443 // ContinueDelegate interface
444 //------------------------------------------------------------------
445 void HandleAsyncStdout(llvm::StringRef out) override;
446 void HandleAsyncMisc(llvm::StringRef data) override;
447 void HandleStopReply() override;
Todd Fialafcdb1af2016-09-10 00:06:29 +0000448 void HandleAsyncStructuredDataPacket(llvm::StringRef data) override;
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000449
Pavel Labathe0a5b572017-01-20 14:17:16 +0000450 void SetThreadPc(const lldb::ThreadSP &thread_sp, uint64_t index);
Pavel Labath2f1fbae2016-09-08 10:07:04 +0000451 using ModuleCacheKey = std::pair<std::string, std::string>;
452 // KeyInfo for the cached module spec DenseMap.
453 // The invariant is that all real keys will have the file and architecture
454 // set.
455 // The empty key has an empty file and an empty arch.
456 // The tombstone key has an invalid arch and an empty file.
457 // The comparison and hash functions take the file name and architecture
458 // triple into account.
459 struct ModuleCacheInfo {
460 static ModuleCacheKey getEmptyKey() { return ModuleCacheKey(); }
461
462 static ModuleCacheKey getTombstoneKey() { return ModuleCacheKey("", "T"); }
463
464 static unsigned getHashValue(const ModuleCacheKey &key) {
465 return llvm::hash_combine(key.first, key.second);
466 }
467
468 static bool isEqual(const ModuleCacheKey &LHS, const ModuleCacheKey &RHS) {
469 return LHS == RHS;
470 }
471 };
472
473 llvm::DenseMap<ModuleCacheKey, ModuleSpec, ModuleCacheInfo>
474 m_cached_module_specs;
475
Kate Stoneb9c1b512016-09-06 20:57:50 +0000476 DISALLOW_COPY_AND_ASSIGN(ProcessGDBRemote);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477};
478
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000479} // namespace process_gdb_remote
480} // namespace lldb_private
481
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000482#endif // liblldb_ProcessGDBRemote_h_