blob: c465acf8357b77b28ab3f466f3f360051dc59564 [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
Jonas Devliegherecdc514e2020-02-17 15:57:45 -08009#ifndef LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_PROCESSGDBREMOTE_H
10#define LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_PROCESSGDBREMOTE_H
Chris Lattner30fdc8d2010-06-08 16:52:24 +000011
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"
Jonas Devlieghereff5225b2019-09-13 23:14:10 +000027#include "lldb/Utility/GDBRemote.h"
Zachary Turner97206d52017-05-12 04:51:55 +000028#include "lldb/Utility/Status.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 // Check if a given Process
Kate Stoneb9c1b512016-09-06 20:57:50 +000071 bool CanDebug(lldb::TargetSP target_sp,
72 bool plugin_specified_by_name) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000073
Kate Stoneb9c1b512016-09-06 20:57:50 +000074 CommandObject *GetPluginCommandObject() override;
Jim Ingham5aee1622010-08-09 23:31:02 +000075
Kate Stoneb9c1b512016-09-06 20:57:50 +000076 // Creating a new process, or attaching to an existing one
Zachary Turner97206d52017-05-12 04:51:55 +000077 Status WillLaunch(Module *module) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078
Zachary Turner97206d52017-05-12 04:51:55 +000079 Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080
Kate Stoneb9c1b512016-09-06 20:57:50 +000081 void DidLaunch() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082
Zachary Turner97206d52017-05-12 04:51:55 +000083 Status WillAttachToProcessWithID(lldb::pid_t pid) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084
Zachary Turner97206d52017-05-12 04:51:55 +000085 Status WillAttachToProcessWithName(const char *process_name,
86 bool wait_for_launch) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087
Zachary Turner97206d52017-05-12 04:51:55 +000088 Status DoConnectRemote(Stream *strm, llvm::StringRef remote_url) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000089
Zachary Turner97206d52017-05-12 04:51:55 +000090 Status WillLaunchOrAttach();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091
Zachary Turner97206d52017-05-12 04:51:55 +000092 Status DoAttachToProcessWithID(lldb::pid_t pid,
93 const ProcessAttachInfo &attach_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094
Zachary Turner97206d52017-05-12 04:51:55 +000095 Status
Kate Stoneb9c1b512016-09-06 20:57:50 +000096 DoAttachToProcessWithName(const char *process_name,
97 const ProcessAttachInfo &attach_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000098
Kate Stoneb9c1b512016-09-06 20:57:50 +000099 void DidAttach(ArchSpec &process_arch) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000100
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101 // PluginInterface protocol
Kate Stoneb9c1b512016-09-06 20:57:50 +0000102 ConstString GetPluginName() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104 uint32_t GetPluginVersion() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105
Kate Stoneb9c1b512016-09-06 20:57:50 +0000106 // Process Control
Zachary Turner97206d52017-05-12 04:51:55 +0000107 Status WillResume() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108
Zachary Turner97206d52017-05-12 04:51:55 +0000109 Status DoResume() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110
Zachary Turner97206d52017-05-12 04:51:55 +0000111 Status DoHalt(bool &caused_stop) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112
Zachary Turner97206d52017-05-12 04:51:55 +0000113 Status DoDetach(bool keep_stopped) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114
Kate Stoneb9c1b512016-09-06 20:57:50 +0000115 bool DetachRequiresHalt() override { return true; }
Chaoren Linc963a222015-09-01 16:58:45 +0000116
Zachary Turner97206d52017-05-12 04:51:55 +0000117 Status DoSignal(int signal) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118
Zachary Turner97206d52017-05-12 04:51:55 +0000119 Status DoDestroy() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000120
Kate Stoneb9c1b512016-09-06 20:57:50 +0000121 void RefreshStateAfterStop() override;
Greg Clayton2e309072015-07-17 23:42:28 +0000122
Kate Stoneb9c1b512016-09-06 20:57:50 +0000123 void SetUnixSignals(const lldb::UnixSignalsSP &signals_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000124
Kate Stoneb9c1b512016-09-06 20:57:50 +0000125 // Process Queries
Kate Stoneb9c1b512016-09-06 20:57:50 +0000126 bool IsAlive() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000127
Kate Stoneb9c1b512016-09-06 20:57:50 +0000128 lldb::addr_t GetImageInfoAddress() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000129
Kate Stoneb9c1b512016-09-06 20:57:50 +0000130 void WillPublicStop() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000131
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132 // Process Memory
Kate Stoneb9c1b512016-09-06 20:57:50 +0000133 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
Zachary Turner97206d52017-05-12 04:51:55 +0000134 Status &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000135
Pavel Labath16064d32018-03-20 11:56:24 +0000136 Status
137 WriteObjectFile(std::vector<ObjectFile::LoadableData> entries) override;
138
Kate Stoneb9c1b512016-09-06 20:57:50 +0000139 size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size,
Zachary Turner97206d52017-05-12 04:51:55 +0000140 Status &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000141
Kate Stoneb9c1b512016-09-06 20:57:50 +0000142 lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
Zachary Turner97206d52017-05-12 04:51:55 +0000143 Status &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000144
Zachary Turner97206d52017-05-12 04:51:55 +0000145 Status GetMemoryRegionInfo(lldb::addr_t load_addr,
146 MemoryRegionInfo &region_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147
Zachary Turner97206d52017-05-12 04:51:55 +0000148 Status DoDeallocateMemory(lldb::addr_t ptr) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149
Kate Stoneb9c1b512016-09-06 20:57:50 +0000150 // Process STDIO
Zachary Turner97206d52017-05-12 04:51:55 +0000151 size_t PutSTDIN(const char *buf, size_t buf_size, Status &error) override;
Jim Ingham1c823b42011-01-22 01:33:44 +0000152
Kate Stoneb9c1b512016-09-06 20:57:50 +0000153 // Process Breakpoints
Zachary Turner97206d52017-05-12 04:51:55 +0000154 Status EnableBreakpointSite(BreakpointSite *bp_site) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000155
Zachary Turner97206d52017-05-12 04:51:55 +0000156 Status DisableBreakpointSite(BreakpointSite *bp_site) override;
Jason Molendaa3329782014-03-29 18:54:20 +0000157
Kate Stoneb9c1b512016-09-06 20:57:50 +0000158 // Process Watchpoints
Zachary Turner97206d52017-05-12 04:51:55 +0000159 Status EnableWatchpoint(Watchpoint *wp, bool notify = true) override;
Greg Claytonfbb76342013-11-20 21:07:01 +0000160
Zachary Turner97206d52017-05-12 04:51:55 +0000161 Status DisableWatchpoint(Watchpoint *wp, bool notify = true) override;
Jason Molenda6076bf42014-05-06 04:34:52 +0000162
Zachary Turner97206d52017-05-12 04:51:55 +0000163 Status GetWatchpointSupportInfo(uint32_t &num) override;
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +0000164
Ravitheja Addepallye714c4f2017-05-26 11:46:27 +0000165 lldb::user_id_t StartTrace(const TraceOptions &options,
166 Status &error) override;
167
168 Status StopTrace(lldb::user_id_t uid, lldb::tid_t thread_id) override;
169
170 Status GetData(lldb::user_id_t uid, lldb::tid_t thread_id,
171 llvm::MutableArrayRef<uint8_t> &buffer,
172 size_t offset = 0) override;
173
174 Status GetMetaData(lldb::user_id_t uid, lldb::tid_t thread_id,
175 llvm::MutableArrayRef<uint8_t> &buffer,
176 size_t offset = 0) override;
177
178 Status GetTraceConfig(lldb::user_id_t uid, TraceOptions &options) override;
179
Zachary Turner97206d52017-05-12 04:51:55 +0000180 Status GetWatchpointSupportInfo(uint32_t &num, bool &after) override;
Jim Ingham13c30d22015-11-05 22:33:17 +0000181
Kate Stoneb9c1b512016-09-06 20:57:50 +0000182 bool StartNoticingNewThreads() override;
Stephane Sezer87b0fe02016-01-12 19:02:41 +0000183
Kate Stoneb9c1b512016-09-06 20:57:50 +0000184 bool StopNoticingNewThreads() override;
Tamas Berghammer783bfc82015-06-18 20:43:56 +0000185
Kate Stoneb9c1b512016-09-06 20:57:50 +0000186 GDBRemoteCommunicationClient &GetGDBRemote() { return m_gdb_comm; }
Colin Rileyc3c95b22015-04-16 15:51:33 +0000187
Zachary Turner97206d52017-05-12 04:51:55 +0000188 Status SendEventData(const char *data) override;
Greg Clayton0b90be12015-06-23 21:27:50 +0000189
Kate Stoneb9c1b512016-09-06 20:57:50 +0000190 // Override DidExit so we can disconnect from the remote GDB server
Kate Stoneb9c1b512016-09-06 20:57:50 +0000191 void DidExit() override;
Jason Molenda20ee21b2015-07-10 23:15:22 +0000192
Kate Stoneb9c1b512016-09-06 20:57:50 +0000193 void SetUserSpecifiedMaxMemoryTransferSize(uint64_t user_specified_max);
Todd Fiala75930012016-08-19 04:21:48 +0000194
Kate Stoneb9c1b512016-09-06 20:57:50 +0000195 bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
196 ModuleSpec &module_spec) override;
Jason Molenda9ab5dc22016-07-21 08:30:55 +0000197
Pavel Labath2f1fbae2016-09-08 10:07:04 +0000198 void PrefetchModuleSpecs(llvm::ArrayRef<FileSpec> module_file_specs,
199 const llvm::Triple &triple) override;
200
Pavel Labath2272c482018-06-18 15:02:23 +0000201 llvm::VersionTuple GetHostOSVersion() override;
Adrian Prantl24610612019-09-04 17:23:15 +0000202 llvm::VersionTuple GetHostMacCatalystVersion() override;
Jason Molenda9ab5dc22016-07-21 08:30:55 +0000203
Antonio Afonsod6682602019-07-25 14:28:21 +0000204 llvm::Error LoadModules() override;
Jason Molenda9ab5dc22016-07-21 08:30:55 +0000205
Antonio Afonsod6682602019-07-25 14:28:21 +0000206 llvm::Expected<LoadedModuleInfoList> GetLoadedModuleList() override;
Jason Molenda37397352016-07-22 00:17:55 +0000207
Zachary Turner97206d52017-05-12 04:51:55 +0000208 Status GetFileLoadAddress(const FileSpec &file, bool &is_loaded,
209 lldb::addr_t &load_addr) override;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000210
211 void ModulesDidLoad(ModuleList &module_list) override;
212
213 StructuredData::ObjectSP
214 GetLoadedDynamicLibrariesInfos(lldb::addr_t image_list_address,
215 lldb::addr_t image_count) override;
216
Zachary Turner97206d52017-05-12 04:51:55 +0000217 Status
Adrian Prantl0e4c4822019-03-06 21:22:25 +0000218 ConfigureStructuredData(ConstString type_name,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000219 const StructuredData::ObjectSP &config_sp) override;
220
221 StructuredData::ObjectSP GetLoadedDynamicLibrariesInfos() override;
222
223 StructuredData::ObjectSP GetLoadedDynamicLibrariesInfos(
224 const std::vector<lldb::addr_t> &load_addresses) override;
225
226 StructuredData::ObjectSP
227 GetLoadedDynamicLibrariesInfos_sender(StructuredData::ObjectSP args);
228
229 StructuredData::ObjectSP GetSharedCacheInfo() override;
230
231 std::string HarmonizeThreadIdsForProfileData(
232 StringExtractorGDBRemote &inputStringExtractor);
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000233
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000234protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000235 friend class ThreadGDBRemote;
236 friend class GDBRemoteCommunicationClient;
237 friend class GDBRemoteRegisterContext;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000238
Kate Stoneb9c1b512016-09-06 20:57:50 +0000239 /// Broadcaster event bits definitions.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000240 enum {
241 eBroadcastBitAsyncContinue = (1 << 0),
242 eBroadcastBitAsyncThreadShouldExit = (1 << 1),
243 eBroadcastBitAsyncThreadDidExit = (1 << 2)
244 };
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000245
Kate Stoneb9c1b512016-09-06 20:57:50 +0000246 GDBRemoteCommunicationClient m_gdb_comm;
Jonas Devlieghere9e046f02018-11-13 19:18:16 +0000247 GDBRemoteCommunicationReplayServer m_gdb_replay_server;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000248 std::atomic<lldb::pid_t> m_debugserver_pid;
249 std::vector<StringExtractorGDBRemote> m_stop_packet_stack; // The stop packet
250 // stack replaces
251 // the last stop
252 // packet variable
253 std::recursive_mutex m_last_stop_packet_mutex;
254 GDBRemoteDynamicRegisterInfo m_register_info;
255 Broadcaster m_async_broadcaster;
256 lldb::ListenerSP m_async_listener_sp;
257 HostThread m_async_thread;
258 std::recursive_mutex m_async_thread_state_mutex;
259 typedef std::vector<lldb::tid_t> tid_collection;
260 typedef std::vector<std::pair<lldb::tid_t, int>> tid_sig_collection;
261 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
262 typedef std::map<uint32_t, std::string> ExpeditedRegisterMap;
263 tid_collection m_thread_ids; // Thread IDs for all threads. This list gets
264 // updated after stopping
265 std::vector<lldb::addr_t> m_thread_pcs; // PC values for all the threads.
266 StructuredData::ObjectSP m_jstopinfo_sp; // Stop info only for any threads
267 // that have valid stop infos
268 StructuredData::ObjectSP m_jthreadsinfo_sp; // Full stop info, expedited
269 // registers and memory for all
270 // threads if "jThreadsInfo"
271 // packet is supported
272 tid_collection m_continue_c_tids; // 'c' for continue
273 tid_sig_collection m_continue_C_tids; // 'C' for continue with signal
274 tid_collection m_continue_s_tids; // 's' for step
275 tid_sig_collection m_continue_S_tids; // 'S' for step with signal
276 uint64_t m_max_memory_size; // The maximum number of bytes to read/write when
277 // reading and writing memory
278 uint64_t m_remote_stub_max_memory_size; // The maximum memory size the remote
279 // gdb stub can handle
280 MMapMap m_addr_to_mmap_size;
281 lldb::BreakpointSP m_thread_create_bp_sp;
282 bool m_waiting_for_attach;
283 bool m_destroy_tried_resuming;
284 lldb::CommandObjectSP m_command_sp;
285 int64_t m_breakpoint_pc_offset;
286 lldb::tid_t m_initial_tid; // The initial thread ID, given by stub on attach
Guilherme Andradeb1b70f62019-11-07 10:38:25 +0100287 bool m_use_g_packet_for_reading;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000288
Jonas Devlieghere9e046f02018-11-13 19:18:16 +0000289 bool m_replay_mode;
Pavel Labath16064d32018-03-20 11:56:24 +0000290 bool m_allow_flash_writes;
291 using FlashRangeVector = lldb_private::RangeVector<lldb::addr_t, size_t>;
292 using FlashRange = FlashRangeVector::Entry;
293 FlashRangeVector m_erased_flash_ranges;
294
Kate Stoneb9c1b512016-09-06 20:57:50 +0000295 // Accessors
Kate Stoneb9c1b512016-09-06 20:57:50 +0000296 bool IsRunning(lldb::StateType state) {
297 return state == lldb::eStateRunning || IsStepping(state);
298 }
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000299
Kate Stoneb9c1b512016-09-06 20:57:50 +0000300 bool IsStepping(lldb::StateType state) {
301 return state == lldb::eStateStepping;
302 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000303
Kate Stoneb9c1b512016-09-06 20:57:50 +0000304 bool CanResume(lldb::StateType state) { return state == lldb::eStateStopped; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000305
Kate Stoneb9c1b512016-09-06 20:57:50 +0000306 bool HasExited(lldb::StateType state) { return state == lldb::eStateExited; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000307
Kate Stoneb9c1b512016-09-06 20:57:50 +0000308 bool ProcessIDIsValid() const;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000309
Kate Stoneb9c1b512016-09-06 20:57:50 +0000310 void Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000311
Kate Stoneb9c1b512016-09-06 20:57:50 +0000312 bool UpdateThreadList(ThreadList &old_thread_list,
313 ThreadList &new_thread_list) override;
Oleksiy Vyalovafd6ce42015-11-23 19:32:24 +0000314
Jonas Devlieghere9e046f02018-11-13 19:18:16 +0000315 Status ConnectToReplayServer(repro::Loader *loader);
316
Zachary Turner97206d52017-05-12 04:51:55 +0000317 Status EstablishConnectionIfNeeded(const ProcessInfo &process_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000318
Zachary Turner97206d52017-05-12 04:51:55 +0000319 Status LaunchAndConnectToDebugserver(const ProcessInfo &process_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000320
Kate Stoneb9c1b512016-09-06 20:57:50 +0000321 void KillDebugserverProcess();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000322
Kate Stoneb9c1b512016-09-06 20:57:50 +0000323 void BuildDynamicRegisterInfo(bool force);
Jason Molendad1fae142012-09-29 08:03:33 +0000324
Kate Stoneb9c1b512016-09-06 20:57:50 +0000325 void SetLastStopPacket(const StringExtractorGDBRemote &response);
Greg Claytonef8180a2013-10-15 00:14:28 +0000326
Kate Stoneb9c1b512016-09-06 20:57:50 +0000327 bool ParsePythonTargetDefinition(const FileSpec &target_definition_fspec);
Steve Pucci03904ac2014-03-04 23:18:46 +0000328
Antonio Afonso943faef2019-06-11 20:16:13 +0000329 DataExtractor GetAuxvData() override;
Jason Molenda705b1802014-06-13 02:37:02 +0000330
Kate Stoneb9c1b512016-09-06 20:57:50 +0000331 StructuredData::ObjectSP GetExtendedInfoForThread(lldb::tid_t tid);
Jason Molenda6076bf42014-05-06 04:34:52 +0000332
Kate Stoneb9c1b512016-09-06 20:57:50 +0000333 void GetMaxMemorySize();
Greg Clayton358cf1e2015-06-25 21:46:34 +0000334
Kate Stoneb9c1b512016-09-06 20:57:50 +0000335 bool CalculateThreadStopInfo(ThreadGDBRemote *thread);
Jason Molenda545304d2015-12-18 00:45:35 +0000336
Kate Stoneb9c1b512016-09-06 20:57:50 +0000337 size_t UpdateThreadPCsFromStopReplyThreadsValue(std::string &value);
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000338
Kate Stoneb9c1b512016-09-06 20:57:50 +0000339 size_t UpdateThreadIDsFromStopReplyThreadsValue(std::string &value);
Ewan Crawford76df2882015-06-23 12:32:06 +0000340
Kate Stoneb9c1b512016-09-06 20:57:50 +0000341 bool HandleNotifyPacket(StringExtractorGDBRemote &packet);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000342
Kate Stoneb9c1b512016-09-06 20:57:50 +0000343 bool StartAsyncThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344
Kate Stoneb9c1b512016-09-06 20:57:50 +0000345 void StopAsyncThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000346
Kate Stoneb9c1b512016-09-06 20:57:50 +0000347 static lldb::thread_result_t AsyncThread(void *arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000348
Kate Stoneb9c1b512016-09-06 20:57:50 +0000349 static bool
350 MonitorDebugserverProcess(std::weak_ptr<ProcessGDBRemote> process_wp,
351 lldb::pid_t pid, bool exited, int signo,
352 int exit_status);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000353
Kate Stoneb9c1b512016-09-06 20:57:50 +0000354 lldb::StateType SetThreadStopInfo(StringExtractor &stop_packet);
Greg Clayton2e309072015-07-17 23:42:28 +0000355
Kate Stoneb9c1b512016-09-06 20:57:50 +0000356 bool
357 GetThreadStopInfoFromJSON(ThreadGDBRemote *thread,
358 const StructuredData::ObjectSP &thread_infos_sp);
Greg Clayton358cf1e2015-06-25 21:46:34 +0000359
Kate Stoneb9c1b512016-09-06 20:57:50 +0000360 lldb::ThreadSP SetThreadStopInfo(StructuredData::Dictionary *thread_dict);
Greg Clayton358cf1e2015-06-25 21:46:34 +0000361
Kate Stoneb9c1b512016-09-06 20:57:50 +0000362 lldb::ThreadSP
363 SetThreadStopInfo(lldb::tid_t tid,
364 ExpeditedRegisterMap &expedited_register_map, uint8_t signo,
365 const std::string &thread_name, const std::string &reason,
366 const std::string &description, uint32_t exc_type,
367 const std::vector<lldb::addr_t> &exc_data,
368 lldb::addr_t thread_dispatch_qaddr, bool queue_vars_valid,
369 lldb_private::LazyBool associated_with_libdispatch_queue,
370 lldb::addr_t dispatch_queue_t, std::string &queue_name,
371 lldb::QueueKind queue_kind, uint64_t queue_serial);
Ewan Crawford78baa192015-05-13 09:18:18 +0000372
Kate Stoneb9c1b512016-09-06 20:57:50 +0000373 void HandleStopReplySequence();
Greg Clayton9e920902012-04-10 02:25:43 +0000374
Kate Stoneb9c1b512016-09-06 20:57:50 +0000375 void ClearThreadIDList();
Greg Clayton9e920902012-04-10 02:25:43 +0000376
Kate Stoneb9c1b512016-09-06 20:57:50 +0000377 bool UpdateThreadIDList();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000378
Kate Stoneb9c1b512016-09-06 20:57:50 +0000379 void DidLaunchOrAttach(ArchSpec &process_arch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380
Zachary Turner97206d52017-05-12 04:51:55 +0000381 Status ConnectToDebugserver(llvm::StringRef host_port);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000382
Kate Stoneb9c1b512016-09-06 20:57:50 +0000383 const char *GetDispatchQueueNameForThread(lldb::addr_t thread_dispatch_qaddr,
384 std::string &dispatch_queue_name);
Jason Molenda5e8534e2012-10-03 01:29:34 +0000385
Kate Stoneb9c1b512016-09-06 20:57:50 +0000386 DynamicLoader *GetDynamicLoader() override;
Aidan Doddsc0c83852015-05-08 09:36:31 +0000387
Jason Molenda16592762019-06-26 21:59:39 +0000388 bool GetGDBServerRegisterInfoXMLAndProcess(ArchSpec &arch_to_use,
389 std::string xml_filename,
390 uint32_t &cur_reg_num,
391 uint32_t &reg_offset);
392
Kate Stoneb9c1b512016-09-06 20:57:50 +0000393 // Query remote GDBServer for register information
394 bool GetGDBServerRegisterInfo(ArchSpec &arch);
Aidan Doddsc0c83852015-05-08 09:36:31 +0000395
Kate Stoneb9c1b512016-09-06 20:57:50 +0000396 lldb::ModuleSP LoadModuleAtAddress(const FileSpec &file,
397 lldb::addr_t link_map,
398 lldb::addr_t base_addr,
399 bool value_is_offset);
Aidan Doddsc0c83852015-05-08 09:36:31 +0000400
Zachary Turner97206d52017-05-12 04:51:55 +0000401 Status UpdateAutomaticSignalFiltering() override;
Eugene Zemtsov7993cc52017-03-07 21:34:40 +0000402
Pavel Labath16064d32018-03-20 11:56:24 +0000403 Status FlashErase(lldb::addr_t addr, size_t size);
404
405 Status FlashDone();
406
407 bool HasErased(FlashRange range);
408
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000409private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000410 // For ProcessGDBRemote only
Kate Stoneb9c1b512016-09-06 20:57:50 +0000411 std::string m_partial_profile_data;
412 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
Eugene Zemtsov7993cc52017-03-07 21:34:40 +0000413 uint64_t m_last_signals_version = 0;
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000414
Kate Stoneb9c1b512016-09-06 20:57:50 +0000415 static bool NewThreadNotifyBreakpointHit(void *baton,
416 StoppointCallbackContext *context,
417 lldb::user_id_t break_id,
418 lldb::user_id_t break_loc_id);
Jim Ingham1c823b42011-01-22 01:33:44 +0000419
Kate Stoneb9c1b512016-09-06 20:57:50 +0000420 // ContinueDelegate interface
Kate Stoneb9c1b512016-09-06 20:57:50 +0000421 void HandleAsyncStdout(llvm::StringRef out) override;
422 void HandleAsyncMisc(llvm::StringRef data) override;
423 void HandleStopReply() override;
Todd Fialafcdb1af2016-09-10 00:06:29 +0000424 void HandleAsyncStructuredDataPacket(llvm::StringRef data) override;
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000425
Pavel Labathe0a5b572017-01-20 14:17:16 +0000426 void SetThreadPc(const lldb::ThreadSP &thread_sp, uint64_t index);
Pavel Labath2f1fbae2016-09-08 10:07:04 +0000427 using ModuleCacheKey = std::pair<std::string, std::string>;
428 // KeyInfo for the cached module spec DenseMap.
429 // The invariant is that all real keys will have the file and architecture
430 // set.
431 // The empty key has an empty file and an empty arch.
432 // The tombstone key has an invalid arch and an empty file.
433 // The comparison and hash functions take the file name and architecture
434 // triple into account.
435 struct ModuleCacheInfo {
436 static ModuleCacheKey getEmptyKey() { return ModuleCacheKey(); }
437
438 static ModuleCacheKey getTombstoneKey() { return ModuleCacheKey("", "T"); }
439
440 static unsigned getHashValue(const ModuleCacheKey &key) {
441 return llvm::hash_combine(key.first, key.second);
442 }
443
444 static bool isEqual(const ModuleCacheKey &LHS, const ModuleCacheKey &RHS) {
445 return LHS == RHS;
446 }
447 };
448
449 llvm::DenseMap<ModuleCacheKey, ModuleSpec, ModuleCacheInfo>
450 m_cached_module_specs;
451
Kate Stoneb9c1b512016-09-06 20:57:50 +0000452 DISALLOW_COPY_AND_ASSIGN(ProcessGDBRemote);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453};
454
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000455} // namespace process_gdb_remote
456} // namespace lldb_private
457
Jonas Devliegherecdc514e2020-02-17 15:57:45 -0800458#endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_PROCESSGDBREMOTE_H