1 //===-- RegisterContextWindows.cpp ------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-private-types.h"
11 #include "lldb/Core/DataBufferHeap.h"
12 #include "lldb/Core/Error.h"
13 #include "lldb/Host/windows/HostThreadWindows.h"
14 #include "lldb/Host/windows/windows.h"
16 #include "ProcessWindowsLog.h"
17 #include "RegisterContextWindows.h"
18 #include "TargetThreadWindows.h"
20 #include "llvm/ADT/STLExtras.h"
23 using namespace lldb_private;
25 const DWORD kWinContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
27 //------------------------------------------------------------------
28 // Constructors and Destructors
29 //------------------------------------------------------------------
30 RegisterContextWindows::RegisterContextWindows(Thread &thread, uint32_t concrete_frame_idx)
31 : RegisterContext(thread, concrete_frame_idx)
33 , m_context_stale(true)
37 RegisterContextWindows::~RegisterContextWindows()
42 RegisterContextWindows::InvalidateAllRegisters()
44 m_context_stale = true;
48 RegisterContextWindows::ReadAllRegisterValues(lldb::DataBufferSP &data_sp)
50 if (!CacheAllRegisterValues())
52 if (data_sp->GetByteSize() < sizeof(m_context))
54 data_sp.reset(new DataBufferHeap(sizeof(CONTEXT), 0));
56 memcpy(data_sp->GetBytes(), &m_context, sizeof(m_context));
61 RegisterContextWindows::WriteAllRegisterValues(const lldb::DataBufferSP &data_sp)
63 assert(data_sp->GetByteSize() >= sizeof(m_context));
64 memcpy(&m_context, data_sp->GetBytes(), sizeof(m_context));
66 TargetThreadWindows &wthread = static_cast<TargetThreadWindows &>(m_thread);
67 if (!::SetThreadContext(wthread.GetHostThread().GetNativeThread().GetSystemHandle(), &m_context))
74 RegisterContextWindows::ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num)
76 const uint32_t num_regs = GetRegisterCount();
78 assert(kind < kNumRegisterKinds);
79 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
81 const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg_idx);
83 if (reg_info->kinds[kind] == num)
87 return LLDB_INVALID_REGNUM;
90 //------------------------------------------------------------------
91 // Subclasses can these functions if desired
92 //------------------------------------------------------------------
94 RegisterContextWindows::NumSupportedHardwareBreakpoints()
96 // Support for hardware breakpoints not yet implemented.
101 RegisterContextWindows::SetHardwareBreakpoint(lldb::addr_t addr, size_t size)
107 RegisterContextWindows::ClearHardwareBreakpoint(uint32_t hw_idx)
113 RegisterContextWindows::NumSupportedHardwareWatchpoints()
115 // Support for hardware watchpoints not yet implemented.
120 RegisterContextWindows::SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read, bool write)
126 RegisterContextWindows::ClearHardwareWatchpoint(uint32_t hw_index)
132 RegisterContextWindows::HardwareSingleStep(bool enable)
138 RegisterContextWindows::CacheAllRegisterValues()
140 if (!m_context_stale)
143 TargetThreadWindows &wthread = static_cast<TargetThreadWindows &>(m_thread);
144 memset(&m_context, 0, sizeof(m_context));
145 m_context.ContextFlags = kWinContextFlags;
146 if (!::GetThreadContext(wthread.GetHostThread().GetNativeThread().GetSystemHandle(), &m_context))
148 WINERR_IFALL(WINDOWS_LOG_REGISTERS, "GetThreadContext failed with error %u while caching register values.",
152 WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "GetThreadContext successfully updated the register values.", ::GetLastError());
153 m_context_stale = false;