99#ifndef LLDB_UTILITY_STATUS_H
1010#define LLDB_UTILITY_STATUS_H
1111
12+ #include " lldb/Utility/FileSpec.h"
1213#include " lldb/lldb-defines.h"
1314#include " lldb/lldb-enumerations.h"
1415#include " llvm/ADT/StringRef.h"
@@ -26,6 +27,48 @@ class raw_ostream;
2627
2728namespace lldb_private {
2829
30+ // / A compiler-independent representation of an \c
31+ // / lldb_private::Diagnostic. Expression evaluation failures often
32+ // / have more than one diagnostic that a UI layer might want to render
33+ // / differently, for example to colorize it.
34+ // /
35+ // / Running example:
36+ // / (lldb) expr 1 + foo
37+ // / error: <user expression 0>:1:3: use of undeclared identifier 'foo'
38+ // / 1 + foo
39+ // / ^~~
40+ struct DiagnosticDetail {
41+ // / A source location consisting of a file name and position.
42+ struct SourceLocation {
43+ // / \c "<user expression 0>" in the example above.
44+ FileSpec file;
45+ // / \c 1 in the example above.
46+ unsigned line = 0 ;
47+ // / \c 5 in the example above.
48+ uint16_t column = 0 ;
49+ // / \c 3 in the example above.
50+ uint16_t length = 0 ;
51+ // / Whether this source location should be surfaced to the
52+ // / user. For example, syntax errors diagnosed in LLDB's
53+ // / expression wrapper code have this set to true.
54+ bool hidden = false ;
55+ // / Whether this source location refers to something the user
56+ // / typed as part of the command, i.e., if this qualifies for
57+ // / inline display, or if the source line would need to be echoed
58+ // / again for the message to make sense.
59+ bool in_user_input = false ;
60+ };
61+ // / Contains this diagnostic's source location, if applicable.
62+ std::optional<SourceLocation> source_location;
63+ // / Contains \c eSeverityError in the example above.
64+ lldb::Severity severity = lldb::eSeverityInfo;
65+ // / Contains "use of undeclared identifier 'foo'" in the example above.
66+ std::string message;
67+ // / Contains the fully rendered error message, without "error: ",
68+ // / but including the source context.
69+ std::string rendered;
70+ };
71+
2972const char *ExpressionResultAsCString (lldb::ExpressionResults result);
3073
3174// / Going a bit against the spirit of llvm::Error,
@@ -86,6 +129,7 @@ class ExpressionErrorBase
86129 ExpressionErrorBase (std::error_code ec, std::string msg = {})
87130 : ErrorInfo(ec) {}
88131 lldb::ErrorType GetErrorType () const override ;
132+ virtual llvm::ArrayRef<DiagnosticDetail> GetDetails () const ;
89133 static char ID;
90134};
91135
0 commit comments