62 #include "llvm/ADT/None.h"
63 #include "llvm/ADT/STLExtras.h"
64 #include "llvm/ADT/StringRef.h"
65 #include "llvm/ADT/iterator.h"
66 #include "llvm/Support/DynamicLibrary.h"
67 #include "llvm/Support/FileSystem.h"
68 #include "llvm/Support/Process.h"
69 #include "llvm/Support/ThreadPool.h"
70 #include "llvm/Support/Threading.h"
71 #include "llvm/Support/raw_ostream.h"
81 #include <system_error>
101 #pragma mark Static Functions
111 Debugger::eStopDisassemblyTypeNever,
113 "Never show disassembly when displaying a stop context.",
116 Debugger::eStopDisassemblyTypeNoDebugInfo,
118 "Show disassembly when there is no debug information.",
121 Debugger::eStopDisassemblyTypeNoSource,
123 "Show disassembly when there is no source information, or the source "
125 "is missing when displaying a stop context.",
128 Debugger::eStopDisassemblyTypeAlways,
130 "Always show disassembly when displaying a stop context.",
138 "Disable scripting languages.",
143 "Select python as the default scripting language.",
148 "Select the lldb default as the default scripting language.",
156 "Highlight the stop column with ANSI terminal codes when color/ANSI "
157 "mode is enabled; otherwise, fall back to using a text-only caret (^) "
158 "as if \"caret-only\" mode was selected.",
163 "Highlight the stop column with ANSI terminal codes when running LLDB "
164 "with color/ANSI enabled.",
169 "Highlight the stop column with a caret character (^) underneath the "
170 "stop column. This method introduces a new line in source listings "
171 "that display thread stop locations.",
176 "Do not highlight the stop column.",
180 #define LLDB_PROPERTIES_debugger
181 #include "CoreProperties.inc"
184 #define LLDB_PROPERTIES_debugger
185 #include "CorePropertiesEnum.inc"
188 LoadPluginCallbackType Debugger::g_load_plugin_callback =
nullptr;
192 llvm::StringRef property_path,
193 llvm::StringRef value) {
194 bool is_load_script =
195 (property_path ==
"target.load-script-from-symbol-file");
197 bool invalidate_data_vis = (property_path ==
"escape-non-printables");
198 invalidate_data_vis |=
199 (property_path ==
"target.max-zero-padding-in-float-format");
200 if (invalidate_data_vis) {
201 DataVisualization::ForceUpdate();
208 load_script_old_value =
209 target_sp->TargetProperties::GetLoadScriptFromSymbolFile();
211 Status error(Properties::SetPropertyValue(exe_ctx, op, property_path, value));
212 if (
error.Success()) {
214 if (property_path == g_debugger_properties[ePropertyPrompt].name) {
215 llvm::StringRef new_prompt = GetPrompt();
217 new_prompt, GetUseColor());
220 GetCommandInterpreter().UpdatePrompt(new_prompt);
221 auto bytes = std::make_unique<EventDataBytes>(new_prompt);
222 auto prompt_change_event_sp = std::make_shared<Event>(
223 CommandInterpreter::eBroadcastBitResetPrompt, bytes.release());
224 GetCommandInterpreter().BroadcastEvent(prompt_change_event_sp);
225 }
else if (property_path == g_debugger_properties[ePropertyUseColor].name) {
228 SetPrompt(GetPrompt());
229 }
else if (property_path == g_debugger_properties[ePropertyUseSourceCache].name) {
231 if (!GetUseSourceCache()) {
232 m_source_file_cache.Clear();
234 }
else if (is_load_script && target_sp &&
236 if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() ==
238 std::list<Status> errors;
240 if (!target_sp->LoadScriptingResources(errors, &feedback_stream)) {
241 Stream &s = GetErrorStream();
242 for (
auto error : errors) {
254 bool Debugger::GetAutoConfirm()
const {
255 const uint32_t idx = ePropertyAutoConfirm;
256 return m_collection_sp->GetPropertyAtIndexAsBoolean(
257 nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
261 const uint32_t idx = ePropertyDisassemblyFormat;
262 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(
nullptr, idx);
266 const uint32_t idx = ePropertyFrameFormat;
267 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(
nullptr, idx);
271 const uint32_t idx = ePropertyFrameFormatUnique;
272 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(
nullptr, idx);
275 uint32_t Debugger::GetStopDisassemblyMaxSize()
const {
276 const uint32_t idx = ePropertyStopDisassemblyMaxSize;
277 return m_collection_sp->GetPropertyAtIndexAsUInt64(
278 nullptr, idx, g_debugger_properties[idx].default_uint_value);
281 bool Debugger::GetNotifyVoid()
const {
282 const uint32_t idx = ePropertyNotiftVoid;
283 return m_collection_sp->GetPropertyAtIndexAsBoolean(
284 nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
287 llvm::StringRef Debugger::GetPrompt()
const {
288 const uint32_t idx = ePropertyPrompt;
289 return m_collection_sp->GetPropertyAtIndexAsString(
290 nullptr, idx, g_debugger_properties[idx].default_cstr_value);
293 void Debugger::SetPrompt(llvm::StringRef p) {
294 const uint32_t idx = ePropertyPrompt;
295 m_collection_sp->SetPropertyAtIndexAsString(
nullptr, idx, p);
296 llvm::StringRef new_prompt = GetPrompt();
301 GetCommandInterpreter().UpdatePrompt(new_prompt);
304 llvm::StringRef Debugger::GetReproducerPath()
const {
305 auto &r = repro::Reproducer::Instance();
306 return r.GetReproducerPath().GetCString();
310 const uint32_t idx = ePropertyThreadFormat;
311 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(
nullptr, idx);
315 const uint32_t idx = ePropertyThreadStopFormat;
316 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(
nullptr, idx);
320 const uint32_t idx = ePropertyScriptLanguage;
322 nullptr, idx, g_debugger_properties[idx].default_uint_value);
326 const uint32_t idx = ePropertyScriptLanguage;
327 return m_collection_sp->SetPropertyAtIndexAsEnumeration(
nullptr, idx,
332 const uint32_t idx = ePropertyREPLLanguage;
334 m_collection_sp->GetPropertyAtIndexAsOptionValueLanguage(
nullptr, idx);
341 const uint32_t idx = ePropertyREPLLanguage;
342 return m_collection_sp->SetPropertyAtIndexAsLanguage(
nullptr, idx, repl_lang);
346 const uint32_t idx = ePropertyTerminalWidth;
347 return m_collection_sp->GetPropertyAtIndexAsSInt64(
348 nullptr, idx, g_debugger_properties[idx].default_uint_value);
351 bool Debugger::SetTerminalWidth(
uint32_t term_width) {
352 if (
auto handler_sp = m_io_handler_stack.Top())
353 handler_sp->TerminalSizeChanged();
355 const uint32_t idx = ePropertyTerminalWidth;
356 return m_collection_sp->SetPropertyAtIndexAsSInt64(
nullptr, idx, term_width);
359 bool Debugger::GetUseExternalEditor()
const {
360 const uint32_t idx = ePropertyUseExternalEditor;
361 return m_collection_sp->GetPropertyAtIndexAsBoolean(
362 nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
365 bool Debugger::SetUseExternalEditor(
bool b) {
366 const uint32_t idx = ePropertyUseExternalEditor;
367 return m_collection_sp->SetPropertyAtIndexAsBoolean(
nullptr, idx, b);
370 bool Debugger::GetUseColor()
const {
371 const uint32_t idx = ePropertyUseColor;
372 return m_collection_sp->GetPropertyAtIndexAsBoolean(
373 nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
376 bool Debugger::SetUseColor(
bool b) {
377 const uint32_t idx = ePropertyUseColor;
378 bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean(
nullptr, idx, b);
379 SetPrompt(GetPrompt());
383 bool Debugger::GetShowProgress()
const {
384 const uint32_t idx = ePropertyShowProgress;
385 return m_collection_sp->GetPropertyAtIndexAsBoolean(
386 nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
389 bool Debugger::SetShowProgress(
bool show_progress) {
390 const uint32_t idx = ePropertyShowProgress;
391 return m_collection_sp->SetPropertyAtIndexAsBoolean(
nullptr, idx,
395 llvm::StringRef Debugger::GetShowProgressAnsiPrefix()
const {
396 const uint32_t idx = ePropertyShowProgressAnsiPrefix;
397 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
400 llvm::StringRef Debugger::GetShowProgressAnsiSuffix()
const {
401 const uint32_t idx = ePropertyShowProgressAnsiSuffix;
402 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
405 bool Debugger::GetUseAutosuggestion()
const {
406 const uint32_t idx = ePropertyShowAutosuggestion;
407 return m_collection_sp->GetPropertyAtIndexAsBoolean(
408 nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
411 llvm::StringRef Debugger::GetAutosuggestionAnsiPrefix()
const {
412 const uint32_t idx = ePropertyShowAutosuggestionAnsiPrefix;
413 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
416 llvm::StringRef Debugger::GetAutosuggestionAnsiSuffix()
const {
417 const uint32_t idx = ePropertyShowAutosuggestionAnsiSuffix;
418 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
421 bool Debugger::GetUseSourceCache()
const {
422 const uint32_t idx = ePropertyUseSourceCache;
423 return m_collection_sp->GetPropertyAtIndexAsBoolean(
424 nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
427 bool Debugger::SetUseSourceCache(
bool b) {
428 const uint32_t idx = ePropertyUseSourceCache;
429 bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean(
nullptr, idx, b);
431 m_source_file_cache.Clear();
435 bool Debugger::GetHighlightSource()
const {
436 const uint32_t idx = ePropertyHighlightSource;
437 return m_collection_sp->GetPropertyAtIndexAsBoolean(
438 nullptr, idx, g_debugger_properties[idx].default_uint_value);
442 const uint32_t idx = ePropertyStopShowColumn;
444 nullptr, idx, g_debugger_properties[idx].default_uint_value);
447 llvm::StringRef Debugger::GetStopShowColumnAnsiPrefix()
const {
448 const uint32_t idx = ePropertyStopShowColumnAnsiPrefix;
449 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
452 llvm::StringRef Debugger::GetStopShowColumnAnsiSuffix()
const {
453 const uint32_t idx = ePropertyStopShowColumnAnsiSuffix;
454 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
457 llvm::StringRef Debugger::GetStopShowLineMarkerAnsiPrefix()
const {
458 const uint32_t idx = ePropertyStopShowLineMarkerAnsiPrefix;
459 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
462 llvm::StringRef Debugger::GetStopShowLineMarkerAnsiSuffix()
const {
463 const uint32_t idx = ePropertyStopShowLineMarkerAnsiSuffix;
464 return m_collection_sp->GetPropertyAtIndexAsString(
nullptr, idx,
"");
467 uint32_t Debugger::GetStopSourceLineCount(
bool before)
const {
469 before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter;
470 return m_collection_sp->GetPropertyAtIndexAsSInt64(
471 nullptr, idx, g_debugger_properties[idx].default_uint_value);
475 const uint32_t idx = ePropertyStopDisassemblyDisplay;
477 m_collection_sp->GetPropertyAtIndexAsEnumeration(
478 nullptr, idx, g_debugger_properties[idx].default_uint_value);
481 uint32_t Debugger::GetDisassemblyLineCount()
const {
482 const uint32_t idx = ePropertyStopDisassemblyCount;
483 return m_collection_sp->GetPropertyAtIndexAsSInt64(
484 nullptr, idx, g_debugger_properties[idx].default_uint_value);
487 bool Debugger::GetAutoOneLineSummaries()
const {
488 const uint32_t idx = ePropertyAutoOneLineSummaries;
489 return m_collection_sp->GetPropertyAtIndexAsBoolean(
nullptr, idx,
true);
492 bool Debugger::GetEscapeNonPrintables()
const {
493 const uint32_t idx = ePropertyEscapeNonPrintables;
494 return m_collection_sp->GetPropertyAtIndexAsBoolean(
nullptr, idx,
true);
497 bool Debugger::GetAutoIndent()
const {
498 const uint32_t idx = ePropertyAutoIndent;
499 return m_collection_sp->GetPropertyAtIndexAsBoolean(
nullptr, idx,
true);
502 bool Debugger::SetAutoIndent(
bool b) {
503 const uint32_t idx = ePropertyAutoIndent;
504 return m_collection_sp->SetPropertyAtIndexAsBoolean(
nullptr, idx, b);
507 bool Debugger::GetPrintDecls()
const {
508 const uint32_t idx = ePropertyPrintDecls;
509 return m_collection_sp->GetPropertyAtIndexAsBoolean(
nullptr, idx,
true);
512 bool Debugger::SetPrintDecls(
bool b) {
513 const uint32_t idx = ePropertyPrintDecls;
514 return m_collection_sp->SetPropertyAtIndexAsBoolean(
nullptr, idx, b);
518 const uint32_t idx = ePropertyTabSize;
519 return m_collection_sp->GetPropertyAtIndexAsUInt64(
520 nullptr, idx, g_debugger_properties[idx].default_uint_value);
524 const uint32_t idx = ePropertyTabSize;
525 return m_collection_sp->SetPropertyAtIndexAsUInt64(
nullptr, idx, tab_size);
528 #pragma mark Debugger
537 void Debugger::Initialize(LoadPluginCallbackType load_plugin_callback) {
539 "Debugger::Initialize called more than once!");
542 g_load_plugin_callback = load_plugin_callback;
545 void Debugger::Terminate() {
547 "Debugger::Terminate called without a matching Debugger::Initialize!");
560 void Debugger::SettingsInitialize() { Target::SettingsInitialize(); }
562 void Debugger::SettingsTerminate() { Target::SettingsTerminate(); }
565 if (g_load_plugin_callback) {
566 llvm::sys::DynamicLibrary dynlib =
567 g_load_plugin_callback(shared_from_this(), spec,
error);
568 if (dynlib.isValid()) {
569 m_loaded_plugins.push_back(dynlib);
576 error.SetErrorString(
"Public API layer is not available");
583 llvm::StringRef path) {
590 return FileSystem::eEnumerateDirectoryResultQuit;
594 namespace fs = llvm::sys::fs;
599 if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file ||
600 ft == fs::file_type::type_unknown) {
602 FileSystem::Instance().Resolve(plugin_file_spec);
606 return FileSystem::eEnumerateDirectoryResultNext;
610 debugger->
LoadPlugin(plugin_file_spec, plugin_load_error);
612 return FileSystem::eEnumerateDirectoryResultNext;
613 }
else if (ft == fs::file_type::directory_file ||
614 ft == fs::file_type::symlink_file ||
615 ft == fs::file_type::type_unknown) {
620 return FileSystem::eEnumerateDirectoryResultEnter;
623 return FileSystem::eEnumerateDirectoryResultNext;
626 void Debugger::InstanceInitialize() {
627 const bool find_directories =
true;
628 const bool find_files =
true;
629 const bool find_other =
true;
631 if (
FileSpec dir_spec = HostInfo::GetSystemPluginDir()) {
632 if (FileSystem::Instance().Exists(dir_spec) &&
633 dir_spec.GetPath(dir_path,
sizeof(dir_path))) {
634 FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
635 find_files, find_other,
640 if (
FileSpec dir_spec = HostInfo::GetUserPluginDir()) {
641 if (FileSystem::Instance().Exists(dir_spec) &&
642 dir_spec.GetPath(dir_path,
sizeof(dir_path))) {
643 FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
644 find_files, find_other,
649 PluginManager::DebuggerInitialize(*
this);
654 DebuggerSP debugger_sp(
new Debugger(log_callback, baton));
659 debugger_sp->InstanceInitialize();
663 void Debugger::Destroy(DebuggerSP &debugger_sp) {
673 (*debugger_sp->GetAsyncOutputStream()) << result.
GetOutputData() <<
'\n';
675 (*debugger_sp->GetAsyncErrorStream()) << result.
GetErrorData() <<
'\n';
678 debugger_sp->Clear();
684 if ((*pos).get() == debugger_sp.get()) {
692 DebuggerSP Debugger::FindDebuggerWithInstanceName(
ConstString instance_name) {
693 DebuggerSP debugger_sp;
698 if ((*pos)->m_instance_name == instance_name) {
713 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID(pid);
721 TargetSP Debugger::FindTargetWithProcess(
Process *process) {
727 target_sp = (*pos)->GetTargetList().FindTargetWithProcess(process);
743 m_input_file_sp(std::make_shared<
NativeFile>(stdin, false)),
744 m_output_stream_sp(std::make_shared<
StreamFile>(stdout, false)),
745 m_error_stream_sp(std::make_shared<
StreamFile>(stderr, false)),
746 m_input_recorder(nullptr),
748 m_terminal_state(), m_target_list(*this), m_platform_list(),
749 m_listener_sp(
Listener::MakeListener(
"lldb.Debugger")),
750 m_source_manager_up(), m_source_file_cache(),
751 m_command_interpreter_up(
753 m_io_handler_stack(), m_instance_name(), m_loaded_plugins(),
754 m_event_handler_thread(), m_io_handler_thread(),
755 m_sync_broadcaster(nullptr,
"lldb.debugger.sync"),
756 m_broadcaster(m_broadcaster_manager_sp,
757 GetStaticBroadcasterClass().AsCString()),
758 m_forward_listener_sp(), m_clear_once() {
762 std::make_shared<StreamCallback>(log_callback, baton);
766 assert(default_platform_sp);
773 arch = HostInfo::GetArchitecture();
774 assert(arch.
IsValid() &&
"No valid default or host archspec");
775 const bool is_dummy_target =
true;
777 new Target(*
this, arch, default_platform_sp, is_dummy_target));
784 ConstString(
"Settings specify to debugging targets."),
true,
795 ConstString(
"Settings specify to the debugger's command interpreter."),
800 nullptr, ePropertyTerminalWidth);
805 const char *term = getenv(
"TERM");
806 if (term && !strcmp(term,
"dumb"))
812 #if defined(_WIN32) && defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
815 llvm::sys::Process::UseANSIEscapeCodes(
true);
837 if (ProcessSP process_sp = target_sp->GetProcessSP())
838 process_sp->Finalize();
839 target_sp->Destroy();
872 static inline int OpenPipe(
int fds[2], std::size_t size) {
874 return _pipe(fds, size, O_BINARY);
884 int fds[2] = {-1, -1};
886 if (data ==
nullptr) {
891 size_t size = strlen(data);
899 "can't create pipe file descriptors for LLDB commands");
903 int r = write(fds[
WRITE], data, size);
907 llvm::sys::Process::SafelyCloseFileDescriptor(fds[
WRITE]);
911 FILE *commands_file = fdopen(fds[
READ],
"rb");
912 if (commands_file ==
nullptr) {
914 "when trying to open LLDB commands pipe",
916 llvm::sys::Process::SafelyCloseFileDescriptor(fds[
READ]);
921 (FileSP)std::make_shared<NativeFile>(commands_file,
true));
930 static std::unique_ptr<repro::MultiLoader<repro::CommandProvider>> loader =
934 llvm::Optional<std::string> nextfile = loader->GetNextFile();
940 file_sp = std::make_shared<NativeFile>(fh,
true);
944 if (!file_sp || !file_sp->IsValid()) {
945 error.SetErrorString(
"invalid file");
954 assert(file_sp && file_sp->IsValid());
963 assert(file_sp && file_sp->IsValid());
968 assert(file_sp && file_sp->IsValid());
981 bool adopt_selected =
true;
990 reader_sp->Interrupt();
1019 std::lock_guard<std::recursive_mutex> guard(
1025 if (top_reader_sp && top_reader_sp->GetIsDone())
1040 IOHandlerSP top_reader_sp = reader_sp;
1042 while (top_reader_sp) {
1046 top_reader_sp->Run();
1049 if (top_reader_sp.get() == reader_sp.get()) {
1058 if (top_reader_sp && top_reader_sp->GetIsDone()) {
1061 if (top_reader_sp.get() == reader_sp.get())
1082 lldb::StreamFileSP stream =
1084 stream->Write(s, len);
1105 bool cancel_top_handler) {
1110 StreamFileSP &err) {
1119 if (!in || !in->IsValid()) {
1121 in = top_reader_sp->GetInputFileSP();
1126 in = std::make_shared<NativeFile>(stdin,
false);
1129 if (!out || !out->GetFile().IsValid()) {
1131 out = top_reader_sp->GetOutputStreamFileSP();
1136 out = std::make_shared<StreamFile>(stdout,
false);
1139 if (!err || !err->GetFile().IsValid()) {
1141 err = top_reader_sp->GetErrorStreamFileSP();
1146 err = std::make_shared<StreamFile>(stderr,
false);
1151 bool cancel_top_handler) {
1161 if (reader_sp == top_reader_sp)
1166 reader_sp->Activate();
1170 if (top_reader_sp) {
1171 top_reader_sp->Deactivate();
1172 if (cancel_top_handler)
1173 top_reader_sp->Cancel();
1190 if (pop_reader_sp != reader_sp)
1193 reader_sp->Deactivate();
1194 reader_sp->Cancel();
1199 reader_sp->Activate();
1205 return std::make_shared<StreamAsynchronousIO>(*
this,
true,
GetUseColor());
1209 return std::make_shared<StreamAsynchronousIO>(*
this,
false,
GetUseColor());
1221 DebuggerSP debugger_sp;
1225 if (index < g_debugger_list_ptr->size())
1233 DebuggerSP debugger_sp;
1239 if ((*pos)->GetID() ==
id) {
1255 if (format ==
nullptr) {
1258 if (format ==
nullptr) {
1260 format = &format_entry;
1263 bool function_changed =
false;
1264 bool initial_function =
false;
1270 function_changed =
true;
1274 function_changed =
true;
1284 initial_function =
true;
1287 function_changed, initial_function);
1296 std::make_shared<StreamCallback>(log_callback, baton);
1301 uint64_t completed, uint64_t total,
1302 bool is_debugger_specific) {
1307 EventSP event_sp(
new Event(
1309 is_debugger_specific)));
1314 uint64_t completed, uint64_t total,
1315 llvm::Optional<lldb::user_id_t> debugger_id) {
1317 if (debugger_id.hasValue()) {
1340 bool debugger_specific) {
1357 event_data.
Dump(stream.get());
1360 EventSP event_sp = std::make_shared<Event>(
1368 llvm::Optional<lldb::user_id_t> debugger_id,
1369 std::once_flag *once) {
1370 auto ReportDiagnosticLambda = [&]() {
1390 std::call_once(*once, ReportDiagnosticLambda);
1392 ReportDiagnosticLambda();
1396 llvm::Optional<lldb::user_id_t> debugger_id,
1397 std::once_flag *once) {
1403 llvm::Optional<lldb::user_id_t> debugger_id,
1404 std::once_flag *once) {
1411 llvm::ArrayRef<const char *> categories,
1412 llvm::StringRef log_file,
uint32_t log_options,
1413 llvm::raw_ostream &error_stream) {
1414 const bool should_close =
true;
1415 const bool unbuffered =
true;
1417 std::shared_ptr<llvm::raw_ostream> log_stream_sp;
1423 }
else if (log_file.empty()) {
1424 log_stream_sp = std::make_shared<llvm::raw_fd_ostream>(
1425 GetOutputFile().GetDescriptor(), !should_close, unbuffered);
1429 log_stream_sp = pos->second.lock();
1430 if (!log_stream_sp) {
1438 FileSpec(log_file), flags, lldb::eFilePermissionsFileDefault,
false);
1440 error_stream <<
"Unable to open log file '" << log_file
1445 log_stream_sp = std::make_shared<llvm::raw_fd_ostream>(
1446 (*file)->GetDescriptor(), should_close, unbuffered);
1450 assert(log_stream_sp);
1452 if (log_options == 0)
1462 llvm::Optional<lldb::ScriptLanguage> language) {
1485 using namespace lldb;
1503 if (event_type & eBreakpointEventTypeLocationsAdded) {
1507 if (num_new_locations > 0) {
1508 BreakpointSP breakpoint =
1512 output_sp->Printf(
"%d location%s added to breakpoint %d\n",
1513 num_new_locations, num_new_locations == 1 ?
"" :
"s",
1514 breakpoint->GetID());
1532 bool flush_stderr) {
1533 const auto &flush = [&](
Stream &stream,
1538 while ((len = (process.*get)(buffer,
sizeof(buffer),
error)) > 0)
1539 stream.
Write(buffer, len);
1552 using namespace lldb;
1553 const uint32_t event_type = event_sp->GetType();
1554 ProcessSP process_sp =
1564 bool pop_process_io_handler =
false;
1567 bool state_is_stopped =
false;
1568 const bool got_state_changed =
1572 const bool got_structured_data =
1575 if (got_state_changed) {
1582 if (got_state_changed && !state_is_stopped) {
1584 pop_process_io_handler);
1589 got_stderr || got_state_changed);
1592 if (got_structured_data) {
1593 StructuredDataPluginSP plugin_sp =
1596 auto structured_data_sp =
1598 if (output_stream_sp) {
1601 plugin_sp->GetDescription(structured_data_sp, content_stream);
1602 if (
error.Success()) {
1603 if (!content_stream.
GetString().empty()) {
1606 content_stream.
Flush();
1609 output_stream_sp->PutCString(content_stream.
GetString());
1612 error_stream_sp->Format(
"Failed to print structured "
1613 "data with plugin {0}: {1}",
1614 plugin_sp->GetPluginName(),
error);
1621 if (got_state_changed && state_is_stopped) {
1623 pop_process_io_handler);
1626 output_stream_sp->Flush();
1627 error_stream_sp->Flush();
1629 if (pop_process_io_handler)
1630 process_sp->PopProcessIOHandler();
1637 using namespace lldb;
1638 const uint32_t event_type = event_sp->GetType();
1639 const bool stop_format =
true;
1669 broadcaster_class_process,
1680 process_event_spec);
1683 listener_sp->StartListeningForEvents(
1689 listener_sp->StartListeningForEvents(
1700 if (listener_sp->GetEvent(event_sp, llvm::None)) {
1702 Broadcaster *broadcaster = event_sp->GetBroadcaster();
1704 uint32_t event_type = event_sp->GetType();
1706 if (broadcaster_class == broadcaster_class_process) {
1708 }
else if (broadcaster_class == broadcaster_class_target) {
1713 }
else if (broadcaster_class == broadcaster_class_thread) {
1719 }
else if (event_type &
1721 const char *data =
static_cast<const char *
>(
1723 if (data && data[0]) {
1726 error_sp->PutCString(data);
1731 eBroadcastBitAsynchronousOutputData) {
1732 const char *data =
static_cast<const char *
>(
1734 if (data && data[0]) {
1737 output_sp->PutCString(data);
1766 ConstString full_name(
"lldb.debugger.event-handler");
1771 llvm::StringRef thread_name =
1772 full_name.
GetLength() < llvm::get_max_thread_name_length()
1774 :
"dbg.evt-handler";
1777 llvm::Expected<HostThread> event_handler_thread =
1782 if (event_handler_thread) {
1794 lldb::EventSP event_sp;
1795 listener_sp->GetEvent(event_sp, llvm::None);
1821 const uint64_t
id = data->GetID();
1825 if (data->GetCompleted())
1846 output->Printf(
"\r");
1848 if (data->GetCompleted()) {
1850 output->Printf(
"\x1B[2K");
1857 if (data->IsFinite())
1858 message = llvm::formatv(
"[{0}/{1}] {2}", data->GetCompleted(),
1865 if (
message.size() + ellipsis >= term_width)
1870 if (!ansi_prefix.empty())
1874 output->Printf(
"%s...",
message.c_str());
1877 if (!ansi_suffix.empty())
1882 output->Printf(
"\x1B[K\r");
1894 data->Dump(stream.get());
1904 if (io_handler_thread) {
1930 if (!prefer_dummy) {
1948 language = *single_lang;
1949 }
else if (repl_languages.
Empty()) {
1951 "LLDB isn't configured with REPL support for any languages.");
1955 "Multiple possible REPL languages. Please specify a language.");
1963 REPLSP repl_sp(
REPL::Create(err, language,
this, target, repl_options));
1975 repl_sp->SetCompilerOptions(repl_options);
1983 static llvm::ThreadPool *g_thread_pool =
nullptr;
1984 static llvm::once_flag g_once_flag;
1985 llvm::call_once(g_once_flag, []() {
1986 g_thread_pool =
new llvm::ThreadPool(llvm::optimal_concurrency());
1988 return *g_thread_pool;