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