[Lldb-commits] [lldb] 7c6e52a - [lldb] Ptrs->refs in CommandObjectExpression::EvaluateExpression parameters

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 17 05:23:40 PDT 2020


Author: Raphael Isemann
Date: 2020-03-17T13:23:16+01:00
New Revision: 7c6e52ac0ce5a6879331bc3c322dd20bfec3bf14

URL: https://github.com/llvm/llvm-project/commit/7c6e52ac0ce5a6879331bc3c322dd20bfec3bf14
DIFF: https://github.com/llvm/llvm-project/commit/7c6e52ac0ce5a6879331bc3c322dd20bfec3bf14.diff

LOG: [lldb] Ptrs->refs in CommandObjectExpression::EvaluateExpression parameters

The error_stream and result parameter were inconsistently checked for
being null, so we might as well make them references instead of crashing
in case someone passes a nullptr and hits one of the code paths that are
currently not doing a nullptr check on those parameters. Also change
output_stream for consistency.

Added: 
    

Modified: 
    lldb/source/Commands/CommandObjectExpression.cpp
    lldb/source/Commands/CommandObjectExpression.h

Removed: 
    


################################################################################
diff  --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index 388f9f0af66a..7d8de573df0e 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -403,9 +403,9 @@ CommandObjectExpression::GetEvalOptions(const Target &target) {
 }
 
 bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
-                                                 Stream *output_stream,
-                                                 Stream *error_stream,
-                                                 CommandReturnObject *result) {
+                                                 Stream &output_stream,
+                                                 Stream &error_stream,
+                                                 CommandReturnObject &result) {
   // Don't use m_exe_ctx as this might be called asynchronously after the
   // command object DoExecute has finished when doing multi-line expression
   // that use an input reader...
@@ -425,11 +425,10 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
 
   // We only tell you about the FixIt if we applied it.  The compiler errors
   // will suggest the FixIt if it parsed.
-  if (error_stream && !m_fixed_expression.empty() &&
-      target->GetEnableNotifyAboutFixIts()) {
+  if (!m_fixed_expression.empty() && target->GetEnableNotifyAboutFixIts()) {
     if (success == eExpressionCompleted)
-      error_stream->Printf("  Fix-it applied, fixed expression was: \n    %s\n",
-                           m_fixed_expression.c_str());
+      error_stream.Printf("  Fix-it applied, fixed expression was: \n    %s\n",
+                          m_fixed_expression.c_str());
   }
 
   if (result_valobj_sp) {
@@ -443,10 +442,10 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
         if (m_varobj_options.elem_count > 0) {
           Status error(CanBeUsedForElementCountPrinting(*result_valobj_sp));
           if (error.Fail()) {
-            result->AppendErrorWithFormat(
+            result.AppendErrorWithFormat(
                 "expression cannot be used with --element-count %s\n",
                 error.AsCString(""));
-            result->SetStatus(eReturnStatusFailed);
+            result.SetStatus(eReturnStatusFailed);
             return false;
           }
         }
@@ -456,36 +455,33 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
         options.SetVariableFormatDisplayLanguage(
             result_valobj_sp->GetPreferredDisplayLanguage());
 
-        result_valobj_sp->Dump(*output_stream, options);
+        result_valobj_sp->Dump(output_stream, options);
 
-        if (result)
-          result->SetStatus(eReturnStatusSuccessFinishResult);
+        result.SetStatus(eReturnStatusSuccessFinishResult);
       }
     } else {
       if (result_valobj_sp->GetError().GetError() ==
           UserExpression::kNoResult) {
         if (format != eFormatVoid && GetDebugger().GetNotifyVoid()) {
-          error_stream->PutCString("(void)\n");
+          error_stream.PutCString("(void)\n");
         }
 
-        if (result)
-          result->SetStatus(eReturnStatusSuccessFinishResult);
+        result.SetStatus(eReturnStatusSuccessFinishResult);
       } else {
         const char *error_cstr = result_valobj_sp->GetError().AsCString();
         if (error_cstr && error_cstr[0]) {
           const size_t error_cstr_len = strlen(error_cstr);
           const bool ends_with_newline = error_cstr[error_cstr_len - 1] == '\n';
           if (strstr(error_cstr, "error:") != error_cstr)
-            error_stream->PutCString("error: ");
-          error_stream->Write(error_cstr, error_cstr_len);
+            error_stream.PutCString("error: ");
+          error_stream.Write(error_cstr, error_cstr_len);
           if (!ends_with_newline)
-            error_stream->EOL();
+            error_stream.EOL();
         } else {
-          error_stream->PutCString("error: unknown error\n");
+          error_stream.PutCString("error: unknown error\n");
         }
 
-        if (result)
-          result->SetStatus(eReturnStatusFailed);
+        result.SetStatus(eReturnStatusFailed);
       }
     }
   }
@@ -502,7 +498,8 @@ void CommandObjectExpression::IOHandlerInputComplete(IOHandler &io_handler,
   StreamFileSP output_sp = io_handler.GetOutputStreamFileSP();
   StreamFileSP error_sp = io_handler.GetErrorStreamFileSP();
 
-  EvaluateExpression(line.c_str(), output_sp.get(), error_sp.get());
+  CommandReturnObject return_obj;
+  EvaluateExpression(line.c_str(), *output_sp, *error_sp, return_obj);
   if (output_sp)
     output_sp->Flush();
   if (error_sp)
@@ -650,8 +647,8 @@ bool CommandObjectExpression::DoExecute(llvm::StringRef command,
   }
 
   Target &target = GetSelectedOrDummyTarget();
-  if (EvaluateExpression(expr, &(result.GetOutputStream()),
-                         &(result.GetErrorStream()), &result)) {
+  if (EvaluateExpression(expr, result.GetOutputStream(),
+                         result.GetErrorStream(), result)) {
 
     if (!m_fixed_expression.empty() && target.GetEnableNotifyAboutFixIts()) {
       CommandHistory &history = m_interpreter.GetCommandHistory();

diff  --git a/lldb/source/Commands/CommandObjectExpression.h b/lldb/source/Commands/CommandObjectExpression.h
index b3bee3ca0e8c..ddee9c36924d 100644
--- a/lldb/source/Commands/CommandObjectExpression.h
+++ b/lldb/source/Commands/CommandObjectExpression.h
@@ -71,9 +71,8 @@ class CommandObjectExpression : public CommandObjectRaw,
   /// expression in the given target.
   EvaluateExpressionOptions GetEvalOptions(const Target &target);
 
-  bool EvaluateExpression(llvm::StringRef expr, Stream *output_stream,
-                          Stream *error_stream,
-                          CommandReturnObject *result = nullptr);
+  bool EvaluateExpression(llvm::StringRef expr, Stream &output_stream,
+                          Stream &error_stream, CommandReturnObject &result);
 
   void GetMultilineExpression();
 


        


More information about the lldb-commits mailing list