1 //===-- SBCommandReturnObject.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_API_SBCOMMANDRETURNOBJECT_H 10 #define LLDB_API_SBCOMMANDRETURNOBJECT_H 11 12 #include <stdio.h> 13 14 #include <memory> 15 16 #include "lldb/API/SBDefines.h" 17 18 namespace lldb_private { 19 class SBCommandReturnObjectImpl; 20 } 21 22 namespace lldb { 23 24 class LLDB_API SBCommandReturnObject { 25 public: 26 SBCommandReturnObject(); 27 28 SBCommandReturnObject(lldb_private::CommandReturnObject &ref); 29 30 // rvalue ctor+assignment are incompatible with Reproducers. 31 32 SBCommandReturnObject(const lldb::SBCommandReturnObject &rhs); 33 34 ~SBCommandReturnObject(); 35 36 lldb::SBCommandReturnObject & 37 operator=(const lldb::SBCommandReturnObject &rhs); 38 39 explicit operator bool() const; 40 41 bool IsValid() const; 42 43 const char *GetOutput(); 44 45 const char *GetError(); 46 47 size_t PutOutput(FILE *fh); // DEPRECATED 48 49 size_t PutOutput(SBFile file); 50 51 size_t PutOutput(FileSP file); 52 53 size_t GetOutputSize(); 54 55 size_t GetErrorSize(); 56 57 size_t PutError(FILE *fh); // DEPRECATED 58 59 size_t PutError(SBFile file); 60 61 size_t PutError(FileSP file); 62 63 void Clear(); 64 65 lldb::ReturnStatus GetStatus(); 66 67 void SetStatus(lldb::ReturnStatus status); 68 69 bool Succeeded(); 70 71 bool HasResult(); 72 73 void AppendMessage(const char *message); 74 75 void AppendWarning(const char *message); 76 77 bool GetDescription(lldb::SBStream &description); 78 79 void SetImmediateOutputFile(FILE *fh); // DEPRECATED 80 81 void SetImmediateErrorFile(FILE *fh); // DEPRECATED 82 83 void SetImmediateOutputFile(FILE *fh, bool transfer_ownership); // DEPRECATED 84 85 void SetImmediateErrorFile(FILE *fh, bool transfer_ownership); // DEPRECATED 86 87 void SetImmediateOutputFile(SBFile file); 88 89 void SetImmediateErrorFile(SBFile file); 90 91 void SetImmediateOutputFile(FileSP file); 92 93 void SetImmediateErrorFile(FileSP file); 94 95 void PutCString(const char *string, int len = -1); 96 97 size_t Printf(const char *format, ...) __attribute__((format(printf, 2, 3))); 98 99 const char *GetOutput(bool only_if_no_immediate); 100 101 const char *GetError(bool only_if_no_immediate); 102 103 void SetError(lldb::SBError &error, 104 const char *fallback_error_cstr = nullptr); 105 106 void SetError(const char *error_cstr); 107 108 // ref() is internal for LLDB only. 109 lldb_private::CommandReturnObject &ref() const; 110 111 protected: 112 friend class SBCommandInterpreter; 113 friend class SBOptions; 114 115 lldb_private::CommandReturnObject *operator->() const; 116 117 lldb_private::CommandReturnObject *get() const; 118 119 lldb_private::CommandReturnObject &operator*() const; 120 121 private: 122 std::unique_ptr<lldb_private::SBCommandReturnObjectImpl> m_opaque_up; 123 }; 124 125 } // namespace lldb 126 127 #endif // LLDB_API_SBCOMMANDRETURNOBJECT_H 128