Zachary Turner | 119767d | 2014-11-17 17:46:43 +0000 | [diff] [blame] | 1 | //===-- TargetThreadWindows.cpp----------------------------------*- 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 | |
Zachary Turner | 17f383d | 2014-11-20 22:47:32 +0000 | [diff] [blame^] | 10 | #include "lldb/Host/HostInfo.h" |
Zachary Turner | 119767d | 2014-11-17 17:46:43 +0000 | [diff] [blame] | 11 | #include "lldb/Host/HostNativeThreadBase.h" |
| 12 | #include "lldb/Host/windows/HostThreadWindows.h" |
| 13 | #include "lldb/Host/windows/windows.h" |
Zachary Turner | 17f383d | 2014-11-20 22:47:32 +0000 | [diff] [blame^] | 14 | #include "lldb/Target/RegisterContext.h" |
| 15 | |
| 16 | #include "TargetThreadWindows.h" |
| 17 | #include "ProcessWindows.h" |
| 18 | #include "RegisterContextWindows_x86.h" |
| 19 | #include "UnwindLLDB.h" |
Zachary Turner | 119767d | 2014-11-17 17:46:43 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace lldb; |
| 22 | using namespace lldb_private; |
| 23 | |
| 24 | TargetThreadWindows::TargetThreadWindows(ProcessWindows &process, const HostThread &thread) |
Zachary Turner | c301899 | 2014-11-17 22:42:57 +0000 | [diff] [blame] | 25 | : Thread(process, thread.GetNativeThread().GetThreadId()) |
Zachary Turner | 119767d | 2014-11-17 17:46:43 +0000 | [diff] [blame] | 26 | , m_host_thread(thread) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | TargetThreadWindows::~TargetThreadWindows() |
| 31 | { |
| 32 | DestroyThread(); |
| 33 | } |
| 34 | |
| 35 | void |
| 36 | TargetThreadWindows::RefreshStateAfterStop() |
| 37 | { |
Zachary Turner | 17f383d | 2014-11-20 22:47:32 +0000 | [diff] [blame^] | 38 | GetRegisterContext()->InvalidateIfNeeded(false); |
Zachary Turner | 119767d | 2014-11-17 17:46:43 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void |
| 42 | TargetThreadWindows::WillResume(lldb::StateType resume_state) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | void |
| 47 | TargetThreadWindows::DidStop() |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | RegisterContextSP |
| 52 | TargetThreadWindows::GetRegisterContext() |
| 53 | { |
Zachary Turner | 17f383d | 2014-11-20 22:47:32 +0000 | [diff] [blame^] | 54 | if (!m_reg_context_sp) |
| 55 | m_reg_context_sp = CreateRegisterContextForFrameIndex(0); |
| 56 | |
| 57 | return m_reg_context_sp; |
Zachary Turner | 119767d | 2014-11-17 17:46:43 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | RegisterContextSP |
| 61 | TargetThreadWindows::CreateRegisterContextForFrame(StackFrame *frame) |
| 62 | { |
Zachary Turner | 17f383d | 2014-11-20 22:47:32 +0000 | [diff] [blame^] | 63 | return CreateRegisterContextForFrameIndex(frame->GetConcreteFrameIndex()); |
| 64 | } |
| 65 | |
| 66 | RegisterContextSP |
| 67 | TargetThreadWindows::CreateRegisterContextForFrameIndex(uint32_t idx) |
| 68 | { |
| 69 | if (!m_reg_context_sp) |
| 70 | { |
| 71 | ArchSpec arch = HostInfo::GetArchitecture(); |
| 72 | switch (arch.GetMachine()) |
| 73 | { |
| 74 | case llvm::Triple::x86: |
| 75 | m_reg_context_sp.reset(new RegisterContextWindows_x86(*this, idx)); |
| 76 | break; |
| 77 | default: |
| 78 | // FIXME: Support x64 by creating a RegisterContextWindows_x86_64 |
| 79 | break; |
| 80 | } |
| 81 | } |
| 82 | return m_reg_context_sp; |
Zachary Turner | 119767d | 2014-11-17 17:46:43 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | bool |
| 86 | TargetThreadWindows::CalculateStopInfo() |
| 87 | { |
Zachary Turner | 17f383d | 2014-11-20 22:47:32 +0000 | [diff] [blame^] | 88 | SetStopInfo(m_stop_info_sp); |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | Unwind * |
| 93 | TargetThreadWindows::GetUnwinder() |
| 94 | { |
| 95 | // FIXME: Implement an unwinder based on the Windows unwinder exposed through DIA SDK. |
| 96 | if (m_unwinder_ap.get() == NULL) |
| 97 | m_unwinder_ap.reset(new UnwindLLDB(*this)); |
| 98 | return m_unwinder_ap.get(); |
Zachary Turner | 119767d | 2014-11-17 17:46:43 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | bool |
| 102 | TargetThreadWindows::DoResume() |
| 103 | { |
| 104 | StateType resume_state = GetResumeState(); |
| 105 | StateType current_state = GetState(); |
| 106 | if (resume_state == current_state) |
| 107 | return true; |
| 108 | |
| 109 | bool success = false; |
| 110 | DWORD suspend_count = 0; |
| 111 | switch (resume_state) |
| 112 | { |
| 113 | case eStateRunning: |
| 114 | SetState(resume_state); |
| 115 | do |
| 116 | { |
| 117 | suspend_count = ::ResumeThread(m_host_thread.GetNativeThread().GetSystemHandle()); |
| 118 | } while (suspend_count > 1 && suspend_count != (DWORD)-1); |
| 119 | success = (suspend_count != (DWORD)-1); |
| 120 | break; |
| 121 | case eStateStopped: |
| 122 | case eStateSuspended: |
| 123 | if (current_state != eStateStopped && current_state != eStateSuspended) |
| 124 | { |
| 125 | suspend_count = SuspendThread(m_host_thread.GetNativeThread().GetSystemHandle()); |
| 126 | success = (suspend_count != (DWORD)-1); |
| 127 | } |
| 128 | break; |
| 129 | default: |
| 130 | success = false; |
| 131 | } |
| 132 | return success; |
| 133 | } |