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