LLDB  mainline
REPL.cpp
Go to the documentation of this file.
1 //===-- REPL.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/Expression/REPL.h"
10 #include "lldb/Core/Debugger.h"
12 #include "lldb/Core/StreamFile.h"
15 #include "lldb/Host/HostInfo.h"
18 #include "lldb/Target/Thread.h"
20 
21 #include <memory>
22 
23 using namespace lldb_private;
24 
25 REPL::REPL(LLVMCastKind kind, Target &target) : m_target(target), m_kind(kind) {
26  // Make sure all option values have sane defaults
27  Debugger &debugger = m_target.GetDebugger();
28  auto exe_ctx = debugger.GetCommandInterpreter().GetExecutionContext();
31 }
32 
33 REPL::~REPL() = default;
34 
35 lldb::REPLSP REPL::Create(Status &err, lldb::LanguageType language,
36  Debugger *debugger, Target *target,
37  const char *repl_options) {
38  uint32_t idx = 0;
39  lldb::REPLSP ret;
40 
41  while (REPLCreateInstance create_instance =
43  ret = (*create_instance)(err, language, debugger, target, repl_options);
44  if (ret) {
45  break;
46  }
47  }
48 
49  return ret;
50 }
51 
53  ConstString file_basename = GetSourceFileBasename();
54  FileSpec tmpdir_file_spec = HostInfo::GetProcessTempDir();
55  if (tmpdir_file_spec) {
56  tmpdir_file_spec.GetFilename() = file_basename;
57  m_repl_source_path = tmpdir_file_spec.GetPath();
58  } else {
59  tmpdir_file_spec = FileSpec("/tmp");
60  tmpdir_file_spec.AppendPathComponent(file_basename.GetStringRef());
61  }
62 
63  return tmpdir_file_spec.GetPath();
64 }
65 
66 lldb::IOHandlerSP REPL::GetIOHandler() {
67  if (!m_io_handler_sp) {
68  Debugger &debugger = m_target.GetDebugger();
69  m_io_handler_sp = std::make_shared<IOHandlerEditline>(
70  debugger, IOHandler::Type::REPL,
71  "lldb-repl", // Name of input reader for history
72  llvm::StringRef("> "), // prompt
73  llvm::StringRef(". "), // Continuation prompt
74  true, // Multi-line
75  true, // The REPL prompt is always colored
76  1, // Line number
77  *this, nullptr);
78 
79  // Don't exit if CTRL+C is pressed
80  static_cast<IOHandlerEditline *>(m_io_handler_sp.get())
81  ->SetInterruptExits(false);
82 
83  if (m_io_handler_sp->GetIsInteractive() &&
84  m_io_handler_sp->GetIsRealTerminal()) {
85  m_indent_str.assign(debugger.GetTabSize(), ' ');
87  } else {
88  m_indent_str.clear();
89  m_enable_auto_indent = false;
90  }
91  }
92  return m_io_handler_sp;
93 }
94 
95 void REPL::IOHandlerActivated(IOHandler &io_handler, bool interactive) {
96  lldb::ProcessSP process_sp = m_target.GetProcessSP();
97  if (process_sp && process_sp->IsAlive())
98  return;
99  lldb::StreamFileSP error_sp(io_handler.GetErrorStreamFileSP());
100  error_sp->Printf("REPL requires a running target process.\n");
101  io_handler.SetIsDone(true);
102 }
103 
104 bool REPL::IOHandlerInterrupt(IOHandler &io_handler) { return false; }
105 
107 }
108 
110  return (m_enable_auto_indent ? GetAutoIndentCharacters() : nullptr);
111 }
112 
114  if (ch == 'd')
115  return ConstString(":quit\n");
116  return ConstString();
117 }
118 
119 const char *REPL::IOHandlerGetCommandPrefix() { return ":"; }
120 
122  return "\nThe REPL (Read-Eval-Print-Loop) acts like an interpreter. "
123  "Valid statements, expressions, and declarations are immediately "
124  "compiled and executed.\n\n"
125  "The complete set of LLDB debugging commands are also available as "
126  "described below.\n\nCommands "
127  "must be prefixed with a colon at the REPL prompt (:quit for "
128  "example.) Typing just a colon "
129  "followed by return will switch to the LLDB prompt.\n\n"
130  "Type “< path” to read in code from a text file “path”.\n\n";
131 }
132 
134  // Check for meta command
135  const size_t num_lines = lines.GetSize();
136  if (num_lines == 1) {
137  const char *first_line = lines.GetStringAtIndex(0);
138  if (first_line[0] == ':')
139  return true; // Meta command is a single line where that starts with ':'
140  }
141 
142  // Check if REPL input is done
143  std::string source_string(lines.CopyList());
144  return SourceIsComplete(source_string);
145 }
146 
148  std::string last_line = lines[lines.GetSize() - 1];
149 
150  int actual_indent = 0;
151  for (char &ch : last_line) {
152  if (ch != ' ')
153  break;
154  ++actual_indent;
155  }
156 
157  return actual_indent;
158 }
159 
161  const StringList &lines,
162  int cursor_position) {
164  return 0;
165 
166  if (!lines.GetSize()) {
167  return 0;
168  }
169 
170  int tab_size = io_handler.GetDebugger().GetTabSize();
171 
172  lldb::offset_t desired_indent =
173  GetDesiredIndentation(lines, cursor_position, tab_size);
174 
175  int actual_indent = REPL::CalculateActualIndentation(lines);
176 
177  if (desired_indent == LLDB_INVALID_OFFSET)
178  return 0;
179 
180  return (int)desired_indent - actual_indent;
181 }
182 
183 static bool ReadCode(const std::string &path, std::string &code,
184  lldb::StreamFileSP &error_sp) {
185  auto &fs = FileSystem::Instance();
186  llvm::Twine pathTwine(path);
187  if (!fs.Exists(pathTwine)) {
188  error_sp->Printf("no such file at path '%s'\n", path.c_str());
189  return false;
190  }
191  if (!fs.Readable(pathTwine)) {
192  error_sp->Printf("could not read file at path '%s'\n", path.c_str());
193  return false;
194  }
195  const size_t file_size = fs.GetByteSize(pathTwine);
196  const size_t max_size = code.max_size();
197  if (file_size > max_size) {
198  error_sp->Printf("file at path '%s' too large: "
199  "file_size = %zu, max_size = %zu\n",
200  path.c_str(), file_size, max_size);
201  return false;
202  }
203  auto data_sp = fs.CreateDataBuffer(pathTwine);
204  if (data_sp == nullptr) {
205  error_sp->Printf("could not create buffer for file at path '%s'\n",
206  path.c_str());
207  return false;
208  }
209  code.assign((const char *)data_sp->GetBytes(), data_sp->GetByteSize());
210  return true;
211 }
212 
214  lldb::StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
215  lldb::StreamFileSP error_sp(io_handler.GetErrorStreamFileSP());
216  bool extra_line = false;
217  bool did_quit = false;
218 
219  if (code.empty()) {
220  m_code.AppendString("");
221  static_cast<IOHandlerEditline &>(io_handler)
222  .SetBaseLineNumber(m_code.GetSize() + 1);
223  } else {
224  Debugger &debugger = m_target.GetDebugger();
225  CommandInterpreter &ci = debugger.GetCommandInterpreter();
226  extra_line = ci.GetSpaceReplPrompts();
227 
229  ->GetThreadList()
230  .GetSelectedThread()
231  ->GetSelectedFrame()
232  .get());
233 
234  lldb::ProcessSP process_sp(exe_ctx.GetProcessSP());
235 
236  if (code[0] == ':') {
237  // Meta command
238  // Strip the ':'
239  code.erase(0, 1);
240  if (!llvm::StringRef(code).trim().empty()) {
241  // "lldb" was followed by arguments, so just execute the command dump
242  // the results
243 
244  // Turn off prompt on quit in case the user types ":quit"
245  const bool saved_prompt_on_quit = ci.GetPromptOnQuit();
246  if (saved_prompt_on_quit)
247  ci.SetPromptOnQuit(false);
248 
249  // Execute the command
250  CommandReturnObject result(debugger.GetUseColor());
251  result.SetImmediateOutputStream(output_sp);
252  result.SetImmediateErrorStream(error_sp);
253  ci.HandleCommand(code.c_str(), eLazyBoolNo, result);
254 
255  if (saved_prompt_on_quit)
256  ci.SetPromptOnQuit(true);
257 
258  if (result.GetStatus() == lldb::eReturnStatusQuit) {
259  did_quit = true;
260  io_handler.SetIsDone(true);
261  if (debugger.CheckTopIOHandlerTypes(
263  // We typed "quit" or an alias to quit so we need to check if the
264  // command interpreter is above us and tell it that it is done as
265  // well so we don't drop back into the command interpreter if we
266  // have already quit
267  lldb::IOHandlerSP io_handler_sp(ci.GetIOHandler());
268  if (io_handler_sp)
269  io_handler_sp->SetIsDone(true);
270  }
271  }
272  } else {
273  // ":" was followed by no arguments, so push the LLDB command prompt
274  if (debugger.CheckTopIOHandlerTypes(
276  // If the user wants to get back to the command interpreter and the
277  // command interpreter is what launched the REPL, then just let the
278  // REPL exit and fall back to the command interpreter.
279  io_handler.SetIsDone(true);
280  } else {
281  // The REPL wasn't launched the by the command interpreter, it is the
282  // base IOHandler, so we need to get the command interpreter and
283  lldb::IOHandlerSP io_handler_sp(ci.GetIOHandler());
284  if (io_handler_sp) {
285  io_handler_sp->SetIsDone(false);
286  debugger.RunIOHandlerAsync(ci.GetIOHandler());
287  }
288  }
289  }
290  } else {
291  if (code[0] == '<') {
292  // User wants to read code from a file.
293  // Interpret rest of line as a literal path.
294  auto path = llvm::StringRef(code.substr(1)).trim().str();
295  if (!ReadCode(path, code, error_sp)) {
296  return;
297  }
298  }
299 
300  // Unwind any expression we might have been running in case our REPL
301  // expression crashed and the user was looking around
302  if (m_dedicated_repl_mode) {
303  Thread *thread = exe_ctx.GetThreadPtr();
304  if (thread && thread->UnwindInnermostExpression().Success()) {
305  thread->SetSelectedFrameByIndex(0, false);
306  exe_ctx.SetFrameSP(thread->GetSelectedFrame());
307  }
308  }
309 
310  const bool colorize_err = error_sp->GetFile().GetIsTerminalWithColors();
311 
314  expr_options.SetKeepInMemory(true);
316  expr_options.SetGenerateDebugInfo(true);
317  expr_options.SetREPLEnabled(true);
318  expr_options.SetColorizeErrors(colorize_err);
319  expr_options.SetPoundLine(m_repl_source_path.c_str(),
320  m_code.GetSize() + 1);
321 
322  expr_options.SetLanguage(GetLanguage());
323 
324  PersistentExpressionState *persistent_state =
326  if (!persistent_state)
327  return;
328 
329  const size_t var_count_before = persistent_state->GetSize();
330 
331  const char *expr_prefix = nullptr;
332  lldb::ValueObjectSP result_valobj_sp;
333  Status error;
334  lldb::ExpressionResults execution_results =
335  UserExpression::Evaluate(exe_ctx, expr_options, code.c_str(),
336  expr_prefix, result_valobj_sp, error,
337  nullptr); // fixed expression
338 
339  // CommandInterpreter &ci = debugger.GetCommandInterpreter();
340 
341  if (process_sp && process_sp->IsAlive()) {
342  bool add_to_code = true;
343  bool handled = false;
344  if (result_valobj_sp) {
346 
347  if (result_valobj_sp->GetError().Success()) {
348  handled |= PrintOneVariable(debugger, output_sp, result_valobj_sp);
349  } else if (result_valobj_sp->GetError().GetError() ==
351  if (format != lldb::eFormatVoid && debugger.GetNotifyVoid()) {
352  error_sp->PutCString("(void)\n");
353  handled = true;
354  }
355  }
356  }
357 
358  if (debugger.GetPrintDecls()) {
359  for (size_t vi = var_count_before, ve = persistent_state->GetSize();
360  vi != ve; ++vi) {
361  lldb::ExpressionVariableSP persistent_var_sp =
362  persistent_state->GetVariableAtIndex(vi);
363  lldb::ValueObjectSP valobj_sp = persistent_var_sp->GetValueObject();
364 
365  PrintOneVariable(debugger, output_sp, valobj_sp,
366  persistent_var_sp.get());
367  }
368  }
369 
370  if (!handled) {
371  bool useColors = error_sp->GetFile().GetIsTerminalWithColors();
372  switch (execution_results) {
375  add_to_code = false;
376  LLVM_FALLTHROUGH;
378  error_sp->Printf("%s\n", error.AsCString());
379  break;
380 
382  break;
384  if (useColors) {
385  error_sp->Printf(ANSI_ESCAPE1(ANSI_FG_COLOR_RED));
386  error_sp->Printf(ANSI_ESCAPE1(ANSI_CTRL_BOLD));
387  }
388  error_sp->Printf("Execution interrupted. ");
389  if (useColors)
390  error_sp->Printf(ANSI_ESCAPE1(ANSI_CTRL_NORMAL));
391  error_sp->Printf("Enter code to recover and continue.\nEnter LLDB "
392  "commands to investigate (type :help for "
393  "assistance.)\n");
394  break;
395 
397  // Breakpoint was hit, drop into LLDB command interpreter
398  if (useColors) {
399  error_sp->Printf(ANSI_ESCAPE1(ANSI_FG_COLOR_RED));
400  error_sp->Printf(ANSI_ESCAPE1(ANSI_CTRL_BOLD));
401  }
402  output_sp->Printf("Execution stopped at breakpoint. ");
403  if (useColors)
404  error_sp->Printf(ANSI_ESCAPE1(ANSI_CTRL_NORMAL));
405  output_sp->Printf("Enter LLDB commands to investigate (type help "
406  "for assistance.)\n");
407  {
408  lldb::IOHandlerSP io_handler_sp(ci.GetIOHandler());
409  if (io_handler_sp) {
410  io_handler_sp->SetIsDone(false);
411  debugger.RunIOHandlerAsync(ci.GetIOHandler());
412  }
413  }
414  break;
415 
417  error_sp->Printf("error: timeout\n");
418  if (error.AsCString())
419  error_sp->Printf("error: %s\n", error.AsCString());
420  break;
422  // Shoulnd't happen???
423  error_sp->Printf("error: could not fetch result -- %s\n",
424  error.AsCString());
425  break;
427  // Shoulnd't happen???
428  error_sp->Printf("error: stopped for debug -- %s\n",
429  error.AsCString());
430  break;
432  // Shoulnd't happen???
433  error_sp->Printf("error: expression thread vanished -- %s\n",
434  error.AsCString());
435  break;
436  }
437  }
438 
439  if (add_to_code) {
440  const uint32_t new_default_line = m_code.GetSize() + 1;
441 
442  m_code.SplitIntoLines(code);
443 
444  // Update our code on disk
445  if (!m_repl_source_path.empty()) {
446  auto file = FileSystem::Instance().Open(
450  lldb::eFilePermissionsFileDefault);
451  if (file) {
452  std::string code(m_code.CopyList());
453  code.append(1, '\n');
454  size_t bytes_written = code.size();
455  file.get()->Write(code.c_str(), bytes_written);
456  file.get()->Close();
457  } else {
458  std::string message = llvm::toString(file.takeError());
459  error_sp->Printf("error: couldn't open %s: %s\n",
460  m_repl_source_path.c_str(), message.c_str());
461  }
462 
463  // Now set the default file and line to the REPL source file
465  FileSpec(m_repl_source_path), new_default_line);
466  }
467  static_cast<IOHandlerEditline &>(io_handler)
468  .SetBaseLineNumber(m_code.GetSize() + 1);
469  }
470  if (extra_line) {
471  output_sp->Printf("\n");
472  }
473  }
474  }
475 
476  // Don't complain about the REPL process going away if we are in the
477  // process of quitting.
478  if (!did_quit && (!process_sp || !process_sp->IsAlive())) {
479  error_sp->Printf(
480  "error: REPL process is no longer alive, exiting REPL\n");
481  io_handler.SetIsDone(true);
482  }
483  }
484 }
485 
487  CompletionRequest &request) {
488  // Complete an LLDB command if the first character is a colon...
489  if (request.GetRawLine().startswith(":")) {
490  Debugger &debugger = m_target.GetDebugger();
491 
492  // auto complete LLDB commands
493  llvm::StringRef new_line = request.GetRawLine().drop_front();
494  CompletionResult sub_result;
495  CompletionRequest sub_request(new_line, request.GetRawCursorPos() - 1,
496  sub_result);
497  debugger.GetCommandInterpreter().HandleCompletion(sub_request);
498  StringList matches, descriptions;
499  sub_result.GetMatches(matches);
500  // Prepend command prefix that was excluded in the completion request.
501  if (request.GetCursorIndex() == 0)
502  for (auto &match : matches)
503  match.insert(0, 1, ':');
504  sub_result.GetDescriptions(descriptions);
505  request.AddCompletions(matches, descriptions);
506  return;
507  }
508 
509  // Strip spaces from the line and see if we had only spaces
510  if (request.GetRawLine().trim().empty()) {
511  // Only spaces on this line, so just indent
512  request.AddCompletion(m_indent_str);
513  return;
514  }
515 
516  std::string current_code;
517  current_code.append(m_code.CopyList());
518 
519  IOHandlerEditline &editline = static_cast<IOHandlerEditline &>(io_handler);
520  const StringList *current_lines = editline.GetCurrentLines();
521  if (current_lines) {
522  const uint32_t current_line_idx = editline.GetCurrentLineIndex();
523 
524  if (current_line_idx < current_lines->GetSize()) {
525  for (uint32_t i = 0; i < current_line_idx; ++i) {
526  const char *line_cstr = current_lines->GetStringAtIndex(i);
527  if (line_cstr) {
528  current_code.append("\n");
529  current_code.append(line_cstr);
530  }
531  }
532  }
533  }
534 
535  current_code.append("\n");
536  current_code += request.GetRawLine();
537 
538  CompleteCode(current_code, request);
539 }
540 
541 bool QuitCommandOverrideCallback(void *baton, const char **argv) {
542  Target *target = (Target *)baton;
543  lldb::ProcessSP process_sp(target->GetProcessSP());
544  if (process_sp) {
545  process_sp->Destroy(false);
546  process_sp->GetTarget().GetDebugger().ClearIOHandlers();
547  }
548  return false;
549 }
550 
552  Status error;
553 
556 
557  if (!error.Success())
558  return error;
559 
560  Debugger &debugger = m_target.GetDebugger();
561 
562  lldb::IOHandlerSP io_handler_sp(GetIOHandler());
563 
564  FileSpec save_default_file;
565  uint32_t save_default_line = 0;
566 
567  if (!m_repl_source_path.empty()) {
568  // Save the current default file and line
569  m_target.GetSourceManager().GetDefaultFileAndLine(save_default_file,
570  save_default_line);
571  }
572 
573  debugger.RunIOHandlerAsync(io_handler_sp);
574 
575  // Check if we are in dedicated REPL mode where LLDB was start with the "--
576  // repl" option from the command line. Currently we know this by checking if
577  // the debugger already has a IOHandler thread.
578  if (!debugger.HasIOHandlerThread()) {
579  // The debugger doesn't have an existing IOHandler thread, so this must be
580  // dedicated REPL mode...
581  m_dedicated_repl_mode = true;
582  debugger.StartIOHandlerThread();
583  llvm::StringRef command_name_str("quit");
584  CommandObject *cmd_obj =
586  command_name_str);
587  if (cmd_obj) {
588  assert(command_name_str.empty());
590  }
591  }
592 
593  // Wait for the REPL command interpreter to get popped
594  io_handler_sp->WaitForPop();
595 
596  if (m_dedicated_repl_mode) {
597  // If we were in dedicated REPL mode we would have started the IOHandler
598  // thread, and we should kill our process
599  lldb::ProcessSP process_sp = m_target.GetProcessSP();
600  if (process_sp && process_sp->IsAlive())
601  process_sp->Destroy(false);
602 
603  // Wait for the IO handler thread to exit (TODO: don't do this if the IO
604  // handler thread already exists...)
605  debugger.JoinIOHandlerThread();
606  }
607 
608  // Restore the default file and line
609  if (save_default_file && save_default_line != 0)
610  m_target.GetSourceManager().SetDefaultFileAndLine(save_default_file,
611  save_default_line);
612  return error;
613 }
lldb_private::toString
const char * toString(AppleArm64ExceptionClass EC)
Definition: AppleArm64ExceptionClass.h:38
lldb_private::CommandInterpreter::GetPromptOnQuit
bool GetPromptOnQuit() const
Definition: CommandInterpreter.cpp:141
lldb_private::ExpressionVariableList::GetSize
size_t GetSize()
Implementation of methods in ExpressionVariableListBase.
Definition: ExpressionVariable.h:123
lldb_private::Debugger::CheckTopIOHandlerTypes
bool CheckTopIOHandlerTypes(IOHandler::Type top_type, IOHandler::Type second_top_type)
Definition: Debugger.cpp:934
lldb_private::OptionGroupFormat::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: OptionGroupFormat.cpp:259
lldb::eExpressionThreadVanished
@ eExpressionThreadVanished
Definition: lldb-enumerations.h:280
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::REPL::m_dedicated_repl_mode
bool m_dedicated_repl_mode
Definition: REPL.h:147
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
ExpressionVariable.h
lldb_private::CompletionRequest::GetRawCursorPos
unsigned GetRawCursorPos() const
Definition: CompletionRequest.h:132
lldb_private::CommandReturnObject::GetStatus
lldb::ReturnStatus GetStatus()
Definition: CommandReturnObject.cpp:123
lldb::eExpressionResultUnavailable
@ eExpressionResultUnavailable
Definition: lldb-enumerations.h:278
lldb::Format
Format
Display format definitions.
Definition: lldb-enumerations.h:155
lldb_private::REPL::m_format_options
OptionGroupFormat m_format_options
Definition: REPL.h:136
lldb_private::EvaluateExpressionOptions::SetREPLEnabled
void SetREPLEnabled(bool b)
Definition: Target.h:367
lldb_private::EvaluateExpressionOptions::SetLanguage
void SetLanguage(lldb::LanguageType language)
Definition: Target.h:287
lldb_private::CommandInterpreter::GetCommandObjectForCommand
CommandObject * GetCommandObjectForCommand(llvm::StringRef &command_line)
ANSI_CTRL_NORMAL
#define ANSI_CTRL_NORMAL
Definition: AnsiTerminal.h:34
lldb_private::Debugger::GetCommandInterpreter
CommandInterpreter & GetCommandInterpreter()
Definition: Debugger.h:193
lldb::eExpressionStoppedForDebug
@ eExpressionStoppedForDebug
Definition: lldb-enumerations.h:279
lldb_private::REPL::GetIOHandler
lldb::IOHandlerSP GetIOHandler()
Definition: REPL.cpp:66
lldb_private::CommandInterpreter::HandleCommand
bool HandleCommand(const char *command_line, LazyBool add_to_history, const ExecutionContext &override_context, CommandReturnObject &result)
lldb::ExpressionResults
ExpressionResults
The results of expression evaluation.
Definition: lldb-enumerations.h:270
lldb_private::REPL::IOHandlerFixIndentation
int IOHandlerFixIndentation(IOHandler &io_handler, const StringList &lines, int cursor_position) override
Called when a new line is created or one of an identified set of indentation characters is typed.
Definition: REPL.cpp:160
lldb_private::REPL::m_expr_options
EvaluateExpressionOptions m_expr_options
Definition: REPL.h:138
lldb_private::REPL::GetAutoIndentCharacters
virtual const char * GetAutoIndentCharacters()=0
lldb_private::StringList::AppendString
void AppendString(const std::string &s)
Definition: StringList.cpp:43
lldb_private::Debugger::GetPrintDecls
bool GetPrintDecls() const
Definition: Debugger.cpp:448
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:961
lldb_private::EvaluateExpressionOptions
Definition: Target.h:259
lldb_private::EvaluateExpressionOptions::SetPoundLine
void SetPoundLine(const char *path, uint32_t line) const
Definition: Target.h:382
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
lldb_private::Thread::UnwindInnermostExpression
Status UnwindInnermostExpression()
Unwinds the thread stack for the innermost expression plan currently on the thread plan stack.
Definition: Thread.cpp:1220
lldb_private::REPL::IOHandlerComplete
void IOHandlerComplete(IOHandler &io_handler, CompletionRequest &request) override
Definition: REPL.cpp:486
lldb::eExpressionSetupError
@ eExpressionSetupError
Definition: lldb-enumerations.h:272
lldb_private::Debugger::StartIOHandlerThread
bool StartIOHandlerThread()
Definition: Debugger.cpp:1624
lldb_private::IOHandler::Type::REPL
@ REPL
UserExpression.h
lldb_private::StringList::SplitIntoLines
size_t SplitIntoLines(const std::string &lines)
Definition: StringList.cpp:146
lldb_private::REPL::m_code
StringList m_code
Definition: REPL.h:149
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
lldb_private::IOHandlerEditline::GetCurrentLines
const StringList * GetCurrentLines() const
Definition: IOHandler.h:414
lldb_private::UserExpression::Evaluate
static lldb::ExpressionResults Evaluate(ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options, llvm::StringRef expr_cstr, llvm::StringRef expr_prefix, lldb::ValueObjectSP &result_valobj_sp, Status &error, std::string *fixed_expression=nullptr, ValueObject *ctx_obj=nullptr)
Evaluate one expression in the scratch context of the target passed in the exe_ctx and return its res...
Definition: UserExpression.cpp:139
lldb_private::CompletionResult::GetMatches
void GetMatches(StringList &matches) const
Adds all collected completion matches to the given list.
Definition: CompletionRequest.cpp:71
lldb_private::CommandInterpreter::GetIOHandler
lldb::IOHandlerSP GetIOHandler(bool force_create=false, CommandInterpreterRunOptions *options=nullptr)
lldb::eExpressionTimedOut
@ eExpressionTimedOut
Definition: lldb-enumerations.h:277
lldb_private::REPL::IOHandlerGetControlSequence
ConstString IOHandlerGetControlSequence(char ch) override
Definition: REPL.cpp:113
lldb_private::Target::GetDebugger
Debugger & GetDebugger()
Definition: Target.h:1000
CommandReturnObject.h
lldb_private::CommandInterpreter::SetPromptOnQuit
void SetPromptOnQuit(bool enable)
Definition: CommandInterpreter.cpp:147
lldb_private::REPL::m_enable_auto_indent
bool m_enable_auto_indent
Definition: REPL.h:141
Debugger.h
lldb_private::Target
Definition: Target.h:451
lldb_private::ExecutionContext::GetThreadPtr
Thread * GetThreadPtr() const
Returns a pointer to the thread object.
Definition: ExecutionContext.h:399
lldb_private::REPL::IOHandlerGetHelpPrologue
const char * IOHandlerGetHelpPrologue() override
Definition: REPL.cpp:121
lldb_private::REPL::GetSourcePath
std::string GetSourcePath()
Definition: REPL.cpp:52
lldb_private::CommandInterpreter::GetSpaceReplPrompts
bool GetSpaceReplPrompts() const
Definition: CommandInterpreter.cpp:230
lldb_private::StringList::GetSize
size_t GetSize() const
Definition: StringList.cpp:68
lldb_private::REPL::IOHandlerInputInterrupted
void IOHandlerInputInterrupted(IOHandler &io_handler, std::string &line) override
Definition: REPL.cpp:106
lldb_private::File::eOpenOptionTruncate
@ eOpenOptionTruncate
Definition: File.h:56
lldb_private::File::eOpenOptionCanCreate
@ eOpenOptionCanCreate
Definition: File.h:55
lldb_private::FileSpec
Definition: FileSpec.h:56
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::Status::Success
bool Success() const
Test for success condition.
Definition: Status.cpp:288
lldb_private::REPL::m_target
Target & m_target
Definition: REPL.h:151
lldb_private::StringList::GetStringAtIndex
const char * GetStringAtIndex(size_t idx) const
Definition: StringList.cpp:80
REPL.h
lldb_private::CommandInterpreter::HandleCompletion
void HandleCompletion(CompletionRequest &request)
lldb_private::REPL::m_indent_str
std::string m_indent_str
Definition: REPL.h:142
lldb_private::REPL::m_io_handler_sp
lldb::IOHandlerSP m_io_handler_sp
Definition: REPL.h:152
lldb_private::Debugger::GetAutoIndent
bool GetAutoIndent() const
Definition: Debugger.cpp:438
LLDB_INVALID_OFFSET
#define LLDB_INVALID_OFFSET
Definition: lldb-defines.h:97
lldb_private::OptionGroupValueObjectDisplay::use_dynamic
lldb::DynamicValueType use_dynamic
Definition: OptionGroupValueObjectDisplay.h:52
lldb_private::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:202
lldb_private::SourceManager::GetDefaultFileAndLine
bool GetDefaultFileAndLine(FileSpec &file_spec, uint32_t &line)
Definition: SourceManager.cpp:325
ANSI_CTRL_BOLD
#define ANSI_CTRL_BOLD
Definition: AnsiTerminal.h:35
lldb_private::REPL::~REPL
~REPL() override
lldb::eExpressionDiscarded
@ eExpressionDiscarded
Definition: lldb-enumerations.h:274
lldb_private::Thread
Definition: Thread.h:60
lldb::eExpressionCompleted
@ eExpressionCompleted
Definition: lldb-enumerations.h:271
lldb_private::OptionGroupFormat::GetFormat
lldb::Format GetFormat() const
Definition: OptionGroupFormat.h:44
lldb_private::REPL::m_varobj_options
OptionGroupValueObjectDisplay m_varobj_options
Definition: REPL.h:137
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:35
lldb_private::StringList
Definition: StringList.h:25
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::IOHandler
Definition: IOHandler.h:46
lldb_private::EvaluateExpressionOptions::SetColorizeErrors
void SetColorizeErrors(bool b)
Definition: Target.h:359
lldb_private::REPL::REPL
REPL(LLVMCastKind kind, Target &target)
Definition: REPL.cpp:25
lldb_private::CommandInterpreter
Definition: CommandInterpreter.h:214
lldb_private::Debugger
Definition: Debugger.h:70
HostInfo.h
lldb_private::REPL::PrintOneVariable
virtual bool PrintOneVariable(Debugger &debugger, lldb::StreamFileSP &output_sp, lldb::ValueObjectSP &valobj_sp, ExpressionVariable *var=nullptr)=0
lldb_private::Target::GetPersistentExpressionStateForLanguage
PersistentExpressionState * GetPersistentExpressionStateForLanguage(lldb::LanguageType language)
Definition: Target.cpp:2258
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::CompletionRequest::AddCompletions
void AddCompletions(const StringList &completions)
Adds multiple possible completion strings.
Definition: CompletionRequest.h:196
lldb_private::EvaluateExpressionOptions::SetKeepInMemory
void SetKeepInMemory(bool keep=true)
Definition: Target.h:316
lldb_private::REPL::GetDesiredIndentation
virtual lldb::offset_t GetDesiredIndentation(const StringList &lines, int cursor_position, int tab_size)=0
Thread.h
lldb_private::REPL::IOHandlerInputComplete
void IOHandlerInputComplete(IOHandler &io_handler, std::string &line) override
Called when a line or lines have been retrieved.
Definition: REPL.cpp:213
lldb_private::PluginManager::GetREPLCreateCallbackAtIndex
static REPLCreateInstance GetREPLCreateCallbackAtIndex(uint32_t idx)
Definition: PluginManager.cpp:1342
lldb::eExpressionInterrupted
@ eExpressionInterrupted
Definition: lldb-enumerations.h:275
lldb_private::SourceManager::SetDefaultFileAndLine
bool SetDefaultFileAndLine(const FileSpec &file_spec, uint32_t line)
Definition: SourceManager.cpp:311
AnsiTerminal.h
lldb_private::REPL::LLVMCastKind
LLVMCastKind
Definition: REPL.h:24
lldb_private::Debugger::JoinIOHandlerThread
void JoinIOHandlerThread()
Definition: Debugger.cpp:1647
lldb_private::REPL::GetSourceFileBasename
virtual ConstString GetSourceFileBasename()=0
lldb_private::IOHandlerEditline::GetCurrentLineIndex
uint32_t GetCurrentLineIndex() const
Definition: IOHandler.cpp:503
lldb_private::REPL::GetLanguage
virtual lldb::LanguageType GetLanguage()=0
lldb_private::OptionGroupValueObjectDisplay::use_objc
bool use_objc
Definition: OptionGroupValueObjectDisplay.h:45
lldb::eExpressionHitBreakpoint
@ eExpressionHitBreakpoint
Definition: lldb-enumerations.h:276
lldb_private::CommandObject
Definition: CommandObject.h:67
lldb::eFormatVoid
@ eFormatVoid
Do not print this.
Definition: lldb-enumerations.h:200
lldb_private::StringList::CopyList
std::string CopyList(const char *item_preamble=nullptr, const char *items_sep="\n") const
Definition: StringList.cpp:192
StreamFile.h
lldb_private::IOHandler::SetIsDone
virtual void SetIsDone(bool b)
Definition: IOHandler.h:90
lldb_private::Target::GetProcessSP
const lldb::ProcessSP & GetProcessSP() const
Definition: Target.cpp:211
lldb_private::CommandObject::SetOverrideCallback
void SetOverrideCallback(lldb::CommandOverrideCallback callback, void *baton)
Definition: CommandObject.h:299
lldb_private::REPL::SourceIsComplete
virtual bool SourceIsComplete(const std::string &source)=0
lldb_private::ExecutionContext::GetProcessSP
const lldb::ProcessSP & GetProcessSP() const
Get accessor to get the process shared pointer.
Definition: ExecutionContext.h:459
lldb_private::File::eOpenOptionWriteOnly
@ eOpenOptionWriteOnly
Definition: File.h:51
lldb_private::REPL::IOHandlerInterrupt
bool IOHandlerInterrupt(IOHandler &io_handler) override
Definition: REPL.cpp:104
lldb_private::CompletionRequest::GetRawLine
llvm::StringRef GetRawLine() const
Returns the raw user input used to create this CompletionRequest cut off at the cursor position.
Definition: CompletionRequest.h:120
lldb_private::Status
Definition: Status.h:44
lldb_private::REPL::IOHandlerActivated
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override
Definition: REPL.cpp:95
lldb_private::Debugger::GetNotifyVoid
bool GetNotifyVoid() const
Definition: Debugger.cpp:268
lldb_private::CommandReturnObject
Definition: CommandReturnObject.h:25
message
message(FATAL_ERROR "invalid libipt include path provided") endif() include_directories($
Definition: Plugins/Trace/intel-pt/CMakeLists.txt:6
uint32_t
lldb_private::Debugger::GetTabSize
uint32_t GetTabSize() const
Definition: Debugger.cpp:458
lldb_private::eLazyBoolNo
@ eLazyBoolNo
Definition: lldb-private-enumerations.h:115
lldb_private::EvaluateExpressionOptions::SetUseDynamic
void SetUseDynamic(lldb::DynamicValueType dynamic=lldb::eDynamicCanRunTarget)
Definition: Target.h:321
lldb_private::EvaluateExpressionOptions::SetCoerceToId
void SetCoerceToId(bool coerce=true)
Definition: Target.h:302
lldb_private::REPL::CalculateActualIndentation
static int CalculateActualIndentation(const StringList &lines)
Definition: REPL.cpp:147
lldb_private::CommandReturnObject::SetImmediateOutputStream
void SetImmediateOutputStream(const lldb::StreamSP &stream_sp)
Definition: CommandReturnObject.h:79
lldb_private::REPL::CompleteCode
virtual void CompleteCode(const std::string &current_code, CompletionRequest &request)=0
lldb_private::IOHandler::GetDebugger
Debugger & GetDebugger()
Definition: IOHandler.h:137
lldb_private::Thread::GetSelectedFrame
lldb::StackFrameSP GetSelectedFrame()
Definition: Thread.cpp:263
lldb_private::EvaluateExpressionOptions::SetGenerateDebugInfo
void SetGenerateDebugInfo(bool b)
Definition: Target.h:355
ReadCode
static bool ReadCode(const std::string &path, std::string &code, lldb::StreamFileSP &error_sp)
Definition: REPL.cpp:183
PluginManager.h
ANSI_FG_COLOR_RED
#define ANSI_FG_COLOR_RED
Definition: AnsiTerminal.h:14
QuitCommandOverrideCallback
bool QuitCommandOverrideCallback(void *baton, const char **argv)
Definition: REPL.cpp:541
lldb_private::Debugger::GetUseColor
bool GetUseColor() const
Definition: Debugger.cpp:343
lldb_private::UserExpression::kNoResult
static const Status::ValueType kNoResult
ValueObject::GetError() returns this if there is no result from the expression.
Definition: UserExpression.h:265
lldb_private::FileSystem::Instance
static FileSystem & Instance()
Definition: common/FileSystem.cpp:45
lldb_private::PersistentExpressionState
Definition: ExpressionVariable.h:203
lldb_private::CompletionRequest::GetCursorIndex
size_t GetCursorIndex() const
Definition: CompletionRequest.h:156
lldb_private::FileSpec::AppendPathComponent
void AppendPathComponent(llvm::StringRef component)
Definition: FileSpec.cpp:435
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::REPL::IOHandlerGetFixIndentationCharacters
const char * IOHandlerGetFixIndentationCharacters() override
Definition: REPL.cpp:109
lldb_private::ExpressionVariableList::GetVariableAtIndex
lldb::ExpressionVariableSP GetVariableAtIndex(size_t index)
Definition: ExpressionVariable.h:125
lldb_private::OptionGroupValueObjectDisplay::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: OptionGroupValueObjectDisplay.cpp:157
lldb_private::CompletionRequest::AddCompletion
void AddCompletion(llvm::StringRef completion, llvm::StringRef description="", CompletionMode mode=CompletionMode::Normal)
Adds a possible completion string.
Definition: CompletionRequest.h:167
lldb_private::IOHandler::Type::CommandInterpreter
@ CommandInterpreter
CommandInterpreter.h
lldb_private::CommandInterpreter::GetExecutionContext
ExecutionContext GetExecutionContext() const
lldb::eReturnStatusQuit
@ eReturnStatusQuit
Definition: lldb-enumerations.h:266
lldb_private::CommandReturnObject::SetImmediateErrorStream
void SetImmediateErrorStream(const lldb::StreamSP &stream_sp)
Definition: CommandReturnObject.h:85
lldb::eExpressionParseError
@ eExpressionParseError
Definition: lldb-enumerations.h:273
lldb_private::CompletionResult
Definition: CompletionRequest.h:38
lldb_private::Target::GetSourceManager
SourceManager & GetSourceManager()
Definition: Target.cpp:2533
REPLCreateInstance
ANSI_ESCAPE1
#define ANSI_ESCAPE1(s)
Definition: AnsiTerminal.h:51
lldb_private::REPL::RunLoop
Status RunLoop()
Definition: REPL.cpp:551
lldb_private::ExecutionContext::SetFrameSP
void SetFrameSP(const lldb::StackFrameSP &frame_sp)
Set accessor to set only the frame shared pointer.
Definition: ExecutionContext.cpp:258
lldb_private::FileSpec::GetPath
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:348
lldb_private::CompletionResult::GetDescriptions
void GetDescriptions(StringList &descriptions) const
Adds all collected completion descriptions to the given list.
Definition: CompletionRequest.cpp:77
lldb_private::REPL::IOHandlerIsInputComplete
bool IOHandlerIsInputComplete(IOHandler &io_handler, StringList &lines) override
Called to determine whether typing enter after the last line in lines should end input.
Definition: REPL.cpp:133
lldb_private::IOHandler::GetOutputStreamFileSP
lldb::StreamFileSP GetOutputStreamFileSP()
Definition: IOHandler.cpp:108
lldb_private::Debugger::HasIOHandlerThread
bool HasIOHandlerThread()
Definition: Debugger.cpp:1622
lldb_private::FileSpec::GetFilename
ConstString & GetFilename()
Filename string get accessor.
Definition: FileSpec.cpp:341
lldb_private::REPL::DoInitialization
virtual Status DoInitialization()=0
lldb_private::REPL::m_repl_source_path
std::string m_repl_source_path
Definition: REPL.h:146
lldb_private::REPL::IOHandlerGetCommandPrefix
const char * IOHandlerGetCommandPrefix() override
Definition: REPL.cpp:119
lldb_private::IOHandler::GetErrorStreamFileSP
lldb::StreamFileSP GetErrorStreamFileSP()
Definition: IOHandler.cpp:110
lldb_private::CompletionRequest
Definition: CompletionRequest.h:100
lldb_private::Thread::SetSelectedFrameByIndex
bool SetSelectedFrameByIndex(uint32_t frame_idx, bool broadcast=false)
Definition: Thread.cpp:280
lldb_private::IOHandlerEditline
Definition: IOHandler.h:332