LLDB  mainline
SBDebugger.h
Go to the documentation of this file.
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_API_SBDEBUGGER_H
10 #define LLDB_API_SBDEBUGGER_H
11 
12 #include <cstdio>
13 
14 #include "lldb/API/SBDefines.h"
15 #include "lldb/API/SBPlatform.h"
16 
17 namespace lldb {
18 
20 public:
21  SBInputReader() = default;
22  ~SBInputReader() = default;
23 
24  SBError Initialize(lldb::SBDebugger &sb_debugger,
25  unsigned long (*callback)(void *, lldb::SBInputReader *,
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 
35 public:
36  FLAGS_ANONYMOUS_ENUM(){eBroadcastBitProgress = (1 << 0)};
37 
38  SBDebugger();
39 
40  SBDebugger(const lldb::SBDebugger &rhs);
41 
42  SBDebugger(const lldb::DebuggerSP &debugger_sp);
43 
44  ~SBDebugger();
45 
46  static const char *GetBroadcasterClass();
47 
48  lldb::SBBroadcaster GetBroadcaster();
49 
50  /// Get progress data from a SBEvent whose type is eBroadcastBitProgress.
51  ///
52  /// \param [in] event
53  /// The event to extract the progress information from.
54  ///
55  /// \param [out] progress_id
56  /// The unique integer identifier for the progress to report.
57  ///
58  /// \param [out] completed
59  /// The amount of work completed. If \a completed is zero, then this event
60  /// is a progress started event. If \a completed is equal to \a total, then
61  /// this event is a progress end event. Otherwise completed indicates the
62  /// current progress update.
63  ///
64  /// \param [out] total
65  /// The total amount of work units that need to be completed. If this value
66  /// is UINT64_MAX, then an indeterminate progress indicator should be
67  /// displayed.
68  ///
69  /// \param [out] is_debugger_specific
70  /// Set to true if this progress is specific to this debugger only. Many
71  /// progress events are not specific to a debugger instance, like any
72  /// progress events for loading information in modules since LLDB has a
73  /// global module cache that all debuggers use.
74  ///
75  /// \return The message for the progress. If the returned value is NULL, then
76  /// \a event was not a eBroadcastBitProgress event.
77  static const char *GetProgressFromEvent(const lldb::SBEvent &event,
78  uint64_t &progress_id,
79  uint64_t &completed, uint64_t &total,
80  bool &is_debugger_specific);
81 
82  lldb::SBDebugger &operator=(const lldb::SBDebugger &rhs);
83 
84  static void Initialize();
85 
86  static lldb::SBError InitializeWithErrorHandling();
87 
88  static void Terminate();
89 
90  // Deprecated, use the one that takes a source_init_files bool.
91  static lldb::SBDebugger Create();
92 
93  static lldb::SBDebugger Create(bool source_init_files);
94 
95  static lldb::SBDebugger Create(bool source_init_files,
96  lldb::LogOutputCallback log_callback,
97  void *baton);
98 
99  static void Destroy(lldb::SBDebugger &debugger);
100 
101  static void MemoryPressureDetected();
102 
103  explicit operator bool() const;
104 
105  bool IsValid() const;
106 
107  void Clear();
108 
109  void SetAsync(bool b);
110 
111  bool GetAsync();
112 
113  void SkipLLDBInitFiles(bool b);
114 
115  void SkipAppInitFiles(bool b);
116 
117  void SetInputFileHandle(FILE *f, bool transfer_ownership);
118 
119  void SetOutputFileHandle(FILE *f, bool transfer_ownership);
120 
121  void SetErrorFileHandle(FILE *f, bool transfer_ownership);
122 
123  FILE *GetInputFileHandle();
124 
125  FILE *GetOutputFileHandle();
126 
127  FILE *GetErrorFileHandle();
128 
129  SBError SetInputString(const char *data);
130 
131  SBError SetInputFile(SBFile file);
132 
133  SBError SetOutputFile(SBFile file);
134 
135  SBError SetErrorFile(SBFile file);
136 
137  SBError SetInputFile(FileSP file);
138 
139  SBError SetOutputFile(FileSP file);
140 
141  SBError SetErrorFile(FileSP file);
142 
143  SBFile GetInputFile();
144 
145  SBFile GetOutputFile();
146 
147  SBFile GetErrorFile();
148 
149  void SaveInputTerminalState();
150 
151  void RestoreInputTerminalState();
152 
153  lldb::SBCommandInterpreter GetCommandInterpreter();
154 
155  void HandleCommand(const char *command);
156 
157  lldb::SBListener GetListener();
158 
159  void HandleProcessEvent(const lldb::SBProcess &process,
160  const lldb::SBEvent &event, FILE *out,
161  FILE *err); // DEPRECATED
162 
163  void HandleProcessEvent(const lldb::SBProcess &process,
164  const lldb::SBEvent &event, SBFile out, SBFile err);
165 
166  void HandleProcessEvent(const lldb::SBProcess &process,
167  const lldb::SBEvent &event, FileSP out, FileSP err);
168 
169  lldb::SBTarget CreateTarget(const char *filename, const char *target_triple,
170  const char *platform_name,
171  bool add_dependent_modules, lldb::SBError &error);
172 
173  lldb::SBTarget CreateTargetWithFileAndTargetTriple(const char *filename,
174  const char *target_triple);
175 
176  lldb::SBTarget CreateTargetWithFileAndArch(const char *filename,
177  const char *archname);
178 
179  lldb::SBTarget CreateTarget(const char *filename);
180 
181  lldb::SBTarget GetDummyTarget();
182 
183  // Return true if target is deleted from the target list of the debugger.
184  bool DeleteTarget(lldb::SBTarget &target);
185 
186  lldb::SBTarget GetTargetAtIndex(uint32_t idx);
187 
188  uint32_t GetIndexOfTarget(lldb::SBTarget target);
189 
190  lldb::SBTarget FindTargetWithProcessID(pid_t pid);
191 
192  lldb::SBTarget FindTargetWithFileAndArch(const char *filename,
193  const char *arch);
194 
195  uint32_t GetNumTargets();
196 
197  lldb::SBTarget GetSelectedTarget();
198 
199  void SetSelectedTarget(SBTarget &target);
200 
201  lldb::SBPlatform GetSelectedPlatform();
202 
203  void SetSelectedPlatform(lldb::SBPlatform &platform);
204 
205  /// Get the number of currently active platforms.
206  uint32_t GetNumPlatforms();
207 
208  /// Get one of the currently active platforms.
209  lldb::SBPlatform GetPlatformAtIndex(uint32_t idx);
210 
211  /// Get the number of available platforms.
212  ///
213  /// The return value should match the number of entries output by the
214  /// "platform list" command.
215  uint32_t GetNumAvailablePlatforms();
216 
217  /// Get the name and description of one of the available platforms.
218  ///
219  /// \param[in] idx
220  /// Zero-based index of the platform for which info should be retrieved,
221  /// must be less than the value returned by GetNumAvailablePlatforms().
222  lldb::SBStructuredData GetAvailablePlatformInfoAtIndex(uint32_t idx);
223 
224  lldb::SBSourceManager GetSourceManager();
225 
226  // REMOVE: just for a quick fix, need to expose platforms through
227  // SBPlatform from this class.
228  lldb::SBError SetCurrentPlatform(const char *platform_name);
229 
230  bool SetCurrentPlatformSDKRoot(const char *sysroot);
231 
232  // FIXME: Once we get the set show stuff in place, the driver won't need
233  // an interface to the Set/Get UseExternalEditor.
234  bool SetUseExternalEditor(bool input);
235 
236  bool GetUseExternalEditor();
237 
238  bool SetUseColor(bool use_color);
239 
240  bool GetUseColor() const;
241 
242  bool SetUseSourceCache(bool use_source_cache);
243 
244  bool GetUseSourceCache() const;
245 
246  static bool GetDefaultArchitecture(char *arch_name, size_t arch_name_len);
247 
248  static bool SetDefaultArchitecture(const char *arch_name);
249 
250  lldb::ScriptLanguage GetScriptingLanguage(const char *script_language_name);
251 
252  SBStructuredData GetScriptInterpreterInfo(ScriptLanguage);
253 
254  static const char *GetVersionString();
255 
256  static const char *StateAsCString(lldb::StateType state);
257 
258  static SBStructuredData GetBuildConfiguration();
259 
260  static bool StateIsRunningState(lldb::StateType state);
261 
262  static bool StateIsStoppedState(lldb::StateType state);
263 
264  bool EnableLog(const char *channel, const char **categories);
265 
266  void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton);
267 
268  // DEPRECATED
269  void DispatchInput(void *baton, const void *data, size_t data_len);
270 
271  void DispatchInput(const void *data, size_t data_len);
272 
273  void DispatchInputInterrupt();
274 
275  void DispatchInputEndOfFile();
276 
277  void PushInputReader(lldb::SBInputReader &reader);
278 
279  const char *GetInstanceName();
280 
281  static SBDebugger FindDebuggerWithID(int id);
282 
283  static lldb::SBError SetInternalVariable(const char *var_name,
284  const char *value,
285  const char *debugger_instance_name);
286 
287  static lldb::SBStringList
288  GetInternalVariableValue(const char *var_name,
289  const char *debugger_instance_name);
290 
291  bool GetDescription(lldb::SBStream &description);
292 
293  uint32_t GetTerminalWidth() const;
294 
295  void SetTerminalWidth(uint32_t term_width);
296 
297  lldb::user_id_t GetID();
298 
299  const char *GetPrompt() const;
300 
301  void SetPrompt(const char *prompt);
302 
303  const char *GetReproducerPath() const;
304 
305  lldb::ScriptLanguage GetScriptLanguage() const;
306 
307  void SetScriptLanguage(lldb::ScriptLanguage script_lang);
308 
309  lldb::LanguageType GetREPLLanguage() const;
310 
311  void SetREPLLanguage(lldb::LanguageType repl_lang);
312 
313  bool GetCloseInputOnEOF() const;
314 
315  void SetCloseInputOnEOF(bool b);
316 
317  SBTypeCategory GetCategory(const char *category_name);
318 
319  SBTypeCategory GetCategory(lldb::LanguageType lang_type);
320 
321  SBTypeCategory CreateCategory(const char *category_name);
322 
323  bool DeleteCategory(const char *category_name);
324 
325  uint32_t GetNumCategories();
326 
327  SBTypeCategory GetCategoryAtIndex(uint32_t);
328 
329  SBTypeCategory GetDefaultCategory();
330 
331  SBTypeFormat GetFormatForType(SBTypeNameSpecifier);
332 
333  SBTypeSummary GetSummaryForType(SBTypeNameSpecifier);
334 
335  SBTypeFilter GetFilterForType(SBTypeNameSpecifier);
336 
337  SBTypeSynthetic GetSyntheticForType(SBTypeNameSpecifier);
338 
339  /// Run the command interpreter.
340  ///
341  /// \param[in] auto_handle_events
342  /// If true, automatically handle resulting events. This takes precedence
343  /// and overrides the corresponding option in
344  /// SBCommandInterpreterRunOptions.
345  ///
346  /// \param[in] spawn_thread
347  /// If true, start a new thread for IO handling. This takes precedence
348  /// and overrides the corresponding option in
349  /// SBCommandInterpreterRunOptions.
350  void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread);
351 
352  /// Run the command interpreter.
353  ///
354  /// \param[in] auto_handle_events
355  /// If true, automatically handle resulting events. This takes precedence
356  /// and overrides the corresponding option in
357  /// SBCommandInterpreterRunOptions.
358  ///
359  /// \param[in] spawn_thread
360  /// If true, start a new thread for IO handling. This takes precedence
361  /// and overrides the corresponding option in
362  /// SBCommandInterpreterRunOptions.
363  ///
364  /// \param[in] options
365  /// Parameter collection of type SBCommandInterpreterRunOptions.
366  ///
367  /// \param[out] num_errors
368  /// The number of errors.
369  ///
370  /// \param[out] quit_requested
371  /// Whether a quit was requested.
372  ///
373  /// \param[out] stopped_for_crash
374  /// Whether the interpreter stopped for a crash.
375  void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread,
377  int &num_errors, bool &quit_requested,
378  bool &stopped_for_crash);
379 
381  RunCommandInterpreter(const SBCommandInterpreterRunOptions &options);
382 
383  SBError RunREPL(lldb::LanguageType language, const char *repl_options);
384 
385 private:
386  friend class SBCommandInterpreter;
387  friend class SBInputReader;
388  friend class SBListener;
389  friend class SBProcess;
390  friend class SBSourceManager;
391  friend class SBTarget;
392 
393  lldb::SBTarget FindTargetWithLLDBProcess(const lldb::ProcessSP &processSP);
394 
395  void reset(const lldb::DebuggerSP &debugger_sp);
396 
397  lldb_private::Debugger *get() const;
398 
399  lldb_private::Debugger &ref() const;
400 
401  const lldb::DebuggerSP &get_sp() const;
402 
403  lldb::DebuggerSP m_opaque_sp;
404 
405 }; // class SBDebugger
406 
407 } // namespace lldb
408 
409 #endif // LLDB_API_SBDEBUGGER_H
lldb::SBStringList
Definition: SBStringList.h:16
lldb::SBCommandInterpreterRunResult
Definition: SBCommandInterpreterRunOptions.h:85
lldb::SBTypeNameSpecifier
Definition: SBTypeNameSpecifier.h:17
lldb::ScriptLanguage
ScriptLanguage
Script interpreter types.
Definition: lldb-enumerations.h:216
lldb::SBTypeFilter
Definition: SBTypeFilter.h:17
SBDefines.h
lldb::LogOutputCallback
void(* LogOutputCallback)(const char *, void *baton)
Definition: lldb-types.h:70
lldb::SBError
Definition: SBError.h:20
lldb::SBCommandInterpreter
Definition: SBCommandInterpreter.h:19
lldb::SBInputReader
Definition: SBDebugger.h:19
lldb::SBDebugger
class LLDB_API SBDebugger
Definition: SBDefines.h:49
lldb_private::StateAsCString
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition: State.cpp:14
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
lldb_private::StateIsRunningState
bool StateIsRunningState(lldb::StateType state)
Check if a state represents a state where the process or thread is running.
Definition: State.cpp:68
lldb::SBEvent
Definition: SBEvent.h:21
lldb::SBProcess
Definition: SBProcess.h:23
lldb::SBTypeSummary
Definition: SBTypeSummary.h:55
lldb::SBTarget
Definition: SBTarget.h:29
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb::SBFile
Definition: SBFile.h:16
lldb::SBDebugger::FLAGS_ANONYMOUS_ENUM
FLAGS_ANONYMOUS_ENUM()
Definition: SBDebugger.h:36
lldb::InputReaderAction
InputReaderAction
Definition: lldb-enumerations.h:385
lldb_private::StateIsStoppedState
bool StateIsStoppedState(lldb::StateType state, bool must_exist)
Check if a state represents a state where the process or thread is stopped.
Definition: State.cpp:89
lldb::SBDebugger
Definition: SBDebugger.h:34
lldb::SBTypeFormat
Definition: SBTypeFormat.h:17
lldb_private::Debugger
Definition: Debugger.h:70
lldb::SBListener
Definition: SBListener.h:16
uint32_t
lldb::SBStructuredData
Definition: SBStructuredData.h:17
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb::SBTypeSynthetic
Definition: SBTypeSynthetic.h:17
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
lldb::SBBroadcaster
Definition: SBBroadcaster.h:16
lldb::SBCommandInterpreterRunOptions
Definition: SBCommandInterpreterRunOptions.h:23
lldb::InputReaderGranularity
InputReaderGranularity
Token size/granularities for Input Readers.
Definition: lldb-enumerations.h:329
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
lldb::SBDebugger::m_opaque_sp
lldb::DebuggerSP m_opaque_sp
Definition: SBDebugger.h:403
lldb::SBStream
Definition: SBStream.h:18
lldb::SBPlatform
Definition: SBPlatform.h:93
lldb::SBTypeCategory
Definition: SBTypeCategory.h:17
lldb
Definition: SBAddress.h:15
SBPlatform.h
LLDB_API
#define LLDB_API
Definition: SBDefines.h:26
lldb::SBSourceManager
Definition: SBSourceManager.h:18