[Lldb-commits] [PATCH] D32568: Protect Proces::GetMemoryRegionInfo and ::GetFileLoadAddress with a lock

Scott Smith via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Apr 26 15:51:01 PDT 2017


scott.smith created this revision.

Both routines (on Linux, at least) utilize a cache; protect the cache with a mutex to allow concurrent callers.


Repository:
  rL LLVM

https://reviews.llvm.org/D32568

Files:
  source/Plugins/Process/Linux/NativeProcessLinux.cpp
  source/Plugins/Process/Linux/NativeProcessLinux.h
  source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
  source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
  source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp


Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -1440,7 +1440,6 @@
   region_info.Clear();
 
   if (m_supports_memory_region_info != eLazyBoolNo) {
-    m_supports_memory_region_info = eLazyBoolYes;
     char packet[64];
     const int packet_len = ::snprintf(
         packet, sizeof(packet), "qMemoryRegionInfo:%" PRIx64, (uint64_t)addr);
@@ -1516,6 +1515,7 @@
         // We got an invalid address range back
         error.SetErrorString("Server returned invalid range");
       }
+      m_supports_memory_region_info = eLazyBoolYes;
     } else {
       m_supports_memory_region_info = eLazyBoolNo;
     }
Index: source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
===================================================================
--- source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
+++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
@@ -106,6 +106,9 @@
 private:
   MainLoop::SignalHandleUP m_sigchld_handle;
   ArchSpec m_arch;
+
+  // Mutex to protect the memory region cache.
+  std::recursive_mutex m_memory_region_mutex;
   LazyBool m_supports_mem_region;
   std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
 
Index: source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
===================================================================
--- source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
+++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -565,6 +565,7 @@
 Error NativeProcessNetBSD::GetMemoryRegionInfo(lldb::addr_t load_addr,
                                                MemoryRegionInfo &range_info) {
 
+  std::lock_guard<std::recursive_mutex> guard(m_memory_region_mutex);
   if (m_supports_mem_region == LazyBool::eLazyBoolNo) {
     // We're done.
     return Error("unsupported");
Index: source/Plugins/Process/Linux/NativeProcessLinux.h
===================================================================
--- source/Plugins/Process/Linux/NativeProcessLinux.h
+++ source/Plugins/Process/Linux/NativeProcessLinux.h
@@ -126,6 +126,8 @@
   MainLoop::SignalHandleUP m_sigchld_handle;
   ArchSpec m_arch;
 
+  // Mutex to protect the memory region cache.
+  std::recursive_mutex m_memory_region_mutex;
   LazyBool m_supports_mem_region;
   std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
 
Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp
===================================================================
--- source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -1516,6 +1516,7 @@
 
 Error NativeProcessLinux::GetMemoryRegionInfo(lldb::addr_t load_addr,
                                               MemoryRegionInfo &range_info) {
+  std::lock_guard<std::recursive_mutex> guard(m_memory_region_mutex);
   // FIXME review that the final memory region returned extends to the end of
   // the virtual address space,
   // with no perms if it is not mapped.
@@ -2221,6 +2222,7 @@
 
 Error NativeProcessLinux::GetLoadedModuleFileSpec(const char *module_path,
                                                   FileSpec &file_spec) {
+  std::lock_guard<std::recursive_mutex> guard(m_memory_region_mutex);
   Error error = PopulateMemoryRegionCache();
   if (error.Fail())
     return error;
@@ -2240,6 +2242,7 @@
 
 Error NativeProcessLinux::GetFileLoadAddress(const llvm::StringRef &file_name,
                                              lldb::addr_t &load_addr) {
+  std::lock_guard<std::recursive_mutex> guard(m_memory_region_mutex);
   load_addr = LLDB_INVALID_ADDRESS;
   Error error = PopulateMemoryRegionCache();
   if (error.Fail())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32568.96839.patch
Type: text/x-patch
Size: 3841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20170426/4c7a2ae3/attachment.bin>


More information about the lldb-commits mailing list