LLDB mainline
Debugger.cpp
Go to the documentation of this file.
1//===-- Debugger.cpp ------------------------------------------------------===//
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
10
14#include "lldb/Core/Mangled.h"
18#include "lldb/Core/Progress.h"
21#include "lldb/Core/Telemetry.h"
24#include "lldb/Host/File.h"
26#include "lldb/Host/HostInfo.h"
28#include "lldb/Host/Terminal.h"
40#include "lldb/Symbol/Symbol.h"
43#include "lldb/Target/Process.h"
45#include "lldb/Target/Target.h"
47#include "lldb/Target/Thread.h"
50#include "lldb/Utility/Event.h"
53#include "lldb/Utility/Log.h"
54#include "lldb/Utility/State.h"
55#include "lldb/Utility/Stream.h"
59
60#if defined(_WIN32)
63#endif
64
65#include "llvm/ADT/STLExtras.h"
66#include "llvm/ADT/StringRef.h"
67#include "llvm/ADT/iterator.h"
68#include "llvm/Config/llvm-config.h"
69#include "llvm/Support/DynamicLibrary.h"
70#include "llvm/Support/FileSystem.h"
71#include "llvm/Support/Process.h"
72#include "llvm/Support/ThreadPool.h"
73#include "llvm/Support/Threading.h"
74#include "llvm/Support/raw_ostream.h"
75
76#include <chrono>
77#include <cstdio>
78#include <cstdlib>
79#include <cstring>
80#include <list>
81#include <memory>
82#include <mutex>
83#include <optional>
84#include <set>
85#include <string>
86#include <system_error>
87
88// Includes for pipe()
89#if defined(_WIN32)
90#include <fcntl.h>
91#include <io.h>
92#else
93#include <unistd.h>
94#endif
95
96namespace lldb_private {
97class Address;
98}
99
100using namespace lldb;
101using namespace lldb_private;
102
104static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024;
105
106#pragma mark Static Functions
107
108static std::recursive_mutex *g_debugger_list_mutex_ptr =
109 nullptr; // NOTE: intentional leak to avoid issues with C++ destructor chain
111 nullptr; // NOTE: intentional leak to avoid issues with C++ destructor chain
112static llvm::DefaultThreadPool *g_thread_pool = nullptr;
113
115 {
117 "never",
118 "Never show disassembly when displaying a stop context.",
119 },
120 {
122 "no-debuginfo",
123 "Show disassembly when there is no debug information.",
124 },
125 {
127 "no-source",
128 "Show disassembly when there is no source information, or the source "
129 "file "
130 "is missing when displaying a stop context.",
131 },
132 {
134 "always",
135 "Always show disassembly when displaying a stop context.",
136 },
137};
138
140 {
142 "none",
143 "Disable scripting languages.",
144 },
145 {
147 "python",
148 "Select python as the default scripting language.",
149 },
150 {
152 "default",
153 "Select the lldb default as the default scripting language.",
154 },
155};
156
159 "Use no verbosity when running dwim-print."},
160 {eDWIMPrintVerbosityExpression, "expression",
161 "Use partial verbosity when running dwim-print - display a message when "
162 "`expression` evaluation is used."},
164 "Use full verbosity when running dwim-print."},
165};
166
168 {
170 "ansi-or-caret",
171 "Highlight the stop column with ANSI terminal codes when color/ANSI "
172 "mode is enabled; otherwise, fall back to using a text-only caret (^) "
173 "as if \"caret-only\" mode was selected.",
174 },
175 {
177 "ansi",
178 "Highlight the stop column with ANSI terminal codes when running LLDB "
179 "with color/ANSI enabled.",
180 },
181 {
183 "caret",
184 "Highlight the stop column with a caret character (^) underneath the "
185 "stop column. This method introduces a new line in source listings "
186 "that display thread stop locations.",
187 },
188 {
190 "none",
191 "Do not highlight the stop column.",
192 },
193};
194
195#define LLDB_PROPERTIES_debugger
196#include "CoreProperties.inc"
197
198enum {
199#define LLDB_PROPERTIES_debugger
200#include "CorePropertiesEnum.inc"
201};
202
204
207 llvm::StringRef property_path,
208 llvm::StringRef value) {
209 bool is_load_script =
210 (property_path == "target.load-script-from-symbol-file");
211 // These properties might change how we visualize data.
212 bool invalidate_data_vis = (property_path == "escape-non-printables");
213 invalidate_data_vis |=
214 (property_path == "target.max-zero-padding-in-float-format");
215 if (invalidate_data_vis) {
217 }
218
219 TargetSP target_sp;
221 if (is_load_script && exe_ctx && exe_ctx->GetTargetSP()) {
222 target_sp = exe_ctx->GetTargetSP();
223 load_script_old_value =
224 target_sp->TargetProperties::GetLoadScriptFromSymbolFile();
225 }
226 Status error(Properties::SetPropertyValue(exe_ctx, op, property_path, value));
227 if (error.Success()) {
228 // FIXME it would be nice to have "on-change" callbacks for properties
229 if (property_path == g_debugger_properties[ePropertyPrompt].name) {
230 llvm::StringRef new_prompt = GetPrompt();
232 new_prompt, GetUseColor());
233 if (str.length())
234 new_prompt = str;
236 auto bytes = std::make_unique<EventDataBytes>(new_prompt);
237 auto prompt_change_event_sp = std::make_shared<Event>(
239 GetCommandInterpreter().BroadcastEvent(prompt_change_event_sp);
240 } else if (property_path == g_debugger_properties[ePropertyUseColor].name) {
241 // use-color changed. set use-color, this also pings the prompt so it can
242 // reset the ansi terminal codes.
244 } else if (property_path ==
245 g_debugger_properties[ePropertyPromptAnsiPrefix].name ||
246 property_path ==
247 g_debugger_properties[ePropertyPromptAnsiSuffix].name) {
248 // Prompt color changed. set use-color, this also pings the prompt so it
249 // can reset the ansi terminal codes.
251 } else if (property_path ==
252 g_debugger_properties[ePropertyShowStatusline].name) {
253 // Statusline setting changed. If we have a statusline instance, update it
254 // now. Otherwise it will get created in the default event handler.
255 std::lock_guard<std::mutex> guard(m_statusline_mutex);
257 m_statusline.emplace(*this);
258 else
259 m_statusline.reset();
260 } else if (property_path ==
261 g_debugger_properties[ePropertyStatuslineFormat].name ||
262 property_path ==
263 g_debugger_properties[ePropertySeparator].name) {
264 // Statusline format changed. Redraw the statusline.
266 } else if (property_path ==
267 g_debugger_properties[ePropertyUseSourceCache].name) {
268 // use-source-cache changed. Wipe out the cache contents if it was
269 // disabled.
270 if (!GetUseSourceCache()) {
271 m_source_file_cache.Clear();
272 }
273 } else if (is_load_script && target_sp &&
274 load_script_old_value == eLoadScriptFromSymFileWarn) {
275 if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() ==
277 std::list<Status> errors;
278 StreamString feedback_stream;
279 if (!target_sp->LoadScriptingResources(errors, feedback_stream)) {
281 for (auto &error : errors)
282 s->Printf("%s\n", error.AsCString());
283 if (feedback_stream.GetSize())
284 s->PutCString(feedback_stream.GetString());
285 }
286 }
287 }
288 }
289 return error;
290}
291
293 constexpr uint32_t idx = ePropertyAutoConfirm;
295 idx, g_debugger_properties[idx].default_uint_value != 0);
296}
297
299 constexpr uint32_t idx = ePropertyDisassemblyFormat;
301}
302
304 constexpr uint32_t idx = ePropertyFrameFormat;
306}
307
309 constexpr uint32_t idx = ePropertyFrameFormatUnique;
311}
312
314 constexpr uint32_t idx = ePropertyStopDisassemblyMaxSize;
316 idx, g_debugger_properties[idx].default_uint_value);
317}
318
320 constexpr uint32_t idx = ePropertyNotiftVoid;
322 idx, g_debugger_properties[idx].default_uint_value != 0);
323}
324
325llvm::StringRef Debugger::GetPrompt() const {
326 constexpr uint32_t idx = ePropertyPrompt;
328 idx, g_debugger_properties[idx].default_cstr_value);
329}
330
331llvm::StringRef Debugger::GetPromptAnsiPrefix() const {
332 const uint32_t idx = ePropertyPromptAnsiPrefix;
334 idx, g_debugger_properties[idx].default_cstr_value);
335}
336
337llvm::StringRef Debugger::GetPromptAnsiSuffix() const {
338 const uint32_t idx = ePropertyPromptAnsiSuffix;
340 idx, g_debugger_properties[idx].default_cstr_value);
341}
342
343void Debugger::SetPrompt(llvm::StringRef p) {
344 constexpr uint32_t idx = ePropertyPrompt;
345 SetPropertyAtIndex(idx, p);
346 llvm::StringRef new_prompt = GetPrompt();
347 std::string str =
349 if (str.length())
350 new_prompt = str;
352}
353
355 constexpr uint32_t idx = ePropertyThreadFormat;
357}
358
360 constexpr uint32_t idx = ePropertyThreadStopFormat;
362}
363
365 const uint32_t idx = ePropertyScriptLanguage;
367 idx, static_cast<lldb::ScriptLanguage>(
368 g_debugger_properties[idx].default_uint_value));
369}
370
372 const uint32_t idx = ePropertyScriptLanguage;
373 return SetPropertyAtIndex(idx, script_lang);
374}
375
377 const uint32_t idx = ePropertyREPLLanguage;
379}
380
382 const uint32_t idx = ePropertyREPLLanguage;
383 return SetPropertyAtIndex(idx, repl_lang);
384}
385
387 const uint32_t idx = ePropertyTerminalWidth;
389 idx, g_debugger_properties[idx].default_uint_value);
390}
391
392bool Debugger::SetTerminalWidth(uint64_t term_width) {
393 const uint32_t idx = ePropertyTerminalWidth;
394 const bool success = SetPropertyAtIndex(idx, term_width);
395
396 if (auto handler_sp = m_io_handler_stack.Top())
397 handler_sp->TerminalSizeChanged();
398
399 {
400 std::lock_guard<std::mutex> guard(m_statusline_mutex);
401 if (m_statusline)
402 m_statusline->TerminalSizeChanged();
403 }
404
405 return success;
406}
407
409 const uint32_t idx = ePropertyTerminalHeight;
411 idx, g_debugger_properties[idx].default_uint_value);
412}
413
414bool Debugger::SetTerminalHeight(uint64_t term_height) {
415 const uint32_t idx = ePropertyTerminalHeight;
416 const bool success = SetPropertyAtIndex(idx, term_height);
417
418 if (auto handler_sp = m_io_handler_stack.Top())
419 handler_sp->TerminalSizeChanged();
420
421 {
422 std::lock_guard<std::mutex> guard(m_statusline_mutex);
423 if (m_statusline)
424 m_statusline->TerminalSizeChanged();
425 }
426
427 return success;
428}
429
431 const uint32_t idx = ePropertyUseExternalEditor;
433 idx, g_debugger_properties[idx].default_uint_value != 0);
434}
435
437 const uint32_t idx = ePropertyUseExternalEditor;
438 return SetPropertyAtIndex(idx, b);
439}
440
441llvm::StringRef Debugger::GetExternalEditor() const {
442 const uint32_t idx = ePropertyExternalEditor;
444 idx, g_debugger_properties[idx].default_cstr_value);
445}
446
447bool Debugger::SetExternalEditor(llvm::StringRef editor) {
448 const uint32_t idx = ePropertyExternalEditor;
449 return SetPropertyAtIndex(idx, editor);
450}
451
453 const uint32_t idx = ePropertyUseColor;
455 idx, g_debugger_properties[idx].default_uint_value != 0);
456}
457
459 const uint32_t idx = ePropertyUseColor;
460 bool ret = SetPropertyAtIndex(idx, b);
461
464 return ret;
465}
466
468 const uint32_t idx = ePropertyShowProgress;
470 idx, g_debugger_properties[idx].default_uint_value != 0);
471}
472
473bool Debugger::SetShowProgress(bool show_progress) {
474 const uint32_t idx = ePropertyShowProgress;
475 return SetPropertyAtIndex(idx, show_progress);
476}
477
478llvm::StringRef Debugger::GetShowProgressAnsiPrefix() const {
479 const uint32_t idx = ePropertyShowProgressAnsiPrefix;
481 idx, g_debugger_properties[idx].default_cstr_value);
482}
483
484llvm::StringRef Debugger::GetShowProgressAnsiSuffix() const {
485 const uint32_t idx = ePropertyShowProgressAnsiSuffix;
487 idx, g_debugger_properties[idx].default_cstr_value);
488}
489
491 const uint32_t idx = ePropertyShowStatusline;
493 idx, g_debugger_properties[idx].default_uint_value != 0);
494}
495
497 constexpr uint32_t idx = ePropertyStatuslineFormat;
499}
500
502 constexpr uint32_t idx = ePropertyStatuslineFormat;
503 bool ret = SetPropertyAtIndex(idx, format);
505 return ret;
506}
507
508llvm::StringRef Debugger::GetSeparator() const {
509 constexpr uint32_t idx = ePropertySeparator;
511 idx, g_debugger_properties[idx].default_cstr_value);
512}
513
514llvm::StringRef Debugger::GetDisabledAnsiPrefix() const {
515 const uint32_t idx = ePropertyShowDisabledAnsiPrefix;
517 idx, g_debugger_properties[idx].default_cstr_value);
518}
519
520llvm::StringRef Debugger::GetDisabledAnsiSuffix() const {
521 const uint32_t idx = ePropertyShowDisabledAnsiSuffix;
523 idx, g_debugger_properties[idx].default_cstr_value);
524}
525
526bool Debugger::SetSeparator(llvm::StringRef s) {
527 constexpr uint32_t idx = ePropertySeparator;
528 bool ret = SetPropertyAtIndex(idx, s);
530 return ret;
531}
532
534 const uint32_t idx = ePropertyShowAutosuggestion;
536 idx, g_debugger_properties[idx].default_uint_value != 0);
537}
538
540 const uint32_t idx = ePropertyShowAutosuggestionAnsiPrefix;
542 idx, g_debugger_properties[idx].default_cstr_value);
543}
544
546 const uint32_t idx = ePropertyShowAutosuggestionAnsiSuffix;
548 idx, g_debugger_properties[idx].default_cstr_value);
549}
550
551llvm::StringRef Debugger::GetRegexMatchAnsiPrefix() const {
552 const uint32_t idx = ePropertyShowRegexMatchAnsiPrefix;
554 idx, g_debugger_properties[idx].default_cstr_value);
555}
556
557llvm::StringRef Debugger::GetRegexMatchAnsiSuffix() const {
558 const uint32_t idx = ePropertyShowRegexMatchAnsiSuffix;
560 idx, g_debugger_properties[idx].default_cstr_value);
561}
562
564 const uint32_t idx = ePropertyShowDontUsePoHint;
566 idx, g_debugger_properties[idx].default_uint_value != 0);
567}
568
570 const uint32_t idx = ePropertyUseSourceCache;
572 idx, g_debugger_properties[idx].default_uint_value != 0);
573}
574
576 const uint32_t idx = ePropertyUseSourceCache;
577 bool ret = SetPropertyAtIndex(idx, b);
578 if (!ret) {
579 m_source_file_cache.Clear();
580 }
581 return ret;
582}
584 const uint32_t idx = ePropertyHighlightSource;
586 idx, g_debugger_properties[idx].default_uint_value != 0);
587}
588
590 const uint32_t idx = ePropertyStopShowColumn;
592 idx, static_cast<lldb::StopShowColumn>(
593 g_debugger_properties[idx].default_uint_value));
594}
595
597 const uint32_t idx = ePropertyStopShowColumnAnsiPrefix;
599 idx, g_debugger_properties[idx].default_cstr_value);
600}
601
603 const uint32_t idx = ePropertyStopShowColumnAnsiSuffix;
605 idx, g_debugger_properties[idx].default_cstr_value);
606}
607
609 const uint32_t idx = ePropertyStopShowLineMarkerAnsiPrefix;
611 idx, g_debugger_properties[idx].default_cstr_value);
612}
613
615 const uint32_t idx = ePropertyStopShowLineMarkerAnsiSuffix;
617 idx, g_debugger_properties[idx].default_cstr_value);
618}
619
620uint64_t Debugger::GetStopSourceLineCount(bool before) const {
621 const uint32_t idx =
622 before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter;
624 idx, g_debugger_properties[idx].default_uint_value);
625}
626
628 const uint32_t idx = ePropertyStopDisassemblyDisplay;
630 idx, static_cast<lldb::StopDisassemblyType>(
631 g_debugger_properties[idx].default_uint_value));
632}
633
635 const uint32_t idx = ePropertyStopDisassemblyCount;
637 idx, g_debugger_properties[idx].default_uint_value);
638}
639
641 const uint32_t idx = ePropertyAutoOneLineSummaries;
643 idx, g_debugger_properties[idx].default_uint_value != 0);
644}
645
647 const uint32_t idx = ePropertyEscapeNonPrintables;
649 idx, g_debugger_properties[idx].default_uint_value != 0);
650}
651
653 const uint32_t idx = ePropertyAutoIndent;
655 idx, g_debugger_properties[idx].default_uint_value != 0);
656}
657
659 const uint32_t idx = ePropertyAutoIndent;
660 return SetPropertyAtIndex(idx, b);
661}
662
664 const uint32_t idx = ePropertyPrintDecls;
666 idx, g_debugger_properties[idx].default_uint_value != 0);
667}
668
670 const uint32_t idx = ePropertyPrintDecls;
671 return SetPropertyAtIndex(idx, b);
672}
673
674uint64_t Debugger::GetTabSize() const {
675 const uint32_t idx = ePropertyTabSize;
677 idx, g_debugger_properties[idx].default_uint_value);
678}
679
680bool Debugger::SetTabSize(uint64_t tab_size) {
681 const uint32_t idx = ePropertyTabSize;
682 return SetPropertyAtIndex(idx, tab_size);
683}
684
686 const uint32_t idx = ePropertyDWIMPrintVerbosity;
688 idx, static_cast<lldb::DWIMPrintVerbosity>(
689 g_debugger_properties[idx].default_uint_value != 0));
690}
691
693 const uint32_t idx = ePropertyShowInlineDiagnostics;
695 idx, g_debugger_properties[idx].default_uint_value);
696}
697
699 const uint32_t idx = ePropertyShowInlineDiagnostics;
700 return SetPropertyAtIndex(idx, b);
701}
702
703#pragma mark Debugger
704
705// const DebuggerPropertiesSP &
706// Debugger::GetSettings() const
707//{
708// return m_properties_sp;
709//}
710//
711
713 assert(g_debugger_list_ptr == nullptr &&
714 "Debugger::Initialize called more than once!");
715 g_debugger_list_mutex_ptr = new std::recursive_mutex();
717 g_thread_pool = new llvm::DefaultThreadPool(llvm::optimal_concurrency());
718 g_load_plugin_callback = load_plugin_callback;
719}
720
722 assert(g_debugger_list_ptr &&
723 "Debugger::Terminate called without a matching Debugger::Initialize!");
724
726 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
727 for (const auto &debugger : *g_debugger_list_ptr)
728 debugger->HandleDestroyCallback();
729 }
730
731 if (g_thread_pool) {
732 // The destructor will wait for all the threads to complete.
733 delete g_thread_pool;
734 }
735
737 // Clear our global list of debugger objects
738 {
739 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
740 for (const auto &debugger : *g_debugger_list_ptr)
741 debugger->Clear();
742 g_debugger_list_ptr->clear();
743 }
744 }
745}
746
748
750
753 llvm::sys::DynamicLibrary dynlib =
754 g_load_plugin_callback(shared_from_this(), spec, error);
755 if (dynlib.isValid()) {
756 m_loaded_plugins.push_back(dynlib);
757 return true;
758 }
759 } else {
760 // The g_load_plugin_callback is registered in SBDebugger::Initialize() and
761 // if the public API layer isn't available (code is linking against all of
762 // the internal LLDB static libraries), then we can't load plugins
763 error = Status::FromErrorString("Public API layer is not available");
764 }
765 return false;
766}
767
769LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft,
770 llvm::StringRef path) {
772
773 static constexpr llvm::StringLiteral g_dylibext(".dylib");
774 static constexpr llvm::StringLiteral g_solibext(".so");
775
776 if (!baton)
778
779 Debugger *debugger = (Debugger *)baton;
780
781 namespace fs = llvm::sys::fs;
782 // If we have a regular file, a symbolic link or unknown file type, try and
783 // process the file. We must handle unknown as sometimes the directory
784 // enumeration might be enumerating a file system that doesn't have correct
785 // file type information.
786 if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file ||
787 ft == fs::file_type::type_unknown) {
788 FileSpec plugin_file_spec(path);
789 FileSystem::Instance().Resolve(plugin_file_spec);
790
791 if (plugin_file_spec.GetFileNameExtension() != g_dylibext &&
792 plugin_file_spec.GetFileNameExtension() != g_solibext) {
794 }
795
796 Status plugin_load_error;
797 debugger->LoadPlugin(plugin_file_spec, plugin_load_error);
798
800 } else if (ft == fs::file_type::directory_file ||
801 ft == fs::file_type::symlink_file ||
802 ft == fs::file_type::type_unknown) {
803 // Try and recurse into anything that a directory or symbolic link. We must
804 // also do this for unknown as sometimes the directory enumeration might be
805 // enumerating a file system that doesn't have correct file type
806 // information.
808 }
809
811}
812
814 const bool find_directories = true;
815 const bool find_files = true;
816 const bool find_other = true;
817 char dir_path[PATH_MAX];
818 if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) {
819 if (FileSystem::Instance().Exists(dir_spec) &&
820 dir_spec.GetPath(dir_path, sizeof(dir_path))) {
821 FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
822 find_files, find_other,
823 LoadPluginCallback, this);
824 }
825 }
826
827 if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) {
828 if (FileSystem::Instance().Exists(dir_spec) &&
829 dir_spec.GetPath(dir_path, sizeof(dir_path))) {
830 FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
831 find_files, find_other,
832 LoadPluginCallback, this);
833 }
834 }
835
837}
838
840 void *baton) {
843 helper([](lldb_private::telemetry::DebuggerInfo *entry) {
845 });
846 DebuggerSP debugger_sp(new Debugger(log_callback, baton));
847 helper.SetDebugger(debugger_sp.get());
848
850 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
851 g_debugger_list_ptr->push_back(debugger_sp);
852 }
853 debugger_sp->InstanceInitialize();
854 return debugger_sp;
855}
856
862
864 const lldb::user_id_t user_id = GetID();
865 // Invoke and remove all the callbacks in an FIFO order. Callbacks which are
866 // added during this loop will be appended, invoked and then removed last.
867 // Callbacks which are removed during this loop will not be invoked.
868 while (true) {
869 DestroyCallbackInfo callback_info;
870 {
871 std::lock_guard<std::mutex> guard(m_destroy_callback_mutex);
872 if (m_destroy_callbacks.empty())
873 break;
874 // Pop the first item in the list
875 callback_info = m_destroy_callbacks.front();
877 }
878 // Call the destroy callback with user id and baton
879 callback_info.callback(user_id, callback_info.baton);
880 }
881}
882
883void Debugger::Destroy(DebuggerSP &debugger_sp) {
884 if (!debugger_sp)
885 return;
886
887 debugger_sp->HandleDestroyCallback();
888 CommandInterpreter &cmd_interpreter = debugger_sp->GetCommandInterpreter();
889
890 if (cmd_interpreter.GetSaveSessionOnQuit()) {
891 CommandReturnObject result(debugger_sp->GetUseColor());
892 cmd_interpreter.SaveTranscript(result);
893 if (result.Succeeded())
894 (*debugger_sp->GetAsyncOutputStream())
895 << result.GetOutputString() << '\n';
896 else
897 (*debugger_sp->GetAsyncErrorStream()) << result.GetErrorString() << '\n';
898 }
899
900 debugger_sp->Clear();
901
903 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
904 DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
905 for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
906 if ((*pos).get() == debugger_sp.get()) {
907 g_debugger_list_ptr->erase(pos);
908 return;
909 }
910 }
911 }
912}
913
915Debugger::FindDebuggerWithInstanceName(llvm::StringRef instance_name) {
917 return DebuggerSP();
918
919 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
920 for (const DebuggerSP &debugger_sp : *g_debugger_list_ptr) {
921 if (!debugger_sp)
922 continue;
923
924 if (llvm::StringRef(debugger_sp->GetInstanceName()) == instance_name)
925 return debugger_sp;
926 }
927 return DebuggerSP();
928}
929
931 TargetSP target_sp;
933 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
934 DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
935 for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
936 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID(pid);
937 if (target_sp)
938 break;
939 }
940 }
941 return target_sp;
942}
943
945 TargetSP target_sp;
947 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
948 DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
949 for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
950 target_sp = (*pos)->GetTargetList().FindTargetWithProcess(process);
951 if (target_sp)
952 break;
953 }
954 }
955 return target_sp;
956}
957
959 static constexpr llvm::StringLiteral class_name("lldb.debugger");
960 return class_name;
961}
962
964 : UserID(g_unique_id++),
965 Properties(std::make_shared<OptionValueProperties>()),
966 m_input_file_sp(std::make_shared<NativeFile>(stdin, NativeFile::Unowned)),
967 m_output_stream_sp(std::make_shared<LockableStreamFile>(
968 stdout, NativeFile::Unowned, m_output_mutex)),
969 m_error_stream_sp(std::make_shared<LockableStreamFile>(
970 stderr, NativeFile::Unowned, m_output_mutex)),
971 m_broadcaster_manager_sp(BroadcasterManager::MakeBroadcasterManager()),
973 m_listener_sp(Listener::MakeListener("lldb.Debugger")),
976 std::make_unique<CommandInterpreter>(*this, false)),
978 m_instance_name(llvm::formatv("debugger_{0}", GetID()).str()),
980 m_sync_broadcaster(nullptr, "lldb.debugger.sync"),
984 // Initialize the debugger properties as early as possible as other parts of
985 // LLDB will start querying them during construction.
986 m_collection_sp->Initialize(g_debugger_properties);
987 m_collection_sp->AppendProperty(
988 "target", "Settings specify to debugging targets.", true,
990 m_collection_sp->AppendProperty(
991 "platform", "Platform settings.", true,
993 m_collection_sp->AppendProperty(
994 "symbols", "Symbol lookup and cache settings.", true,
996 m_collection_sp->AppendProperty(
997 LanguageProperties::GetSettingName(), "Language settings.", true,
1000 m_collection_sp->AppendProperty(
1001 "interpreter",
1002 "Settings specify to the debugger's command interpreter.", true,
1003 m_command_interpreter_up->GetValueProperties());
1004 }
1005 if (log_callback)
1007 std::make_shared<CallbackLogHandler>(log_callback, baton);
1008 m_command_interpreter_up->Initialize();
1009 // Always add our default platform to the platform list
1010 PlatformSP default_platform_sp(Platform::GetHostPlatform());
1011 assert(default_platform_sp);
1012 m_platform_list.Append(default_platform_sp, true);
1013
1014 // Create the dummy target.
1015 {
1017 if (!arch.IsValid())
1018 arch = HostInfo::GetArchitecture();
1019 assert(arch.IsValid() && "No valid default or host archspec");
1020 const bool is_dummy_target = true;
1021 m_dummy_target_sp.reset(
1022 new Target(*this, arch, default_platform_sp, is_dummy_target));
1023 }
1024 assert(m_dummy_target_sp.get() && "Couldn't construct dummy target?");
1025
1026 OptionValueUInt64 *term_width =
1027 m_collection_sp->GetPropertyAtIndexAsOptionValueUInt64(
1028 ePropertyTerminalWidth);
1029 term_width->SetMinimumValue(10);
1030
1031 OptionValueUInt64 *term_height =
1032 m_collection_sp->GetPropertyAtIndexAsOptionValueUInt64(
1033 ePropertyTerminalHeight);
1034 term_height->SetMinimumValue(10);
1035
1036 // Turn off use-color if this is a dumb terminal.
1037 const char *term = getenv("TERM");
1038 auto disable_color = [&]() {
1039 SetUseColor(false);
1040 SetSeparator("| ");
1041 };
1042
1043 if (term && !strcmp(term, "dumb"))
1044 disable_color();
1045 // Turn off use-color if we don't write to a terminal with color support.
1046 if (!GetOutputFileSP()->GetIsTerminalWithColors())
1047 disable_color();
1048
1049 if (Diagnostics::Enabled()) {
1051 [this](const FileSpec &dir) -> llvm::Error {
1052 for (auto &entry : m_stream_handlers) {
1053 llvm::StringRef log_path = entry.first();
1054 llvm::StringRef file_name = llvm::sys::path::filename(log_path);
1055 FileSpec destination = dir.CopyByAppendingPathComponent(file_name);
1056 std::error_code ec =
1057 llvm::sys::fs::copy_file(log_path, destination.GetPath());
1058 if (ec)
1059 return llvm::errorCodeToError(ec);
1060 }
1061 return llvm::Error::success();
1062 });
1063 }
1064
1065#if defined(_WIN32) && defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
1066 // Enabling use of ANSI color codes because LLDB is using them to highlight
1067 // text.
1068 llvm::sys::Process::UseANSIEscapeCodes(true);
1069#endif
1070}
1071
1073
1075 // Make sure we call this function only once. With the C++ global destructor
1076 // chain having a list of debuggers and with code that can be running on
1077 // other threads, we need to ensure this doesn't happen multiple times.
1078 //
1079 // The following functions call Debugger::Clear():
1080 // Debugger::~Debugger();
1081 // static void Debugger::Destroy(lldb::DebuggerSP &debugger_sp);
1082 // static void Debugger::Terminate();
1083 llvm::call_once(m_clear_once, [this]() {
1086 assert(this == info->debugger);
1087 (void)this;
1088 info->is_exit_entry = true;
1089 },
1090 this);
1094 m_listener_sp->Clear();
1095 for (TargetSP target_sp : m_target_list.Targets()) {
1096 if (target_sp) {
1097 if (ProcessSP process_sp = target_sp->GetProcessSP())
1098 process_sp->Finalize(false /* not destructing */);
1099 target_sp->Destroy();
1100 }
1101 }
1102 m_broadcaster_manager_sp->Clear();
1103
1104 // Close the input file _before_ we close the input read communications
1105 // class as it does NOT own the input file, our m_input_file does.
1106 m_terminal_state.Clear();
1107 GetInputFile().Close();
1108
1109 m_command_interpreter_up->Clear();
1110
1113 });
1114}
1115
1117 return !m_command_interpreter_up->GetSynchronous();
1118}
1119
1120void Debugger::SetAsyncExecution(bool async_execution) {
1121 m_command_interpreter_up->SetSynchronous(!async_execution);
1122}
1123
1124static inline int OpenPipe(int fds[2], std::size_t size) {
1125#ifdef _WIN32
1126 return _pipe(fds, size, O_BINARY);
1127#else
1128 (void)size;
1129 return pipe(fds);
1130#endif
1131}
1132
1134 Status result;
1135 enum PIPES { READ, WRITE }; // Indexes for the read and write fds
1136 int fds[2] = {-1, -1};
1137
1138 if (data == nullptr) {
1139 result = Status::FromErrorString("String data is null");
1140 return result;
1141 }
1142
1143 size_t size = strlen(data);
1144 if (size == 0) {
1145 result = Status::FromErrorString("String data is empty");
1146 return result;
1147 }
1148
1149 if (OpenPipe(fds, size) != 0) {
1150 result = Status::FromErrorString(
1151 "can't create pipe file descriptors for LLDB commands");
1152 return result;
1153 }
1154
1155 int r = write(fds[WRITE], data, size);
1156 (void)r;
1157 // Close the write end of the pipe, so that the command interpreter will exit
1158 // when it consumes all the data.
1159 llvm::sys::Process::SafelyCloseFileDescriptor(fds[WRITE]);
1160
1161 // Open the read file descriptor as a FILE * that we can return as an input
1162 // handle.
1163 FILE *commands_file = fdopen(fds[READ], "rb");
1164 if (commands_file == nullptr) {
1166 "fdopen(%i, \"rb\") failed (errno = %i) "
1167 "when trying to open LLDB commands pipe",
1168 fds[READ], errno);
1169 llvm::sys::Process::SafelyCloseFileDescriptor(fds[READ]);
1170 return result;
1171 }
1172
1173 SetInputFile((FileSP)std::make_shared<NativeFile>(commands_file, true));
1174 return result;
1175}
1176
1178 assert(file_sp && file_sp->IsValid());
1179 m_input_file_sp = std::move(file_sp);
1180 // Save away the terminal state if that is relevant, so that we can restore
1181 // it in RestoreInputState.
1183}
1184
1186 assert(file_sp && file_sp->IsValid());
1188 std::make_shared<LockableStreamFile>(file_sp, m_output_mutex);
1189}
1190
1192 assert(file_sp && file_sp->IsValid());
1194 std::make_shared<LockableStreamFile>(file_sp, m_output_mutex);
1195}
1196
1198 {
1199 std::lock_guard<std::mutex> guard(m_statusline_mutex);
1200 if (m_statusline)
1201 m_statusline->Disable();
1202 }
1203 int fd = GetInputFile().GetDescriptor();
1204 if (fd != File::kInvalidDescriptor)
1205 m_terminal_state.Save(fd, true);
1206}
1207
1209 m_terminal_state.Restore();
1210 {
1211 std::lock_guard<std::mutex> guard(m_statusline_mutex);
1212 if (m_statusline)
1213 m_statusline->Enable();
1214 }
1215}
1216
1218 std::lock_guard<std::mutex> guard(m_statusline_mutex);
1219 if (m_statusline)
1220 m_statusline->Redraw(update);
1221}
1222
1224 bool adopt_selected = true;
1225 ExecutionContextRef exe_ctx_ref(GetSelectedTarget().get(), adopt_selected);
1226 return ExecutionContext(exe_ctx_ref);
1227}
1228
1230 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1231 IOHandlerSP reader_sp(m_io_handler_stack.Top());
1232 if (reader_sp)
1233 reader_sp->Interrupt();
1234}
1235
1237 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1238 IOHandlerSP reader_sp(m_io_handler_stack.Top());
1239 if (reader_sp)
1240 reader_sp->GotEOF();
1241}
1242
1244 // The bottom input reader should be the main debugger input reader. We do
1245 // not want to close that one here.
1246 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1247 while (m_io_handler_stack.GetSize() > 1) {
1248 IOHandlerSP reader_sp(m_io_handler_stack.Top());
1249 if (reader_sp)
1250 PopIOHandler(reader_sp);
1251 }
1252}
1253
1255 IOHandlerSP reader_sp = m_io_handler_stack.Top();
1256 while (true) {
1257 if (!reader_sp)
1258 break;
1259
1260 reader_sp->Run();
1261 {
1262 std::lock_guard<std::recursive_mutex> guard(
1264
1265 // Remove all input readers that are done from the top of the stack
1266 while (true) {
1267 IOHandlerSP top_reader_sp = m_io_handler_stack.Top();
1268 if (top_reader_sp && top_reader_sp->GetIsDone())
1269 PopIOHandler(top_reader_sp);
1270 else
1271 break;
1272 }
1273 reader_sp = m_io_handler_stack.Top();
1274 }
1275 }
1277}
1278
1280 std::lock_guard<std::recursive_mutex> guard(m_io_handler_synchronous_mutex);
1281
1282 PushIOHandler(reader_sp);
1283 IOHandlerSP top_reader_sp = reader_sp;
1284
1285 while (top_reader_sp) {
1286 top_reader_sp->Run();
1287
1288 // Don't unwind past the starting point.
1289 if (top_reader_sp.get() == reader_sp.get()) {
1290 if (PopIOHandler(reader_sp))
1291 break;
1292 }
1293
1294 // If we pushed new IO handlers, pop them if they're done or restart the
1295 // loop to run them if they're not.
1296 while (true) {
1297 top_reader_sp = m_io_handler_stack.Top();
1298 if (top_reader_sp && top_reader_sp->GetIsDone()) {
1299 PopIOHandler(top_reader_sp);
1300 // Don't unwind past the starting point.
1301 if (top_reader_sp.get() == reader_sp.get())
1302 return;
1303 } else {
1304 break;
1305 }
1306 }
1307 }
1308}
1309
1311 return m_io_handler_stack.IsTop(reader_sp);
1312}
1313
1315 IOHandler::Type second_top_type) {
1316 return m_io_handler_stack.CheckTopIOHandlerTypes(top_type, second_top_type);
1317}
1318
1319void Debugger::PrintAsync(const char *s, size_t len, bool is_stdout) {
1320 bool printed = m_io_handler_stack.PrintAsync(s, len, is_stdout);
1321 if (!printed) {
1322 LockableStreamFileSP stream_sp =
1324 LockedStreamFile locked_stream = stream_sp->Lock();
1325 locked_stream.Write(s, len);
1326 }
1327}
1328
1330 return m_io_handler_stack.GetTopIOHandlerControlSequence(ch);
1331}
1332
1334 return m_io_handler_stack.GetTopIOHandlerCommandPrefix();
1335}
1336
1338 return m_io_handler_stack.GetTopIOHandlerHelpPrologue();
1339}
1340
1342 return PopIOHandler(reader_sp);
1343}
1344
1346 bool cancel_top_handler) {
1347 PushIOHandler(reader_sp, cancel_top_handler);
1348}
1349
1352 LockableStreamFileSP &err) {
1353 // Before an IOHandler runs, it must have in/out/err streams. This function
1354 // is called when one ore more of the streams are nullptr. We use the top
1355 // input reader's in/out/err streams, or fall back to the debugger file
1356 // handles, or we fall back onto stdin/stdout/stderr as a last resort.
1357
1358 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1359 IOHandlerSP top_reader_sp(m_io_handler_stack.Top());
1360 // If no STDIN has been set, then set it appropriately
1361 if (!in || !in->IsValid()) {
1362 if (top_reader_sp)
1363 in = top_reader_sp->GetInputFileSP();
1364 else
1365 in = GetInputFileSP();
1366 // If there is nothing, use stdin
1367 if (!in)
1368 in = std::make_shared<NativeFile>(stdin, NativeFile::Unowned);
1369 }
1370 // If no STDOUT has been set, then set it appropriately
1371 if (!out || !out->GetUnlockedFile().IsValid()) {
1372 if (top_reader_sp)
1373 out = top_reader_sp->GetOutputStreamFileSP();
1374 else
1375 out = GetOutputStreamSP();
1376 // If there is nothing, use stdout
1377 if (!out)
1378 out = std::make_shared<LockableStreamFile>(stdout, NativeFile::Unowned,
1380 }
1381 // If no STDERR has been set, then set it appropriately
1382 if (!err || !err->GetUnlockedFile().IsValid()) {
1383 if (top_reader_sp)
1384 err = top_reader_sp->GetErrorStreamFileSP();
1385 else
1386 err = GetErrorStreamSP();
1387 // If there is nothing, use stderr
1388 if (!err)
1389 err = std::make_shared<LockableStreamFile>(stderr, NativeFile::Unowned,
1391 }
1392}
1393
1395 bool cancel_top_handler) {
1396 if (!reader_sp)
1397 return;
1398
1399 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1400
1401 // Get the current top input reader...
1402 IOHandlerSP top_reader_sp(m_io_handler_stack.Top());
1403
1404 // Don't push the same IO handler twice...
1405 if (reader_sp == top_reader_sp)
1406 return;
1407
1408 // Push our new input reader
1409 m_io_handler_stack.Push(reader_sp);
1410 reader_sp->Activate();
1411
1412 // Interrupt the top input reader to it will exit its Run() function and let
1413 // this new input reader take over
1414 if (top_reader_sp) {
1415 top_reader_sp->Deactivate();
1416 if (cancel_top_handler)
1417 top_reader_sp->Cancel();
1418 }
1419}
1420
1421bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) {
1422 if (!pop_reader_sp)
1423 return false;
1424
1425 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1426
1427 // The reader on the stop of the stack is done, so let the next read on the
1428 // stack refresh its prompt and if there is one...
1429 if (m_io_handler_stack.IsEmpty())
1430 return false;
1431
1432 IOHandlerSP reader_sp(m_io_handler_stack.Top());
1433
1434 if (pop_reader_sp != reader_sp)
1435 return false;
1436
1437 reader_sp->Deactivate();
1438 reader_sp->Cancel();
1439 m_io_handler_stack.Pop();
1440
1441 reader_sp = m_io_handler_stack.Top();
1442 if (reader_sp)
1443 reader_sp->Activate();
1444
1445 return true;
1446}
1447
1449 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1450 IOHandlerSP reader_sp(m_io_handler_stack.Top());
1451 if (reader_sp)
1452 reader_sp->Refresh();
1453}
1454
1456 return std::make_unique<StreamAsynchronousIO>(*this,
1458}
1459
1461 return std::make_unique<StreamAsynchronousIO>(*this,
1463}
1464
1466 std::lock_guard<std::mutex> guard(m_interrupt_mutex);
1468}
1469
1471 std::lock_guard<std::mutex> guard(m_interrupt_mutex);
1472 if (m_interrupt_requested > 0)
1474}
1475
1477 // This is the one we should call internally. This will return true either
1478 // if there's a debugger interrupt and we aren't on the IOHandler thread,
1479 // or if we are on the IOHandler thread and there's a CommandInterpreter
1480 // interrupt.
1482 std::lock_guard<std::mutex> guard(m_interrupt_mutex);
1483 return m_interrupt_requested != 0;
1484 }
1486}
1487
1489 std::string function_name, const llvm::formatv_object_base &payload)
1490 : m_function_name(std::move(function_name)),
1491 m_interrupt_time(std::chrono::system_clock::now()),
1492 m_thread_id(llvm::get_threadid()) {
1493 llvm::raw_string_ostream desc(m_description);
1494 desc << payload << "\n";
1495}
1496
1498 // For now, just log the description:
1499 Log *log = GetLog(LLDBLog::Host);
1500 LLDB_LOG(log, "Interruption: {0}", report.m_description);
1501}
1502
1504 DebuggerList result;
1506 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1507 for (auto debugger_sp : *g_debugger_list_ptr) {
1508 if (debugger_sp->InterruptRequested())
1509 result.push_back(debugger_sp);
1510 }
1511 }
1512 return result;
1513}
1514
1517 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1518 return g_debugger_list_ptr->size();
1519 }
1520 return 0;
1521}
1522
1524 DebuggerSP debugger_sp;
1525
1527 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1528 if (index < g_debugger_list_ptr->size())
1529 debugger_sp = g_debugger_list_ptr->at(index);
1530 }
1531
1532 return debugger_sp;
1533}
1534
1536 DebuggerSP debugger_sp;
1537
1539 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1540 DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
1541 for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
1542 if ((*pos)->GetID() == id) {
1543 debugger_sp = *pos;
1544 break;
1545 }
1546 }
1547 }
1548 return debugger_sp;
1549}
1550
1552 const SymbolContext *sc,
1553 const SymbolContext *prev_sc,
1554 const ExecutionContext *exe_ctx,
1555 const Address *addr, Stream &s) {
1556 FormatEntity::Entry format_entry;
1557
1558 if (format == nullptr) {
1559 if (exe_ctx != nullptr && exe_ctx->HasTargetScope()) {
1560 format_entry =
1562 format = &format_entry;
1563 }
1564 if (format == nullptr) {
1565 FormatEntity::Parse("${addr}: ", format_entry);
1566 format = &format_entry;
1567 }
1568 }
1569 bool function_changed = false;
1570 bool initial_function = false;
1571 if (prev_sc && (prev_sc->function || prev_sc->symbol)) {
1572 if (sc && (sc->function || sc->symbol)) {
1573 if (prev_sc->symbol && sc->symbol) {
1574 if (!sc->symbol->Compare(prev_sc->symbol->GetName(),
1575 prev_sc->symbol->GetType())) {
1576 function_changed = true;
1577 }
1578 } else if (prev_sc->function && sc->function) {
1579 if (prev_sc->function->GetMangled() != sc->function->GetMangled()) {
1580 function_changed = true;
1581 }
1582 }
1583 }
1584 }
1585 // The first context on a list of instructions will have a prev_sc that has
1586 // no Function or Symbol -- if SymbolContext had an IsValid() method, it
1587 // would return false. But we do get a prev_sc pointer.
1588 if ((sc && (sc->function || sc->symbol)) && prev_sc &&
1589 (prev_sc->function == nullptr && prev_sc->symbol == nullptr)) {
1590 initial_function = true;
1591 }
1592 return FormatEntity::Format(*format, s, sc, exe_ctx, addr, nullptr,
1593 function_changed, initial_function);
1594}
1595
1596void Debugger::AssertCallback(llvm::StringRef message,
1597 llvm::StringRef backtrace,
1598 llvm::StringRef prompt) {
1599 Debugger::ReportError(llvm::formatv("{0}\n{1}{2}\n{3}", message, backtrace,
1600 GetVersion(), prompt)
1601 .str());
1602}
1603
1605 void *baton) {
1606 // For simplicity's sake, I am not going to deal with how to close down any
1607 // open logging streams, I just redirect everything from here on out to the
1608 // callback.
1610 std::make_shared<CallbackLogHandler>(log_callback, baton);
1611}
1612
1614 lldb_private::DebuggerDestroyCallback destroy_callback, void *baton) {
1615 std::lock_guard<std::mutex> guard(m_destroy_callback_mutex);
1616 m_destroy_callbacks.clear();
1618 m_destroy_callbacks.emplace_back(token, destroy_callback, baton);
1619}
1620
1622 lldb_private::DebuggerDestroyCallback destroy_callback, void *baton) {
1623 std::lock_guard<std::mutex> guard(m_destroy_callback_mutex);
1625 m_destroy_callbacks.emplace_back(token, destroy_callback, baton);
1626 return token;
1627}
1628
1630 std::lock_guard<std::mutex> guard(m_destroy_callback_mutex);
1631 for (auto it = m_destroy_callbacks.begin(); it != m_destroy_callbacks.end();
1632 ++it) {
1633 if (it->token == token) {
1634 m_destroy_callbacks.erase(it);
1635 return true;
1636 }
1637 }
1638 return false;
1639}
1640
1641static void PrivateReportProgress(Debugger &debugger, uint64_t progress_id,
1642 std::string title, std::string details,
1643 uint64_t completed, uint64_t total,
1644 bool is_debugger_specific,
1645 uint32_t progress_broadcast_bit) {
1646 // Only deliver progress events if we have any progress listeners.
1647 if (!debugger.GetBroadcaster().EventTypeHasListeners(progress_broadcast_bit))
1648 return;
1649
1650 EventSP event_sp(new Event(
1651 progress_broadcast_bit,
1652 new ProgressEventData(progress_id, std::move(title), std::move(details),
1653 completed, total, is_debugger_specific)));
1654 debugger.GetBroadcaster().BroadcastEvent(event_sp);
1655}
1656
1657void Debugger::ReportProgress(uint64_t progress_id, std::string title,
1658 std::string details, uint64_t completed,
1659 uint64_t total,
1660 std::optional<lldb::user_id_t> debugger_id,
1661 uint32_t progress_broadcast_bit) {
1662 // Check if this progress is for a specific debugger.
1663 if (debugger_id) {
1664 // It is debugger specific, grab it and deliver the event if the debugger
1665 // still exists.
1666 DebuggerSP debugger_sp = FindDebuggerWithID(*debugger_id);
1667 if (debugger_sp)
1668 PrivateReportProgress(*debugger_sp, progress_id, std::move(title),
1669 std::move(details), completed, total,
1670 /*is_debugger_specific*/ true,
1671 progress_broadcast_bit);
1672 return;
1673 }
1674 // The progress event is not debugger specific, iterate over all debuggers
1675 // and deliver a progress event to each one.
1677 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1678 DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
1679 for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos)
1680 PrivateReportProgress(*(*pos), progress_id, title, details, completed,
1681 total, /*is_debugger_specific*/ false,
1682 progress_broadcast_bit);
1683 }
1684}
1685
1686static void PrivateReportDiagnostic(Debugger &debugger, Severity severity,
1687 std::string message,
1688 bool debugger_specific) {
1689 uint32_t event_type = 0;
1690 switch (severity) {
1691 case eSeverityInfo:
1692 assert(false && "eSeverityInfo should not be broadcast");
1693 return;
1694 case eSeverityWarning:
1695 event_type = lldb::eBroadcastBitWarning;
1696 break;
1697 case eSeverityError:
1698 event_type = lldb::eBroadcastBitError;
1699 break;
1700 }
1701
1702 Broadcaster &broadcaster = debugger.GetBroadcaster();
1703 if (!broadcaster.EventTypeHasListeners(event_type)) {
1704 // Diagnostics are too important to drop. If nobody is listening, print the
1705 // diagnostic directly to the debugger's error stream.
1706 DiagnosticEventData event_data(severity, std::move(message),
1707 debugger_specific);
1708 event_data.Dump(debugger.GetAsyncErrorStream().get());
1709 return;
1710 }
1711 EventSP event_sp = std::make_shared<Event>(
1712 event_type,
1713 new DiagnosticEventData(severity, std::move(message), debugger_specific));
1714 broadcaster.BroadcastEvent(event_sp);
1715}
1716
1717void Debugger::ReportDiagnosticImpl(Severity severity, std::string message,
1718 std::optional<lldb::user_id_t> debugger_id,
1719 std::once_flag *once) {
1720 auto ReportDiagnosticLambda = [&]() {
1721 // Always log diagnostics to the system log.
1722 Host::SystemLog(severity, message);
1723
1724 // The diagnostic subsystem is optional but we still want to broadcast
1725 // events when it's disabled.
1727 Diagnostics::Instance().Report(message);
1728
1729 // We don't broadcast info events.
1730 if (severity == lldb::eSeverityInfo)
1731 return;
1732
1733 // Check if this diagnostic is for a specific debugger.
1734 if (debugger_id) {
1735 // It is debugger specific, grab it and deliver the event if the debugger
1736 // still exists.
1737 DebuggerSP debugger_sp = FindDebuggerWithID(*debugger_id);
1738 if (debugger_sp)
1739 PrivateReportDiagnostic(*debugger_sp, severity, std::move(message),
1740 true);
1741 return;
1742 }
1743 // The diagnostic event is not debugger specific, iterate over all debuggers
1744 // and deliver a diagnostic event to each one.
1746 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1747 for (const auto &debugger : *g_debugger_list_ptr)
1748 PrivateReportDiagnostic(*debugger, severity, message, false);
1749 }
1750 };
1751
1752 if (once)
1753 std::call_once(*once, ReportDiagnosticLambda);
1754 else
1755 ReportDiagnosticLambda();
1756}
1757
1758void Debugger::ReportWarning(std::string message,
1759 std::optional<lldb::user_id_t> debugger_id,
1760 std::once_flag *once) {
1761 ReportDiagnosticImpl(eSeverityWarning, std::move(message), debugger_id, once);
1762}
1763
1764void Debugger::ReportError(std::string message,
1765 std::optional<lldb::user_id_t> debugger_id,
1766 std::once_flag *once) {
1767 ReportDiagnosticImpl(eSeverityError, std::move(message), debugger_id, once);
1768}
1769
1770void Debugger::ReportInfo(std::string message,
1771 std::optional<lldb::user_id_t> debugger_id,
1772 std::once_flag *once) {
1773 ReportDiagnosticImpl(eSeverityInfo, std::move(message), debugger_id, once);
1774}
1775
1778 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1779 for (DebuggerSP debugger_sp : *g_debugger_list_ptr) {
1780 EventSP event_sp = std::make_shared<Event>(
1782 new SymbolChangeEventData(debugger_sp, module_spec));
1783 debugger_sp->GetBroadcaster().BroadcastEvent(event_sp);
1784 }
1785 }
1786}
1787
1788static std::shared_ptr<LogHandler>
1789CreateLogHandler(LogHandlerKind log_handler_kind, int fd, bool should_close,
1790 size_t buffer_size) {
1791 switch (log_handler_kind) {
1792 case eLogHandlerStream:
1793 return std::make_shared<StreamLogHandler>(fd, should_close, buffer_size);
1795 return std::make_shared<RotatingLogHandler>(buffer_size);
1796 case eLogHandlerSystem:
1797 return std::make_shared<SystemLogHandler>();
1799 return {};
1800 }
1801 return {};
1802}
1803
1804bool Debugger::EnableLog(llvm::StringRef channel,
1805 llvm::ArrayRef<const char *> categories,
1806 llvm::StringRef log_file, uint32_t log_options,
1807 size_t buffer_size, LogHandlerKind log_handler_kind,
1808 llvm::raw_ostream &error_stream) {
1809
1810 std::shared_ptr<LogHandler> log_handler_sp;
1812 log_handler_sp = m_callback_handler_sp;
1813 // For now when using the callback mode you always get thread & timestamp.
1814 log_options |=
1816 } else if (log_file.empty()) {
1817 log_handler_sp =
1818 CreateLogHandler(log_handler_kind, GetOutputFileSP()->GetDescriptor(),
1819 /*should_close=*/false, buffer_size);
1820 } else {
1821 auto pos = m_stream_handlers.find(log_file);
1822 if (pos != m_stream_handlers.end())
1823 log_handler_sp = pos->second.lock();
1824 if (!log_handler_sp) {
1825 File::OpenOptions flags =
1827 if (log_options & LLDB_LOG_OPTION_APPEND)
1828 flags |= File::eOpenOptionAppend;
1829 else
1831 llvm::Expected<FileUP> file = FileSystem::Instance().Open(
1832 FileSpec(log_file), flags, lldb::eFilePermissionsFileDefault, false);
1833 if (!file) {
1834 error_stream << "Unable to open log file '" << log_file
1835 << "': " << llvm::toString(file.takeError()) << "\n";
1836 return false;
1837 }
1838
1839 log_handler_sp =
1840 CreateLogHandler(log_handler_kind, (*file)->GetDescriptor(),
1841 /*should_close=*/true, buffer_size);
1842 m_stream_handlers[log_file] = log_handler_sp;
1843 }
1844 }
1845 assert(log_handler_sp);
1846
1847 if (log_options == 0)
1849
1850 return Log::EnableLogChannel(log_handler_sp, log_options, channel, categories,
1851 error_stream);
1852}
1853
1856 std::optional<lldb::ScriptLanguage> language) {
1857 std::lock_guard<std::recursive_mutex> locker(m_script_interpreter_mutex);
1858 lldb::ScriptLanguage script_language =
1859 language ? *language : GetScriptLanguage();
1860
1861 if (!m_script_interpreters[script_language]) {
1862 if (!can_create)
1863 return nullptr;
1864 m_script_interpreters[script_language] =
1865 PluginManager::GetScriptInterpreterForLanguage(script_language, *this);
1866 }
1867
1868 return m_script_interpreters[script_language].get();
1869}
1870
1873 m_source_manager_up = std::make_unique<SourceManager>(shared_from_this());
1874 return *m_source_manager_up;
1875}
1876
1877// This function handles events that were broadcast by the process.
1879 using namespace lldb;
1880 const uint32_t event_type =
1882 event_sp);
1883
1884 // if (event_type & eBreakpointEventTypeAdded
1885 // || event_type & eBreakpointEventTypeRemoved
1886 // || event_type & eBreakpointEventTypeEnabled
1887 // || event_type & eBreakpointEventTypeDisabled
1888 // || event_type & eBreakpointEventTypeCommandChanged
1889 // || event_type & eBreakpointEventTypeConditionChanged
1890 // || event_type & eBreakpointEventTypeIgnoreChanged
1891 // || event_type & eBreakpointEventTypeLocationsResolved)
1892 // {
1893 // // Don't do anything about these events, since the breakpoint
1894 // commands already echo these actions.
1895 // }
1896 //
1897 if (event_type & eBreakpointEventTypeLocationsAdded) {
1898 uint32_t num_new_locations =
1900 event_sp);
1901 if (num_new_locations > 0) {
1902 BreakpointSP breakpoint =
1904 if (StreamUP output_up = GetAsyncOutputStream()) {
1905 output_up->Printf("%d location%s added to breakpoint %d\n",
1906 num_new_locations, num_new_locations == 1 ? "" : "s",
1907 breakpoint->GetID());
1908 output_up->Flush();
1909 }
1910 }
1911 }
1912 // else if (event_type & eBreakpointEventTypeLocationsRemoved)
1913 // {
1914 // // These locations just get disabled, not sure it is worth spamming
1915 // folks about this on the command line.
1916 // }
1917 // else if (event_type & eBreakpointEventTypeLocationsResolved)
1918 // {
1919 // // This might be an interesting thing to note, but I'm going to
1920 // leave it quiet for now, it just looked noisy.
1921 // }
1922}
1923
1924void Debugger::FlushProcessOutput(Process &process, bool flush_stdout,
1925 bool flush_stderr) {
1926 const auto &flush = [&](Stream &stream,
1927 size_t (Process::*get)(char *, size_t, Status &)) {
1928 Status error;
1929 size_t len;
1930 char buffer[1024];
1931 while ((len = (process.*get)(buffer, sizeof(buffer), error)) > 0)
1932 stream.Write(buffer, len);
1933 stream.Flush();
1934 };
1935
1936 std::lock_guard<std::mutex> guard(m_output_flush_mutex);
1937 if (flush_stdout)
1939 if (flush_stderr)
1941}
1942
1943// This function handles events that were broadcast by the process.
1945 using namespace lldb;
1946 const uint32_t event_type = event_sp->GetType();
1947 ProcessSP process_sp =
1951
1952 StreamUP output_stream_up = GetAsyncOutputStream();
1953 StreamUP error_stream_up = GetAsyncErrorStream();
1954 const bool gui_enabled = IsForwardingEvents();
1955
1956 if (!gui_enabled) {
1957 bool pop_process_io_handler = false;
1958 assert(process_sp);
1959
1960 bool state_is_stopped = false;
1961 const bool got_state_changed =
1962 (event_type & Process::eBroadcastBitStateChanged) != 0;
1963 const bool got_stdout = (event_type & Process::eBroadcastBitSTDOUT) != 0;
1964 const bool got_stderr = (event_type & Process::eBroadcastBitSTDERR) != 0;
1965 const bool got_structured_data =
1966 (event_type & Process::eBroadcastBitStructuredData) != 0;
1967
1968 if (got_state_changed) {
1969 StateType event_state =
1971 state_is_stopped = StateIsStoppedState(event_state, false);
1972 }
1973
1974 // Display running state changes first before any STDIO
1975 if (got_state_changed && !state_is_stopped) {
1976 // This is a public stop which we are going to announce to the user, so
1977 // we should force the most relevant frame selection here.
1978 Process::HandleProcessStateChangedEvent(event_sp, output_stream_up.get(),
1980 pop_process_io_handler);
1981 }
1982
1983 // Now display STDOUT and STDERR
1984 FlushProcessOutput(*process_sp, got_stdout || got_state_changed,
1985 got_stderr || got_state_changed);
1986
1987 // Give structured data events an opportunity to display.
1988 if (got_structured_data) {
1989 StructuredDataPluginSP plugin_sp =
1991 if (plugin_sp) {
1992 auto structured_data_sp =
1994 StreamString content_stream;
1995 Status error =
1996 plugin_sp->GetDescription(structured_data_sp, content_stream);
1997 if (error.Success()) {
1998 if (!content_stream.GetString().empty()) {
1999 // Add newline.
2000 content_stream.PutChar('\n');
2001 content_stream.Flush();
2002
2003 // Print it.
2004 output_stream_up->PutCString(content_stream.GetString());
2005 }
2006 } else {
2007 error_stream_up->Format("Failed to print structured "
2008 "data with plugin {0}: {1}",
2009 plugin_sp->GetPluginName(), error);
2010 }
2011 }
2012 }
2013
2014 // Now display any stopped state changes after any STDIO
2015 if (got_state_changed && state_is_stopped) {
2016 Process::HandleProcessStateChangedEvent(event_sp, output_stream_up.get(),
2018 pop_process_io_handler);
2019 }
2020
2021 output_stream_up->Flush();
2022 error_stream_up->Flush();
2023
2024 if (pop_process_io_handler)
2025 process_sp->PopProcessIOHandler();
2026 }
2027}
2028
2030 // At present the only thread event we handle is the Frame Changed event, and
2031 // all we do for that is just reprint the thread status for that thread.
2032 using namespace lldb;
2033 const uint32_t event_type = event_sp->GetType();
2034 const bool stop_format = true;
2035 if (event_type == Thread::eBroadcastBitStackChanged ||
2037 ThreadSP thread_sp(
2039 if (thread_sp) {
2040 thread_sp->GetStatus(*GetAsyncOutputStream(), 0, 1, 1, stop_format,
2041 /*show_hidden*/ true);
2042 }
2043 }
2044}
2045
2047
2049 m_forward_listener_sp = listener_sp;
2050}
2051
2053 m_forward_listener_sp.reset();
2054}
2055
2057// We have trouble with the contol codes on Windows, see
2058// https://github.com/llvm/llvm-project/issues/134846.
2059#ifndef _WIN32
2060 if (GetShowStatusline()) {
2062 File &file = stream_sp->GetUnlockedFile();
2063 return file.GetIsInteractive() && file.GetIsRealTerminal() &&
2065 }
2066 }
2067#endif
2068 return false;
2069}
2070
2072 ListenerSP listener_sp(GetListener());
2073 ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass());
2074 ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass());
2075 ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass());
2076 BroadcastEventSpec target_event_spec(broadcaster_class_target,
2078
2079 BroadcastEventSpec process_event_spec(
2080 broadcaster_class_process,
2083
2084 BroadcastEventSpec thread_event_spec(broadcaster_class_thread,
2087
2088 listener_sp->StartListeningForEventSpec(m_broadcaster_manager_sp,
2089 target_event_spec);
2090 listener_sp->StartListeningForEventSpec(m_broadcaster_manager_sp,
2091 process_event_spec);
2092 listener_sp->StartListeningForEventSpec(m_broadcaster_manager_sp,
2093 thread_event_spec);
2094 listener_sp->StartListeningForEvents(
2099
2100 listener_sp->StartListeningForEvents(
2105
2106 // Let the thread that spawned us know that we have started up and that we
2107 // are now listening to all required events so no events get missed
2109
2110 if (StatuslineSupported()) {
2111 std::lock_guard<std::mutex> guard(m_statusline_mutex);
2112 if (!m_statusline)
2113 m_statusline.emplace(*this);
2114 }
2115
2116 bool done = false;
2117 while (!done) {
2118 EventSP event_sp;
2119 if (listener_sp->GetEvent(event_sp, std::nullopt)) {
2120 if (event_sp) {
2121 Broadcaster *broadcaster = event_sp->GetBroadcaster();
2122 if (broadcaster) {
2123 uint32_t event_type = event_sp->GetType();
2124 ConstString broadcaster_class(broadcaster->GetBroadcasterClass());
2125 if (broadcaster_class == broadcaster_class_process) {
2126 HandleProcessEvent(event_sp);
2127 } else if (broadcaster_class == broadcaster_class_target) {
2129 event_sp.get())) {
2130 HandleBreakpointEvent(event_sp);
2131 }
2132 } else if (broadcaster_class == broadcaster_class_thread) {
2133 HandleThreadEvent(event_sp);
2134 } else if (broadcaster == m_command_interpreter_up.get()) {
2135 if (event_type &
2137 done = true;
2138 } else if (event_type &
2140 const char *data = static_cast<const char *>(
2141 EventDataBytes::GetBytesFromEvent(event_sp.get()));
2142 if (data && data[0]) {
2143 StreamUP error_up = GetAsyncErrorStream();
2144 error_up->PutCString(data);
2145 error_up->Flush();
2146 }
2147 } else if (event_type & CommandInterpreter::
2148 eBroadcastBitAsynchronousOutputData) {
2149 const char *data = static_cast<const char *>(
2150 EventDataBytes::GetBytesFromEvent(event_sp.get()));
2151 if (data && data[0]) {
2152 StreamUP output_up = GetAsyncOutputStream();
2153 output_up->PutCString(data);
2154 output_up->Flush();
2155 }
2156 }
2157 } else if (broadcaster == &m_broadcaster) {
2158 if (event_type & lldb::eBroadcastBitProgress ||
2160 HandleProgressEvent(event_sp);
2161 else if (event_type & lldb::eBroadcastBitWarning)
2162 HandleDiagnosticEvent(event_sp);
2163 else if (event_type & lldb::eBroadcastBitError)
2164 HandleDiagnosticEvent(event_sp);
2165 }
2166 }
2167
2169 m_forward_listener_sp->AddEvent(event_sp);
2170 }
2172 }
2173 }
2174
2175 {
2176 std::lock_guard<std::mutex> guard(m_statusline_mutex);
2177 if (m_statusline)
2178 m_statusline.reset();
2179 }
2180
2181 return {};
2182}
2183
2185 if (!m_event_handler_thread.IsJoinable()) {
2186 // We must synchronize with the DefaultEventHandler() thread to ensure it
2187 // is up and running and listening to events before we return from this
2188 // function. We do this by listening to events for the
2189 // eBroadcastBitEventThreadIsListening from the m_sync_broadcaster
2190 ConstString full_name("lldb.debugger.event-handler");
2191 ListenerSP listener_sp(Listener::MakeListener(full_name.AsCString()));
2192 listener_sp->StartListeningForEvents(&m_sync_broadcaster,
2194
2195 llvm::StringRef thread_name =
2196 full_name.GetLength() < llvm::get_max_thread_name_length()
2197 ? full_name.GetStringRef()
2198 : "dbg.evt-handler";
2199
2200 // Use larger 8MB stack for this thread
2201 llvm::Expected<HostThread> event_handler_thread =
2203 thread_name, [this] { return DefaultEventHandler(); },
2205
2206 if (event_handler_thread) {
2207 m_event_handler_thread = *event_handler_thread;
2208 } else {
2209 LLDB_LOG_ERROR(GetLog(LLDBLog::Host), event_handler_thread.takeError(),
2210 "failed to launch host thread: {0}");
2211 }
2212
2213 // Make sure DefaultEventHandler() is running and listening to events
2214 // before we return from this function. We are only listening for events of
2215 // type eBroadcastBitEventThreadIsListening so we don't need to check the
2216 // event, we just need to wait an infinite amount of time for it (nullptr
2217 // timeout as the first parameter)
2218 lldb::EventSP event_sp;
2219 listener_sp->GetEvent(event_sp, std::nullopt);
2220 }
2221 return m_event_handler_thread.IsJoinable();
2222}
2223
2231
2237
2239 auto *data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
2240 if (!data)
2241 return;
2242
2243 // Make a local copy of the incoming progress report that we'll store.
2244 ProgressReport progress_report{data->GetID(), data->GetCompleted(),
2245 data->GetTotal(), data->GetMessage()};
2246
2247 // Do some bookkeeping regardless of whether we're going to display
2248 // progress reports.
2249 {
2250 std::lock_guard<std::mutex> guard(m_progress_reports_mutex);
2251 auto it = llvm::find_if(m_progress_reports, [&](const auto &report) {
2252 return report.id == progress_report.id;
2253 });
2254 if (it != m_progress_reports.end()) {
2255 const bool complete = data->GetCompleted() == data->GetTotal();
2256 if (complete)
2257 m_progress_reports.erase(it);
2258 else
2259 *it = progress_report;
2260 } else {
2261 m_progress_reports.push_back(progress_report);
2262 }
2263 }
2264}
2265
2266std::optional<Debugger::ProgressReport>
2268 std::lock_guard<std::mutex> guard(m_progress_reports_mutex);
2269 if (m_progress_reports.empty())
2270 return std::nullopt;
2271 return m_progress_reports.back();
2272}
2273
2275 auto *data = DiagnosticEventData::GetEventDataFromEvent(event_sp.get());
2276 if (!data)
2277 return;
2278
2279 data->Dump(GetAsyncErrorStream().get());
2280}
2281
2283 return m_io_handler_thread.IsJoinable();
2284}
2285
2288 m_io_handler_thread = new_thread;
2289 return old_host;
2290}
2291
2293 if (!m_io_handler_thread.IsJoinable()) {
2294 llvm::Expected<HostThread> io_handler_thread = ThreadLauncher::LaunchThread(
2295 "lldb.debugger.io-handler", [this] { return IOHandlerThread(); },
2296 8 * 1024 * 1024); // Use larger 8MB stack for this thread
2297 if (io_handler_thread) {
2298 m_io_handler_thread = *io_handler_thread;
2299 } else {
2300 LLDB_LOG_ERROR(GetLog(LLDBLog::Host), io_handler_thread.takeError(),
2301 "failed to launch host thread: {0}");
2302 }
2303 }
2304 return m_io_handler_thread.IsJoinable();
2305}
2306
2308 if (m_io_handler_thread.IsJoinable()) {
2309 GetInputFile().Close();
2310 m_io_handler_thread.Join(nullptr);
2311 }
2312}
2313
2321
2323 if (!HasIOHandlerThread())
2324 return false;
2325 return m_io_handler_thread.EqualsThread(Host::GetCurrentThread());
2326}
2327
2329 if (!prefer_dummy) {
2330 if (TargetSP target = m_target_list.GetSelectedTarget())
2331 return *target;
2332 }
2333 return GetDummyTarget();
2334}
2335
2336Status Debugger::RunREPL(LanguageType language, const char *repl_options) {
2337 Status err;
2338 FileSpec repl_executable;
2339
2340 if (language == eLanguageTypeUnknown)
2341 language = GetREPLLanguage();
2342
2343 if (language == eLanguageTypeUnknown) {
2345
2346 if (auto single_lang = repl_languages.GetSingularLanguage()) {
2347 language = *single_lang;
2348 } else if (repl_languages.Empty()) {
2350 "LLDB isn't configured with REPL support for any languages.");
2351 return err;
2352 } else {
2354 "Multiple possible REPL languages. Please specify a language.");
2355 return err;
2356 }
2357 }
2358
2359 Target *const target =
2360 nullptr; // passing in an empty target means the REPL must create one
2361
2362 REPLSP repl_sp(REPL::Create(err, language, this, target, repl_options));
2363
2364 if (!err.Success()) {
2365 return err;
2366 }
2367
2368 if (!repl_sp) {
2370 "couldn't find a REPL for %s",
2372 return err;
2373 }
2374
2375 repl_sp->SetCompilerOptions(repl_options);
2376 repl_sp->RunLoop();
2377
2378 return err;
2379}
2380
2381llvm::ThreadPoolInterface &Debugger::GetThreadPool() {
2382 assert(g_thread_pool &&
2383 "Debugger::GetThreadPool called before Debugger::Initialize");
2384 return *g_thread_pool;
2385}
static llvm::raw_ostream & error(Stream &strm)
static std::recursive_mutex * g_debugger_list_mutex_ptr
Definition Debugger.cpp:108
static llvm::DefaultThreadPool * g_thread_pool
Definition Debugger.cpp:112
static constexpr OptionEnumValueElement g_show_disassembly_enum_values[]
Definition Debugger.cpp:114
static lldb::user_id_t g_unique_id
Definition Debugger.cpp:103
static constexpr OptionEnumValueElement g_language_enumerators[]
Definition Debugger.cpp:139
static void PrivateReportDiagnostic(Debugger &debugger, Severity severity, std::string message, bool debugger_specific)
static constexpr OptionEnumValueElement g_dwim_print_verbosities[]
Definition Debugger.cpp:157
static constexpr OptionEnumValueElement s_stop_show_column_values[]
Definition Debugger.cpp:167
static void PrivateReportProgress(Debugger &debugger, uint64_t progress_id, std::string title, std::string details, uint64_t completed, uint64_t total, bool is_debugger_specific, uint32_t progress_broadcast_bit)
static Debugger::DebuggerList * g_debugger_list_ptr
Definition Debugger.cpp:110
static int OpenPipe(int fds[2], std::size_t size)
static size_t g_debugger_event_thread_stack_bytes
Definition Debugger.cpp:104
static FileSystem::EnumerateDirectoryResult LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path)
Definition Debugger.cpp:769
static std::shared_ptr< LogHandler > CreateLogHandler(LogHandlerKind log_handler_kind, int fd, bool should_close, size_t buffer_size)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:369
#define LLDB_LOG_OPTION_APPEND
Definition Log.h:42
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
#define LLDB_LOG_OPTION_PREPEND_TIMESTAMP
Definition Log.h:38
#define LLDB_LOG_OPTION_PREPEND_THREAD_NAME
Definition Log.h:40
PIPES
Definition PipePosix.cpp:32
@ WRITE
Definition PipePosix.cpp:32
@ READ
Definition PipePosix.cpp:32
A section + offset based address class.
Definition Address.h:62
An architecture specification class.
Definition ArchSpec.h:31
bool IsValid() const
Tests if this ArchSpec is valid.
Definition ArchSpec.h:361
static lldb::BreakpointEventType GetBreakpointEventTypeFromEvent(const lldb::EventSP &event_sp)
static lldb::BreakpointSP GetBreakpointFromEvent(const lldb::EventSP &event_sp)
static const BreakpointEventData * GetEventDataFromEvent(const Event *event_sp)
static size_t GetNumBreakpointLocationsFromEvent(const lldb::EventSP &event_sp)
lldb::BroadcastEventSpec
Definition Broadcaster.h:40
An event broadcasting class.
bool EventTypeHasListeners(uint32_t event_type)
virtual llvm::StringRef GetBroadcasterClass() const
This needs to be filled in if you are going to register the broadcaster with the broadcaster manager ...
void BroadcastEvent(lldb::EventSP &event_sp)
Broadcast an event which has no associated data.
void UpdatePrompt(llvm::StringRef prompt)
bool SaveTranscript(CommandReturnObject &result, std::optional< std::string > output_file=std::nullopt)
Save the current debugger session transcript to a file on disk.
std::string GetErrorString(bool with_diagnostics=true) const
Return the errors as a string.
llvm::StringRef GetOutputString() const
A uniqued constant string class.
Definition ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
size_t GetLength() const
Get the length in bytes of string value.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const std::chrono::time_point< std::chrono::system_clock > m_interrupt_time
Definition Debugger.h:485
InterruptionReport(std::string function_name, std::string description)
Definition Debugger.h:467
A class to manage flag bits.
Definition Debugger.h:80
static void AssertCallback(llvm::StringRef message, llvm::StringRef backtrace, llvm::StringRef prompt)
llvm::StringRef GetAutosuggestionAnsiPrefix() const
Definition Debugger.cpp:539
bool SetUseExternalEditor(bool use_external_editor_p)
Definition Debugger.cpp:436
PlatformList m_platform_list
Definition Debugger.h:732
HostThread m_event_handler_thread
Definition Debugger.h:762
static lldb::TargetSP FindTargetWithProcessID(lldb::pid_t pid)
Definition Debugger.cpp:930
FormatEntity::Entry GetDisassemblyFormat() const
Definition Debugger.cpp:298
uint64_t GetDisassemblyLineCount() const
Definition Debugger.cpp:634
lldb::TargetSP GetSelectedTarget()
Definition Debugger.h:180
llvm::StringRef GetDisabledAnsiSuffix() const
Definition Debugger.cpp:520
uint64_t GetTerminalHeight() const
Definition Debugger.cpp:408
lldb::LockableStreamFileSP m_output_stream_sp
Definition Debugger.h:719
bool SetExternalEditor(llvm::StringRef editor)
Definition Debugger.cpp:447
void RequestInterrupt()
Interruption in LLDB:
void ReportInterruption(const InterruptionReport &report)
ExecutionContext GetSelectedExecutionContext()
const std::string m_instance_name
Definition Debugger.h:758
static void Terminate()
Definition Debugger.cpp:721
void HandleProgressEvent(const lldb::EventSP &event_sp)
SourceManager & GetSourceManager()
bool SetShowProgress(bool show_progress)
Definition Debugger.cpp:473
bool StartEventHandlerThread()
Manually start the global event handler thread.
bool SetUseSourceCache(bool use_source_cache)
Definition Debugger.cpp:575
void StopEventHandlerThread()
Manually stop the debugger's default event handler.
static void ReportInfo(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report info events.
void SetAsyncExecution(bool async)
HostThread SetIOHandlerThread(HostThread &new_thread)
void CancelForwardEvents(const lldb::ListenerSP &listener_sp)
bool GetPrintDecls() const
Definition Debugger.cpp:663
lldb::FileSP GetInputFileSP()
Definition Debugger.h:136
bool GetHighlightSource() const
Definition Debugger.cpp:583
llvm::StringMap< std::weak_ptr< LogHandler > > m_stream_handlers
Definition Debugger.h:756
CommandInterpreter & GetCommandInterpreter()
Definition Debugger.h:163
FormatEntity::Entry GetStatuslineFormat() const
Definition Debugger.cpp:496
LoadedPluginsList m_loaded_plugins
Definition Debugger.h:761
bool GetShowInlineDiagnostics() const
Definition Debugger.cpp:692
bool SetTabSize(uint64_t tab_size)
Definition Debugger.cpp:680
void HandleDiagnosticEvent(const lldb::EventSP &event_sp)
static lldb::DebuggerSP GetDebuggerAtIndex(size_t index)
llvm::StringRef GetAutosuggestionAnsiSuffix() const
Definition Debugger.cpp:545
lldb::ListenerSP m_listener_sp
Definition Debugger.h:733
void PushIOHandler(const lldb::IOHandlerSP &reader_sp, bool cancel_top_handler=true)
std::mutex m_destroy_callback_mutex
Definition Debugger.h:777
lldb::callback_token_t AddDestroyCallback(lldb_private::DebuggerDestroyCallback destroy_callback, void *baton)
Add a callback for when the debugger is destroyed.
lldb::thread_result_t IOHandlerThread()
FormatEntity::Entry GetFrameFormatUnique() const
Definition Debugger.cpp:308
std::optional< ProgressReport > GetCurrentProgressReport() const
static lldb::TargetSP FindTargetWithProcess(Process *process)
Definition Debugger.cpp:944
llvm::StringRef GetDisabledAnsiPrefix() const
Definition Debugger.cpp:514
bool GetUseExternalEditor() const
Definition Debugger.cpp:430
TerminalState m_terminal_state
Definition Debugger.h:729
lldb::StreamUP GetAsyncErrorStream()
bool GetEscapeNonPrintables() const
Definition Debugger.cpp:646
lldb::TargetSP m_dummy_target_sp
Definition Debugger.h:768
llvm::SmallVector< DestroyCallbackInfo, 2 > m_destroy_callbacks
Definition Debugger.h:789
std::unique_ptr< CommandInterpreter > m_command_interpreter_up
Definition Debugger.h:743
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
static bool FormatDisassemblerAddress(const FormatEntity::Entry *format, const SymbolContext *sc, const SymbolContext *prev_sc, const ExecutionContext *exe_ctx, const Address *addr, Stream &s)
static void SettingsInitialize()
Definition Debugger.cpp:747
LockableStreamFile::Mutex m_output_mutex
Definition Debugger.h:721
static llvm::ThreadPoolInterface & GetThreadPool()
Shared thread pool. Use only with ThreadPoolTaskGroup.
llvm::StringRef GetShowProgressAnsiSuffix() const
Definition Debugger.cpp:484
bool IsTopIOHandler(const lldb::IOHandlerSP &reader_sp)
bool HasIOHandlerThread() const
llvm::SmallVector< ProgressReport, 4 > m_progress_reports
Bookkeeping for command line progress events.
Definition Debugger.h:773
bool IsIOHandlerThreadCurrentThread() const
void DispatchClientTelemetry(const lldb_private::StructuredDataImpl &entry)
Definition Debugger.cpp:857
std::mutex m_progress_reports_mutex
Definition Debugger.h:774
lldb::ListenerSP m_forward_listener_sp
Definition Debugger.h:766
std::array< lldb::ScriptInterpreterSP, lldb::eScriptLanguageUnknown > m_script_interpreters
Definition Debugger.h:747
std::shared_ptr< CallbackLogHandler > m_callback_handler_sp
Definition Debugger.h:757
void SetDestroyCallback(lldb_private::DebuggerDestroyCallback destroy_callback, void *baton)
DEPRECATED: We used to only support one Destroy callback.
lldb::FileSP GetOutputFileSP()
Definition Debugger.h:139
Broadcaster m_broadcaster
Public Debugger event broadcaster.
Definition Debugger.h:765
static void Initialize(LoadPluginCallbackType load_plugin_callback)
Definition Debugger.cpp:712
static lldb::DebuggerSP FindDebuggerWithInstanceName(llvm::StringRef instance_name)
Definition Debugger.cpp:915
uint64_t GetTerminalWidth() const
Definition Debugger.cpp:386
std::mutex m_interrupt_mutex
Definition Debugger.h:792
std::recursive_mutex m_io_handler_synchronous_mutex
Definition Debugger.h:750
bool RemoveIOHandler(const lldb::IOHandlerSP &reader_sp)
Remove the given IO handler if it's currently active.
Diagnostics::CallbackID m_diagnostics_callback_id
Definition Debugger.h:769
bool GetAutoOneLineSummaries() const
Definition Debugger.cpp:640
const char * GetIOHandlerCommandPrefix()
std::optional< Statusline > m_statusline
Definition Debugger.h:754
bool GetUseColor() const
Definition Debugger.cpp:452
lldb::BroadcasterManagerSP m_broadcaster_manager_sp
Definition Debugger.h:723
Status RunREPL(lldb::LanguageType language, const char *repl_options)
bool PopIOHandler(const lldb::IOHandlerSP &reader_sp)
bool RemoveDestroyCallback(lldb::callback_token_t token)
Remove the specified callback. Return true if successful.
static LoadPluginCallbackType g_load_plugin_callback
Definition Debugger.h:759
bool GetShowStatusline() const
Definition Debugger.cpp:490
std::recursive_mutex m_script_interpreter_mutex
Definition Debugger.h:745
void RunIOHandlerAsync(const lldb::IOHandlerSP &reader_sp, bool cancel_top_handler=true)
Run the given IO handler and return immediately.
void SetInputFile(lldb::FileSP file)
lldb::LockableStreamFileSP GetOutputStreamSP()
Except for Debugger and IOHandler, GetOutputStreamSP and GetErrorStreamSP should not be used directly...
Definition Debugger.h:673
void SetPrompt(llvm::StringRef p)
Definition Debugger.cpp:343
llvm::StringRef GetSeparator() const
Definition Debugger.cpp:508
bool EnableLog(llvm::StringRef channel, llvm::ArrayRef< const char * > categories, llvm::StringRef log_file, uint32_t log_options, size_t buffer_size, LogHandlerKind log_handler_kind, llvm::raw_ostream &error_stream)
uint64_t GetStopDisassemblyMaxSize() const
Definition Debugger.cpp:313
bool SetTerminalHeight(uint64_t term_height)
Definition Debugger.cpp:414
Broadcaster m_sync_broadcaster
Private debugger synchronization.
Definition Debugger.h:764
bool GetUseSourceCache() const
Definition Debugger.cpp:569
HostThread m_io_handler_thread
Definition Debugger.h:763
llvm::StringRef GetRegexMatchAnsiSuffix() const
Definition Debugger.cpp:557
static llvm::StringRef GetStaticBroadcasterClass()
Definition Debugger.cpp:958
lldb::FileSP m_input_file_sp
Definition Debugger.h:718
bool SetREPLLanguage(lldb::LanguageType repl_lang)
Definition Debugger.cpp:381
bool GetAutoIndent() const
Definition Debugger.cpp:652
llvm::StringRef GetStopShowColumnAnsiSuffix() const
Definition Debugger.cpp:602
Status SetPropertyValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef property_path, llvm::StringRef value) override
Definition Debugger.cpp:205
llvm::StringRef GetPromptAnsiSuffix() const
Definition Debugger.cpp:337
FormatEntity::Entry GetThreadStopFormat() const
Definition Debugger.cpp:359
void SetErrorFile(lldb::FileSP file)
bool GetAutoConfirm() const
Definition Debugger.cpp:292
TargetList m_target_list
Definition Debugger.h:730
lldb::ScriptLanguage GetScriptLanguage() const
Definition Debugger.cpp:364
lldb::callback_token_t m_destroy_callback_next_token
Definition Debugger.h:778
std::unique_ptr< SourceManager > m_source_manager_up
Definition Debugger.h:734
void RedrawStatusline(bool update=true)
Redraw the statusline if enabled.
static lldb::DebuggerSP CreateInstance(lldb::LogOutputCallback log_callback=nullptr, void *baton=nullptr)
Definition Debugger.cpp:839
lldb::StopShowColumn GetStopShowColumn() const
Definition Debugger.cpp:589
static void ReportSymbolChange(const ModuleSpec &module_spec)
static void ReportError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report error events.
bool SetPrintDecls(bool b)
Definition Debugger.cpp:669
bool SetScriptLanguage(lldb::ScriptLanguage script_lang)
Definition Debugger.cpp:371
lldb::LockableStreamFileSP m_error_stream_sp
Definition Debugger.h:720
bool SetShowInlineDiagnostics(bool)
Definition Debugger.cpp:698
bool LoadPlugin(const FileSpec &spec, Status &error)
Definition Debugger.cpp:751
void SetOutputFile(lldb::FileSP file)
uint64_t GetStopSourceLineCount(bool before) const
Definition Debugger.cpp:620
bool SetStatuslineFormat(const FormatEntity::Entry &format)
Definition Debugger.cpp:501
void EnableForwardEvents(const lldb::ListenerSP &listener_sp)
static lldb::DebuggerSP FindDebuggerWithID(lldb::user_id_t id)
void HandleBreakpointEvent(const lldb::EventSP &event_sp)
bool CheckTopIOHandlerTypes(IOHandler::Type top_type, IOHandler::Type second_top_type)
Target & GetDummyTarget()
Definition Debugger.h:500
lldb::ListenerSP GetListener()
Definition Debugger.h:172
static void Destroy(lldb::DebuggerSP &debugger_sp)
Definition Debugger.cpp:883
SourceManager::SourceFileCache m_source_file_cache
Definition Debugger.h:738
llvm::StringRef GetPromptAnsiPrefix() const
Definition Debugger.cpp:331
lldb::StreamUP GetAsyncOutputStream()
void RunIOHandlerSync(const lldb::IOHandlerSP &reader_sp)
Run the given IO handler and block until it's complete.
Broadcaster & GetBroadcaster()
Get the public broadcaster for this debugger.
Definition Debugger.h:87
llvm::StringRef GetStopShowLineMarkerAnsiPrefix() const
Definition Debugger.cpp:608
bool GetShowDontUsePoHint() const
Definition Debugger.cpp:563
uint64_t GetTabSize() const
Definition Debugger.cpp:674
bool GetShowProgress() const
Definition Debugger.cpp:467
llvm::StringRef GetRegexMatchAnsiPrefix() const
Definition Debugger.cpp:551
std::mutex m_output_flush_mutex
Definition Debugger.h:713
llvm::StringRef GetStopShowLineMarkerAnsiSuffix() const
Definition Debugger.cpp:614
bool SetSeparator(llvm::StringRef s)
Definition Debugger.cpp:526
bool SetUseColor(bool use_color)
Definition Debugger.cpp:458
std::mutex m_statusline_mutex
Mutex protecting the m_statusline member.
Definition Debugger.h:753
const char * GetIOHandlerHelpPrologue()
Status SetInputString(const char *data)
bool GetUseAutosuggestion() const
Definition Debugger.cpp:533
Target & GetSelectedOrDummyTarget(bool prefer_dummy=false)
void HandleProcessEvent(const lldb::EventSP &event_sp)
IOHandlerStack m_io_handler_stack
Definition Debugger.h:749
llvm::once_flag m_clear_once
Definition Debugger.h:767
static void SettingsTerminate()
Definition Debugger.cpp:749
static void ReportProgress(uint64_t progress_id, std::string title, std::string details, uint64_t completed, uint64_t total, std::optional< lldb::user_id_t > debugger_id, uint32_t progress_category_bit=lldb::eBroadcastBitProgress)
Report progress events.
lldb::LanguageType GetREPLLanguage() const
Definition Debugger.cpp:376
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, std::optional< lldb::ScriptLanguage > language={})
void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton)
bool SetTerminalWidth(uint64_t term_width)
Definition Debugger.cpp:392
Debugger(lldb::LogOutputCallback m_log_callback, void *baton)
Definition Debugger.cpp:963
llvm::StringRef GetExternalEditor() const
Definition Debugger.cpp:441
void HandleThreadEvent(const lldb::EventSP &event_sp)
static size_t GetNumDebuggers()
FormatEntity::Entry GetThreadFormat() const
Definition Debugger.cpp:354
uint32_t m_interrupt_requested
Tracks interrupt requests.
Definition Debugger.h:791
lldb::DWIMPrintVerbosity GetDWIMPrintVerbosity() const
Definition Debugger.cpp:685
lldb::thread_result_t DefaultEventHandler()
void PrintAsync(const char *s, size_t len, bool is_stdout)
lldb::LockableStreamFileSP GetErrorStreamSP()
Definition Debugger.h:674
llvm::StringRef GetPrompt() const
Definition Debugger.cpp:325
bool GetNotifyVoid() const
Definition Debugger.cpp:319
llvm::StringRef GetShowProgressAnsiPrefix() const
Definition Debugger.cpp:478
void AdoptTopIOHandlerFilesIfInvalid(lldb::FileSP &in, lldb::LockableStreamFileSP &out, lldb::LockableStreamFileSP &err)
FormatEntity::Entry GetFrameFormat() const
Definition Debugger.cpp:303
lldb::StopDisassemblyType GetStopDisassemblyDisplay() const
Definition Debugger.cpp:627
llvm::StringRef GetTopIOHandlerControlSequence(char ch)
void FlushProcessOutput(Process &process, bool flush_stdout, bool flush_stderr)
Force flushing the process's pending stdout and stderr to the debugger's asynchronous stdout and stde...
void CancelInterruptRequest()
Decrement the "interrupt requested" counter.
static void ReportDiagnosticImpl(lldb::Severity severity, std::string message, std::optional< lldb::user_id_t > debugger_id, std::once_flag *once)
std::vector< lldb::DebuggerSP > DebuggerList
Definition Debugger.h:82
bool SetAutoIndent(bool b)
Definition Debugger.cpp:658
friend class CommandInterpreter
Definition Debugger.h:620
llvm::StringRef GetStopShowColumnAnsiPrefix() const
Definition Debugger.cpp:596
static DebuggerList DebuggersRequestingInterruption()
void Dump(Stream *s) const override
static const DiagnosticEventData * GetEventDataFromEvent(const Event *event_ptr)
CallbackID AddCallback(Callback callback)
void Report(llvm::StringRef message)
void RemoveCallback(CallbackID id)
static Diagnostics & Instance()
static const void * GetBytesFromEvent(const Event *event_ptr)
Definition Event.cpp:146
static lldb::ProcessSP GetProcessFromEvent(const Event *event_ptr)
Definition Event.cpp:247
static lldb::StructuredDataPluginSP GetPluginFromEvent(const Event *event_ptr)
Definition Event.cpp:265
static StructuredData::ObjectSP GetObjectFromEvent(const Event *event_ptr)
Definition Event.cpp:256
Execution context objects refer to objects in the execution of the program that is being debugged.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
bool HasTargetScope() const
Returns true the ExecutionContext object contains a valid target.
Target & GetTargetRef() const
Returns a reference to the target object.
A file utility class.
Definition FileSpec.h:57
FileSpec CopyByAppendingPathComponent(llvm::StringRef component) const
Definition FileSpec.cpp:425
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:374
llvm::StringRef GetFileNameExtension() const
Extract the extension of the file.
Definition FileSpec.cpp:410
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
void EnumerateDirectory(llvm::Twine path, bool find_directories, bool find_files, bool find_other, EnumerateDirectoryCallbackType callback, void *callback_baton)
@ eEnumerateDirectoryResultEnter
Recurse into the current entry if it is a directory or symlink, or next if not.
Definition FileSystem.h:181
@ eEnumerateDirectoryResultNext
Enumerate next entry in the current directory.
Definition FileSystem.h:178
@ eEnumerateDirectoryResultQuit
Stop directory enumerations at any level.
Definition FileSystem.h:183
int Open(const char *path, int flags, int mode=0600)
Wraps open in a platform-independent way.
static FileSystem & Instance()
An abstract base class for files.
Definition File.h:36
bool GetIsRealTerminal()
Return true if this file from a real terminal.
Definition File.cpp:200
static int kInvalidDescriptor
Definition File.h:38
virtual int GetDescriptor() const
Get underlying OS file descriptor for this file, or kInvalidDescriptor.
Definition File.cpp:127
bool GetIsTerminalWithColors()
Return true if this file is a terminal which supports colors.
Definition File.cpp:206
Status Close() override
Flush any buffers and release any resources owned by the file.
Definition File.cpp:116
@ eOpenOptionWriteOnly
Definition File.h:52
@ eOpenOptionCanCreate
Definition File.h:56
@ eOpenOptionTruncate
Definition File.h:57
bool GetIsInteractive()
Return true if this file is interactive.
Definition File.cpp:194
const Mangled & GetMangled() const
Definition Function.h:534
static void SystemLog(lldb::Severity severity, llvm::StringRef message)
Emit the given message to the operating system log.
static lldb::thread_t GetCurrentThread()
Get the thread token (the one returned by ThreadCreate when the thread was created) for the calling t...
static llvm::StringRef GetSettingName()
Definition Language.cpp:45
static LanguageSet GetLanguagesSupportingREPLs()
Definition Language.cpp:432
static const char * GetNameForLanguageType(lldb::LanguageType language)
Definition Language.cpp:266
static LanguageProperties & GetGlobalLanguageProperties()
Definition Language.cpp:40
static lldb::ListenerSP MakeListener(const char *name)
Definition Listener.cpp:375
static bool EnableLogChannel(const std::shared_ptr< LogHandler > &log_handler_sp, uint32_t log_options, llvm::StringRef channel, llvm::ArrayRef< const char * > categories, llvm::raw_ostream &error_stream)
Definition Log.cpp:234
static ModuleListProperties & GetGlobalModuleListProperties()
static lldb::PlatformSP GetHostPlatform()
Get the native host platform plug-in.
Definition Platform.cpp:134
static PlatformProperties & GetGlobalPlatformProperties()
Definition Platform.cpp:140
static lldb::ScriptInterpreterSP GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang, Debugger &debugger)
static void DebuggerInitialize(Debugger &debugger)
static lldb::ProcessSP GetProcessFromEvent(const Event *event_ptr)
Definition Process.cpp:4404
static lldb::StateType GetStateFromEvent(const Event *event_ptr)
Definition Process.cpp:4412
A plug-in interface definition class for debugging a process.
Definition Process.h:357
static bool HandleProcessStateChangedEvent(const lldb::EventSP &event_sp, Stream *stream, SelectMostRelevant select_most_relevant, bool &pop_process_io_handler)
Centralize the code that handles and prints descriptions for process state changes.
Definition Process.cpp:733
static llvm::StringRef GetStaticBroadcasterClass()
Definition Process.cpp:422
virtual size_t GetSTDERR(char *buf, size_t buf_size, Status &error)
Get any available STDERR.
Definition Process.cpp:4607
virtual size_t GetSTDOUT(char *buf, size_t buf_size, Status &error)
Get any available STDOUT.
Definition Process.cpp:4588
static const ProgressEventData * GetEventDataFromEvent(const Event *event_ptr)
lldb::OptionValuePropertiesSP m_collection_sp
virtual Status SetPropertyValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef property_path, llvm::StringRef value)
T GetPropertyAtIndexAs(uint32_t idx, T default_value, const ExecutionContext *exe_ctx=nullptr) const
bool SetPropertyAtIndex(uint32_t idx, T t, const ExecutionContext *exe_ctx=nullptr) const
lldb::OptionValuePropertiesSP GetValueProperties() const
static lldb::REPLSP Create(Status &Status, lldb::LanguageType language, Debugger *debugger, Target *target, const char *repl_options)
Get a REPL with an existing target (or, failing that, a debugger to use), and (optional) extra argume...
Definition REPL.cpp:38
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
bool Success() const
Test for success condition.
Definition Status.cpp:304
void Flush() override
Flush the stream.
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
Definition Stream.h:112
size_t PutChar(char ch)
Definition Stream.cpp:131
virtual void Flush()=0
Flush the stream.
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
Symbol * symbol
The Symbol for a given query.
bool Compare(ConstString name, lldb::SymbolType type) const
Definition Symbol.cpp:386
ConstString GetName() const
Definition Symbol.cpp:511
lldb::SymbolType GetType() const
Definition Symbol.h:169
@ eBroadcastBitBreakpointChanged
Definition Target.h:534
Debugger & GetDebugger() const
Definition Target.h:1097
static void SettingsTerminate()
Definition Target.cpp:2787
static llvm::StringRef GetStaticBroadcasterClass()
Definition Target.cpp:168
static TargetProperties & GetGlobalProperties()
Definition Target.cpp:3249
static ArchSpec GetDefaultArchitecture()
Definition Target.cpp:2797
static void SettingsInitialize()
Definition Target.cpp:2785
static llvm::Expected< HostThread > LaunchThread(llvm::StringRef name, std::function< lldb::thread_result_t()> thread_function, size_t min_stack_byte_size=0)
static lldb::ThreadSP GetThreadFromEvent(const Event *event_ptr)
Definition Thread.cpp:182
static llvm::StringRef GetStaticBroadcasterClass()
Definition Thread.cpp:214
@ eBroadcastBitThreadSelected
Definition Thread.h:77
virtual void DispatchClientTelemetry(const lldb_private::StructuredDataImpl &entry, Debugger *debugger)
static TelemetryManager * GetInstance()
@ SelectMostRelevantFrame
#define LLDB_INVALID_HOST_THREAD
Definition lldb-types.h:69
Status Parse(const llvm::StringRef &format, Entry &entry)
bool Format(const Entry &entry, Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const Address *addr, ValueObject *valobj, bool function_changed, bool initial_function)
std::string FormatAnsiTerminalCodes(llvm::StringRef format, bool do_color=true)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
LoadScriptFromSymFile
Definition Target.h:54
@ eLoadScriptFromSymFileTrue
Definition Target.h:55
@ eLoadScriptFromSymFileFalse
Definition Target.h:56
@ eLoadScriptFromSymFileWarn
Definition Target.h:57
const char * GetVersion()
Retrieves a string representing the complete LLDB version, which includes the lldb version number,...
Definition Version.cpp:38
void(* DebuggerDestroyCallback)(lldb::user_id_t debugger_id, void *baton)
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
llvm::sys::DynamicLibrary(* LoadPluginCallbackType)(const lldb::DebuggerSP &debugger_sp, const FileSpec &spec, Status &error)
VarSetOperationType
Settable state variable types.
ScriptLanguage
Script interpreter types.
@ eScriptLanguageDefault
@ eScriptLanguageNone
@ eScriptLanguagePython
Severity
Used for expressing severity in logs and diagnostics.
@ eBroadcastBitExternalProgress
@ eBroadcastBitProgress
@ eBroadcastSymbolChange
std::shared_ptr< lldb_private::IOHandler > IOHandlerSP
std::shared_ptr< lldb_private::Thread > ThreadSP
void * thread_result_t
Definition lldb-types.h:62
std::shared_ptr< lldb_private::Platform > PlatformSP
DWIMPrintVerbosity
Enum to control the verbosity level of dwim-print execution.
@ eDWIMPrintVerbosityFull
Always print a message indicating how dwim-print is evaluating its expression.
@ eDWIMPrintVerbosityNone
Run dwim-print with no verbosity.
@ eDWIMPrintVerbosityExpression
Print a message when dwim-print uses expression evaluation.
StateType
Process and Thread States.
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
std::shared_ptr< lldb_private::StructuredDataPlugin > StructuredDataPluginSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Debugger > DebuggerSP
StopDisassemblyType
Used to determine when to show disassembly.
@ eStopDisassemblyTypeNever
@ eStopDisassemblyTypeNoSource
@ eStopDisassemblyTypeAlways
@ eStopDisassemblyTypeNoDebugInfo
@ eStopShowColumnAnsi
@ eStopShowColumnCaret
@ eStopShowColumnNone
@ eStopShowColumnAnsiOrCaret
std::shared_ptr< lldb_private::Event > EventSP
uint64_t pid_t
Definition lldb-types.h:83
std::shared_ptr< lldb_private::Listener > ListenerSP
int32_t callback_token_t
Definition lldb-types.h:81
uint64_t user_id_t
Definition lldb-types.h:82
std::shared_ptr< lldb_private::LockableStreamFile > LockableStreamFileSP
void(* LogOutputCallback)(const char *, void *baton)
Definition lldb-types.h:73
std::shared_ptr< lldb_private::Target > TargetSP
std::unique_ptr< lldb_private::Stream > StreamUP
std::shared_ptr< lldb_private::File > FileSP
std::shared_ptr< lldb_private::REPL > REPLSP
lldb_private::DebuggerDestroyCallback callback
Definition Debugger.h:786
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
Definition Type.h:38
std::optional< lldb::LanguageType > GetSingularLanguage()
If the set contains a single language only, return it.
UserID(lldb::user_id_t uid=LLDB_INVALID_UID)
Construct with optional user ID.
Definition UserID.h:33
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47
Helper RAII class for collecting telemetry.
Definition Telemetry.h:269
#define PATH_MAX