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
17namespace lldb_private {
18class CommandPluginInterfaceImplementation;
19namespace python {
20class SWIGBridge;
21}
22} // namespace lldb_private
23
24namespace lldb {
25
26#ifndef SWIG
28public:
29 SBInputReader() = default;
30 ~SBInputReader() = default;
31
32 SBError Initialize(lldb::SBDebugger &sb_debugger,
33 unsigned long (*callback)(void *, lldb::SBInputReader *,
35 char const *, unsigned long),
36 void *a, lldb::InputReaderGranularity b, char const *c,
37 char const *d, bool e);
38 void SetIsDone(bool);
39 bool IsActive() const;
40};
41#endif
42
44public:
51 };
52 SBDebugger();
53
54 SBDebugger(const lldb::SBDebugger &rhs);
55
57
58 static const char *GetBroadcasterClass();
59
60 static bool SupportsLanguage(lldb::LanguageType language);
61
62 lldb::SBBroadcaster GetBroadcaster();
63
64 /// Get progress data from a SBEvent whose type is eBroadcastBitProgress.
65 ///
66 /// \param [in] event
67 /// The event to extract the progress information from.
68 ///
69 /// \param [out] progress_id
70 /// The unique integer identifier for the progress to report.
71 ///
72 /// \param [out] completed
73 /// The amount of work completed. If \a completed is zero, then this event
74 /// is a progress started event. If \a completed is equal to \a total, then
75 /// this event is a progress end event. Otherwise completed indicates the
76 /// current progress update.
77 ///
78 /// \param [out] total
79 /// The total amount of work units that need to be completed. If this value
80 /// is UINT64_MAX, then an indeterminate progress indicator should be
81 /// displayed.
82 ///
83 /// \param [out] is_debugger_specific
84 /// Set to true if this progress is specific to this debugger only. Many
85 /// progress events are not specific to a debugger instance, like any
86 /// progress events for loading information in modules since LLDB has a
87 /// global module cache that all debuggers use.
88 ///
89 /// \return The message for the progress. If the returned value is NULL, then
90 /// \a event was not a eBroadcastBitProgress event.
91#ifdef SWIG
92 static const char *GetProgressFromEvent(const lldb::SBEvent &event,
93 uint64_t &OUTPUT,
94 uint64_t &OUTPUT, uint64_t &OUTPUT,
95 bool &OUTPUT);
96#else
97 static const char *GetProgressFromEvent(const lldb::SBEvent &event,
98 uint64_t &progress_id,
99 uint64_t &completed, uint64_t &total,
100 bool &is_debugger_specific);
101#endif
102
104 GetProgressDataFromEvent(const lldb::SBEvent &event);
105
107 GetDiagnosticFromEvent(const lldb::SBEvent &event);
108
109 lldb::SBDebugger &operator=(const lldb::SBDebugger &rhs);
110
111 static void Initialize();
112
113 static lldb::SBError InitializeWithErrorHandling();
114
115 static void PrintStackTraceOnError();
116
117 static void PrintDiagnosticsOnError();
118
119 static void Terminate();
120
121 LLDB_DEPRECATED_FIXME("Use one of the other Create variants", "Create(bool)")
122 static lldb::SBDebugger Create();
123
124 static lldb::SBDebugger Create(bool source_init_files);
125
126 static lldb::SBDebugger Create(bool source_init_files,
127 lldb::LogOutputCallback log_callback,
128 void *baton);
129
130 static void Destroy(lldb::SBDebugger &debugger);
131
132 static void MemoryPressureDetected();
133
134 explicit operator bool() const;
135
136 bool IsValid() const;
137
138 void Clear();
139
140 /// Getting a specific setting value into SBStructuredData format.
141 /// Client can specify empty string or null to get all settings.
142 ///
143 /// Example usages:
144 /// lldb::SBStructuredData settings = debugger.GetSetting();
145 /// lldb::SBStructuredData settings = debugger.GetSetting(nullptr);
146 /// lldb::SBStructuredData settings = debugger.GetSetting("");
147 /// lldb::SBStructuredData settings = debugger.GetSetting("target.arg0");
148 /// lldb::SBStructuredData settings = debugger.GetSetting("target");
149 ///
150 /// \param[out] setting
151 /// Property setting path to retrieve values. e.g "target.source-map"
152 ///
153 lldb::SBStructuredData GetSetting(const char *setting = nullptr);
154
155 void SetAsync(bool b);
156
157 bool GetAsync();
158
159 void SkipLLDBInitFiles(bool b);
160
161 void SkipAppInitFiles(bool b);
162
163#ifndef SWIG
164 void SetInputFileHandle(FILE *f, bool transfer_ownership);
165
166 void SetOutputFileHandle(FILE *f, bool transfer_ownership);
167
168 void SetErrorFileHandle(FILE *f, bool transfer_ownership);
169#endif
170
171#ifndef SWIG
172 FILE *GetInputFileHandle();
173
174 FILE *GetOutputFileHandle();
175
176 FILE *GetErrorFileHandle();
177#endif
178
179 SBError SetInputString(const char *data);
180
181 SBError SetInputFile(SBFile file);
182
183 SBError SetOutputFile(SBFile file);
184
185 SBError SetErrorFile(SBFile file);
186
187 SBError SetInputFile(FileSP file);
188
189 SBError SetOutputFile(FileSP file);
190
191 SBError SetErrorFile(FileSP file);
192
193 SBFile GetInputFile();
194
195 SBFile GetOutputFile();
196
197 SBFile GetErrorFile();
198
199 void SaveInputTerminalState();
200
201 void RestoreInputTerminalState();
202
203 lldb::SBCommandInterpreter GetCommandInterpreter();
204
205 void HandleCommand(const char *command);
206
207 void RequestInterrupt();
208 void CancelInterruptRequest();
209 bool InterruptRequested();
210
211 lldb::SBListener GetListener();
212
213#ifndef SWIG
215 "Use HandleProcessEvent(const SBProcess &, const SBEvent &, SBFile, "
216 "SBFile) or HandleProcessEvent(const SBProcess &, const SBEvent &, "
217 "FileSP, FileSP)",
218 "HandleProcessEvent(const SBProcess &, const SBEvent &, SBFile, SBFile)")
219 void HandleProcessEvent(const lldb::SBProcess &process,
220 const lldb::SBEvent &event, FILE *out, FILE *err);
221#endif
222
224 const lldb::SBEvent &event, SBFile out, SBFile err);
225
226#ifdef SWIG
227 void HandleProcessEvent(const lldb::SBProcess &process,
228 const lldb::SBEvent &event, FileSP BORROWED, FileSP BORROWED);
229#else
231 const lldb::SBEvent &event, FileSP out, FileSP err);
232#endif
233
234 lldb::SBTarget CreateTarget(const char *filename, const char *target_triple,
235 const char *platform_name,
236 bool add_dependent_modules, lldb::SBError &error);
237
238 lldb::SBTarget CreateTargetWithFileAndTargetTriple(const char *filename,
239 const char *target_triple);
240
241 lldb::SBTarget CreateTargetWithFileAndArch(const char *filename,
242 const char *archname);
243
244 lldb::SBTarget CreateTarget(const char *filename);
245
246 lldb::SBTarget GetDummyTarget();
247
248 // Return true if target is deleted from the target list of the debugger.
249 bool DeleteTarget(lldb::SBTarget &target);
250
251 lldb::SBTarget GetTargetAtIndex(uint32_t idx);
252
253 uint32_t GetIndexOfTarget(lldb::SBTarget target);
254
255 lldb::SBTarget FindTargetWithProcessID(lldb::pid_t pid);
256
257 lldb::SBTarget FindTargetWithFileAndArch(const char *filename,
258 const char *arch);
259
260 uint32_t GetNumTargets();
261
262 lldb::SBTarget GetSelectedTarget();
263
264 void SetSelectedTarget(SBTarget &target);
265
266 lldb::SBPlatform GetSelectedPlatform();
267
268 void SetSelectedPlatform(lldb::SBPlatform &platform);
269
270 /// Get the number of currently active platforms.
271 uint32_t GetNumPlatforms();
272
273 /// Get one of the currently active platforms.
274 lldb::SBPlatform GetPlatformAtIndex(uint32_t idx);
275
276 /// Get the number of available platforms.
277 ///
278 /// The return value should match the number of entries output by the
279 /// "platform list" command.
280 uint32_t GetNumAvailablePlatforms();
281
282 /// Get the name and description of one of the available platforms.
283 ///
284 /// \param[in] idx
285 /// Zero-based index of the platform for which info should be retrieved,
286 /// must be less than the value returned by GetNumAvailablePlatforms().
287 lldb::SBStructuredData GetAvailablePlatformInfoAtIndex(uint32_t idx);
288
289 lldb::SBSourceManager GetSourceManager();
290
291 // REMOVE: just for a quick fix, need to expose platforms through
292 // SBPlatform from this class.
293 lldb::SBError SetCurrentPlatform(const char *platform_name);
294
295 bool SetCurrentPlatformSDKRoot(const char *sysroot);
296
297 // FIXME: Once we get the set show stuff in place, the driver won't need
298 // an interface to the Set/Get UseExternalEditor.
299 bool SetUseExternalEditor(bool input);
300
301 bool GetUseExternalEditor();
302
303 bool SetUseColor(bool use_color);
304
305 bool GetUseColor() const;
306
307 bool SetShowInlineDiagnostics(bool);
308
309 bool SetUseSourceCache(bool use_source_cache);
310
311 bool GetUseSourceCache() const;
312
313 static bool GetDefaultArchitecture(char *arch_name, size_t arch_name_len);
314
315 static bool SetDefaultArchitecture(const char *arch_name);
316
317 lldb::ScriptLanguage GetScriptingLanguage(const char *script_language_name);
318
319 SBStructuredData GetScriptInterpreterInfo(ScriptLanguage);
320
321 static const char *GetVersionString();
322
323 static const char *StateAsCString(lldb::StateType state);
324
325 static SBStructuredData GetBuildConfiguration();
326
327 static bool StateIsRunningState(lldb::StateType state);
328
329 static bool StateIsStoppedState(lldb::StateType state);
330
331 bool EnableLog(const char *channel, const char **categories);
332
333 void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton);
334
335 /// Clear all previously added callbacks and only add the given one.
336 LLDB_DEPRECATED_FIXME("Use AddDestroyCallback and RemoveDestroyCallback",
337 "AddDestroyCallback")
338 void SetDestroyCallback(lldb::SBDebuggerDestroyCallback destroy_callback,
339 void *baton);
340
341 /// Add a callback for when the debugger is destroyed. Return a token, which
342 /// can be used to remove said callback. Multiple callbacks can be added by
343 /// calling this function multiple times, and will be invoked in FIFO order.
345 AddDestroyCallback(lldb::SBDebuggerDestroyCallback destroy_callback,
346 void *baton);
347
348 /// Remove the specified callback. Return true if successful.
349 bool RemoveDestroyCallback(lldb::callback_token_t token);
350
351#ifndef SWIG
352 LLDB_DEPRECATED_FIXME("Use DispatchInput(const void *, size_t)",
353 "DispatchInput(const void *, size_t)")
354 void DispatchInput(void *baton, const void *data, size_t data_len);
355#endif
356
357 void DispatchInput(const void *data, size_t data_len);
358
359 void DispatchInputInterrupt();
360
361 void DispatchInputEndOfFile();
362
363#ifndef SWIG
364 void PushInputReader(lldb::SBInputReader &reader);
365#endif
366
367 const char *GetInstanceName();
368
369 static SBDebugger FindDebuggerWithID(int id);
370
371 static lldb::SBError SetInternalVariable(const char *var_name,
372 const char *value,
373 const char *debugger_instance_name);
374
375 static lldb::SBStringList
376 GetInternalVariableValue(const char *var_name,
377 const char *debugger_instance_name);
378
379 bool GetDescription(lldb::SBStream &description);
380
381 uint32_t GetTerminalWidth() const;
382
383 void SetTerminalWidth(uint32_t term_width);
384
385 uint32_t GetTerminalHeight() const;
386
387 void SetTerminalHeight(uint32_t term_height);
388
389 lldb::user_id_t GetID();
390
391 const char *GetPrompt() const;
392
393 void SetPrompt(const char *prompt);
394
395 const char *GetReproducerPath() const;
396
397 lldb::ScriptLanguage GetScriptLanguage() const;
398
399 void SetScriptLanguage(lldb::ScriptLanguage script_lang);
400
401 lldb::LanguageType GetREPLLanguage() const;
402
403 void SetREPLLanguage(lldb::LanguageType repl_lang);
404
405 LLDB_DEPRECATED("SBDebugger::GetCloseInputOnEOF() is deprecated.")
406 bool GetCloseInputOnEOF() const;
407
408 LLDB_DEPRECATED("SBDebugger::SetCloseInputOnEOF() is deprecated.")
409 void SetCloseInputOnEOF(bool b);
410
411 SBTypeCategory GetCategory(const char *category_name);
412
413 SBTypeCategory GetCategory(lldb::LanguageType lang_type);
414
415 SBTypeCategory CreateCategory(const char *category_name);
416
417 bool DeleteCategory(const char *category_name);
418
419 uint32_t GetNumCategories();
420
421 SBTypeCategory GetCategoryAtIndex(uint32_t);
422
423 SBTypeCategory GetDefaultCategory();
424
425 SBTypeFormat GetFormatForType(SBTypeNameSpecifier);
426
427 SBTypeSummary GetSummaryForType(SBTypeNameSpecifier);
428
429 SBTypeFilter GetFilterForType(SBTypeNameSpecifier);
430
431 SBTypeSynthetic GetSyntheticForType(SBTypeNameSpecifier);
432
433 /// Clear collected statistics for targets belonging to this debugger. This
434 /// includes clearing symbol table and debug info parsing/index time for all
435 /// modules, breakpoint resolve time and target statistics.
436 void ResetStatistics();
437
438#ifndef SWIG
439 /// Run the command interpreter.
440 ///
441 /// \param[in] auto_handle_events
442 /// If true, automatically handle resulting events. This takes precedence
443 /// and overrides the corresponding option in
444 /// SBCommandInterpreterRunOptions.
445 ///
446 /// \param[in] spawn_thread
447 /// If true, start a new thread for IO handling. This takes precedence
448 /// and overrides the corresponding option in
449 /// SBCommandInterpreterRunOptions.
450 void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread);
451#endif
452
453 /// Run the command interpreter.
454 ///
455 /// \param[in] auto_handle_events
456 /// If true, automatically handle resulting events. This takes precedence
457 /// and overrides the corresponding option in
458 /// SBCommandInterpreterRunOptions.
459 ///
460 /// \param[in] spawn_thread
461 /// If true, start a new thread for IO handling. This takes precedence
462 /// and overrides the corresponding option in
463 /// SBCommandInterpreterRunOptions.
464 ///
465 /// \param[in] options
466 /// Parameter collection of type SBCommandInterpreterRunOptions.
467 ///
468 /// \param[out] num_errors
469 /// The number of errors.
470 ///
471 /// \param[out] quit_requested
472 /// Whether a quit was requested.
473 ///
474 /// \param[out] stopped_for_crash
475 /// Whether the interpreter stopped for a crash.
476#ifdef SWIG
477 %apply int& INOUT { int& num_errors };
478 %apply bool& INOUT { bool& quit_requested };
479 %apply bool& INOUT { bool& stopped_for_crash };
480#endif
481 void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread,
482 SBCommandInterpreterRunOptions &options,
483 int &num_errors, bool &quit_requested,
484 bool &stopped_for_crash);
485
486#ifndef SWIG
488 RunCommandInterpreter(const SBCommandInterpreterRunOptions &options);
489#endif
490
491 SBError RunREPL(lldb::LanguageType language, const char *repl_options);
492
493 /// Load a trace from a trace description file and create Targets,
494 /// Processes and Threads based on the contents of such file.
495 ///
496 /// \param[out] error
497 /// An error if the trace could not be created.
498 ///
499 /// \param[in] trace_description_file
500 /// The file containing the necessary information to load the trace.
501 SBTrace LoadTraceFromFile(SBError &error,
502 const SBFileSpec &trace_description_file);
503
504protected:
506 friend class lldb_private::python::SWIGBridge;
507
508 SBDebugger(const lldb::DebuggerSP &debugger_sp);
509
510private:
512 friend class SBInputReader;
513 friend class SBListener;
514 friend class SBProcess;
515 friend class SBSourceManager;
516 friend class SBStructuredData;
517 friend class SBPlatform;
518 friend class SBTarget;
519 friend class SBTrace;
520
521 lldb::SBTarget FindTargetWithLLDBProcess(const lldb::ProcessSP &processSP);
522
523 void reset(const lldb::DebuggerSP &debugger_sp);
524
525 lldb_private::Debugger *get() const;
526
527 lldb_private::Debugger &ref() const;
528
529 const lldb::DebuggerSP &get_sp() const;
530
532
533}; // class SBDebugger
534
535} // namespace lldb
536
537#endif // LLDB_API_SBDEBUGGER_H
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_API
Definition: SBDefines.h:28
#define LLDB_DEPRECATED_FIXME(MSG, FIX)
Definition: SBDefines.h:39
#define LLDB_DEPRECATED(MSG)
Definition: SBDefines.h:38
Set the output file path.
LLDB_DEPRECATED_FIXME("Use DispatchInput(const void *, size_t)", "DispatchInput(const void *, size_t)") void DispatchInput(void *baton
lldb::DebuggerSP m_opaque_sp
Definition: SBDebugger.h:531
void HandleProcessEvent(const lldb::SBProcess &process, const lldb::SBEvent &event, FileSP out, FileSP err)
LLDB_DEPRECATED_FIXME("Use HandleProcessEvent(const SBProcess &, const SBEvent &, SBFile, " "SBFile) or HandleProcessEvent(const SBProcess &, const SBEvent &, " "FileSP, FileSP)", "HandleProcessEvent(const SBProcess &, const SBEvent &, SBFile, SBFile)") void HandleProcessEvent(const lldb void HandleProcessEvent(const lldb::SBProcess &process, const lldb::SBEvent &event, SBFile out, SBFile err)
Definition: SBDebugger.h:223
~SBInputReader()=default
SBInputReader()=default
A class to manage flag bits.
Definition: Debugger.h:80
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
ScriptLanguage
Script interpreter types.
@ eBroadcastBitProgressCategory
@ eBroadcastBitProgress
@ eBroadcastBitError
@ eBroadcastBitWarning
StateType
Process and Thread States.
LanguageType
Programming language type.
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:389
std::shared_ptr< lldb_private::Debugger > DebuggerSP
Definition: lldb-forward.h:339
uint64_t pid_t
Definition: lldb-types.h:83
int32_t callback_token_t
Definition: lldb-types.h:81
class LLDB_API SBTrace
Definition: SBDefines.h:116
uint64_t user_id_t
Definition: lldb-types.h:82
void(* LogOutputCallback)(const char *, void *baton)
Definition: lldb-types.h:73
class LLDB_API SBError
Definition: SBDefines.h:69
std::shared_ptr< lldb_private::File > FileSP
Definition: lldb-forward.h:353
class LLDB_API SBCommandInterpreterRunResult
Definition: SBDefines.h:59
InputReaderGranularity
Token size/granularities for Input Readers.