1 //===-- SBDebugger.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 LLDB_SBDebugger_h_
11 #define LLDB_SBDebugger_h_
12 
13 #include <stdio.h>
14 
15 #include "lldb/API/SBDefines.h"
16 #include "lldb/API/SBPlatform.h"
17 
18 namespace lldb {
19 
20 class LLDB_API SBInputReader
21 {
22 public:
23     SBInputReader() = default;
24     ~SBInputReader() = default;
25 
26     SBError Initialize(lldb::SBDebugger&, unsigned long (*)(void*, lldb::SBInputReader*, lldb::InputReaderAction, char const*, unsigned long), void*, lldb::InputReaderGranularity, char const*, char const*, bool);
27     void SetIsDone(bool);
28     bool IsActive() const;
29 };
30 
31 class LLDB_API SBDebugger
32 {
33 public:
34     SBDebugger();
35 
36     SBDebugger(const lldb::SBDebugger &rhs);
37 
38     SBDebugger(const lldb::DebuggerSP &debugger_sp);
39 
40     ~SBDebugger();
41 
42     lldb::SBDebugger &
43     operator = (const lldb::SBDebugger &rhs);
44 
45     static void
46     Initialize();
47 
48     static void
49     Terminate();
50 
51     // Deprecated, use the one that takes a source_init_files bool.
52     static lldb::SBDebugger
53     Create();
54 
55     static lldb::SBDebugger
56     Create(bool source_init_files);
57 
58     static lldb::SBDebugger
59     Create(bool source_init_files, lldb::LogOutputCallback log_callback, void *baton);
60 
61     static void
62     Destroy (lldb::SBDebugger &debugger);
63 
64     static void
65     MemoryPressureDetected ();
66 
67     bool
68     IsValid() const;
69 
70     void
71     Clear ();
72 
73     void
74     SetAsync (bool b);
75 
76     bool
77     GetAsync ();
78 
79     void
80     SkipLLDBInitFiles (bool b);
81 
82     void
83     SkipAppInitFiles (bool b);
84 
85     void
86     SetInputFileHandle (FILE *f, bool transfer_ownership);
87 
88     void
89     SetOutputFileHandle (FILE *f, bool transfer_ownership);
90 
91     void
92     SetErrorFileHandle (FILE *f, bool transfer_ownership);
93 
94     FILE *
95     GetInputFileHandle ();
96 
97     FILE *
98     GetOutputFileHandle ();
99 
100     FILE *
101     GetErrorFileHandle ();
102 
103     void
104     SaveInputTerminalState();
105 
106     void
107     RestoreInputTerminalState();
108 
109     lldb::SBCommandInterpreter
110     GetCommandInterpreter ();
111 
112     void
113     HandleCommand (const char *command);
114 
115     lldb::SBListener
116     GetListener ();
117 
118     void
119     HandleProcessEvent (const lldb::SBProcess &process,
120                         const lldb::SBEvent &event,
121                         FILE *out,
122                         FILE *err);
123 
124     lldb::SBTarget
125     CreateTarget (const char *filename,
126                   const char *target_triple,
127                   const char *platform_name,
128                   bool add_dependent_modules,
129                   lldb::SBError& error);
130 
131     lldb::SBTarget
132     CreateTargetWithFileAndTargetTriple (const char *filename,
133                                          const char *target_triple);
134 
135     lldb::SBTarget
136     CreateTargetWithFileAndArch (const char *filename,
137                                  const char *archname);
138 
139     lldb::SBTarget
140     CreateTarget (const char *filename);
141 
142     // Return true if target is deleted from the target list of the debugger.
143     bool
144     DeleteTarget (lldb::SBTarget &target);
145 
146     lldb::SBTarget
147     GetTargetAtIndex (uint32_t idx);
148 
149     uint32_t
150     GetIndexOfTarget (lldb::SBTarget target);
151 
152     lldb::SBTarget
153     FindTargetWithProcessID (pid_t pid);
154 
155     lldb::SBTarget
156     FindTargetWithFileAndArch (const char *filename,
157                                const char *arch);
158 
159     uint32_t
160     GetNumTargets ();
161 
162     lldb::SBTarget
163     GetSelectedTarget ();
164 
165     void
166     SetSelectedTarget (SBTarget& target);
167 
168     lldb::SBPlatform
169     GetSelectedPlatform();
170 
171     void
172     SetSelectedPlatform(lldb::SBPlatform &platform);
173 
174     lldb::SBSourceManager
175     GetSourceManager ();
176 
177     // REMOVE: just for a quick fix, need to expose platforms through
178     // SBPlatform from this class.
179     lldb::SBError
180     SetCurrentPlatform (const char *platform_name);
181 
182     bool
183     SetCurrentPlatformSDKRoot (const char *sysroot);
184 
185     // FIXME: Once we get the set show stuff in place, the driver won't need
186     // an interface to the Set/Get UseExternalEditor.
187     bool
188     SetUseExternalEditor (bool input);
189 
190     bool
191     GetUseExternalEditor ();
192 
193     bool
194     SetUseColor (bool use_color);
195 
196     bool
197     GetUseColor () const;
198 
199     static bool
200     GetDefaultArchitecture (char *arch_name, size_t arch_name_len);
201 
202     static bool
203     SetDefaultArchitecture (const char *arch_name);
204 
205     lldb::ScriptLanguage
206     GetScriptingLanguage (const char *script_language_name);
207 
208     static const char *
209     GetVersionString ();
210 
211     static const char *
212     StateAsCString (lldb::StateType state);
213 
214     static bool
215     StateIsRunningState (lldb::StateType state);
216 
217     static bool
218     StateIsStoppedState (lldb::StateType state);
219 
220     bool
221     EnableLog (const char *channel, const char **categories);
222 
223     void
224     SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
225 
226     // DEPRECATED
227     void
228     DispatchInput (void* baton,
229                    const void* data,
230                    size_t data_len);
231 
232     void
233     DispatchInput (const void *data, size_t data_len);
234 
235     void
236     DispatchInputInterrupt ();
237 
238     void
239     DispatchInputEndOfFile ();
240 
241     void
242     PushInputReader (lldb::SBInputReader &reader);
243 
244     const char *
245     GetInstanceName  ();
246 
247     static SBDebugger
248     FindDebuggerWithID (int id);
249 
250     static lldb::SBError
251     SetInternalVariable (const char *var_name, const char *value, const char *debugger_instance_name);
252 
253     static lldb::SBStringList
254     GetInternalVariableValue (const char *var_name, const char *debugger_instance_name);
255 
256     bool
257     GetDescription (lldb::SBStream &description);
258 
259     uint32_t
260     GetTerminalWidth () const;
261 
262     void
263     SetTerminalWidth (uint32_t term_width);
264 
265     lldb::user_id_t
266     GetID ();
267 
268     const char *
269     GetPrompt() const;
270 
271     void
272     SetPrompt (const char *prompt);
273 
274     lldb::ScriptLanguage
275     GetScriptLanguage() const;
276 
277     void
278     SetScriptLanguage (lldb::ScriptLanguage script_lang);
279 
280     bool
281     GetCloseInputOnEOF () const;
282 
283     void
284     SetCloseInputOnEOF (bool b);
285 
286     SBTypeCategory
287     GetCategory (const char* category_name);
288 
289     SBTypeCategory
290     GetCategory (lldb::LanguageType lang_type);
291 
292     SBTypeCategory
293     CreateCategory (const char* category_name);
294 
295     bool
296     DeleteCategory (const char* category_name);
297 
298     uint32_t
299     GetNumCategories ();
300 
301     SBTypeCategory
302     GetCategoryAtIndex (uint32_t);
303 
304     SBTypeCategory
305     GetDefaultCategory();
306 
307     SBTypeFormat
308     GetFormatForType (SBTypeNameSpecifier);
309 
310 #ifndef LLDB_DISABLE_PYTHON
311     SBTypeSummary
312     GetSummaryForType (SBTypeNameSpecifier);
313 #endif
314 
315     SBTypeFilter
316     GetFilterForType (SBTypeNameSpecifier);
317 
318 #ifndef LLDB_DISABLE_PYTHON
319     SBTypeSynthetic
320     GetSyntheticForType (SBTypeNameSpecifier);
321 #endif
322 
323     void
324     RunCommandInterpreter (bool auto_handle_events,
325                            bool spawn_thread);
326 
327     void
328     RunCommandInterpreter (bool auto_handle_events,
329                            bool spawn_thread,
330                            SBCommandInterpreterRunOptions &options,
331                            int  &num_errors,
332                            bool &quit_requested,
333                            bool &stopped_for_crash);
334 
335     SBError
336     RunREPL (lldb::LanguageType language, const char *repl_options);
337 
338 private:
339     friend class SBCommandInterpreter;
340     friend class SBInputReader;
341     friend class SBListener;
342     friend class SBProcess;
343     friend class SBSourceManager;
344     friend class SBTarget;
345 
346     lldb::SBTarget
347     FindTargetWithLLDBProcess (const lldb::ProcessSP &processSP);
348 
349     void
350     reset (const lldb::DebuggerSP &debugger_sp);
351 
352     lldb_private::Debugger *
353     get () const;
354 
355     lldb_private::Debugger &
356     ref () const;
357 
358     const lldb::DebuggerSP &
359     get_sp () const;
360 
361     lldb::DebuggerSP m_opaque_sp;
362 
363 }; // class SBDebugger
364 
365 } // namespace lldb
366 
367 #endif // LLDB_SBDebugger_h_
368