blob: 417cead24a8c61e479bc9e4590697e5c51420b01 [file] [log] [blame]
Andrew Walbran3d2c1972020-04-07 12:24:26 +01001//===-- SBDebugger.h --------------------------------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SBDebugger_h_
10#define LLDB_SBDebugger_h_
11
12#include <stdio.h>
13
14#include "lldb/API/SBDefines.h"
15#include "lldb/API/SBPlatform.h"
16
17namespace lldb {
18
19class LLDB_API SBInputReader {
20public:
21 SBInputReader() = default;
22 ~SBInputReader() = default;
23
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);
30 void SetIsDone(bool);
31 bool IsActive() const;
32};
33
34class LLDB_API SBDebugger {
35public:
36 SBDebugger();
37
38 SBDebugger(const lldb::SBDebugger &rhs);
39
40 SBDebugger(const lldb::DebuggerSP &debugger_sp);
41
42 ~SBDebugger();
43
44 lldb::SBDebugger &operator=(const lldb::SBDebugger &rhs);
45
46 static void Initialize();
47
48 static lldb::SBError InitializeWithErrorHandling();
49
50 static void Terminate();
51
52 // Deprecated, use the one that takes a source_init_files bool.
53 static lldb::SBDebugger Create();
54
55 static lldb::SBDebugger Create(bool source_init_files);
56
57 static lldb::SBDebugger Create(bool source_init_files,
58 lldb::LogOutputCallback log_callback,
59 void *baton);
60
61 static void Destroy(lldb::SBDebugger &debugger);
62
63 static void MemoryPressureDetected();
64
65 explicit operator bool() const;
66
67 bool IsValid() const;
68
69 void Clear();
70
71 void SetAsync(bool b);
72
73 bool GetAsync();
74
75 void SkipLLDBInitFiles(bool b);
76
77 void SkipAppInitFiles(bool b);
78
79 void SetInputFileHandle(FILE *f, bool transfer_ownership);
80
81 void SetOutputFileHandle(FILE *f, bool transfer_ownership);
82
83 void SetErrorFileHandle(FILE *f, bool transfer_ownership);
84
85 FILE *GetInputFileHandle();
86
87 FILE *GetOutputFileHandle();
88
89 FILE *GetErrorFileHandle();
90
91 void SaveInputTerminalState();
92
93 void RestoreInputTerminalState();
94
95 lldb::SBCommandInterpreter GetCommandInterpreter();
96
97 void HandleCommand(const char *command);
98
99 lldb::SBListener GetListener();
100
101 void HandleProcessEvent(const lldb::SBProcess &process,
102 const lldb::SBEvent &event, FILE *out, FILE *err);
103
104 lldb::SBTarget CreateTarget(const char *filename, const char *target_triple,
105 const char *platform_name,
106 bool add_dependent_modules, lldb::SBError &error);
107
108 lldb::SBTarget CreateTargetWithFileAndTargetTriple(const char *filename,
109 const char *target_triple);
110
111 lldb::SBTarget CreateTargetWithFileAndArch(const char *filename,
112 const char *archname);
113
114 lldb::SBTarget CreateTarget(const char *filename);
115
116 lldb::SBTarget GetDummyTarget();
117
118 // Return true if target is deleted from the target list of the debugger.
119 bool DeleteTarget(lldb::SBTarget &target);
120
121 lldb::SBTarget GetTargetAtIndex(uint32_t idx);
122
123 uint32_t GetIndexOfTarget(lldb::SBTarget target);
124
125 lldb::SBTarget FindTargetWithProcessID(pid_t pid);
126
127 lldb::SBTarget FindTargetWithFileAndArch(const char *filename,
128 const char *arch);
129
130 uint32_t GetNumTargets();
131
132 lldb::SBTarget GetSelectedTarget();
133
134 void SetSelectedTarget(SBTarget &target);
135
136 lldb::SBPlatform GetSelectedPlatform();
137
138 void SetSelectedPlatform(lldb::SBPlatform &platform);
139
140 /// Get the number of currently active platforms.
141 uint32_t GetNumPlatforms();
142
143 /// Get one of the currently active platforms.
144 lldb::SBPlatform GetPlatformAtIndex(uint32_t idx);
145
146 /// Get the number of available platforms.
147 ///
148 /// The return value should match the number of entries output by the
149 /// "platform list" command.
150 uint32_t GetNumAvailablePlatforms();
151
152 /// Get the name and description of one of the available platforms.
153 ///
154 /// \param[in] idx
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);
158
159 lldb::SBSourceManager GetSourceManager();
160
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);
164
165 bool SetCurrentPlatformSDKRoot(const char *sysroot);
166
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);
170
171 bool GetUseExternalEditor();
172
173 bool SetUseColor(bool use_color);
174
175 bool GetUseColor() const;
176
177 static bool GetDefaultArchitecture(char *arch_name, size_t arch_name_len);
178
179 static bool SetDefaultArchitecture(const char *arch_name);
180
181 lldb::ScriptLanguage GetScriptingLanguage(const char *script_language_name);
182
183 static const char *GetVersionString();
184
185 static const char *StateAsCString(lldb::StateType state);
186
187 static SBStructuredData GetBuildConfiguration();
188
189 static bool StateIsRunningState(lldb::StateType state);
190
191 static bool StateIsStoppedState(lldb::StateType state);
192
193 bool EnableLog(const char *channel, const char **categories);
194
195 void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton);
196
197 // DEPRECATED
198 void DispatchInput(void *baton, const void *data, size_t data_len);
199
200 void DispatchInput(const void *data, size_t data_len);
201
202 void DispatchInputInterrupt();
203
204 void DispatchInputEndOfFile();
205
206 void PushInputReader(lldb::SBInputReader &reader);
207
208 const char *GetInstanceName();
209
210 static SBDebugger FindDebuggerWithID(int id);
211
212 static lldb::SBError SetInternalVariable(const char *var_name,
213 const char *value,
214 const char *debugger_instance_name);
215
216 static lldb::SBStringList
217 GetInternalVariableValue(const char *var_name,
218 const char *debugger_instance_name);
219
220 bool GetDescription(lldb::SBStream &description);
221
222 uint32_t GetTerminalWidth() const;
223
224 void SetTerminalWidth(uint32_t term_width);
225
226 lldb::user_id_t GetID();
227
228 const char *GetPrompt() const;
229
230 void SetPrompt(const char *prompt);
231
232 const char *GetReproducerPath() const;
233
234 lldb::ScriptLanguage GetScriptLanguage() const;
235
236 void SetScriptLanguage(lldb::ScriptLanguage script_lang);
237
238 bool GetCloseInputOnEOF() const;
239
240 void SetCloseInputOnEOF(bool b);
241
242 SBTypeCategory GetCategory(const char *category_name);
243
244 SBTypeCategory GetCategory(lldb::LanguageType lang_type);
245
246 SBTypeCategory CreateCategory(const char *category_name);
247
248 bool DeleteCategory(const char *category_name);
249
250 uint32_t GetNumCategories();
251
252 SBTypeCategory GetCategoryAtIndex(uint32_t);
253
254 SBTypeCategory GetDefaultCategory();
255
256 SBTypeFormat GetFormatForType(SBTypeNameSpecifier);
257
258 SBTypeSummary GetSummaryForType(SBTypeNameSpecifier);
259
260 SBTypeFilter GetFilterForType(SBTypeNameSpecifier);
261
262 SBTypeSynthetic GetSyntheticForType(SBTypeNameSpecifier);
263
264 void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread);
265
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);
270
271 SBError RunREPL(lldb::LanguageType language, const char *repl_options);
272
273private:
274 friend class SBCommandInterpreter;
275 friend class SBInputReader;
276 friend class SBListener;
277 friend class SBProcess;
278 friend class SBSourceManager;
279 friend class SBTarget;
280
281 lldb::SBTarget FindTargetWithLLDBProcess(const lldb::ProcessSP &processSP);
282
283 void reset(const lldb::DebuggerSP &debugger_sp);
284
285 lldb_private::Debugger *get() const;
286
287 lldb_private::Debugger &ref() const;
288
289 const lldb::DebuggerSP &get_sp() const;
290
291 lldb::DebuggerSP m_opaque_sp;
292
293}; // class SBDebugger
294
295} // namespace lldb
296
297#endif // LLDB_SBDebugger_h_