[Lldb-commits] [lldb] eebda15 - [lldb] Guarded GDBRemoteCommunicationServerLLGS::m_saved_registers_map (#219431)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Sep 17 07:00:31 PDT 2026
Author: Raphael Isemann
Date: 2026-09-17T15:00:26+01:00
New Revision: eebda156ed5330e03c603b018cec3f20b2d9a113
URL: https://github.com/llvm/llvm-project/commit/eebda156ed5330e03c603b018cec3f20b2d9a113
DIFF: https://github.com/llvm/llvm-project/commit/eebda156ed5330e03c603b018cec3f20b2d9a113.diff
LOG: [lldb] Guarded GDBRemoteCommunicationServerLLGS::m_saved_registers_map (#219431)
m_saved_registers_map and m_next_saved_registers_id were guarded by a
dedicated std::mutex. This replaces the manual locking logic with
`Guarded`.
This also fixes the missing lock in the Handle_QSaveRegisterState
assert which was previously a race condition.
Added:
Modified:
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
Removed:
################################################################################
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index 38aeb1bb40903..14e2a65c63aea 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -3624,13 +3624,13 @@ GDBRemoteCommunicationServerLLGS::Handle_QSaveRegisterState(
// Allocate a new save id.
const uint32_t save_id = GetNextSavedRegistersID();
- assert((m_saved_registers_map.find(save_id) == m_saved_registers_map.end()) &&
- "GetNextRegisterSaveID() returned an existing register save id");
// Save the register data buffer under the save id.
{
- std::lock_guard<std::mutex> guard(m_saved_registers_mutex);
- m_saved_registers_map[save_id] = register_data_sp;
+ auto saved_registers = m_saved_registers.Lock();
+ assert((saved_registers->map.find(save_id) == saved_registers->map.end()) &&
+ "GetNextRegisterSaveID() returned an existing register save id");
+ saved_registers->map[save_id] = register_data_sp;
}
// Write the response.
@@ -3674,11 +3674,11 @@ GDBRemoteCommunicationServerLLGS::Handle_QRestoreRegisterState(
// Retrieve register state buffer, then remove from the list.
DataBufferSP register_data_sp;
{
- std::lock_guard<std::mutex> guard(m_saved_registers_mutex);
+ auto saved_registers = m_saved_registers.Lock();
// Find the register set buffer for the given save id.
- auto it = m_saved_registers_map.find(save_id);
- if (it == m_saved_registers_map.end()) {
+ auto it = saved_registers->map.find(save_id);
+ if (it == saved_registers->map.end()) {
LLDB_LOG(log,
"pid {0} does not have a register set save buffer for id {1}",
m_current_process->GetID(), save_id);
@@ -3687,7 +3687,7 @@ GDBRemoteCommunicationServerLLGS::Handle_QRestoreRegisterState(
register_data_sp = it->second;
// Remove it from the map.
- m_saved_registers_map.erase(it);
+ saved_registers->map.erase(it);
}
Status error = reg_context.WriteAllRegisterValues(register_data_sp);
@@ -4476,8 +4476,7 @@ lldb::tid_t GDBRemoteCommunicationServerLLGS::GetCurrentThreadID() const {
}
uint32_t GDBRemoteCommunicationServerLLGS::GetNextSavedRegistersID() {
- std::lock_guard<std::mutex> guard(m_saved_registers_mutex);
- return m_next_saved_registers_id++;
+ return m_saved_registers.Lock()->next_id++;
}
void GDBRemoteCommunicationServerLLGS::ClearProcessSpecificData() {
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
index f3f1bbc557244..873f24d10a627 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
@@ -16,6 +16,7 @@
#include "lldb/Core/Communication.h"
#include "lldb/Host/MainLoop.h"
#include "lldb/Host/common/NativeProcessProtocol.h"
+#include "lldb/Utility/Locked.h"
#include "lldb/Utility/RegisterValue.h"
#include "lldb/lldb-private-forward.h"
@@ -133,9 +134,13 @@ class GDBRemoteCommunicationServerLLGS
std::mutex m_pending_output_mutex;
llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> m_xfer_buffer_map;
- std::mutex m_saved_registers_mutex;
- std::unordered_map<uint32_t, lldb::DataBufferSP> m_saved_registers_map;
- uint32_t m_next_saved_registers_id = 1;
+
+ struct SavedRegisters {
+ std::unordered_map<uint32_t, lldb::DataBufferSP> map;
+ uint32_t next_id = 1;
+ };
+ Guarded<SavedRegisters, std::mutex> m_saved_registers;
+
bool m_thread_suffix_supported = false;
bool m_address_space_suffix_supported = false;
bool m_list_threads_in_stop_reply = false;
More information about the lldb-commits
mailing list