LLDB  mainline
RegisterContextWindows.cpp
Go to the documentation of this file.
1 //===-- RegisterContextWindows.cpp ------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
12 #include "lldb/Utility/Status.h"
14 
15 #include "ProcessWindowsLog.h"
16 #include "RegisterContextWindows.h"
17 #include "TargetThreadWindows.h"
18 
19 #include "llvm/ADT/STLExtras.h"
20 
21 using namespace lldb;
22 using namespace lldb_private;
23 
24 const DWORD kWinContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
25 
26 // Constructors and Destructors
27 RegisterContextWindows::RegisterContextWindows(Thread &thread,
28  uint32_t concrete_frame_idx)
29  : RegisterContext(thread, concrete_frame_idx), m_context(),
30  m_context_stale(true) {}
31 
33 
35  m_context_stale = true;
36 }
37 
39  lldb::DataBufferSP &data_sp) {
40 
42  return false;
43 
44  data_sp.reset(new DataBufferHeap(sizeof(CONTEXT), 0));
45  memcpy(data_sp->GetBytes(), &m_context, sizeof(m_context));
46 
47  return true;
48 }
49 
51  const lldb::DataBufferSP &data_sp) {
52  assert(data_sp->GetByteSize() >= sizeof(m_context));
53  memcpy(&m_context, data_sp->GetBytes(), sizeof(m_context));
54 
55  TargetThreadWindows &wthread = static_cast<TargetThreadWindows &>(m_thread);
56  if (!::SetThreadContext(
58  &m_context))
59  return false;
60 
61  return true;
62 }
63 
65  lldb::RegisterKind kind, uint32_t num) {
66  const uint32_t num_regs = GetRegisterCount();
67 
68  assert(kind < kNumRegisterKinds);
69  for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
70  const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg_idx);
71 
72  if (reg_info->kinds[kind] == num)
73  return reg_idx;
74  }
75 
76  return LLDB_INVALID_REGNUM;
77 }
78 
79 // Subclasses can these functions if desired
81  // Support for hardware breakpoints not yet implemented.
82  return 0;
83 }
84 
86  size_t size) {
87  return 0;
88 }
89 
91  return false;
92 }
93 
95  // Support for hardware watchpoints not yet implemented.
96  return 0;
97 }
98 
100  size_t size, bool read,
101  bool write) {
102  return 0;
103 }
104 
106  return false;
107 }
108 
109 bool RegisterContextWindows::HardwareSingleStep(bool enable) { return false; }
110 
113  if (!m_context_stale)
114  return true;
115 
116  TargetThreadWindows &wthread = static_cast<TargetThreadWindows &>(m_thread);
117  memset(&m_context, 0, sizeof(m_context));
118  m_context.ContextFlags = kWinContextFlags;
119  if (!::GetThreadContext(
121  &m_context)) {
122  LLDB_LOG(
123  log,
124  "GetThreadContext failed with error {0} while caching register values.",
125  ::GetLastError());
126  return false;
127  }
128  LLDB_LOG(log, "successfully updated the register values.");
129  m_context_stale = false;
130  return true;
131 }
uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read, bool write) override
bool ClearHardwareWatchpoint(uint32_t hw_index) override
#define WINDOWS_LOG_REGISTERS
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
const DWORD kWinContextFlags
HostNativeThread & GetNativeThread()
Definition: HostThread.cpp:32
#define LLDB_LOG(log,...)
Definition: Log.h:209
A subclass of DataBuffer that stores a data buffer on the heap.
bool ClearHardwareBreakpoint(uint32_t hw_idx) override
virtual size_t GetRegisterCount()=0
virtual const RegisterInfo * GetRegisterInfoAtIndex(size_t reg)=0
bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override
uint64_t addr_t
Definition: lldb-types.h:83
Definition: SBAddress.h:15
bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override
static Log * GetLogIfAny(uint32_t mask)
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num) override
Convert from a given register numbering scheme to the lldb register numbering scheme.
uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:90