62 #include "llvm/ADT/STLExtras.h"
63 #include "llvm/ADT/StringRef.h"
64 #include "llvm/ADT/iterator.h"
65 #include "llvm/Support/DynamicLibrary.h"
66 #include "llvm/Support/FileSystem.h"
67 #include "llvm/Support/Process.h"
68 #include "llvm/Support/ThreadPool.h"
69 #include "llvm/Support/Threading.h"
70 #include "llvm/Support/raw_ostream.h"
81 #include <system_error>
101 #pragma mark Static Functions
112 Debugger::eStopDisassemblyTypeNever,
114 "Never show disassembly when displaying a stop context.",
117 Debugger::eStopDisassemblyTypeNoDebugInfo,
119 "Show disassembly when there is no debug information.",
122 Debugger::eStopDisassemblyTypeNoSource,
124 "Show disassembly when there is no source information, or the source "
126 "is missing when displaying a stop context.",
129 Debugger::eStopDisassemblyTypeAlways,
131 "Always show disassembly when displaying a stop context.",
139 "Disable scripting languages.",
144 "Select python as the default scripting language.",
149 "Select the lldb default as the default scripting language.",
155 "Use no verbosity when running dwim-print."},
157 "Use partial verbosity when running dwim-print - display a message when "
158 "`expression` evaluation is used."},
160 "Use full verbosity when running dwim-print."},
167 "Highlight the stop column with ANSI terminal codes when color/ANSI "
168 "mode is enabled; otherwise, fall back to using a text-only caret (^) "
169 "as if \"caret-only\" mode was selected.",
174 "Highlight the stop column with ANSI terminal codes when running LLDB "
175 "with color/ANSI enabled.",
180 "Highlight the stop column with a caret character (^) underneath the "
181 "stop column. This method introduces a new line in source listings "
182 "that display thread stop locations.",
187 "Do not highlight the stop column.",
191 #define LLDB_PROPERTIES_debugger
192 #include "CoreProperties.inc"
195 #define LLDB_PROPERTIES_debugger
196 #include "CorePropertiesEnum.inc"
199 LoadPluginCallbackType Debugger::g_load_plugin_callback =
nullptr;
203 llvm::StringRef property_path,
204 llvm::StringRef value) {
205 bool is_load_script =
206 (property_path ==
"target.load-script-from-symbol-file");
208 bool invalidate_data_vis = (property_path ==
"escape-non-printables");
209 invalidate_data_vis |=
210 (property_path ==
"target.max-zero-padding-in-float-format");
211 if (invalidate_data_vis) {
212 DataVisualization::ForceUpdate();
219 load_script_old_value =
220 target_sp->TargetProperties::GetLoadScriptFromSymbolFile();
222 Status error(Properties::SetPropertyValue(exe_ctx, op, property_path, value));
223 if (
error.Success()) {
225 if (property_path == g_debugger_properties[ePropertyPrompt].name) {
226 llvm::StringRef new_prompt = GetPrompt();
228 new_prompt, GetUseColor());
231 GetCommandInterpreter().UpdatePrompt(new_prompt);
232 auto bytes = std::make_unique<EventDataBytes>(new_prompt);
233 auto prompt_change_event_sp = std::make_shared<Event>(
234 CommandInterpreter::eBroadcastBitResetPrompt, bytes.release());
235 GetCommandInterpreter().BroadcastEvent(prompt_change_event_sp);
236 }
else if (property_path == g_debugger_properties[ePropertyUseColor].name) {
239 SetPrompt(GetPrompt());
240 }
else if (property_path == g_debugger_properties[ePropertyUseSourceCache].name) {
242 if (!GetUseSourceCache()) {
243 m_source_file_cache.Clear();
245 }
else if (is_load_script && target_sp &&
247 if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() ==
249 std::list<Status> errors;
251 if (!target_sp->LoadScriptingResources(errors, &feedback_stream)) {
252 Stream &s = GetErrorStream();
253 for (
auto error : errors) {
265 bool Debugger::GetAutoConfirm()
const {
266 const uint32_t idx = ePropertyAutoConfirm;
267 return m_collection_sp->GetPropertyAtIndexAsBoolean(
268 nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
272 const uint32_t idx = ePropertyDisassemblyFormat;
273 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(
nullptr, idx);
277 const uint32_t idx = ePropertyFrameFormat;
278 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(
nullptr, idx);
282 const uint32_t idx = ePropertyFrameFormatUnique;
283 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(
nullptr, idx);
286 uint32_t Debugger::GetStopDisassemblyMaxSize()
const {
287 const uint32_t idx = ePropertyStopDisassemblyMaxSize;
288 return m_collection_sp->GetPropertyAtIndexAsUInt64(
289 nullptr, idx, g_debugger_properties[idx].default_uint_value);
292 bool Debugger::GetNotifyVoid()
const {
293 const uint32_t idx = ePropertyNotiftVoid;
294 return m_collection_sp->GetPropertyAtIndexAsBoolean(
295 nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
298 llvm::StringRef Debugger::GetPrompt()
const {
299 const uint32_t idx = ePropertyPrompt;
300 return m_collection_sp->GetPropertyAtIndexAsString(
301 nullptr, idx, g_debugger_properties[idx].default_cstr_value);
304 void Debugger::SetPrompt(llvm::StringRef p) {
305 const uint32_t idx = ePropertyPrompt;
306 m_collection_sp->SetPropertyAtIndexAsString(
nullptr, idx, p);
307 llvm::StringRef new_prompt = GetPrompt();
312 GetCommandInterpreter().UpdatePrompt(new_prompt);
316 const uint32_t idx = ePropertyThreadFormat;
317 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(
nullptr, idx);
321 const uint32_t idx = ePropertyThreadStopFormat;
322 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(
nullptr, idx);
326 const uint32_t idx = ePropertyScriptLanguage;
328 nullptr, idx, g_debugger_properties[idx].default_uint_value);
332 const uint32_t idx = ePropertyScriptLanguage;
333 return m_collection_sp->SetPropertyAtIndexAsEnumeration(
nullptr, idx,
338 const uint32_t idx = ePropertyREPLLanguage;
340 m_collection_sp->GetPropertyAtIndexAsOptionValueLanguage(
nullptr, idx);
347 const uint32_t idx = ePropertyREPLLanguage;
348 return m_collection_sp->SetPropertyAtIndexAsLanguage(
nullptr, idx, repl_lang);
352 const uint32_t idx = ePropertyTerminalWidth;
353 return m_collection_sp->GetPropertyAtIndexAsSInt64(
354 nullptr, idx, g_debugger_properties[idx].default_uint_value);
357 bool Debugger::SetTerminalWidth(
uint32_t term_width) {
358 if (
auto handler_sp = m_io_handler_stack.Top())
359 handler_sp->TerminalSizeChanged();
361 const uint32_t idx = ePropertyTerminalWidth;
362 return m_collection_sp->SetPropertyAtIndexAsSInt64(
nullptr, idx, term_width);
365 bool Debugger::GetUseExternalEditor()
const {
366 const uint32_t idx = ePropertyUseExternalEditor;
367 return m_collection_sp->GetPropertyAtIndexAsBoolean(
368 nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
371 bool Debugger::SetUseExternalEditor(
bool b) {
372 const uint32_t idx = ePropertyUseExternalEditor;
373 return m_collection_sp->SetPropertyAtIndexAsBoolean(
nullptr, idx, b);
376 bool Debugger::GetUseColor()
const {
377 const uint32_t idx = ePropertyUseColor;
378 return m_collection_sp->GetPropertyAtIndexAsBoolean(
379 nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
382 bool Debugger::SetUseColor(
bool b) {
383 const uint32_t idx = ePropertyUseColor;
384 bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean(
nullptr, idx, b);
385 SetPrompt(GetPrompt());
389 bool Debugger::GetShowProgress()
const {
390 const uint32_t idx = ePropertyShowProgress;
391 return m_collection_sp->GetPropertyAtIndexAsBoolean(
392 nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
395 bool Debugger::SetShowProgress(
bool show_progress) {
396 const uint32_t idx = ePropertyShowProgress;
397 return m_collection_sp->SetPropertyAtIndexAsBoolean(
nullptr, idx,
401 llvm::StringRef Debugger::GetShowProgressAnsiPrefix()
const {
402 const uint32_t idx = ePropertyShowProgressAnsiPrefix;
403 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
406 llvm::StringRef Debugger::GetShowProgressAnsiSuffix()
const {
407 const uint32_t idx = ePropertyShowProgressAnsiSuffix;
408 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
411 bool Debugger::GetUseAutosuggestion()
const {
412 const uint32_t idx = ePropertyShowAutosuggestion;
413 return m_collection_sp->GetPropertyAtIndexAsBoolean(
414 nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
417 llvm::StringRef Debugger::GetAutosuggestionAnsiPrefix()
const {
418 const uint32_t idx = ePropertyShowAutosuggestionAnsiPrefix;
419 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
422 llvm::StringRef Debugger::GetAutosuggestionAnsiSuffix()
const {
423 const uint32_t idx = ePropertyShowAutosuggestionAnsiSuffix;
424 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
427 bool Debugger::GetUseSourceCache()
const {
428 const uint32_t idx = ePropertyUseSourceCache;
429 return m_collection_sp->GetPropertyAtIndexAsBoolean(
430 nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
433 bool Debugger::SetUseSourceCache(
bool b) {
434 const uint32_t idx = ePropertyUseSourceCache;
435 bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean(
nullptr, idx, b);
437 m_source_file_cache.Clear();
441 bool Debugger::GetHighlightSource()
const {
442 const uint32_t idx = ePropertyHighlightSource;
443 return m_collection_sp->GetPropertyAtIndexAsBoolean(
444 nullptr, idx, g_debugger_properties[idx].default_uint_value);
448 const uint32_t idx = ePropertyStopShowColumn;
450 nullptr, idx, g_debugger_properties[idx].default_uint_value);
453 llvm::StringRef Debugger::GetStopShowColumnAnsiPrefix()
const {
454 const uint32_t idx = ePropertyStopShowColumnAnsiPrefix;
455 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
458 llvm::StringRef Debugger::GetStopShowColumnAnsiSuffix()
const {
459 const uint32_t idx = ePropertyStopShowColumnAnsiSuffix;
460 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
463 llvm::StringRef Debugger::GetStopShowLineMarkerAnsiPrefix()
const {
464 const uint32_t idx = ePropertyStopShowLineMarkerAnsiPrefix;
465 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
468 llvm::StringRef Debugger::GetStopShowLineMarkerAnsiSuffix()
const {
469 const uint32_t idx = ePropertyStopShowLineMarkerAnsiSuffix;
470 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
473 uint32_t Debugger::GetStopSourceLineCount(
bool before)
const {
475 before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter;
476 return m_collection_sp->GetPropertyAtIndexAsSInt64(
477 nullptr, idx, g_debugger_properties[idx].default_uint_value);
481 const uint32_t idx = ePropertyStopDisassemblyDisplay;
483 m_collection_sp->GetPropertyAtIndexAsEnumeration(
484 nullptr, idx, g_debugger_properties[idx].default_uint_value);
487 uint32_t Debugger::GetDisassemblyLineCount()
const {
488 const uint32_t idx = ePropertyStopDisassemblyCount;
489 return m_collection_sp->GetPropertyAtIndexAsSInt64(
490 nullptr, idx, g_debugger_properties[idx].default_uint_value);
493 bool Debugger::GetAutoOneLineSummaries()
const {
494 const uint32_t idx = ePropertyAutoOneLineSummaries;
495 return m_collection_sp->GetPropertyAtIndexAsBoolean(
nullptr, idx,
true);
498 bool Debugger::GetEscapeNonPrintables()
const {
499 const uint32_t idx = ePropertyEscapeNonPrintables;
500 return m_collection_sp->GetPropertyAtIndexAsBoolean(
nullptr, idx,
true);
503 bool Debugger::GetAutoIndent()
const {
504 const uint32_t idx = ePropertyAutoIndent;
505 return m_collection_sp->GetPropertyAtIndexAsBoolean(
nullptr, idx,
true);
508 bool Debugger::SetAutoIndent(
bool b) {
509 const uint32_t idx = ePropertyAutoIndent;
510 return m_collection_sp->SetPropertyAtIndexAsBoolean(
nullptr, idx, b);
513 bool Debugger::GetPrintDecls()
const {
514 const uint32_t idx = ePropertyPrintDecls;
515 return m_collection_sp->GetPropertyAtIndexAsBoolean(
nullptr, idx,
true);
518 bool Debugger::SetPrintDecls(
bool b) {
519 const uint32_t idx = ePropertyPrintDecls;
520 return m_collection_sp->SetPropertyAtIndexAsBoolean(
nullptr, idx, b);
524 const uint32_t idx = ePropertyTabSize;
525 return m_collection_sp->GetPropertyAtIndexAsUInt64(
526 nullptr, idx, g_debugger_properties[idx].default_uint_value);
530 const uint32_t idx = ePropertyTabSize;
531 return m_collection_sp->SetPropertyAtIndexAsUInt64(
nullptr, idx, tab_size);
535 const uint32_t idx = ePropertyDWIMPrintVerbosity;
537 m_collection_sp->GetPropertyAtIndexAsEnumeration(
538 nullptr, idx, g_debugger_properties[idx].default_uint_value);
541 #pragma mark Debugger
550 void Debugger::Initialize(LoadPluginCallbackType load_plugin_callback) {
552 "Debugger::Initialize called more than once!");
555 g_thread_pool =
new llvm::ThreadPool(llvm::optimal_concurrency());
556 g_load_plugin_callback = load_plugin_callback;
559 void Debugger::Terminate() {
561 "Debugger::Terminate called without a matching Debugger::Initialize!");
579 void Debugger::SettingsInitialize() { Target::SettingsInitialize(); }
581 void Debugger::SettingsTerminate() { Target::SettingsTerminate(); }
584 if (g_load_plugin_callback) {
585 llvm::sys::DynamicLibrary dynlib =
586 g_load_plugin_callback(shared_from_this(), spec,
error);
587 if (dynlib.isValid()) {
588 m_loaded_plugins.push_back(dynlib);
595 error.SetErrorString(
"Public API layer is not available");
602 llvm::StringRef path) {
609 return FileSystem::eEnumerateDirectoryResultQuit;
613 namespace fs = llvm::sys::fs;
618 if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file ||
619 ft == fs::file_type::type_unknown) {
621 FileSystem::Instance().Resolve(plugin_file_spec);
625 return FileSystem::eEnumerateDirectoryResultNext;
629 debugger->
LoadPlugin(plugin_file_spec, plugin_load_error);
631 return FileSystem::eEnumerateDirectoryResultNext;
632 }
else if (ft == fs::file_type::directory_file ||
633 ft == fs::file_type::symlink_file ||
634 ft == fs::file_type::type_unknown) {
639 return FileSystem::eEnumerateDirectoryResultEnter;
642 return FileSystem::eEnumerateDirectoryResultNext;
645 void Debugger::InstanceInitialize() {
646 const bool find_directories =
true;
647 const bool find_files =
true;
648 const bool find_other =
true;
650 if (
FileSpec dir_spec = HostInfo::GetSystemPluginDir()) {
651 if (FileSystem::Instance().Exists(dir_spec) &&
652 dir_spec.GetPath(dir_path,
sizeof(dir_path))) {
653 FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
654 find_files, find_other,
659 if (
FileSpec dir_spec = HostInfo::GetUserPluginDir()) {
660 if (FileSystem::Instance().Exists(dir_spec) &&
661 dir_spec.GetPath(dir_path,
sizeof(dir_path))) {
662 FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
663 find_files, find_other,
668 PluginManager::DebuggerInitialize(*
this);
673 DebuggerSP debugger_sp(
new Debugger(log_callback, baton));
678 debugger_sp->InstanceInitialize();
682 void Debugger::Destroy(DebuggerSP &debugger_sp) {
692 (*debugger_sp->GetAsyncOutputStream()) << result.
GetOutputData() <<
'\n';
694 (*debugger_sp->GetAsyncErrorStream()) << result.
GetErrorData() <<
'\n';
697 debugger_sp->Clear();
703 if ((*pos).get() == debugger_sp.get()) {
711 DebuggerSP Debugger::FindDebuggerWithInstanceName(
ConstString instance_name) {
712 DebuggerSP debugger_sp;
717 if ((*pos)->m_instance_name == instance_name) {
732 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID(pid);
740 TargetSP Debugger::FindTargetWithProcess(
Process *process) {
746 target_sp = (*pos)->GetTargetList().FindTargetWithProcess(process);
762 m_input_file_sp(std::make_shared<
NativeFile>(stdin, false)),
763 m_output_stream_sp(std::make_shared<
StreamFile>(stdout, false)),
764 m_error_stream_sp(std::make_shared<
StreamFile>(stderr, false)),
765 m_input_recorder(nullptr),
767 m_terminal_state(), m_target_list(*this), m_platform_list(),
768 m_listener_sp(
Listener::MakeListener(
"lldb.Debugger")),
769 m_source_manager_up(), m_source_file_cache(),
770 m_command_interpreter_up(
772 m_io_handler_stack(), m_instance_name(), m_loaded_plugins(),
773 m_event_handler_thread(), m_io_handler_thread(),
774 m_sync_broadcaster(nullptr,
"lldb.debugger.sync"),
775 m_broadcaster(m_broadcaster_manager_sp,
776 GetStaticBroadcasterClass().AsCString()),
777 m_forward_listener_sp(), m_clear_once() {
781 std::make_shared<CallbackLogHandler>(log_callback, baton);
785 assert(default_platform_sp);
792 arch = HostInfo::GetArchitecture();
793 assert(arch.
IsValid() &&
"No valid default or host archspec");
794 const bool is_dummy_target =
true;
796 new Target(*
this, arch, default_platform_sp, is_dummy_target));
803 ConstString(
"Settings specify to debugging targets."),
true,
814 ConstString(
"Settings specify to the debugger's command interpreter."),
819 nullptr, ePropertyTerminalWidth);
824 const char *term = getenv(
"TERM");
825 if (term && !strcmp(term,
"dumb"))
831 #if defined(_WIN32) && defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
834 llvm::sys::Process::UseANSIEscapeCodes(
true);
856 if (ProcessSP process_sp = target_sp->GetProcessSP())
857 process_sp->Finalize();
858 target_sp->Destroy();
891 static inline int OpenPipe(
int fds[2], std::size_t size) {
893 return _pipe(fds, size, O_BINARY);
903 int fds[2] = {-1, -1};
905 if (data ==
nullptr) {
910 size_t size = strlen(data);
918 "can't create pipe file descriptors for LLDB commands");
922 int r = write(fds[
WRITE], data, size);
926 llvm::sys::Process::SafelyCloseFileDescriptor(fds[
WRITE]);
930 FILE *commands_file = fdopen(fds[
READ],
"rb");
931 if (commands_file ==
nullptr) {
933 "when trying to open LLDB commands pipe",
935 llvm::sys::Process::SafelyCloseFileDescriptor(fds[
READ]);
939 SetInputFile((FileSP)std::make_shared<NativeFile>(commands_file,
true));
944 assert(file_sp && file_sp->IsValid());
952 assert(file_sp && file_sp->IsValid());
957 assert(file_sp && file_sp->IsValid());
970 bool adopt_selected =
true;
979 reader_sp->Interrupt();
1008 std::lock_guard<std::recursive_mutex> guard(
1014 if (top_reader_sp && top_reader_sp->GetIsDone())
1029 IOHandlerSP top_reader_sp = reader_sp;
1031 while (top_reader_sp) {
1035 top_reader_sp->Run();
1038 if (top_reader_sp.get() == reader_sp.get()) {
1047 if (top_reader_sp && top_reader_sp->GetIsDone()) {
1050 if (top_reader_sp.get() == reader_sp.get())
1071 lldb::StreamFileSP stream =
1073 stream->Write(s, len);
1094 bool cancel_top_handler) {
1099 StreamFileSP &err) {
1108 if (!in || !in->IsValid()) {
1110 in = top_reader_sp->GetInputFileSP();
1115 in = std::make_shared<NativeFile>(stdin,
false);
1118 if (!out || !out->GetFile().IsValid()) {
1120 out = top_reader_sp->GetOutputStreamFileSP();
1125 out = std::make_shared<StreamFile>(stdout,
false);
1128 if (!err || !err->GetFile().IsValid()) {
1130 err = top_reader_sp->GetErrorStreamFileSP();
1135 err = std::make_shared<StreamFile>(stderr,
false);
1140 bool cancel_top_handler) {
1150 if (reader_sp == top_reader_sp)
1155 reader_sp->Activate();
1159 if (top_reader_sp) {
1160 top_reader_sp->Deactivate();
1161 if (cancel_top_handler)
1162 top_reader_sp->Cancel();
1179 if (pop_reader_sp != reader_sp)
1182 reader_sp->Deactivate();
1183 reader_sp->Cancel();
1188 reader_sp->Activate();
1194 return std::make_shared<StreamAsynchronousIO>(*
this,
true,
GetUseColor());
1198 return std::make_shared<StreamAsynchronousIO>(*
this,
false,
GetUseColor());
1210 DebuggerSP debugger_sp;
1214 if (index < g_debugger_list_ptr->size())
1222 DebuggerSP debugger_sp;
1228 if ((*pos)->GetID() ==
id) {
1244 if (format ==
nullptr) {
1247 if (format ==
nullptr) {
1249 format = &format_entry;
1252 bool function_changed =
false;
1253 bool initial_function =
false;
1259 function_changed =
true;
1263 function_changed =
true;
1273 initial_function =
true;
1276 function_changed, initial_function);
1285 std::make_shared<CallbackLogHandler>(log_callback, baton);
1290 uint64_t completed, uint64_t total,
1291 bool is_debugger_specific) {
1296 EventSP event_sp(
new Event(
1298 is_debugger_specific)));
1303 uint64_t completed, uint64_t total,
1304 std::optional<lldb::user_id_t> debugger_id) {
1329 bool debugger_specific) {
1333 assert(
false &&
"DiagnosticEventData::Type::Info should not be broadcast");
1349 event_data.
Dump(stream.get());
1352 EventSP event_sp = std::make_shared<Event>(
1360 std::optional<lldb::user_id_t> debugger_id,
1361 std::once_flag *once) {
1362 auto ReportDiagnosticLambda = [&]() {
1391 std::call_once(*once, ReportDiagnosticLambda);
1393 ReportDiagnosticLambda();
1397 std::optional<lldb::user_id_t> debugger_id,
1398 std::once_flag *once) {
1404 std::optional<lldb::user_id_t> debugger_id,
1405 std::once_flag *once) {
1411 std::optional<lldb::user_id_t> debugger_id,
1412 std::once_flag *once) {
1421 EventSP event_sp = std::make_shared<Event>(
1424 debugger_sp->GetBroadcaster().BroadcastEvent(event_sp);
1429 static std::shared_ptr<LogHandler>
1431 size_t buffer_size) {
1432 switch (log_handler_kind) {
1434 return std::make_shared<StreamLogHandler>(fd, should_close, buffer_size);
1436 return std::make_shared<RotatingLogHandler>(buffer_size);
1438 return std::make_shared<SystemLogHandler>();
1446 llvm::ArrayRef<const char *> categories,
1447 llvm::StringRef log_file,
uint32_t log_options,
1449 llvm::raw_ostream &error_stream) {
1451 std::shared_ptr<LogHandler> log_handler_sp;
1457 }
else if (log_file.empty()) {
1460 false, buffer_size);
1464 log_handler_sp = pos->second.lock();
1465 if (!log_handler_sp) {
1473 FileSpec(log_file), flags, lldb::eFilePermissionsFileDefault,
false);
1475 error_stream <<
"Unable to open log file '" << log_file
1486 assert(log_handler_sp);
1488 if (log_options == 0)
1497 std::optional<lldb::ScriptLanguage> language) {
1520 using namespace lldb;
1538 if (event_type & eBreakpointEventTypeLocationsAdded) {
1542 if (num_new_locations > 0) {
1543 BreakpointSP breakpoint =
1547 output_sp->Printf(
"%d location%s added to breakpoint %d\n",
1548 num_new_locations, num_new_locations == 1 ?
"" :
"s",
1549 breakpoint->GetID());
1567 bool flush_stderr) {
1568 const auto &flush = [&](
Stream &stream,
1573 while ((len = (process.*get)(buffer,
sizeof(buffer),
error)) > 0)
1574 stream.
Write(buffer, len);
1587 using namespace lldb;
1588 const uint32_t event_type = event_sp->GetType();
1589 ProcessSP process_sp =
1599 bool pop_process_io_handler =
false;
1602 bool state_is_stopped =
false;
1603 const bool got_state_changed =
1607 const bool got_structured_data =
1610 if (got_state_changed) {
1617 if (got_state_changed && !state_is_stopped) {
1619 pop_process_io_handler);
1624 got_stderr || got_state_changed);
1627 if (got_structured_data) {
1628 StructuredDataPluginSP plugin_sp =
1631 auto structured_data_sp =
1633 if (output_stream_sp) {
1636 plugin_sp->GetDescription(structured_data_sp, content_stream);
1637 if (
error.Success()) {
1638 if (!content_stream.
GetString().empty()) {
1641 content_stream.
Flush();
1644 output_stream_sp->PutCString(content_stream.
GetString());
1647 error_stream_sp->Format(
"Failed to print structured "
1648 "data with plugin {0}: {1}",
1649 plugin_sp->GetPluginName(),
error);
1656 if (got_state_changed && state_is_stopped) {
1658 pop_process_io_handler);
1661 output_stream_sp->Flush();
1662 error_stream_sp->Flush();
1664 if (pop_process_io_handler)
1665 process_sp->PopProcessIOHandler();
1672 using namespace lldb;
1673 const uint32_t event_type = event_sp->GetType();
1674 const bool stop_format =
true;
1704 broadcaster_class_process,
1715 process_event_spec);
1718 listener_sp->StartListeningForEvents(
1724 listener_sp->StartListeningForEvents(
1735 if (listener_sp->GetEvent(event_sp, std::nullopt)) {
1737 Broadcaster *broadcaster = event_sp->GetBroadcaster();
1739 uint32_t event_type = event_sp->GetType();
1741 if (broadcaster_class == broadcaster_class_process) {
1743 }
else if (broadcaster_class == broadcaster_class_target) {
1748 }
else if (broadcaster_class == broadcaster_class_thread) {
1754 }
else if (event_type &
1756 const char *data =
static_cast<const char *
>(
1758 if (data && data[0]) {
1761 error_sp->PutCString(data);
1766 eBroadcastBitAsynchronousOutputData) {
1767 const char *data =
static_cast<const char *
>(
1769 if (data && data[0]) {
1772 output_sp->PutCString(data);
1801 ConstString full_name(
"lldb.debugger.event-handler");
1806 llvm::StringRef thread_name =
1807 full_name.
GetLength() < llvm::get_max_thread_name_length()
1809 :
"dbg.evt-handler";
1812 llvm::Expected<HostThread> event_handler_thread =
1817 if (event_handler_thread) {
1829 lldb::EventSP event_sp;
1830 listener_sp->GetEvent(event_sp, std::nullopt);
1856 const uint64_t
id = data->GetID();
1862 <<
static_cast<void *
>(
this) <<
" Debugger(" <<
GetID()
1863 <<
")::HandleProgressEvent( m_current_event_id = "
1865 data->Dump(&log_stream);
1866 log_stream <<
" } )";
1871 if (data->GetCompleted() == data->GetTotal())
1892 output->Printf(
"\r");
1894 if (data->GetCompleted() == data->GetTotal()) {
1896 output->Printf(
"\x1B[2K");
1903 if (data->IsFinite())
1904 message = llvm::formatv(
"[{0}/{1}] {2}", data->GetCompleted(),
1911 if (
message.size() + ellipsis >= term_width)
1916 if (!ansi_prefix.empty())
1920 output->Printf(
"%s...",
message.c_str());
1923 if (!ansi_suffix.empty())
1928 output->Printf(
"\x1B[K\r");
1940 data->Dump(stream.get());
1950 if (io_handler_thread) {
1976 if (!prefer_dummy) {
1994 language = *single_lang;
1995 }
else if (repl_languages.
Empty()) {
1997 "LLDB isn't configured with REPL support for any languages.");
2001 "Multiple possible REPL languages. Please specify a language.");
2009 REPLSP repl_sp(
REPL::Create(err, language,
this, target, repl_options));
2021 repl_sp->SetCompilerOptions(repl_options);
2029 "Debugger::GetThreadPool called before Debugger::Initialize");