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