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 AppendNote(llvm::StringRef in_string);
118
119 void AppendWarning(llvm::StringRef in_string);
120
121 void AppendError(llvm::StringRef in_string);
122
123 void AppendErrorWithFormat(const char *format, ...)
124 __attribute__((format(printf, 2, 3)));
125
126 template <typename... Args>
127 void AppendMessageWithFormatv(const char *format, Args &&...args) {
128 AppendMessage(llvm::formatv(format, std::forward<Args>(args)...).str());
129 }
130
131 template <typename... Args>
132 void AppendNoteWithFormatv(const char *format, Args &&...args) {
133 AppendNote(llvm::formatv(format, std::forward<Args>(args)...).str());
134 }
135
136 template <typename... Args>
137 void AppendWarningWithFormatv(const char *format, Args &&...args) {
138 AppendWarning(llvm::formatv(format, std::forward<Args>(args)...).str());
139 }
140
141 template <typename... Args>
142 void AppendErrorWithFormatv(const char *format, Args &&...args) {
143 AppendError(llvm::formatv(format, std::forward<Args>(args)...).str());
144 }
145
146 void SetError(Status error);
147
148 void SetError(llvm::Error error);
149
150 void SetDiagnosticIndent(std::optional<uint16_t> indent) {
151 m_diagnostic_indent = indent;
152 }
153
154 std::optional<uint16_t> GetDiagnosticIndent() const {
155 return m_diagnostic_indent;
156 }
157
159
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
185 std::string m_command;
186
189 std::vector<DiagnosticDetail> m_diagnostics;
190 std::optional<uint16_t> m_diagnostic_indent;
191
193
194 /// An optionally empty list of values produced by this command.
196
199
200 /// If true, then the input handle from the debugger will be hooked up.
201 bool m_interactive = true;
203};
204
205} // namespace lldb_private
206
207#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 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 AppendNote(llvm::StringRef in_string)
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 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 AppendWarning(llvm::StringRef in_string)
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