blob: 6423abc558363e47eac665ff3d067bd623d6453c [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
21// Other libraries and framework includes
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000022// Project includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Core/ArchSpec.h"
24#include "lldb/Core/Broadcaster.h"
Jason Molenda2e56a252013-05-11 03:09:05 +000025#include "lldb/Core/ConstString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Core/Error.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000027#include "lldb/Core/LoadedModuleInfoList.h"
Pavel Labath2f1fbae2016-09-08 10:07:04 +000028#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/StreamString.h"
Jim Ingham5aee1622010-08-09 23:31:02 +000030#include "lldb/Core/StringList.h"
Jason Molenda705b1802014-06-13 02:37:02 +000031#include "lldb/Core/StructuredData.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Core/ThreadSafeValue.h"
Zachary Turner39de3112014-09-09 20:54:56 +000033#include "lldb/Host/HostThread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034#include "lldb/Target/Process.h"
35#include "lldb/Target/Thread.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000036#include "lldb/Utility/StringExtractor.h"
37#include "lldb/lldb-private-forward.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038
Greg Clayton576d8832011-03-22 04:00:09 +000039#include "GDBRemoteCommunicationClient.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "GDBRemoteRegisterContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041
Pavel Labath2f1fbae2016-09-08 10:07:04 +000042#include "llvm/ADT/DenseMap.h"
43
Tamas Berghammerdb264a62015-03-31 09:52:22 +000044namespace lldb_private {
45namespace 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 //------------------------------------------------------------------
81 Error WillLaunch(Module *module) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082
Kate Stoneb9c1b512016-09-06 20:57:50 +000083 Error 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
Kate Stoneb9c1b512016-09-06 20:57:50 +000087 Error WillAttachToProcessWithID(lldb::pid_t pid) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088
Kate Stoneb9c1b512016-09-06 20:57:50 +000089 Error WillAttachToProcessWithName(const char *process_name,
90 bool wait_for_launch) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091
Zachary Turner31659452016-11-17 21:15:14 +000092 Error DoConnectRemote(Stream *strm, llvm::StringRef remote_url) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093
Kate Stoneb9c1b512016-09-06 20:57:50 +000094 Error WillLaunchOrAttach();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000095
Kate Stoneb9c1b512016-09-06 20:57:50 +000096 Error DoAttachToProcessWithID(lldb::pid_t pid,
97 const ProcessAttachInfo &attach_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000098
Kate Stoneb9c1b512016-09-06 20:57:50 +000099 Error
100 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 //------------------------------------------------------------------
115 Error WillResume() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116
Kate Stoneb9c1b512016-09-06 20:57:50 +0000117 Error DoResume() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118
Kate Stoneb9c1b512016-09-06 20:57:50 +0000119 Error DoHalt(bool &caused_stop) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000120
Kate Stoneb9c1b512016-09-06 20:57:50 +0000121 Error 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
Kate Stoneb9c1b512016-09-06 20:57:50 +0000125 Error DoSignal(int signal) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126
Kate Stoneb9c1b512016-09-06 20:57:50 +0000127 Error 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,
146 Error &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147
Kate Stoneb9c1b512016-09-06 20:57:50 +0000148 size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size,
149 Error &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000150
Kate Stoneb9c1b512016-09-06 20:57:50 +0000151 lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
152 Error &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000153
Kate Stoneb9c1b512016-09-06 20:57:50 +0000154 Error GetMemoryRegionInfo(lldb::addr_t load_addr,
155 MemoryRegionInfo &region_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156
Kate Stoneb9c1b512016-09-06 20:57:50 +0000157 Error DoDeallocateMemory(lldb::addr_t ptr) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158
Kate Stoneb9c1b512016-09-06 20:57:50 +0000159 //------------------------------------------------------------------
160 // Process STDIO
161 //------------------------------------------------------------------
162 size_t PutSTDIN(const char *buf, size_t buf_size, Error &error) override;
Jim Ingham1c823b42011-01-22 01:33:44 +0000163
Kate Stoneb9c1b512016-09-06 20:57:50 +0000164 //----------------------------------------------------------------------
165 // Process Breakpoints
166 //----------------------------------------------------------------------
167 Error EnableBreakpointSite(BreakpointSite *bp_site) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168
Kate Stoneb9c1b512016-09-06 20:57:50 +0000169 Error DisableBreakpointSite(BreakpointSite *bp_site) override;
Jason Molendaa3329782014-03-29 18:54:20 +0000170
Kate Stoneb9c1b512016-09-06 20:57:50 +0000171 //----------------------------------------------------------------------
172 // Process Watchpoints
173 //----------------------------------------------------------------------
174 Error EnableWatchpoint(Watchpoint *wp, bool notify = true) override;
Greg Claytonfbb76342013-11-20 21:07:01 +0000175
Kate Stoneb9c1b512016-09-06 20:57:50 +0000176 Error DisableWatchpoint(Watchpoint *wp, bool notify = true) override;
Jason Molenda6076bf42014-05-06 04:34:52 +0000177
Kate Stoneb9c1b512016-09-06 20:57:50 +0000178 Error GetWatchpointSupportInfo(uint32_t &num) override;
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +0000179
Kate Stoneb9c1b512016-09-06 20:57:50 +0000180 Error 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
Kate Stoneb9c1b512016-09-06 20:57:50 +0000188 Error SendEventData(const char *data) override;
Greg Clayton0b90be12015-06-23 21:27:50 +0000189
Kate Stoneb9c1b512016-09-06 20:57:50 +0000190 //----------------------------------------------------------------------
191 // Override DidExit so we can disconnect from the remote GDB server
192 //----------------------------------------------------------------------
193 void DidExit() override;
Jason Molenda20ee21b2015-07-10 23:15:22 +0000194
Kate Stoneb9c1b512016-09-06 20:57:50 +0000195 void SetUserSpecifiedMaxMemoryTransferSize(uint64_t user_specified_max);
Todd Fiala75930012016-08-19 04:21:48 +0000196
Kate Stoneb9c1b512016-09-06 20:57:50 +0000197 bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
198 ModuleSpec &module_spec) override;
Jason Molenda9ab5dc22016-07-21 08:30:55 +0000199
Pavel Labath2f1fbae2016-09-08 10:07:04 +0000200 void PrefetchModuleSpecs(llvm::ArrayRef<FileSpec> module_file_specs,
201 const llvm::Triple &triple) override;
202
Kate Stoneb9c1b512016-09-06 20:57:50 +0000203 bool GetHostOSVersion(uint32_t &major, uint32_t &minor,
204 uint32_t &update) override;
Jason Molenda9ab5dc22016-07-21 08:30:55 +0000205
Kate Stoneb9c1b512016-09-06 20:57:50 +0000206 size_t LoadModules(LoadedModuleInfoList &module_list) override;
Jason Molenda9ab5dc22016-07-21 08:30:55 +0000207
Kate Stoneb9c1b512016-09-06 20:57:50 +0000208 size_t LoadModules() override;
Jason Molenda37397352016-07-22 00:17:55 +0000209
Kate Stoneb9c1b512016-09-06 20:57:50 +0000210 Error GetFileLoadAddress(const FileSpec &file, bool &is_loaded,
211 lldb::addr_t &load_addr) override;
212
213 void ModulesDidLoad(ModuleList &module_list) override;
214
215 StructuredData::ObjectSP
216 GetLoadedDynamicLibrariesInfos(lldb::addr_t image_list_address,
217 lldb::addr_t image_count) override;
218
219 Error
220 ConfigureStructuredData(const ConstString &type_name,
221 const StructuredData::ObjectSP &config_sp) override;
222
223 StructuredData::ObjectSP GetLoadedDynamicLibrariesInfos() override;
224
225 StructuredData::ObjectSP GetLoadedDynamicLibrariesInfos(
226 const std::vector<lldb::addr_t> &load_addresses) override;
227
228 StructuredData::ObjectSP
229 GetLoadedDynamicLibrariesInfos_sender(StructuredData::ObjectSP args);
230
231 StructuredData::ObjectSP GetSharedCacheInfo() override;
232
233 std::string HarmonizeThreadIdsForProfileData(
234 StringExtractorGDBRemote &inputStringExtractor);
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000235
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000236protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000237 friend class ThreadGDBRemote;
238 friend class GDBRemoteCommunicationClient;
239 friend class GDBRemoteRegisterContext;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240
Kate Stoneb9c1b512016-09-06 20:57:50 +0000241 //------------------------------------------------------------------
242 /// Broadcaster event bits definitions.
243 //------------------------------------------------------------------
244 enum {
245 eBroadcastBitAsyncContinue = (1 << 0),
246 eBroadcastBitAsyncThreadShouldExit = (1 << 1),
247 eBroadcastBitAsyncThreadDidExit = (1 << 2)
248 };
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000249
Kate Stoneb9c1b512016-09-06 20:57:50 +0000250 Flags m_flags; // Process specific flags (see eFlags enums)
251 GDBRemoteCommunicationClient m_gdb_comm;
252 std::atomic<lldb::pid_t> m_debugserver_pid;
253 std::vector<StringExtractorGDBRemote> m_stop_packet_stack; // The stop packet
254 // stack replaces
255 // the last stop
256 // packet variable
257 std::recursive_mutex m_last_stop_packet_mutex;
258 GDBRemoteDynamicRegisterInfo m_register_info;
259 Broadcaster m_async_broadcaster;
260 lldb::ListenerSP m_async_listener_sp;
261 HostThread m_async_thread;
262 std::recursive_mutex m_async_thread_state_mutex;
263 typedef std::vector<lldb::tid_t> tid_collection;
264 typedef std::vector<std::pair<lldb::tid_t, int>> tid_sig_collection;
265 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
266 typedef std::map<uint32_t, std::string> ExpeditedRegisterMap;
267 tid_collection m_thread_ids; // Thread IDs for all threads. This list gets
268 // updated after stopping
269 std::vector<lldb::addr_t> m_thread_pcs; // PC values for all the threads.
270 StructuredData::ObjectSP m_jstopinfo_sp; // Stop info only for any threads
271 // that have valid stop infos
272 StructuredData::ObjectSP m_jthreadsinfo_sp; // Full stop info, expedited
273 // registers and memory for all
274 // threads if "jThreadsInfo"
275 // packet is supported
276 tid_collection m_continue_c_tids; // 'c' for continue
277 tid_sig_collection m_continue_C_tids; // 'C' for continue with signal
278 tid_collection m_continue_s_tids; // 's' for step
279 tid_sig_collection m_continue_S_tids; // 'S' for step with signal
280 uint64_t m_max_memory_size; // The maximum number of bytes to read/write when
281 // reading and writing memory
282 uint64_t m_remote_stub_max_memory_size; // The maximum memory size the remote
283 // gdb stub can handle
284 MMapMap m_addr_to_mmap_size;
285 lldb::BreakpointSP m_thread_create_bp_sp;
286 bool m_waiting_for_attach;
287 bool m_destroy_tried_resuming;
288 lldb::CommandObjectSP m_command_sp;
289 int64_t m_breakpoint_pc_offset;
290 lldb::tid_t m_initial_tid; // The initial thread ID, given by stub on attach
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000291
Kate Stoneb9c1b512016-09-06 20:57:50 +0000292 //----------------------------------------------------------------------
293 // Accessors
294 //----------------------------------------------------------------------
295 bool IsRunning(lldb::StateType state) {
296 return state == lldb::eStateRunning || IsStepping(state);
297 }
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000298
Kate Stoneb9c1b512016-09-06 20:57:50 +0000299 bool IsStepping(lldb::StateType state) {
300 return state == lldb::eStateStepping;
301 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302
Kate Stoneb9c1b512016-09-06 20:57:50 +0000303 bool CanResume(lldb::StateType state) { return state == lldb::eStateStopped; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000304
Kate Stoneb9c1b512016-09-06 20:57:50 +0000305 bool HasExited(lldb::StateType state) { return state == lldb::eStateExited; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000306
Kate Stoneb9c1b512016-09-06 20:57:50 +0000307 bool ProcessIDIsValid() const;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000308
Kate Stoneb9c1b512016-09-06 20:57:50 +0000309 void Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310
Kate Stoneb9c1b512016-09-06 20:57:50 +0000311 Flags &GetFlags() { return m_flags; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312
Kate Stoneb9c1b512016-09-06 20:57:50 +0000313 const Flags &GetFlags() const { return m_flags; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000314
Kate Stoneb9c1b512016-09-06 20:57:50 +0000315 bool UpdateThreadList(ThreadList &old_thread_list,
316 ThreadList &new_thread_list) override;
Oleksiy Vyalovafd6ce42015-11-23 19:32:24 +0000317
Kate Stoneb9c1b512016-09-06 20:57:50 +0000318 Error EstablishConnectionIfNeeded(const ProcessInfo &process_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000319
Kate Stoneb9c1b512016-09-06 20:57:50 +0000320 Error LaunchAndConnectToDebugserver(const ProcessInfo &process_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000321
Kate Stoneb9c1b512016-09-06 20:57:50 +0000322 void KillDebugserverProcess();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000323
Kate Stoneb9c1b512016-09-06 20:57:50 +0000324 void BuildDynamicRegisterInfo(bool force);
Jason Molendad1fae142012-09-29 08:03:33 +0000325
Kate Stoneb9c1b512016-09-06 20:57:50 +0000326 void SetLastStopPacket(const StringExtractorGDBRemote &response);
Greg Claytonef8180a2013-10-15 00:14:28 +0000327
Kate Stoneb9c1b512016-09-06 20:57:50 +0000328 bool ParsePythonTargetDefinition(const FileSpec &target_definition_fspec);
Steve Pucci03904ac2014-03-04 23:18:46 +0000329
Kate Stoneb9c1b512016-09-06 20:57:50 +0000330 const lldb::DataBufferSP GetAuxvData() override;
Jason Molenda705b1802014-06-13 02:37:02 +0000331
Kate Stoneb9c1b512016-09-06 20:57:50 +0000332 StructuredData::ObjectSP GetExtendedInfoForThread(lldb::tid_t tid);
Jason Molenda6076bf42014-05-06 04:34:52 +0000333
Kate Stoneb9c1b512016-09-06 20:57:50 +0000334 void GetMaxMemorySize();
Greg Clayton358cf1e2015-06-25 21:46:34 +0000335
Kate Stoneb9c1b512016-09-06 20:57:50 +0000336 bool CalculateThreadStopInfo(ThreadGDBRemote *thread);
Jason Molenda545304d2015-12-18 00:45:35 +0000337
Kate Stoneb9c1b512016-09-06 20:57:50 +0000338 size_t UpdateThreadPCsFromStopReplyThreadsValue(std::string &value);
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000339
Kate Stoneb9c1b512016-09-06 20:57:50 +0000340 size_t UpdateThreadIDsFromStopReplyThreadsValue(std::string &value);
Ewan Crawford76df2882015-06-23 12:32:06 +0000341
Kate Stoneb9c1b512016-09-06 20:57:50 +0000342 bool HandleNotifyPacket(StringExtractorGDBRemote &packet);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000343
Kate Stoneb9c1b512016-09-06 20:57:50 +0000344 bool StartAsyncThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000345
Kate Stoneb9c1b512016-09-06 20:57:50 +0000346 void StopAsyncThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000347
Kate Stoneb9c1b512016-09-06 20:57:50 +0000348 static lldb::thread_result_t AsyncThread(void *arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000349
Kate Stoneb9c1b512016-09-06 20:57:50 +0000350 static bool
351 MonitorDebugserverProcess(std::weak_ptr<ProcessGDBRemote> process_wp,
352 lldb::pid_t pid, bool exited, int signo,
353 int exit_status);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000354
Kate Stoneb9c1b512016-09-06 20:57:50 +0000355 lldb::StateType SetThreadStopInfo(StringExtractor &stop_packet);
Greg Clayton2e309072015-07-17 23:42:28 +0000356
Kate Stoneb9c1b512016-09-06 20:57:50 +0000357 bool
358 GetThreadStopInfoFromJSON(ThreadGDBRemote *thread,
359 const StructuredData::ObjectSP &thread_infos_sp);
Greg Clayton358cf1e2015-06-25 21:46:34 +0000360
Kate Stoneb9c1b512016-09-06 20:57:50 +0000361 lldb::ThreadSP SetThreadStopInfo(StructuredData::Dictionary *thread_dict);
Greg Clayton358cf1e2015-06-25 21:46:34 +0000362
Kate Stoneb9c1b512016-09-06 20:57:50 +0000363 lldb::ThreadSP
364 SetThreadStopInfo(lldb::tid_t tid,
365 ExpeditedRegisterMap &expedited_register_map, uint8_t signo,
366 const std::string &thread_name, const std::string &reason,
367 const std::string &description, uint32_t exc_type,
368 const std::vector<lldb::addr_t> &exc_data,
369 lldb::addr_t thread_dispatch_qaddr, bool queue_vars_valid,
370 lldb_private::LazyBool associated_with_libdispatch_queue,
371 lldb::addr_t dispatch_queue_t, std::string &queue_name,
372 lldb::QueueKind queue_kind, uint64_t queue_serial);
Ewan Crawford78baa192015-05-13 09:18:18 +0000373
Kate Stoneb9c1b512016-09-06 20:57:50 +0000374 void HandleStopReplySequence();
Greg Clayton9e920902012-04-10 02:25:43 +0000375
Kate Stoneb9c1b512016-09-06 20:57:50 +0000376 void ClearThreadIDList();
Greg Clayton9e920902012-04-10 02:25:43 +0000377
Kate Stoneb9c1b512016-09-06 20:57:50 +0000378 bool UpdateThreadIDList();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379
Kate Stoneb9c1b512016-09-06 20:57:50 +0000380 void DidLaunchOrAttach(ArchSpec &process_arch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381
Zachary Turner31659452016-11-17 21:15:14 +0000382 Error ConnectToDebugserver(llvm::StringRef host_port);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383
Kate Stoneb9c1b512016-09-06 20:57:50 +0000384 const char *GetDispatchQueueNameForThread(lldb::addr_t thread_dispatch_qaddr,
385 std::string &dispatch_queue_name);
Jason Molenda5e8534e2012-10-03 01:29:34 +0000386
Kate Stoneb9c1b512016-09-06 20:57:50 +0000387 DynamicLoader *GetDynamicLoader() override;
Aidan Doddsc0c83852015-05-08 09:36:31 +0000388
Kate Stoneb9c1b512016-09-06 20:57:50 +0000389 // Query remote GDBServer for register information
390 bool GetGDBServerRegisterInfo(ArchSpec &arch);
Aidan Doddsc0c83852015-05-08 09:36:31 +0000391
Kate Stoneb9c1b512016-09-06 20:57:50 +0000392 // Query remote GDBServer for a detailed loaded library list
393 Error GetLoadedModuleList(LoadedModuleInfoList &);
394
395 lldb::ModuleSP LoadModuleAtAddress(const FileSpec &file,
396 lldb::addr_t link_map,
397 lldb::addr_t base_addr,
398 bool value_is_offset);
Aidan Doddsc0c83852015-05-08 09:36:31 +0000399
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000401 //------------------------------------------------------------------
402 // For ProcessGDBRemote only
403 //------------------------------------------------------------------
404 std::string m_partial_profile_data;
405 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000406
Kate Stoneb9c1b512016-09-06 20:57:50 +0000407 static bool NewThreadNotifyBreakpointHit(void *baton,
408 StoppointCallbackContext *context,
409 lldb::user_id_t break_id,
410 lldb::user_id_t break_loc_id);
Jim Ingham1c823b42011-01-22 01:33:44 +0000411
Kate Stoneb9c1b512016-09-06 20:57:50 +0000412 //------------------------------------------------------------------
413 // ContinueDelegate interface
414 //------------------------------------------------------------------
415 void HandleAsyncStdout(llvm::StringRef out) override;
416 void HandleAsyncMisc(llvm::StringRef data) override;
417 void HandleStopReply() override;
Todd Fialafcdb1af2016-09-10 00:06:29 +0000418 void HandleAsyncStructuredDataPacket(llvm::StringRef data) override;
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000419
Pavel Labath2f1fbae2016-09-08 10:07:04 +0000420 using ModuleCacheKey = std::pair<std::string, std::string>;
421 // KeyInfo for the cached module spec DenseMap.
422 // The invariant is that all real keys will have the file and architecture
423 // set.
424 // The empty key has an empty file and an empty arch.
425 // The tombstone key has an invalid arch and an empty file.
426 // The comparison and hash functions take the file name and architecture
427 // triple into account.
428 struct ModuleCacheInfo {
429 static ModuleCacheKey getEmptyKey() { return ModuleCacheKey(); }
430
431 static ModuleCacheKey getTombstoneKey() { return ModuleCacheKey("", "T"); }
432
433 static unsigned getHashValue(const ModuleCacheKey &key) {
434 return llvm::hash_combine(key.first, key.second);
435 }
436
437 static bool isEqual(const ModuleCacheKey &LHS, const ModuleCacheKey &RHS) {
438 return LHS == RHS;
439 }
440 };
441
442 llvm::DenseMap<ModuleCacheKey, ModuleSpec, ModuleCacheInfo>
443 m_cached_module_specs;
444
Kate Stoneb9c1b512016-09-06 20:57:50 +0000445 DISALLOW_COPY_AND_ASSIGN(ProcessGDBRemote);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446};
447
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000448} // namespace process_gdb_remote
449} // namespace lldb_private
450
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000451#endif // liblldb_ProcessGDBRemote_h_