[Lldb-commits] [lldb] [lldb] Store expression evaluator diagnostics in an llvm::Error (NFC) (PR #106442)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 19 07:33:14 PDT 2024


================
@@ -20,6 +23,47 @@
 
 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 DetailedExpressionError
+    : public llvm::ErrorInfo<DetailedExpressionError, llvm::ECError> {
----------------
labath wrote:

Is this really an `instanceof` ECError? e.g.:
- should it be constructible with any kind of error category/code combination?
- do you intend to support the setErrorCode ECError API?

If the answer to either of these is no, I think it'd be better to derive this directly from the base class.

https://github.com/llvm/llvm-project/pull/106442


More information about the lldb-commits mailing list