LLDB mainline
CommandReturnObject.h
Go to the documentation of this file.
1//===-- CommandReturnObject.h -----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_INTERPRETER_COMMANDRETURNOBJECT_H
10#define LLDB_INTERPRETER_COMMANDRETURNOBJECT_H
11
17#include "lldb/lldb-private.h"
18
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/Error.h"
21#include "llvm/Support/FormatVariadic.h"
22#include "llvm/Support/WithColor.h"
23
24#include <memory>
25
26namespace lldb_private {
27
29public:
30 CommandReturnObject(bool colors);
31
33
34 /// Format any inline diagnostics with an indentation of \c indent.
35 std::string GetInlineDiagnosticString(unsigned indent);
36
37 llvm::StringRef GetOutputString() {
39 if (stream_sp)
40 return std::static_pointer_cast<StreamString>(stream_sp)->GetString();
41 return llvm::StringRef();
42 }
43
44 /// Return the errors as a string.
45 ///
46 /// If \c with_diagnostics is true, all diagnostics are also
47 /// rendered into the string. Otherwise the expectation is that they
48 /// are fetched with \ref GetInlineDiagnosticString().
49 std::string GetErrorString(bool with_diagnostics = true);
51
53 // Make sure we at least have our normal string stream output stream
55 if (!stream_sp) {
56 stream_sp = std::make_shared<StreamString>();
58 }
59 return m_out_stream;
60 }
61
63 // Make sure we at least have our normal string stream output stream
65 if (!stream_sp) {
66 stream_sp = std::make_shared<StreamString>();
68 }
69 return m_err_stream;
70 }
71
74 return;
75 lldb::StreamSP stream_sp(new StreamFile(file_sp));
77 }
78
81 return;
82 lldb::StreamSP stream_sp(new StreamFile(file_sp));
84 }
85
88 return;
90 }
91
92 void SetImmediateErrorStream(const lldb::StreamSP &stream_sp) {
94 return;
96 }
97
100 }
101
104 }
105
106 void Clear();
107
108 void AppendMessage(llvm::StringRef in_string);
109
110 void AppendMessageWithFormat(const char *format, ...)
111 __attribute__((format(printf, 2, 3)));
112
113 void AppendNote(llvm::StringRef in_string);
114
115 void AppendNoteWithFormat(const char *format, ...)
116 __attribute__((format(printf, 2, 3)));
117
118 void AppendWarning(llvm::StringRef in_string);
119
120 void AppendWarningWithFormat(const char *format, ...)
121 __attribute__((format(printf, 2, 3)));
122
123 void AppendError(llvm::StringRef in_string);
124
125 void AppendRawError(llvm::StringRef in_string);
126
127 void AppendErrorWithFormat(const char *format, ...)
128 __attribute__((format(printf, 2, 3)));
129
130 template <typename... Args>
131 void AppendMessageWithFormatv(const char *format, Args &&... args) {
132 AppendMessage(llvm::formatv(format, std::forward<Args>(args)...).str());
133 }
134
135 template <typename... Args>
136 void AppendNoteWithFormatv(const char *format, Args &&...args) {
137 AppendNote(llvm::formatv(format, std::forward<Args>(args)...).str());
138 }
139
140 template <typename... Args>
141 void AppendWarningWithFormatv(const char *format, Args &&... args) {
142 AppendWarning(llvm::formatv(format, std::forward<Args>(args)...).str());
143 }
144
145 template <typename... Args>
146 void AppendErrorWithFormatv(const char *format, Args &&... args) {
147 AppendError(llvm::formatv(format, std::forward<Args>(args)...).str());
148 }
149
150 void SetError(Status error);
151
152 void SetError(llvm::Error error);
153
154 void SetDiagnosticIndent(std::optional<uint16_t> indent) {
155 m_diagnostic_indent = indent;
156 }
157
158 std::optional<uint16_t> GetDiagnosticIndent() const {
159 return m_diagnostic_indent;
160 }
161
163
164 void SetStatus(lldb::ReturnStatus status);
165
166 bool Succeeded() const;
167
168 bool HasResult() const;
169
170 bool GetDidChangeProcessState() const;
171
172 void SetDidChangeProcessState(bool b);
173
174 bool GetInteractive() const;
175
176 void SetInteractive(bool b);
177
178 bool GetSuppressImmediateOutput() const;
179
180 void SetSuppressImmediateOutput(bool b);
181
182private:
184
187 std::vector<DiagnosticDetail> m_diagnostics;
188 std::optional<uint16_t> m_diagnostic_indent;
189
191
194
195 /// If true, then the input handle from the debugger will be hooked up.
196 bool m_interactive = true;
198};
199
200} // namespace lldb_private
201
202#endif // LLDB_INTERPRETER_COMMANDRETURNOBJECT_H
static llvm::raw_ostream & error(Stream &strm)
A command line argument class.
Definition: Args.h:33
void AppendErrorWithFormatv(const char *format, Args &&... args)
void AppendMessage(llvm::StringRef in_string)
void SetImmediateErrorStream(const lldb::StreamSP &stream_sp)
void SetImmediateErrorFile(lldb::FileSP file_sp)
void void AppendError(llvm::StringRef in_string)
void void AppendNote(llvm::StringRef in_string)
void AppendWarningWithFormat(const char *format,...) __attribute__((format(printf
bool m_interactive
If true, then the input handle from the debugger will be hooked up.
void AppendWarningWithFormatv(const char *format, Args &&... args)
void AppendRawError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
std::string GetErrorString(bool with_diagnostics=true)
Return the errors as a string.
void void AppendMessageWithFormatv(const char *format, Args &&... args)
std::optional< uint16_t > m_diagnostic_indent
std::optional< uint16_t > GetDiagnosticIndent() const
std::string GetInlineDiagnosticString(unsigned indent)
Format any inline diagnostics with an indentation of indent.
void SetImmediateOutputStream(const lldb::StreamSP &stream_sp)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
void SetDiagnosticIndent(std::optional< uint16_t > indent)
lldb::ReturnStatus GetStatus() const
StructuredData::ObjectSP GetErrorData()
void SetImmediateOutputFile(lldb::FileSP file_sp)
std::vector< DiagnosticDetail > m_diagnostics
void void AppendWarning(llvm::StringRef in_string)
void AppendNoteWithFormat(const char *format,...) __attribute__((format(printf
void AppendNoteWithFormatv(const char *format, Args &&...args)
An error handling class.
Definition: Status.h:115
void SetStreamAtIndex(uint32_t idx, const lldb::StreamSP &stream_sp)
Definition: StreamTee.h:96
lldb::StreamSP GetStreamAtIndex(uint32_t idx)
Definition: StreamTee.h:88
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Stream > StreamSP
Definition: lldb-forward.h:432
ReturnStatus
Command Return Status Types.
@ eReturnStatusStarted
std::shared_ptr< lldb_private::File > FileSP
Definition: lldb-forward.h:353
Definition: Debugger.h:54