[Lldb-commits] [lldb] r150195 - in /lldb/trunk: source/Commands/CommandObjectWatchpoint.cpp test/functionalities/watchpoint/watchpoint_set_command/TestWatchpointSetErrorCases.py

Johnny Chen johnny.chen at apple.com
Thu Feb 9 10:44:27 PST 2012


Author: johnny
Date: Thu Feb  9 12:44:27 2012
New Revision: 150195

URL: http://llvm.org/viewvc/llvm-project?rev=150195&view=rev
Log:
Add error handling for missing option terminator "--" and a test scenario for it.
Also fix a logic error for a missing return stmt. Oops.

Modified:
    lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
    lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchpointSetErrorCases.py

Modified: lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp?rev=150195&r1=150194&r2=150195&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp Thu Feb  9 12:44:27 2012
@@ -1129,11 +1129,11 @@
         return false;
     }
 
-    bool no_dash_w = !m_option_watchpoint.watch_type_specified;
-    bool no_dash_x = (m_option_watchpoint.watch_size == 0);
+    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 read_write'.
-    if (no_dash_w)
+    if (!with_dash_w)
     {
         m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchReadWrite;
     }
@@ -1149,7 +1149,15 @@
 
     // We will process the raw command string to rid of the '-w', '-x', or '--'
     llvm::StringRef raw_expr_str(raw_command);
-    std::string expr_str = StripOptionTerminator(raw_expr_str, !no_dash_w, !no_dash_x).str();
+    std::string expr_str = StripOptionTerminator(raw_expr_str, with_dash_w, with_dash_x).str();
+
+    // Sanity check for when the user forgets to terminate the option strings with a '--'.
+    if ((with_dash_w || with_dash_w) && expr_str.empty())
+    {
+        result.GetErrorStream().Printf("error: did you forget to enter the option terminator string \"--\"?\n");
+        result.SetStatus(eReturnStatusFailed);
+        return false;
+    }
 
     // Use expression evaluation to arrive at the address to watch.
     const bool coerce_to_id = true;
@@ -1167,6 +1175,7 @@
         result.GetErrorStream().Printf("error: expression evaluation of address to watch failed\n");
         result.GetErrorStream().Printf("expression evaluated: %s\n", expr_str.c_str());
         result.SetStatus(eReturnStatusFailed);
+        return false;
     }
 
     // Get the address to watch.
@@ -1176,8 +1185,8 @@
         result.SetStatus(eReturnStatusFailed);
         return false;
     }
-    size = no_dash_x ? target->GetArchitecture().GetAddressByteSize()
-                     : m_option_watchpoint.watch_size;
+    size = with_dash_x ? m_option_watchpoint.watch_size
+                       : target->GetArchitecture().GetAddressByteSize();
 
     // Now it's time to create the watchpoint.
     uint32_t watch_type = m_option_watchpoint.watch_type;

Modified: lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchpointSetErrorCases.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchpointSetErrorCases.py?rev=150195&r1=150194&r2=150195&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchpointSetErrorCases.py (original)
+++ lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchpointSetErrorCases.py Thu Feb  9 12:44:27 2012
@@ -61,6 +61,10 @@
         self.expect("watchpoint set expression -w write --", error=True,
             startstr = 'error: required argument missing; specify an expression to evaulate into the addres to watch for')
 
+        # Check for missing option terminator '--'.
+        self.expect("watchpoint set expression -w write -x 1 g_char_ptr", error=True,
+            startstr = 'error: did you forget to enter the option terminator string "--"?')
+
         # Wrong size parameter is an error.
         self.expect("watchpoint set variable -x -128", error=True,
             substrs = ['invalid enumeration value'])





More information about the lldb-commits mailing list