[Lldb-commits] [lldb] r232482 - Report stopped by trace if none of the watchpoint was hit

Tamas Berghammer tberghammer at google.com
Tue Mar 17 07:40:58 PDT 2015


Author: tberghammer
Date: Tue Mar 17 09:40:57 2015
New Revision: 232482

URL: http://llvm.org/viewvc/llvm-project?rev=232482&view=rev
Log:
Report stopped by trace if none of the watchpoint was hit

Some linux kernel reports a watchpoint hit after single stepping even
when no watchpoint was hit. This CL looks for a watchpoint which was hit
and reports a stop by trace if it haven't found any.

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

Modified:
    lldb/trunk/include/lldb/Host/common/NativeRegisterContext.h
    lldb/trunk/source/Host/common/NativeRegisterContext.cpp
    lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h
    lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp

Modified: lldb/trunk/include/lldb/Host/common/NativeRegisterContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/common/NativeRegisterContext.h?rev=232482&r1=232481&r2=232482&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/common/NativeRegisterContext.h (original)
+++ lldb/trunk/include/lldb/Host/common/NativeRegisterContext.h Tue Mar 17 09:40:57 2015
@@ -99,6 +99,15 @@ public:
     virtual Error
     ClearAllHardwareWatchpoints ();
 
+    virtual Error
+    IsWatchpointHit (uint8_t wp_index);
+
+    virtual Error
+    IsWatchpointVacant (uint32_t wp_index);
+
+    virtual lldb::addr_t
+    GetWatchpointAddress (uint32_t wp_index);
+
     virtual bool
     HardwareSingleStep (bool enable);
 

Modified: lldb/trunk/source/Host/common/NativeRegisterContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/NativeRegisterContext.cpp?rev=232482&r1=232481&r2=232482&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/NativeRegisterContext.cpp (original)
+++ lldb/trunk/source/Host/common/NativeRegisterContext.cpp Tue Mar 17 09:40:57 2015
@@ -303,6 +303,24 @@ NativeRegisterContext::ClearAllHardwareW
     return Error ("not implemented");
 }
 
+Error
+NativeRegisterContext::IsWatchpointHit (uint8_t wp_index)
+{
+    return Error ("not implemented");
+}
+
+Error
+NativeRegisterContext::IsWatchpointVacant (uint32_t wp_index)
+{
+    return Error ("not implemented");
+}
+
+lldb::addr_t
+NativeRegisterContext::GetWatchpointAddress (uint32_t wp_index)
+{
+    return LLDB_INVALID_ADDRESS;
+}
+
 bool
 NativeRegisterContext::HardwareSingleStep (bool enable)
 {

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h?rev=232482&r1=232481&r2=232482&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h Tue Mar 17 09:40:57 2015
@@ -46,10 +46,10 @@ namespace lldb_private
         WriteAllRegisterValues (const lldb::DataBufferSP &data_sp) override;
 
         Error
-        IsWatchpointHit(uint8_t wp_index);
+        IsWatchpointHit(uint8_t wp_index) override;
 
         Error
-        IsWatchpointVacant(uint32_t wp_index);
+        IsWatchpointVacant(uint32_t wp_index) override;
 
         bool
         ClearHardwareWatchpoint(uint32_t wp_index) override;
@@ -66,7 +66,7 @@ namespace lldb_private
                 uint32_t watch_flags) override;
 
         lldb::addr_t
-        GetWatchpointAddress(uint32_t wp_index);
+        GetWatchpointAddress(uint32_t wp_index) override;
 
         uint32_t
         NumSupportedHardwareWatchpoints() override;

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp?rev=232482&r1=232481&r2=232482&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp Tue Mar 17 09:40:57 2015
@@ -382,36 +382,51 @@ NativeThreadLinux::SetStoppedByBreakpoin
 void
 NativeThreadLinux::SetStoppedByWatchpoint ()
 {
+    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
+    lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
+    if (log)
+    {
+        NativeProcessProtocolSP process_sp = m_process_wp.lock ();
+        if (process_sp)
+            pid = process_sp->GetID ();
+    }
+
     const StateType new_state = StateType::eStateStopped;
     MaybeLogStateChange (new_state);
     m_state = new_state;
 
-    m_stop_info.reason = StopReason::eStopReasonWatchpoint;
-    m_stop_info.details.signal.signo = SIGTRAP;
-
-    NativeRegisterContextLinux_x86_64 *reg_ctx =
-        reinterpret_cast<NativeRegisterContextLinux_x86_64*> (GetRegisterContext().get());
-    const uint32_t num_hw_watchpoints =
-        reg_ctx->NumSupportedHardwareWatchpoints();
+    NativeRegisterContextSP reg_ctx = GetRegisterContext ();
+    const uint32_t num_hw_watchpoints = reg_ctx->NumSupportedHardwareWatchpoints ();
 
     m_stop_description.clear ();
     for (uint32_t wp_index = 0; wp_index < num_hw_watchpoints; ++wp_index)
-        if (reg_ctx->IsWatchpointHit(wp_index).Success())
+    {
+        if (reg_ctx->IsWatchpointHit (wp_index).Success())
         {
+            if (log)
+                log->Printf ("NativeThreadLinux:%s (pid=%" PRIu64 ", tid=%" PRIu64 ") watchpoint found with idx: %u",
+                             __FUNCTION__, pid, GetID (), wp_index);
+
             std::ostringstream ostr;
-            ostr << reg_ctx->GetWatchpointAddress(wp_index) << " " << wp_index;
+            ostr << reg_ctx->GetWatchpointAddress (wp_index) << " " << wp_index;
             m_stop_description = ostr.str();
+
+            m_stop_info.reason = StopReason::eStopReasonWatchpoint;
+            m_stop_info.details.signal.signo = SIGTRAP;
             return;
         }
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
-    if (log)
-    {
-        NativeProcessProtocolSP m_process_sp = m_process_wp.lock ();
-        lldb::pid_t pid = m_process_sp ? m_process_sp->GetID () : LLDB_INVALID_PROCESS_ID;
-        log->Printf ("NativeThreadLinux: thread (pid=%" PRIu64 ", tid=%" PRIu64 ") "
-                "stopped by a watchpoint, but failed to find it",
-                pid, GetID ());
     }
+
+    // The process reported a watchpoint was hit, but we haven't found the
+    // watchpoint. Assume that a stopped by trace is reported as a hardware
+    // watchpoint what happens on some linux kernels (e.g.: android-arm64
+    // platfrom-21).
+
+    if (log)
+        log->Printf ("NativeThreadLinux:%s (pid=%" PRIu64 ", tid=%" PRIu64 ") none of the watchpoint was hit.",
+                     __FUNCTION__, pid, GetID ());
+
+    SetStoppedByTrace ();
 }
 
 bool





More information about the lldb-commits mailing list