This revision was not accepted when it landed; it landed in state "Needs 
Revision".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL336955: Get rid of the C-string parameter in DoExecute 
(authored by teemperor, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D49207?vs=155079&id=155286#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D49207

Files:
  lldb/trunk/include/lldb/Interpreter/CommandObject.h
  lldb/trunk/include/lldb/Interpreter/CommandObjectRegexCommand.h
  lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
  lldb/trunk/source/Commands/CommandObjectCommands.cpp
  lldb/trunk/source/Commands/CommandObjectExpression.cpp
  lldb/trunk/source/Commands/CommandObjectExpression.h
  lldb/trunk/source/Commands/CommandObjectPlatform.cpp
  lldb/trunk/source/Commands/CommandObjectSettings.cpp
  lldb/trunk/source/Commands/CommandObjectThread.cpp
  lldb/trunk/source/Commands/CommandObjectType.cpp
  lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
  lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp
  lldb/trunk/source/Interpreter/CommandObjectScript.cpp
  lldb/trunk/source/Interpreter/CommandObjectScript.h
  lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
  lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h
  lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h

Index: lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp
===================================================================
--- lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp
+++ lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp
@@ -35,53 +35,47 @@
 //----------------------------------------------------------------------
 CommandObjectRegexCommand::~CommandObjectRegexCommand() {}
 
-bool CommandObjectRegexCommand::DoExecute(const char *command,
+bool CommandObjectRegexCommand::DoExecute(llvm::StringRef command,
                                           CommandReturnObject &result) {
-  if (command) {
-    EntryCollection::const_iterator pos, end = m_entries.end();
-    for (pos = m_entries.begin(); pos != end; ++pos) {
-      RegularExpression::Match regex_match(m_max_matches);
-
-      if (pos->regex.Execute(command, &regex_match)) {
-        std::string new_command(pos->command);
-        std::string match_str;
-        char percent_var[8];
-        size_t idx, percent_var_idx;
-        for (uint32_t match_idx = 1; match_idx <= m_max_matches; ++match_idx) {
-          if (regex_match.GetMatchAtIndex(command, match_idx, match_str)) {
-            const int percent_var_len =
-                ::snprintf(percent_var, sizeof(percent_var), "%%%u", match_idx);
-            for (idx = 0; (percent_var_idx = new_command.find(
-                               percent_var, idx)) != std::string::npos;) {
-              new_command.erase(percent_var_idx, percent_var_len);
-              new_command.insert(percent_var_idx, match_str);
-              idx += percent_var_idx + match_str.size();
-            }
+  EntryCollection::const_iterator pos, end = m_entries.end();
+  for (pos = m_entries.begin(); pos != end; ++pos) {
+    RegularExpression::Match regex_match(m_max_matches);
+
+    if (pos->regex.Execute(command, &regex_match)) {
+      std::string new_command(pos->command);
+      std::string match_str;
+      char percent_var[8];
+      size_t idx, percent_var_idx;
+      for (uint32_t match_idx = 1; match_idx <= m_max_matches; ++match_idx) {
+        if (regex_match.GetMatchAtIndex(command, match_idx, match_str)) {
+          const int percent_var_len =
+              ::snprintf(percent_var, sizeof(percent_var), "%%%u", match_idx);
+          for (idx = 0; (percent_var_idx = new_command.find(
+                             percent_var, idx)) != std::string::npos;) {
+            new_command.erase(percent_var_idx, percent_var_len);
+            new_command.insert(percent_var_idx, match_str);
+            idx += percent_var_idx + match_str.size();
           }
         }
-        // Interpret the new command and return this as the result!
-        if (m_interpreter.GetExpandRegexAliases())
-          result.GetOutputStream().Printf("%s\n", new_command.c_str());
-        // Pass in true for "no context switching".  The command that called us
-        // should have set up the context appropriately, we shouldn't have to
-        // redo that.
-        return m_interpreter.HandleCommand(new_command.c_str(),
-                                           eLazyBoolCalculate, result, nullptr,
-                                           true, true);
       }
+      // Interpret the new command and return this as the result!
+      if (m_interpreter.GetExpandRegexAliases())
+        result.GetOutputStream().Printf("%s\n", new_command.c_str());
+      // Pass in true for "no context switching".  The command that called us
+      // should have set up the context appropriately, we shouldn't have to
+      // redo that.
+      return m_interpreter.HandleCommand(
+          new_command.c_str(), eLazyBoolCalculate, result, nullptr, true, true);
     }
-    result.SetStatus(eReturnStatusFailed);
-    if (!GetSyntax().empty())
-      result.AppendError(GetSyntax());
-    else
-      result.AppendErrorWithFormat("Command contents '%s' failed to match any "
-                                   "regular expression in the '%s' regex "
-                                   "command.\n",
-                                   command, m_cmd_name.c_str());
-    return false;
   }
-  result.AppendError("empty command passed to regular expression command");
   result.SetStatus(eReturnStatusFailed);
+  if (!GetSyntax().empty())
+    result.AppendError(GetSyntax());
+  else
+    result.GetOutputStream() << "Command contents '" << command
+                             << "' failed to match any "
+                                "regular expression in the '"
+                             << m_cmd_name << "' regex ";
   return false;
 }
 
Index: lldb/trunk/source/Interpreter/CommandObjectScript.cpp
===================================================================
--- lldb/trunk/source/Interpreter/CommandObjectScript.cpp
+++ lldb/trunk/source/Interpreter/CommandObjectScript.cpp
@@ -40,7 +40,7 @@
 
 CommandObjectScript::~CommandObjectScript() {}
 
-bool CommandObjectScript::DoExecute(const char *command,
+bool CommandObjectScript::DoExecute(llvm::StringRef command,
                                     CommandReturnObject &result) {
 #ifdef LLDB_DISABLE_PYTHON
   // if we ever support languages other than Python this simple #ifdef won't
@@ -69,7 +69,7 @@
                                     // for formatting.. make sure we keep up to
                                     // date with it
 
-  if (command == nullptr || command[0] == '\0') {
+  if (command.empty()) {
     script_interpreter->ExecuteInterpreterLoop();
     result.SetStatus(eReturnStatusSuccessFinishNoResult);
     return result.Succeeded();
Index: lldb/trunk/source/Interpreter/CommandObjectScript.h
===================================================================
--- lldb/trunk/source/Interpreter/CommandObjectScript.h
+++ lldb/trunk/source/Interpreter/CommandObjectScript.h
@@ -30,7 +30,7 @@
   ~CommandObjectScript() override;
 
 protected:
-  bool DoExecute(const char *command, CommandReturnObject &result) override;
+  bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override;
 };
 
 } // namespace lldb_private
Index: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -5244,8 +5244,9 @@
 
   ~CommandObjectProcessGDBRemotePacketMonitor() {}
 
-  bool DoExecute(const char *command, CommandReturnObject &result) override {
-    if (command == NULL || command[0] == '\0') {
+  bool DoExecute(llvm::StringRef command,
+                 CommandReturnObject &result) override {
+    if (command.empty()) {
       result.AppendErrorWithFormat("'%s' takes a command string argument",
                                    m_cmd_name.c_str());
       result.SetStatus(eReturnStatusFailed);
@@ -5257,7 +5258,7 @@
     if (process) {
       StreamString packet;
       packet.PutCString("qRcmd,");
-      packet.PutBytesAsRawHex8(command, strlen(command));
+      packet.PutBytesAsRawHex8(command.data(), command.size());
 
       bool send_async = true;
       StringExtractorGDBRemote response;
Index: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
===================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
@@ -151,14 +151,14 @@
   bool Interrupt() override;
 
   bool ExecuteOneLine(
-      const char *command, CommandReturnObject *result,
+      llvm::StringRef command, CommandReturnObject *result,
       const ExecuteScriptOptions &options = ExecuteScriptOptions()) override;
 
   void ExecuteInterpreterLoop() override;
 
   bool ExecuteOneLineWithReturn(
-      const char *in_string, ScriptInterpreter::ScriptReturnType return_type,
-      void *ret_value,
+      llvm::StringRef in_string,
+      ScriptInterpreter::ScriptReturnType return_type, void *ret_value,
       const ExecuteScriptOptions &options = ExecuteScriptOptions()) override;
 
   lldb_private::Status ExecuteMultipleLines(
@@ -259,18 +259,17 @@
   GetSyntheticTypeName(const StructuredData::ObjectSP &implementor) override;
 
   bool
-  RunScriptBasedCommand(const char *impl_function, const char *args,
+  RunScriptBasedCommand(const char *impl_function, llvm::StringRef args,
                         ScriptedCommandSynchronicity synchronicity,
                         lldb_private::CommandReturnObject &cmd_retobj,
                         Status &error,
                         const lldb_private::ExecutionContext &exe_ctx) override;
 
-  bool
-  RunScriptBasedCommand(StructuredData::GenericSP impl_obj_sp, const char *args,
-                        ScriptedCommandSynchronicity synchronicity,
-                        lldb_private::CommandReturnObject &cmd_retobj,
-                        Status &error,
-                        const lldb_private::ExecutionContext &exe_ctx) override;
+  bool RunScriptBasedCommand(
+      StructuredData::GenericSP impl_obj_sp, llvm::StringRef args,
+      ScriptedCommandSynchronicity synchronicity,
+      lldb_private::CommandReturnObject &cmd_retobj, Status &error,
+      const lldb_private::ExecutionContext &exe_ctx) override;
 
   Status GenerateFunction(const char *signature,
                           const StringList &input) override;
Index: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -751,12 +751,12 @@
 }
 
 bool ScriptInterpreterPython::ExecuteOneLine(
-    const char *command, CommandReturnObject *result,
+    llvm::StringRef command, CommandReturnObject *result,
     const ExecuteScriptOptions &options) {
   if (!m_valid_session)
     return false;
 
-  if (command && command[0]) {
+  if (!command.empty()) {
     // We want to call run_one_line, passing in the dictionary and the command
     // string.  We cannot do this through PyRun_SimpleString here because the
     // command string may contain escaped characters, and putting it inside
@@ -894,9 +894,11 @@
       return true;
 
     // The one-liner failed.  Append the error message.
-    if (result)
+    if (result) {
+      std::string command_str = command.str();
       result->AppendErrorWithFormat(
-          "python failed attempting to evaluate '%s'\n", command);
+          "python failed attempting to evaluate '%s'\n", command_str.c_str());
+    }
     return false;
   }
 
@@ -1021,7 +1023,7 @@
   return false;
 }
 bool ScriptInterpreterPython::ExecuteOneLineWithReturn(
-    const char *in_string, ScriptInterpreter::ScriptReturnType return_type,
+    llvm::StringRef in_string, ScriptInterpreter::ScriptReturnType return_type,
     void *ret_value, const ExecuteScriptOptions &options) {
 
   Locker locker(this, ScriptInterpreterPython::Locker::AcquireLock |
@@ -1056,116 +1058,114 @@
   if (py_error.IsValid())
     PyErr_Clear();
 
-  if (in_string != nullptr) {
-    { // scope for PythonInputReaderManager
-      // PythonInputReaderManager py_input(options.GetEnableIO() ? this : NULL);
-      py_return.Reset(
-          PyRefType::Owned,
-          PyRun_String(in_string, Py_eval_input, globals.get(), locals.get()));
-      if (!py_return.IsValid()) {
-        py_error.Reset(PyRefType::Borrowed, PyErr_Occurred());
-        if (py_error.IsValid())
-          PyErr_Clear();
-
-        py_return.Reset(PyRefType::Owned,
-                        PyRun_String(in_string, Py_single_input, globals.get(),
-                                     locals.get()));
-      }
+  std::string as_string = in_string.str();
+  { // scope for PythonInputReaderManager
+    // PythonInputReaderManager py_input(options.GetEnableIO() ? this : NULL);
+    py_return.Reset(PyRefType::Owned,
+                    PyRun_String(as_string.c_str(), Py_eval_input,
+                                 globals.get(), locals.get()));
+    if (!py_return.IsValid()) {
+      py_error.Reset(PyRefType::Borrowed, PyErr_Occurred());
+      if (py_error.IsValid())
+        PyErr_Clear();
+
+      py_return.Reset(PyRefType::Owned,
+                      PyRun_String(as_string.c_str(), Py_single_input,
+                                   globals.get(), locals.get()));
     }
+  }
 
-    if (py_return.IsValid()) {
-      switch (return_type) {
-      case eScriptReturnTypeCharPtr: // "char *"
-      {
-        const char format[3] = "s#";
-        success = PyArg_Parse(py_return.get(), format, (char **)ret_value);
-        break;
-      }
-      case eScriptReturnTypeCharStrOrNone: // char* or NULL if py_return ==
-                                           // Py_None
-        {
-          const char format[3] = "z";
-          success = PyArg_Parse(py_return.get(), format, (char **)ret_value);
-          break;
-        }
-      case eScriptReturnTypeBool: {
-        const char format[2] = "b";
-        success = PyArg_Parse(py_return.get(), format, (bool *)ret_value);
-        break;
-      }
-      case eScriptReturnTypeShortInt: {
-        const char format[2] = "h";
-        success = PyArg_Parse(py_return.get(), format, (short *)ret_value);
-        break;
-      }
-      case eScriptReturnTypeShortIntUnsigned: {
-        const char format[2] = "H";
-        success =
-            PyArg_Parse(py_return.get(), format, (unsigned short *)ret_value);
-        break;
-      }
-      case eScriptReturnTypeInt: {
-        const char format[2] = "i";
-        success = PyArg_Parse(py_return.get(), format, (int *)ret_value);
-        break;
-      }
-      case eScriptReturnTypeIntUnsigned: {
-        const char format[2] = "I";
-        success =
-            PyArg_Parse(py_return.get(), format, (unsigned int *)ret_value);
-        break;
-      }
-      case eScriptReturnTypeLongInt: {
-        const char format[2] = "l";
-        success = PyArg_Parse(py_return.get(), format, (long *)ret_value);
-        break;
-      }
-      case eScriptReturnTypeLongIntUnsigned: {
-        const char format[2] = "k";
-        success =
-            PyArg_Parse(py_return.get(), format, (unsigned long *)ret_value);
-        break;
-      }
-      case eScriptReturnTypeLongLong: {
-        const char format[2] = "L";
-        success = PyArg_Parse(py_return.get(), format, (long long *)ret_value);
-        break;
-      }
-      case eScriptReturnTypeLongLongUnsigned: {
-        const char format[2] = "K";
-        success = PyArg_Parse(py_return.get(), format,
-                              (unsigned long long *)ret_value);
-        break;
-      }
-      case eScriptReturnTypeFloat: {
-        const char format[2] = "f";
-        success = PyArg_Parse(py_return.get(), format, (float *)ret_value);
-        break;
-      }
-      case eScriptReturnTypeDouble: {
-        const char format[2] = "d";
-        success = PyArg_Parse(py_return.get(), format, (double *)ret_value);
-        break;
-      }
-      case eScriptReturnTypeChar: {
-        const char format[2] = "c";
-        success = PyArg_Parse(py_return.get(), format, (char *)ret_value);
-        break;
-      }
-      case eScriptReturnTypeOpaqueObject: {
-        success = true;
-        PyObject *saved_value = py_return.get();
-        Py_XINCREF(saved_value);
-        *((PyObject **)ret_value) = saved_value;
-        break;
-      }
-      }
-
-      if (success)
-        ret_success = true;
-      else
-        ret_success = false;
+  if (py_return.IsValid()) {
+    switch (return_type) {
+    case eScriptReturnTypeCharPtr: // "char *"
+    {
+      const char format[3] = "s#";
+      success = PyArg_Parse(py_return.get(), format, (char **)ret_value);
+      break;
     }
+    case eScriptReturnTypeCharStrOrNone: // char* or NULL if py_return ==
+                                         // Py_None
+    {
+      const char format[3] = "z";
+      success = PyArg_Parse(py_return.get(), format, (char **)ret_value);
+      break;
+    }
+    case eScriptReturnTypeBool: {
+      const char format[2] = "b";
+      success = PyArg_Parse(py_return.get(), format, (bool *)ret_value);
+      break;
+    }
+    case eScriptReturnTypeShortInt: {
+      const char format[2] = "h";
+      success = PyArg_Parse(py_return.get(), format, (short *)ret_value);
+      break;
+    }
+    case eScriptReturnTypeShortIntUnsigned: {
+      const char format[2] = "H";
+      success =
+          PyArg_Parse(py_return.get(), format, (unsigned short *)ret_value);
+      break;
+    }
+    case eScriptReturnTypeInt: {
+      const char format[2] = "i";
+      success = PyArg_Parse(py_return.get(), format, (int *)ret_value);
+      break;
+    }
+    case eScriptReturnTypeIntUnsigned: {
+      const char format[2] = "I";
+      success = PyArg_Parse(py_return.get(), format, (unsigned int *)ret_value);
+      break;
+    }
+    case eScriptReturnTypeLongInt: {
+      const char format[2] = "l";
+      success = PyArg_Parse(py_return.get(), format, (long *)ret_value);
+      break;
+    }
+    case eScriptReturnTypeLongIntUnsigned: {
+      const char format[2] = "k";
+      success =
+          PyArg_Parse(py_return.get(), format, (unsigned long *)ret_value);
+      break;
+    }
+    case eScriptReturnTypeLongLong: {
+      const char format[2] = "L";
+      success = PyArg_Parse(py_return.get(), format, (long long *)ret_value);
+      break;
+    }
+    case eScriptReturnTypeLongLongUnsigned: {
+      const char format[2] = "K";
+      success =
+          PyArg_Parse(py_return.get(), format, (unsigned long long *)ret_value);
+      break;
+    }
+    case eScriptReturnTypeFloat: {
+      const char format[2] = "f";
+      success = PyArg_Parse(py_return.get(), format, (float *)ret_value);
+      break;
+    }
+    case eScriptReturnTypeDouble: {
+      const char format[2] = "d";
+      success = PyArg_Parse(py_return.get(), format, (double *)ret_value);
+      break;
+    }
+    case eScriptReturnTypeChar: {
+      const char format[2] = "c";
+      success = PyArg_Parse(py_return.get(), format, (char *)ret_value);
+      break;
+    }
+    case eScriptReturnTypeOpaqueObject: {
+      success = true;
+      PyObject *saved_value = py_return.get();
+      Py_XINCREF(saved_value);
+      *((PyObject **)ret_value) = saved_value;
+      break;
+    }
+    }
+
+    if (success)
+      ret_success = true;
+    else
+      ret_success = false;
   }
 
   py_error.Reset(PyRefType::Borrowed, PyErr_Occurred());
@@ -2779,7 +2779,7 @@
 }
 
 bool ScriptInterpreterPython::RunScriptBasedCommand(
-    const char *impl_function, const char *args,
+    const char *impl_function, llvm::StringRef args,
     ScriptedCommandSynchronicity synchronicity,
     lldb_private::CommandReturnObject &cmd_retobj, Status &error,
     const lldb_private::ExecutionContext &exe_ctx) {
@@ -2813,9 +2813,10 @@
 
     SynchronicityHandler synch_handler(debugger_sp, synchronicity);
 
-    ret_val =
-        g_swig_call_command(impl_function, m_dictionary_name.c_str(),
-                            debugger_sp, args, cmd_retobj, exe_ctx_ref_sp);
+    std::string args_str = args.str();
+    ret_val = g_swig_call_command(impl_function, m_dictionary_name.c_str(),
+                                  debugger_sp, args_str.c_str(), cmd_retobj,
+                                  exe_ctx_ref_sp);
   }
 
   if (!ret_val)
@@ -2827,7 +2828,7 @@
 }
 
 bool ScriptInterpreterPython::RunScriptBasedCommand(
-    StructuredData::GenericSP impl_obj_sp, const char *args,
+    StructuredData::GenericSP impl_obj_sp, llvm::StringRef args,
     ScriptedCommandSynchronicity synchronicity,
     lldb_private::CommandReturnObject &cmd_retobj, Status &error,
     const lldb_private::ExecutionContext &exe_ctx) {
@@ -2861,8 +2862,10 @@
 
     SynchronicityHandler synch_handler(debugger_sp, synchronicity);
 
+    std::string args_str = args.str();
     ret_val = g_swig_call_command_object(impl_obj_sp->GetValue(), debugger_sp,
-                                         args, cmd_retobj, exe_ctx_ref_sp);
+                                         args_str.c_str(), cmd_retobj,
+                                         exe_ctx_ref_sp);
   }
 
   if (!ret_val)
Index: lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h
===================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h
+++ lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h
@@ -25,7 +25,7 @@
   ~ScriptInterpreterNone() override;
 
   bool ExecuteOneLine(
-      const char *command, CommandReturnObject *result,
+      llvm::StringRef command, CommandReturnObject *result,
       const ExecuteScriptOptions &options = ExecuteScriptOptions()) override;
 
   void ExecuteInterpreterLoop() override;
Index: lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
===================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
+++ lldb/trunk/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
@@ -27,7 +27,7 @@
 
 ScriptInterpreterNone::~ScriptInterpreterNone() {}
 
-bool ScriptInterpreterNone::ExecuteOneLine(const char *command,
+bool ScriptInterpreterNone::ExecuteOneLine(llvm::StringRef command,
                                            CommandReturnObject *,
                                            const ExecuteScriptOptions &) {
   m_interpreter.GetDebugger().GetErrorFile()->PutCString(
Index: lldb/trunk/source/Commands/CommandObjectThread.cpp
===================================================================
--- lldb/trunk/source/Commands/CommandObjectThread.cpp
+++ lldb/trunk/source/Commands/CommandObjectThread.cpp
@@ -1603,12 +1603,13 @@
   Options *GetOptions() override { return &m_options; }
 
 protected:
-  bool DoExecute(const char *command, CommandReturnObject &result) override {
+  bool DoExecute(llvm::StringRef command,
+                 CommandReturnObject &result) override {
     // I am going to handle this by hand, because I don't want you to have to
     // say:
     // "thread return -- -5".
-    if (command[0] == '-' && command[1] == 'x') {
-      if (command && command[2] != '\0')
+    if (command.startswith("-x")) {
+      if (command.size() != 2U)
         result.AppendWarning("Return values ignored when returning from user "
                              "called expressions");
 
@@ -1645,7 +1646,7 @@
       return false;
     }
 
-    if (command && command[0] != '\0') {
+    if (!command.empty()) {
       Target *target = m_exe_ctx.GetTargetPtr();
       EvaluateExpressionOptions options;
 
Index: lldb/trunk/source/Commands/CommandObjectSettings.cpp
===================================================================
--- lldb/trunk/source/Commands/CommandObjectSettings.cpp
+++ lldb/trunk/source/Commands/CommandObjectSettings.cpp
@@ -188,7 +188,8 @@
   }
 
 protected:
-  bool DoExecute(const char *command, CommandReturnObject &result) override {
+  bool DoExecute(llvm::StringRef command,
+                 CommandReturnObject &result) override {
     Args cmd_args(command);
 
     // Process possible options.
@@ -467,7 +468,8 @@
   }
 
 protected:
-  bool DoExecute(const char *command, CommandReturnObject &result) override {
+  bool DoExecute(llvm::StringRef command,
+                 CommandReturnObject &result) override {
     result.SetStatus(eReturnStatusSuccessFinishNoResult);
 
     Args cmd_args(command);
@@ -591,7 +593,8 @@
   }
 
 protected:
-  bool DoExecute(const char *command, CommandReturnObject &result) override {
+  bool DoExecute(llvm::StringRef command,
+                 CommandReturnObject &result) override {
     result.SetStatus(eReturnStatusSuccessFinishNoResult);
 
     Args cmd_args(command);
@@ -698,7 +701,8 @@
   }
 
 protected:
-  bool DoExecute(const char *command, CommandReturnObject &result) override {
+  bool DoExecute(llvm::StringRef command,
+                 CommandReturnObject &result) override {
     result.SetStatus(eReturnStatusSuccessFinishNoResult);
 
     Args cmd_args(command);
@@ -810,7 +814,8 @@
   }
 
 protected:
-  bool DoExecute(const char *command, CommandReturnObject &result) override {
+  bool DoExecute(llvm::StringRef command,
+                 CommandReturnObject &result) override {
     result.SetStatus(eReturnStatusSuccessFinishNoResult);
 
     Args cmd_args(command);
@@ -911,7 +916,8 @@
   }
 
 protected:
-  bool DoExecute(const char *command, CommandReturnObject &result) override {
+  bool DoExecute(llvm::StringRef command,
+                 CommandReturnObject &result) override {
     result.SetStatus(eReturnStatusSuccessFinishNoResult);
     Args cmd_args(command);
     const size_t argc = cmd_args.GetArgumentCount();
Index: lldb/trunk/source/Commands/CommandObjectExpression.cpp
===================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.cpp
+++ lldb/trunk/source/Commands/CommandObjectExpression.cpp
@@ -318,7 +318,7 @@
   return Status();
 }
 
-bool CommandObjectExpression::EvaluateExpression(const char *expr,
+bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
                                                  Stream *output_stream,
                                                  Stream *error_stream,
                                                  CommandReturnObject *result) {
@@ -508,19 +508,19 @@
   debugger.PushIOHandler(io_handler_sp);
 }
 
-bool CommandObjectExpression::DoExecute(const char *command,
+bool CommandObjectExpression::DoExecute(llvm::StringRef command,
                                         CommandReturnObject &result) {
   m_fixed_expression.clear();
   auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
   m_option_group.NotifyOptionParsingStarting(&exe_ctx);
 
-  if (command[0] == '\0') {
+  if (command.empty()) {
     GetMultilineExpression();
     return result.Succeeded();
   }
 
   OptionsWithRaw args(command);
-  const char *expr = args.GetRawPart().c_str();
+  llvm::StringRef expr = args.GetRawPart();
 
   if (args.HasArgs()) {
     if (!ParseOptionsAndNotify(args.GetArgs(), result, m_option_group, exe_ctx))
@@ -584,7 +584,7 @@
       }
     }
     // No expression following options
-    else if (expr[0] == '\0') {
+    else if (expr.empty()) {
       GetMultilineExpression();
       return result.Succeeded();
     }
Index: lldb/trunk/source/Commands/CommandObjectPlatform.cpp
===================================================================
--- lldb/trunk/source/Commands/CommandObjectPlatform.cpp
+++ lldb/trunk/source/Commands/CommandObjectPlatform.cpp
@@ -1742,14 +1742,14 @@
 
   Options *GetOptions() override { return &m_options; }
 
-  bool DoExecute(const char *raw_command_line,
+  bool DoExecute(llvm::StringRef raw_command_line,
                  CommandReturnObject &result) override {
     ExecutionContext exe_ctx = GetCommandInterpreter().GetExecutionContext();
     m_options.NotifyOptionParsingStarting(&exe_ctx);
 
 
     // Print out an usage syntax on an empty command line.
-    if (raw_command_line[0] == '\0') {
+    if (raw_command_line.empty()) {
       result.GetOutputStream().Printf("%s\n", this->GetSyntax().str().c_str());
       return true;
     }
Index: lldb/trunk/source/Commands/CommandObjectType.cpp
===================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp
+++ lldb/trunk/source/Commands/CommandObjectType.cpp
@@ -2862,9 +2862,9 @@
     return m_cmd_help_long;
   }
 
-  bool DoExecute(const char *raw_command_line,
+  bool DoExecute(llvm::StringRef raw_command_line,
                  CommandReturnObject &result) override {
-    if (!raw_command_line || !raw_command_line[0]) {
+    if (raw_command_line.empty()) {
       result.SetError(
           "type lookup cannot be invoked without a type name as argument");
       return false;
@@ -2994,7 +2994,8 @@
   ~CommandObjectFormatterInfo() override = default;
 
 protected:
-  bool DoExecute(const char *command, CommandReturnObject &result) override {
+  bool DoExecute(llvm::StringRef command,
+                 CommandReturnObject &result) override {
     TargetSP target_sp = m_interpreter.GetDebugger().GetSelectedTarget();
     Thread *thread = GetDefaultThread();
     if (!thread) {
@@ -3017,16 +3018,16 @@
           m_discovery_function(*result_valobj_sp);
       if (formatter_sp) {
         std::string description(formatter_sp->GetDescription());
-        result.AppendMessageWithFormat(
-            "%s applied to (%s) %s is: %s\n", m_formatter_name.c_str(),
-            result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>"),
-            command, description.c_str());
+        result.GetOutputStream()
+            << m_formatter_name << " applied to ("
+            << result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>")
+            << ") " << command << " is: " << description << "\n";
         result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
       } else {
-        result.AppendMessageWithFormat(
-            "no %s applies to (%s) %s\n", m_formatter_name.c_str(),
-            result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>"),
-            command);
+        result.GetOutputStream()
+            << "no " << m_formatter_name << " applies to ("
+            << result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>")
+            << ") " << command << "\n";
         result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult);
       }
       return true;
Index: lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
===================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
+++ lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
@@ -1026,7 +1026,7 @@
   Options *GetOptions() override { return &m_option_group; }
 
 protected:
-  bool DoExecute(const char *raw_command,
+  bool DoExecute(llvm::StringRef raw_command,
                  CommandReturnObject &result) override {
     auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
     m_option_group.NotifyOptionParsingStarting(
@@ -1046,7 +1046,7 @@
 
     // If no argument is present, issue an error message.  There's no way to
     // set a watchpoint.
-    if (llvm::StringRef(raw_command).trim().empty()) {
+    if (raw_command.trim().empty()) {
       result.GetErrorStream().Printf("error: required argument missing; "
                                      "specify an expression to evaulate into "
                                      "the address to watch for\n");
Index: lldb/trunk/source/Commands/CommandObjectExpression.h
===================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.h
+++ lldb/trunk/source/Commands/CommandObjectExpression.h
@@ -72,9 +72,9 @@
   bool IOHandlerIsInputComplete(IOHandler &io_handler,
                                 StringList &lines) override;
 
-  bool DoExecute(const char *command, CommandReturnObject &result) override;
+  bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override;
 
-  bool EvaluateExpression(const char *expr, Stream *output_stream,
+  bool EvaluateExpression(llvm::StringRef expr, Stream *output_stream,
                           Stream *error_stream,
                           CommandReturnObject *result = NULL);
 
Index: lldb/trunk/source/Commands/CommandObjectCommands.cpp
===================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp
@@ -543,9 +543,9 @@
   ~CommandObjectCommandsAlias() override = default;
 
 protected:
-  bool DoExecute(const char *raw_command_line,
+  bool DoExecute(llvm::StringRef raw_command_line,
                  CommandReturnObject &result) override {
-    if (!raw_command_line || !raw_command_line[0]) {
+    if (raw_command_line.empty()) {
       result.AppendError("'command alias' requires at least two arguments");
       return false;
     }
@@ -1275,7 +1275,7 @@
   }
 
 protected:
-  bool DoExecute(const char *raw_command_line,
+  bool DoExecute(llvm::StringRef raw_command_line,
                  CommandReturnObject &result) override {
     ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
 
@@ -1364,7 +1364,7 @@
   }
 
 protected:
-  bool DoExecute(const char *raw_command_line,
+  bool DoExecute(llvm::StringRef raw_command_line,
                  CommandReturnObject &result) override {
     ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
 
Index: lldb/trunk/include/lldb/Interpreter/CommandObject.h
===================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObject.h
+++ lldb/trunk/include/lldb/Interpreter/CommandObject.h
@@ -434,7 +434,8 @@
   bool Execute(const char *args_string, CommandReturnObject &result) override;
 
 protected:
-  virtual bool DoExecute(const char *command, CommandReturnObject &result) = 0;
+  virtual bool DoExecute(llvm::StringRef command,
+                         CommandReturnObject &result) = 0;
 
   bool WantsRawCommandString() override { return true; }
 };
Index: lldb/trunk/include/lldb/Interpreter/CommandObjectRegexCommand.h
===================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObjectRegexCommand.h
+++ lldb/trunk/include/lldb/Interpreter/CommandObjectRegexCommand.h
@@ -43,7 +43,7 @@
   int HandleCompletion(CompletionRequest &request) override;
 
 protected:
-  bool DoExecute(const char *command, CommandReturnObject &result) override;
+  bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override;
 
   struct Entry {
     RegularExpression regex;
Index: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
===================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
@@ -96,13 +96,13 @@
   virtual bool Interrupt() { return false; }
 
   virtual bool ExecuteOneLine(
-      const char *command, CommandReturnObject *result,
+      llvm::StringRef command, CommandReturnObject *result,
       const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
 
   virtual void ExecuteInterpreterLoop() = 0;
 
   virtual bool ExecuteOneLineWithReturn(
-      const char *in_string, ScriptReturnType return_type, void *ret_value,
+      llvm::StringRef in_string, ScriptReturnType return_type, void *ret_value,
       const ExecuteScriptOptions &options = ExecuteScriptOptions()) {
     return true;
   }
@@ -343,20 +343,19 @@
   }
 
   virtual bool
-  RunScriptBasedCommand(const char *impl_function, const char *args,
+  RunScriptBasedCommand(const char *impl_function, llvm::StringRef args,
                         ScriptedCommandSynchronicity synchronicity,
                         lldb_private::CommandReturnObject &cmd_retobj,
                         Status &error,
                         const lldb_private::ExecutionContext &exe_ctx) {
     return false;
   }
 
-  virtual bool
-  RunScriptBasedCommand(StructuredData::GenericSP impl_obj_sp, const char *args,
-                        ScriptedCommandSynchronicity synchronicity,
-                        lldb_private::CommandReturnObject &cmd_retobj,
-                        Status &error,
-                        const lldb_private::ExecutionContext &exe_ctx) {
+  virtual bool RunScriptBasedCommand(
+      StructuredData::GenericSP impl_obj_sp, llvm::StringRef args,
+      ScriptedCommandSynchronicity synchronicity,
+      lldb_private::CommandReturnObject &cmd_retobj, Status &error,
+      const lldb_private::ExecutionContext &exe_ctx) {
     return false;
   }
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to