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 if (m_destroy_callback) {
748 m_destroy_callback = nullptr;
749 }
750}
751
752void Debugger::Destroy(DebuggerSP &debugger_sp) {
753 if (!debugger_sp)
754 return;
755
756 debugger_sp->HandleDestroyCallback();
757 CommandInterpreter &cmd_interpreter = debugger_sp->GetCommandInterpreter();
758
759 if (cmd_interpreter.GetSaveSessionOnQuit()) {
760 CommandReturnObject result(debugger_sp->GetUseColor());
761 cmd_interpreter.SaveTranscript(result);
762 if (result.Succeeded())
763 (*debugger_sp->GetAsyncOutputStream()) << result.GetOutputData() << '\n';
764 else
765 (*debugger_sp->GetAsyncErrorStream()) << result.GetErrorData() << '\n';
766 }
767
768 debugger_sp->Clear();
769
771 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
772 DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
773 for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
774 if ((*pos).get() == debugger_sp.get()) {
775 g_debugger_list_ptr->erase(pos);
776 return;
777 }
778 }
779 }
780}
781
783Debugger::FindDebuggerWithInstanceName(llvm::StringRef instance_name) {
785 return DebuggerSP();
786
787 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
788 for (const DebuggerSP &debugger_sp : *g_debugger_list_ptr) {
789 if (!debugger_sp)
790 continue;
791
792 if (llvm::StringRef(debugger_sp->GetInstanceName()) == instance_name)
793 return debugger_sp;
794 }
795 return DebuggerSP();
796}
797
799 TargetSP target_sp;
801 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
802 DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
803 for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
804 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID(pid);
805 if (target_sp)
806 break;
807 }
808 }
809 return target_sp;
810}
811
813 TargetSP target_sp;
815 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
816 DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
817 for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
818 target_sp = (*pos)->GetTargetList().FindTargetWithProcess(process);
819 if (target_sp)
820 break;
821 }
822 }
823 return target_sp;
824}
825
827 static constexpr llvm::StringLiteral class_name("lldb.debugger");
828 return class_name;
829}
830
832 : UserID(g_unique_id++),
833 Properties(std::make_shared<OptionValueProperties>()),
834 m_input_file_sp(std::make_shared<NativeFile>(stdin, false)),
835 m_output_stream_sp(std::make_shared<StreamFile>(stdout, false)),
836 m_error_stream_sp(std::make_shared<StreamFile>(stderr, false)),
837 m_input_recorder(nullptr),
838 m_broadcaster_manager_sp(BroadcasterManager::MakeBroadcasterManager()),
839 m_terminal_state(), m_target_list(*this), m_platform_list(),
840 m_listener_sp(Listener::MakeListener("lldb.Debugger")),
841 m_source_manager_up(), m_source_file_cache(),
842 m_command_interpreter_up(
843 std::make_unique<CommandInterpreter>(*this, false)),
844 m_io_handler_stack(),
845 m_instance_name(llvm::formatv("debugger_{0}", GetID()).str()),
846 m_loaded_plugins(), m_event_handler_thread(), m_io_handler_thread(),
847 m_sync_broadcaster(nullptr, "lldb.debugger.sync"),
848 m_broadcaster(m_broadcaster_manager_sp,
849 GetStaticBroadcasterClass().str()),
850 m_forward_listener_sp(), m_clear_once() {
851 // Initialize the debugger properties as early as possible as other parts of
852 // LLDB will start querying them during construction.
853 m_collection_sp->Initialize(g_debugger_properties);
854 m_collection_sp->AppendProperty(
855 "target", "Settings specify to debugging targets.", true,
857 m_collection_sp->AppendProperty(
858 "platform", "Platform settings.", true,
860 m_collection_sp->AppendProperty(
861 "symbols", "Symbol lookup and cache settings.", true,
863 m_collection_sp->AppendProperty(
864 LanguageProperties::GetSettingName(), "Language settings.", true,
867 m_collection_sp->AppendProperty(
868 "interpreter",
869 "Settings specify to the debugger's command interpreter.", true,
870 m_command_interpreter_up->GetValueProperties());
871 }
872 if (log_callback)
874 std::make_shared<CallbackLogHandler>(log_callback, baton);
875 m_command_interpreter_up->Initialize();
876 // Always add our default platform to the platform list
877 PlatformSP default_platform_sp(Platform::GetHostPlatform());
878 assert(default_platform_sp);
879 m_platform_list.Append(default_platform_sp, true);
880
881 // Create the dummy target.
882 {
884 if (!arch.IsValid())
885 arch = HostInfo::GetArchitecture();
886 assert(arch.IsValid() && "No valid default or host archspec");
887 const bool is_dummy_target = true;
888 m_dummy_target_sp.reset(
889 new Target(*this, arch, default_platform_sp, is_dummy_target));
890 }
891 assert(m_dummy_target_sp.get() && "Couldn't construct dummy target?");
892
893 OptionValueUInt64 *term_width =
894 m_collection_sp->GetPropertyAtIndexAsOptionValueUInt64(
895 ePropertyTerminalWidth);
896 term_width->SetMinimumValue(10);
897 term_width->SetMaximumValue(1024);
898
899 // Turn off use-color if this is a dumb terminal.
900 const char *term = getenv("TERM");
901 if (term && !strcmp(term, "dumb"))
902 SetUseColor(false);
903 // Turn off use-color if we don't write to a terminal with color support.
904 if (!GetOutputFile().GetIsTerminalWithColors())
905 SetUseColor(false);
906
907 if (Diagnostics::Enabled()) {
909 [this](const FileSpec &dir) -> llvm::Error {
910 for (auto &entry : m_stream_handlers) {
911 llvm::StringRef log_path = entry.first();
912 llvm::StringRef file_name = llvm::sys::path::filename(log_path);
913 FileSpec destination = dir.CopyByAppendingPathComponent(file_name);
914 std::error_code ec =
915 llvm::sys::fs::copy_file(log_path, destination.GetPath());
916 if (ec)
917 return llvm::errorCodeToError(ec);
918 }
919 return llvm::Error::success();
920 });
921 }
922
923#if defined(_WIN32) && defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
924 // Enabling use of ANSI color codes because LLDB is using them to highlight
925 // text.
926 llvm::sys::Process::UseANSIEscapeCodes(true);
927#endif
928}
929
931
933 // Make sure we call this function only once. With the C++ global destructor
934 // chain having a list of debuggers and with code that can be running on
935 // other threads, we need to ensure this doesn't happen multiple times.
936 //
937 // The following functions call Debugger::Clear():
938 // Debugger::~Debugger();
939 // static void Debugger::Destroy(lldb::DebuggerSP &debugger_sp);
940 // static void Debugger::Terminate();
941 llvm::call_once(m_clear_once, [this]() {
945 m_listener_sp->Clear();
946 for (TargetSP target_sp : m_target_list.Targets()) {
947 if (target_sp) {
948 if (ProcessSP process_sp = target_sp->GetProcessSP())
949 process_sp->Finalize(false /* not destructing */);
950 target_sp->Destroy();
951 }
952 }
954
955 // Close the input file _before_ we close the input read communications
956 // class as it does NOT own the input file, our m_input_file does.
959
961
964 });
965}
966
968 return !m_command_interpreter_up->GetSynchronous();
969}
970
971void Debugger::SetAsyncExecution(bool async_execution) {
972 m_command_interpreter_up->SetSynchronous(!async_execution);
973}
974
975repro::DataRecorder *Debugger::GetInputRecorder() { return m_input_recorder; }
976
977static inline int OpenPipe(int fds[2], std::size_t size) {
978#ifdef _WIN32
979 return _pipe(fds, size, O_BINARY);
980#else
981 (void)size;
982 return pipe(fds);
983#endif
984}
985
987 Status result;
988 enum PIPES { READ, WRITE }; // Indexes for the read and write fds
989 int fds[2] = {-1, -1};
990
991 if (data == nullptr) {
992 result.SetErrorString("String data is null");
993 return result;
994 }
995
996 size_t size = strlen(data);
997 if (size == 0) {
998 result.SetErrorString("String data is empty");
999 return result;
1000 }
1001
1002 if (OpenPipe(fds, size) != 0) {
1003 result.SetErrorString(
1004 "can't create pipe file descriptors for LLDB commands");
1005 return result;
1006 }
1007
1008 int r = write(fds[WRITE], data, size);
1009 (void)r;
1010 // Close the write end of the pipe, so that the command interpreter will exit
1011 // when it consumes all the data.
1012 llvm::sys::Process::SafelyCloseFileDescriptor(fds[WRITE]);
1013
1014 // Open the read file descriptor as a FILE * that we can return as an input
1015 // handle.
1016 FILE *commands_file = fdopen(fds[READ], "rb");
1017 if (commands_file == nullptr) {
1018 result.SetErrorStringWithFormat("fdopen(%i, \"rb\") failed (errno = %i) "
1019 "when trying to open LLDB commands pipe",
1020 fds[READ], errno);
1021 llvm::sys::Process::SafelyCloseFileDescriptor(fds[READ]);
1022 return result;
1023 }
1024
1025 SetInputFile((FileSP)std::make_shared<NativeFile>(commands_file, true));
1026 return result;
1027}
1028
1030 assert(file_sp && file_sp->IsValid());
1031 m_input_file_sp = std::move(file_sp);
1032 // Save away the terminal state if that is relevant, so that we can restore
1033 // it in RestoreInputState.
1035}
1036
1038 assert(file_sp && file_sp->IsValid());
1039 m_output_stream_sp = std::make_shared<StreamFile>(file_sp);
1040}
1041
1043 assert(file_sp && file_sp->IsValid());
1044 m_error_stream_sp = std::make_shared<StreamFile>(file_sp);
1045}
1046
1048 int fd = GetInputFile().GetDescriptor();
1049 if (fd != File::kInvalidDescriptor)
1050 m_terminal_state.Save(fd, true);
1051}
1052
1054
1056 bool adopt_selected = true;
1057 ExecutionContextRef exe_ctx_ref(GetSelectedTarget().get(), adopt_selected);
1058 return ExecutionContext(exe_ctx_ref);
1059}
1060
1062 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1063 IOHandlerSP reader_sp(m_io_handler_stack.Top());
1064 if (reader_sp)
1065 reader_sp->Interrupt();
1066}
1067
1069 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1070 IOHandlerSP reader_sp(m_io_handler_stack.Top());
1071 if (reader_sp)
1072 reader_sp->GotEOF();
1073}
1074
1076 // The bottom input reader should be the main debugger input reader. We do
1077 // not want to close that one here.
1078 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1079 while (m_io_handler_stack.GetSize() > 1) {
1080 IOHandlerSP reader_sp(m_io_handler_stack.Top());
1081 if (reader_sp)
1082 PopIOHandler(reader_sp);
1083 }
1084}
1085
1087 IOHandlerSP reader_sp = m_io_handler_stack.Top();
1088 while (true) {
1089 if (!reader_sp)
1090 break;
1091
1092 reader_sp->Run();
1093 {
1094 std::lock_guard<std::recursive_mutex> guard(
1096
1097 // Remove all input readers that are done from the top of the stack
1098 while (true) {
1099 IOHandlerSP top_reader_sp = m_io_handler_stack.Top();
1100 if (top_reader_sp && top_reader_sp->GetIsDone())
1101 PopIOHandler(top_reader_sp);
1102 else
1103 break;
1104 }
1105 reader_sp = m_io_handler_stack.Top();
1106 }
1107 }
1109}
1110
1112 std::lock_guard<std::recursive_mutex> guard(m_io_handler_synchronous_mutex);
1113
1114 PushIOHandler(reader_sp);
1115 IOHandlerSP top_reader_sp = reader_sp;
1116
1117 while (top_reader_sp) {
1118 top_reader_sp->Run();
1119
1120 // Don't unwind past the starting point.
1121 if (top_reader_sp.get() == reader_sp.get()) {
1122 if (PopIOHandler(reader_sp))
1123 break;
1124 }
1125
1126 // If we pushed new IO handlers, pop them if they're done or restart the
1127 // loop to run them if they're not.
1128 while (true) {
1129 top_reader_sp = m_io_handler_stack.Top();
1130 if (top_reader_sp && top_reader_sp->GetIsDone()) {
1131 PopIOHandler(top_reader_sp);
1132 // Don't unwind past the starting point.
1133 if (top_reader_sp.get() == reader_sp.get())
1134 return;
1135 } else {
1136 break;
1137 }
1138 }
1139 }
1140}
1141
1143 return m_io_handler_stack.IsTop(reader_sp);
1144}
1145
1147 IOHandler::Type second_top_type) {
1148 return m_io_handler_stack.CheckTopIOHandlerTypes(top_type, second_top_type);
1149}
1150
1151void Debugger::PrintAsync(const char *s, size_t len, bool is_stdout) {
1152 bool printed = m_io_handler_stack.PrintAsync(s, len, is_stdout);
1153 if (!printed) {
1154 lldb::StreamFileSP stream =
1156 stream->Write(s, len);
1157 }
1158}
1159
1162}
1163
1166}
1167
1170}
1171
1173 return PopIOHandler(reader_sp);
1174}
1175
1177 bool cancel_top_handler) {
1178 PushIOHandler(reader_sp, cancel_top_handler);
1179}
1180
1182 StreamFileSP &err) {
1183 // Before an IOHandler runs, it must have in/out/err streams. This function
1184 // is called when one ore more of the streams are nullptr. We use the top
1185 // input reader's in/out/err streams, or fall back to the debugger file
1186 // handles, or we fall back onto stdin/stdout/stderr as a last resort.
1187
1188 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1189 IOHandlerSP top_reader_sp(m_io_handler_stack.Top());
1190 // If no STDIN has been set, then set it appropriately
1191 if (!in || !in->IsValid()) {
1192 if (top_reader_sp)
1193 in = top_reader_sp->GetInputFileSP();
1194 else
1195 in = GetInputFileSP();
1196 // If there is nothing, use stdin
1197 if (!in)
1198 in = std::make_shared<NativeFile>(stdin, false);
1199 }
1200 // If no STDOUT has been set, then set it appropriately
1201 if (!out || !out->GetFile().IsValid()) {
1202 if (top_reader_sp)
1203 out = top_reader_sp->GetOutputStreamFileSP();
1204 else
1205 out = GetOutputStreamSP();
1206 // If there is nothing, use stdout
1207 if (!out)
1208 out = std::make_shared<StreamFile>(stdout, false);
1209 }
1210 // If no STDERR has been set, then set it appropriately
1211 if (!err || !err->GetFile().IsValid()) {
1212 if (top_reader_sp)
1213 err = top_reader_sp->GetErrorStreamFileSP();
1214 else
1215 err = GetErrorStreamSP();
1216 // If there is nothing, use stderr
1217 if (!err)
1218 err = std::make_shared<StreamFile>(stderr, false);
1219 }
1220}
1221
1223 bool cancel_top_handler) {
1224 if (!reader_sp)
1225 return;
1226
1227 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1228
1229 // Get the current top input reader...
1230 IOHandlerSP top_reader_sp(m_io_handler_stack.Top());
1231
1232 // Don't push the same IO handler twice...
1233 if (reader_sp == top_reader_sp)
1234 return;
1235
1236 // Push our new input reader
1237 m_io_handler_stack.Push(reader_sp);
1238 reader_sp->Activate();
1239
1240 // Interrupt the top input reader to it will exit its Run() function and let
1241 // this new input reader take over
1242 if (top_reader_sp) {
1243 top_reader_sp->Deactivate();
1244 if (cancel_top_handler)
1245 top_reader_sp->Cancel();
1246 }
1247}
1248
1249bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) {
1250 if (!pop_reader_sp)
1251 return false;
1252
1253 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1254
1255 // The reader on the stop of the stack is done, so let the next read on the
1256 // stack refresh its prompt and if there is one...
1258 return false;
1259
1260 IOHandlerSP reader_sp(m_io_handler_stack.Top());
1261
1262 if (pop_reader_sp != reader_sp)
1263 return false;
1264
1265 reader_sp->Deactivate();
1266 reader_sp->Cancel();
1268
1269 reader_sp = m_io_handler_stack.Top();
1270 if (reader_sp)
1271 reader_sp->Activate();
1272
1273 return true;
1274}
1275
1277 return std::make_shared<StreamAsynchronousIO>(*this, true, GetUseColor());
1278}
1279
1281 return std::make_shared<StreamAsynchronousIO>(*this, false, GetUseColor());
1282}
1283
1285 std::lock_guard<std::mutex> guard(m_interrupt_mutex);
1287}
1288
1290 std::lock_guard<std::mutex> guard(m_interrupt_mutex);
1291 if (m_interrupt_requested > 0)
1293}
1294
1296 // This is the one we should call internally. This will return true either
1297 // if there's a debugger interrupt and we aren't on the IOHandler thread,
1298 // or if we are on the IOHandler thread and there's a CommandInterpreter
1299 // interrupt.
1301 std::lock_guard<std::mutex> guard(m_interrupt_mutex);
1302 return m_interrupt_requested != 0;
1303 }
1305}
1306
1308 std::string function_name, const llvm::formatv_object_base &payload)
1309 : m_function_name(std::move(function_name)),
1310 m_interrupt_time(std::chrono::system_clock::now()),
1311 m_thread_id(llvm::get_threadid()) {
1312 llvm::raw_string_ostream desc(m_description);
1313 desc << payload << "\n";
1314}
1315
1317 // For now, just log the description:
1318 Log *log = GetLog(LLDBLog::Host);
1319 LLDB_LOG(log, "Interruption: {0}", report.m_description);
1320}
1321
1323 DebuggerList result;
1325 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1326 for (auto debugger_sp : *g_debugger_list_ptr) {
1327 if (debugger_sp->InterruptRequested())
1328 result.push_back(debugger_sp);
1329 }
1330 }
1331 return result;
1332}
1333
1336 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1337 return g_debugger_list_ptr->size();
1338 }
1339 return 0;
1340}
1341
1343 DebuggerSP debugger_sp;
1344
1346 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1347 if (index < g_debugger_list_ptr->size())
1348 debugger_sp = g_debugger_list_ptr->at(index);
1349 }
1350
1351 return debugger_sp;
1352}
1353
1355 DebuggerSP debugger_sp;
1356
1358 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1359 DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
1360 for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
1361 if ((*pos)->GetID() == id) {
1362 debugger_sp = *pos;
1363 break;
1364 }
1365 }
1366 }
1367 return debugger_sp;
1368}
1369
1371 const SymbolContext *sc,
1372 const SymbolContext *prev_sc,
1373 const ExecutionContext *exe_ctx,
1374 const Address *addr, Stream &s) {
1375 FormatEntity::Entry format_entry;
1376
1377 if (format == nullptr) {
1378 if (exe_ctx != nullptr && exe_ctx->HasTargetScope())
1379 format = exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
1380 if (format == nullptr) {
1381 FormatEntity::Parse("${addr}: ", format_entry);
1382 format = &format_entry;
1383 }
1384 }
1385 bool function_changed = false;
1386 bool initial_function = false;
1387 if (prev_sc && (prev_sc->function || prev_sc->symbol)) {
1388 if (sc && (sc->function || sc->symbol)) {
1389 if (prev_sc->symbol && sc->symbol) {
1390 if (!sc->symbol->Compare(prev_sc->symbol->GetName(),
1391 prev_sc->symbol->GetType())) {
1392 function_changed = true;
1393 }
1394 } else if (prev_sc->function && sc->function) {
1395 if (prev_sc->function->GetMangled() != sc->function->GetMangled()) {
1396 function_changed = true;
1397 }
1398 }
1399 }
1400 }
1401 // The first context on a list of instructions will have a prev_sc that has
1402 // no Function or Symbol -- if SymbolContext had an IsValid() method, it
1403 // would return false. But we do get a prev_sc pointer.
1404 if ((sc && (sc->function || sc->symbol)) && prev_sc &&
1405 (prev_sc->function == nullptr && prev_sc->symbol == nullptr)) {
1406 initial_function = true;
1407 }
1408 return FormatEntity::Format(*format, s, sc, exe_ctx, addr, nullptr,
1409 function_changed, initial_function);
1410}
1411
1412void Debugger::AssertCallback(llvm::StringRef message,
1413 llvm::StringRef backtrace,
1414 llvm::StringRef prompt) {
1416 llvm::formatv("{0}\n{1}{2}", message, backtrace, prompt).str());
1417}
1418
1420 void *baton) {
1421 // For simplicity's sake, I am not going to deal with how to close down any
1422 // open logging streams, I just redirect everything from here on out to the
1423 // callback.
1425 std::make_shared<CallbackLogHandler>(log_callback, baton);
1426}
1427
1429 lldb_private::DebuggerDestroyCallback destroy_callback, void *baton) {
1430 m_destroy_callback = destroy_callback;
1432}
1433
1434static void PrivateReportProgress(Debugger &debugger, uint64_t progress_id,
1435 std::string title, std::string details,
1436 uint64_t completed, uint64_t total,
1437 bool is_debugger_specific,
1438 uint32_t progress_broadcast_bit) {
1439 // Only deliver progress events if we have any progress listeners.
1440 if (!debugger.GetBroadcaster().EventTypeHasListeners(progress_broadcast_bit))
1441 return;
1442
1443 EventSP event_sp(new Event(
1444 progress_broadcast_bit,
1445 new ProgressEventData(progress_id, std::move(title), std::move(details),
1446 completed, total, is_debugger_specific)));
1447 debugger.GetBroadcaster().BroadcastEvent(event_sp);
1448}
1449
1450void Debugger::ReportProgress(uint64_t progress_id, std::string title,
1451 std::string details, uint64_t completed,
1452 uint64_t total,
1453 std::optional<lldb::user_id_t> debugger_id,
1454 uint32_t progress_category_bit) {
1455 // Check if this progress is for a specific debugger.
1456 if (debugger_id) {
1457 // It is debugger specific, grab it and deliver the event if the debugger
1458 // still exists.
1459 DebuggerSP debugger_sp = FindDebuggerWithID(*debugger_id);
1460 if (debugger_sp)
1461 PrivateReportProgress(*debugger_sp, progress_id, std::move(title),
1462 std::move(details), completed, total,
1463 /*is_debugger_specific*/ true,
1464 progress_category_bit);
1465 return;
1466 }
1467 // The progress event is not debugger specific, iterate over all debuggers
1468 // and deliver a progress event to each one.
1470 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1471 DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
1472 for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos)
1473 PrivateReportProgress(*(*pos), progress_id, title, details, completed,
1474 total, /*is_debugger_specific*/ false,
1475 progress_category_bit);
1476 }
1477}
1478
1479static void PrivateReportDiagnostic(Debugger &debugger,
1481 std::string message,
1482 bool debugger_specific) {
1483 uint32_t event_type = 0;
1484 switch (type) {
1486 assert(false && "DiagnosticEventData::Type::Info should not be broadcast");
1487 return;
1489 event_type = Debugger::eBroadcastBitWarning;
1490 break;
1492 event_type = Debugger::eBroadcastBitError;
1493 break;
1494 }
1495
1496 Broadcaster &broadcaster = debugger.GetBroadcaster();
1497 if (!broadcaster.EventTypeHasListeners(event_type)) {
1498 // Diagnostics are too important to drop. If nobody is listening, print the
1499 // diagnostic directly to the debugger's error stream.
1500 DiagnosticEventData event_data(type, std::move(message), debugger_specific);
1501 StreamSP stream = debugger.GetAsyncErrorStream();
1502 event_data.Dump(stream.get());
1503 return;
1504 }
1505 EventSP event_sp = std::make_shared<Event>(
1506 event_type,
1507 new DiagnosticEventData(type, std::move(message), debugger_specific));
1508 broadcaster.BroadcastEvent(event_sp);
1509}
1510
1512 std::string message,
1513 std::optional<lldb::user_id_t> debugger_id,
1514 std::once_flag *once) {
1515 auto ReportDiagnosticLambda = [&]() {
1516 // The diagnostic subsystem is optional but we still want to broadcast
1517 // events when it's disabled.
1519 Diagnostics::Instance().Report(message);
1520
1521 // We don't broadcast info events.
1523 return;
1524
1525 // Check if this diagnostic is for a specific debugger.
1526 if (debugger_id) {
1527 // It is debugger specific, grab it and deliver the event if the debugger
1528 // still exists.
1529 DebuggerSP debugger_sp = FindDebuggerWithID(*debugger_id);
1530 if (debugger_sp)
1531 PrivateReportDiagnostic(*debugger_sp, type, std::move(message), true);
1532 return;
1533 }
1534 // The diagnostic event is not debugger specific, iterate over all debuggers
1535 // and deliver a diagnostic event to each one.
1537 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1538 for (const auto &debugger : *g_debugger_list_ptr)
1539 PrivateReportDiagnostic(*debugger, type, message, false);
1540 }
1541 };
1542
1543 if (once)
1544 std::call_once(*once, ReportDiagnosticLambda);
1545 else
1546 ReportDiagnosticLambda();
1547}
1548
1549void Debugger::ReportWarning(std::string message,
1550 std::optional<lldb::user_id_t> debugger_id,
1551 std::once_flag *once) {
1553 debugger_id, once);
1554}
1555
1556void Debugger::ReportError(std::string message,
1557 std::optional<lldb::user_id_t> debugger_id,
1558 std::once_flag *once) {
1560 debugger_id, once);
1561}
1562
1563void Debugger::ReportInfo(std::string message,
1564 std::optional<lldb::user_id_t> debugger_id,
1565 std::once_flag *once) {
1567 debugger_id, once);
1568}
1569
1572 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1573 for (DebuggerSP debugger_sp : *g_debugger_list_ptr) {
1574 EventSP event_sp = std::make_shared<Event>(
1576 new SymbolChangeEventData(debugger_sp, module_spec));
1577 debugger_sp->GetBroadcaster().BroadcastEvent(event_sp);
1578 }
1579 }
1580}
1581
1582static std::shared_ptr<LogHandler>
1583CreateLogHandler(LogHandlerKind log_handler_kind, int fd, bool should_close,
1584 size_t buffer_size) {
1585 switch (log_handler_kind) {
1586 case eLogHandlerStream:
1587 return std::make_shared<StreamLogHandler>(fd, should_close, buffer_size);
1589 return std::make_shared<RotatingLogHandler>(buffer_size);
1590 case eLogHandlerSystem:
1591 return std::make_shared<SystemLogHandler>();
1593 return {};
1594 }
1595 return {};
1596}
1597
1598bool Debugger::EnableLog(llvm::StringRef channel,
1599 llvm::ArrayRef<const char *> categories,
1600 llvm::StringRef log_file, uint32_t log_options,
1601 size_t buffer_size, LogHandlerKind log_handler_kind,
1602 llvm::raw_ostream &error_stream) {
1603
1604 std::shared_ptr<LogHandler> log_handler_sp;
1606 log_handler_sp = m_callback_handler_sp;
1607 // For now when using the callback mode you always get thread & timestamp.
1608 log_options |=
1610 } else if (log_file.empty()) {
1611 log_handler_sp =
1612 CreateLogHandler(log_handler_kind, GetOutputFile().GetDescriptor(),
1613 /*should_close=*/false, buffer_size);
1614 } else {
1615 auto pos = m_stream_handlers.find(log_file);
1616 if (pos != m_stream_handlers.end())
1617 log_handler_sp = pos->second.lock();
1618 if (!log_handler_sp) {
1619 File::OpenOptions flags =
1621 if (log_options & LLDB_LOG_OPTION_APPEND)
1622 flags |= File::eOpenOptionAppend;
1623 else
1625 llvm::Expected<FileUP> file = FileSystem::Instance().Open(
1626 FileSpec(log_file), flags, lldb::eFilePermissionsFileDefault, false);
1627 if (!file) {
1628 error_stream << "Unable to open log file '" << log_file
1629 << "': " << llvm::toString(file.takeError()) << "\n";
1630 return false;
1631 }
1632
1633 log_handler_sp =
1634 CreateLogHandler(log_handler_kind, (*file)->GetDescriptor(),
1635 /*should_close=*/true, buffer_size);
1636 m_stream_handlers[log_file] = log_handler_sp;
1637 }
1638 }
1639 assert(log_handler_sp);
1640
1641 if (log_options == 0)
1643
1644 return Log::EnableLogChannel(log_handler_sp, log_options, channel, categories,
1645 error_stream);
1646}
1647
1650 std::optional<lldb::ScriptLanguage> language) {
1651 std::lock_guard<std::recursive_mutex> locker(m_script_interpreter_mutex);
1652 lldb::ScriptLanguage script_language =
1653 language ? *language : GetScriptLanguage();
1654
1655 if (!m_script_interpreters[script_language]) {
1656 if (!can_create)
1657 return nullptr;
1658 m_script_interpreters[script_language] =
1659 PluginManager::GetScriptInterpreterForLanguage(script_language, *this);
1660 }
1661
1662 return m_script_interpreters[script_language].get();
1663}
1664
1667 m_source_manager_up = std::make_unique<SourceManager>(shared_from_this());
1668 return *m_source_manager_up;
1669}
1670
1671// This function handles events that were broadcast by the process.
1673 using namespace lldb;
1674 const uint32_t event_type =
1676 event_sp);
1677
1678 // if (event_type & eBreakpointEventTypeAdded
1679 // || event_type & eBreakpointEventTypeRemoved
1680 // || event_type & eBreakpointEventTypeEnabled
1681 // || event_type & eBreakpointEventTypeDisabled
1682 // || event_type & eBreakpointEventTypeCommandChanged
1683 // || event_type & eBreakpointEventTypeConditionChanged
1684 // || event_type & eBreakpointEventTypeIgnoreChanged
1685 // || event_type & eBreakpointEventTypeLocationsResolved)
1686 // {
1687 // // Don't do anything about these events, since the breakpoint
1688 // commands already echo these actions.
1689 // }
1690 //
1691 if (event_type & eBreakpointEventTypeLocationsAdded) {
1692 uint32_t num_new_locations =
1694 event_sp);
1695 if (num_new_locations > 0) {
1696 BreakpointSP breakpoint =
1698 StreamSP output_sp(GetAsyncOutputStream());
1699 if (output_sp) {
1700 output_sp->Printf("%d location%s added to breakpoint %d\n",
1701 num_new_locations, num_new_locations == 1 ? "" : "s",
1702 breakpoint->GetID());
1703 output_sp->Flush();
1704 }
1705 }
1706 }
1707 // else if (event_type & eBreakpointEventTypeLocationsRemoved)
1708 // {
1709 // // These locations just get disabled, not sure it is worth spamming
1710 // folks about this on the command line.
1711 // }
1712 // else if (event_type & eBreakpointEventTypeLocationsResolved)
1713 // {
1714 // // This might be an interesting thing to note, but I'm going to
1715 // leave it quiet for now, it just looked noisy.
1716 // }
1717}
1718
1719void Debugger::FlushProcessOutput(Process &process, bool flush_stdout,
1720 bool flush_stderr) {
1721 const auto &flush = [&](Stream &stream,
1722 size_t (Process::*get)(char *, size_t, Status &)) {
1723 Status error;
1724 size_t len;
1725 char buffer[1024];
1726 while ((len = (process.*get)(buffer, sizeof(buffer), error)) > 0)
1727 stream.Write(buffer, len);
1728 stream.Flush();
1729 };
1730
1731 std::lock_guard<std::mutex> guard(m_output_flush_mutex);
1732 if (flush_stdout)
1734 if (flush_stderr)
1736}
1737
1738// This function handles events that were broadcast by the process.
1740 using namespace lldb;
1741 const uint32_t event_type = event_sp->GetType();
1742 ProcessSP process_sp =
1746
1747 StreamSP output_stream_sp = GetAsyncOutputStream();
1748 StreamSP error_stream_sp = GetAsyncErrorStream();
1749 const bool gui_enabled = IsForwardingEvents();
1750
1751 if (!gui_enabled) {
1752 bool pop_process_io_handler = false;
1753 assert(process_sp);
1754
1755 bool state_is_stopped = false;
1756 const bool got_state_changed =
1757 (event_type & Process::eBroadcastBitStateChanged) != 0;
1758 const bool got_stdout = (event_type & Process::eBroadcastBitSTDOUT) != 0;
1759 const bool got_stderr = (event_type & Process::eBroadcastBitSTDERR) != 0;
1760 const bool got_structured_data =
1761 (event_type & Process::eBroadcastBitStructuredData) != 0;
1762
1763 if (got_state_changed) {
1764 StateType event_state =
1766 state_is_stopped = StateIsStoppedState(event_state, false);
1767 }
1768
1769 // Display running state changes first before any STDIO
1770 if (got_state_changed && !state_is_stopped) {
1771 // This is a public stop which we are going to announce to the user, so
1772 // we should force the most relevant frame selection here.
1773 Process::HandleProcessStateChangedEvent(event_sp, output_stream_sp.get(),
1775 pop_process_io_handler);
1776 }
1777
1778 // Now display STDOUT and STDERR
1779 FlushProcessOutput(*process_sp, got_stdout || got_state_changed,
1780 got_stderr || got_state_changed);
1781
1782 // Give structured data events an opportunity to display.
1783 if (got_structured_data) {
1784 StructuredDataPluginSP plugin_sp =
1786 if (plugin_sp) {
1787 auto structured_data_sp =
1789 if (output_stream_sp) {
1790 StreamString content_stream;
1791 Status error =
1792 plugin_sp->GetDescription(structured_data_sp, content_stream);
1793 if (error.Success()) {
1794 if (!content_stream.GetString().empty()) {
1795 // Add newline.
1796 content_stream.PutChar('\n');
1797 content_stream.Flush();
1798
1799 // Print it.
1800 output_stream_sp->PutCString(content_stream.GetString());
1801 }
1802 } else {
1803 error_stream_sp->Format("Failed to print structured "
1804 "data with plugin {0}: {1}",
1805 plugin_sp->GetPluginName(), error);
1806 }
1807 }
1808 }
1809 }
1810
1811 // Now display any stopped state changes after any STDIO
1812 if (got_state_changed && state_is_stopped) {
1813 Process::HandleProcessStateChangedEvent(event_sp, output_stream_sp.get(),
1815 pop_process_io_handler);
1816 }
1817
1818 output_stream_sp->Flush();
1819 error_stream_sp->Flush();
1820
1821 if (pop_process_io_handler)
1822 process_sp->PopProcessIOHandler();
1823 }
1824}
1825
1827 // At present the only thread event we handle is the Frame Changed event, and
1828 // all we do for that is just reprint the thread status for that thread.
1829 using namespace lldb;
1830 const uint32_t event_type = event_sp->GetType();
1831 const bool stop_format = true;
1832 if (event_type == Thread::eBroadcastBitStackChanged ||
1834 ThreadSP thread_sp(
1836 if (thread_sp) {
1837 thread_sp->GetStatus(*GetAsyncOutputStream(), 0, 1, 1, stop_format);
1838 }
1839 }
1840}
1841
1843
1845 m_forward_listener_sp = listener_sp;
1846}
1847
1849 m_forward_listener_sp.reset();
1850}
1851
1853 ListenerSP listener_sp(GetListener());
1854 ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass());
1855 ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass());
1856 ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass());
1857 BroadcastEventSpec target_event_spec(broadcaster_class_target,
1859
1860 BroadcastEventSpec process_event_spec(
1861 broadcaster_class_process,
1864
1865 BroadcastEventSpec thread_event_spec(broadcaster_class_thread,
1868
1869 listener_sp->StartListeningForEventSpec(m_broadcaster_manager_sp,
1870 target_event_spec);
1871 listener_sp->StartListeningForEventSpec(m_broadcaster_manager_sp,
1872 process_event_spec);
1873 listener_sp->StartListeningForEventSpec(m_broadcaster_manager_sp,
1874 thread_event_spec);
1875 listener_sp->StartListeningForEvents(
1880
1881 listener_sp->StartListeningForEvents(
1884
1885 // Let the thread that spawned us know that we have started up and that we
1886 // are now listening to all required events so no events get missed
1888
1889 bool done = false;
1890 while (!done) {
1891 EventSP event_sp;
1892 if (listener_sp->GetEvent(event_sp, std::nullopt)) {
1893 if (event_sp) {
1894 Broadcaster *broadcaster = event_sp->GetBroadcaster();
1895 if (broadcaster) {
1896 uint32_t event_type = event_sp->GetType();
1897 ConstString broadcaster_class(broadcaster->GetBroadcasterClass());
1898 if (broadcaster_class == broadcaster_class_process) {
1899 HandleProcessEvent(event_sp);
1900 } else if (broadcaster_class == broadcaster_class_target) {
1902 event_sp.get())) {
1903 HandleBreakpointEvent(event_sp);
1904 }
1905 } else if (broadcaster_class == broadcaster_class_thread) {
1906 HandleThreadEvent(event_sp);
1907 } else if (broadcaster == m_command_interpreter_up.get()) {
1908 if (event_type &
1910 done = true;
1911 } else if (event_type &
1913 const char *data = static_cast<const char *>(
1914 EventDataBytes::GetBytesFromEvent(event_sp.get()));
1915 if (data && data[0]) {
1916 StreamSP error_sp(GetAsyncErrorStream());
1917 if (error_sp) {
1918 error_sp->PutCString(data);
1919 error_sp->Flush();
1920 }
1921 }
1922 } else if (event_type & CommandInterpreter::
1923 eBroadcastBitAsynchronousOutputData) {
1924 const char *data = static_cast<const char *>(
1925 EventDataBytes::GetBytesFromEvent(event_sp.get()));
1926 if (data && data[0]) {
1927 StreamSP output_sp(GetAsyncOutputStream());
1928 if (output_sp) {
1929 output_sp->PutCString(data);
1930 output_sp->Flush();
1931 }
1932 }
1933 }
1934 } else if (broadcaster == &m_broadcaster) {
1935 if (event_type & Debugger::eBroadcastBitProgress)
1936 HandleProgressEvent(event_sp);
1937 else if (event_type & Debugger::eBroadcastBitWarning)
1938 HandleDiagnosticEvent(event_sp);
1939 else if (event_type & Debugger::eBroadcastBitError)
1940 HandleDiagnosticEvent(event_sp);
1941 }
1942 }
1943
1945 m_forward_listener_sp->AddEvent(event_sp);
1946 }
1947 }
1948 }
1949 return {};
1950}
1951
1954 // We must synchronize with the DefaultEventHandler() thread to ensure it
1955 // is up and running and listening to events before we return from this
1956 // function. We do this by listening to events for the
1957 // eBroadcastBitEventThreadIsListening from the m_sync_broadcaster
1958 ConstString full_name("lldb.debugger.event-handler");
1959 ListenerSP listener_sp(Listener::MakeListener(full_name.AsCString()));
1960 listener_sp->StartListeningForEvents(&m_sync_broadcaster,
1962
1963 llvm::StringRef thread_name =
1964 full_name.GetLength() < llvm::get_max_thread_name_length()
1965 ? full_name.GetStringRef()
1966 : "dbg.evt-handler";
1967
1968 // Use larger 8MB stack for this thread
1969 llvm::Expected<HostThread> event_handler_thread =
1971 thread_name, [this] { return DefaultEventHandler(); },
1973
1974 if (event_handler_thread) {
1975 m_event_handler_thread = *event_handler_thread;
1976 } else {
1977 LLDB_LOG_ERROR(GetLog(LLDBLog::Host), event_handler_thread.takeError(),
1978 "failed to launch host thread: {0}");
1979 }
1980
1981 // Make sure DefaultEventHandler() is running and listening to events
1982 // before we return from this function. We are only listening for events of
1983 // type eBroadcastBitEventThreadIsListening so we don't need to check the
1984 // event, we just need to wait an infinite amount of time for it (nullptr
1985 // timeout as the first parameter)
1986 lldb::EventSP event_sp;
1987 listener_sp->GetEvent(event_sp, std::nullopt);
1988 }
1990}
1991
1997 }
1998}
1999
2001 RunIOHandlers();
2003 return {};
2004}
2005
2007 auto *data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
2008 if (!data)
2009 return;
2010
2011 // Do some bookkeeping for the current event, regardless of whether we're
2012 // going to show the progress.
2013 const uint64_t id = data->GetID();
2014 if (m_current_event_id) {
2015 Log *log = GetLog(LLDBLog::Events);
2016 if (log && log->GetVerbose()) {
2017 StreamString log_stream;
2018 log_stream.AsRawOstream()
2019 << static_cast<void *>(this) << " Debugger(" << GetID()
2020 << ")::HandleProgressEvent( m_current_event_id = "
2021 << *m_current_event_id << ", data = { ";
2022 data->Dump(&log_stream);
2023 log_stream << " } )";
2024 log->PutString(log_stream.GetString());
2025 }
2026 if (id != *m_current_event_id)
2027 return;
2028 if (data->GetCompleted() == data->GetTotal())
2029 m_current_event_id.reset();
2030 } else {
2032 }
2033
2034 // Decide whether we actually are going to show the progress. This decision
2035 // can change between iterations so check it inside the loop.
2036 if (!GetShowProgress())
2037 return;
2038
2039 // Determine whether the current output file is an interactive terminal with
2040 // color support. We assume that if we support ANSI escape codes we support
2041 // vt100 escape codes.
2042 File &file = GetOutputFile();
2043 if (!file.GetIsInteractive() || !file.GetIsTerminalWithColors())
2044 return;
2045
2046 StreamSP output = GetAsyncOutputStream();
2047
2048 // Print over previous line, if any.
2049 output->Printf("\r");
2050
2051 if (data->GetCompleted() == data->GetTotal()) {
2052 // Clear the current line.
2053 output->Printf("\x1B[2K");
2054 output->Flush();
2055 return;
2056 }
2057
2058 // Trim the progress message if it exceeds the window's width and print it.
2059 std::string message = data->GetMessage();
2060 if (data->IsFinite())
2061 message = llvm::formatv("[{0}/{1}] {2}", data->GetCompleted(),
2062 data->GetTotal(), message)
2063 .str();
2064
2065 // Trim the progress message if it exceeds the window's width and print it.
2066 const uint32_t term_width = GetTerminalWidth();
2067 const uint32_t ellipsis = 3;
2068 if (message.size() + ellipsis >= term_width)
2069 message = message.substr(0, term_width - ellipsis);
2070
2071 const bool use_color = GetUseColor();
2072 llvm::StringRef ansi_prefix = GetShowProgressAnsiPrefix();
2073 if (!ansi_prefix.empty())
2074 output->Printf(
2075 "%s", ansi::FormatAnsiTerminalCodes(ansi_prefix, use_color).c_str());
2076
2077 output->Printf("%s...", message.c_str());
2078
2079 llvm::StringRef ansi_suffix = GetShowProgressAnsiSuffix();
2080 if (!ansi_suffix.empty())
2081 output->Printf(
2082 "%s", ansi::FormatAnsiTerminalCodes(ansi_suffix, use_color).c_str());
2083
2084 // Clear until the end of the line.
2085 output->Printf("\x1B[K\r");
2086
2087 // Flush the output.
2088 output->Flush();
2089}
2090
2092 auto *data = DiagnosticEventData::GetEventDataFromEvent(event_sp.get());
2093 if (!data)
2094 return;
2095
2096 StreamSP stream = GetAsyncErrorStream();
2097 data->Dump(stream.get());
2098}
2099
2102}
2103
2106 m_io_handler_thread = new_thread;
2107 return old_host;
2108}
2109
2112 llvm::Expected<HostThread> io_handler_thread = ThreadLauncher::LaunchThread(
2113 "lldb.debugger.io-handler", [this] { return IOHandlerThread(); },
2114 8 * 1024 * 1024); // Use larger 8MB stack for this thread
2115 if (io_handler_thread) {
2116 m_io_handler_thread = *io_handler_thread;
2117 } else {
2118 LLDB_LOG_ERROR(GetLog(LLDBLog::Host), io_handler_thread.takeError(),
2119 "failed to launch host thread: {0}");
2120 }
2121 }
2123}
2124
2127 GetInputFile().Close();
2128 m_io_handler_thread.Join(nullptr);
2129 }
2130}
2131
2133 if (HasIOHandlerThread()) {
2134 thread_result_t result;
2135 m_io_handler_thread.Join(&result);
2137 }
2138}
2139
2141 if (!HasIOHandlerThread())
2142 return false;
2144}
2145
2147 if (!prefer_dummy) {
2149 return *target;
2150 }
2151 return GetDummyTarget();
2152}
2153
2154Status Debugger::RunREPL(LanguageType language, const char *repl_options) {
2155 Status err;
2156 FileSpec repl_executable;
2157
2158 if (language == eLanguageTypeUnknown)
2159 language = GetREPLLanguage();
2160
2161 if (language == eLanguageTypeUnknown) {
2163
2164 if (auto single_lang = repl_languages.GetSingularLanguage()) {
2165 language = *single_lang;
2166 } else if (repl_languages.Empty()) {
2167 err.SetErrorString(
2168 "LLDB isn't configured with REPL support for any languages.");
2169 return err;
2170 } else {
2171 err.SetErrorString(
2172 "Multiple possible REPL languages. Please specify a language.");
2173 return err;
2174 }
2175 }
2176
2177 Target *const target =
2178 nullptr; // passing in an empty target means the REPL must create one
2179
2180 REPLSP repl_sp(REPL::Create(err, language, this, target, repl_options));
2181
2182 if (!err.Success()) {
2183 return err;
2184 }
2185
2186 if (!repl_sp) {
2187 err.SetErrorStringWithFormat("couldn't find a REPL for %s",
2189 return err;
2190 }
2191
2192 repl_sp->SetCompilerOptions(repl_options);
2193 repl_sp->RunLoop();
2194
2195 return err;
2196}
2197
2198llvm::ThreadPoolInterface &Debugger::GetThreadPool() {
2199 assert(g_thread_pool &&
2200 "Debugger::GetThreadPool called before Debugger::Initialize");
2201 return *g_thread_pool;
2202}
static llvm::raw_ostream & error(Stream &strm)
static void PrivateReportDiagnostic(Debugger &debugger, DiagnosticEventData::Type type, std::string message, bool debugger_specific)
Definition: Debugger.cpp:1479
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 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:1434
static Debugger::DebuggerList * g_debugger_list_ptr
Definition: Debugger.cpp:105
static int OpenPipe(int fds[2], std::size_t size)
Definition: Debugger.cpp:977
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:1583
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:342
#define LLDB_LOG_OPTION_APPEND
Definition: Log.h:42
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:365
#define LLDB_LOG_OPTION_PREPEND_TIMESTAMP
Definition: Log.h:38
#define LLDB_LOG_OPTION_PREPEND_THREAD_NAME
Definition: Log.h:40
PIPES
Definition: PipePosix.cpp:30
@ WRITE
Definition: PipePosix.cpp:30
@ READ
Definition: PipePosix.cpp:30
A section + offset based address class.
Definition: Address.h: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:145
bool EventTypeHasListeners(uint32_t event_type)
Definition: Broadcaster.h:250
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:167
void UpdatePrompt(llvm::StringRef prompt)
bool SaveTranscript(CommandReturnObject &result, std::optional< std::string > output_file=std::nullopt)
Save the current debugger session transcript to a file on disk.
A uniqued constant string class.
Definition: ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:188
size_t GetLength() const
Get the length in bytes of string value.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:197
InterruptionReport(std::string function_name, std::string description)
Definition: Debugger.h:463
A class to manage flag bits.
Definition: Debugger.h:79
static void AssertCallback(llvm::StringRef message, llvm::StringRef backtrace, llvm::StringRef prompt)
Definition: Debugger.cpp:1412
llvm::StringRef GetAutosuggestionAnsiPrefix() const
Definition: Debugger.cpp:445
repro::DataRecorder * GetInputRecorder()
Definition: Debugger.cpp:975
lldb::StreamFileSP m_error_stream_sp
Definition: Debugger.h:683
bool SetUseExternalEditor(bool use_external_editor_p)
Definition: Debugger.cpp:387
PlatformList m_platform_list
Definition: Debugger.h:697
HostThread m_event_handler_thread
Definition: Debugger.h:725
static lldb::TargetSP FindTargetWithProcessID(lldb::pid_t pid)
Definition: Debugger.cpp:798
uint64_t GetDisassemblyLineCount() const
Definition: Debugger.cpp:540
lldb::TargetSP GetSelectedTarget()
Definition: Debugger.h:193
bool SetExternalEditor(llvm::StringRef editor)
Definition: Debugger.cpp:398
void RequestInterrupt()
Interruption in LLDB:
Definition: Debugger.cpp:1284
void ReportInterruption(const InterruptionReport &report)
Definition: Debugger.cpp:1316
ExecutionContext GetSelectedExecutionContext()
Definition: Debugger.cpp:1055
static void Terminate()
Definition: Debugger.cpp:616
void HandleProgressEvent(const lldb::EventSP &event_sp)
Definition: Debugger.cpp:2006
SourceManager & GetSourceManager()
Definition: Debugger.cpp:1665
bool SetShowProgress(bool show_progress)
Definition: Debugger.cpp:422
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=eBroadcastBitProgress)
Report progress events.
Definition: Debugger.cpp:1450
lldb::StreamSP GetAsyncOutputStream()
Definition: Debugger.cpp:1276
bool StartEventHandlerThread()
Manually start the global event handler thread.
Definition: Debugger.cpp:1952
bool SetUseSourceCache(bool use_source_cache)
Definition: Debugger.cpp:481
void StopEventHandlerThread()
Manually stop the debugger's default event handler.
Definition: Debugger.cpp:1992
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:1563
void SetAsyncExecution(bool async)
Definition: Debugger.cpp:971
HostThread SetIOHandlerThread(HostThread &new_thread)
Definition: Debugger.cpp:2104
void CancelForwardEvents(const lldb::ListenerSP &listener_sp)
Definition: Debugger.cpp:1848
bool GetPrintDecls() const
Definition: Debugger.cpp:569
lldb::FileSP GetInputFileSP()
Definition: Debugger.h:142
bool GetHighlightSource() const
Definition: Debugger.cpp:489
llvm::StringMap< std::weak_ptr< LogHandler > > m_stream_handlers
Definition: Debugger.h:719
CommandInterpreter & GetCommandInterpreter()
Definition: Debugger.h:176
LoadedPluginsList m_loaded_plugins
Definition: Debugger.h:724
bool SetTabSize(uint64_t tab_size)
Definition: Debugger.cpp:586
void HandleDiagnosticEvent(const lldb::EventSP &event_sp)
Definition: Debugger.cpp:2091
static lldb::DebuggerSP GetDebuggerAtIndex(size_t index)
Definition: Debugger.cpp:1342
llvm::StringRef GetAutosuggestionAnsiSuffix() const
Definition: Debugger.cpp:451
StreamFile & GetErrorStream()
Definition: Debugger.h:156
lldb::ListenerSP m_listener_sp
Definition: Debugger.h:698
void PushIOHandler(const lldb::IOHandlerSP &reader_sp, bool cancel_top_handler=true)
Definition: Debugger.cpp:1222
lldb::thread_result_t IOHandlerThread()
Definition: Debugger.cpp:2000
static lldb::TargetSP FindTargetWithProcess(Process *process)
Definition: Debugger.cpp:812
bool GetUseExternalEditor() const
Definition: Debugger.cpp:381
TerminalState m_terminal_state
Definition: Debugger.h:694
static void ReportDiagnosticImpl(DiagnosticEventData::Type type, std::string message, std::optional< lldb::user_id_t > debugger_id, std::once_flag *once)
Definition: Debugger.cpp:1511
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:731
std::unique_ptr< CommandInterpreter > m_command_interpreter_up
Definition: Debugger.h:708
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:1549
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:1370
static void SettingsInitialize()
Definition: Debugger.cpp:642
static llvm::ThreadPoolInterface & GetThreadPool()
Shared thread pool. Use only with ThreadPoolTaskGroup.
Definition: Debugger.cpp:2198
llvm::StringRef GetShowProgressAnsiSuffix() const
Definition: Debugger.cpp:433
bool IsTopIOHandler(const lldb::IOHandlerSP &reader_sp)
Definition: Debugger.cpp:1142
bool HasIOHandlerThread() const
Definition: Debugger.cpp:2100
bool IsIOHandlerThreadCurrentThread() const
Definition: Debugger.cpp:2140
lldb::ListenerSP m_forward_listener_sp
Definition: Debugger.h:729
std::array< lldb::ScriptInterpreterSP, lldb::eScriptLanguageUnknown > m_script_interpreters
Definition: Debugger.h:712
std::shared_ptr< CallbackLogHandler > m_callback_handler_sp
Definition: Debugger.h:720
void SetDestroyCallback(lldb_private::DebuggerDestroyCallback destroy_callback, void *baton)
Definition: Debugger.cpp:1428
void * m_destroy_callback_baton
Definition: Debugger.h:735
StopDisassemblyType GetStopDisassemblyDisplay() const
Definition: Debugger.cpp:533
Broadcaster m_broadcaster
Public Debugger event broadcaster.
Definition: Debugger.h:728
static void Initialize(LoadPluginCallbackType load_plugin_callback)
Definition: Debugger.cpp:607
static lldb::DebuggerSP FindDebuggerWithInstanceName(llvm::StringRef instance_name)
Definition: Debugger.cpp:783
uint64_t GetTerminalWidth() const
Definition: Debugger.cpp:367
std::mutex m_interrupt_mutex
Definition: Debugger.h:738
std::recursive_mutex m_io_handler_synchronous_mutex
Definition: Debugger.h:715
bool RemoveIOHandler(const lldb::IOHandlerSP &reader_sp)
Remove the given IO handler if it's currently active.
Definition: Debugger.cpp:1172
Diagnostics::CallbackID m_diagnostics_callback_id
Definition: Debugger.h:732
bool GetAutoOneLineSummaries() const
Definition: Debugger.cpp:546
const char * GetIOHandlerCommandPrefix()
Definition: Debugger.cpp:1164
bool GetUseColor() const
Definition: Debugger.cpp:403
lldb::BroadcasterManagerSP m_broadcaster_manager_sp
Definition: Debugger.h:688
Status RunREPL(lldb::LanguageType language, const char *repl_options)
Definition: Debugger.cpp:2154
bool PopIOHandler(const lldb::IOHandlerSP &reader_sp)
Definition: Debugger.cpp:1249
static LoadPluginCallbackType g_load_plugin_callback
Definition: Debugger.h:722
std::recursive_mutex m_script_interpreter_mutex
Definition: Debugger.h:710
void RunIOHandlerAsync(const lldb::IOHandlerSP &reader_sp, bool cancel_top_handler=true)
Run the given IO handler and return immediately.
Definition: Debugger.cpp:1176
void SetInputFile(lldb::FileSP file)
Definition: Debugger.cpp:1029
lldb::StreamFileSP GetErrorStreamSP()
Definition: Debugger.h:146
void SetPrompt(llvm::StringRef p)
Definition: Debugger.cpp:324
lldb::StreamSP GetAsyncErrorStream()
Definition: Debugger.cpp:1280
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:1598
uint64_t GetStopDisassemblyMaxSize() const
Definition: Debugger.cpp:294
Broadcaster m_sync_broadcaster
Private debugger synchronization.
Definition: Debugger.h:727
void RestoreInputTerminalState()
Definition: Debugger.cpp:1053
bool GetUseSourceCache() const
Definition: Debugger.cpp:475
HostThread m_io_handler_thread
Definition: Debugger.h:726
llvm::StringRef GetRegexMatchAnsiSuffix() const
Definition: Debugger.cpp:463
static llvm::StringRef GetStaticBroadcasterClass()
Definition: Debugger.cpp:826
lldb::FileSP m_input_file_sp
Definition: Debugger.h:681
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:1042
bool GetAutoConfirm() const
Definition: Debugger.cpp:273
TargetList m_target_list
Definition: Debugger.h:695
lldb::ScriptLanguage GetScriptLanguage() const
Definition: Debugger.cpp:345
std::unique_ptr< SourceManager > m_source_manager_up
Definition: Debugger.h:699
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:1570
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:1556
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:1037
uint64_t GetStopSourceLineCount(bool before) const
Definition: Debugger.cpp:526
void EnableForwardEvents(const lldb::ListenerSP &listener_sp)
Definition: Debugger.cpp:1844
@ eBroadcastBitEventThreadIsListening
Definition: Debugger.h:742
static lldb::DebuggerSP FindDebuggerWithID(lldb::user_id_t id)
Definition: Debugger.cpp:1354
void HandleBreakpointEvent(const lldb::EventSP &event_sp)
Definition: Debugger.cpp:1672
bool CheckTopIOHandlerTypes(IOHandler::Type top_type, IOHandler::Type second_top_type)
Definition: Debugger.cpp:1146
Target & GetDummyTarget()
Definition: Debugger.h:496
const FormatEntity::Entry * GetFrameFormat() const
Definition: Debugger.cpp:284
lldb::ListenerSP GetListener()
Definition: Debugger.h:185
static void Destroy(lldb::DebuggerSP &debugger_sp)
Definition: Debugger.cpp:752
SourceManager::SourceFileCache m_source_file_cache
Definition: Debugger.h:703
llvm::StringRef GetPromptAnsiPrefix() const
Definition: Debugger.cpp:312
std::optional< uint64_t > m_current_event_id
Definition: Debugger.h:717
void RunIOHandlerSync(const lldb::IOHandlerSP &reader_sp)
Run the given IO handler and block until it's complete.
Definition: Debugger.cpp:1111
const FormatEntity::Entry * GetThreadFormat() const
Definition: Debugger.cpp:335
Broadcaster & GetBroadcaster()
Get the public broadcaster for this debugger.
Definition: Debugger.h:95
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:682
bool GetShowProgress() const
Definition: Debugger.cpp:416
llvm::StringRef GetRegexMatchAnsiPrefix() const
Definition: Debugger.cpp:457
std::mutex m_output_flush_mutex
Definition: Debugger.h:676
llvm::StringRef GetStopShowLineMarkerAnsiSuffix() const
Definition: Debugger.cpp:520
bool SetUseColor(bool use_color)
Definition: Debugger.cpp:409
lldb_private::DebuggerDestroyCallback m_destroy_callback
Definition: Debugger.h:734
const char * GetIOHandlerHelpPrologue()
Definition: Debugger.cpp:1168
Status SetInputString(const char *data)
Definition: Debugger.cpp:986
bool GetUseAutosuggestion() const
Definition: Debugger.cpp:439
Target & GetSelectedOrDummyTarget(bool prefer_dummy=false)
Definition: Debugger.cpp:2146
void HandleProcessEvent(const lldb::EventSP &event_sp)
Definition: Debugger.cpp:1739
IOHandlerStack m_io_handler_stack
Definition: Debugger.h:714
repro::DataRecorder * m_input_recorder
Used for shadowing the input file when capturing a reproducer.
Definition: Debugger.h:686
lldb::StreamFileSP GetOutputStreamSP()
Definition: Debugger.h:144
llvm::once_flag m_clear_once
Definition: Debugger.h:730
void AdoptTopIOHandlerFilesIfInvalid(lldb::FileSP &in, lldb::StreamFileSP &out, lldb::StreamFileSP &err)
Definition: Debugger.cpp:1181
static void SettingsTerminate()
Definition: Debugger.cpp:644
lldb::LanguageType GetREPLLanguage() const
Definition: Debugger.cpp:357
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, std::optional< lldb::ScriptLanguage > language={})
Definition: Debugger.cpp:1649
void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton)
Definition: Debugger.cpp:1419
bool SetTerminalWidth(uint64_t term_width)
Definition: Debugger.cpp:373
Debugger(lldb::LogOutputCallback m_log_callback, void *baton)
Definition: Debugger.cpp:831
llvm::StringRef GetExternalEditor() const
Definition: Debugger.cpp:392
void HandleThreadEvent(const lldb::EventSP &event_sp)
Definition: Debugger.cpp:1826
static size_t GetNumDebuggers()
Definition: Debugger.cpp:1334
File & GetOutputFile()
Definition: Debugger.h:150
uint32_t m_interrupt_requested
Tracks interrupt requests.
Definition: Debugger.h:737
lldb::DWIMPrintVerbosity GetDWIMPrintVerbosity() const
Definition: Debugger.cpp:591
lldb::thread_result_t DefaultEventHandler()
Definition: Debugger.cpp:1852
void PrintAsync(const char *s, size_t len, bool is_stdout)
Definition: Debugger.cpp:1151
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:1160
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:1719
void CancelInterruptRequest()
Decrement the "interrupt requested" counter.
Definition: Debugger.cpp:1289
std::vector< lldb::DebuggerSP > DebuggerList
Definition: Debugger.h:90
bool SetAutoIndent(bool b)
Definition: Debugger.cpp:564
llvm::StringRef GetStopShowColumnAnsiPrefix() const
Definition: Debugger.cpp:502
static DebuggerList DebuggersRequestingInterruption()
Definition: Debugger.cpp:1322
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:140
static lldb::ProcessSP GetProcessFromEvent(const Event *event_ptr)
Definition: Event.cpp:241
static lldb::StructuredDataPluginSP GetPluginFromEvent(const Event *event_ptr)
Definition: Event.cpp:259
static StructuredData::ObjectSP GetObjectFromEvent(const Event *event_ptr)
Definition: Event.cpp:250
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 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:44
static LanguageSet GetLanguagesSupportingREPLs()
Definition: Language.cpp:431
static const char * GetNameForLanguageType(lldb::LanguageType language)
Definition: Language.cpp:265
static LanguageProperties & GetGlobalLanguageProperties()
Definition: Language.cpp:39
static lldb::ListenerSP MakeListener(const char *name)
Definition: Listener.cpp:385
static bool EnableLogChannel(const std::shared_ptr< LogHandler > &log_handler_sp, uint32_t log_options, llvm::StringRef channel, llvm::ArrayRef< const char * > categories, llvm::raw_ostream &error_stream)
Definition: Log.cpp:223
bool GetVerbose() const
Definition: Log.cpp:313
void PutString(llvm::StringRef str)
Definition: Log.cpp:136
static ModuleListProperties & GetGlobalModuleListProperties()
Definition: ModuleList.cpp:763
void Append(const lldb::PlatformSP &platform_sp, bool set_selected)
Definition: Platform.h:1032
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:4166
static lldb::StateType GetStateFromEvent(const Event *event_ptr)
Definition: Process.cpp:4174
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:719
static llvm::StringRef GetStaticBroadcasterClass()
Definition: Process.cpp:411
virtual size_t GetSTDERR(char *buf, size_t buf_size, Status &error)
Get any available STDERR.
Definition: Process.cpp:4369
virtual size_t GetSTDOUT(char *buf, size_t buf_size, Status &error)
Get any available STDOUT.
Definition: Process.cpp:4350
static const ProgressEventData * GetEventDataFromEvent(const Event *event_ptr)
lldb::OptionValuePropertiesSP m_collection_sp
virtual Status SetPropertyValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef property_path, llvm::StringRef value)
bool SetPropertyAtIndex(uint32_t idx, T t, const ExecutionContext *exe_ctx=nullptr) const
virtual lldb::OptionValuePropertiesSP GetValueProperties() const
static lldb::REPLSP Create(Status &Status, lldb::LanguageType language, Debugger *debugger, Target *target, const char *repl_options)
Get a REPL with an existing target (or, failing that, a debugger to use), and (optional) extra argume...
Definition: REPL.cpp:38
An error handling class.
Definition: Status.h:44
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
Definition: Status.cpp:247
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:233
bool Success() const
Test for success condition.
Definition: Status.cpp:279
void Flush() override
Flush the stream.
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
Definition: Stream.h: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:390
ConstString GetName() const
Definition: Symbol.cpp:552
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:2599
Debugger & GetDebugger()
Definition: Target.h:1055
@ eBroadcastBitBreakpointChanged
Definition: Target.h:492
static llvm::StringRef GetStaticBroadcasterClass()
Definition: Target.cpp:90
static TargetProperties & GetGlobalProperties()
Definition: Target.cpp:3055
static ArchSpec GetDefaultArchitecture()
Definition: Target.cpp:2609
static void SettingsInitialize()
Definition: Target.cpp:2597
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:74
@ eBroadcastBitStackChanged
Definition: Thread.h:70
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.
Definition: SBAttachInfo.h:14
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:314
LoadScriptFromSymFile
Definition: Target.h:50
@ eLoadScriptFromSymFileTrue
Definition: Target.h:51
@ eLoadScriptFromSymFileFalse
Definition: Target.h:52
@ eLoadScriptFromSymFileWarn
Definition: Target.h:53
void(* DebuggerDestroyCallback)(lldb::user_id_t debugger_id, void *baton)
bool StateIsStoppedState(lldb::StateType state, bool must_exist)
Check if a state represents a state where the process or thread is stopped.
Definition: State.cpp:89
llvm::sys::DynamicLibrary(* LoadPluginCallbackType)(const lldb::DebuggerSP &debugger_sp, const FileSpec &spec, Status &error)
VarSetOperationType
Settable state variable types.
Definition: SBAddress.h:15
ScriptLanguage
Script interpreter types.
@ eScriptLanguageDefault
@ eScriptLanguageNone
@ eScriptLanguagePython
std::shared_ptr< lldb_private::IOHandler > IOHandlerSP
Definition: lldb-forward.h:353
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:438
void * thread_result_t
Definition: lldb-types.h:62
std::shared_ptr< lldb_private::Platform > PlatformSP
Definition: lldb-forward.h:380
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:420
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
Definition: lldb-forward.h:313
std::shared_ptr< lldb_private::StructuredDataPlugin > StructuredDataPluginSP
Definition: lldb-forward.h:426
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:381
std::shared_ptr< lldb_private::Debugger > DebuggerSP
Definition: lldb-forward.h:331
@ eStopShowColumnAnsi
@ eStopShowColumnCaret
@ eStopShowColumnNone
@ eStopShowColumnAnsiOrCaret
std::shared_ptr< lldb_private::Event > EventSP
Definition: lldb-forward.h:337
uint64_t pid_t
Definition: lldb-types.h:81
std::shared_ptr< lldb_private::Listener > ListenerSP
Definition: lldb-forward.h:360
std::shared_ptr< lldb_private::StreamFile > StreamFileSP
Definition: lldb-forward.h:421
uint64_t user_id_t
Definition: lldb-types.h:80
void(* LogOutputCallback)(const char *, void *baton)
Definition: lldb-types.h:72
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:436
std::shared_ptr< lldb_private::File > FileSP
Definition: lldb-forward.h:345
std::shared_ptr< lldb_private::REPL > REPLSP
Definition: lldb-forward.h:393
Definition: Debugger.h:53
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
Definition: Type.h:36
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