Greg Clayton | 269f91e | 2011-07-15 18:02:58 +0000 | [diff] [blame] | 1 | //===-- ProcessKDP.cpp ------------------------------------------*- C++ -*-===// |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 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 | // C Includes |
| 11 | #include <errno.h> |
| 12 | #include <stdlib.h> |
| 13 | |
| 14 | // C++ Includes |
| 15 | // Other libraries and framework includes |
Greg Clayton | 8d2ea28 | 2011-07-17 20:36:25 +0000 | [diff] [blame] | 16 | #include "lldb/Core/ConnectionFileDescriptor.h" |
Greg Clayton | 234981a | 2011-07-20 03:41:06 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Debugger.h" |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 18 | #include "lldb/Core/PluginManager.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 19 | #include "lldb/Core/Module.h" |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 20 | #include "lldb/Core/State.h" |
| 21 | #include "lldb/Host/Host.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 22 | #include "lldb/Symbol/ObjectFile.h" |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 23 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | 1e5b021 | 2011-07-15 16:31:38 +0000 | [diff] [blame] | 24 | #include "lldb/Target/Target.h" |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Thread.h" |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 26 | |
| 27 | // Project includes |
| 28 | #include "ProcessKDP.h" |
| 29 | #include "ProcessKDPLog.h" |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 30 | #include "ThreadKDP.h" |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 31 | |
| 32 | using namespace lldb; |
| 33 | using namespace lldb_private; |
| 34 | |
| 35 | const char * |
| 36 | ProcessKDP::GetPluginNameStatic() |
| 37 | { |
| 38 | return "kdp-remote"; |
| 39 | } |
| 40 | |
| 41 | const char * |
| 42 | ProcessKDP::GetPluginDescriptionStatic() |
| 43 | { |
| 44 | return "KDP Remote protocol based debugging plug-in for darwin kernel debugging."; |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | ProcessKDP::Terminate() |
| 49 | { |
| 50 | PluginManager::UnregisterPlugin (ProcessKDP::CreateInstance); |
| 51 | } |
| 52 | |
| 53 | |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 54 | lldb::ProcessSP |
| 55 | ProcessKDP::CreateInstance (Target &target, |
| 56 | Listener &listener, |
| 57 | const FileSpec *crash_file_path) |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 58 | { |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 59 | lldb::ProcessSP process_sp; |
| 60 | if (crash_file_path == NULL) |
| 61 | process_sp.reset(new ProcessKDP (target, listener)); |
| 62 | return process_sp; |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | bool |
Greg Clayton | 8d2ea28 | 2011-07-17 20:36:25 +0000 | [diff] [blame] | 66 | ProcessKDP::CanDebug(Target &target, bool plugin_specified_by_name) |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 67 | { |
Greg Clayton | 61ddf56 | 2011-10-21 21:41:45 +0000 | [diff] [blame] | 68 | if (plugin_specified_by_name) |
| 69 | return true; |
| 70 | |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 71 | // For now we are just making sure the file exists for a given module |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 72 | Module *exe_module = target.GetExecutableModulePointer(); |
| 73 | if (exe_module) |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 74 | { |
| 75 | const llvm::Triple &triple_ref = target.GetArchitecture().GetTriple(); |
Greg Clayton | b170aee | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 76 | switch (triple_ref.getOS()) |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 77 | { |
Greg Clayton | b170aee | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 78 | case llvm::Triple::Darwin: // Should use "macosx" for desktop and "ios" for iOS, but accept darwin just in case |
| 79 | case llvm::Triple::MacOSX: // For desktop targets |
| 80 | case llvm::Triple::IOS: // For arm targets |
| 81 | if (triple_ref.getVendor() == llvm::Triple::Apple) |
| 82 | { |
| 83 | ObjectFile *exe_objfile = exe_module->GetObjectFile(); |
| 84 | if (exe_objfile->GetType() == ObjectFile::eTypeExecutable && |
| 85 | exe_objfile->GetStrata() == ObjectFile::eStrataKernel) |
| 86 | return true; |
| 87 | } |
| 88 | break; |
| 89 | |
| 90 | default: |
| 91 | break; |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 92 | } |
| 93 | } |
Greg Clayton | 61ddf56 | 2011-10-21 21:41:45 +0000 | [diff] [blame] | 94 | return false; |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | //---------------------------------------------------------------------- |
| 98 | // ProcessKDP constructor |
| 99 | //---------------------------------------------------------------------- |
| 100 | ProcessKDP::ProcessKDP(Target& target, Listener &listener) : |
| 101 | Process (target, listener), |
| 102 | m_comm("lldb.process.kdp-remote.communication"), |
Jim Ingham | 5a15e69 | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 103 | m_async_broadcaster (NULL, "lldb.process.kdp-remote.async-broadcaster"), |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 104 | m_async_thread (LLDB_INVALID_HOST_THREAD), |
| 105 | m_destroy_in_process (false) |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 106 | { |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 107 | m_async_broadcaster.SetEventName (eBroadcastBitAsyncThreadShouldExit, "async thread should exit"); |
| 108 | m_async_broadcaster.SetEventName (eBroadcastBitAsyncContinue, "async thread continue"); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | //---------------------------------------------------------------------- |
| 112 | // Destructor |
| 113 | //---------------------------------------------------------------------- |
| 114 | ProcessKDP::~ProcessKDP() |
| 115 | { |
| 116 | Clear(); |
Greg Clayton | ffa43a6 | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 117 | // We need to call finalize on the process before destroying ourselves |
| 118 | // to make sure all of the broadcaster cleanup goes as planned. If we |
| 119 | // destruct this class, then Process::~Process() might have problems |
| 120 | // trying to fully destroy the broadcaster. |
| 121 | Finalize(); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | //---------------------------------------------------------------------- |
| 125 | // PluginInterface |
| 126 | //---------------------------------------------------------------------- |
| 127 | const char * |
| 128 | ProcessKDP::GetPluginName() |
| 129 | { |
| 130 | return "Process debugging plug-in that uses the Darwin KDP remote protocol"; |
| 131 | } |
| 132 | |
| 133 | const char * |
| 134 | ProcessKDP::GetShortPluginName() |
| 135 | { |
| 136 | return GetPluginNameStatic(); |
| 137 | } |
| 138 | |
| 139 | uint32_t |
| 140 | ProcessKDP::GetPluginVersion() |
| 141 | { |
| 142 | return 1; |
| 143 | } |
| 144 | |
| 145 | Error |
| 146 | ProcessKDP::WillLaunch (Module* module) |
| 147 | { |
| 148 | Error error; |
| 149 | error.SetErrorString ("launching not supported in kdp-remote plug-in"); |
| 150 | return error; |
| 151 | } |
| 152 | |
| 153 | Error |
| 154 | ProcessKDP::WillAttachToProcessWithID (lldb::pid_t pid) |
| 155 | { |
| 156 | Error error; |
| 157 | error.SetErrorString ("attaching to a by process ID not supported in kdp-remote plug-in"); |
| 158 | return error; |
| 159 | } |
| 160 | |
| 161 | Error |
| 162 | ProcessKDP::WillAttachToProcessWithName (const char *process_name, bool wait_for_launch) |
| 163 | { |
| 164 | Error error; |
| 165 | error.SetErrorString ("attaching to a by process name not supported in kdp-remote plug-in"); |
| 166 | return error; |
| 167 | } |
| 168 | |
| 169 | Error |
| 170 | ProcessKDP::DoConnectRemote (const char *remote_url) |
| 171 | { |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 172 | Error error; |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 173 | |
| 174 | // Don't let any JIT happen when doing KDP as we can't allocate |
| 175 | // memory and we don't want to be mucking with threads that might |
| 176 | // already be handling exceptions |
| 177 | SetCanJIT(false); |
| 178 | |
Greg Clayton | 8d2ea28 | 2011-07-17 20:36:25 +0000 | [diff] [blame] | 179 | if (remote_url == NULL || remote_url[0] == '\0') |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 180 | { |
| 181 | error.SetErrorStringWithFormat ("invalid connection URL '%s'", remote_url); |
| 182 | return error; |
| 183 | } |
Greg Clayton | 8d2ea28 | 2011-07-17 20:36:25 +0000 | [diff] [blame] | 184 | |
| 185 | std::auto_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor()); |
| 186 | if (conn_ap.get()) |
| 187 | { |
| 188 | // Only try once for now. |
| 189 | // TODO: check if we should be retrying? |
| 190 | const uint32_t max_retry_count = 1; |
| 191 | for (uint32_t retry_count = 0; retry_count < max_retry_count; ++retry_count) |
| 192 | { |
| 193 | if (conn_ap->Connect(remote_url, &error) == eConnectionStatusSuccess) |
| 194 | break; |
| 195 | usleep (100000); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | if (conn_ap->IsConnected()) |
| 200 | { |
| 201 | const uint16_t reply_port = conn_ap->GetReadPort (); |
| 202 | |
| 203 | if (reply_port != 0) |
| 204 | { |
| 205 | m_comm.SetConnection(conn_ap.release()); |
| 206 | |
| 207 | if (m_comm.SendRequestReattach(reply_port)) |
| 208 | { |
| 209 | if (m_comm.SendRequestConnect(reply_port, reply_port, "Greetings from LLDB...")) |
| 210 | { |
| 211 | m_comm.GetVersion(); |
| 212 | uint32_t cpu = m_comm.GetCPUType(); |
| 213 | uint32_t sub = m_comm.GetCPUSubtype(); |
| 214 | ArchSpec kernel_arch; |
| 215 | kernel_arch.SetArchitecture(eArchTypeMachO, cpu, sub); |
| 216 | m_target.SetArchitecture(kernel_arch); |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 217 | // Set the thread ID |
| 218 | UpdateThreadListIfNeeded (); |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 219 | SetID (1); |
Greg Clayton | 37f962e | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 220 | GetThreadList (); |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 221 | SetPrivateState (eStateStopped); |
Greg Clayton | 234981a | 2011-07-20 03:41:06 +0000 | [diff] [blame] | 222 | StreamSP async_strm_sp(m_target.GetDebugger().GetAsyncOutputStream()); |
| 223 | if (async_strm_sp) |
| 224 | { |
Greg Clayton | 7b13922 | 2011-07-21 01:12:01 +0000 | [diff] [blame] | 225 | const char *cstr; |
| 226 | if ((cstr = m_comm.GetKernelVersion ()) != NULL) |
Greg Clayton | 234981a | 2011-07-20 03:41:06 +0000 | [diff] [blame] | 227 | { |
Greg Clayton | 7b13922 | 2011-07-21 01:12:01 +0000 | [diff] [blame] | 228 | async_strm_sp->Printf ("Version: %s\n", cstr); |
Greg Clayton | 234981a | 2011-07-20 03:41:06 +0000 | [diff] [blame] | 229 | async_strm_sp->Flush(); |
| 230 | } |
Greg Clayton | 7b13922 | 2011-07-21 01:12:01 +0000 | [diff] [blame] | 231 | // if ((cstr = m_comm.GetImagePath ()) != NULL) |
| 232 | // { |
| 233 | // async_strm_sp->Printf ("Image Path: %s\n", cstr); |
| 234 | // async_strm_sp->Flush(); |
| 235 | // } |
Greg Clayton | 234981a | 2011-07-20 03:41:06 +0000 | [diff] [blame] | 236 | } |
Greg Clayton | 8d2ea28 | 2011-07-17 20:36:25 +0000 | [diff] [blame] | 237 | } |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 238 | else |
| 239 | { |
| 240 | puts ("KDP_CONNECT failed"); // REMOVE THIS |
| 241 | error.SetErrorString("KDP_REATTACH failed"); |
| 242 | } |
Greg Clayton | 8d2ea28 | 2011-07-17 20:36:25 +0000 | [diff] [blame] | 243 | } |
| 244 | else |
| 245 | { |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 246 | puts ("KDP_REATTACH failed"); // REMOVE THIS |
| 247 | error.SetErrorString("KDP_REATTACH failed"); |
Greg Clayton | 8d2ea28 | 2011-07-17 20:36:25 +0000 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | else |
| 251 | { |
| 252 | error.SetErrorString("invalid reply port from UDP connection"); |
| 253 | } |
| 254 | } |
| 255 | else |
| 256 | { |
| 257 | if (error.Success()) |
| 258 | error.SetErrorStringWithFormat ("failed to connect to '%s'", remote_url); |
| 259 | } |
| 260 | if (error.Fail()) |
| 261 | m_comm.Disconnect(); |
| 262 | |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 263 | return error; |
| 264 | } |
| 265 | |
| 266 | //---------------------------------------------------------------------- |
| 267 | // Process Control |
| 268 | //---------------------------------------------------------------------- |
| 269 | Error |
Greg Clayton | 36bc5ea | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 270 | ProcessKDP::DoLaunch (Module *exe_module, |
| 271 | const ProcessLaunchInfo &launch_info) |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 272 | { |
| 273 | Error error; |
| 274 | error.SetErrorString ("launching not supported in kdp-remote plug-in"); |
| 275 | return error; |
| 276 | } |
| 277 | |
| 278 | |
| 279 | Error |
| 280 | ProcessKDP::DoAttachToProcessWithID (lldb::pid_t attach_pid) |
| 281 | { |
| 282 | Error error; |
| 283 | error.SetErrorString ("attach to process by ID is not suppported in kdp remote debugging"); |
| 284 | return error; |
| 285 | } |
| 286 | |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 287 | Error |
Han Ming Ong | d1040dd | 2012-02-25 01:07:38 +0000 | [diff] [blame] | 288 | ProcessKDP::DoAttachToProcessWithID (lldb::pid_t attach_pid, const ProcessAttachInfo &attach_info) |
| 289 | { |
| 290 | Error error; |
| 291 | error.SetErrorString ("attach to process by ID is not suppported in kdp remote debugging"); |
| 292 | return error; |
| 293 | } |
| 294 | |
| 295 | Error |
| 296 | ProcessKDP::DoAttachToProcessWithName (const char *process_name, bool wait_for_launch, const ProcessAttachInfo &attach_info) |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 297 | { |
| 298 | Error error; |
| 299 | error.SetErrorString ("attach to process by name is not suppported in kdp remote debugging"); |
| 300 | return error; |
| 301 | } |
| 302 | |
| 303 | |
| 304 | void |
| 305 | ProcessKDP::DidAttach () |
| 306 | { |
| 307 | LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_PROCESS)); |
| 308 | if (log) |
Johnny Chen | 01df057 | 2011-10-11 21:17:10 +0000 | [diff] [blame] | 309 | log->Printf ("ProcessKDP::DidAttach()"); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 310 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
| 311 | { |
| 312 | // TODO: figure out the register context that we will use |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | Error |
| 317 | ProcessKDP::WillResume () |
| 318 | { |
| 319 | return Error(); |
| 320 | } |
| 321 | |
| 322 | Error |
| 323 | ProcessKDP::DoResume () |
| 324 | { |
| 325 | Error error; |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 326 | LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_PROCESS)); |
| 327 | // Only start the async thread if we try to do any process control |
| 328 | if (!IS_VALID_LLDB_HOST_THREAD(m_async_thread)) |
| 329 | StartAsyncThread (); |
| 330 | |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 331 | bool resume = false; |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 332 | |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 333 | // With KDP there is only one thread we can tell what to do |
| 334 | ThreadSP kernel_thread_sp (GetKernelThread(m_thread_list, m_thread_list)); |
| 335 | if (kernel_thread_sp) |
Greg Clayton | ea63601 | 2012-09-21 01:55:30 +0000 | [diff] [blame] | 336 | { |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 337 | const StateType thread_resume_state = kernel_thread_sp->GetTemporaryResumeState(); |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 338 | switch (thread_resume_state) |
Greg Clayton | ea63601 | 2012-09-21 01:55:30 +0000 | [diff] [blame] | 339 | { |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 340 | case eStateSuspended: |
| 341 | // Nothing to do here when a thread will stay suspended |
| 342 | // we just leave the CPU mask bit set to zero for the thread |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 343 | puts("REMOVE THIS: ProcessKDP::DoResume () -- thread suspended"); |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 344 | break; |
| 345 | |
| 346 | case eStateStepping: |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 347 | puts("REMOVE THIS: ProcessKDP::DoResume () -- thread stepping"); |
| 348 | kernel_thread_sp->GetRegisterContext()->HardwareSingleStep (true); |
| 349 | resume = true; |
| 350 | break; |
| 351 | |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 352 | case eStateRunning: |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 353 | puts("REMOVE THIS: ProcessKDP::DoResume () -- thread running"); |
| 354 | kernel_thread_sp->GetRegisterContext()->HardwareSingleStep (false); |
| 355 | resume = true; |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 356 | break; |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 357 | |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 358 | default: |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 359 | // The only valid thread resume states are listed above |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 360 | assert (!"invalid thread resume state"); |
| 361 | break; |
Greg Clayton | ea63601 | 2012-09-21 01:55:30 +0000 | [diff] [blame] | 362 | } |
| 363 | } |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 364 | |
| 365 | if (resume) |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 366 | { |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 367 | if (log) |
| 368 | log->Printf ("ProcessKDP::DoResume () sending resume"); |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 369 | |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 370 | if (m_comm.SendRequestResume ()) |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 371 | { |
| 372 | m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncContinue); |
| 373 | SetPrivateState(eStateRunning); |
| 374 | } |
| 375 | else |
| 376 | error.SetErrorString ("KDP resume failed"); |
| 377 | } |
Greg Clayton | ea63601 | 2012-09-21 01:55:30 +0000 | [diff] [blame] | 378 | else |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 379 | { |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 380 | error.SetErrorString ("kernel thread is suspended"); |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 383 | return error; |
| 384 | } |
| 385 | |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 386 | lldb::ThreadSP |
| 387 | ProcessKDP::GetKernelThread(ThreadList &old_thread_list, ThreadList &new_thread_list) |
| 388 | { |
| 389 | // KDP only tells us about one thread/core. Any other threads will usually |
| 390 | // be the ones that are read from memory by the OS plug-ins. |
| 391 | const lldb::tid_t kernel_tid = 1; |
| 392 | ThreadSP thread_sp (old_thread_list.FindThreadByID (kernel_tid, false)); |
| 393 | if (!thread_sp) |
| 394 | { |
| 395 | thread_sp.reset(new ThreadKDP (shared_from_this(), kernel_tid)); |
| 396 | new_thread_list.AddThread(thread_sp); |
| 397 | } |
| 398 | return thread_sp; |
| 399 | } |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
Greg Clayton | ae93235 | 2012-04-10 00:18:59 +0000 | [diff] [blame] | 404 | bool |
Greg Clayton | 37f962e | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 405 | ProcessKDP::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list) |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 406 | { |
| 407 | // locker will keep a mutex locked until it goes out of scope |
| 408 | LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_THREAD)); |
| 409 | if (log && log->GetMask().Test(KDP_LOG_VERBOSE)) |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 410 | log->Printf ("ProcessKDP::%s (pid = %llu)", __FUNCTION__, GetID()); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 411 | |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 412 | // Even though there is a CPU mask, it doesn't mean to can see each CPU |
| 413 | // indivudually, there is really only one. Lets call this thread 1. |
| 414 | GetKernelThread (old_thread_list, new_thread_list); |
| 415 | |
Greg Clayton | ae93235 | 2012-04-10 00:18:59 +0000 | [diff] [blame] | 416 | return new_thread_list.GetSize(false) > 0; |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 419 | void |
| 420 | ProcessKDP::RefreshStateAfterStop () |
| 421 | { |
| 422 | // Let all threads recover from stopping and do any clean up based |
| 423 | // on the previous thread state (if any). |
| 424 | m_thread_list.RefreshStateAfterStop(); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | Error |
| 428 | ProcessKDP::DoHalt (bool &caused_stop) |
| 429 | { |
| 430 | Error error; |
| 431 | |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 432 | if (m_comm.IsRunning()) |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 433 | { |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 434 | if (m_destroy_in_process) |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 435 | { |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 436 | // If we are attemping to destroy, we need to not return an error to |
| 437 | // Halt or DoDestroy won't get called. |
| 438 | // We are also currently running, so send a process stopped event |
| 439 | SetPrivateState (eStateStopped); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 440 | } |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 441 | else |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 442 | { |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 443 | error.SetErrorString ("KDP cannot interrupt a running kernel"); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | return error; |
| 447 | } |
| 448 | |
| 449 | Error |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 450 | ProcessKDP::DoDetach() |
| 451 | { |
| 452 | Error error; |
| 453 | LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); |
| 454 | if (log) |
| 455 | log->Printf ("ProcessKDP::DoDetach()"); |
| 456 | |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 457 | if (m_comm.IsRunning()) |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 458 | { |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 459 | // We are running and we can't interrupt a running kernel, so we need |
| 460 | // to just close the connection to the kernel and hope for the best |
| 461 | } |
| 462 | else |
| 463 | { |
| 464 | DisableAllBreakpointSites (); |
| 465 | |
| 466 | m_thread_list.DiscardThreadPlans(); |
| 467 | |
| 468 | if (m_comm.IsConnected()) |
Greg Clayton | 8d2ea28 | 2011-07-17 20:36:25 +0000 | [diff] [blame] | 469 | { |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 470 | |
| 471 | m_comm.SendRequestDisconnect(); |
| 472 | |
| 473 | size_t response_size = m_comm.Disconnect (); |
| 474 | if (log) |
| 475 | { |
| 476 | if (response_size) |
| 477 | log->PutCString ("ProcessKDP::DoDetach() detach packet sent successfully"); |
| 478 | else |
| 479 | log->PutCString ("ProcessKDP::DoDetach() detach packet send failed"); |
| 480 | } |
Greg Clayton | 8d2ea28 | 2011-07-17 20:36:25 +0000 | [diff] [blame] | 481 | } |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 482 | } |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 483 | StopAsyncThread (); |
Greg Clayton | db9d6f4 | 2012-01-31 04:56:17 +0000 | [diff] [blame] | 484 | m_comm.Clear(); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 485 | |
| 486 | SetPrivateState (eStateDetached); |
| 487 | ResumePrivateStateThread(); |
| 488 | |
| 489 | //KillDebugserverProcess (); |
| 490 | return error; |
| 491 | } |
| 492 | |
| 493 | Error |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 494 | ProcessKDP::WillDestroy () |
| 495 | { |
| 496 | Error error; |
| 497 | m_destroy_in_process = true; |
| 498 | return error; |
| 499 | } |
| 500 | |
| 501 | Error |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 502 | ProcessKDP::DoDestroy () |
| 503 | { |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 504 | // For KDP there really is no difference between destroy and detach |
| 505 | return DoDetach(); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | //------------------------------------------------------------------ |
| 509 | // Process Queries |
| 510 | //------------------------------------------------------------------ |
| 511 | |
| 512 | bool |
| 513 | ProcessKDP::IsAlive () |
| 514 | { |
| 515 | return m_comm.IsConnected() && m_private_state.GetValue() != eStateExited; |
| 516 | } |
| 517 | |
| 518 | //------------------------------------------------------------------ |
| 519 | // Process Memory |
| 520 | //------------------------------------------------------------------ |
| 521 | size_t |
| 522 | ProcessKDP::DoReadMemory (addr_t addr, void *buf, size_t size, Error &error) |
| 523 | { |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 524 | if (m_comm.IsConnected()) |
| 525 | return m_comm.SendRequestReadMemory (addr, buf, size, error); |
| 526 | error.SetErrorString ("not connected"); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | size_t |
| 531 | ProcessKDP::DoWriteMemory (addr_t addr, const void *buf, size_t size, Error &error) |
| 532 | { |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 533 | if (m_comm.IsConnected()) |
| 534 | return m_comm.SendRequestWriteMemory (addr, buf, size, error); |
| 535 | error.SetErrorString ("not connected"); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 536 | return 0; |
| 537 | } |
| 538 | |
| 539 | lldb::addr_t |
| 540 | ProcessKDP::DoAllocateMemory (size_t size, uint32_t permissions, Error &error) |
| 541 | { |
| 542 | error.SetErrorString ("memory allocation not suppported in kdp remote debugging"); |
| 543 | return LLDB_INVALID_ADDRESS; |
| 544 | } |
| 545 | |
| 546 | Error |
| 547 | ProcessKDP::DoDeallocateMemory (lldb::addr_t addr) |
| 548 | { |
| 549 | Error error; |
| 550 | error.SetErrorString ("memory deallocation not suppported in kdp remote debugging"); |
| 551 | return error; |
| 552 | } |
| 553 | |
| 554 | Error |
| 555 | ProcessKDP::EnableBreakpoint (BreakpointSite *bp_site) |
| 556 | { |
Greg Clayton | 234981a | 2011-07-20 03:41:06 +0000 | [diff] [blame] | 557 | if (m_comm.LocalBreakpointsAreSupported ()) |
| 558 | { |
| 559 | Error error; |
Greg Clayton | 7b13922 | 2011-07-21 01:12:01 +0000 | [diff] [blame] | 560 | if (!bp_site->IsEnabled()) |
| 561 | { |
| 562 | if (m_comm.SendRequestBreakpoint(true, bp_site->GetLoadAddress())) |
| 563 | { |
| 564 | bp_site->SetEnabled(true); |
| 565 | bp_site->SetType (BreakpointSite::eExternal); |
| 566 | } |
| 567 | else |
| 568 | { |
| 569 | error.SetErrorString ("KDP set breakpoint failed"); |
| 570 | } |
| 571 | } |
Greg Clayton | 234981a | 2011-07-20 03:41:06 +0000 | [diff] [blame] | 572 | return error; |
| 573 | } |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 574 | return EnableSoftwareBreakpoint (bp_site); |
| 575 | } |
| 576 | |
| 577 | Error |
| 578 | ProcessKDP::DisableBreakpoint (BreakpointSite *bp_site) |
| 579 | { |
Greg Clayton | 234981a | 2011-07-20 03:41:06 +0000 | [diff] [blame] | 580 | if (m_comm.LocalBreakpointsAreSupported ()) |
| 581 | { |
| 582 | Error error; |
Greg Clayton | 7b13922 | 2011-07-21 01:12:01 +0000 | [diff] [blame] | 583 | if (bp_site->IsEnabled()) |
| 584 | { |
| 585 | BreakpointSite::Type bp_type = bp_site->GetType(); |
| 586 | if (bp_type == BreakpointSite::eExternal) |
| 587 | { |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 588 | if (m_destroy_in_process && m_comm.IsRunning()) |
| 589 | { |
| 590 | // We are trying to destroy our connection and we are running |
Greg Clayton | 7b13922 | 2011-07-21 01:12:01 +0000 | [diff] [blame] | 591 | bp_site->SetEnabled(false); |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 592 | } |
Greg Clayton | 7b13922 | 2011-07-21 01:12:01 +0000 | [diff] [blame] | 593 | else |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 594 | { |
| 595 | if (m_comm.SendRequestBreakpoint(false, bp_site->GetLoadAddress())) |
| 596 | bp_site->SetEnabled(false); |
| 597 | else |
| 598 | error.SetErrorString ("KDP remove breakpoint failed"); |
| 599 | } |
Greg Clayton | 7b13922 | 2011-07-21 01:12:01 +0000 | [diff] [blame] | 600 | } |
| 601 | else |
| 602 | { |
| 603 | error = DisableSoftwareBreakpoint (bp_site); |
| 604 | } |
| 605 | } |
Greg Clayton | 234981a | 2011-07-20 03:41:06 +0000 | [diff] [blame] | 606 | return error; |
| 607 | } |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 608 | return DisableSoftwareBreakpoint (bp_site); |
| 609 | } |
| 610 | |
| 611 | Error |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 612 | ProcessKDP::EnableWatchpoint (Watchpoint *wp) |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 613 | { |
| 614 | Error error; |
| 615 | error.SetErrorString ("watchpoints are not suppported in kdp remote debugging"); |
| 616 | return error; |
| 617 | } |
| 618 | |
| 619 | Error |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 620 | ProcessKDP::DisableWatchpoint (Watchpoint *wp) |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 621 | { |
| 622 | Error error; |
| 623 | error.SetErrorString ("watchpoints are not suppported in kdp remote debugging"); |
| 624 | return error; |
| 625 | } |
| 626 | |
| 627 | void |
| 628 | ProcessKDP::Clear() |
| 629 | { |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 630 | m_thread_list.Clear(); |
| 631 | } |
| 632 | |
| 633 | Error |
| 634 | ProcessKDP::DoSignal (int signo) |
| 635 | { |
| 636 | Error error; |
| 637 | error.SetErrorString ("sending signals is not suppported in kdp remote debugging"); |
| 638 | return error; |
| 639 | } |
| 640 | |
| 641 | void |
| 642 | ProcessKDP::Initialize() |
| 643 | { |
| 644 | static bool g_initialized = false; |
| 645 | |
| 646 | if (g_initialized == false) |
| 647 | { |
| 648 | g_initialized = true; |
| 649 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 650 | GetPluginDescriptionStatic(), |
| 651 | CreateInstance); |
| 652 | |
| 653 | Log::Callbacks log_callbacks = { |
| 654 | ProcessKDPLog::DisableLog, |
| 655 | ProcessKDPLog::EnableLog, |
| 656 | ProcessKDPLog::ListLogCategories |
| 657 | }; |
| 658 | |
| 659 | Log::RegisterLogChannel (ProcessKDP::GetPluginNameStatic(), log_callbacks); |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | bool |
| 664 | ProcessKDP::StartAsyncThread () |
| 665 | { |
| 666 | LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); |
| 667 | |
| 668 | if (log) |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 669 | log->Printf ("ProcessKDP::StartAsyncThread ()"); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 670 | |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 671 | if (IS_VALID_LLDB_HOST_THREAD(m_async_thread)) |
| 672 | return true; |
| 673 | |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 674 | m_async_thread = Host::ThreadCreate ("<lldb.process.kdp-remote.async>", ProcessKDP::AsyncThread, this, NULL); |
| 675 | return IS_VALID_LLDB_HOST_THREAD(m_async_thread); |
| 676 | } |
| 677 | |
| 678 | void |
| 679 | ProcessKDP::StopAsyncThread () |
| 680 | { |
| 681 | LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); |
| 682 | |
| 683 | if (log) |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 684 | log->Printf ("ProcessKDP::StopAsyncThread ()"); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 685 | |
| 686 | m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncThreadShouldExit); |
| 687 | |
| 688 | // Stop the stdio thread |
| 689 | if (IS_VALID_LLDB_HOST_THREAD(m_async_thread)) |
| 690 | { |
| 691 | Host::ThreadJoin (m_async_thread, NULL, NULL); |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 692 | m_async_thread = LLDB_INVALID_HOST_THREAD; |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | |
| 696 | |
| 697 | void * |
| 698 | ProcessKDP::AsyncThread (void *arg) |
| 699 | { |
| 700 | ProcessKDP *process = (ProcessKDP*) arg; |
| 701 | |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 702 | const lldb::pid_t pid = process->GetID(); |
| 703 | |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 704 | LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_PROCESS)); |
| 705 | if (log) |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 706 | log->Printf ("ProcessKDP::AsyncThread (arg = %p, pid = %llu) thread starting...", arg, pid); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 707 | |
| 708 | Listener listener ("ProcessKDP::AsyncThread"); |
| 709 | EventSP event_sp; |
| 710 | const uint32_t desired_event_mask = eBroadcastBitAsyncContinue | |
| 711 | eBroadcastBitAsyncThreadShouldExit; |
| 712 | |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 713 | |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 714 | if (listener.StartListeningForEvents (&process->m_async_broadcaster, desired_event_mask) == desired_event_mask) |
| 715 | { |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 716 | bool done = false; |
| 717 | while (!done) |
| 718 | { |
| 719 | if (log) |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 720 | log->Printf ("ProcessKDP::AsyncThread (pid = %llu) listener.WaitForEvent (NULL, event_sp)...", |
| 721 | pid); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 722 | if (listener.WaitForEvent (NULL, event_sp)) |
| 723 | { |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 724 | uint32_t event_type = event_sp->GetType(); |
| 725 | if (log) |
| 726 | log->Printf ("ProcessKDP::AsyncThread (pid = %llu) Got an event of type: %d...", |
| 727 | pid, |
| 728 | event_type); |
| 729 | |
| 730 | // When we are running, poll for 1 second to try and get an exception |
| 731 | // to indicate the process has stopped. If we don't get one, check to |
| 732 | // make sure no one asked us to exit |
| 733 | bool is_running = false; |
| 734 | DataExtractor exc_reply_packet; |
| 735 | do |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 736 | { |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 737 | switch (event_type) |
| 738 | { |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 739 | case eBroadcastBitAsyncContinue: |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 740 | { |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 741 | is_running = true; |
| 742 | if (process->m_comm.WaitForPacketWithTimeoutMicroSeconds (exc_reply_packet, 1 * USEC_PER_SEC)) |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 743 | { |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 744 | ThreadSP thread_sp (process->GetKernelThread(process->GetThreadList(), process->GetThreadList())); |
| 745 | thread_sp->GetRegisterContext()->InvalidateAllRegisters(); |
| 746 | static_cast<ThreadKDP *>(thread_sp.get())->SetStopInfoFrom_KDP_EXCEPTION (exc_reply_packet); |
| 747 | |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 748 | // TODO: parse the stop reply packet |
Greg Clayton | 3acaa92 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 749 | is_running = false; |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 750 | process->SetPrivateState(eStateStopped); |
| 751 | } |
| 752 | else |
| 753 | { |
| 754 | // Check to see if we are supposed to exit. There is no way to |
| 755 | // interrupt a running kernel, so all we can do is wait for an |
| 756 | // exception or detach... |
| 757 | if (listener.GetNextEvent(event_sp)) |
| 758 | { |
| 759 | // We got an event, go through the loop again |
| 760 | event_type = event_sp->GetType(); |
| 761 | } |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 762 | } |
| 763 | } |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 764 | break; |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 765 | |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 766 | case eBroadcastBitAsyncThreadShouldExit: |
| 767 | if (log) |
| 768 | log->Printf ("ProcessKDP::AsyncThread (pid = %llu) got eBroadcastBitAsyncThreadShouldExit...", |
| 769 | pid); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 770 | done = true; |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 771 | is_running = false; |
| 772 | break; |
| 773 | |
| 774 | default: |
| 775 | if (log) |
| 776 | log->Printf ("ProcessKDP::AsyncThread (pid = %llu) got unknown event 0x%8.8x", |
| 777 | pid, |
| 778 | event_type); |
| 779 | done = true; |
| 780 | is_running = false; |
| 781 | break; |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 782 | } |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 783 | } while (is_running); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 784 | } |
| 785 | else |
| 786 | { |
| 787 | if (log) |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 788 | log->Printf ("ProcessKDP::AsyncThread (pid = %llu) listener.WaitForEvent (NULL, event_sp) => false", |
| 789 | pid); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 790 | done = true; |
| 791 | } |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | if (log) |
Greg Clayton | e76f8c4 | 2012-09-21 16:31:20 +0000 | [diff] [blame] | 796 | log->Printf ("ProcessKDP::AsyncThread (arg = %p, pid = %llu) thread exiting...", |
| 797 | arg, |
| 798 | pid); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 799 | |
| 800 | process->m_async_thread = LLDB_INVALID_HOST_THREAD; |
| 801 | return NULL; |
| 802 | } |
| 803 | |
| 804 | |