[Lldb-commits] [lldb] [lldb] Inline expression evaluator error visualization (PR #106470)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Sep 25 05:45:54 PDT 2024
================
@@ -486,19 +603,37 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
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);
- if (!ends_with_newline)
- error_stream.EOL();
+ // Retrieve the diagnostics.
+ std::vector<DiagnosticDetail> details;
+ llvm::consumeError(
+ llvm::handleErrors(result_valobj_sp->GetError().ToError(),
+ [&](DetailedExpressionError &error) {
+ details.push_back(error.GetDetail());
+ }));
+ // 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 multiline = expr.contains('\n');
+ RenderDiagnosticDetails(error_stream, expr_pos, multiline, details);
} else {
- error_stream.PutCString("error: unknown error\n");
+ 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)
----------------
labath wrote:
Yes, please.
https://github.com/llvm/llvm-project/pull/106470
More information about the lldb-commits
mailing list