21#include "llvm/ADT/StringRef.h" 
   22#include "llvm/Support/FormatAdapters.h" 
   44                          llvm::StringRef(
">>> "), 
llvm::StringRef(
"..> "),
 
   45                          true, debugger.GetUseColor(), 0, *this),
 
 
   59    const char *instructions = 
nullptr;
 
   64      instructions = 
"Enter your Lua command(s). Type 'quit' to end.\n" 
   65                     "The commands are compiled as the body of the following " 
   67                     "function (frame, wp) end\n";
 
   71      instructions = 
"Enter your Lua command(s). Type 'quit' to end.\n" 
   72                     "The commands are compiled as the body of the following " 
   74                     "function (frame, bp_loc, ...) end\n";
 
   78    if (instructions == 
nullptr)
 
   84        locked_stream << instructions;
 
 
   91    size_t last = lines.
GetSize() - 1;
 
   99    lines.
Join(
"\n", str);
 
  102      std::string error_str = 
toString(std::move(E));
 
  104      return error_str.find(
"<eof>") == std::string::npos;
 
 
  112                              std::string &data)
 override {
 
  115      auto *bp_options_vec =
 
  116          static_cast<std::vector<std::reference_wrapper<BreakpointOptions>
> *>(
 
  120            bp_options, data.c_str(), 
false);
 
  124          locked_stream << 
error.AsCString() << 
'\n';
 
 
 
  165  auto info = std::make_shared<StructuredData::Dictionary>();
 
  166  info->AddStringItem(
"language", 
"lua");
 
 
  173  if (command.empty()) {
 
  175      result->
AppendError(
"empty command passed to lua\n");
 
  179  llvm::Expected<std::unique_ptr<ScriptInterpreterIORedirect>>
 
  182  if (!io_redirect_or_error) {
 
  185          "failed to redirect I/O: {0}\n",
 
  186          llvm::fmt_consume(io_redirect_or_error.takeError()));
 
  188      llvm::consumeError(io_redirect_or_error.takeError());
 
  198                                   llvm::toString(std::move(e)));
 
  202  if (llvm::Error e = 
m_lua->Run(command)) {
 
  204        "lua failed attempting to evaluate '{0}': {1}\n", command,
 
  205        llvm::toString(std::move(e)));
 
 
  233  if (llvm::Error e = 
m_lua->LoadModule(filename)) {
 
  235        "lua failed to import '{0}': {1}\n", filename,
 
  236        llvm::toString(std::move(e)));
 
 
  243  static llvm::once_flag g_once_flag;
 
  245  llvm::call_once(g_once_flag, []() {
 
 
  256    return llvm::Error::success();
 
  258  const char *fmt_str =
 
  259      "lldb.debugger = lldb.SBDebugger.FindDebuggerWithID({0}); " 
  260      "lldb.target = lldb.debugger:GetSelectedTarget(); " 
  261      "lldb.process = lldb.target:GetProcess(); " 
  262      "lldb.thread = lldb.process:GetSelectedThread(); " 
  263      "lldb.frame = lldb.thread:GetSelectedFrame()";
 
  264  return m_lua->Run(llvm::formatv(fmt_str, debugger_id).str());
 
 
  269    return llvm::Error::success();
 
  273  llvm::StringRef str = 
"lldb.debugger = nil; " 
  274                        "lldb.target = nil; " 
  275                        "lldb.process = nil; " 
  276                        "lldb.thread = nil; " 
  278  return m_lua->Run(str);
 
 
  288  if (target == 
nullptr)
 
  301  llvm::Expected<bool> BoolOrErr = 
lua.CallBreakpointCallback(
 
  303  if (llvm::Error E = BoolOrErr.takeError()) {
 
 
  317  if (target == 
nullptr)
 
  328  llvm::Expected<bool> BoolOrErr =
 
  329      lua.CallWatchpointCallback(baton, stop_frame_sp, wp_sp);
 
  330  if (llvm::Error E = BoolOrErr.takeError()) {
 
 
  339    std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec,
 
  343  io_handler_sp->SetUserData(&bp_options_vec);
 
 
  351  io_handler_sp->SetUserData(wp_options);
 
 
  358  const char *fmt_str = 
"return {0}(frame, bp_loc, ...)";
 
  359  std::string oneliner = llvm::formatv(fmt_str, function_name).str();
 
 
  373  auto data_up = std::make_unique<CommandDataLua>(extra_args_sp);
 
  375      m_lua->RegisterBreakpointCallback(data_up.get(), command_body_text);
 
  379      std::make_shared<BreakpointOptions::CommandBaton>(std::move(data_up));
 
 
  394  auto data_up = std::make_unique<WatchpointOptions::CommandData>();
 
  396      m_lua->RegisterWatchpointCallback(data_up.get(), command_body_text);
 
  400      std::make_shared<WatchpointOptions::CommandBaton>(std::move(data_up));
 
 
  408  return std::make_shared<ScriptInterpreterLua>(debugger);
 
 
  412  return "Lua script interpreter";
 
 
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_PLUGIN_DEFINE(PluginName)
#define LLDB_SCOPED_TIMER()
IOHandlerLuaInterpreter(Debugger &debugger, ScriptInterpreterLua &script_interpreter, ActiveIOHandler active_io_handler=eIOHandlerNone)
~IOHandlerLuaInterpreter() override
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override
ActiveIOHandler m_active_io_handler
ScriptInterpreterLua & m_script_interpreter
bool IOHandlerIsInputComplete(IOHandler &io_handler, StringList &lines) override
Called to determine whether typing enter after the last line in lines should end input.
bool IsQuitCommand(llvm::StringRef cmd)
void IOHandlerInputComplete(IOHandler &io_handler, std::string &data) override
Called when a line or lines have been retrieved.
"lldb/Breakpoint/BreakpointOptions.h" Class that manages the options on a breakpoint or breakpoint lo...
void SetCallback(BreakpointHitCallback callback, const lldb::BatonSP &baton_sp, bool synchronous=false)
Adds a callback to the breakpoint option set.
void void AppendError(llvm::StringRef in_string)
void AppendErrorWithFormatv(const char *format, Args &&...args)
A class to manage flag bits.
lldb::StreamUP GetAsyncErrorStream()
lldb::FileSP GetErrorFileSP()
lldb::FileSP GetOutputFileSP()
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, std::optional< lldb::ScriptLanguage > language={})
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
const lldb::StackFrameSP & GetFrameSP() const
Get accessor to get the frame shared pointer.
Target * GetTargetPtr() const
Returns a pointer to the target object.
IOHandlerDelegate(Completion completion=Completion::None)
bool SetPrompt(llvm::StringRef prompt) override
IOHandlerEditline(Debugger &debugger, IOHandler::Type type, const char *editline_name, llvm::StringRef prompt, llvm::StringRef continuation_prompt, bool multi_line, bool color, uint32_t line_number_start, IOHandlerDelegate &delegate)
lldb::LockableStreamFileSP GetErrorStreamFileSP()
lldb::LockableStreamFileSP GetOutputStreamFileSP()
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
lldb::FileSP GetOutputFile() const
lldb::FileSP GetErrorFile() const
void Flush()
Flush our output and error file handles.
static llvm::Expected< std::unique_ptr< ScriptInterpreterIORedirect > > Create(bool enable_io, Debugger &debugger, CommandReturnObject *result)
Create an IO redirect.
StructuredData::ObjectSP m_extra_args_sp
Status SetBreakpointCommandCallbackFunction(BreakpointOptions &bp_options, const char *function_name, StructuredData::ObjectSP extra_args_sp) override
Set a script function as the callback for the breakpoint.
llvm::Error EnterSession(lldb::user_id_t debugger_id)
static bool WatchpointCallbackFunction(void *baton, StoppointCallbackContext *context, lldb::user_id_t watch_id)
std::unique_ptr< Lua > m_lua
static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger)
bool LoadScriptingModule(const char *filename, const LoadScriptOptions &options, lldb_private::Status &error, StructuredData::ObjectSP *module_sp=nullptr, FileSpec extra_search_dir={}, lldb::TargetSP loaded_into_target_sp={}) override
Status SetBreakpointCommandCallback(BreakpointOptions &bp_options, const char *command_body_text, bool is_callback) override
void SetWatchpointCommandCallback(WatchpointOptions *wp_options, const char *command_body_text, bool is_callback) override
Set a one-liner as the callback for the watchpoint.
static bool BreakpointCallbackFunction(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
void ExecuteInterpreterLoop() override
void CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options, CommandReturnObject &result) override
llvm::Error LeaveSession()
ScriptInterpreterLua(Debugger &debugger)
~ScriptInterpreterLua() override
bool ExecuteOneLine(llvm::StringRef command, CommandReturnObject *result, const ExecuteScriptOptions &options=ExecuteScriptOptions()) override
Status RegisterBreakpointCallback(BreakpointOptions &bp_options, const char *command_body_text, StructuredData::ObjectSP extra_args_sp)
static llvm::StringRef GetPluginNameStatic()
void CollectDataForBreakpointCommandCallback(std::vector< std::reference_wrapper< BreakpointOptions > > &bp_options_vec, CommandReturnObject &result) override
StructuredData::DictionarySP GetInterpreterInfo() override
static llvm::StringRef GetPluginDescriptionStatic()
Status RegisterWatchpointCallback(WatchpointOptions *wp_options, const char *command_body_text, StructuredData::ObjectSP extra_args_sp)
ScriptInterpreter(Debugger &debugger, lldb::ScriptLanguage script_lang)
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
ExecutionContextRef exe_ctx_ref
llvm::StringRef GetString() const
const char * GetStringAtIndex(size_t idx) const
void DeleteStringAtIndex(size_t id)
void Join(const char *separator, Stream &strm)
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
lldb::BreakpointSP GetBreakpointByID(lldb::break_id_t break_id)
Debugger & GetDebugger() const
WatchpointList & GetWatchpointList()
lldb::WatchpointSP FindByID(lldb::watch_id_t watchID) const
Returns a shared pointer to the watchpoint with id watchID, const version.
"lldb/Breakpoint/WatchpointOptions.h" Class that manages the options on a watchpoint.
void SetCallback(WatchpointHitCallback callback, const lldb::BatonSP &baton_sp, bool synchronous=false)
Adds a callback to the watchpoint option set.
A class that represents a running process on the host machine.
const char * toString(AppleArm64ExceptionClass EC)
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
std::shared_ptr< lldb_private::IOHandler > IOHandlerSP
std::shared_ptr< lldb_private::ScriptInterpreter > ScriptInterpreterSP
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
std::shared_ptr< lldb_private::Watchpoint > WatchpointSP
std::shared_ptr< lldb_private::LockableStreamFile > LockableStreamFileSP
std::shared_ptr< lldb_private::Target > TargetSP
lldb::user_id_t GetID() const
Get accessor for the user ID.