[Lldb-commits] [lldb] r184245 - We were getting an assert because somebody was making a watchpoint that was

Jim Ingham jingham at apple.com
Tue Jun 18 14:52:48 PDT 2013


Author: jingham
Date: Tue Jun 18 16:52:48 2013
New Revision: 184245

URL: http://llvm.org/viewvc/llvm-project?rev=184245&view=rev
Log:
We were getting an assert because somebody was making a watchpoint that was
neither read nor write.  Tighten up the checking so this isn't possible.

<rdar://problem/14111167>

Modified:
    lldb/trunk/include/lldb/lldb-defines.h
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
    lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/lldb-defines.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-defines.h?rev=184245&r1=184244&r2=184245&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-defines.h (original)
+++ lldb/trunk/include/lldb/lldb-defines.h Tue Jun 18 16:52:48 2013
@@ -49,6 +49,7 @@
 #define LLDB_WATCH_ID_IS_VALID(uid)     ((uid) != (LLDB_INVALID_WATCH_ID))
 #define LLDB_WATCH_TYPE_READ            (1u << 0)
 #define LLDB_WATCH_TYPE_WRITE           (1u << 1)
+#define LLDB_WATCH_TYPE_IS_VALID(type)  ((type | LLDB_WATCH_TYPE_READ) || (type | LLDB_WATCH_TYPE_WRITE))
 
 //----------------------------------------------------------------------
 // Generic Register Numbers

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=184245&r1=184244&r2=184245&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Tue Jun 18 16:52:48 2013
@@ -1807,6 +1807,12 @@ SBTarget::WatchAddress (lldb::addr_t add
             watch_type |= LLDB_WATCH_TYPE_READ;
         if (write)
             watch_type |= LLDB_WATCH_TYPE_WRITE;
+        if (watch_type == 0)
+        {
+            error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
+            return sb_watchpoint;
+        }
+        
         // Target::CreateWatchpoint() is thread safe.
         Error cw_error;
         // This API doesn't take in a type, so we can't figure out what it is.

Modified: lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp?rev=184245&r1=184244&r2=184245&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp Tue Jun 18 16:52:48 2013
@@ -1066,6 +1066,7 @@ protected:
 
         // Now it's time to create the watchpoint.
         uint32_t watch_type = m_option_watchpoint.watch_type;
+        
         error.Clear();
         Watchpoint *wp = target->CreateWatchpoint(addr, size, &type, watch_type, error).get();
         if (wp)
@@ -1221,16 +1222,13 @@ protected:
         // If no argument is present, issue an error message.  There's no way to set a watchpoint.
         if (command.GetArgumentCount() == 0)
         {
-            result.GetErrorStream().Printf("error: required argument missing; specify an expression to evaulate into the addres to watch for\n");
+            result.GetErrorStream().Printf("error: required argument missing; specify an expression to evaulate into the address to watch for\n");
             result.SetStatus(eReturnStatusFailed);
             return false;
         }
 
-        bool with_dash_w = m_option_watchpoint.watch_type_specified;
-        bool with_dash_x = (m_option_watchpoint.watch_size != 0);
-
         // If no '-w' is specified, default to '-w write'.
-        if (!with_dash_w)
+        if (!m_option_watchpoint.watch_type_specified)
         {
             m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchWrite;
         }
@@ -1271,8 +1269,11 @@ protected:
             result.SetStatus(eReturnStatusFailed);
             return false;
         }
-        size = with_dash_x ? m_option_watchpoint.watch_size
-                           : target->GetArchitecture().GetAddressByteSize();
+        
+        if (m_option_watchpoint.watch_size != 0)
+            size = m_option_watchpoint.watch_size;
+        else
+            size = target->GetArchitecture().GetAddressByteSize();
 
         // Now it's time to create the watchpoint.
         uint32_t watch_type = m_option_watchpoint.watch_type;

Modified: lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp?rev=184245&r1=184244&r2=184245&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp Tue Jun 18 16:52:48 2013
@@ -77,11 +77,16 @@ OptionGroupWatchpoint::SetOptionValue (C
     switch (short_option)
     {
         case 'w':
-            watch_type = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
+        {
+            WatchType tmp_watch_type;
+            tmp_watch_type = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
             if (error.Success())
+            {
+                watch_type = tmp_watch_type;
                 watch_type_specified = true;
+            }
             break;
-
+        }
         case 'x':
             watch_size = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
             break;

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=184245&r1=184244&r2=184245&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Tue Jun 18 16:52:48 2013
@@ -564,6 +564,7 @@ Target::CreateWatchpoint(lldb::addr_t ad
         error.SetErrorString("process is not alive");
         return wp_sp;
     }
+    
     if (addr == LLDB_INVALID_ADDRESS || size == 0)
     {
         if (size == 0)
@@ -572,6 +573,11 @@ Target::CreateWatchpoint(lldb::addr_t ad
             error.SetErrorStringWithFormat("invalid watch address: %" PRIu64, addr);
         return wp_sp;
     }
+    
+    if (!LLDB_WATCH_TYPE_IS_VALID(kind))
+    {
+        error.SetErrorStringWithFormat ("invalid watchpoint type: %d", kind);
+    }
 
     // Currently we only support one watchpoint per address, with total number
     // of watchpoints limited by the hardware which the inferior is running on.
@@ -588,10 +594,13 @@ Target::CreateWatchpoint(lldb::addr_t ad
             (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
             (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
         // Return the existing watchpoint if both size and type match.
-        if (size == old_size && kind == old_type) {
+        if (size == old_size && kind == old_type)
+        {
             wp_sp = matched_sp;
             wp_sp->SetEnabled(false, notify);
-        } else {
+        }
+        else
+        {
             // Nil the matched watchpoint; we will be creating a new one.
             m_process_sp->DisableWatchpoint(matched_sp.get(), notify);
             m_watchpoint_list.Remove(matched_sp->GetID(), true);





More information about the lldb-commits mailing list