diff options
| author | Adrian Prantl <aprantl@apple.com> | 2024-10-14 16:29:26 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-14 16:29:26 -0700 |
| commit | 9eddc8b9bf4e4e0b01e2ecc90a71c4b3b4e9c8af (patch) | |
| tree | c5525898a47401b0e6ebb6d4cc8b72569fd5d953 /lldb/source/Commands/CommandObjectExpression.cpp | |
| parent | fc08ad6610c66856f48559e543eb7be317e908e7 (diff) | |
[lldb] Expose structured command diagnostics via the SBAPI. (#112109)
This allows IDEs to render LLDB expression diagnostics to their liking
without relying on characterprecise ASCII art from LLDB. It is exposed
as a versioned SBStructuredData object, since it is expected that this
may need to be tweaked based on actual usage.
Diffstat (limited to 'lldb/source/Commands/CommandObjectExpression.cpp')
| -rw-r--r-- | lldb/source/Commands/CommandObjectExpression.cpp | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index 8effb1a59883..13491b5c7944 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -485,35 +485,8 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr, result.SetStatus(eReturnStatusSuccessFinishResult); } else { - // Retrieve the diagnostics. - std::vector<DiagnosticDetail> details; - llvm::consumeError(llvm::handleErrors( - result_valobj_sp->GetError().ToError(), - [&](DiagnosticError &error) { details = error.GetDetails(); })); - // Find the position of the expression in the command. - std::optional<uint16_t> expr_pos; - size_t nchar = m_original_command.find(expr); - if (nchar != std::string::npos) - expr_pos = nchar + GetDebugger().GetPrompt().size(); - - if (!details.empty()) { - bool show_inline = - GetDebugger().GetShowInlineDiagnostics() && !expr.contains('\n'); - RenderDiagnosticDetails(error_stream, expr_pos, show_inline, details); - } else { - const char *error_cstr = result_valobj_sp->GetError().AsCString(); - llvm::StringRef error(error_cstr); - if (!error.empty()) { - if (!error.starts_with("error:")) - error_stream << "error: "; - error_stream << error; - if (!error.ends_with('\n')) - error_stream.EOL(); - } else { - error_stream << "error: unknown error\n"; - } - } result.SetStatus(eReturnStatusFailed); + result.SetError(result_valobj_sp->GetError().ToError()); } } } else { @@ -533,10 +506,13 @@ void CommandObjectExpression::IOHandlerInputComplete(IOHandler &io_handler, CommandReturnObject return_obj( GetCommandInterpreter().GetDebugger().GetUseColor()); EvaluateExpression(line.c_str(), *output_sp, *error_sp, return_obj); + if (output_sp) output_sp->Flush(); - if (error_sp) + if (error_sp) { + *error_sp << return_obj.GetErrorString(); error_sp->Flush(); + } } bool CommandObjectExpression::IOHandlerIsInputComplete(IOHandler &io_handler, @@ -679,6 +655,14 @@ void CommandObjectExpression::DoExecute(llvm::StringRef command, } } + // Previously the indent was set up for diagnosing command line + // parsing errors. Now point it to the expression. + std::optional<uint16_t> indent; + size_t pos = m_original_command.rfind(expr); + if (pos != llvm::StringRef::npos) + indent = pos; + result.SetDiagnosticIndent(indent); + Target &target = GetTarget(); if (EvaluateExpression(expr, result.GetOutputStream(), result.GetErrorStream(), result)) { |
