blob: fe05f3068bb44451cba5bd019a5177d40b356b82 [file] [log] [blame]
Zachary Turner119767d2014-11-17 17:46:43 +00001//===-- 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
Adrian McCarthy3ae74922015-06-01 21:51:50 +000010#include "lldb/Core/Log.h"
11#include "lldb/Core/Logging.h"
12#include "lldb/Core/State.h"
Zachary Turner17f383d2014-11-20 22:47:32 +000013#include "lldb/Host/HostInfo.h"
Zachary Turner119767d2014-11-17 17:46:43 +000014#include "lldb/Host/HostNativeThreadBase.h"
15#include "lldb/Host/windows/HostThreadWindows.h"
16#include "lldb/Host/windows/windows.h"
Zachary Turner17f383d2014-11-20 22:47:32 +000017#include "lldb/Target/RegisterContext.h"
18
Zachary Turner17f383d2014-11-20 22:47:32 +000019#include "ProcessWindows.h"
Adrian McCarthy3ae74922015-06-01 21:51:50 +000020#include "ProcessWindowsLog.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000021#include "TargetThreadWindows.h"
Zachary Turner17f383d2014-11-20 22:47:32 +000022#include "UnwindLLDB.h"
Zachary Turner119767d2014-11-17 17:46:43 +000023
24using namespace lldb;
25using namespace lldb_private;
26
Kate Stoneb9c1b512016-09-06 20:57:50 +000027TargetThreadWindows::TargetThreadWindows(ProcessWindows &process,
28 const HostThread &thread)
29 : Thread(process, thread.GetNativeThread().GetThreadId()),
30 m_host_thread(thread) {}
31
32TargetThreadWindows::~TargetThreadWindows() { DestroyThread(); }
33
34void TargetThreadWindows::RefreshStateAfterStop() {
35 ::SuspendThread(m_host_thread.GetNativeThread().GetSystemHandle());
36 SetState(eStateStopped);
37 GetRegisterContext()->InvalidateIfNeeded(false);
Zachary Turner119767d2014-11-17 17:46:43 +000038}
39
Kate Stoneb9c1b512016-09-06 20:57:50 +000040void TargetThreadWindows::WillResume(lldb::StateType resume_state) {}
41
42void TargetThreadWindows::DidStop() {}
43
44bool TargetThreadWindows::CalculateStopInfo() {
45 SetStopInfo(m_stop_info_sp);
46 return true;
Zachary Turner119767d2014-11-17 17:46:43 +000047}
48
Kate Stoneb9c1b512016-09-06 20:57:50 +000049Unwind *TargetThreadWindows::GetUnwinder() {
50 // FIXME: Implement an unwinder based on the Windows unwinder exposed through
51 // DIA SDK.
52 if (m_unwinder_ap.get() == NULL)
53 m_unwinder_ap.reset(new UnwindLLDB(*this));
54 return m_unwinder_ap.get();
Zachary Turner119767d2014-11-17 17:46:43 +000055}
56
Kate Stoneb9c1b512016-09-06 20:57:50 +000057bool TargetThreadWindows::DoResume() {
58 StateType resume_state = GetTemporaryResumeState();
59 StateType current_state = GetState();
60 if (resume_state == current_state)
Zachary Turner17f383d2014-11-20 22:47:32 +000061 return true;
Zachary Turner17f383d2014-11-20 22:47:32 +000062
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 if (resume_state == eStateStepping) {
64 uint32_t flags_index =
65 GetRegisterContext()->ConvertRegisterKindToRegisterNumber(
66 eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS);
67 uint64_t flags_value =
68 GetRegisterContext()->ReadRegisterAsUnsigned(flags_index, 0);
69 flags_value |= 0x100; // Set the trap flag on the CPU
70 GetRegisterContext()->WriteRegisterFromUnsigned(flags_index, flags_value);
71 }
Zachary Turner119767d2014-11-17 17:46:43 +000072
Kate Stoneb9c1b512016-09-06 20:57:50 +000073 if (resume_state == eStateStepping || resume_state == eStateRunning) {
74 DWORD previous_suspend_count = 0;
75 HANDLE thread_handle = m_host_thread.GetNativeThread().GetSystemHandle();
76 do {
77 previous_suspend_count = ::ResumeThread(thread_handle);
78 } while (previous_suspend_count > 0);
79 }
80 return true;
Zachary Turner119767d2014-11-17 17:46:43 +000081}