1 //===-- SWIG Interface for SBStream -----------------------------*- 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 #include <stdio.h> 10 11 namespace lldb { 12 13 %feature("docstring", 14 "Represents a destination for streaming data output to. By default, a string 15 stream is created. 16 17 For example (from test/source-manager/TestSourceManager.py), 18 19 # Create the filespec for 'main.c'. 20 filespec = lldb.SBFileSpec('main.c', False) 21 source_mgr = self.dbg.GetSourceManager() 22 # Use a string stream as the destination. 23 stream = lldb.SBStream() 24 source_mgr.DisplaySourceLinesWithLineNumbers(filespec, 25 self.line, 26 2, # context before 27 2, # context after 28 '=>', # prefix for current line 29 stream) 30 31 # 2 32 # 3 int main(int argc, char const *argv[]) { 33 # => 4 printf('Hello world.\\n'); // Set break point at this line. 34 # 5 return 0; 35 # 6 } 36 self.expect(stream.GetData(), 'Source code displayed correctly', 37 exe=False, 38 patterns = ['=> %d.*Hello world' % self.line])") SBStream; 39 class SBStream 40 { 41 public: 42 43 SBStream (); 44 45 ~SBStream (); 46 47 bool 48 IsValid() const; 49 50 explicit operator bool() const; 51 52 %feature("docstring", " 53 If this stream is not redirected to a file, it will maintain a local 54 cache for the stream data which can be accessed using this accessor.") GetData; 55 const char * 56 GetData (); 57 58 %feature("docstring", " 59 If this stream is not redirected to a file, it will maintain a local 60 cache for the stream output whose length can be accessed using this 61 accessor.") GetSize; 62 size_t 63 GetSize(); 64 65 // wrapping the variadic Printf() with a plain Print() 66 // because it is hard to support varargs in SWIG bridgings 67 %extend { 68 void Print (const char* str) 69 { 70 self->Printf("%s", str); 71 } 72 } 73 74 void 75 RedirectToFile (const char *path, bool append); 76 77 void 78 RedirectToFile (lldb::SBFile file); 79 80 void 81 RedirectToFile (lldb::FileSP file); 82 83 %extend { 84 %feature("autodoc", "DEPRECATED, use RedirectToFile"); 85 void 86 RedirectToFileHandle (lldb::FileSP file, bool transfer_fh_ownership) { 87 self->RedirectToFile(file); 88 } 89 } 90 91 void 92 RedirectToFileDescriptor (int fd, bool transfer_fh_ownership); 93 94 %feature("docstring", " 95 If the stream is redirected to a file, forget about the file and if 96 ownership of the file was transferred to this object, close the file. 97 If the stream is backed by a local cache, clear this cache.") Clear; 98 void 99 Clear (); 100 }; 101 102 } // namespace lldb 103