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