blob: 3a0dd2f72357caa265b388303655efbdc1ccbe12 [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
Todd Fiala75930012016-08-19 04:21:48 +0000264 Error
265 ConfigureStructuredData(const ConstString &type_name,
266 const StructuredData::ObjectSP &config_sp) override;
267
Jason Molenda9ab5dc22016-07-21 08:30:55 +0000268 StructuredData::ObjectSP
269 GetLoadedDynamicLibrariesInfos () override;
270
271 StructuredData::ObjectSP
272 GetLoadedDynamicLibrariesInfos (const std::vector<lldb::addr_t> &load_addresses) override;
273
274 StructuredData::ObjectSP
275 GetLoadedDynamicLibrariesInfos_sender (StructuredData::ObjectSP args);
276
Jason Molenda37397352016-07-22 00:17:55 +0000277 StructuredData::ObjectSP
278 GetSharedCacheInfo () override;
279
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000280 std::string
281 HarmonizeThreadIdsForProfileData(StringExtractorGDBRemote &inputStringExtractor);
282
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283protected:
284 friend class ThreadGDBRemote;
Greg Clayton576d8832011-03-22 04:00:09 +0000285 friend class GDBRemoteCommunicationClient;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000286 friend class GDBRemoteRegisterContext;
287
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000288 //------------------------------------------------------------------
289 /// Broadcaster event bits definitions.
290 //------------------------------------------------------------------
291 enum
292 {
293 eBroadcastBitAsyncContinue = (1 << 0),
294 eBroadcastBitAsyncThreadShouldExit = (1 << 1),
295 eBroadcastBitAsyncThreadDidExit = (1 << 2)
296 };
297
298 Flags m_flags; // Process specific flags (see eFlags enums)
299 GDBRemoteCommunicationClient m_gdb_comm;
300 std::atomic<lldb::pid_t> m_debugserver_pid;
301 std::vector<StringExtractorGDBRemote> m_stop_packet_stack; // The stop packet stack replaces the last stop packet variable
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +0000302 std::recursive_mutex m_last_stop_packet_mutex;
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000303 GDBRemoteDynamicRegisterInfo m_register_info;
304 Broadcaster m_async_broadcaster;
Jim Ingham583bbb12016-03-07 21:50:25 +0000305 lldb::ListenerSP m_async_listener_sp;
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000306 HostThread m_async_thread;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +0000307 std::recursive_mutex m_async_thread_state_mutex;
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000308 typedef std::vector<lldb::tid_t> tid_collection;
309 typedef std::vector< std::pair<lldb::tid_t,int> > tid_sig_collection;
310 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
311 typedef std::map<uint32_t, std::string> ExpeditedRegisterMap;
312 tid_collection m_thread_ids; // Thread IDs for all threads. This list gets updated after stopping
Jason Molenda545304d2015-12-18 00:45:35 +0000313 std::vector<lldb::addr_t> m_thread_pcs; // PC values for all the threads.
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000314 StructuredData::ObjectSP m_jstopinfo_sp; // Stop info only for any threads that have valid stop infos
315 StructuredData::ObjectSP m_jthreadsinfo_sp; // Full stop info, expedited registers and memory for all threads if "jThreadsInfo" packet is supported
316 tid_collection m_continue_c_tids; // 'c' for continue
317 tid_sig_collection m_continue_C_tids; // 'C' for continue with signal
318 tid_collection m_continue_s_tids; // 's' for step
319 tid_sig_collection m_continue_S_tids; // 'S' for step with signal
320 uint64_t m_max_memory_size; // The maximum number of bytes to read/write when reading and writing memory
321 uint64_t m_remote_stub_max_memory_size; // The maximum memory size the remote gdb stub can handle
322 MMapMap m_addr_to_mmap_size;
323 lldb::BreakpointSP m_thread_create_bp_sp;
324 bool m_waiting_for_attach;
325 bool m_destroy_tried_resuming;
326 lldb::CommandObjectSP m_command_sp;
327 int64_t m_breakpoint_pc_offset;
328 lldb::tid_t m_initial_tid; // The initial thread ID, given by stub on attach
329
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000330 //----------------------------------------------------------------------
331 // Accessors
332 //----------------------------------------------------------------------
333 bool
334 IsRunning ( lldb::StateType state )
335 {
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000336 return state == lldb::eStateRunning || IsStepping(state);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000337 }
338
339 bool
340 IsStepping ( lldb::StateType state)
341 {
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000342 return state == lldb::eStateStepping;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000343 }
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000344
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000345 bool
346 CanResume ( lldb::StateType state)
347 {
348 return state == lldb::eStateStopped;
349 }
350
351 bool
352 HasExited (lldb::StateType state)
353 {
354 return state == lldb::eStateExited;
355 }
356
357 bool
358 ProcessIDIsValid ( ) const;
359
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000360 void
361 Clear ( );
362
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000363 Flags &
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000364 GetFlags ()
365 {
366 return m_flags;
367 }
368
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000369 const Flags &
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370 GetFlags () const
371 {
372 return m_flags;
373 }
374
Tamas Berghammer30b8cd32015-03-23 15:50:03 +0000375 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000376 UpdateThreadList (ThreadList &old_thread_list,
377 ThreadList &new_thread_list) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000378
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000379 Error
Oleksiy Vyalovafd6ce42015-11-23 19:32:24 +0000380 EstablishConnectionIfNeeded (const ProcessInfo &process_info);
381
382 Error
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000383 LaunchAndConnectToDebugserver (const ProcessInfo &process_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384
385 void
386 KillDebugserverProcess ();
387
388 void
Greg Clayton513c26c2011-01-29 07:10:55 +0000389 BuildDynamicRegisterInfo (bool force);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390
Greg Clayton09c3e3d2011-12-06 04:51:14 +0000391 void
Greg Clayton8cda7f02013-05-21 21:55:59 +0000392 SetLastStopPacket (const StringExtractorGDBRemote &response);
Jason Molendad1fae142012-09-29 08:03:33 +0000393
Greg Claytonef8180a2013-10-15 00:14:28 +0000394 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000395 ParsePythonTargetDefinition(const FileSpec &target_definition_fspec);
Greg Claytonef8180a2013-10-15 00:14:28 +0000396
Todd Fialaaf245d12014-06-30 21:05:18 +0000397 const lldb::DataBufferSP
398 GetAuxvData() override;
Steve Pucci03904ac2014-03-04 23:18:46 +0000399
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000400 StructuredData::ObjectSP
Jason Molenda705b1802014-06-13 02:37:02 +0000401 GetExtendedInfoForThread (lldb::tid_t tid);
402
Jason Molenda6076bf42014-05-06 04:34:52 +0000403 void
404 GetMaxMemorySize();
405
Greg Clayton358cf1e2015-06-25 21:46:34 +0000406 bool
407 CalculateThreadStopInfo (ThreadGDBRemote *thread);
408
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000409 size_t
Jason Molenda545304d2015-12-18 00:45:35 +0000410 UpdateThreadPCsFromStopReplyThreadsValue (std::string &value);
411
412 size_t
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000413 UpdateThreadIDsFromStopReplyThreadsValue (std::string &value);
414
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415 bool
Ewan Crawford76df2882015-06-23 12:32:06 +0000416 HandleNotifyPacket(StringExtractorGDBRemote &packet);
417
418 bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000419 StartAsyncThread ();
420
421 void
422 StopAsyncThread ();
423
Virgile Bellob2f1fb22013-08-23 12:44:05 +0000424 static lldb::thread_result_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 AsyncThread (void *arg);
426
427 static bool
Pavel Labath194357c2016-05-12 11:10:01 +0000428 MonitorDebugserverProcess(std::weak_ptr<ProcessGDBRemote> process_wp, lldb::pid_t pid, bool exited, int signo,
429 int exit_status);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000430
431 lldb::StateType
432 SetThreadStopInfo (StringExtractor& stop_packet);
433
Greg Clayton2e309072015-07-17 23:42:28 +0000434 bool
435 GetThreadStopInfoFromJSON (ThreadGDBRemote *thread, const StructuredData::ObjectSP &thread_infos_sp);
436
437 lldb::ThreadSP
Greg Clayton358cf1e2015-06-25 21:46:34 +0000438 SetThreadStopInfo (StructuredData::Dictionary *thread_dict);
439
440 lldb::ThreadSP
441 SetThreadStopInfo (lldb::tid_t tid,
442 ExpeditedRegisterMap &expedited_register_map,
443 uint8_t signo,
444 const std::string &thread_name,
445 const std::string &reason,
446 const std::string &description,
447 uint32_t exc_type,
448 const std::vector<lldb::addr_t> &exc_data,
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000449 lldb::addr_t thread_dispatch_qaddr,
450 bool queue_vars_valid,
Jason Molenda77f89352016-01-12 07:09:16 +0000451 lldb_private::LazyBool associated_with_libdispatch_queue,
452 lldb::addr_t dispatch_queue_t,
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000453 std::string &queue_name,
454 lldb::QueueKind queue_kind,
455 uint64_t queue_serial);
Greg Clayton358cf1e2015-06-25 21:46:34 +0000456
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457 void
Ewan Crawford78baa192015-05-13 09:18:18 +0000458 HandleStopReplySequence ();
459
460 void
Greg Clayton9e920902012-04-10 02:25:43 +0000461 ClearThreadIDList ();
462
463 bool
464 UpdateThreadIDList ();
465
466 void
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000467 DidLaunchOrAttach (ArchSpec& process_arch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000469 Error
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470 ConnectToDebugserver (const char *host_port);
471
472 const char *
473 GetDispatchQueueNameForThread (lldb::addr_t thread_dispatch_qaddr,
474 std::string &dispatch_queue_name);
475
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000476 DynamicLoader *
Eric Christopher7ab81b92014-11-04 03:13:17 +0000477 GetDynamicLoader () override;
Jason Molenda5e8534e2012-10-03 01:29:34 +0000478
Aidan Doddsc0c83852015-05-08 09:36:31 +0000479 // Query remote GDBServer for register information
480 bool
Jim Ingham7b71c0b2016-02-18 23:58:45 +0000481 GetGDBServerRegisterInfo (ArchSpec &arch);
Aidan Doddsc0c83852015-05-08 09:36:31 +0000482
483 // Query remote GDBServer for a detailed loaded library list
484 Error
Stephane Sezer87b0fe02016-01-12 19:02:41 +0000485 GetLoadedModuleList (LoadedModuleInfoList &);
Aidan Doddsc0c83852015-05-08 09:36:31 +0000486
487 lldb::ModuleSP
Stephane Sezer3553c0e2016-04-05 17:25:32 +0000488 LoadModuleAtAddress (const FileSpec &file, lldb::addr_t link_map, lldb::addr_t base_addr,
489 bool value_is_offset);
Aidan Doddsc0c83852015-05-08 09:36:31 +0000490
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491private:
492 //------------------------------------------------------------------
493 // For ProcessGDBRemote only
494 //------------------------------------------------------------------
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000495 std::string m_partial_profile_data;
496 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
497
Jim Ingham1c823b42011-01-22 01:33:44 +0000498 static bool
499 NewThreadNotifyBreakpointHit (void *baton,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000500 StoppointCallbackContext *context,
Jim Ingham1c823b42011-01-22 01:33:44 +0000501 lldb::user_id_t break_id,
502 lldb::user_id_t break_loc_id);
503
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000504 //------------------------------------------------------------------
505 // ContinueDelegate interface
506 //------------------------------------------------------------------
507 void
508 HandleAsyncStdout(llvm::StringRef out) override;
509 void
510 HandleAsyncMisc(llvm::StringRef data) override;
511 void
512 HandleStopReply() override;
Todd Fiala75930012016-08-19 04:21:48 +0000513 bool
514 HandleAsyncStructuredData(const StructuredData::ObjectSP
515 &object_sp) override;
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000516
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000517 DISALLOW_COPY_AND_ASSIGN (ProcessGDBRemote);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000518};
519
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000520} // namespace process_gdb_remote
521} // namespace lldb_private
522
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000523#endif // liblldb_ProcessGDBRemote_h_