blob: 0f41a2149ea08e54f20781846460ed93be4a6b76 [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"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/StreamString.h"
Jim Ingham5aee1622010-08-09 23:31:02 +000028#include "lldb/Core/StringList.h"
Jason Molenda705b1802014-06-13 02:37:02 +000029#include "lldb/Core/StructuredData.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Core/ThreadSafeValue.h"
Stephane Sezer87b0fe02016-01-12 19:02:41 +000031#include "lldb/Core/LoadedModuleInfoList.h"
Zachary Turner39de3112014-09-09 20:54:56 +000032#include "lldb/Host/HostThread.h"
Todd Fiala4ceced32014-08-29 17:35:57 +000033#include "lldb/lldb-private-forward.h"
Pavel Labathf805e192015-07-07 10:08:41 +000034#include "lldb/Utility/StringExtractor.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035#include "lldb/Target/Process.h"
36#include "lldb/Target/Thread.h"
37
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
Tamas Berghammerdb264a62015-03-31 09:52:22 +000041namespace lldb_private {
42namespace process_gdb_remote {
43
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044class ThreadGDBRemote;
45
Pavel Labath8c1b6bd2016-08-09 12:04:46 +000046class ProcessGDBRemote : public Process, private GDBRemoteClientBase::ContinueDelegate
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047{
48public:
Jim Ingham583bbb12016-03-07 21:50:25 +000049 ProcessGDBRemote(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000050
51 ~ProcessGDBRemote() override;
52
Greg Claytonc3776bf2012-02-09 06:16:32 +000053 static lldb::ProcessSP
Zachary Turner7529df92015-09-01 20:02:29 +000054 CreateInstance (lldb::TargetSP target_sp,
Jim Ingham583bbb12016-03-07 21:50:25 +000055 lldb::ListenerSP listener_sp,
Tamas Berghammerdb264a62015-03-31 09:52:22 +000056 const FileSpec *crash_file_path);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
58 static void
59 Initialize();
60
61 static void
Tamas Berghammerdb264a62015-03-31 09:52:22 +000062 DebuggerInitialize (Debugger &debugger);
Greg Clayton7f982402013-07-15 22:54:20 +000063
64 static void
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 Terminate();
66
Tamas Berghammerdb264a62015-03-31 09:52:22 +000067 static ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068 GetPluginNameStatic();
69
70 static const char *
71 GetPluginDescriptionStatic();
72
73 //------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +000074 // Check if a given Process
75 //------------------------------------------------------------------
Tamas Berghammer30b8cd32015-03-23 15:50:03 +000076 bool
Zachary Turner7529df92015-09-01 20:02:29 +000077 CanDebug (lldb::TargetSP target_sp, bool plugin_specified_by_name) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078
Tamas Berghammerdb264a62015-03-31 09:52:22 +000079 CommandObject *
Eric Christopher7ab81b92014-11-04 03:13:17 +000080 GetPluginCommandObject() override;
Jim Ingham5aee1622010-08-09 23:31:02 +000081
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082 //------------------------------------------------------------------
83 // Creating a new process, or attaching to an existing one
84 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +000085 Error
86 WillLaunch (Module* module) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087
Tamas Berghammerdb264a62015-03-31 09:52:22 +000088 Error
89 DoLaunch (Module *exe_module, ProcessLaunchInfo &launch_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000090
Tamas Berghammer30b8cd32015-03-23 15:50:03 +000091 void
Eric Christopher7ab81b92014-11-04 03:13:17 +000092 DidLaunch () override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093
Tamas Berghammerdb264a62015-03-31 09:52:22 +000094 Error
Eric Christopher7ab81b92014-11-04 03:13:17 +000095 WillAttachToProcessWithID (lldb::pid_t pid) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096
Tamas Berghammerdb264a62015-03-31 09:52:22 +000097 Error
Eric Christopher7ab81b92014-11-04 03:13:17 +000098 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000099
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000100 Error
101 DoConnectRemote (Stream *strm, const char *remote_url) override;
Greg Claytonb766a732011-02-04 01:58:07 +0000102
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000103 Error
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000104 WillLaunchOrAttach ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000106 Error
107 DoAttachToProcessWithID (lldb::pid_t pid, const ProcessAttachInfo &attach_info) override;
Han Ming Ong84647042012-02-25 01:07:38 +0000108
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000109 Error
Han Ming Ong84647042012-02-25 01:07:38 +0000110 DoAttachToProcessWithName (const char *process_name,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000111 const ProcessAttachInfo &attach_info) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112
Tamas Berghammer30b8cd32015-03-23 15:50:03 +0000113 void
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000114 DidAttach (ArchSpec &process_arch) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115
116 //------------------------------------------------------------------
117 // PluginInterface protocol
118 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000119 ConstString
Eric Christopher7ab81b92014-11-04 03:13:17 +0000120 GetPluginName() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000121
Tamas Berghammer30b8cd32015-03-23 15:50:03 +0000122 uint32_t
Eric Christopher7ab81b92014-11-04 03:13:17 +0000123 GetPluginVersion() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000124
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000125 //------------------------------------------------------------------
126 // Process Control
127 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000128 Error
Eric Christopher7ab81b92014-11-04 03:13:17 +0000129 WillResume () override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000130
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000131 Error
Eric Christopher7ab81b92014-11-04 03:13:17 +0000132 DoResume () override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000133
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000134 Error
Eric Christopher7ab81b92014-11-04 03:13:17 +0000135 DoHalt (bool &caused_stop) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000137 Error
Eric Christopher7ab81b92014-11-04 03:13:17 +0000138 DoDetach (bool keep_stopped) override;
Jim Ingham8af3b9c2013-03-29 01:18:12 +0000139
Tamas Berghammer30b8cd32015-03-23 15:50:03 +0000140 bool
Eric Christopher7ab81b92014-11-04 03:13:17 +0000141 DetachRequiresHalt() override { return true; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000142
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000143 Error
Eric Christopher7ab81b92014-11-04 03:13:17 +0000144 DoSignal (int signal) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000146 Error
Eric Christopher7ab81b92014-11-04 03:13:17 +0000147 DoDestroy () override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148
Tamas Berghammer30b8cd32015-03-23 15:50:03 +0000149 void
Eric Christopher7ab81b92014-11-04 03:13:17 +0000150 RefreshStateAfterStop() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000151
Chaoren Linc963a222015-09-01 16:58:45 +0000152 void
153 SetUnixSignals(const lldb::UnixSignalsSP &signals_sp);
154
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000155 //------------------------------------------------------------------
156 // Process Queries
157 //------------------------------------------------------------------
Tamas Berghammer30b8cd32015-03-23 15:50:03 +0000158 bool
Eric Christopher7ab81b92014-11-04 03:13:17 +0000159 IsAlive () override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160
Tamas Berghammer30b8cd32015-03-23 15:50:03 +0000161 lldb::addr_t
Eric Christopher7ab81b92014-11-04 03:13:17 +0000162 GetImageInfoAddress() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163
Greg Clayton2e309072015-07-17 23:42:28 +0000164 void
165 WillPublicStop () override;
166
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167 //------------------------------------------------------------------
168 // Process Memory
169 //------------------------------------------------------------------
Tamas Berghammer30b8cd32015-03-23 15:50:03 +0000170 size_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000171 DoReadMemory (lldb::addr_t addr, void *buf, size_t size, Error &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000172
Tamas Berghammer30b8cd32015-03-23 15:50:03 +0000173 size_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000174 DoWriteMemory (lldb::addr_t addr, const void *buf, size_t size, Error &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000175
Tamas Berghammer30b8cd32015-03-23 15:50:03 +0000176 lldb::addr_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000177 DoAllocateMemory (size_t size, uint32_t permissions, Error &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000178
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000179 Error
180 GetMemoryRegionInfo (lldb::addr_t load_addr, MemoryRegionInfo &region_info) override;
Greg Clayton46fb5582011-11-18 07:03:08 +0000181
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000182 Error
Eric Christopher7ab81b92014-11-04 03:13:17 +0000183 DoDeallocateMemory (lldb::addr_t ptr) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000184
185 //------------------------------------------------------------------
186 // Process STDIO
187 //------------------------------------------------------------------
Tamas Berghammer30b8cd32015-03-23 15:50:03 +0000188 size_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000189 PutSTDIN (const char *buf, size_t buf_size, Error &error) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000190
191 //----------------------------------------------------------------------
192 // Process Breakpoints
193 //----------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000194 Error
195 EnableBreakpointSite (BreakpointSite *bp_site) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000196
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000197 Error
198 DisableBreakpointSite (BreakpointSite *bp_site) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000199
200 //----------------------------------------------------------------------
201 // Process Watchpoints
202 //----------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000203 Error
204 EnableWatchpoint (Watchpoint *wp, bool notify = true) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000206 Error
207 DisableWatchpoint (Watchpoint *wp, bool notify = true) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000209 Error
Eric Christopher7ab81b92014-11-04 03:13:17 +0000210 GetWatchpointSupportInfo (uint32_t &num) override;
Johnny Chen64637202012-05-23 21:09:52 +0000211
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000212 Error
Eric Christopher7ab81b92014-11-04 03:13:17 +0000213 GetWatchpointSupportInfo (uint32_t &num, bool& after) override;
Enrico Granataf04a2192012-07-13 23:18:48 +0000214
Tamas Berghammer30b8cd32015-03-23 15:50:03 +0000215 bool
Eric Christopher7ab81b92014-11-04 03:13:17 +0000216 StartNoticingNewThreads() override;
Jim Ingham1c823b42011-01-22 01:33:44 +0000217
Tamas Berghammer30b8cd32015-03-23 15:50:03 +0000218 bool
Eric Christopher7ab81b92014-11-04 03:13:17 +0000219 StopNoticingNewThreads() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000220
Greg Claytonc1422c12012-04-09 22:46:21 +0000221 GDBRemoteCommunicationClient &
222 GetGDBRemote()
223 {
224 return m_gdb_comm;
225 }
Greg Claytonfbb76342013-11-20 21:07:01 +0000226
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000227 Error
Eric Christopher7ab81b92014-11-04 03:13:17 +0000228 SendEventData(const char *data) override;
Jason Molendaa3329782014-03-29 18:54:20 +0000229
Greg Claytonfbb76342013-11-20 21:07:01 +0000230 //----------------------------------------------------------------------
Greg Clayton5df78fa2015-05-23 03:54:53 +0000231 // Override DidExit so we can disconnect from the remote GDB server
Greg Claytonfbb76342013-11-20 21:07:01 +0000232 //----------------------------------------------------------------------
Greg Clayton5df78fa2015-05-23 03:54:53 +0000233 void
234 DidExit () override;
Greg Claytonfbb76342013-11-20 21:07:01 +0000235
Jason Molenda6076bf42014-05-06 04:34:52 +0000236 void
237 SetUserSpecifiedMaxMemoryTransferSize (uint64_t user_specified_max);
238
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +0000239 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000240 GetModuleSpec(const FileSpec& module_file_spec,
241 const ArchSpec& arch,
242 ModuleSpec &module_spec) override;
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +0000243
Jim Ingham13c30d22015-11-05 22:33:17 +0000244 bool
245 GetHostOSVersion(uint32_t &major,
246 uint32_t &minor,
247 uint32_t &update) override;
248
Tamas Berghammer783bfc82015-06-18 20:43:56 +0000249 size_t
Stephane Sezer87b0fe02016-01-12 19:02:41 +0000250 LoadModules(LoadedModuleInfoList &module_list) override;
251
252 size_t
Tamas Berghammer783bfc82015-06-18 20:43:56 +0000253 LoadModules() override;
254
255 Error
256 GetFileLoadAddress(const FileSpec& file, bool& is_loaded, lldb::addr_t& load_addr) override;
Colin Rileyc3c95b22015-04-16 15:51:33 +0000257
Greg Clayton0b90be12015-06-23 21:27:50 +0000258 void
259 ModulesDidLoad (ModuleList &module_list) override;
260
Jason Molenda20ee21b2015-07-10 23:15:22 +0000261 StructuredData::ObjectSP
262 GetLoadedDynamicLibrariesInfos (lldb::addr_t image_list_address, lldb::addr_t image_count) override;
263
Jason Molenda9ab5dc22016-07-21 08:30:55 +0000264 StructuredData::ObjectSP
265 GetLoadedDynamicLibrariesInfos () override;
266
267 StructuredData::ObjectSP
268 GetLoadedDynamicLibrariesInfos (const std::vector<lldb::addr_t> &load_addresses) override;
269
270 StructuredData::ObjectSP
271 GetLoadedDynamicLibrariesInfos_sender (StructuredData::ObjectSP args);
272
Jason Molenda37397352016-07-22 00:17:55 +0000273 StructuredData::ObjectSP
274 GetSharedCacheInfo () override;
275
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000276 std::string
277 HarmonizeThreadIdsForProfileData(StringExtractorGDBRemote &inputStringExtractor);
278
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000279protected:
280 friend class ThreadGDBRemote;
Greg Clayton576d8832011-03-22 04:00:09 +0000281 friend class GDBRemoteCommunicationClient;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282 friend class GDBRemoteRegisterContext;
283
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000284 //------------------------------------------------------------------
285 /// Broadcaster event bits definitions.
286 //------------------------------------------------------------------
287 enum
288 {
289 eBroadcastBitAsyncContinue = (1 << 0),
290 eBroadcastBitAsyncThreadShouldExit = (1 << 1),
291 eBroadcastBitAsyncThreadDidExit = (1 << 2)
292 };
293
294 Flags m_flags; // Process specific flags (see eFlags enums)
295 GDBRemoteCommunicationClient m_gdb_comm;
296 std::atomic<lldb::pid_t> m_debugserver_pid;
297 std::vector<StringExtractorGDBRemote> m_stop_packet_stack; // The stop packet stack replaces the last stop packet variable
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +0000298 std::recursive_mutex m_last_stop_packet_mutex;
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000299 GDBRemoteDynamicRegisterInfo m_register_info;
300 Broadcaster m_async_broadcaster;
Jim Ingham583bbb12016-03-07 21:50:25 +0000301 lldb::ListenerSP m_async_listener_sp;
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000302 HostThread m_async_thread;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +0000303 std::recursive_mutex m_async_thread_state_mutex;
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000304 typedef std::vector<lldb::tid_t> tid_collection;
305 typedef std::vector< std::pair<lldb::tid_t,int> > tid_sig_collection;
306 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
307 typedef std::map<uint32_t, std::string> ExpeditedRegisterMap;
308 tid_collection m_thread_ids; // Thread IDs for all threads. This list gets updated after stopping
Jason Molenda545304d2015-12-18 00:45:35 +0000309 std::vector<lldb::addr_t> m_thread_pcs; // PC values for all the threads.
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000310 StructuredData::ObjectSP m_jstopinfo_sp; // Stop info only for any threads that have valid stop infos
311 StructuredData::ObjectSP m_jthreadsinfo_sp; // Full stop info, expedited registers and memory for all threads if "jThreadsInfo" packet is supported
312 tid_collection m_continue_c_tids; // 'c' for continue
313 tid_sig_collection m_continue_C_tids; // 'C' for continue with signal
314 tid_collection m_continue_s_tids; // 's' for step
315 tid_sig_collection m_continue_S_tids; // 'S' for step with signal
316 uint64_t m_max_memory_size; // The maximum number of bytes to read/write when reading and writing memory
317 uint64_t m_remote_stub_max_memory_size; // The maximum memory size the remote gdb stub can handle
318 MMapMap m_addr_to_mmap_size;
319 lldb::BreakpointSP m_thread_create_bp_sp;
320 bool m_waiting_for_attach;
321 bool m_destroy_tried_resuming;
322 lldb::CommandObjectSP m_command_sp;
323 int64_t m_breakpoint_pc_offset;
324 lldb::tid_t m_initial_tid; // The initial thread ID, given by stub on attach
325
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000326 //----------------------------------------------------------------------
327 // Accessors
328 //----------------------------------------------------------------------
329 bool
330 IsRunning ( lldb::StateType state )
331 {
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000332 return state == lldb::eStateRunning || IsStepping(state);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333 }
334
335 bool
336 IsStepping ( lldb::StateType state)
337 {
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000338 return state == lldb::eStateStepping;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000339 }
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000340
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000341 bool
342 CanResume ( lldb::StateType state)
343 {
344 return state == lldb::eStateStopped;
345 }
346
347 bool
348 HasExited (lldb::StateType state)
349 {
350 return state == lldb::eStateExited;
351 }
352
353 bool
354 ProcessIDIsValid ( ) const;
355
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000356 void
357 Clear ( );
358
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000359 Flags &
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000360 GetFlags ()
361 {
362 return m_flags;
363 }
364
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000365 const Flags &
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000366 GetFlags () const
367 {
368 return m_flags;
369 }
370
Tamas Berghammer30b8cd32015-03-23 15:50:03 +0000371 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000372 UpdateThreadList (ThreadList &old_thread_list,
373 ThreadList &new_thread_list) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000375 Error
Oleksiy Vyalovafd6ce42015-11-23 19:32:24 +0000376 EstablishConnectionIfNeeded (const ProcessInfo &process_info);
377
378 Error
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000379 LaunchAndConnectToDebugserver (const ProcessInfo &process_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380
381 void
382 KillDebugserverProcess ();
383
384 void
Greg Clayton513c26c2011-01-29 07:10:55 +0000385 BuildDynamicRegisterInfo (bool force);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000386
Greg Clayton09c3e3d2011-12-06 04:51:14 +0000387 void
Greg Clayton8cda7f02013-05-21 21:55:59 +0000388 SetLastStopPacket (const StringExtractorGDBRemote &response);
Jason Molendad1fae142012-09-29 08:03:33 +0000389
Greg Claytonef8180a2013-10-15 00:14:28 +0000390 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000391 ParsePythonTargetDefinition(const FileSpec &target_definition_fspec);
Greg Claytonef8180a2013-10-15 00:14:28 +0000392
Todd Fialaaf245d12014-06-30 21:05:18 +0000393 const lldb::DataBufferSP
394 GetAuxvData() override;
Steve Pucci03904ac2014-03-04 23:18:46 +0000395
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000396 StructuredData::ObjectSP
Jason Molenda705b1802014-06-13 02:37:02 +0000397 GetExtendedInfoForThread (lldb::tid_t tid);
398
Jason Molenda6076bf42014-05-06 04:34:52 +0000399 void
400 GetMaxMemorySize();
401
Greg Clayton358cf1e2015-06-25 21:46:34 +0000402 bool
403 CalculateThreadStopInfo (ThreadGDBRemote *thread);
404
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000405 size_t
Jason Molenda545304d2015-12-18 00:45:35 +0000406 UpdateThreadPCsFromStopReplyThreadsValue (std::string &value);
407
408 size_t
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000409 UpdateThreadIDsFromStopReplyThreadsValue (std::string &value);
410
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411 bool
Ewan Crawford76df2882015-06-23 12:32:06 +0000412 HandleNotifyPacket(StringExtractorGDBRemote &packet);
413
414 bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415 StartAsyncThread ();
416
417 void
418 StopAsyncThread ();
419
Virgile Bellob2f1fb22013-08-23 12:44:05 +0000420 static lldb::thread_result_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421 AsyncThread (void *arg);
422
423 static bool
Pavel Labath194357c2016-05-12 11:10:01 +0000424 MonitorDebugserverProcess(std::weak_ptr<ProcessGDBRemote> process_wp, lldb::pid_t pid, bool exited, int signo,
425 int exit_status);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426
427 lldb::StateType
428 SetThreadStopInfo (StringExtractor& stop_packet);
429
Greg Clayton2e309072015-07-17 23:42:28 +0000430 bool
431 GetThreadStopInfoFromJSON (ThreadGDBRemote *thread, const StructuredData::ObjectSP &thread_infos_sp);
432
433 lldb::ThreadSP
Greg Clayton358cf1e2015-06-25 21:46:34 +0000434 SetThreadStopInfo (StructuredData::Dictionary *thread_dict);
435
436 lldb::ThreadSP
437 SetThreadStopInfo (lldb::tid_t tid,
438 ExpeditedRegisterMap &expedited_register_map,
439 uint8_t signo,
440 const std::string &thread_name,
441 const std::string &reason,
442 const std::string &description,
443 uint32_t exc_type,
444 const std::vector<lldb::addr_t> &exc_data,
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000445 lldb::addr_t thread_dispatch_qaddr,
446 bool queue_vars_valid,
Jason Molenda77f89352016-01-12 07:09:16 +0000447 lldb_private::LazyBool associated_with_libdispatch_queue,
448 lldb::addr_t dispatch_queue_t,
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000449 std::string &queue_name,
450 lldb::QueueKind queue_kind,
451 uint64_t queue_serial);
Greg Clayton358cf1e2015-06-25 21:46:34 +0000452
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 void
Ewan Crawford78baa192015-05-13 09:18:18 +0000454 HandleStopReplySequence ();
455
456 void
Greg Clayton9e920902012-04-10 02:25:43 +0000457 ClearThreadIDList ();
458
459 bool
460 UpdateThreadIDList ();
461
462 void
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000463 DidLaunchOrAttach (ArchSpec& process_arch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000465 Error
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000466 ConnectToDebugserver (const char *host_port);
467
468 const char *
469 GetDispatchQueueNameForThread (lldb::addr_t thread_dispatch_qaddr,
470 std::string &dispatch_queue_name);
471
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000472 DynamicLoader *
Eric Christopher7ab81b92014-11-04 03:13:17 +0000473 GetDynamicLoader () override;
Jason Molenda5e8534e2012-10-03 01:29:34 +0000474
Aidan Doddsc0c83852015-05-08 09:36:31 +0000475 // Query remote GDBServer for register information
476 bool
Jim Ingham7b71c0b2016-02-18 23:58:45 +0000477 GetGDBServerRegisterInfo (ArchSpec &arch);
Aidan Doddsc0c83852015-05-08 09:36:31 +0000478
479 // Query remote GDBServer for a detailed loaded library list
480 Error
Stephane Sezer87b0fe02016-01-12 19:02:41 +0000481 GetLoadedModuleList (LoadedModuleInfoList &);
Aidan Doddsc0c83852015-05-08 09:36:31 +0000482
483 lldb::ModuleSP
Stephane Sezer3553c0e2016-04-05 17:25:32 +0000484 LoadModuleAtAddress (const FileSpec &file, lldb::addr_t link_map, lldb::addr_t base_addr,
485 bool value_is_offset);
Aidan Doddsc0c83852015-05-08 09:36:31 +0000486
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487private:
488 //------------------------------------------------------------------
489 // For ProcessGDBRemote only
490 //------------------------------------------------------------------
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000491 std::string m_partial_profile_data;
492 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
493
Jim Ingham1c823b42011-01-22 01:33:44 +0000494 static bool
495 NewThreadNotifyBreakpointHit (void *baton,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000496 StoppointCallbackContext *context,
Jim Ingham1c823b42011-01-22 01:33:44 +0000497 lldb::user_id_t break_id,
498 lldb::user_id_t break_loc_id);
499
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000500 //------------------------------------------------------------------
501 // ContinueDelegate interface
502 //------------------------------------------------------------------
503 void
504 HandleAsyncStdout(llvm::StringRef out) override;
505 void
506 HandleAsyncMisc(llvm::StringRef data) override;
507 void
508 HandleStopReply() override;
509
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510 DISALLOW_COPY_AND_ASSIGN (ProcessGDBRemote);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511};
512
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000513} // namespace process_gdb_remote
514} // namespace lldb_private
515
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000516#endif // liblldb_ProcessGDBRemote_h_