SBDebugger.h revision 360784
1//===-- 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  SBError SetInputFile(SBFile file);
92
93  SBError SetOutputFile(SBFile file);
94
95  SBError SetErrorFile(SBFile file);
96
97  SBError SetInputFile(FileSP file);
98
99  SBError SetOutputFile(FileSP file);
100
101  SBError SetErrorFile(FileSP file);
102
103  SBFile GetInputFile();
104
105  SBFile GetOutputFile();
106
107  SBFile GetErrorFile();
108
109  void SaveInputTerminalState();
110
111  void RestoreInputTerminalState();
112
113  lldb::SBCommandInterpreter GetCommandInterpreter();
114
115  void HandleCommand(const char *command);
116
117  lldb::SBListener GetListener();
118
119  void HandleProcessEvent(const lldb::SBProcess &process,
120                          const lldb::SBEvent &event, FILE *out,
121                          FILE *err); // DEPRECATED
122
123  void HandleProcessEvent(const lldb::SBProcess &process,
124                          const lldb::SBEvent &event, SBFile out, SBFile err);
125
126  void HandleProcessEvent(const lldb::SBProcess &process,
127                          const lldb::SBEvent &event, FileSP out, FileSP err);
128
129  lldb::SBTarget CreateTarget(const char *filename, const char *target_triple,
130                              const char *platform_name,
131                              bool add_dependent_modules, lldb::SBError &error);
132
133  lldb::SBTarget CreateTargetWithFileAndTargetTriple(const char *filename,
134                                                     const char *target_triple);
135
136  lldb::SBTarget CreateTargetWithFileAndArch(const char *filename,
137                                             const char *archname);
138
139  lldb::SBTarget CreateTarget(const char *filename);
140
141  lldb::SBTarget GetDummyTarget();
142
143  // Return true if target is deleted from the target list of the debugger.
144  bool DeleteTarget(lldb::SBTarget &target);
145
146  lldb::SBTarget GetTargetAtIndex(uint32_t idx);
147
148  uint32_t GetIndexOfTarget(lldb::SBTarget target);
149
150  lldb::SBTarget FindTargetWithProcessID(pid_t pid);
151
152  lldb::SBTarget FindTargetWithFileAndArch(const char *filename,
153                                           const char *arch);
154
155  uint32_t GetNumTargets();
156
157  lldb::SBTarget GetSelectedTarget();
158
159  void SetSelectedTarget(SBTarget &target);
160
161  lldb::SBPlatform GetSelectedPlatform();
162
163  void SetSelectedPlatform(lldb::SBPlatform &platform);
164
165  /// Get the number of currently active platforms.
166  uint32_t GetNumPlatforms();
167
168  /// Get one of the currently active platforms.
169  lldb::SBPlatform GetPlatformAtIndex(uint32_t idx);
170
171  /// Get the number of available platforms.
172  ///
173  /// The return value should match the number of entries output by the
174  /// "platform list" command.
175  uint32_t GetNumAvailablePlatforms();
176
177  /// Get the name and description of one of the available platforms.
178  ///
179  /// \param[in] idx
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);
183
184  lldb::SBSourceManager GetSourceManager();
185
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);
189
190  bool SetCurrentPlatformSDKRoot(const char *sysroot);
191
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);
195
196  bool GetUseExternalEditor();
197
198  bool SetUseColor(bool use_color);
199
200  bool GetUseColor() const;
201
202  static bool GetDefaultArchitecture(char *arch_name, size_t arch_name_len);
203
204  static bool SetDefaultArchitecture(const char *arch_name);
205
206  lldb::ScriptLanguage GetScriptingLanguage(const char *script_language_name);
207
208  static const char *GetVersionString();
209
210  static const char *StateAsCString(lldb::StateType state);
211
212  static SBStructuredData GetBuildConfiguration();
213
214  static bool StateIsRunningState(lldb::StateType state);
215
216  static bool StateIsStoppedState(lldb::StateType state);
217
218  bool EnableLog(const char *channel, const char **categories);
219
220  void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton);
221
222  // DEPRECATED
223  void DispatchInput(void *baton, const void *data, size_t data_len);
224
225  void DispatchInput(const void *data, size_t data_len);
226
227  void DispatchInputInterrupt();
228
229  void DispatchInputEndOfFile();
230
231  void PushInputReader(lldb::SBInputReader &reader);
232
233  const char *GetInstanceName();
234
235  static SBDebugger FindDebuggerWithID(int id);
236
237  static lldb::SBError SetInternalVariable(const char *var_name,
238                                           const char *value,
239                                           const char *debugger_instance_name);
240
241  static lldb::SBStringList
242  GetInternalVariableValue(const char *var_name,
243                           const char *debugger_instance_name);
244
245  bool GetDescription(lldb::SBStream &description);
246
247  uint32_t GetTerminalWidth() const;
248
249  void SetTerminalWidth(uint32_t term_width);
250
251  lldb::user_id_t GetID();
252
253  const char *GetPrompt() const;
254
255  void SetPrompt(const char *prompt);
256
257  const char *GetReproducerPath() const;
258
259  lldb::ScriptLanguage GetScriptLanguage() const;
260
261  void SetScriptLanguage(lldb::ScriptLanguage script_lang);
262
263  bool GetCloseInputOnEOF() const;
264
265  void SetCloseInputOnEOF(bool b);
266
267  SBTypeCategory GetCategory(const char *category_name);
268
269  SBTypeCategory GetCategory(lldb::LanguageType lang_type);
270
271  SBTypeCategory CreateCategory(const char *category_name);
272
273  bool DeleteCategory(const char *category_name);
274
275  uint32_t GetNumCategories();
276
277  SBTypeCategory GetCategoryAtIndex(uint32_t);
278
279  SBTypeCategory GetDefaultCategory();
280
281  SBTypeFormat GetFormatForType(SBTypeNameSpecifier);
282
283  SBTypeSummary GetSummaryForType(SBTypeNameSpecifier);
284
285  SBTypeFilter GetFilterForType(SBTypeNameSpecifier);
286
287  SBTypeSynthetic GetSyntheticForType(SBTypeNameSpecifier);
288
289  void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread);
290
291  void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread,
292                             SBCommandInterpreterRunOptions &options,
293                             int &num_errors, bool &quit_requested,
294                             bool &stopped_for_crash);
295
296  SBError RunREPL(lldb::LanguageType language, const char *repl_options);
297
298private:
299  friend class SBCommandInterpreter;
300  friend class SBInputReader;
301  friend class SBListener;
302  friend class SBProcess;
303  friend class SBSourceManager;
304  friend class SBTarget;
305
306  lldb::SBTarget FindTargetWithLLDBProcess(const lldb::ProcessSP &processSP);
307
308  void reset(const lldb::DebuggerSP &debugger_sp);
309
310  lldb_private::Debugger *get() const;
311
312  lldb_private::Debugger &ref() const;
313
314  const lldb::DebuggerSP &get_sp() const;
315
316  lldb::DebuggerSP m_opaque_sp;
317
318}; // class SBDebugger
319
320} // namespace lldb
321
322#endif // LLDB_SBDebugger_h_
323