1 //===-- SBDebugger.h --------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_API_SBDEBUGGER_H
10 #define LLDB_API_SBDEBUGGER_H
14 #include "lldb/API/SBDefines.h"
15 #include "lldb/API/SBPlatform.h"
19 class LLDB_API SBInputReader {
21 SBInputReader() = default;
22 ~SBInputReader() = default;
24 SBError Initialize(lldb::SBDebugger &sb_debugger,
25 unsigned long (*callback)(void *, lldb::SBInputReader *,
26 lldb::InputReaderAction,
27 char const *, unsigned long),
28 void *a, lldb::InputReaderGranularity b, char const *c,
29 char const *d, bool e);
31 bool IsActive() const;
34 class LLDB_API SBDebugger {
38 SBDebugger(const lldb::SBDebugger &rhs);
40 SBDebugger(const lldb::DebuggerSP &debugger_sp);
44 lldb::SBDebugger &operator=(const lldb::SBDebugger &rhs);
46 static void Initialize();
48 static lldb::SBError InitializeWithErrorHandling();
50 static void Terminate();
52 // Deprecated, use the one that takes a source_init_files bool.
53 static lldb::SBDebugger Create();
55 static lldb::SBDebugger Create(bool source_init_files);
57 static lldb::SBDebugger Create(bool source_init_files,
58 lldb::LogOutputCallback log_callback,
61 static void Destroy(lldb::SBDebugger &debugger);
63 static void MemoryPressureDetected();
65 explicit operator bool() const;
71 void SetAsync(bool b);
75 void SkipLLDBInitFiles(bool b);
77 void SkipAppInitFiles(bool b);
79 void SetInputFileHandle(FILE *f, bool transfer_ownership);
81 void SetOutputFileHandle(FILE *f, bool transfer_ownership);
83 void SetErrorFileHandle(FILE *f, bool transfer_ownership);
85 FILE *GetInputFileHandle();
87 FILE *GetOutputFileHandle();
89 FILE *GetErrorFileHandle();
91 SBError SetInputFile(SBFile file);
93 SBError SetOutputFile(SBFile file);
95 SBError SetErrorFile(SBFile file);
97 SBError SetInputFile(FileSP file);
99 SBError SetOutputFile(FileSP file);
101 SBError SetErrorFile(FileSP file);
103 SBFile GetInputFile();
105 SBFile GetOutputFile();
107 SBFile GetErrorFile();
109 void SaveInputTerminalState();
111 void RestoreInputTerminalState();
113 lldb::SBCommandInterpreter GetCommandInterpreter();
115 void HandleCommand(const char *command);
117 lldb::SBListener GetListener();
119 void HandleProcessEvent(const lldb::SBProcess &process,
120 const lldb::SBEvent &event, FILE *out,
121 FILE *err); // DEPRECATED
123 void HandleProcessEvent(const lldb::SBProcess &process,
124 const lldb::SBEvent &event, SBFile out, SBFile err);
126 void HandleProcessEvent(const lldb::SBProcess &process,
127 const lldb::SBEvent &event, FileSP out, FileSP err);
129 lldb::SBTarget CreateTarget(const char *filename, const char *target_triple,
130 const char *platform_name,
131 bool add_dependent_modules, lldb::SBError &error);
133 lldb::SBTarget CreateTargetWithFileAndTargetTriple(const char *filename,
134 const char *target_triple);
136 lldb::SBTarget CreateTargetWithFileAndArch(const char *filename,
137 const char *archname);
139 lldb::SBTarget CreateTarget(const char *filename);
141 lldb::SBTarget GetDummyTarget();
143 // Return true if target is deleted from the target list of the debugger.
144 bool DeleteTarget(lldb::SBTarget &target);
146 lldb::SBTarget GetTargetAtIndex(uint32_t idx);
148 uint32_t GetIndexOfTarget(lldb::SBTarget target);
150 lldb::SBTarget FindTargetWithProcessID(pid_t pid);
152 lldb::SBTarget FindTargetWithFileAndArch(const char *filename,
155 uint32_t GetNumTargets();
157 lldb::SBTarget GetSelectedTarget();
159 void SetSelectedTarget(SBTarget &target);
161 lldb::SBPlatform GetSelectedPlatform();
163 void SetSelectedPlatform(lldb::SBPlatform &platform);
165 /// Get the number of currently active platforms.
166 uint32_t GetNumPlatforms();
168 /// Get one of the currently active platforms.
169 lldb::SBPlatform GetPlatformAtIndex(uint32_t idx);
171 /// Get the number of available platforms.
173 /// The return value should match the number of entries output by the
174 /// "platform list" command.
175 uint32_t GetNumAvailablePlatforms();
177 /// Get the name and description of one of the available platforms.
180 /// Zero-based index of the platform for which info should be retrieved,
181 /// must be less than the value returned by GetNumAvailablePlatforms().
182 lldb::SBStructuredData GetAvailablePlatformInfoAtIndex(uint32_t idx);
184 lldb::SBSourceManager GetSourceManager();
186 // REMOVE: just for a quick fix, need to expose platforms through
187 // SBPlatform from this class.
188 lldb::SBError SetCurrentPlatform(const char *platform_name);
190 bool SetCurrentPlatformSDKRoot(const char *sysroot);
192 // FIXME: Once we get the set show stuff in place, the driver won't need
193 // an interface to the Set/Get UseExternalEditor.
194 bool SetUseExternalEditor(bool input);
196 bool GetUseExternalEditor();
198 bool SetUseColor(bool use_color);
200 bool GetUseColor() const;
202 bool SetUseSourceCache(bool use_source_cache);
204 bool GetUseSourceCache() const;
206 static bool GetDefaultArchitecture(char *arch_name, size_t arch_name_len);
208 static bool SetDefaultArchitecture(const char *arch_name);
210 lldb::ScriptLanguage GetScriptingLanguage(const char *script_language_name);
212 static const char *GetVersionString();
214 static const char *StateAsCString(lldb::StateType state);
216 static SBStructuredData GetBuildConfiguration();
218 static bool StateIsRunningState(lldb::StateType state);
220 static bool StateIsStoppedState(lldb::StateType state);
222 bool EnableLog(const char *channel, const char **categories);
224 void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton);
227 void DispatchInput(void *baton, const void *data, size_t data_len);
229 void DispatchInput(const void *data, size_t data_len);
231 void DispatchInputInterrupt();
233 void DispatchInputEndOfFile();
235 void PushInputReader(lldb::SBInputReader &reader);
237 const char *GetInstanceName();
239 static SBDebugger FindDebuggerWithID(int id);
241 static lldb::SBError SetInternalVariable(const char *var_name,
243 const char *debugger_instance_name);
245 static lldb::SBStringList
246 GetInternalVariableValue(const char *var_name,
247 const char *debugger_instance_name);
249 bool GetDescription(lldb::SBStream &description);
251 uint32_t GetTerminalWidth() const;
253 void SetTerminalWidth(uint32_t term_width);
255 lldb::user_id_t GetID();
257 const char *GetPrompt() const;
259 void SetPrompt(const char *prompt);
261 const char *GetReproducerPath() const;
263 lldb::ScriptLanguage GetScriptLanguage() const;
265 void SetScriptLanguage(lldb::ScriptLanguage script_lang);
267 bool GetCloseInputOnEOF() const;
269 void SetCloseInputOnEOF(bool b);
271 SBTypeCategory GetCategory(const char *category_name);
273 SBTypeCategory GetCategory(lldb::LanguageType lang_type);
275 SBTypeCategory CreateCategory(const char *category_name);
277 bool DeleteCategory(const char *category_name);
279 uint32_t GetNumCategories();
281 SBTypeCategory GetCategoryAtIndex(uint32_t);
283 SBTypeCategory GetDefaultCategory();
285 SBTypeFormat GetFormatForType(SBTypeNameSpecifier);
287 SBTypeSummary GetSummaryForType(SBTypeNameSpecifier);
289 SBTypeFilter GetFilterForType(SBTypeNameSpecifier);
291 SBTypeSynthetic GetSyntheticForType(SBTypeNameSpecifier);
293 /// Run the command interpreter.
295 /// \param[in] auto_handle_events
296 /// If true, automatically handle resulting events. This takes precedence
297 /// and overrides the corresponding option in
298 /// SBCommandInterpreterRunOptions.
300 /// \param[in] spawn_thread
301 /// If true, start a new thread for IO handling. This takes precedence
302 /// and overrides the corresponding option in
303 /// SBCommandInterpreterRunOptions.
304 void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread);
306 /// Run the command interpreter.
308 /// \param[in] auto_handle_events
309 /// If true, automatically handle resulting events. This takes precedence
310 /// and overrides the corresponding option in
311 /// SBCommandInterpreterRunOptions.
313 /// \param[in] spawn_thread
314 /// If true, start a new thread for IO handling. This takes precedence
315 /// and overrides the corresponding option in
316 /// SBCommandInterpreterRunOptions.
318 /// \param[in] options
319 /// Parameter collection of type SBCommandInterpreterRunOptions.
321 /// \param[out] num_errors
322 /// The number of errors.
324 /// \param[out] quit_requested
325 /// Whether a quit was requested.
327 /// \param[out] stopped_for_crash
328 /// Whether the interpreter stopped for a crash.
329 void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread,
330 SBCommandInterpreterRunOptions &options,
331 int &num_errors, bool &quit_requested,
332 bool &stopped_for_crash);
334 SBCommandInterpreterRunResult
335 RunCommandInterpreter(const SBCommandInterpreterRunOptions &options);
337 SBError RunREPL(lldb::LanguageType language, const char *repl_options);
340 friend class SBCommandInterpreter;
341 friend class SBInputReader;
342 friend class SBListener;
343 friend class SBProcess;
344 friend class SBSourceManager;
345 friend class SBTarget;
347 lldb::SBTarget FindTargetWithLLDBProcess(const lldb::ProcessSP &processSP);
349 void reset(const lldb::DebuggerSP &debugger_sp);
351 lldb_private::Debugger *get() const;
353 lldb_private::Debugger &ref() const;
355 const lldb::DebuggerSP &get_sp() const;
357 lldb::DebuggerSP m_opaque_sp;
359 }; // class SBDebugger
363 #endif // LLDB_API_SBDEBUGGER_H