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