1 //===-- SBDebugger.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLDB_SBDebugger_h_
11 #define LLDB_SBDebugger_h_
15 #include "lldb/API/SBDefines.h"
16 #include "lldb/API/SBInitializerOptions.h"
17 #include "lldb/API/SBPlatform.h"
21 class LLDB_API SBInputReader {
23 SBInputReader() = default;
24 ~SBInputReader() = default;
26 SBError Initialize(lldb::SBDebugger &,
27 unsigned long (*)(void *, lldb::SBInputReader *,
28 lldb::InputReaderAction, char const *,
30 void *, lldb::InputReaderGranularity, char const *,
33 bool IsActive() const;
36 class LLDB_API SBDebugger {
40 SBDebugger(const lldb::SBDebugger &rhs);
42 SBDebugger(const lldb::DebuggerSP &debugger_sp);
46 lldb::SBDebugger &operator=(const lldb::SBDebugger &rhs);
48 static void Initialize();
49 static lldb::SBError Initialize(SBInitializerOptions &options);
51 static void Terminate();
53 // Deprecated, use the one that takes a source_init_files bool.
54 static lldb::SBDebugger Create();
56 static lldb::SBDebugger Create(bool source_init_files);
58 static lldb::SBDebugger Create(bool source_init_files,
59 lldb::LogOutputCallback log_callback,
62 static void Destroy(lldb::SBDebugger &debugger);
64 static void MemoryPressureDetected();
70 void SetAsync(bool b);
74 void SkipLLDBInitFiles(bool b);
76 void SkipAppInitFiles(bool b);
78 void SetInputFileHandle(FILE *f, bool transfer_ownership);
80 void SetOutputFileHandle(FILE *f, bool transfer_ownership);
82 void SetErrorFileHandle(FILE *f, bool transfer_ownership);
84 FILE *GetInputFileHandle();
86 FILE *GetOutputFileHandle();
88 FILE *GetErrorFileHandle();
90 void SaveInputTerminalState();
92 void RestoreInputTerminalState();
94 lldb::SBCommandInterpreter GetCommandInterpreter();
96 void HandleCommand(const char *command);
98 lldb::SBListener GetListener();
100 void HandleProcessEvent(const lldb::SBProcess &process,
101 const lldb::SBEvent &event, FILE *out, FILE *err);
103 lldb::SBTarget CreateTarget(const char *filename, const char *target_triple,
104 const char *platform_name,
105 bool add_dependent_modules, lldb::SBError &error);
107 lldb::SBTarget CreateTargetWithFileAndTargetTriple(const char *filename,
108 const char *target_triple);
110 lldb::SBTarget CreateTargetWithFileAndArch(const char *filename,
111 const char *archname);
113 lldb::SBTarget CreateTarget(const char *filename);
115 lldb::SBTarget GetDummyTarget();
117 // Return true if target is deleted from the target list of the debugger.
118 bool DeleteTarget(lldb::SBTarget &target);
120 lldb::SBTarget GetTargetAtIndex(uint32_t idx);
122 uint32_t GetIndexOfTarget(lldb::SBTarget target);
124 lldb::SBTarget FindTargetWithProcessID(pid_t pid);
126 lldb::SBTarget FindTargetWithFileAndArch(const char *filename,
129 uint32_t GetNumTargets();
131 lldb::SBTarget GetSelectedTarget();
133 void SetSelectedTarget(SBTarget &target);
135 lldb::SBPlatform GetSelectedPlatform();
137 void SetSelectedPlatform(lldb::SBPlatform &platform);
139 /// Get the number of currently active platforms.
140 uint32_t GetNumPlatforms();
142 /// Get one of the currently active platforms.
143 lldb::SBPlatform GetPlatformAtIndex(uint32_t idx);
145 /// Get the number of available platforms.
147 /// The return value should match the number of entries output by the
148 /// "platform list" command.
149 uint32_t GetNumAvailablePlatforms();
151 /// Get the name and description of one of the available platforms.
154 /// Zero-based index of the platform for which info should be retrieved,
155 /// must be less than the value returned by GetNumAvailablePlatforms().
156 lldb::SBStructuredData GetAvailablePlatformInfoAtIndex(uint32_t idx);
158 lldb::SBSourceManager GetSourceManager();
160 // REMOVE: just for a quick fix, need to expose platforms through
161 // SBPlatform from this class.
162 lldb::SBError SetCurrentPlatform(const char *platform_name);
164 bool SetCurrentPlatformSDKRoot(const char *sysroot);
166 // FIXME: Once we get the set show stuff in place, the driver won't need
167 // an interface to the Set/Get UseExternalEditor.
168 bool SetUseExternalEditor(bool input);
170 bool GetUseExternalEditor();
172 bool SetUseColor(bool use_color);
174 bool GetUseColor() const;
176 static bool GetDefaultArchitecture(char *arch_name, size_t arch_name_len);
178 static bool SetDefaultArchitecture(const char *arch_name);
180 lldb::ScriptLanguage GetScriptingLanguage(const char *script_language_name);
182 static const char *GetVersionString();
184 static const char *StateAsCString(lldb::StateType state);
186 static SBStructuredData GetBuildConfiguration();
188 static bool StateIsRunningState(lldb::StateType state);
190 static bool StateIsStoppedState(lldb::StateType state);
192 bool EnableLog(const char *channel, const char **categories);
194 void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton);
197 void DispatchInput(void *baton, const void *data, size_t data_len);
199 void DispatchInput(const void *data, size_t data_len);
201 void DispatchInputInterrupt();
203 void DispatchInputEndOfFile();
205 void PushInputReader(lldb::SBInputReader &reader);
207 const char *GetInstanceName();
209 static SBDebugger FindDebuggerWithID(int id);
211 static lldb::SBError SetInternalVariable(const char *var_name,
213 const char *debugger_instance_name);
215 static lldb::SBStringList
216 GetInternalVariableValue(const char *var_name,
217 const char *debugger_instance_name);
219 bool GetDescription(lldb::SBStream &description);
221 uint32_t GetTerminalWidth() const;
223 void SetTerminalWidth(uint32_t term_width);
225 lldb::user_id_t GetID();
227 const char *GetPrompt() const;
229 void SetPrompt(const char *prompt);
231 const char *GetReproducerPath() const;
233 lldb::ScriptLanguage GetScriptLanguage() const;
235 void SetScriptLanguage(lldb::ScriptLanguage script_lang);
237 bool GetCloseInputOnEOF() const;
239 void SetCloseInputOnEOF(bool b);
241 SBTypeCategory GetCategory(const char *category_name);
243 SBTypeCategory GetCategory(lldb::LanguageType lang_type);
245 SBTypeCategory CreateCategory(const char *category_name);
247 bool DeleteCategory(const char *category_name);
249 uint32_t GetNumCategories();
251 SBTypeCategory GetCategoryAtIndex(uint32_t);
253 SBTypeCategory GetDefaultCategory();
255 SBTypeFormat GetFormatForType(SBTypeNameSpecifier);
257 #ifndef LLDB_DISABLE_PYTHON
258 SBTypeSummary GetSummaryForType(SBTypeNameSpecifier);
261 SBTypeFilter GetFilterForType(SBTypeNameSpecifier);
263 #ifndef LLDB_DISABLE_PYTHON
264 SBTypeSynthetic GetSyntheticForType(SBTypeNameSpecifier);
267 void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread);
269 void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread,
270 SBCommandInterpreterRunOptions &options,
271 int &num_errors, bool &quit_requested,
272 bool &stopped_for_crash);
274 SBError RunREPL(lldb::LanguageType language, const char *repl_options);
277 friend class SBCommandInterpreter;
278 friend class SBInputReader;
279 friend class SBListener;
280 friend class SBProcess;
281 friend class SBSourceManager;
282 friend class SBTarget;
284 lldb::SBTarget FindTargetWithLLDBProcess(const lldb::ProcessSP &processSP);
286 void reset(const lldb::DebuggerSP &debugger_sp);
288 lldb_private::Debugger *get() const;
290 lldb_private::Debugger &ref() const;
292 const lldb::DebuggerSP &get_sp() const;
294 lldb::DebuggerSP m_opaque_sp;
296 }; // class SBDebugger
300 #endif // LLDB_SBDebugger_h_