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
18#include "lldb/lldb-private.h"
19
20#include "llvm/ADT/StringRef.h"
21#include "llvm/Support/Error.h"
22#include "llvm/Support/FormatVariadic.h"
23#include "llvm/Support/WithColor.h"
24
25#include <memory>
26
27namespace lldb_private {
28
30public:
31 CommandReturnObject(bool colors);
32
34
35 /// Get the command as the user typed it. Empty string if commands were run on
36 /// behalf of lldb.
37 const std::string &GetCommand() const { return m_command; }
38
39 void SetCommand(std::string command) { m_command = std::move(command); }
40
41 /// Format any inline diagnostics with an indentation of \c indent.
42 std::string GetInlineDiagnosticString(unsigned indent) const;
43
44 llvm::StringRef GetOutputString() const {
45 lldb::StreamSP stream_sp(m_out_stream.GetStreamAtIndex(eStreamStringIndex));
46 if (stream_sp)
47 return std::static_pointer_cast<StreamString>(stream_sp)->GetString();
48 return llvm::StringRef();
49 }
50
51 /// Return the errors as a string.
52 ///
53 /// If \c with_diagnostics is true, all diagnostics are also
54 /// rendered into the string. Otherwise the expectation is that they
55 /// are fetched with \ref GetInlineDiagnosticString().
56 std::string GetErrorString(bool with_diagnostics = true) const;
58
60 // Make sure we at least have our normal string stream output stream
61 lldb::StreamSP stream_sp(m_out_stream.GetStreamAtIndex(eStreamStringIndex));
62 if (!stream_sp) {
63 stream_sp = std::make_shared<StreamString>();
64 m_out_stream.SetStreamAtIndex(eStreamStringIndex, stream_sp);
65 }
66 return m_out_stream;
67 }
68
70 // Make sure we at least have our normal string stream output stream
71 lldb::StreamSP stream_sp(m_err_stream.GetStreamAtIndex(eStreamStringIndex));
72 if (!stream_sp) {
73 stream_sp = std::make_shared<StreamString>();
74 m_err_stream.SetStreamAtIndex(eStreamStringIndex, stream_sp);
75 }
76 return m_err_stream;
77 }
78
81 return;
82 lldb::StreamSP stream_sp(new StreamFile(file_sp));
83 m_out_stream.SetStreamAtIndex(eImmediateStreamIndex, stream_sp);
84 }
85
88 return;
89 lldb::StreamSP stream_sp(new StreamFile(file_sp));
90 m_err_stream.SetStreamAtIndex(eImmediateStreamIndex, stream_sp);
91 }
92
95 return;
96 m_out_stream.SetStreamAtIndex(eImmediateStreamIndex, stream_sp);
97 }
98
99 void SetImmediateErrorStream(const lldb::StreamSP &stream_sp) {
101 return;
102 m_err_stream.SetStreamAtIndex(eImmediateStreamIndex, stream_sp);
103 }
104
106 return m_out_stream.GetStreamAtIndex(eImmediateStreamIndex);
107 }
108
110 return m_err_stream.GetStreamAtIndex(eImmediateStreamIndex);
111 }
112
113 void Clear();
114
115 void AppendMessage(llvm::StringRef in_string);
116
117 void AppendMessageWithFormat(const char *format, ...)
118 __attribute__((format(printf, 2, 3)));
119
120 void AppendNote(llvm::StringRef in_string);
121
122 void AppendNoteWithFormat(const char *format, ...)
123 __attribute__((format(printf, 2, 3)));
124
125 void AppendWarning(llvm::StringRef in_string);
126
127 void AppendWarningWithFormat(const char *format, ...)
128 __attribute__((format(printf, 2, 3)));
129
130 void AppendError(llvm::StringRef in_string);
131
132 void AppendErrorWithFormat(const char *format, ...)
133 __attribute__((format(printf, 2, 3)));
134
135 template <typename... Args>
136 void AppendMessageWithFormatv(const char *format, Args &&...args) {
137 AppendMessage(llvm::formatv(format, std::forward<Args>(args)...).str());
138 }
139
140 template <typename... Args>
141 void AppendNoteWithFormatv(const char *format, Args &&...args) {
142 AppendNote(llvm::formatv(format, std::forward<Args>(args)...).str());
143 }
144
145 template <typename... Args>
146 void AppendWarningWithFormatv(const char *format, Args &&...args) {
147 AppendWarning(llvm::formatv(format, std::forward<Args>(args)...).str());
148 }
149
150 template <typename... Args>
151 void AppendErrorWithFormatv(const char *format, Args &&...args) {
152 AppendError(llvm::formatv(format, std::forward<Args>(args)...).str());
153 }
154
155 void SetError(Status error);
156
157 void SetError(llvm::Error error);
158
159 void SetDiagnosticIndent(std::optional<uint16_t> indent) {
160 m_diagnostic_indent = indent;
161 }
162
163 std::optional<uint16_t> GetDiagnosticIndent() const {
164 return m_diagnostic_indent;
165 }
166
168
170
172
173 void SetStatus(lldb::ReturnStatus status);
174
175 bool Succeeded() const;
176
177 bool HasResult() const;
178
179 bool GetDidChangeProcessState() const;
180
181 void SetDidChangeProcessState(bool b);
182
183 bool GetInteractive() const;
184
185 void SetInteractive(bool b);
186
187 bool GetSuppressImmediateOutput() const;
188
189 void SetSuppressImmediateOutput(bool b);
190
191private:
193
194 std::string m_command;
195
198 std::vector<DiagnosticDetail> m_diagnostics;
199 std::optional<uint16_t> m_diagnostic_indent;
200
202
203 /// An optionally empty list of values produced by this command.
205
208
209 /// If true, then the input handle from the debugger will be hooked up.
210 bool m_interactive = true;
212};
213
214} // namespace lldb_private
215
216#endif // LLDB_INTERPRETER_COMMANDRETURNOBJECT_H
static llvm::raw_ostream & error(Stream &strm)
A command line argument class.
Definition Args.h:33
void AppendMessage(llvm::StringRef in_string)
void SetImmediateErrorStream(const lldb::StreamSP &stream_sp)
ValueObjectList m_value_objects
An optionally empty list of values produced by this command.
void SetImmediateErrorFile(lldb::FileSP file_sp)
void void AppendError(llvm::StringRef in_string)
std::string GetErrorString(bool with_diagnostics=true) const
Return the errors as a string.
llvm::StringRef GetOutputString() const
const ValueObjectList & GetValueObjectList() const
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 SetStatus(lldb::ReturnStatus status)
std::optional< uint16_t > m_diagnostic_indent
std::optional< uint16_t > GetDiagnosticIndent() const
void SetImmediateOutputStream(const lldb::StreamSP &stream_sp)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
void void AppendMessageWithFormatv(const char *format, Args &&...args)
void SetDiagnosticIndent(std::optional< uint16_t > indent)
StructuredData::ObjectSP GetErrorData()
lldb::StreamSP GetImmediateErrorStream() const
void SetImmediateOutputFile(lldb::FileSP file_sp)
std::vector< DiagnosticDetail > m_diagnostics
void SetCommand(std::string command)
lldb::StreamSP GetImmediateOutputStream() const
void void AppendWarning(llvm::StringRef in_string)
void AppendNoteWithFormat(const char *format,...) __attribute__((format(printf
const std::string & GetCommand() const
Get the command as the user typed it.
void AppendNoteWithFormatv(const char *format, Args &&...args)
std::string GetInlineDiagnosticString(unsigned indent) const
Format any inline diagnostics with an indentation of indent.
void AppendErrorWithFormatv(const char *format, Args &&...args)
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
std::shared_ptr< Object > ObjectSP
A collection of ValueObject values that.
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Stream > StreamSP
ReturnStatus
Command Return Status Types.
@ eReturnStatusStarted
std::shared_ptr< lldb_private::File > FileSP