================ @@ -20,6 +23,53 @@ namespace lldb_private { +/// A compiler-independent representation of a Diagnostic. Expression +/// evaluation failures often have more than one diagnostic that a UI +/// layer might want to render differently, for example to colorize +/// it. +/// +/// Running example: +/// (lldb) expr 1+foo +/// error: <user expression 0>:1:3: use of undeclared identifier 'foo' +/// 1+foo +/// ^ +struct DiagnosticDetail { + struct SourceLocation { + FileSpec file; + unsigned line = 0; + uint16_t column = 0; + uint16_t length = 0; + bool in_user_input = false; + }; + /// Contains {{}, 1, 3, 3, true} in the example above. + std::optional<SourceLocation> source_location; + /// Contains eSeverityError in the example above. + lldb::Severity severity = lldb::eSeverityInfo; + /// Contains "use of undeclared identifier 'x'" in the example above. + std::string message; + /// Contains the fully rendered error message. + std::string rendered; +}; + +/// An llvm::Error used to communicate diagnostics in Status. Multiple +/// diagnostics may be chained in an llvm::ErrorList. +class ExpressionError + : public llvm::ErrorInfo<ExpressionError, ExpressionErrorBase> { + std::string m_message; + std::vector<DiagnosticDetail> m_details; + +public: + static char ID; + using llvm::ErrorInfo<ExpressionError, ExpressionErrorBase>::ErrorInfo; + ExpressionError(lldb::ExpressionResults result, std::string msg, + std::vector<DiagnosticDetail> details = {}); + std::string message() const override; + llvm::ArrayRef<DiagnosticDetail> GetDetail() const { return m_details; } ---------------- labath wrote:
GetDetail***s*** ? https://github.com/llvm/llvm-project/pull/106442 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits