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