[Lldb-commits] [lldb] r251386 - Fix for Arm watchpoint cache corruption in case of ptrace failure

Omair Javaid via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 26 22:56:57 PDT 2015


Author: omjavaid
Date: Tue Oct 27 00:56:56 2015
New Revision: 251386

URL: http://llvm.org/viewvc/llvm-project?rev=251386&view=rev
Log:
Fix for Arm watchpoint cache corruption in case of ptrace failure

Differential revision: http://reviews.llvm.org/D14051


Modified:
    lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp?rev=251386&r1=251385&r2=251386&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp Tue Oct 27 00:56:56 2015
@@ -451,7 +451,13 @@ NativeRegisterContextLinux_arm::SetHardw
         error = WriteHardwareDebugRegs(eDREGTypeBREAK, bp_index);
 
         if (error.Fail())
+        {
+            m_hbr_regs[bp_index].address = 0;
+            m_hbr_regs[bp_index].control &= ~1;
+            m_hbr_regs[bp_index].refcount = 0;
+
             return LLDB_INVALID_INDEX32;
+        }
     }
     else
         m_hbr_regs[bp_index].refcount++;
@@ -486,6 +492,11 @@ NativeRegisterContextLinux_arm::ClearHar
     }
     else if (m_hbr_regs[hw_idx].refcount == 1)
     {
+        // Create a backup we can revert to in case of failure.
+        lldb::addr_t tempAddr = m_hbr_regs[hw_idx].address;
+        uint32_t tempControl = m_hbr_regs[hw_idx].control;
+        uint32_t tempRefCount = m_hbr_regs[hw_idx].refcount;
+
         m_hbr_regs[hw_idx].control &= ~1;
         m_hbr_regs[hw_idx].address = 0;
         m_hbr_regs[hw_idx].refcount = 0;
@@ -494,7 +505,13 @@ NativeRegisterContextLinux_arm::ClearHar
         WriteHardwareDebugRegs(eDREGTypeBREAK, hw_idx);
 
         if (error.Fail())
+        {
+            m_hbr_regs[hw_idx].control = tempControl;
+            m_hbr_regs[hw_idx].address = tempAddr;
+            m_hbr_regs[hw_idx].refcount = tempRefCount;
+
             return false;
+        }
 
         return true;
     }
@@ -614,7 +631,13 @@ NativeRegisterContextLinux_arm::SetHardw
         error = WriteHardwareDebugRegs(eDREGTypeWATCH, wp_index);
 
         if (error.Fail())
+        {
+            m_hwp_regs[wp_index].address = 0;
+            m_hwp_regs[wp_index].control &= ~1;
+            m_hwp_regs[wp_index].refcount = 0;
+
             return LLDB_INVALID_INDEX32;
+        }
     }
     else
         m_hwp_regs[wp_index].refcount++;
@@ -649,6 +672,11 @@ NativeRegisterContextLinux_arm::ClearHar
     }
     else if (m_hwp_regs[wp_index].refcount == 1)
     {
+        // Create a backup we can revert to in case of failure.
+        lldb::addr_t tempAddr = m_hwp_regs[wp_index].address;
+        uint32_t tempControl = m_hwp_regs[wp_index].control;
+        uint32_t tempRefCount = m_hwp_regs[wp_index].refcount;
+
         // Update watchpoint in local cache
         m_hwp_regs[wp_index].control &= ~1;
         m_hwp_regs[wp_index].address = 0;
@@ -658,7 +686,13 @@ NativeRegisterContextLinux_arm::ClearHar
         error = WriteHardwareDebugRegs(eDREGTypeWATCH, wp_index);
 
         if (error.Fail())
+        {
+            m_hwp_regs[wp_index].control = tempControl;
+            m_hwp_regs[wp_index].address = tempAddr;
+            m_hwp_regs[wp_index].refcount = tempRefCount;
+
             return false;
+        }
 
         return true;
     }
@@ -682,10 +716,18 @@ NativeRegisterContextLinux_arm::ClearAll
     if (error.Fail())
         return error;
 
+    lldb::addr_t tempAddr = 0;
+    uint32_t tempControl = 0, tempRefCount = 0;
+
     for (uint32_t i = 0; i < m_max_hwp_supported; i++)
     {
         if (m_hwp_regs[i].control & 0x01)
         {
+            // Create a backup we can revert to in case of failure.
+            tempAddr = m_hwp_regs[i].address;
+            tempControl = m_hwp_regs[i].control;
+            tempRefCount = m_hwp_regs[i].refcount;
+
             // Clear watchpoints in local cache
             m_hwp_regs[i].control &= ~1;
             m_hwp_regs[i].address = 0;
@@ -695,7 +737,13 @@ NativeRegisterContextLinux_arm::ClearAll
             error = WriteHardwareDebugRegs(eDREGTypeWATCH, i);
 
             if (error.Fail())
+            {
+                m_hwp_regs[i].control = tempControl;
+                m_hwp_regs[i].address = tempAddr;
+                m_hwp_regs[i].refcount = tempRefCount;
+
                 return error;
+            }
         }
     }
 




More information about the lldb-commits mailing list