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
11namespace lldb {
12
13%feature("docstring",
14"Represents a destination for streaming data output to. By default, a string
15stream is created.
16
17For 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;
39class SBStream
40{
41public:
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    void
66    Print (const char* str);
67
68    void
69    RedirectToFile (const char *path, bool append);
70
71    void
72    RedirectToFile (lldb::SBFile file);
73
74    void
75    RedirectToFile (lldb::FileSP file);
76
77    %extend {
78        %feature("autodoc", "DEPRECATED, use RedirectToFile");
79        void
80        RedirectToFileHandle (lldb::FileSP file, bool transfer_fh_ownership) {
81            self->RedirectToFile(file);
82        }
83    }
84
85    void
86    RedirectToFileDescriptor (int fd, bool transfer_fh_ownership);
87
88    %feature("docstring", "
89    If the stream is redirected to a file, forget about the file and if
90    ownership of the file was transferred to this object, close the file.
91    If the stream is backed by a local cache, clear this cache.") Clear;
92    void
93    Clear ();
94};
95
96} // namespace lldb
97