]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Interpreter/CommandReturnObject.h
Update llvm, clang and lldb to trunk r257626, and update build glue.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Interpreter / CommandReturnObject.h
1 //===-- CommandReturnObject.h -----------------------------------*- 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 #ifndef liblldb_CommandReturnObject_h_
11 #define liblldb_CommandReturnObject_h_
12
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/lldb-private.h"
18 #include "lldb/Core/STLUtils.h"
19 #include "lldb/Core/StreamFile.h"
20 #include "lldb/Core/StreamString.h"
21 #include "lldb/Core/StreamTee.h"
22
23 namespace lldb_private {
24
25 class CommandReturnObject
26 {
27 public:
28     CommandReturnObject ();
29     
30     ~CommandReturnObject ();
31
32     const char *
33     GetOutputData ()
34     {
35         lldb::StreamSP stream_sp (m_out_stream.GetStreamAtIndex (eStreamStringIndex));
36         if (stream_sp)
37             return static_cast<StreamString *>(stream_sp.get())->GetData();
38         return "";
39     }
40
41     const char *
42     GetErrorData ()
43     {
44         lldb::StreamSP stream_sp (m_err_stream.GetStreamAtIndex (eStreamStringIndex));
45         if (stream_sp)
46             return static_cast<StreamString *>(stream_sp.get())->GetData();
47         else
48             return "";
49     }
50
51     Stream &
52     GetOutputStream ()
53     {
54         // Make sure we at least have our normal string stream output stream
55         lldb::StreamSP stream_sp (m_out_stream.GetStreamAtIndex (eStreamStringIndex));
56         if (!stream_sp)
57         {
58             stream_sp.reset (new StreamString());
59             m_out_stream.SetStreamAtIndex (eStreamStringIndex, stream_sp);
60         }   
61         return m_out_stream;
62     }
63
64     Stream &
65     GetErrorStream ()
66     {
67         // Make sure we at least have our normal string stream output stream
68         lldb::StreamSP stream_sp (m_err_stream.GetStreamAtIndex (eStreamStringIndex));
69         if (!stream_sp)
70         {
71             stream_sp.reset (new StreamString());
72             m_err_stream.SetStreamAtIndex (eStreamStringIndex, stream_sp);
73         }   
74         return m_err_stream;
75     }
76
77     void
78     SetImmediateOutputFile (FILE *fh, bool transfer_fh_ownership = false)
79     {
80         lldb::StreamSP stream_sp (new StreamFile (fh, transfer_fh_ownership));
81         m_out_stream.SetStreamAtIndex (eImmediateStreamIndex, stream_sp);
82     }
83     
84     void
85     SetImmediateErrorFile (FILE *fh, bool transfer_fh_ownership = false)
86     {
87         lldb::StreamSP stream_sp (new StreamFile (fh, transfer_fh_ownership));
88         m_err_stream.SetStreamAtIndex (eImmediateStreamIndex, stream_sp);
89     }
90     
91     void
92     SetImmediateOutputStream (const lldb::StreamSP &stream_sp)
93     {
94         m_out_stream.SetStreamAtIndex (eImmediateStreamIndex, stream_sp);
95     }
96     
97     void
98     SetImmediateErrorStream (const lldb::StreamSP &stream_sp)
99     {
100         m_err_stream.SetStreamAtIndex (eImmediateStreamIndex, stream_sp);
101     }
102     
103     lldb::StreamSP
104     GetImmediateOutputStream ()
105     {
106         return m_out_stream.GetStreamAtIndex (eImmediateStreamIndex);
107     }
108     
109     lldb::StreamSP
110     GetImmediateErrorStream ()
111     {
112         return m_err_stream.GetStreamAtIndex (eImmediateStreamIndex);
113     }
114     
115     void
116     Clear();
117
118     void
119     AppendMessage (const char *in_string);
120
121     void
122     AppendMessageWithFormat (const char *format, ...)  __attribute__ ((format (printf, 2, 3)));
123
124     void
125     AppendRawWarning (const char *in_string);
126
127     void
128     AppendWarning (const char *in_string);
129
130     void
131     AppendWarningWithFormat (const char *format, ...)  __attribute__ ((format (printf, 2, 3)));
132
133     void
134     AppendError (const char *in_string);
135
136     void
137     AppendRawError (const char *in_string);
138
139     void
140     AppendErrorWithFormat (const char *format, ...)  __attribute__ ((format (printf, 2, 3)));
141
142     void
143     SetError(const Error &error,
144              const char *fallback_error_cstr = nullptr);
145     
146     void
147     SetError (const char *error_cstr);
148
149     lldb::ReturnStatus
150     GetStatus();
151
152     void
153     SetStatus (lldb::ReturnStatus status);
154
155     bool
156     Succeeded ();
157
158     bool
159     HasResult ();
160
161     bool
162     GetDidChangeProcessState ();
163
164     void
165     SetDidChangeProcessState (bool b);
166
167     bool
168     GetInteractive () const;
169     
170     void
171     SetInteractive (bool b);
172     
173     bool
174     GetAbnormalStopWasExpected() const
175     {
176         return m_abnormal_stop_was_expected;
177     }
178     
179     void
180     SetAbnormalStopWasExpected(bool signal_was_expected)
181     {
182         m_abnormal_stop_was_expected = signal_was_expected;
183     }
184
185 private:
186     enum 
187     {
188         eStreamStringIndex = 0,
189         eImmediateStreamIndex = 1
190     };
191     
192     StreamTee    m_out_stream;
193     StreamTee    m_err_stream;
194     
195     lldb::ReturnStatus m_status;
196     bool m_did_change_process_state;
197     bool m_interactive;          // If true, then the input handle from the debugger will be hooked up
198     bool m_abnormal_stop_was_expected;  // This is to support eHandleCommandFlagStopOnCrash vrs. attach.
199                                         // The attach command often ends up with the process stopped due to a signal.
200                                         // Normally that would mean stop on crash should halt batch execution, but we
201                                         // obviously don't want that for attach.  Using this flag, the attach command
202                                         // (and anything else for which this is relevant) can say that the signal is
203                                         // expected, and batch command execution can continue.
204 };
205
206 } // namespace lldb_private
207
208 #endif // liblldb_CommandReturnObject_h_