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