1 //===-- SBStream.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_SBSTREAM_H 10 #define LLDB_API_SBSTREAM_H 11 12 #include <cstdio> 13 14 #include "lldb/API/SBDefines.h" 15 16 namespace lldb_private { 17 class ScriptInterpreter; 18 } // namespace lldb_private 19 20 namespace lldb { 21 22 class LLDB_API SBStream { 23 public: 24 SBStream(); 25 26 #ifndef SWIG 27 SBStream(SBStream &&rhs); 28 #endif 29 30 ~SBStream(); 31 32 explicit operator bool() const; 33 34 bool IsValid() const; 35 36 // If this stream is not redirected to a file, it will maintain a local cache 37 // for the stream data which can be accessed using this accessor. 38 const char *GetData(); 39 40 // If this stream is not redirected to a file, it will maintain a local cache 41 // for the stream output whose length can be accessed using this accessor. 42 size_t GetSize(); 43 44 #ifndef SWIG 45 __attribute__((format(printf, 2, 3))) void Printf(const char *format, ...); 46 #endif 47 48 void Print(const char *str); 49 50 void RedirectToFile(const char *path, bool append); 51 52 void RedirectToFile(lldb::SBFile file); 53 54 void RedirectToFile(lldb::FileSP file); 55 56 #ifndef SWIG 57 void RedirectToFileHandle(FILE *fh, bool transfer_fh_ownership); 58 #endif 59 60 void RedirectToFileDescriptor(int fd, bool transfer_fh_ownership); 61 62 // If the stream is redirected to a file, forget about the file and if 63 // ownership of the file was transferred to this object, close the file. If 64 // the stream is backed by a local cache, clear this cache. 65 void Clear(); 66 67 protected: 68 friend class SBAddress; 69 friend class SBAddressRange; 70 friend class SBAddressRangeList; 71 friend class SBBlock; 72 friend class SBBreakpoint; 73 friend class SBBreakpointLocation; 74 friend class SBBreakpointName; 75 friend class SBCommandReturnObject; 76 friend class SBCompileUnit; 77 friend class SBData; 78 friend class SBDebugger; 79 friend class SBDeclaration; 80 friend class SBEvent; 81 friend class SBFileSpec; 82 friend class SBFileSpecList; 83 friend class SBFrame; 84 friend class SBFunction; 85 friend class SBInstruction; 86 friend class SBInstructionList; 87 friend class SBLaunchInfo; 88 friend class SBLineEntry; 89 friend class SBMemoryRegionInfo; 90 friend class SBModule; 91 friend class SBModuleSpec; 92 friend class SBModuleSpecList; 93 friend class SBProcess; 94 friend class SBSection; 95 friend class SBSourceManager; 96 friend class SBStructuredData; 97 friend class SBSymbol; 98 friend class SBSymbolContext; 99 friend class SBSymbolContextList; 100 friend class SBTarget; 101 friend class SBThread; 102 friend class SBThreadPlan; 103 friend class SBType; 104 friend class SBTypeEnumMember; 105 friend class SBTypeMemberFunction; 106 friend class SBTypeMember; 107 friend class SBValue; 108 friend class SBWatchpoint; 109 110 friend class lldb_private::ScriptInterpreter; 111 112 lldb_private::Stream *operator->(); 113 114 lldb_private::Stream *get(); 115 116 lldb_private::Stream &ref(); 117 118 private: 119 SBStream(const SBStream &) = delete; 120 const SBStream &operator=(const SBStream &) = delete; 121 std::unique_ptr<lldb_private::Stream> m_opaque_up; 122 bool m_is_file = false; 123 }; 124 125 } // namespace lldb 126 127 #endif // LLDB_API_SBSTREAM_H 128