[Lldb-commits] [lldb] r157948 - in /lldb/trunk: include/lldb/Interpreter/OptionGroupWatchpoint.h source/Commands/CommandObjectWatchpoint.cpp source/Interpreter/OptionGroupWatchpoint.cpp

Johnny Chen johnny.chen at apple.com
Mon Jun 4 13:08:23 PDT 2012


Author: johnny
Date: Mon Jun  4 15:08:23 2012
New Revision: 157948

URL: http://llvm.org/viewvc/llvm-project?rev=157948&view=rev
Log:
Give more explicit error messages when watchpoint creation command (watchpoint set) fails,
like number of supported hardware watchpoints reached or the watch size is not allowed.

Modified:
    lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h
    lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
    lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp

Modified: lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h?rev=157948&r1=157947&r2=157948&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h (original)
+++ lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h Mon Jun  4 15:08:23 2012
@@ -26,6 +26,9 @@
     {
     public:
         
+        static bool
+        IsWatchSizeSupported(uint32_t watch_size);
+
         OptionGroupWatchpoint ();
 
         virtual

Modified: lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp?rev=157948&r1=157947&r2=157948&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp Mon Jun  4 15:08:23 2012
@@ -59,6 +59,20 @@
     return true;
 }
 
+static void
+CheckIfWatchpointsExhausted(Target *target, CommandReturnObject &result)
+{
+    uint32_t num_supported_hardware_watchpoints;
+    Error error = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
+    if (error.Success())
+    {
+        uint32_t num_current_watchpoints = target->GetWatchpointList().GetSize();
+        if (num_current_watchpoints >= num_supported_hardware_watchpoints)
+            result.AppendErrorWithFormat("Number of supported hardware watchpoints (%u) has been reached.\n",
+                                         num_supported_hardware_watchpoints);
+    }
+}
+
 #include "llvm/ADT/StringRef.h"
 
 // Equivalent class: {"-", "to", "To", "TO"} of range specifier array.
@@ -943,6 +957,7 @@
     CommandReturnObject &result
 )
 {
+    Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
     ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
     StackFrame *frame = exe_ctx.GetFramePtr();
     if (frame == NULL)
@@ -998,6 +1013,11 @@
             // Find out the size of this variable.
             size = m_option_watchpoint.watch_size == 0 ? valobj_sp->GetByteSize()
                                                        : m_option_watchpoint.watch_size;
+            if (!m_option_watchpoint.IsWatchSizeSupported(size))
+            {
+                result.GetErrorStream().Printf("Watch size of %lu is not supported\n", size);
+                return false;
+            }
         }
     } else {
         const char *error_cstr = error.AsCString(NULL);
@@ -1011,7 +1031,7 @@
 
     // Now it's time to create the watchpoint.
     uint32_t watch_type = m_option_watchpoint.watch_type;
-    Watchpoint *wp = exe_ctx.GetTargetRef().CreateWatchpoint(addr, size, watch_type).get();
+    Watchpoint *wp = target->CreateWatchpoint(addr, size, watch_type).get();
     if (wp) {
         if (var_sp && var_sp->GetDeclaration().GetFile()) {
             StreamString ss;
@@ -1027,6 +1047,7 @@
     } else {
         result.AppendErrorWithFormat("Watchpoint creation failed (addr=0x%llx, size=%lu).\n",
                                      addr, size);
+        CheckIfWatchpointsExhausted(target, result);
         result.SetStatus(eReturnStatusFailed);
     }
 
@@ -1200,10 +1221,15 @@
     }
     size = with_dash_x ? m_option_watchpoint.watch_size
                        : target->GetArchitecture().GetAddressByteSize();
+    if (!m_option_watchpoint.IsWatchSizeSupported(size))
+    {
+        result.GetErrorStream().Printf("Watch size of %lu is not supported\n", size);
+        return false;
+    }
 
     // Now it's time to create the watchpoint.
     uint32_t watch_type = m_option_watchpoint.watch_type;
-    Watchpoint *wp = exe_ctx.GetTargetRef().CreateWatchpoint(addr, size, watch_type).get();
+    Watchpoint *wp = target->CreateWatchpoint(addr, size, watch_type).get();
     if (wp) {
         if (var_sp && var_sp->GetDeclaration().GetFile()) {
             StreamString ss;
@@ -1219,6 +1245,7 @@
     } else {
         result.AppendErrorWithFormat("Watchpoint creation failed (addr=0x%llx, size=%lu).\n",
                                      addr, size);
+        CheckIfWatchpointsExhausted(target, result);
         result.SetStatus(eReturnStatusFailed);
     }
 

Modified: lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp?rev=157948&r1=157947&r2=157948&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp Mon Jun  4 15:08:23 2012
@@ -45,6 +45,19 @@
 };
 
 
+bool
+OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size)
+{
+    for (uint32_t i = 0; i < llvm::array_lengthof(g_watch_size); ++i)
+    {
+        if (g_watch_size[i].value == 0)
+            break;
+        if (watch_size == g_watch_size[i].value)
+            return true;
+    }
+    return false;
+}
+
 OptionGroupWatchpoint::OptionGroupWatchpoint () :
     OptionGroup()
 {





More information about the lldb-commits mailing list