Alexander Shaposhnikov | 696bd63 | 2016-11-26 05:23:44 +0000 | [diff] [blame] | 1 | //===-- DebuggerThread.cpp --------------------------------------*- C++ -*-===// |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "DebuggerThread.h" |
Zachary Turner | dcd8037 | 2014-11-11 00:00:14 +0000 | [diff] [blame] | 10 | #include "ExceptionRecord.h" |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 11 | #include "IDebugDelegate.h" |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 12 | |
Zachary Turner | a32d2ce | 2014-11-12 19:31:56 +0000 | [diff] [blame] | 13 | #include "lldb/Core/ModuleSpec.h" |
Pavel Labath | e7404d9 | 2019-02-04 15:03:06 +0000 | [diff] [blame] | 14 | #include "lldb/Host/ProcessLaunchInfo.h" |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 15 | #include "lldb/Host/ThreadLauncher.h" |
| 16 | #include "lldb/Host/windows/HostProcessWindows.h" |
| 17 | #include "lldb/Host/windows/HostThreadWindows.h" |
| 18 | #include "lldb/Host/windows/ProcessLauncherWindows.h" |
Zachary Turner | c62733b | 2015-05-20 18:31:17 +0000 | [diff] [blame] | 19 | #include "lldb/Target/Process.h" |
Zachary Turner | 5713a05 | 2017-03-22 18:40:07 +0000 | [diff] [blame] | 20 | #include "lldb/Utility/FileSpec.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 21 | #include "lldb/Utility/Log.h" |
Raphael Isemann | 7fae493 | 2018-08-30 17:51:10 +0000 | [diff] [blame] | 22 | #include "lldb/Utility/Predicate.h" |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 23 | #include "lldb/Utility/Status.h" |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 24 | |
Adrian McCarthy | 18a9135d | 2015-10-28 18:21:45 +0000 | [diff] [blame] | 25 | #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h" |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 26 | |
Zachary Turner | a32d2ce | 2014-11-12 19:31:56 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/STLExtras.h" |
Zachary Turner | 190fadc | 2016-03-22 17:58:09 +0000 | [diff] [blame] | 28 | #include "llvm/Support/ConvertUTF.h" |
Zachary Turner | ed96be9 | 2017-03-04 01:31:06 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Threading.h" |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 30 | #include "llvm/Support/raw_ostream.h" |
| 31 | |
Aaron Smith | 5146a9e | 2019-08-13 22:18:01 +0000 | [diff] [blame] | 32 | #ifndef STATUS_WX86_BREAKPOINT |
| 33 | #define STATUS_WX86_BREAKPOINT 0x4000001FL // For WOW64 |
| 34 | #endif |
| 35 | |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 36 | using namespace lldb; |
| 37 | using namespace lldb_private; |
| 38 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 39 | namespace { |
| 40 | struct DebugLaunchContext { |
| 41 | DebugLaunchContext(DebuggerThread *thread, |
| 42 | const ProcessLaunchInfo &launch_info) |
| 43 | : m_thread(thread), m_launch_info(launch_info) {} |
| 44 | DebuggerThread *m_thread; |
| 45 | ProcessLaunchInfo m_launch_info; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 46 | }; |
Zachary Turner | c62733b | 2015-05-20 18:31:17 +0000 | [diff] [blame] | 47 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 48 | struct DebugAttachContext { |
| 49 | DebugAttachContext(DebuggerThread *thread, lldb::pid_t pid, |
| 50 | const ProcessAttachInfo &attach_info) |
| 51 | : m_thread(thread), m_pid(pid), m_attach_info(attach_info) {} |
| 52 | DebuggerThread *m_thread; |
| 53 | lldb::pid_t m_pid; |
| 54 | ProcessAttachInfo m_attach_info; |
Zachary Turner | c62733b | 2015-05-20 18:31:17 +0000 | [diff] [blame] | 55 | }; |
Aaron Smith | e303790 | 2018-10-10 18:30:32 +0000 | [diff] [blame] | 56 | } // namespace |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 57 | |
| 58 | DebuggerThread::DebuggerThread(DebugDelegateSP debug_delegate) |
Zachary Turner | 5a8ad459 | 2016-10-05 17:07:34 +0000 | [diff] [blame] | 59 | : m_debug_delegate(debug_delegate), m_pid_to_detach(0), |
| 60 | m_is_shutting_down(false) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | m_debugging_ended_event = ::CreateEvent(nullptr, TRUE, FALSE, nullptr); |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | DebuggerThread::~DebuggerThread() { ::CloseHandle(m_debugging_ended_event); } |
| 65 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 66 | Status DebuggerThread::DebugLaunch(const ProcessLaunchInfo &launch_info) { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 67 | Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); |
| 68 | LLDB_LOG(log, "launching '{0}'", launch_info.GetExecutableFile().GetPath()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 69 | |
Stella Stamenova | 631b5f7d | 2019-07-09 18:10:36 +0000 | [diff] [blame] | 70 | Status result; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 71 | DebugLaunchContext *context = new DebugLaunchContext(this, launch_info); |
Stella Stamenova | 631b5f7d | 2019-07-09 18:10:36 +0000 | [diff] [blame] | 72 | |
| 73 | llvm::Expected<HostThread> slave_thread = ThreadLauncher::LaunchThread( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | "lldb.plugin.process-windows.slave[?]", DebuggerThreadLaunchRoutine, |
Stella Stamenova | 631b5f7d | 2019-07-09 18:10:36 +0000 | [diff] [blame] | 75 | context); |
| 76 | if (!slave_thread) { |
| 77 | result = Status(slave_thread.takeError()); |
| 78 | LLDB_LOG(log, "couldn't launch debugger thread. {0}", result); |
| 79 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | |
Stella Stamenova | 631b5f7d | 2019-07-09 18:10:36 +0000 | [diff] [blame] | 81 | return result; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 84 | Status DebuggerThread::DebugAttach(lldb::pid_t pid, |
| 85 | const ProcessAttachInfo &attach_info) { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 86 | Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); |
| 87 | LLDB_LOG(log, "attaching to '{0}'", pid); |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 88 | |
Stella Stamenova | 631b5f7d | 2019-07-09 18:10:36 +0000 | [diff] [blame] | 89 | Status result; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | DebugAttachContext *context = new DebugAttachContext(this, pid, attach_info); |
Stella Stamenova | 631b5f7d | 2019-07-09 18:10:36 +0000 | [diff] [blame] | 91 | |
| 92 | llvm::Expected<HostThread> slave_thread = ThreadLauncher::LaunchThread( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 93 | "lldb.plugin.process-windows.slave[?]", DebuggerThreadAttachRoutine, |
Stella Stamenova | 631b5f7d | 2019-07-09 18:10:36 +0000 | [diff] [blame] | 94 | context); |
| 95 | if (!slave_thread) { |
| 96 | result = Status(slave_thread.takeError()); |
| 97 | LLDB_LOG(log, "couldn't attach to process '{0}'. {1}", pid, result); |
| 98 | } |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 99 | |
Stella Stamenova | 631b5f7d | 2019-07-09 18:10:36 +0000 | [diff] [blame] | 100 | return result; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 103 | lldb::thread_result_t DebuggerThread::DebuggerThreadLaunchRoutine(void *data) { |
| 104 | DebugLaunchContext *context = static_cast<DebugLaunchContext *>(data); |
| 105 | lldb::thread_result_t result = |
| 106 | context->m_thread->DebuggerThreadLaunchRoutine(context->m_launch_info); |
| 107 | delete context; |
| 108 | return result; |
Zachary Turner | c62733b | 2015-05-20 18:31:17 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 111 | lldb::thread_result_t DebuggerThread::DebuggerThreadAttachRoutine(void *data) { |
| 112 | DebugAttachContext *context = static_cast<DebugAttachContext *>(data); |
| 113 | lldb::thread_result_t result = context->m_thread->DebuggerThreadAttachRoutine( |
| 114 | context->m_pid, context->m_attach_info); |
| 115 | delete context; |
| 116 | return result; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 119 | lldb::thread_result_t DebuggerThread::DebuggerThreadLaunchRoutine( |
| 120 | const ProcessLaunchInfo &launch_info) { |
| 121 | // Grab a shared_ptr reference to this so that we know it won't get deleted |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 122 | // until after the thread routine has exited. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 123 | std::shared_ptr<DebuggerThread> this_ref(shared_from_this()); |
Zachary Turner | c62733b | 2015-05-20 18:31:17 +0000 | [diff] [blame] | 124 | |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 125 | Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); |
| 126 | LLDB_LOG(log, "preparing to launch '{0}' on background thread.", |
| 127 | launch_info.GetExecutableFile().GetPath()); |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 128 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 129 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 130 | ProcessLauncherWindows launcher; |
| 131 | HostProcess process(launcher.LaunchProcess(launch_info, error)); |
| 132 | // If we couldn't create the process, notify waiters immediately. Otherwise |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 133 | // enter the debug loop and wait until we get the create process debug |
| 134 | // notification. Note that if the process was created successfully, we can |
| 135 | // throw away the process handle we got from CreateProcess because Windows |
| 136 | // will give us another (potentially more useful?) handle when it sends us |
| 137 | // the CREATE_PROCESS_DEBUG_EVENT. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 138 | if (error.Success()) |
Zachary Turner | c62733b | 2015-05-20 18:31:17 +0000 | [diff] [blame] | 139 | DebugLoop(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 140 | else |
| 141 | m_debug_delegate->OnDebuggerError(error, 0); |
Zachary Turner | c62733b | 2015-05-20 18:31:17 +0000 | [diff] [blame] | 142 | |
Konrad Kleine | 8520064 | 2019-05-23 15:17:39 +0000 | [diff] [blame] | 143 | return {}; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | lldb::thread_result_t DebuggerThread::DebuggerThreadAttachRoutine( |
| 147 | lldb::pid_t pid, const ProcessAttachInfo &attach_info) { |
| 148 | // Grab a shared_ptr reference to this so that we know it won't get deleted |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 149 | // until after the thread routine has exited. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 150 | std::shared_ptr<DebuggerThread> this_ref(shared_from_this()); |
| 151 | |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 152 | Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); |
| 153 | LLDB_LOG(log, "preparing to attach to process '{0}' on background thread.", |
| 154 | pid); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 155 | |
| 156 | if (!DebugActiveProcess((DWORD)pid)) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 157 | Status error(::GetLastError(), eErrorTypeWin32); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 158 | m_debug_delegate->OnDebuggerError(error, 0); |
Konrad Kleine | 8520064 | 2019-05-23 15:17:39 +0000 | [diff] [blame] | 159 | return {}; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 162 | // The attach was successful, enter the debug loop. From here on out, this |
| 163 | // is no different than a create process operation, so all the same comments |
| 164 | // in DebugLaunch should apply from this point out. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 165 | DebugLoop(); |
| 166 | |
Konrad Kleine | 8520064 | 2019-05-23 15:17:39 +0000 | [diff] [blame] | 167 | return {}; |
Zachary Turner | c62733b | 2015-05-20 18:31:17 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 170 | Status DebuggerThread::StopDebugging(bool terminate) { |
| 171 | Status error; |
Zachary Turner | c6a6653 | 2014-12-03 22:04:18 +0000 | [diff] [blame] | 172 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 173 | lldb::pid_t pid = m_process.GetProcessId(); |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 174 | |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 175 | Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); |
| 176 | LLDB_LOG(log, "terminate = {0}, inferior={1}.", terminate, pid); |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 177 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 178 | // Set m_is_shutting_down to true if it was false. Return if it was already |
| 179 | // true. |
| 180 | bool expected = false; |
| 181 | if (!m_is_shutting_down.compare_exchange_strong(expected, true)) |
Zachary Turner | c6a6653 | 2014-12-03 22:04:18 +0000 | [diff] [blame] | 182 | return error; |
Zachary Turner | c6a6653 | 2014-12-03 22:04:18 +0000 | [diff] [blame] | 183 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 184 | // Make a copy of the process, since the termination sequence will reset |
| 185 | // DebuggerThread's internal copy and it needs to remain open for the Wait |
| 186 | // operation. |
| 187 | HostProcess process_copy = m_process; |
| 188 | lldb::process_t handle = m_process.GetNativeProcess().GetSystemHandle(); |
Zachary Turner | c6a6653 | 2014-12-03 22:04:18 +0000 | [diff] [blame] | 189 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 190 | if (terminate) { |
Stella Stamenova | 9d6fabf | 2018-06-13 19:02:44 +0000 | [diff] [blame] | 191 | if (handle != nullptr && handle != LLDB_INVALID_PROCESS) { |
| 192 | // Initiate the termination before continuing the exception, so that the |
| 193 | // next debug event we get is the exit process event, and not some other |
| 194 | // event. |
| 195 | BOOL terminate_suceeded = TerminateProcess(handle, 0); |
| 196 | LLDB_LOG(log, |
| 197 | "calling TerminateProcess({0}, 0) (inferior={1}), success={2}", |
| 198 | handle, pid, terminate_suceeded); |
| 199 | } else { |
| 200 | LLDB_LOG(log, |
Aaron Smith | e303790 | 2018-10-10 18:30:32 +0000 | [diff] [blame] | 201 | "NOT calling TerminateProcess because the inferior is not valid " |
| 202 | "({0}, 0) (inferior={1})", |
Stella Stamenova | 9d6fabf | 2018-06-13 19:02:44 +0000 | [diff] [blame] | 203 | handle, pid); |
| 204 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 205 | } |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 206 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 207 | // If we're stuck waiting for an exception to continue (e.g. the user is at a |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 208 | // breakpoint messing around in the debugger), continue it now. But only |
| 209 | // AFTER calling TerminateProcess to make sure that the very next call to |
| 210 | // WaitForDebugEvent is an exit process event. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 211 | if (m_active_exception.get()) { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 212 | LLDB_LOG(log, "masking active exception"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 213 | ContinueAsyncException(ExceptionResult::MaskException); |
| 214 | } |
| 215 | |
| 216 | if (!terminate) { |
| 217 | // Indicate that we want to detach. |
| 218 | m_pid_to_detach = GetProcess().GetProcessId(); |
| 219 | |
| 220 | // Force a fresh break so that the detach can happen from the debugger |
| 221 | // thread. |
| 222 | if (!::DebugBreakProcess( |
| 223 | GetProcess().GetNativeProcess().GetSystemHandle())) { |
| 224 | error.SetError(::GetLastError(), eErrorTypeWin32); |
Zachary Turner | c6a6653 | 2014-12-03 22:04:18 +0000 | [diff] [blame] | 225 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 228 | LLDB_LOG(log, "waiting for detach from process {0} to complete.", pid); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 229 | |
| 230 | DWORD wait_result = WaitForSingleObject(m_debugging_ended_event, 5000); |
| 231 | if (wait_result != WAIT_OBJECT_0) { |
| 232 | error.SetError(GetLastError(), eErrorTypeWin32); |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 233 | LLDB_LOG(log, "error: WaitForSingleObject({0}, 5000) returned {1}", |
| 234 | m_debugging_ended_event, wait_result); |
| 235 | } else |
| 236 | LLDB_LOG(log, "detach from process {0} completed successfully.", pid); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 237 | |
| 238 | if (!error.Success()) { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 239 | LLDB_LOG(log, "encountered an error while trying to stop process {0}. {1}", |
| 240 | pid, error); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 241 | } |
| 242 | return error; |
Zachary Turner | dcd8037 | 2014-11-11 00:00:14 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 245 | void DebuggerThread::ContinueAsyncException(ExceptionResult result) { |
| 246 | if (!m_active_exception.get()) |
| 247 | return; |
Zachary Turner | dcd8037 | 2014-11-11 00:00:14 +0000 | [diff] [blame] | 248 | |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 249 | Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS | |
| 250 | WINDOWS_LOG_EXCEPTION); |
| 251 | LLDB_LOG(log, "broadcasting for inferior process {0}.", |
| 252 | m_process.GetProcessId()); |
Zachary Turner | 6c3c0ed | 2015-10-02 22:47:04 +0000 | [diff] [blame] | 253 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 254 | m_active_exception.reset(); |
| 255 | m_exception_pred.SetValue(result, eBroadcastAlways); |
| 256 | } |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 257 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 258 | void DebuggerThread::FreeProcessHandles() { |
| 259 | m_process = HostProcess(); |
| 260 | m_main_thread = HostThread(); |
| 261 | if (m_image_file) { |
| 262 | ::CloseHandle(m_image_file); |
| 263 | m_image_file = nullptr; |
| 264 | } |
| 265 | } |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 266 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 267 | void DebuggerThread::DebugLoop() { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 268 | Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT); |
Zachary Turner | 5a8ad459 | 2016-10-05 17:07:34 +0000 | [diff] [blame] | 269 | DEBUG_EVENT dbe = {}; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 270 | bool should_debug = true; |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 271 | LLDB_LOGV(log, "Entering WaitForDebugEvent loop"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 272 | while (should_debug) { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 273 | LLDB_LOGV(log, "Calling WaitForDebugEvent"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 274 | BOOL wait_result = WaitForDebugEvent(&dbe, INFINITE); |
| 275 | if (wait_result) { |
| 276 | DWORD continue_status = DBG_CONTINUE; |
| 277 | switch (dbe.dwDebugEventCode) { |
Aaron Smith | e303790 | 2018-10-10 18:30:32 +0000 | [diff] [blame] | 278 | default: |
| 279 | llvm_unreachable("Unhandle debug event code!"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 280 | case EXCEPTION_DEBUG_EVENT: { |
| 281 | ExceptionResult status = |
| 282 | HandleExceptionEvent(dbe.u.Exception, dbe.dwThreadId); |
Adrian McCarthy | a59a721 | 2015-06-19 18:26:53 +0000 | [diff] [blame] | 283 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 284 | if (status == ExceptionResult::MaskException) |
| 285 | continue_status = DBG_CONTINUE; |
| 286 | else if (status == ExceptionResult::SendToApplication) |
| 287 | continue_status = DBG_EXCEPTION_NOT_HANDLED; |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 288 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 289 | break; |
| 290 | } |
| 291 | case CREATE_THREAD_DEBUG_EVENT: |
| 292 | continue_status = |
| 293 | HandleCreateThreadEvent(dbe.u.CreateThread, dbe.dwThreadId); |
| 294 | break; |
| 295 | case CREATE_PROCESS_DEBUG_EVENT: |
| 296 | continue_status = |
| 297 | HandleCreateProcessEvent(dbe.u.CreateProcessInfo, dbe.dwThreadId); |
| 298 | break; |
| 299 | case EXIT_THREAD_DEBUG_EVENT: |
| 300 | continue_status = |
| 301 | HandleExitThreadEvent(dbe.u.ExitThread, dbe.dwThreadId); |
| 302 | break; |
| 303 | case EXIT_PROCESS_DEBUG_EVENT: |
| 304 | continue_status = |
| 305 | HandleExitProcessEvent(dbe.u.ExitProcess, dbe.dwThreadId); |
| 306 | should_debug = false; |
| 307 | break; |
| 308 | case LOAD_DLL_DEBUG_EVENT: |
| 309 | continue_status = HandleLoadDllEvent(dbe.u.LoadDll, dbe.dwThreadId); |
| 310 | break; |
| 311 | case UNLOAD_DLL_DEBUG_EVENT: |
| 312 | continue_status = HandleUnloadDllEvent(dbe.u.UnloadDll, dbe.dwThreadId); |
| 313 | break; |
| 314 | case OUTPUT_DEBUG_STRING_EVENT: |
| 315 | continue_status = HandleODSEvent(dbe.u.DebugString, dbe.dwThreadId); |
| 316 | break; |
| 317 | case RIP_EVENT: |
| 318 | continue_status = HandleRipEvent(dbe.u.RipInfo, dbe.dwThreadId); |
| 319 | if (dbe.u.RipInfo.dwType == SLE_ERROR) |
| 320 | should_debug = false; |
| 321 | break; |
| 322 | } |
| 323 | |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 324 | LLDB_LOGV(log, "calling ContinueDebugEvent({0}, {1}, {2}) on thread {3}.", |
| 325 | dbe.dwProcessId, dbe.dwThreadId, continue_status, |
| 326 | ::GetCurrentThreadId()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 327 | |
| 328 | ::ContinueDebugEvent(dbe.dwProcessId, dbe.dwThreadId, continue_status); |
| 329 | |
| 330 | if (m_detached) { |
| 331 | should_debug = false; |
| 332 | } |
| 333 | } else { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 334 | LLDB_LOG(log, "returned FALSE from WaitForDebugEvent. Error = {0}", |
| 335 | ::GetLastError()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 336 | |
| 337 | should_debug = false; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 338 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 339 | } |
| 340 | FreeProcessHandles(); |
Zachary Turner | 3c1c5b9 | 2015-05-21 19:56:26 +0000 | [diff] [blame] | 341 | |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 342 | LLDB_LOG(log, "WaitForDebugEvent loop completed, exiting."); |
Aaron Smith | e303790 | 2018-10-10 18:30:32 +0000 | [diff] [blame] | 343 | ::SetEvent(m_debugging_ended_event); |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Zachary Turner | dcd8037 | 2014-11-11 00:00:14 +0000 | [diff] [blame] | 346 | ExceptionResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 347 | DebuggerThread::HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info, |
| 348 | DWORD thread_id) { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 349 | Log *log = |
| 350 | ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_EXCEPTION); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 351 | if (m_is_shutting_down) { |
| 352 | // A breakpoint that occurs while `m_pid_to_detach` is non-zero is a magic |
| 353 | // exception that |
| 354 | // we use simply to wake up the DebuggerThread so that we can close out the |
| 355 | // debug loop. |
| 356 | if (m_pid_to_detach != 0 && |
Aaron Smith | 5146a9e | 2019-08-13 22:18:01 +0000 | [diff] [blame] | 357 | (info.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT || |
| 358 | info.ExceptionRecord.ExceptionCode == STATUS_WX86_BREAKPOINT)) { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 359 | LLDB_LOG(log, "Breakpoint exception is cue to detach from process {0:x}", |
| 360 | m_pid_to_detach.load()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 361 | ::DebugActiveProcessStop(m_pid_to_detach); |
| 362 | m_detached = true; |
Zachary Turner | 6c3c0ed | 2015-10-02 22:47:04 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 365 | // Don't perform any blocking operations while we're shutting down. That |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 366 | // will cause TerminateProcess -> WaitForSingleObject to time out. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 367 | return ExceptionResult::SendToApplication; |
| 368 | } |
Zachary Turner | c6a6653 | 2014-12-03 22:04:18 +0000 | [diff] [blame] | 369 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 370 | bool first_chance = (info.dwFirstChance != 0); |
Zachary Turner | c6a6653 | 2014-12-03 22:04:18 +0000 | [diff] [blame] | 371 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 372 | m_active_exception.reset( |
| 373 | new ExceptionRecord(info.ExceptionRecord, thread_id)); |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 374 | LLDB_LOG(log, "encountered {0} chance exception {1:x} on thread {2:x}", |
| 375 | first_chance ? "first" : "second", |
| 376 | info.ExceptionRecord.ExceptionCode, thread_id); |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 377 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 378 | ExceptionResult result = |
| 379 | m_debug_delegate->OnDebugException(first_chance, *m_active_exception); |
| 380 | m_exception_pred.SetValue(result, eBroadcastNever); |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 381 | |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 382 | LLDB_LOG(log, "waiting for ExceptionPred != BreakInDebugger"); |
Pavel Labath | 4b13033 | 2018-05-09 14:49:43 +0000 | [diff] [blame] | 383 | result = *m_exception_pred.WaitForValueNotEqualTo( |
| 384 | ExceptionResult::BreakInDebugger); |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 385 | |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 386 | LLDB_LOG(log, "got ExceptionPred = {0}", (int)m_exception_pred.GetValue()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 387 | return result; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | DWORD |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 391 | DebuggerThread::HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info, |
| 392 | DWORD thread_id) { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 393 | Log *log = |
| 394 | ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD); |
Aaron Smith | e303790 | 2018-10-10 18:30:32 +0000 | [diff] [blame] | 395 | LLDB_LOG(log, "Thread {0} spawned in process {1}", thread_id, |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 396 | m_process.GetProcessId()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 397 | HostThread thread(info.hThread); |
| 398 | thread.GetNativeThread().SetOwnsHandle(false); |
| 399 | m_debug_delegate->OnCreateThread(thread); |
| 400 | return DBG_CONTINUE; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | DWORD |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 404 | DebuggerThread::HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info, |
| 405 | DWORD thread_id) { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 406 | Log *log = |
| 407 | ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_PROCESS); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 408 | uint32_t process_id = ::GetProcessId(info.hProcess); |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 409 | |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 410 | LLDB_LOG(log, "process {0} spawned", process_id); |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 411 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 412 | std::string thread_name; |
| 413 | llvm::raw_string_ostream name_stream(thread_name); |
| 414 | name_stream << "lldb.plugin.process-windows.slave[" << process_id << "]"; |
| 415 | name_stream.flush(); |
Zachary Turner | ed96be9 | 2017-03-04 01:31:06 +0000 | [diff] [blame] | 416 | llvm::set_thread_name(thread_name); |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 417 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 418 | // info.hProcess and info.hThread are closed automatically by Windows when |
| 419 | // EXIT_PROCESS_DEBUG_EVENT is received. |
| 420 | m_process = HostProcess(info.hProcess); |
| 421 | ((HostProcessWindows &)m_process.GetNativeProcess()).SetOwnsHandle(false); |
| 422 | m_main_thread = HostThread(info.hThread); |
| 423 | m_main_thread.GetNativeThread().SetOwnsHandle(false); |
| 424 | m_image_file = info.hFile; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 425 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 426 | lldb::addr_t load_addr = reinterpret_cast<lldb::addr_t>(info.lpBaseOfImage); |
| 427 | m_debug_delegate->OnDebuggerConnected(load_addr); |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 428 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 429 | return DBG_CONTINUE; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | DWORD |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 433 | DebuggerThread::HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info, |
| 434 | DWORD thread_id) { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 435 | Log *log = |
| 436 | ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD); |
| 437 | LLDB_LOG(log, "Thread {0} exited with code {1} in process {2}", thread_id, |
| 438 | info.dwExitCode, m_process.GetProcessId()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 439 | m_debug_delegate->OnExitThread(thread_id, info.dwExitCode); |
| 440 | return DBG_CONTINUE; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | DWORD |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 444 | DebuggerThread::HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info, |
| 445 | DWORD thread_id) { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 446 | Log *log = |
| 447 | ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD); |
| 448 | LLDB_LOG(log, "process {0} exited with code {1}", m_process.GetProcessId(), |
| 449 | info.dwExitCode); |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 450 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 451 | m_debug_delegate->OnExitProcess(info.dwExitCode); |
Adrian McCarthy | 2f8e4c3 | 2015-05-18 23:24:32 +0000 | [diff] [blame] | 452 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 453 | return DBG_CONTINUE; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | DWORD |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 457 | DebuggerThread::HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, |
| 458 | DWORD thread_id) { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 459 | Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 460 | if (info.hFile == nullptr) { |
| 461 | // Not sure what this is, so just ignore it. |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 462 | LLDB_LOG(log, "Warning: Inferior {0} has a NULL file handle, returning...", |
| 463 | m_process.GetProcessId()); |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 464 | return DBG_CONTINUE; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | std::vector<wchar_t> buffer(1); |
| 468 | DWORD required_size = |
| 469 | GetFinalPathNameByHandleW(info.hFile, &buffer[0], 0, VOLUME_NAME_DOS); |
| 470 | if (required_size > 0) { |
| 471 | buffer.resize(required_size + 1); |
| 472 | required_size = GetFinalPathNameByHandleW(info.hFile, &buffer[0], |
| 473 | required_size, VOLUME_NAME_DOS); |
| 474 | std::string path_str_utf8; |
| 475 | llvm::convertWideToUTF8(buffer.data(), path_str_utf8); |
| 476 | llvm::StringRef path_str = path_str_utf8; |
| 477 | const char *path = path_str.data(); |
| 478 | if (path_str.startswith("\\\\?\\")) |
| 479 | path += 4; |
| 480 | |
Aleksandr Urakov | 54bb316 | 2018-11-02 08:47:33 +0000 | [diff] [blame] | 481 | FileSpec file_spec(path); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 482 | ModuleSpec module_spec(file_spec); |
| 483 | lldb::addr_t load_addr = reinterpret_cast<lldb::addr_t>(info.lpBaseOfDll); |
| 484 | |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 485 | LLDB_LOG(log, "Inferior {0} - DLL '{1}' loaded at address {2:x}...", |
| 486 | m_process.GetProcessId(), path, info.lpBaseOfDll); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 487 | |
| 488 | m_debug_delegate->OnLoadDll(module_spec, load_addr); |
| 489 | } else { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 490 | LLDB_LOG( |
| 491 | log, |
| 492 | "Inferior {0} - Error {1} occurred calling GetFinalPathNameByHandle", |
| 493 | m_process.GetProcessId(), ::GetLastError()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 494 | } |
| 495 | // Windows does not automatically close info.hFile, so we need to do it. |
| 496 | ::CloseHandle(info.hFile); |
| 497 | return DBG_CONTINUE; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | DWORD |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 501 | DebuggerThread::HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info, |
| 502 | DWORD thread_id) { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 503 | Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT); |
| 504 | LLDB_LOG(log, "process {0} unloading DLL at addr {1:x}.", |
| 505 | m_process.GetProcessId(), info.lpBaseOfDll); |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 506 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 507 | m_debug_delegate->OnUnloadDll( |
| 508 | reinterpret_cast<lldb::addr_t>(info.lpBaseOfDll)); |
| 509 | return DBG_CONTINUE; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | DWORD |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 513 | DebuggerThread::HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, |
| 514 | DWORD thread_id) { |
| 515 | return DBG_CONTINUE; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | DWORD |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 519 | DebuggerThread::HandleRipEvent(const RIP_INFO &info, DWORD thread_id) { |
Pavel Labath | a385d2c | 2017-02-22 10:38:02 +0000 | [diff] [blame] | 520 | Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT); |
| 521 | LLDB_LOG(log, "encountered error {0} (type={1}) in process {2} thread {3}", |
| 522 | info.dwError, info.dwType, m_process.GetProcessId(), thread_id); |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 523 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 524 | Status error(info.dwError, eErrorTypeWin32); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 525 | m_debug_delegate->OnDebuggerError(error, info.dwType); |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 526 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 527 | return DBG_CONTINUE; |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 528 | } |