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