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