aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Commands')
-rw-r--r--lldb/source/Commands/CommandObjectDWIMPrint.cpp11
-rw-r--r--lldb/source/Commands/CommandObjectExpression.cpp5
-rw-r--r--lldb/source/Commands/DiagnosticRendering.h133
3 files changed, 13 insertions, 136 deletions
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index 2e1d6e6..beff5f4 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -191,6 +191,17 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
ExpressionResults expr_result = target.EvaluateExpression(
expr, exe_scope, valobj_sp, eval_options, &fixed_expression);
+ // Record the position of the expression in the command.
+ std::optional<uint16_t> indent;
+ if (fixed_expression.empty()) {
+ size_t pos = m_original_command.find(expr);
+ if (pos != llvm::StringRef::npos)
+ indent = pos;
+ }
+ // Previously the indent was set up for diagnosing command line
+ // parsing errors. Now point it to the expression.
+ result.SetDiagnosticIndent(indent);
+
// Only mention Fix-Its if the expression evaluator applied them.
// Compiler errors refer to the final expression after applying Fix-It(s).
if (!fixed_expression.empty() && target.GetEnableNotifyAboutFixIts()) {
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index a72b409..8effb1a 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -7,9 +7,7 @@
//===----------------------------------------------------------------------===//
#include "CommandObjectExpression.h"
-#include "DiagnosticRendering.h"
#include "lldb/Core/Debugger.h"
-#include "lldb/Expression/DiagnosticManager.h"
#include "lldb/Expression/ExpressionVariable.h"
#include "lldb/Expression/REPL.h"
#include "lldb/Expression/UserExpression.h"
@@ -22,6 +20,7 @@
#include "lldb/Target/Process.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
+#include "lldb/Utility/DiagnosticsRendering.h"
#include "lldb/lldb-enumerations.h"
#include "lldb/lldb-private-enumerations.h"
@@ -490,7 +489,7 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
std::vector<DiagnosticDetail> details;
llvm::consumeError(llvm::handleErrors(
result_valobj_sp->GetError().ToError(),
- [&](ExpressionError &error) { details = error.GetDetails(); }));
+ [&](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);
diff --git a/lldb/source/Commands/DiagnosticRendering.h b/lldb/source/Commands/DiagnosticRendering.h
deleted file mode 100644
index 5fdd090..0000000
--- a/lldb/source/Commands/DiagnosticRendering.h
+++ /dev/null
@@ -1,133 +0,0 @@
-//===-- DiagnosticRendering.h -----------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLDB_SOURCE_COMMANDS_DIAGNOSTICRENDERING_H
-#define LLDB_SOURCE_COMMANDS_DIAGNOSTICRENDERING_H
-
-#include "lldb/Expression/DiagnosticManager.h"
-#include "lldb/Utility/Stream.h"
-#include "llvm/Support/WithColor.h"
-
-namespace lldb_private {
-
-static llvm::raw_ostream &PrintSeverity(Stream &stream,
- lldb::Severity severity) {
- llvm::HighlightColor color;
- llvm::StringRef text;
- switch (severity) {
- case lldb::eSeverityError:
- color = llvm::HighlightColor::Error;
- text = "error: ";
- break;
- case lldb::eSeverityWarning:
- color = llvm::HighlightColor::Warning;
- text = "warning: ";
- break;
- case lldb::eSeverityInfo:
- color = llvm::HighlightColor::Remark;
- text = "note: ";
- break;
- }
- return llvm::WithColor(stream.AsRawOstream(), color, llvm::ColorMode::Enable)
- << text;
-}
-
-// Public for unittesting.
-static void RenderDiagnosticDetails(Stream &stream,
- std::optional<uint16_t> offset_in_command,
- bool show_inline,
- llvm::ArrayRef<DiagnosticDetail> details) {
- if (details.empty())
- return;
-
- if (!offset_in_command) {
- for (const DiagnosticDetail &detail : details) {
- PrintSeverity(stream, detail.severity);
- stream << detail.rendered << '\n';
- }
- return;
- }
-
- // Print a line with caret indicator(s) below the lldb prompt + command.
- const size_t padding = *offset_in_command;
- stream << std::string(padding, ' ');
-
- size_t offset = 1;
- std::vector<DiagnosticDetail> remaining_details, other_details,
- hidden_details;
- for (const DiagnosticDetail &detail : details) {
- if (!show_inline || !detail.source_location) {
- other_details.push_back(detail);
- continue;
- }
- if (detail.source_location->hidden) {
- hidden_details.push_back(detail);
- continue;
- }
- if (!detail.source_location->in_user_input) {
- other_details.push_back(detail);
- continue;
- }
-
- auto &loc = *detail.source_location;
- remaining_details.push_back(detail);
- if (offset > loc.column)
- continue;
- stream << std::string(loc.column - offset, ' ') << '^';
- if (loc.length > 1)
- stream << std::string(loc.length - 1, '~');
- offset = loc.column + 1;
- }
- stream << '\n';
-
- // Work through each detail in reverse order using the vector/stack.
- bool did_print = false;
- for (auto detail = remaining_details.rbegin();
- detail != remaining_details.rend();
- ++detail, remaining_details.pop_back()) {
- // Get the information to print this detail and remove it from the stack.
- // Print all the lines for all the other messages first.
- stream << std::string(padding, ' ');
- size_t offset = 1;
- for (auto &remaining_detail :
- llvm::ArrayRef(remaining_details).drop_back(1)) {
- uint16_t column = remaining_detail.source_location->column;
- stream << std::string(column - offset, ' ') << "│";
- offset = column + 1;
- }
-
- // Print the line connecting the ^ with the error message.
- uint16_t column = detail->source_location->column;
- if (offset <= column)
- stream << std::string(column - offset, ' ') << "╰─ ";
-
- // Print a colorized string based on the message's severity type.
- PrintSeverity(stream, detail->severity);
-
- // Finally, print the message and start a new line.
- stream << detail->message << '\n';
- did_print = true;
- }
-
- // Print the non-located details.
- for (const DiagnosticDetail &detail : other_details) {
- PrintSeverity(stream, detail.severity);
- stream << detail.rendered << '\n';
- did_print = true;
- }
-
- // Print the hidden details as a last resort.
- if (!did_print)
- for (const DiagnosticDetail &detail : hidden_details) {
- PrintSeverity(stream, detail.severity);
- stream << detail.rendered << '\n';
- }
-}
-
-} // namespace lldb_private
-#endif