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