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_SBDebugger_h_
10 #define LLDB_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 void SaveInputTerminalState();
93 void RestoreInputTerminalState();
95 lldb::SBCommandInterpreter GetCommandInterpreter();
97 void HandleCommand(const char *command);
99 lldb::SBListener GetListener();
101 void HandleProcessEvent(const lldb::SBProcess &process,
102 const lldb::SBEvent &event, FILE *out, FILE *err);
104 lldb::SBTarget CreateTarget(const char *filename, const char *target_triple,
105 const char *platform_name,
106 bool add_dependent_modules, lldb::SBError &error);
108 lldb::SBTarget CreateTargetWithFileAndTargetTriple(const char *filename,
109 const char *target_triple);
111 lldb::SBTarget CreateTargetWithFileAndArch(const char *filename,
112 const char *archname);
114 lldb::SBTarget CreateTarget(const char *filename);
116 lldb::SBTarget GetDummyTarget();
118 // Return true if target is deleted from the target list of the debugger.
119 bool DeleteTarget(lldb::SBTarget &target);
121 lldb::SBTarget GetTargetAtIndex(uint32_t idx);
123 uint32_t GetIndexOfTarget(lldb::SBTarget target);
125 lldb::SBTarget FindTargetWithProcessID(pid_t pid);
127 lldb::SBTarget FindTargetWithFileAndArch(const char *filename,
130 uint32_t GetNumTargets();
132 lldb::SBTarget GetSelectedTarget();
134 void SetSelectedTarget(SBTarget &target);
136 lldb::SBPlatform GetSelectedPlatform();
138 void SetSelectedPlatform(lldb::SBPlatform &platform);
140 /// Get the number of currently active platforms.
141 uint32_t GetNumPlatforms();
143 /// Get one of the currently active platforms.
144 lldb::SBPlatform GetPlatformAtIndex(uint32_t idx);
146 /// Get the number of available platforms.
148 /// The return value should match the number of entries output by the
149 /// "platform list" command.
150 uint32_t GetNumAvailablePlatforms();
152 /// Get the name and description of one of the available platforms.
155 /// Zero-based index of the platform for which info should be retrieved,
156 /// must be less than the value returned by GetNumAvailablePlatforms().
157 lldb::SBStructuredData GetAvailablePlatformInfoAtIndex(uint32_t idx);
159 lldb::SBSourceManager GetSourceManager();
161 // REMOVE: just for a quick fix, need to expose platforms through
162 // SBPlatform from this class.
163 lldb::SBError SetCurrentPlatform(const char *platform_name);
165 bool SetCurrentPlatformSDKRoot(const char *sysroot);
167 // FIXME: Once we get the set show stuff in place, the driver won't need
168 // an interface to the Set/Get UseExternalEditor.
169 bool SetUseExternalEditor(bool input);
171 bool GetUseExternalEditor();
173 bool SetUseColor(bool use_color);
175 bool GetUseColor() const;
177 static bool GetDefaultArchitecture(char *arch_name, size_t arch_name_len);
179 static bool SetDefaultArchitecture(const char *arch_name);
181 lldb::ScriptLanguage GetScriptingLanguage(const char *script_language_name);
183 static const char *GetVersionString();
185 static const char *StateAsCString(lldb::StateType state);
187 static SBStructuredData GetBuildConfiguration();
189 static bool StateIsRunningState(lldb::StateType state);
191 static bool StateIsStoppedState(lldb::StateType state);
193 bool EnableLog(const char *channel, const char **categories);
195 void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton);
198 void DispatchInput(void *baton, const void *data, size_t data_len);
200 void DispatchInput(const void *data, size_t data_len);
202 void DispatchInputInterrupt();
204 void DispatchInputEndOfFile();
206 void PushInputReader(lldb::SBInputReader &reader);
208 const char *GetInstanceName();
210 static SBDebugger FindDebuggerWithID(int id);
212 static lldb::SBError SetInternalVariable(const char *var_name,
214 const char *debugger_instance_name);
216 static lldb::SBStringList
217 GetInternalVariableValue(const char *var_name,
218 const char *debugger_instance_name);
220 bool GetDescription(lldb::SBStream &description);
222 uint32_t GetTerminalWidth() const;
224 void SetTerminalWidth(uint32_t term_width);
226 lldb::user_id_t GetID();
228 const char *GetPrompt() const;
230 void SetPrompt(const char *prompt);
232 const char *GetReproducerPath() const;
234 lldb::ScriptLanguage GetScriptLanguage() const;
236 void SetScriptLanguage(lldb::ScriptLanguage script_lang);
238 bool GetCloseInputOnEOF() const;
240 void SetCloseInputOnEOF(bool b);
242 SBTypeCategory GetCategory(const char *category_name);
244 SBTypeCategory GetCategory(lldb::LanguageType lang_type);
246 SBTypeCategory CreateCategory(const char *category_name);
248 bool DeleteCategory(const char *category_name);
250 uint32_t GetNumCategories();
252 SBTypeCategory GetCategoryAtIndex(uint32_t);
254 SBTypeCategory GetDefaultCategory();
256 SBTypeFormat GetFormatForType(SBTypeNameSpecifier);
258 SBTypeSummary GetSummaryForType(SBTypeNameSpecifier);
260 SBTypeFilter GetFilterForType(SBTypeNameSpecifier);
262 SBTypeSynthetic GetSyntheticForType(SBTypeNameSpecifier);
264 void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread);
266 void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread,
267 SBCommandInterpreterRunOptions &options,
268 int &num_errors, bool &quit_requested,
269 bool &stopped_for_crash);
271 SBError RunREPL(lldb::LanguageType language, const char *repl_options);
274 friend class SBCommandInterpreter;
275 friend class SBInputReader;
276 friend class SBListener;
277 friend class SBProcess;
278 friend class SBSourceManager;
279 friend class SBTarget;
281 lldb::SBTarget FindTargetWithLLDBProcess(const lldb::ProcessSP &processSP);
283 void reset(const lldb::DebuggerSP &debugger_sp);
285 lldb_private::Debugger *get() const;
287 lldb_private::Debugger &ref() const;
289 const lldb::DebuggerSP &get_sp() const;
291 lldb::DebuggerSP m_opaque_sp;
293 }; // class SBDebugger
297 #endif // LLDB_SBDebugger_h_