1 //===-- CommandReturnObject.h -----------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_CommandReturnObject_h_ 11 #define liblldb_CommandReturnObject_h_ 12 13 // C Includes 14 // C++ Includes 15 // Other libraries and framework includes 16 // Project includes 17 #include "lldb/lldb-private.h" 18 #include "lldb/Core/STLUtils.h" 19 #include "lldb/Core/StreamFile.h" 20 #include "lldb/Core/StreamString.h" 21 #include "lldb/Core/StreamTee.h" 22 23 namespace lldb_private { 24 25 26 class CommandReturnObject 27 { 28 public: 29 30 CommandReturnObject (); 31 32 ~CommandReturnObject (); 33 34 const char * 35 GetOutputData () 36 { 37 lldb::StreamSP stream_sp (m_out_stream.GetStreamAtIndex (eStreamStringIndex)); 38 if (stream_sp) 39 return static_cast<StreamString *>(stream_sp.get())->GetData(); 40 return ""; 41 } 42 43 const char * 44 GetErrorData () 45 { 46 lldb::StreamSP stream_sp (m_err_stream.GetStreamAtIndex (eStreamStringIndex)); 47 if (stream_sp) 48 return static_cast<StreamString *>(stream_sp.get())->GetData(); 49 else 50 return ""; 51 } 52 53 Stream & 54 GetOutputStream () 55 { 56 // Make sure we at least have our normal string stream output stream 57 lldb::StreamSP stream_sp (m_out_stream.GetStreamAtIndex (eStreamStringIndex)); 58 if (!stream_sp) 59 { 60 stream_sp.reset (new StreamString()); 61 m_out_stream.SetStreamAtIndex (eStreamStringIndex, stream_sp); 62 } 63 return m_out_stream; 64 } 65 66 Stream & 67 GetErrorStream () 68 { 69 // Make sure we at least have our normal string stream output stream 70 lldb::StreamSP stream_sp (m_err_stream.GetStreamAtIndex (eStreamStringIndex)); 71 if (!stream_sp) 72 { 73 stream_sp.reset (new StreamString()); 74 m_err_stream.SetStreamAtIndex (eStreamStringIndex, stream_sp); 75 } 76 return m_err_stream; 77 } 78 79 void 80 SetImmediateOutputFile (FILE *fh, bool transfer_fh_ownership = false) 81 { 82 lldb::StreamSP stream_sp (new StreamFile (fh, transfer_fh_ownership)); 83 m_out_stream.SetStreamAtIndex (eImmediateStreamIndex, stream_sp); 84 } 85 86 void 87 SetImmediateErrorFile (FILE *fh, bool transfer_fh_ownership = false) 88 { 89 lldb::StreamSP stream_sp (new StreamFile (fh, transfer_fh_ownership)); 90 m_err_stream.SetStreamAtIndex (eImmediateStreamIndex, stream_sp); 91 } 92 93 void 94 SetImmediateOutputStream (const lldb::StreamSP &stream_sp) 95 { 96 m_out_stream.SetStreamAtIndex (eImmediateStreamIndex, stream_sp); 97 } 98 99 void 100 SetImmediateErrorStream (const lldb::StreamSP &stream_sp) 101 { 102 m_err_stream.SetStreamAtIndex (eImmediateStreamIndex, stream_sp); 103 } 104 105 lldb::StreamSP 106 GetImmediateOutputStream () 107 { 108 return m_out_stream.GetStreamAtIndex (eImmediateStreamIndex); 109 } 110 111 lldb::StreamSP 112 GetImmediateErrorStream () 113 { 114 return m_err_stream.GetStreamAtIndex (eImmediateStreamIndex); 115 } 116 117 void 118 Clear(); 119 120 void 121 AppendMessage (const char *in_string); 122 123 void 124 AppendMessageWithFormat (const char *format, ...) __attribute__ ((format (printf, 2, 3))); 125 126 void 127 AppendRawWarning (const char *in_string); 128 129 void 130 AppendWarning (const char *in_string); 131 132 void 133 AppendWarningWithFormat (const char *format, ...) __attribute__ ((format (printf, 2, 3))); 134 135 void 136 AppendError (const char *in_string); 137 138 void 139 AppendRawError (const char *in_string); 140 141 void 142 AppendErrorWithFormat (const char *format, ...) __attribute__ ((format (printf, 2, 3))); 143 144 void 145 SetError (const Error &error, 146 const char *fallback_error_cstr = NULL); 147 148 void 149 SetError (const char *error_cstr); 150 151 lldb::ReturnStatus 152 GetStatus(); 153 154 void 155 SetStatus (lldb::ReturnStatus status); 156 157 bool 158 Succeeded (); 159 160 bool 161 HasResult (); 162 163 bool GetDidChangeProcessState (); 164 165 void SetDidChangeProcessState (bool b); 166 167 private: 168 enum 169 { 170 eStreamStringIndex = 0, 171 eImmediateStreamIndex = 1 172 }; 173 174 StreamTee m_out_stream; 175 StreamTee m_err_stream; 176 177 lldb::ReturnStatus m_status; 178 bool m_did_change_process_state; 179 }; 180 181 } // namespace lldb_private 182 183 #endif // liblldb_CommandReturnObject_h_ 184