Author: omjavaid Date: Wed Aug 26 13:23:27 2015 New Revision: 246045 URL: http://llvm.org/viewvc/llvm-project?rev=246045&view=rev Log: Error checking correction in AArch64 hardware watchpoint code
Differential Revision: http://reviews.llvm.org/D12328 Modified: lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp Modified: lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp?rev=246045&r1=246044&r2=246045&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp Wed Aug 26 13:23:27 2015 @@ -391,10 +391,15 @@ NativeRegisterContextLinux_arm64::SetHar if (log) log->Printf ("NativeRegisterContextLinux_arm64::%s()", __FUNCTION__); + Error error; + // Read hardware breakpoint and watchpoint information. - ReadHardwareDebugInfo (); + error = ReadHardwareDebugInfo (); - uint32_t control_value, bp_index; + if (error.Fail()) + return LLDB_INVALID_INDEX32; + + uint32_t control_value = 0, bp_index = 0; // Check if size has a valid hardware breakpoint length. if (size != 4) @@ -436,7 +441,10 @@ NativeRegisterContextLinux_arm64::SetHar m_hbr_regs[bp_index].refcount = 1; // PTRACE call to set corresponding hardware breakpoint register. - WriteHardwareDebugRegs(eDREGTypeBREAK); + error = WriteHardwareDebugRegs(eDREGTypeBREAK); + + if (error.Fail()) + return LLDB_INVALID_INDEX32; } else m_hbr_regs[bp_index].refcount++; @@ -452,8 +460,13 @@ NativeRegisterContextLinux_arm64::ClearH if (log) log->Printf ("NativeRegisterContextLinux_arm64::%s()", __FUNCTION__); + Error error; + // Read hardware breakpoint and watchpoint information. - ReadHardwareDebugInfo (); + error = ReadHardwareDebugInfo (); + + if (error.Fail()) + return false; if (hw_idx >= m_max_hbp_supported) return false; @@ -472,6 +485,11 @@ NativeRegisterContextLinux_arm64::ClearH // PTRACE call to clear corresponding hardware breakpoint register. WriteHardwareDebugRegs(eDREGTypeBREAK); + + if (error.Fail()) + return false; + + return true; } return false; @@ -485,8 +503,13 @@ NativeRegisterContextLinux_arm64::NumSup if (log) log->Printf ("NativeRegisterContextLinux_arm64::%s()", __FUNCTION__); + Error error; + // Read hardware breakpoint and watchpoint information. - ReadHardwareDebugInfo (); + error = ReadHardwareDebugInfo (); + + if (error.Fail()) + return LLDB_INVALID_INDEX32; return m_max_hwp_supported; } @@ -499,10 +522,15 @@ NativeRegisterContextLinux_arm64::SetHar if (log) log->Printf ("NativeRegisterContextLinux_arm64::%s()", __FUNCTION__); + Error error; + // Read hardware breakpoint and watchpoint information. - ReadHardwareDebugInfo (); + error = ReadHardwareDebugInfo (); + + if (error.Fail()) + return LLDB_INVALID_INDEX32; - uint32_t control_value, wp_index; + uint32_t control_value = 0, wp_index = 0; // Check if we are setting watchpoint other than read/write/access // Also update watchpoint flag to match AArch64 write-read bit configuration. @@ -562,7 +590,10 @@ NativeRegisterContextLinux_arm64::SetHar m_hwp_regs[wp_index].refcount = 1; // PTRACE call to set corresponding watchpoint register. - WriteHardwareDebugRegs(eDREGTypeWATCH); + error = WriteHardwareDebugRegs(eDREGTypeWATCH); + + if (error.Fail()) + return LLDB_INVALID_INDEX32; } else m_hwp_regs[wp_index].refcount++; @@ -578,8 +609,13 @@ NativeRegisterContextLinux_arm64::ClearH if (log) log->Printf ("NativeRegisterContextLinux_arm64::%s()", __FUNCTION__); + Error error; + // Read hardware breakpoint and watchpoint information. - ReadHardwareDebugInfo (); + error = ReadHardwareDebugInfo (); + + if (error.Fail()) + return false; if (wp_index >= m_max_hwp_supported) return false; @@ -598,7 +634,11 @@ NativeRegisterContextLinux_arm64::ClearH m_hwp_regs[wp_index].refcount = 0; // Ptrace call to update hardware debug registers - WriteHardwareDebugRegs(eDREGTypeWATCH); + error = WriteHardwareDebugRegs(eDREGTypeWATCH); + + if (error.Fail()) + return false; + return true; } @@ -613,8 +653,13 @@ NativeRegisterContextLinux_arm64::ClearA if (log) log->Printf ("NativeRegisterContextLinux_arm64::%s()", __FUNCTION__); + Error error; + // Read hardware breakpoint and watchpoint information. - ReadHardwareDebugInfo (); + error = ReadHardwareDebugInfo (); + + if (error.Fail()) + return error; for (uint32_t i = 0; i < m_max_hwp_supported; i++) { @@ -626,7 +671,10 @@ NativeRegisterContextLinux_arm64::ClearA m_hwp_regs[i].refcount = 0; // Ptrace call to update hardware debug registers - WriteHardwareDebugRegs(eDREGTypeWATCH); + error = WriteHardwareDebugRegs(eDREGTypeWATCH); + + if (error.Fail()) + return error; } } @@ -730,12 +778,19 @@ NativeRegisterContextLinux_arm64::ReadHa ioVec.iov_base = &dreg_state; ioVec.iov_len = sizeof (dreg_state); error = NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, ®set, &ioVec, ioVec.iov_len); + + if (error.Fail()) + return error; + m_max_hwp_supported = dreg_state.dbg_info & 0xff; regset = NT_ARM_HW_BREAK; error = NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, ®set, &ioVec, ioVec.iov_len); - m_max_hbp_supported = dreg_state.dbg_info & 0xff; + if (error.Fail()) + return error; + + m_max_hbp_supported = dreg_state.dbg_info & 0xff; m_refresh_hwdebug_info = false; return error; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits