[Lldb-commits] [lldb] r157964 - in /lldb/trunk: include/lldb/API/ include/lldb/Target/ scripts/Python/interface/ source/API/ source/Commands/ source/Target/ test/python_api/default-constructor/ test/python_api/watchpoint/ test/python_api/watchpoint/condition/ test/python_api/watchpoint/watchlocation/

Johnny Chen johnny.chen at apple.com
Mon Jun 4 16:19:55 PDT 2012


Author: johnny
Date: Mon Jun  4 18:19:54 2012
New Revision: 157964

URL: http://llvm.org/viewvc/llvm-project?rev=157964&view=rev
Log:
rdar://problem/11584012

Refactorings of watchpoint creation APIs so that SBTarget::WatchAddress(), SBValue::Watch(), and SBValue::WatchPointee()
now take an additional 'SBError &error' parameter (at the end) to contain the reason if there is some failure in the
operation.  Update 'watchpoint set variable/expression' commands to take advantage of that.

Update existing test cases to reflect the API change and add test cases to verify that the SBError mechanism works for
SBTarget::WatchAddress() by passing an invalid watch_size.

Modified:
    lldb/trunk/include/lldb/API/SBTarget.h
    lldb/trunk/include/lldb/API/SBValue.h
    lldb/trunk/include/lldb/API/SBWatchpoint.h
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/scripts/Python/interface/SBTarget.i
    lldb/trunk/scripts/Python/interface/SBValue.i
    lldb/trunk/scripts/Python/interface/SBWatchpoint.i
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/source/API/SBValue.cpp
    lldb/trunk/source/API/SBWatchpoint.cpp
    lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
    lldb/trunk/source/Target/Target.cpp
    lldb/trunk/test/python_api/default-constructor/sb_target.py
    lldb/trunk/test/python_api/default-constructor/sb_value.py
    lldb/trunk/test/python_api/default-constructor/sb_watchpoint.py
    lldb/trunk/test/python_api/watchpoint/TestSetWatchpoint.py
    lldb/trunk/test/python_api/watchpoint/TestWatchpointIgnoreCount.py
    lldb/trunk/test/python_api/watchpoint/TestWatchpointIter.py
    lldb/trunk/test/python_api/watchpoint/condition/TestWatchpointConditionAPI.py
    lldb/trunk/test/python_api/watchpoint/watchlocation/TestSetWatchlocation.py
    lldb/trunk/test/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py

Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Mon Jun  4 18:19:54 2012
@@ -692,7 +692,7 @@
     FindWatchpointByID (lldb::watch_id_t watch_id);
 
     lldb::SBWatchpoint
-    WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write);
+    WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError& error);
 
     bool
     EnableAllWatchpoints ();

Modified: lldb/trunk/include/lldb/API/SBValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBValue.h?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBValue.h (original)
+++ lldb/trunk/include/lldb/API/SBValue.h Mon Jun  4 18:19:54 2012
@@ -325,6 +325,9 @@
     /// @param[in] write
     ///     Stop when this value is modified
     ///
+    /// @param[out]
+    ///     An error object. Contains the reason if there is some failure.
+    ///
     /// @return
     ///     An SBWatchpoint object. This object might not be valid upon
     ///     return due to a value not being contained in memory, too 
@@ -332,7 +335,7 @@
     ///     use.
     //------------------------------------------------------------------
     lldb::SBWatchpoint
-    Watch (bool resolve_location, bool read, bool write);
+    Watch (bool resolve_location, bool read, bool write, SBError &error);
 
     //------------------------------------------------------------------
     /// Watch this value that this value points to in memory
@@ -351,6 +354,9 @@
     /// @param[in] write
     ///     Stop when this value is modified
     ///
+    /// @param[out]
+    ///     An error object. Contains the reason if there is some failure.
+    ///
     /// @return
     ///     An SBWatchpoint object. This object might not be valid upon
     ///     return due to a value not being contained in memory, too 
@@ -358,7 +364,7 @@
     ///     use.
     //------------------------------------------------------------------
     lldb::SBWatchpoint
-    WatchPointee (bool resolve_location, bool read, bool write);
+    WatchPointee (bool resolve_location, bool read, bool write, SBError &error);
 
     // this must be defined in the .h file because synthetic children as implemented in the core
     // currently rely on being able to extract the SharedPointer out of an SBValue. if the implementation

Modified: lldb/trunk/include/lldb/API/SBWatchpoint.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBWatchpoint.h?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBWatchpoint.h (original)
+++ lldb/trunk/include/lldb/API/SBWatchpoint.h Mon Jun  4 18:19:54 2012
@@ -32,9 +32,6 @@
     bool
     IsValid() const;
 
-    SBError
-    GetError();
-
     watch_id_t
     GetID ();
 

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Mon Jun  4 18:19:54 2012
@@ -523,7 +523,8 @@
     lldb::WatchpointSP
     CreateWatchpoint (lldb::addr_t addr,
                       size_t size,
-                      uint32_t type);
+                      uint32_t type,
+                      Error &error);
 
     lldb::WatchpointSP
     GetLastCreatedWatchpoint ()

Modified: lldb/trunk/scripts/Python/interface/SBTarget.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBTarget.i?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBTarget.i (original)
+++ lldb/trunk/scripts/Python/interface/SBTarget.i Mon Jun  4 18:19:54 2012
@@ -668,7 +668,8 @@
     WatchAddress (lldb::addr_t addr, 
                   size_t size, 
                   bool read, 
-                  bool write);
+                  bool write,
+                  SBError &error);
              
 
     lldb::SBBroadcaster

Modified: lldb/trunk/scripts/Python/interface/SBValue.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBValue.i?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBValue.i (original)
+++ lldb/trunk/scripts/Python/interface/SBValue.i Mon Jun  4 18:19:54 2012
@@ -313,14 +313,14 @@
     /// It returns an SBWatchpoint, which may be invalid.
     ") Watch;
     lldb::SBWatchpoint
-    Watch (bool resolve_location, bool read, bool write);
+    Watch (bool resolve_location, bool read, bool write, SBError &error);
 
     %feature("docstring", "
     /// Find and watch the location pointed to by a variable.
     /// It returns an SBWatchpoint, which may be invalid.
     ") WatchPointee;
     lldb::SBWatchpoint
-    WatchPointee (bool resolve_location, bool read, bool write);
+    WatchPointee (bool resolve_location, bool read, bool write, SBError &error);
 
     bool
     GetDescription (lldb::SBStream &description);

Modified: lldb/trunk/scripts/Python/interface/SBWatchpoint.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBWatchpoint.i?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBWatchpoint.i (original)
+++ lldb/trunk/scripts/Python/interface/SBWatchpoint.i Mon Jun  4 18:19:54 2012
@@ -31,9 +31,6 @@
     bool
     IsValid();
 
-    SBError
-    GetError();
-
     watch_id_t
     GetID ();
 

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Mon Jun  4 18:19:54 2012
@@ -1674,7 +1674,7 @@
 }
 
 lldb::SBWatchpoint
-SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
+SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
 {
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     
@@ -1690,7 +1690,9 @@
         if (write)
             watch_type |= LLDB_WATCH_TYPE_WRITE;
         // Target::CreateWatchpoint() is thread safe.
-        watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type);
+        Error cw_error;
+        watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type, cw_error);
+        error.SetError(cw_error);
         sb_watchpoint.SetSP (watchpoint_sp);
     }
     

Modified: lldb/trunk/source/API/SBValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/source/API/SBValue.cpp (original)
+++ lldb/trunk/source/API/SBValue.cpp Mon Jun  4 18:19:54 2012
@@ -1655,7 +1655,7 @@
 }
 
 lldb::SBWatchpoint
-SBValue::Watch (bool resolve_location, bool read, bool write)
+SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
 {
     SBWatchpoint sb_watchpoint;
     
@@ -1696,7 +1696,9 @@
         if (write)
             watch_type |= LLDB_WATCH_TYPE_WRITE;
         
-        WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type);
+        Error rc;
+        WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type, rc);
+        error.SetError(rc);
                 
         if (watchpoint_sp) 
         {
@@ -1718,11 +1720,11 @@
 }
 
 lldb::SBWatchpoint
-SBValue::WatchPointee (bool resolve_location, bool read, bool write)
+SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
 {
     SBWatchpoint sb_watchpoint;
     if (IsInScope() && GetType().IsPointerType())
-        sb_watchpoint = Dereference().Watch (resolve_location, read, write);
+        sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
     return sb_watchpoint;
 }
 

Modified: lldb/trunk/source/API/SBWatchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBWatchpoint.cpp?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/source/API/SBWatchpoint.cpp (original)
+++ lldb/trunk/source/API/SBWatchpoint.cpp Mon Jun  4 18:19:54 2012
@@ -87,22 +87,7 @@
 bool
 SBWatchpoint::IsValid() const
 {
-    lldb::WatchpointSP watchpoint_sp(GetSP());
-    if (watchpoint_sp && watchpoint_sp->GetError().Success())
-        return true;
-    return false;
-}
-
-SBError
-SBWatchpoint::GetError ()
-{
-    SBError sb_error;
-    lldb::WatchpointSP watchpoint_sp(GetSP());
-    if (watchpoint_sp)
-    {
-        sb_error.SetError(watchpoint_sp->GetError());
-    }
-    return sb_error;
+    return m_opaque_sp;
 }
 
 int32_t

Modified: lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp Mon Jun  4 18:19:54 2012
@@ -59,20 +59,6 @@
     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.
@@ -1013,11 +999,6 @@
             // 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);
@@ -1031,7 +1012,8 @@
 
     // Now it's time to create the watchpoint.
     uint32_t watch_type = m_option_watchpoint.watch_type;
-    Watchpoint *wp = target->CreateWatchpoint(addr, size, watch_type).get();
+    error.Clear();
+    Watchpoint *wp = target->CreateWatchpoint(addr, size, watch_type, error).get();
     if (wp) {
         if (var_sp && var_sp->GetDeclaration().GetFile()) {
             StreamString ss;
@@ -1047,7 +1029,8 @@
     } else {
         result.AppendErrorWithFormat("Watchpoint creation failed (addr=0x%llx, size=%lu).\n",
                                      addr, size);
-        CheckIfWatchpointsExhausted(target, result);
+        if (error.AsCString(NULL))
+            result.AppendError(error.AsCString());
         result.SetStatus(eReturnStatusFailed);
     }
 
@@ -1221,15 +1204,11 @@
     }
     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 = target->CreateWatchpoint(addr, size, watch_type).get();
+    Error error;
+    Watchpoint *wp = target->CreateWatchpoint(addr, size, watch_type, error).get();
     if (wp) {
         if (var_sp && var_sp->GetDeclaration().GetFile()) {
             StreamString ss;
@@ -1245,7 +1224,8 @@
     } else {
         result.AppendErrorWithFormat("Watchpoint creation failed (addr=0x%llx, size=%lu).\n",
                                      addr, size);
-        CheckIfWatchpointsExhausted(target, result);
+        if (error.AsCString(NULL))
+            result.AppendError(error.AsCString());
         result.SetStatus(eReturnStatusFailed);
     }
 

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Mon Jun  4 18:19:54 2012
@@ -30,6 +30,7 @@
 #include "lldb/Host/Host.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionGroupWatchpoint.h"
 #include "lldb/lldb-private-log.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Target/Process.h"
@@ -465,10 +466,25 @@
     return (m_process_sp && m_process_sp->IsAlive());
 }
 
+static bool
+CheckIfWatchpointsExhausted(Target *target, Error &error)
+{
+    uint32_t num_supported_hardware_watchpoints;
+    Error rc = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
+    if (rc.Success())
+    {
+        uint32_t num_current_watchpoints = target->GetWatchpointList().GetSize();
+        if (num_current_watchpoints >= num_supported_hardware_watchpoints)
+            error.SetErrorStringWithFormat("number of supported hardware watchpoints (%u) has been reached",
+                                           num_supported_hardware_watchpoints);
+    }
+    return false;
+}
+
 // See also Watchpoint::SetWatchpointType(uint32_t type) and
 // the OptionGroupWatchpoint::WatchType enum type.
 WatchpointSP
-Target::CreateWatchpoint(lldb::addr_t addr, size_t size, uint32_t type)
+Target::CreateWatchpoint(lldb::addr_t addr, size_t size, uint32_t type, Error &error)
 {
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
     if (log)
@@ -477,9 +493,18 @@
 
     WatchpointSP wp_sp;
     if (!ProcessIsValid())
+    {
+        error.SetErrorString("process is not alive");
         return wp_sp;
+    }
     if (addr == LLDB_INVALID_ADDRESS || size == 0)
+    {
+        if (size == 0)
+            error.SetErrorString("cannot set a watchpoint with watch_size of 0");
+        else
+            error.SetErrorStringWithFormat("invalid watch address: %llu", addr);
         return wp_sp;
+    }
 
     // Currently we only support one watchpoint per address, with total number
     // of watchpoints limited by the hardware which the inferior is running on.
@@ -517,17 +542,23 @@
         m_watchpoint_list.Add(wp_sp);
     }
 
-    Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
+    error = m_process_sp->EnableWatchpoint(wp_sp.get());
     if (log)
             log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
                         __FUNCTION__,
-                        rc.Success() ? "succeeded" : "failed",
+                        error.Success() ? "succeeded" : "failed",
                         wp_sp->GetID());
 
-    if (rc.Fail()) {
+    if (error.Fail()) {
         // Enabling the watchpoint on the device side failed.
         // Remove the said watchpoint from the list maintained by the target instance.
         m_watchpoint_list.Remove(wp_sp->GetID());
+        // See if we could provide more helpful error message.
+        if (!CheckIfWatchpointsExhausted(this, error))
+        {
+            if (!OptionGroupWatchpoint::IsWatchSizeSupported(size))
+                error.SetErrorStringWithFormat("watch size of %lu is not supported", size);
+        }
         wp_sp.reset();
     }
     else

Modified: lldb/trunk/test/python_api/default-constructor/sb_target.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_target.py?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/test/python_api/default-constructor/sb_target.py (original)
+++ lldb/trunk/test/python_api/default-constructor/sb_target.py Mon Jun  4 18:19:54 2012
@@ -52,7 +52,8 @@
     obj.GetAddressByteSize()
     obj.GetByteOrder()
     obj.GetTriple()
-    obj.WatchAddress(123, 8, True, True)
+    error = lldb.SBError()
+    obj.WatchAddress(123, 8, True, True, error)
     obj.GetBroadcaster()
     obj.GetDescription(lldb.SBStream(), lldb.eDescriptionLevelBrief)
     obj.Clear()

Modified: lldb/trunk/test/python_api/default-constructor/sb_value.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_value.py?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/test/python_api/default-constructor/sb_value.py (original)
+++ lldb/trunk/test/python_api/default-constructor/sb_value.py Mon Jun  4 18:19:54 2012
@@ -34,8 +34,9 @@
     obj.GetDescription(stream)
     obj.GetExpressionPath(stream)
     obj.GetExpressionPath(stream, True)
-    obj.Watch(True, True, False)
-    obj.WatchPointee(True, False, True)
+    error = lldb.SBError()
+    obj.Watch(True, True, False, error)
+    obj.WatchPointee(True, False, True, error)
     for child_val in obj:
         print child_val
     error = lldb.SBError()

Modified: lldb/trunk/test/python_api/default-constructor/sb_watchpoint.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_watchpoint.py?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/test/python_api/default-constructor/sb_watchpoint.py (original)
+++ lldb/trunk/test/python_api/default-constructor/sb_watchpoint.py Mon Jun  4 18:19:54 2012
@@ -8,7 +8,6 @@
 def fuzz_obj(obj):
     obj.GetID()
     obj.IsValid()
-    obj.GetError()
     obj.GetHardwareIndex()
     obj.GetWatchAddress()
     obj.GetWatchSize()

Modified: lldb/trunk/test/python_api/watchpoint/TestSetWatchpoint.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/watchpoint/TestSetWatchpoint.py?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/test/python_api/watchpoint/TestSetWatchpoint.py (original)
+++ lldb/trunk/test/python_api/watchpoint/TestSetWatchpoint.py Mon Jun  4 18:19:54 2012
@@ -61,7 +61,8 @@
 
         # Watch 'global' for read and write.
         value = frame0.FindValue('global', lldb.eValueTypeVariableGlobal)
-        watchpoint = value.Watch(True, True, True)
+        error = lldb.SBError();
+        watchpoint = value.Watch(True, True, True, error)
         self.assertTrue(value and watchpoint,
                         "Successfully found the variable and set a watchpoint")
         self.DebugSBValue(value)

Modified: lldb/trunk/test/python_api/watchpoint/TestWatchpointIgnoreCount.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/watchpoint/TestWatchpointIgnoreCount.py?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/test/python_api/watchpoint/TestWatchpointIgnoreCount.py (original)
+++ lldb/trunk/test/python_api/watchpoint/TestWatchpointIgnoreCount.py Mon Jun  4 18:19:54 2012
@@ -61,7 +61,8 @@
 
         # Watch 'global' for read and write.
         value = frame0.FindValue('global', lldb.eValueTypeVariableGlobal)
-        watchpoint = value.Watch(True, True, True)
+        error = lldb.SBError();
+        watchpoint = value.Watch(True, True, True, error)
         self.assertTrue(value and watchpoint,
                         "Successfully found the variable and set a watchpoint")
         self.DebugSBValue(value)

Modified: lldb/trunk/test/python_api/watchpoint/TestWatchpointIter.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/watchpoint/TestWatchpointIter.py?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/test/python_api/watchpoint/TestWatchpointIter.py (original)
+++ lldb/trunk/test/python_api/watchpoint/TestWatchpointIter.py Mon Jun  4 18:19:54 2012
@@ -61,7 +61,8 @@
 
         # Watch 'global' for read and write.
         value = frame0.FindValue('global', lldb.eValueTypeVariableGlobal)
-        watchpoint = value.Watch(True, True, True)
+        error = lldb.SBError();
+        watchpoint = value.Watch(True, True, True, error)
         self.assertTrue(value and watchpoint,
                         "Successfully found the variable and set a watchpoint")
         self.DebugSBValue(value)

Modified: lldb/trunk/test/python_api/watchpoint/condition/TestWatchpointConditionAPI.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/watchpoint/condition/TestWatchpointConditionAPI.py?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/test/python_api/watchpoint/condition/TestWatchpointConditionAPI.py (original)
+++ lldb/trunk/test/python_api/watchpoint/condition/TestWatchpointConditionAPI.py Mon Jun  4 18:19:54 2012
@@ -66,7 +66,8 @@
 
         # Watch 'global' for write.
         value = frame0.FindValue('global', lldb.eValueTypeVariableGlobal)
-        watchpoint = value.Watch(True, False, True)
+        error = lldb.SBError();
+        watchpoint = value.Watch(True, False, True, error)
         self.assertTrue(value and watchpoint,
                         "Successfully found the variable and set a watchpoint")
         self.DebugSBValue(value)

Modified: lldb/trunk/test/python_api/watchpoint/watchlocation/TestSetWatchlocation.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/watchpoint/watchlocation/TestSetWatchlocation.py?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/test/python_api/watchpoint/watchlocation/TestSetWatchlocation.py (original)
+++ lldb/trunk/test/python_api/watchpoint/watchlocation/TestSetWatchlocation.py Mon Jun  4 18:19:54 2012
@@ -67,7 +67,8 @@
                                                value.GetValueAsUnsigned(0),
                                                value.GetType().GetPointeeType())
         # Watch for write to *g_char_ptr.
-        watchpoint = value.WatchPointee(True, False, True)
+        error = lldb.SBError();
+        watchpoint = value.WatchPointee(True, False, True, error)
         self.assertTrue(value and watchpoint,
                         "Successfully found the pointer and set a watchpoint")
         self.DebugSBValue(value)

Modified: lldb/trunk/test/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py?rev=157964&r1=157963&r2=157964&view=diff
==============================================================================
--- lldb/trunk/test/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py (original)
+++ lldb/trunk/test/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py Mon Jun  4 18:19:54 2012
@@ -37,6 +37,21 @@
         self.buildDwarf()
         self.do_set_watchaddress()
 
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @python_api_test
+    @dsym_test
+    def test_watch_address_with_invalid_watch_size_with_dsym(self):
+        """Exercise SBTarget.WatchAddress() API but pass an invalid watch_size."""
+        self.buildDsym()
+        self.do_set_watchaddress_with_invalid_watch_size()
+
+    @python_api_test
+    @dwarf_test
+    def test_watch_address_with_invalid_watch_size_with_dwarf(self):
+        """Exercise SBTarget.WatchAddress() API but pass an invalid watch_size."""
+        self.buildDwarf()
+        self.do_set_watchaddress_with_invalid_watch_size()
+
     def do_set_watchaddress(self):
         """Use SBTarget.WatchAddress() to set a watchpoint and verify that the program stops later due to the watchpoint."""
         exe = os.path.join(os.getcwd(), "a.out")
@@ -67,7 +82,8 @@
                                                value.GetValueAsUnsigned(0),
                                                value.GetType().GetPointeeType())
         # Watch for write to *g_char_ptr.
-        watchpoint = target.WatchAddress(value.GetValueAsUnsigned(), 1, False, True)
+        error = lldb.SBError();
+        watchpoint = target.WatchAddress(value.GetValueAsUnsigned(), 1, False, True, error)
         self.assertTrue(value and watchpoint,
                         "Successfully found the pointer and set a watchpoint")
         self.DebugSBValue(value)
@@ -95,6 +111,42 @@
 
         # This finishes our test.
 
+    def do_set_watchaddress_with_invalid_watch_size(self):
+        """Use SBTarget.WatchAddress() to set a watchpoint with invalid watch_size and verify we get a meaningful error message."""
+        exe = os.path.join(os.getcwd(), "a.out")
+
+        # Create a target by the debugger.
+        target = self.dbg.CreateTarget(exe)
+        self.assertTrue(target, VALID_TARGET)
+
+        # Now create a breakpoint on main.c.
+        breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
+        self.assertTrue(breakpoint and
+                        breakpoint.GetNumLocations() == 1,
+                        VALID_BREAKPOINT)
+
+        # Now launch the process, and do not stop at the entry point.
+        process = target.LaunchSimple(None, None, os.getcwd())
+
+        # We should be stopped due to the breakpoint.  Get frame #0.
+        process = target.GetProcess()
+        self.assertTrue(process.GetState() == lldb.eStateStopped,
+                        PROCESS_STOPPED)
+        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+        frame0 = thread.GetFrameAtIndex(0)
+
+        value = frame0.FindValue('g_char_ptr',
+                                 lldb.eValueTypeVariableGlobal)
+        pointee = value.CreateValueFromAddress("pointee",
+                                               value.GetValueAsUnsigned(0),
+                                               value.GetType().GetPointeeType())
+        # Watch for write to *g_char_ptr.
+        error = lldb.SBError();
+        watchpoint = target.WatchAddress(value.GetValueAsUnsigned(), 365, False, True, error)
+        self.assertFalse(watchpoint)
+        self.expect(error.GetCString(), exe=False,
+            substrs = ['watch size of %d is not supported' % 365])
+
 
 if __name__ == '__main__':
     import atexit





More information about the lldb-commits mailing list