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 ConstString 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().AsCString()),
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 if (!top_reader_sp)
1119 break;
1120
1121 top_reader_sp->Run();
1122
1123 // Don't unwind past the starting point.
1124 if (top_reader_sp.get() == reader_sp.get()) {
1125 if (PopIOHandler(reader_sp))
1126 break;
1127 }
1128
1129 // If we pushed new IO handlers, pop them if they're done or restart the
1130 // loop to run them if they're not.
1131 while (true) {
1132 top_reader_sp = m_io_handler_stack.Top();
1133 if (top_reader_sp && top_reader_sp->GetIsDone()) {
1134 PopIOHandler(top_reader_sp);
1135 // Don't unwind past the starting point.
1136 if (top_reader_sp.get() == reader_sp.get())
1137 return;
1138 } else {
1139 break;
1140 }
1141 }
1142 }
1143}
1144
1146 return m_io_handler_stack.IsTop(reader_sp);
1147}
1148
1150 IOHandler::Type second_top_type) {
1151 return m_io_handler_stack.CheckTopIOHandlerTypes(top_type, second_top_type);
1152}
1153
1154void Debugger::PrintAsync(const char *s, size_t len, bool is_stdout) {
1155 bool printed = m_io_handler_stack.PrintAsync(s, len, is_stdout);
1156 if (!printed) {
1157 lldb::StreamFileSP stream =
1159 stream->Write(s, len);
1160 }
1161}
1162
1165}
1166
1169}
1170
1173}
1174
1176 return PopIOHandler(reader_sp);
1177}
1178
1180 bool cancel_top_handler) {
1181 PushIOHandler(reader_sp, cancel_top_handler);
1182}
1183
1185 StreamFileSP &err) {
1186 // Before an IOHandler runs, it must have in/out/err streams. This function
1187 // is called when one ore more of the streams are nullptr. We use the top
1188 // input reader's in/out/err streams, or fall back to the debugger file
1189 // handles, or we fall back onto stdin/stdout/stderr as a last resort.
1190
1191 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1192 IOHandlerSP top_reader_sp(m_io_handler_stack.Top());
1193 // If no STDIN has been set, then set it appropriately
1194 if (!in || !in->IsValid()) {
1195 if (top_reader_sp)
1196 in = top_reader_sp->GetInputFileSP();
1197 else
1198 in = GetInputFileSP();
1199 // If there is nothing, use stdin
1200 if (!in)
1201 in = std::make_shared<NativeFile>(stdin, false);
1202 }
1203 // If no STDOUT has been set, then set it appropriately
1204 if (!out || !out->GetFile().IsValid()) {
1205 if (top_reader_sp)
1206 out = top_reader_sp->GetOutputStreamFileSP();
1207 else
1208 out = GetOutputStreamSP();
1209 // If there is nothing, use stdout
1210 if (!out)
1211 out = std::make_shared<StreamFile>(stdout, false);
1212 }
1213 // If no STDERR has been set, then set it appropriately
1214 if (!err || !err->GetFile().IsValid()) {
1215 if (top_reader_sp)
1216 err = top_reader_sp->GetErrorStreamFileSP();
1217 else
1218 err = GetErrorStreamSP();
1219 // If there is nothing, use stderr
1220 if (!err)
1221 err = std::make_shared<StreamFile>(stderr, false);
1222 }
1223}
1224
1226 bool cancel_top_handler) {
1227 if (!reader_sp)
1228 return;
1229
1230 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1231
1232 // Get the current top input reader...
1233 IOHandlerSP top_reader_sp(m_io_handler_stack.Top());
1234
1235 // Don't push the same IO handler twice...
1236 if (reader_sp == top_reader_sp)
1237 return;
1238
1239 // Push our new input reader
1240 m_io_handler_stack.Push(reader_sp);
1241 reader_sp->Activate();
1242
1243 // Interrupt the top input reader to it will exit its Run() function and let
1244 // this new input reader take over
1245 if (top_reader_sp) {
1246 top_reader_sp->Deactivate();
1247 if (cancel_top_handler)
1248 top_reader_sp->Cancel();
1249 }
1250}
1251
1252bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) {
1253 if (!pop_reader_sp)
1254 return false;
1255
1256 std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1257
1258 // The reader on the stop of the stack is done, so let the next read on the
1259 // stack refresh its prompt and if there is one...
1261 return false;
1262
1263 IOHandlerSP reader_sp(m_io_handler_stack.Top());
1264
1265 if (pop_reader_sp != reader_sp)
1266 return false;
1267
1268 reader_sp->Deactivate();
1269 reader_sp->Cancel();
1271
1272 reader_sp = m_io_handler_stack.Top();
1273 if (reader_sp)
1274 reader_sp->Activate();
1275
1276 return true;
1277}
1278
1280 return std::make_shared<StreamAsynchronousIO>(*this, true, GetUseColor());
1281}
1282
1284 return std::make_shared<StreamAsynchronousIO>(*this, false, GetUseColor());
1285}
1286
1288 std::lock_guard<std::mutex> guard(m_interrupt_mutex);
1290}
1291
1293 std::lock_guard<std::mutex> guard(m_interrupt_mutex);
1294 if (m_interrupt_requested > 0)
1296}
1297
1299 // This is the one we should call internally. This will return true either
1300 // if there's a debugger interrupt and we aren't on the IOHandler thread,
1301 // or if we are on the IOHandler thread and there's a CommandInterpreter
1302 // interrupt.
1304 std::lock_guard<std::mutex> guard(m_interrupt_mutex);
1305 return m_interrupt_requested != 0;
1306 }
1308}
1309
1311 std::string function_name, const llvm::formatv_object_base &payload)
1312 : m_function_name(std::move(function_name)),
1313 m_interrupt_time(std::chrono::system_clock::now()),
1314 m_thread_id(llvm::get_threadid()) {
1315 llvm::raw_string_ostream desc(m_description);
1316 desc << payload << "\n";
1317}
1318
1320 // For now, just log the description:
1321 Log *log = GetLog(LLDBLog::Host);
1322 LLDB_LOG(log, "Interruption: {0}", report.m_description);
1323}
1324
1326 DebuggerList result;
1328 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1329 for (auto debugger_sp : *g_debugger_list_ptr) {
1330 if (debugger_sp->InterruptRequested())
1331 result.push_back(debugger_sp);
1332 }
1333 }
1334 return result;
1335}
1336
1339 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1340 return g_debugger_list_ptr->size();
1341 }
1342 return 0;
1343}
1344
1346 DebuggerSP debugger_sp;
1347
1349 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1350 if (index < g_debugger_list_ptr->size())
1351 debugger_sp = g_debugger_list_ptr->at(index);
1352 }
1353
1354 return debugger_sp;
1355}
1356
1358 DebuggerSP debugger_sp;
1359
1361 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1362 DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
1363 for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
1364 if ((*pos)->GetID() == id) {
1365 debugger_sp = *pos;
1366 break;
1367 }
1368 }
1369 }
1370 return debugger_sp;
1371}
1372
1374 const SymbolContext *sc,
1375 const SymbolContext *prev_sc,
1376 const ExecutionContext *exe_ctx,
1377 const Address *addr, Stream &s) {
1378 FormatEntity::Entry format_entry;
1379
1380 if (format == nullptr) {
1381 if (exe_ctx != nullptr && exe_ctx->HasTargetScope())
1382 format = exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
1383 if (format == nullptr) {
1384 FormatEntity::Parse("${addr}: ", format_entry);
1385 format = &format_entry;
1386 }
1387 }
1388 bool function_changed = false;
1389 bool initial_function = false;
1390 if (prev_sc && (prev_sc->function || prev_sc->symbol)) {
1391 if (sc && (sc->function || sc->symbol)) {
1392 if (prev_sc->symbol && sc->symbol) {
1393 if (!sc->symbol->Compare(prev_sc->symbol->GetName(),
1394 prev_sc->symbol->GetType())) {
1395 function_changed = true;
1396 }
1397 } else if (prev_sc->function && sc->function) {
1398 if (prev_sc->function->GetMangled() != sc->function->GetMangled()) {
1399 function_changed = true;
1400 }
1401 }
1402 }
1403 }
1404 // The first context on a list of instructions will have a prev_sc that has
1405 // no Function or Symbol -- if SymbolContext had an IsValid() method, it
1406 // would return false. But we do get a prev_sc pointer.
1407 if ((sc && (sc->function || sc->symbol)) && prev_sc &&
1408 (prev_sc->function == nullptr && prev_sc->symbol == nullptr)) {
1409 initial_function = true;
1410 }
1411 return FormatEntity::Format(*format, s, sc, exe_ctx, addr, nullptr,
1412 function_changed, initial_function);
1413}
1414
1415void Debugger::AssertCallback(llvm::StringRef message,
1416 llvm::StringRef backtrace,
1417 llvm::StringRef prompt) {
1419 llvm::formatv("{0}\n{1}{2}", message, backtrace, prompt).str());
1420}
1421
1423 void *baton) {
1424 // For simplicity's sake, I am not going to deal with how to close down any
1425 // open logging streams, I just redirect everything from here on out to the
1426 // callback.
1428 std::make_shared<CallbackLogHandler>(log_callback, baton);
1429}
1430
1432 lldb_private::DebuggerDestroyCallback destroy_callback, void *baton) {
1433 m_destroy_callback = destroy_callback;
1435}
1436
1437static void PrivateReportProgress(Debugger &debugger, uint64_t progress_id,
1438 std::string title, std::string details,
1439 uint64_t completed, uint64_t total,
1440 bool is_debugger_specific,
1441 uint32_t progress_broadcast_bit) {
1442 // Only deliver progress events if we have any progress listeners.
1443 if (!debugger.GetBroadcaster().EventTypeHasListeners(progress_broadcast_bit))
1444 return;
1445
1446 EventSP event_sp(new Event(
1447 progress_broadcast_bit,
1448 new ProgressEventData(progress_id, std::move(title), std::move(details),
1449 completed, total, is_debugger_specific)));
1450 debugger.GetBroadcaster().BroadcastEvent(event_sp);
1451}
1452
1453void Debugger::ReportProgress(uint64_t progress_id, std::string title,
1454 std::string details, uint64_t completed,
1455 uint64_t total,
1456 std::optional<lldb::user_id_t> debugger_id,
1457 uint32_t progress_category_bit) {
1458 // Check if this progress is for a specific debugger.
1459 if (debugger_id) {
1460 // It is debugger specific, grab it and deliver the event if the debugger
1461 // still exists.
1462 DebuggerSP debugger_sp = FindDebuggerWithID(*debugger_id);
1463 if (debugger_sp)
1464 PrivateReportProgress(*debugger_sp, progress_id, std::move(title),
1465 std::move(details), completed, total,
1466 /*is_debugger_specific*/ true,
1467 progress_category_bit);
1468 return;
1469 }
1470 // The progress event is not debugger specific, iterate over all debuggers
1471 // and deliver a progress event to each one.
1473 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1474 DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
1475 for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos)
1476 PrivateReportProgress(*(*pos), progress_id, title, details, completed,
1477 total, /*is_debugger_specific*/ false,
1478 progress_category_bit);
1479 }
1480}
1481
1482static void PrivateReportDiagnostic(Debugger &debugger,
1484 std::string message,
1485 bool debugger_specific) {
1486 uint32_t event_type = 0;
1487 switch (type) {
1489 assert(false && "DiagnosticEventData::Type::Info should not be broadcast");
1490 return;
1492 event_type = Debugger::eBroadcastBitWarning;
1493 break;
1495 event_type = Debugger::eBroadcastBitError;
1496 break;
1497 }
1498
1499 Broadcaster &broadcaster = debugger.GetBroadcaster();
1500 if (!broadcaster.EventTypeHasListeners(event_type)) {
1501 // Diagnostics are too important to drop. If nobody is listening, print the
1502 // diagnostic directly to the debugger's error stream.
1503 DiagnosticEventData event_data(type, std::move(message), debugger_specific);
1504 StreamSP stream = debugger.GetAsyncErrorStream();
1505 event_data.Dump(stream.get());
1506 return;
1507 }
1508 EventSP event_sp = std::make_shared<Event>(
1509 event_type,
1510 new DiagnosticEventData(type, std::move(message), debugger_specific));
1511 broadcaster.BroadcastEvent(event_sp);
1512}
1513
1515 std::string message,
1516 std::optional<lldb::user_id_t> debugger_id,
1517 std::once_flag *once) {
1518 auto ReportDiagnosticLambda = [&]() {
1519 // The diagnostic subsystem is optional but we still want to broadcast
1520 // events when it's disabled.
1522 Diagnostics::Instance().Report(message);
1523
1524 // We don't broadcast info events.
1526 return;
1527
1528 // Check if this diagnostic is for a specific debugger.
1529 if (debugger_id) {
1530 // It is debugger specific, grab it and deliver the event if the debugger
1531 // still exists.
1532 DebuggerSP debugger_sp = FindDebuggerWithID(*debugger_id);
1533 if (debugger_sp)
1534 PrivateReportDiagnostic(*debugger_sp, type, std::move(message), true);
1535 return;
1536 }
1537 // The diagnostic event is not debugger specific, iterate over all debuggers
1538 // and deliver a diagnostic event to each one.
1540 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1541 for (const auto &debugger : *g_debugger_list_ptr)
1542 PrivateReportDiagnostic(*debugger, type, message, false);
1543 }
1544 };
1545
1546 if (once)
1547 std::call_once(*once, ReportDiagnosticLambda);
1548 else
1549 ReportDiagnosticLambda();
1550}
1551
1552void Debugger::ReportWarning(std::string message,
1553 std::optional<lldb::user_id_t> debugger_id,
1554 std::once_flag *once) {
1556 debugger_id, once);
1557}
1558
1559void Debugger::ReportError(std::string message,
1560 std::optional<lldb::user_id_t> debugger_id,
1561 std::once_flag *once) {
1563 debugger_id, once);
1564}
1565
1566void Debugger::ReportInfo(std::string message,
1567 std::optional<lldb::user_id_t> debugger_id,
1568 std::once_flag *once) {
1570 debugger_id, once);
1571}
1572
1575 std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
1576 for (DebuggerSP debugger_sp : *g_debugger_list_ptr) {
1577 EventSP event_sp = std::make_shared<Event>(
1579 new SymbolChangeEventData(debugger_sp, module_spec));
1580 debugger_sp->GetBroadcaster().BroadcastEvent(event_sp);
1581 }
1582 }
1583}
1584
1585static std::shared_ptr<LogHandler>
1586CreateLogHandler(LogHandlerKind log_handler_kind, int fd, bool should_close,
1587 size_t buffer_size) {
1588 switch (log_handler_kind) {
1589 case eLogHandlerStream:
1590 return std::make_shared<StreamLogHandler>(fd, should_close, buffer_size);
1592 return std::make_shared<RotatingLogHandler>(buffer_size);
1593 case eLogHandlerSystem:
1594 return std::make_shared<SystemLogHandler>();
1596 return {};
1597 }
1598 return {};
1599}
1600
1601bool Debugger::EnableLog(llvm::StringRef channel,
1602 llvm::ArrayRef<const char *> categories,
1603 llvm::StringRef log_file, uint32_t log_options,
1604 size_t buffer_size, LogHandlerKind log_handler_kind,
1605 llvm::raw_ostream &error_stream) {
1606
1607 std::shared_ptr<LogHandler> log_handler_sp;
1609 log_handler_sp = m_callback_handler_sp;
1610 // For now when using the callback mode you always get thread & timestamp.
1611 log_options |=
1613 } else if (log_file.empty()) {
1614 log_handler_sp =
1615 CreateLogHandler(log_handler_kind, GetOutputFile().GetDescriptor(),
1616 /*should_close=*/false, buffer_size);
1617 } else {
1618 auto pos = m_stream_handlers.find(log_file);
1619 if (pos != m_stream_handlers.end())
1620 log_handler_sp = pos->second.lock();
1621 if (!log_handler_sp) {
1622 File::OpenOptions flags =
1624 if (log_options & LLDB_LOG_OPTION_APPEND)
1625 flags |= File::eOpenOptionAppend;
1626 else
1628 llvm::Expected<FileUP> file = FileSystem::Instance().Open(
1629 FileSpec(log_file), flags, lldb::eFilePermissionsFileDefault, false);
1630 if (!file) {
1631 error_stream << "Unable to open log file '" << log_file
1632 << "': " << llvm::toString(file.takeError()) << "\n";
1633 return false;
1634 }
1635
1636 log_handler_sp =
1637 CreateLogHandler(log_handler_kind, (*file)->GetDescriptor(),
1638 /*should_close=*/true, buffer_size);
1639 m_stream_handlers[log_file] = log_handler_sp;
1640 }
1641 }
1642 assert(log_handler_sp);
1643
1644 if (log_options == 0)
1646
1647 return Log::EnableLogChannel(log_handler_sp, log_options, channel, categories,
1648 error_stream);
1649}
1650
1653 std::optional<lldb::ScriptLanguage> language) {
1654 std::lock_guard<std::recursive_mutex> locker(m_script_interpreter_mutex);
1655 lldb::ScriptLanguage script_language =
1656 language ? *language : GetScriptLanguage();
1657
1658 if (!m_script_interpreters[script_language]) {
1659 if (!can_create)
1660 return nullptr;
1661 m_script_interpreters[script_language] =
1662 PluginManager::GetScriptInterpreterForLanguage(script_language, *this);
1663 }
1664
1665 return m_script_interpreters[script_language].get();
1666}
1667
1670 m_source_manager_up = std::make_unique<SourceManager>(shared_from_this());
1671 return *m_source_manager_up;
1672}
1673
1674// This function handles events that were broadcast by the process.
1676 using namespace lldb;
1677 const uint32_t event_type =
1679 event_sp);
1680
1681 // if (event_type & eBreakpointEventTypeAdded
1682 // || event_type & eBreakpointEventTypeRemoved
1683 // || event_type & eBreakpointEventTypeEnabled
1684 // || event_type & eBreakpointEventTypeDisabled
1685 // || event_type & eBreakpointEventTypeCommandChanged
1686 // || event_type & eBreakpointEventTypeConditionChanged
1687 // || event_type & eBreakpointEventTypeIgnoreChanged
1688 // || event_type & eBreakpointEventTypeLocationsResolved)
1689 // {
1690 // // Don't do anything about these events, since the breakpoint
1691 // commands already echo these actions.
1692 // }
1693 //
1694 if (event_type & eBreakpointEventTypeLocationsAdded) {
1695 uint32_t num_new_locations =
1697 event_sp);
1698 if (num_new_locations > 0) {
1699 BreakpointSP breakpoint =
1701 StreamSP output_sp(GetAsyncOutputStream());
1702 if (output_sp) {
1703 output_sp->Printf("%d location%s added to breakpoint %d\n",
1704 num_new_locations, num_new_locations == 1 ? "" : "s",
1705 breakpoint->GetID());
1706 output_sp->Flush();
1707 }
1708 }
1709 }
1710 // else if (event_type & eBreakpointEventTypeLocationsRemoved)
1711 // {
1712 // // These locations just get disabled, not sure it is worth spamming
1713 // folks about this on the command line.
1714 // }
1715 // else if (event_type & eBreakpointEventTypeLocationsResolved)
1716 // {
1717 // // This might be an interesting thing to note, but I'm going to
1718 // leave it quiet for now, it just looked noisy.
1719 // }
1720}
1721
1722void Debugger::FlushProcessOutput(Process &process, bool flush_stdout,
1723 bool flush_stderr) {
1724 const auto &flush = [&](Stream &stream,
1725 size_t (Process::*get)(char *, size_t, Status &)) {
1726 Status error;
1727 size_t len;
1728 char buffer[1024];
1729 while ((len = (process.*get)(buffer, sizeof(buffer), error)) > 0)
1730 stream.Write(buffer, len);
1731 stream.Flush();
1732 };
1733
1734 std::lock_guard<std::mutex> guard(m_output_flush_mutex);
1735 if (flush_stdout)
1737 if (flush_stderr)
1739}
1740
1741// This function handles events that were broadcast by the process.
1743 using namespace lldb;
1744 const uint32_t event_type = event_sp->GetType();
1745 ProcessSP process_sp =
1749
1750 StreamSP output_stream_sp = GetAsyncOutputStream();
1751 StreamSP error_stream_sp = GetAsyncErrorStream();
1752 const bool gui_enabled = IsForwardingEvents();
1753
1754 if (!gui_enabled) {
1755 bool pop_process_io_handler = false;
1756 assert(process_sp);
1757
1758 bool state_is_stopped = false;
1759 const bool got_state_changed =
1760 (event_type & Process::eBroadcastBitStateChanged) != 0;
1761 const bool got_stdout = (event_type & Process::eBroadcastBitSTDOUT) != 0;
1762 const bool got_stderr = (event_type & Process::eBroadcastBitSTDERR) != 0;
1763 const bool got_structured_data =
1764 (event_type & Process::eBroadcastBitStructuredData) != 0;
1765
1766 if (got_state_changed) {
1767 StateType event_state =
1769 state_is_stopped = StateIsStoppedState(event_state, false);
1770 }
1771
1772 // Display running state changes first before any STDIO
1773 if (got_state_changed && !state_is_stopped) {
1774 // This is a public stop which we are going to announce to the user, so
1775 // we should force the most relevant frame selection here.
1776 Process::HandleProcessStateChangedEvent(event_sp, output_stream_sp.get(),
1778 pop_process_io_handler);
1779 }
1780
1781 // Now display STDOUT and STDERR
1782 FlushProcessOutput(*process_sp, got_stdout || got_state_changed,
1783 got_stderr || got_state_changed);
1784
1785 // Give structured data events an opportunity to display.
1786 if (got_structured_data) {
1787 StructuredDataPluginSP plugin_sp =
1789 if (plugin_sp) {
1790 auto structured_data_sp =
1792 if (output_stream_sp) {
1793 StreamString content_stream;
1794 Status error =
1795 plugin_sp->GetDescription(structured_data_sp, content_stream);
1796 if (error.Success()) {
1797 if (!content_stream.GetString().empty()) {
1798 // Add newline.
1799 content_stream.PutChar('\n');
1800 content_stream.Flush();
1801
1802 // Print it.
1803 output_stream_sp->PutCString(content_stream.GetString());
1804 }
1805 } else {
1806 error_stream_sp->Format("Failed to print structured "
1807 "data with plugin {0}: {1}",
1808 plugin_sp->GetPluginName(), error);
1809 }
1810 }
1811 }
1812 }
1813
1814 // Now display any stopped state changes after any STDIO
1815 if (got_state_changed && state_is_stopped) {
1816 Process::HandleProcessStateChangedEvent(event_sp, output_stream_sp.get(),
1818 pop_process_io_handler);
1819 }
1820
1821 output_stream_sp->Flush();
1822 error_stream_sp->Flush();
1823
1824 if (pop_process_io_handler)
1825 process_sp->PopProcessIOHandler();
1826 }
1827}
1828
1830 // At present the only thread event we handle is the Frame Changed event, and
1831 // all we do for that is just reprint the thread status for that thread.
1832 using namespace lldb;
1833 const uint32_t event_type = event_sp->GetType();
1834 const bool stop_format = true;
1835 if (event_type == Thread::eBroadcastBitStackChanged ||
1837 ThreadSP thread_sp(
1839 if (thread_sp) {
1840 thread_sp->GetStatus(*GetAsyncOutputStream(), 0, 1, 1, stop_format);
1841 }
1842 }
1843}
1844
1846
1848 m_forward_listener_sp = listener_sp;
1849}
1850
1852 m_forward_listener_sp.reset();
1853}
1854
1856 ListenerSP listener_sp(GetListener());
1857 ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass());
1858 ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass());
1859 ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass());
1860 BroadcastEventSpec target_event_spec(broadcaster_class_target,
1862
1863 BroadcastEventSpec process_event_spec(
1864 broadcaster_class_process,
1867
1868 BroadcastEventSpec thread_event_spec(broadcaster_class_thread,
1871
1872 listener_sp->StartListeningForEventSpec(m_broadcaster_manager_sp,
1873 target_event_spec);
1874 listener_sp->StartListeningForEventSpec(m_broadcaster_manager_sp,
1875 process_event_spec);
1876 listener_sp->StartListeningForEventSpec(m_broadcaster_manager_sp,
1877 thread_event_spec);
1878 listener_sp->StartListeningForEvents(
1883
1884 listener_sp->StartListeningForEvents(
1887
1888 // Let the thread that spawned us know that we have started up and that we
1889 // are now listening to all required events so no events get missed
1891
1892 bool done = false;
1893 while (!done) {
1894 EventSP event_sp;
1895 if (listener_sp->GetEvent(event_sp, std::nullopt)) {
1896 if (event_sp) {
1897 Broadcaster *broadcaster = event_sp->GetBroadcaster();
1898 if (broadcaster) {
1899 uint32_t event_type = event_sp->GetType();
1900 ConstString broadcaster_class(broadcaster->GetBroadcasterClass());
1901 if (broadcaster_class == broadcaster_class_process) {
1902 HandleProcessEvent(event_sp);
1903 } else if (broadcaster_class == broadcaster_class_target) {
1905 event_sp.get())) {
1906 HandleBreakpointEvent(event_sp);
1907 }
1908 } else if (broadcaster_class == broadcaster_class_thread) {
1909 HandleThreadEvent(event_sp);
1910 } else if (broadcaster == m_command_interpreter_up.get()) {
1911 if (event_type &
1913 done = true;
1914 } else if (event_type &
1916 const char *data = static_cast<const char *>(
1917 EventDataBytes::GetBytesFromEvent(event_sp.get()));
1918 if (data && data[0]) {
1919 StreamSP error_sp(GetAsyncErrorStream());
1920 if (error_sp) {
1921 error_sp->PutCString(data);
1922 error_sp->Flush();
1923 }
1924 }
1925 } else if (event_type & CommandInterpreter::
1926 eBroadcastBitAsynchronousOutputData) {
1927 const char *data = static_cast<const char *>(
1928 EventDataBytes::GetBytesFromEvent(event_sp.get()));
1929 if (data && data[0]) {
1930 StreamSP output_sp(GetAsyncOutputStream());
1931 if (output_sp) {
1932 output_sp->PutCString(data);
1933 output_sp->Flush();
1934 }
1935 }
1936 }
1937 } else if (broadcaster == &m_broadcaster) {
1938 if (event_type & Debugger::eBroadcastBitProgress)
1939 HandleProgressEvent(event_sp);
1940 else if (event_type & Debugger::eBroadcastBitWarning)
1941 HandleDiagnosticEvent(event_sp);
1942 else if (event_type & Debugger::eBroadcastBitError)
1943 HandleDiagnosticEvent(event_sp);
1944 }
1945 }
1946
1948 m_forward_listener_sp->AddEvent(event_sp);
1949 }
1950 }
1951 }
1952 return {};
1953}
1954
1957 // We must synchronize with the DefaultEventHandler() thread to ensure it
1958 // is up and running and listening to events before we return from this
1959 // function. We do this by listening to events for the
1960 // eBroadcastBitEventThreadIsListening from the m_sync_broadcaster
1961 ConstString full_name("lldb.debugger.event-handler");
1962 ListenerSP listener_sp(Listener::MakeListener(full_name.AsCString()));
1963 listener_sp->StartListeningForEvents(&m_sync_broadcaster,
1965
1966 llvm::StringRef thread_name =
1967 full_name.GetLength() < llvm::get_max_thread_name_length()
1968 ? full_name.GetStringRef()
1969 : "dbg.evt-handler";
1970
1971 // Use larger 8MB stack for this thread
1972 llvm::Expected<HostThread> event_handler_thread =
1974 thread_name, [this] { return DefaultEventHandler(); },
1976
1977 if (event_handler_thread) {
1978 m_event_handler_thread = *event_handler_thread;
1979 } else {
1980 LLDB_LOG_ERROR(GetLog(LLDBLog::Host), event_handler_thread.takeError(),
1981 "failed to launch host thread: {0}");
1982 }
1983
1984 // Make sure DefaultEventHandler() is running and listening to events
1985 // before we return from this function. We are only listening for events of
1986 // type eBroadcastBitEventThreadIsListening so we don't need to check the
1987 // event, we just need to wait an infinite amount of time for it (nullptr
1988 // timeout as the first parameter)
1989 lldb::EventSP event_sp;
1990 listener_sp->GetEvent(event_sp, std::nullopt);
1991 }
1993}
1994
2000 }
2001}
2002
2004 RunIOHandlers();
2006 return {};
2007}
2008
2010 auto *data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
2011 if (!data)
2012 return;
2013
2014 // Do some bookkeeping for the current event, regardless of whether we're
2015 // going to show the progress.
2016 const uint64_t id = data->GetID();
2017 if (m_current_event_id) {
2018 Log *log = GetLog(LLDBLog::Events);
2019 if (log && log->GetVerbose()) {
2020 StreamString log_stream;
2021 log_stream.AsRawOstream()
2022 << static_cast<void *>(this) << " Debugger(" << GetID()
2023 << ")::HandleProgressEvent( m_current_event_id = "
2024 << *m_current_event_id << ", data = { ";
2025 data->Dump(&log_stream);
2026 log_stream << " } )";
2027 log->PutString(log_stream.GetString());
2028 }
2029 if (id != *m_current_event_id)
2030 return;
2031 if (data->GetCompleted() == data->GetTotal())
2032 m_current_event_id.reset();
2033 } else {
2035 }
2036
2037 // Decide whether we actually are going to show the progress. This decision
2038 // can change between iterations so check it inside the loop.
2039 if (!GetShowProgress())
2040 return;
2041
2042 // Determine whether the current output file is an interactive terminal with
2043 // color support. We assume that if we support ANSI escape codes we support
2044 // vt100 escape codes.
2045 File &file = GetOutputFile();
2046 if (!file.GetIsInteractive() || !file.GetIsTerminalWithColors())
2047 return;
2048
2049 StreamSP output = GetAsyncOutputStream();
2050
2051 // Print over previous line, if any.
2052 output->Printf("\r");
2053
2054 if (data->GetCompleted() == data->GetTotal()) {
2055 // Clear the current line.
2056 output->Printf("\x1B[2K");
2057 output->Flush();
2058 return;
2059 }
2060
2061 // Trim the progress message if it exceeds the window's width and print it.
2062 std::string message = data->GetMessage();
2063 if (data->IsFinite())
2064 message = llvm::formatv("[{0}/{1}] {2}", data->GetCompleted(),
2065 data->GetTotal(), message)
2066 .str();
2067
2068 // Trim the progress message if it exceeds the window's width and print it.
2069 const uint32_t term_width = GetTerminalWidth();
2070 const uint32_t ellipsis = 3;
2071 if (message.size() + ellipsis >= term_width)
2072 message = message.substr(0, term_width - ellipsis);
2073
2074 const bool use_color = GetUseColor();
2075 llvm::StringRef ansi_prefix = GetShowProgressAnsiPrefix();
2076 if (!ansi_prefix.empty())
2077 output->Printf(
2078 "%s", ansi::FormatAnsiTerminalCodes(ansi_prefix, use_color).c_str());
2079
2080 output->Printf("%s...", message.c_str());
2081
2082 llvm::StringRef ansi_suffix = GetShowProgressAnsiSuffix();
2083 if (!ansi_suffix.empty())
2084 output->Printf(
2085 "%s", ansi::FormatAnsiTerminalCodes(ansi_suffix, use_color).c_str());
2086
2087 // Clear until the end of the line.
2088 output->Printf("\x1B[K\r");
2089
2090 // Flush the output.
2091 output->Flush();
2092}
2093
2095 auto *data = DiagnosticEventData::GetEventDataFromEvent(event_sp.get());
2096 if (!data)
2097 return;
2098
2099 StreamSP stream = GetAsyncErrorStream();
2100 data->Dump(stream.get());
2101}
2102
2105}
2106
2109 m_io_handler_thread = new_thread;
2110 return old_host;
2111}
2112
2115 llvm::Expected<HostThread> io_handler_thread = ThreadLauncher::LaunchThread(
2116 "lldb.debugger.io-handler", [this] { return IOHandlerThread(); },
2117 8 * 1024 * 1024); // Use larger 8MB stack for this thread
2118 if (io_handler_thread) {
2119 m_io_handler_thread = *io_handler_thread;
2120 } else {
2121 LLDB_LOG_ERROR(GetLog(LLDBLog::Host), io_handler_thread.takeError(),
2122 "failed to launch host thread: {0}");
2123 }
2124 }
2126}
2127
2130 GetInputFile().Close();
2131 m_io_handler_thread.Join(nullptr);
2132 }
2133}
2134
2136 if (HasIOHandlerThread()) {
2137 thread_result_t result;
2138 m_io_handler_thread.Join(&result);
2140 }
2141}
2142
2144 if (!HasIOHandlerThread())
2145 return false;
2147}
2148
2150 if (!prefer_dummy) {
2152 return *target;
2153 }
2154 return GetDummyTarget();
2155}
2156
2157Status Debugger::RunREPL(LanguageType language, const char *repl_options) {
2158 Status err;
2159 FileSpec repl_executable;
2160
2161 if (language == eLanguageTypeUnknown)
2162 language = GetREPLLanguage();
2163
2164 if (language == eLanguageTypeUnknown) {
2166
2167 if (auto single_lang = repl_languages.GetSingularLanguage()) {
2168 language = *single_lang;
2169 } else if (repl_languages.Empty()) {
2170 err.SetErrorString(
2171 "LLDB isn't configured with REPL support for any languages.");
2172 return err;
2173 } else {
2174 err.SetErrorString(
2175 "Multiple possible REPL languages. Please specify a language.");
2176 return err;
2177 }
2178 }
2179
2180 Target *const target =
2181 nullptr; // passing in an empty target means the REPL must create one
2182
2183 REPLSP repl_sp(REPL::Create(err, language, this, target, repl_options));
2184
2185 if (!err.Success()) {
2186 return err;
2187 }
2188
2189 if (!repl_sp) {
2190 err.SetErrorStringWithFormat("couldn't find a REPL for %s",
2192 return err;
2193 }
2194
2195 repl_sp->SetCompilerOptions(repl_options);
2196 repl_sp->RunLoop();
2197
2198 return err;
2199}
2200
2201llvm::ThreadPoolInterface &Debugger::GetThreadPool() {
2202 assert(g_thread_pool &&
2203 "Debugger::GetThreadPool called before Debugger::Initialize");
2204 return *g_thread_pool;
2205}
static llvm::raw_ostream & error(Stream &strm)
static void PrivateReportDiagnostic(Debugger &debugger, DiagnosticEventData::Type type, std::string message, bool debugger_specific)
Definition: Debugger.cpp:1482
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:1437
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:1586
#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 ConstString & GetBroadcasterClass() const
This needs to be filled in if you are going to register the broadcaster with the broadcaster manager ...
void BroadcastEvent(lldb::EventSP &event_sp)
Broadcast an event which has no associated data.
Definition: Broadcaster.h:167
void UpdatePrompt(llvm::StringRef prompt)
bool SaveTranscript(CommandReturnObject &result, std::optional< std::string > output_file=std::nullopt)
Save the current debugger session transcript to a file on disk.
A uniqued constant string class.
Definition: ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h: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:1415
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:1287
void ReportInterruption(const InterruptionReport &report)
Definition: Debugger.cpp:1319
ExecutionContext GetSelectedExecutionContext()
Definition: Debugger.cpp:1055
static void Terminate()
Definition: Debugger.cpp:616
void HandleProgressEvent(const lldb::EventSP &event_sp)
Definition: Debugger.cpp:2009
SourceManager & GetSourceManager()
Definition: Debugger.cpp:1668
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:1453
lldb::StreamSP GetAsyncOutputStream()
Definition: Debugger.cpp:1279
bool StartEventHandlerThread()
Manually start the global event handler thread.
Definition: Debugger.cpp:1955
bool SetUseSourceCache(bool use_source_cache)
Definition: Debugger.cpp:481
void StopEventHandlerThread()
Manually stop the debugger's default event handler.
Definition: Debugger.cpp:1995
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:1566
void SetAsyncExecution(bool async)
Definition: Debugger.cpp:971
HostThread SetIOHandlerThread(HostThread &new_thread)
Definition: Debugger.cpp:2107
void CancelForwardEvents(const lldb::ListenerSP &listener_sp)
Definition: Debugger.cpp:1851
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:2094
static lldb::DebuggerSP GetDebuggerAtIndex(size_t index)
Definition: Debugger.cpp:1345
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:1225
lldb::thread_result_t IOHandlerThread()
Definition: Debugger.cpp:2003
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:1514
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:1552
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:1373
static void SettingsInitialize()
Definition: Debugger.cpp:642
static llvm::ThreadPoolInterface & GetThreadPool()
Shared thread pool. Use only with ThreadPoolTaskGroup.
Definition: Debugger.cpp:2201
llvm::StringRef GetShowProgressAnsiSuffix() const
Definition: Debugger.cpp:433
bool IsTopIOHandler(const lldb::IOHandlerSP &reader_sp)
Definition: Debugger.cpp:1145
bool HasIOHandlerThread() const
Definition: Debugger.cpp:2103
bool IsIOHandlerThreadCurrentThread() const
Definition: Debugger.cpp:2143
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:1431
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:1175
Diagnostics::CallbackID m_diagnostics_callback_id
Definition: Debugger.h:732
bool GetAutoOneLineSummaries() const
Definition: Debugger.cpp:546
const char * GetIOHandlerCommandPrefix()
Definition: Debugger.cpp:1167
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:2157
bool PopIOHandler(const lldb::IOHandlerSP &reader_sp)
Definition: Debugger.cpp:1252
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:1179
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:1283
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:1601
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
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:1573
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:1559
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:1847
@ eBroadcastBitEventThreadIsListening
Definition: Debugger.h:742
static lldb::DebuggerSP FindDebuggerWithID(lldb::user_id_t id)
Definition: Debugger.cpp:1357
void HandleBreakpointEvent(const lldb::EventSP &event_sp)
Definition: Debugger.cpp:1675
static ConstString GetStaticBroadcasterClass()
Definition: Debugger.cpp:826
bool CheckTopIOHandlerTypes(IOHandler::Type top_type, IOHandler::Type second_top_type)
Definition: Debugger.cpp:1149
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:1171
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:2149
void HandleProcessEvent(const lldb::EventSP &event_sp)
Definition: Debugger.cpp:1742
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:1184
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:1652
void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton)
Definition: Debugger.cpp:1422
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:1829
static size_t GetNumDebuggers()
Definition: Debugger.cpp:1337
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:1855
void PrintAsync(const char *s, size_t len, bool is_stdout)
Definition: Debugger.cpp:1154
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:1163
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:1722
void CancelInterruptRequest()
Decrement the "interrupt requested" counter.
Definition: Debugger.cpp:1292
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:1325
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:4165
static lldb::StateType GetStateFromEvent(const Event *event_ptr)
Definition: Process.cpp:4173
A plug-in interface definition class for debugging a process.
Definition: Process.h:340
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:718
virtual size_t GetSTDERR(char *buf, size_t buf_size, Status &error)
Get any available STDERR.
Definition: Process.cpp:4368
static ConstString & GetStaticBroadcasterClass()
Definition: Process.cpp:410
virtual size_t GetSTDOUT(char *buf, size_t buf_size, Status &error)
Get any available STDOUT.
Definition: Process.cpp:4349
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 ConstString & GetStaticBroadcasterClass()
Definition: Target.cpp:90
static void SettingsTerminate()
Definition: Target.cpp:2599
Debugger & GetDebugger()
Definition: Target.h:1055
@ eBroadcastBitBreakpointChanged
Definition: Target.h:492
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
static ConstString & GetStaticBroadcasterClass()
Definition: Thread.cpp:208
@ eBroadcastBitThreadSelected
Definition: Thread.h:74
@ eBroadcastBitStackChanged
Definition: Thread.h:70
@ 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