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 
12 #include "lldb/Core/StreamFile.h"
14 #include "lldb/Utility/StreamTee.h"
15 #include "lldb/lldb-private.h"
16 
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Error.h"
19 #include "llvm/Support/FormatVariadic.h"
20 #include "llvm/Support/WithColor.h"
21 
22 #include <memory>
23 
24 namespace lldb_private {
25 
27 public:
28  CommandReturnObject(bool colors);
29 
30  ~CommandReturnObject() = default;
31 
32  llvm::StringRef GetOutputData() {
33  lldb::StreamSP stream_sp(m_out_stream.GetStreamAtIndex(eStreamStringIndex));
34  if (stream_sp)
35  return std::static_pointer_cast<StreamString>(stream_sp)->GetString();
36  return llvm::StringRef();
37  }
38 
39  llvm::StringRef GetErrorData() {
40  lldb::StreamSP stream_sp(m_err_stream.GetStreamAtIndex(eStreamStringIndex));
41  if (stream_sp)
42  return std::static_pointer_cast<StreamString>(stream_sp)->GetString();
43  return llvm::StringRef();
44  }
45 
47  // Make sure we at least have our normal string stream output stream
48  lldb::StreamSP stream_sp(m_out_stream.GetStreamAtIndex(eStreamStringIndex));
49  if (!stream_sp) {
50  stream_sp = std::make_shared<StreamString>();
52  }
53  return m_out_stream;
54  }
55 
57  // Make sure we at least have our normal string stream output stream
58  lldb::StreamSP stream_sp(m_err_stream.GetStreamAtIndex(eStreamStringIndex));
59  if (!stream_sp) {
60  stream_sp = std::make_shared<StreamString>();
62  }
63  return m_err_stream;
64  }
65 
66  void SetImmediateOutputFile(lldb::FileSP file_sp) {
68  return;
69  lldb::StreamSP stream_sp(new StreamFile(file_sp));
71  }
72 
73  void SetImmediateErrorFile(lldb::FileSP file_sp) {
75  return;
76  lldb::StreamSP stream_sp(new StreamFile(file_sp));
78  }
79 
80  void SetImmediateOutputStream(const lldb::StreamSP &stream_sp) {
82  return;
84  }
85 
86  void SetImmediateErrorStream(const lldb::StreamSP &stream_sp) {
88  return;
90  }
91 
92  lldb::StreamSP GetImmediateOutputStream() {
94  }
95 
96  lldb::StreamSP GetImmediateErrorStream() {
98  }
99 
100  void Clear();
101 
102  void AppendMessage(llvm::StringRef in_string);
103 
104  void AppendMessageWithFormat(const char *format, ...)
105  __attribute__((format(printf, 2, 3)));
106 
107  void AppendWarning(llvm::StringRef in_string);
108 
109  void AppendWarningWithFormat(const char *format, ...)
110  __attribute__((format(printf, 2, 3)));
111 
112  void AppendError(llvm::StringRef in_string);
113 
114  void AppendRawError(llvm::StringRef in_string);
115 
116  void AppendErrorWithFormat(const char *format, ...)
117  __attribute__((format(printf, 2, 3)));
118 
119  template <typename... Args>
120  void AppendMessageWithFormatv(const char *format, Args &&... args) {
121  AppendMessage(llvm::formatv(format, std::forward<Args>(args)...).str());
122  }
123 
124  template <typename... Args>
125  void AppendWarningWithFormatv(const char *format, Args &&... args) {
126  AppendWarning(llvm::formatv(format, std::forward<Args>(args)...).str());
127  }
128 
129  template <typename... Args>
130  void AppendErrorWithFormatv(const char *format, Args &&... args) {
131  AppendError(llvm::formatv(format, std::forward<Args>(args)...).str());
132  }
133 
134  void SetError(const Status &error, const char *fallback_error_cstr = nullptr);
135 
136  void SetError(llvm::Error error);
137 
139 
140  void SetStatus(lldb::ReturnStatus status);
141 
142  bool Succeeded() const;
143 
144  bool HasResult() const;
145 
146  bool GetDidChangeProcessState() const;
147 
148  void SetDidChangeProcessState(bool b);
149 
150  bool GetInteractive() const;
151 
152  void SetInteractive(bool b);
153 
154  bool GetSuppressImmediateOutput() const;
155 
156  void SetSuppressImmediateOutput(bool b);
157 
158 private:
160 
163 
165 
168 
169  /// If true, then the input handle from the debugger will be hooked up.
170  bool m_interactive = true;
171 };
172 
173 } // namespace lldb_private
174 
175 #endif // LLDB_INTERPRETER_COMMANDRETURNOBJECT_H
lldb_private::CommandReturnObject::GetStatus
lldb::ReturnStatus GetStatus() const
Definition: CommandReturnObject.cpp:129
lldb_private::CommandReturnObject::HasResult
bool HasResult() const
Definition: CommandReturnObject.cpp:135
llvm
Definition: Debugger.h:50
lldb_private::CommandReturnObject::SetError
void SetError(const Status &error, const char *fallback_error_cstr=nullptr)
Definition: CommandReturnObject.cpp:107
lldb_private::CommandReturnObject::eImmediateStreamIndex
@ eImmediateStreamIndex
Definition: CommandReturnObject.h:159
lldb_private::CommandReturnObject::m_status
lldb::ReturnStatus m_status
Definition: CommandReturnObject.h:164
lldb_private::CommandReturnObject::AppendRawError
void AppendRawError(llvm::StringRef in_string)
Definition: CommandReturnObject.cpp:121
lldb_private::CommandReturnObject::GetOutputData
llvm::StringRef GetOutputData()
Definition: CommandReturnObject.h:32
lldb_private::Stream
Definition: Stream.h:28
lldb_private::Args
Definition: Args.h:33
lldb_private::CommandReturnObject::Succeeded
bool Succeeded() const
Definition: CommandReturnObject.cpp:131
lldb_private::CommandReturnObject::AppendErrorWithFormatv
void AppendErrorWithFormatv(const char *format, Args &&... args)
Definition: CommandReturnObject.h:130
lldb_private::CommandReturnObject::Clear
void Clear()
Definition: CommandReturnObject.cpp:140
lldb_private::CommandReturnObject::m_err_stream
StreamTee m_err_stream
Definition: CommandReturnObject.h:162
lldb_private::CommandReturnObject::GetSuppressImmediateOutput
bool GetSuppressImmediateOutput() const
Definition: CommandReturnObject.cpp:166
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::CommandReturnObject::CommandReturnObject
CommandReturnObject(bool colors)
Definition: CommandReturnObject.cpp:43
lldb_private::CommandReturnObject::GetInteractive
bool GetInteractive() const
Definition: CommandReturnObject.cpp:162
lldb_private::CommandReturnObject::SetImmediateOutputFile
void SetImmediateOutputFile(lldb::FileSP file_sp)
Definition: CommandReturnObject.h:66
lldb_private::CommandReturnObject::m_out_stream
StreamTee m_out_stream
Definition: CommandReturnObject.h:161
lldb::ReturnStatus
ReturnStatus
Command Return Status Types.
Definition: lldb-enumerations.h:258
lldb_private::CommandReturnObject::eStreamStringIndex
@ eStreamStringIndex
Definition: CommandReturnObject.h:159
lldb_private::StreamTee
Definition: StreamTee.h:20
lldb_private::CommandReturnObject::SetStatus
void SetStatus(lldb::ReturnStatus status)
Definition: CommandReturnObject.cpp:127
lldb_private::CommandReturnObject::m_suppress_immediate_output
bool m_suppress_immediate_output
Definition: CommandReturnObject.h:167
lldb::eReturnStatusStarted
@ eReturnStatusStarted
Definition: lldb-enumerations.h:264
lldb_private::CommandReturnObject::GetImmediateErrorStream
lldb::StreamSP GetImmediateErrorStream()
Definition: CommandReturnObject.h:96
StreamString.h
lldb_private::CommandReturnObject::GetOutputStream
Stream & GetOutputStream()
Definition: CommandReturnObject.h:46
lldb_private::CommandReturnObject::SetSuppressImmediateOutput
void SetSuppressImmediateOutput(bool b)
Definition: CommandReturnObject.cpp:170
lldb_private::StreamTee::GetStreamAtIndex
lldb::StreamSP GetStreamAtIndex(uint32_t idx)
Definition: StreamTee.h:88
lldb_private::CommandReturnObject::GetImmediateOutputStream
lldb::StreamSP GetImmediateOutputStream()
Definition: CommandReturnObject.h:92
lldb_private::CommandReturnObject::GetDidChangeProcessState
bool GetDidChangeProcessState() const
Definition: CommandReturnObject.cpp:154
lldb_private::CommandReturnObject::GetErrorStream
Stream & GetErrorStream()
Definition: CommandReturnObject.h:56
lldb_private::StreamTee::SetStreamAtIndex
void SetStreamAtIndex(uint32_t idx, const lldb::StreamSP &stream_sp)
Definition: StreamTee.h:96
StreamTee.h
lldb-private.h
lldb_private::CommandReturnObject::AppendWarningWithFormatv
void AppendWarningWithFormatv(const char *format, Args &&... args)
Definition: CommandReturnObject.h:125
StreamFile.h
lldb_private::CommandReturnObject::m_interactive
bool m_interactive
If true, then the input handle from the debugger will be hooked up.
Definition: CommandReturnObject.h:170
lldb_private::Status
Definition: Status.h:44
lldb_private::CommandReturnObject
Definition: CommandReturnObject.h:26
lldb_private::CommandReturnObject::GetErrorData
llvm::StringRef GetErrorData()
Definition: CommandReturnObject.h:39
lldb_private::CommandReturnObject::SetImmediateOutputStream
void SetImmediateOutputStream(const lldb::StreamSP &stream_sp)
Definition: CommandReturnObject.h:80
lldb_private::CommandReturnObject::AppendWarning
void void AppendWarning(llvm::StringRef in_string)
Definition: CommandReturnObject.cpp:94
lldb_private::CommandReturnObject::AppendMessageWithFormat
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
Definition: CommandReturnObject.cpp:64
lldb_private::CommandReturnObject::SetInteractive
void SetInteractive(bool b)
Definition: CommandReturnObject.cpp:164
lldb_private::CommandReturnObject::AppendWarningWithFormat
void AppendWarningWithFormat(const char *format,...) __attribute__((format(printf
Definition: CommandReturnObject.cpp:76
lldb_private::CommandReturnObject::SetImmediateErrorFile
void SetImmediateErrorFile(lldb::FileSP file_sp)
Definition: CommandReturnObject.h:73
lldb_private::CommandReturnObject::SetDidChangeProcessState
void SetDidChangeProcessState(bool b)
Definition: CommandReturnObject.cpp:158
lldb_private::CommandReturnObject::AppendErrorWithFormat
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
Definition: CommandReturnObject.cpp:46
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::CommandReturnObject::m_did_change_process_state
bool m_did_change_process_state
Definition: CommandReturnObject.h:166
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:30
lldb_private::CommandReturnObject::SetImmediateErrorStream
void SetImmediateErrorStream(const lldb::StreamSP &stream_sp)
Definition: CommandReturnObject.h:86
lldb_private::StreamFile
Definition: StreamFile.h:22
lldb_private::CommandReturnObject::AppendError
void void AppendError(llvm::StringRef in_string)
Definition: CommandReturnObject.cpp:100
lldb_private::CommandReturnObject::~CommandReturnObject
~CommandReturnObject()=default
lldb_private::CommandReturnObject::AppendMessage
void AppendMessage(llvm::StringRef in_string)
Definition: CommandReturnObject.cpp:88
lldb_private::CommandReturnObject::AppendMessageWithFormatv
void void AppendMessageWithFormatv(const char *format, Args &&... args)
Definition: CommandReturnObject.h:120