[Lldb-commits] [lldb] [lldb][Windows] Cache thread context in NativeRegisterContextWindows_arm64 (PR #197385)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Wed May 13 03:01:28 PDT 2026


================
@@ -677,73 +712,143 @@ Status NativeRegisterContextWindows_arm64::WriteRegister(
 
 Status NativeRegisterContextWindows_arm64::ReadAllRegisterValues(
     lldb::WritableDataBufferSP &data_sp) {
-  const size_t data_size = REG_CONTEXT_SIZE;
-  data_sp = std::make_shared<DataBufferHeap>(data_size, 0);
-  ::CONTEXT tls_context;
-  Status error =
-      GetThreadContextHelper(GetThreadHandle(), &tls_context, CONTEXT_ALL);
+  Log *log = GetLog(WindowsLog::Registers);
+
+  Status error = CacheAllRegisterValues();
   if (error.Fail())
     return error;
 
-  uint8_t *dst = data_sp->GetBytes();
-  ::memcpy(dst, &tls_context, data_size);
+  if (!m_context_buffer) {
+    error = Status::FromErrorString("register context buffer is not available");
+    LLDB_LOG(log, "{0} {1}", __FUNCTION__, error);
+    return error;
+  }
+
+  const size_t data_size = m_context_buffer->GetByteSize();
+  data_sp = std::make_shared<DataBufferHeap>(data_size, 0);
+
+  if (!data_sp) {
+    error = Status::FromErrorString("failed to allocate register data buffer");
+    LLDB_LOG(log, "{0} {1}", __FUNCTION__, error);
+    return error;
+  }
+
+  ::memcpy(data_sp->GetBytes(), m_context_buffer->GetBytes(), data_size);
+
   return error;
 }
 
 Status NativeRegisterContextWindows_arm64::WriteAllRegisterValues(
     const lldb::DataBufferSP &data_sp) {
+  auto cleanup = llvm::make_scope_exit([&]() { m_context = nullptr; });
+
+  Log *log = GetLog(WindowsLog::Registers);
   Status error;
-  const size_t data_size = REG_CONTEXT_SIZE;
+
   if (!data_sp) {
-    error = Status::FromErrorStringWithFormat(
-        "NativeRegisterContextWindows_arm64::%s invalid data_sp provided",
-        __FUNCTION__);
+    error = Status::FromErrorString("invalid data_sp");
+    LLDB_LOG(log, "{0} {1}", __FUNCTION__, error);
+    return error;
+  }
+
+  DWORD context_flags = CONTEXT_ALL;
+
+  DWORD context_length = 0;
+  if (InitializeContext(nullptr, context_flags, nullptr, &context_length)) {
+    error = Status::FromErrorString("InitializeContext succeeded unexpectedly");
+    LLDB_LOG(log, "{0} {1}", __FUNCTION__, error);
     return error;
   }
 
-  if (data_sp->GetByteSize() != data_size) {
+  if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
+    error = Status(GetLastError(), eErrorTypeWin32);
+    LLDB_LOG(log, "{0} InitializeContext failed with error {1}", __FUNCTION__,
----------------
DavidSpickett wrote:

"failed with error {}, expected ERROR_..."

https://github.com/llvm/llvm-project/pull/197385


More information about the lldb-commits mailing list