diff options
author | Raphael Isemann <teemperor@gmail.com> | 2020-03-17 12:57:32 +0100 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2020-03-17 13:23:16 +0100 |
commit | 7c6e52ac0ce5a6879331bc3c322dd20bfec3bf14 (patch) | |
tree | 7d3ea623917de2828efa579d4ac0f4655d8a0632 /lldb/source/Commands/CommandObjectExpression.cpp | |
parent | 4add24920550beeaed15b24e6427154a58b02e50 (diff) | |
download | llvm-7c6e52ac0ce5a6879331bc3c322dd20bfec3bf14.zip llvm-7c6e52ac0ce5a6879331bc3c322dd20bfec3bf14.tar.gz llvm-7c6e52ac0ce5a6879331bc3c322dd20bfec3bf14.tar.bz2 |
[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.
Diffstat (limited to 'lldb/source/Commands/CommandObjectExpression.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectExpression.cpp | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index 388f9f0..7d8de57 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(); |