1480093f4SDimitry Andric //===-- ScriptInterpreterLua.h ----------------------------------*- C++ -*-===// 2480093f4SDimitry Andric // 3480093f4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4480093f4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5480093f4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6480093f4SDimitry Andric // 7480093f4SDimitry Andric //===----------------------------------------------------------------------===// 8480093f4SDimitry Andric 9480093f4SDimitry Andric #ifndef liblldb_ScriptInterpreterLua_h_ 10480093f4SDimitry Andric #define liblldb_ScriptInterpreterLua_h_ 11480093f4SDimitry Andric 12fe6060f1SDimitry Andric #include <vector> 13fe6060f1SDimitry Andric 14fe6060f1SDimitry Andric #include "lldb/Breakpoint/WatchpointOptions.h" 15e8d8bef9SDimitry Andric #include "lldb/Core/StructuredDataImpl.h" 16480093f4SDimitry Andric #include "lldb/Interpreter/ScriptInterpreter.h" 17e8d8bef9SDimitry Andric #include "lldb/Utility/Status.h" 18e8d8bef9SDimitry Andric #include "lldb/lldb-enumerations.h" 19480093f4SDimitry Andric 20480093f4SDimitry Andric namespace lldb_private { 21480093f4SDimitry Andric class Lua; 22480093f4SDimitry Andric class ScriptInterpreterLua : public ScriptInterpreter { 23480093f4SDimitry Andric public: 24e8d8bef9SDimitry Andric class CommandDataLua : public BreakpointOptions::CommandData { 25e8d8bef9SDimitry Andric public: CommandDataLua()26e8d8bef9SDimitry Andric CommandDataLua() : BreakpointOptions::CommandData() { 27e8d8bef9SDimitry Andric interpreter = lldb::eScriptLanguageLua; 28e8d8bef9SDimitry Andric } CommandDataLua(StructuredData::ObjectSP extra_args_sp)29e8d8bef9SDimitry Andric CommandDataLua(StructuredData::ObjectSP extra_args_sp) 30e8d8bef9SDimitry Andric : BreakpointOptions::CommandData(), m_extra_args_sp(extra_args_sp) { 31e8d8bef9SDimitry Andric interpreter = lldb::eScriptLanguageLua; 32e8d8bef9SDimitry Andric } 33e8d8bef9SDimitry Andric StructuredData::ObjectSP m_extra_args_sp; 34e8d8bef9SDimitry Andric }; 35e8d8bef9SDimitry Andric 36480093f4SDimitry Andric ScriptInterpreterLua(Debugger &debugger); 37480093f4SDimitry Andric 38480093f4SDimitry Andric ~ScriptInterpreterLua() override; 39480093f4SDimitry Andric 40480093f4SDimitry Andric bool ExecuteOneLine( 41480093f4SDimitry Andric llvm::StringRef command, CommandReturnObject *result, 42480093f4SDimitry Andric const ExecuteScriptOptions &options = ExecuteScriptOptions()) override; 43480093f4SDimitry Andric 44480093f4SDimitry Andric void ExecuteInterpreterLoop() override; 45480093f4SDimitry Andric 46fe6060f1SDimitry Andric bool LoadScriptingModule(const char *filename, 47fe6060f1SDimitry Andric const LoadScriptOptions &options, 48480093f4SDimitry Andric lldb_private::Status &error, 49e8d8bef9SDimitry Andric StructuredData::ObjectSP *module_sp = nullptr, 50e8d8bef9SDimitry Andric FileSpec extra_search_dir = {}) override; 51480093f4SDimitry Andric 52349cc55cSDimitry Andric StructuredData::DictionarySP GetInterpreterInfo() override; 53349cc55cSDimitry Andric 54480093f4SDimitry Andric // Static Functions 55480093f4SDimitry Andric static void Initialize(); 56480093f4SDimitry Andric 57480093f4SDimitry Andric static void Terminate(); 58480093f4SDimitry Andric 59480093f4SDimitry Andric static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger); 60480093f4SDimitry Andric GetPluginNameStatic()61349cc55cSDimitry Andric static llvm::StringRef GetPluginNameStatic() { return "script-lua"; } 62480093f4SDimitry Andric 63349cc55cSDimitry Andric static llvm::StringRef GetPluginDescriptionStatic(); 64480093f4SDimitry Andric 65e8d8bef9SDimitry Andric static bool BreakpointCallbackFunction(void *baton, 66e8d8bef9SDimitry Andric StoppointCallbackContext *context, 67e8d8bef9SDimitry Andric lldb::user_id_t break_id, 68e8d8bef9SDimitry Andric lldb::user_id_t break_loc_id); 69e8d8bef9SDimitry Andric 70fe6060f1SDimitry Andric static bool WatchpointCallbackFunction(void *baton, 71fe6060f1SDimitry Andric StoppointCallbackContext *context, 72fe6060f1SDimitry Andric lldb::user_id_t watch_id); 73fe6060f1SDimitry Andric 74480093f4SDimitry Andric // PluginInterface protocol GetPluginName()75349cc55cSDimitry Andric llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } 76480093f4SDimitry Andric 77480093f4SDimitry Andric Lua &GetLua(); 78480093f4SDimitry Andric 79480093f4SDimitry Andric llvm::Error EnterSession(lldb::user_id_t debugger_id); 80480093f4SDimitry Andric llvm::Error LeaveSession(); 81480093f4SDimitry Andric 82e8d8bef9SDimitry Andric void CollectDataForBreakpointCommandCallback( 83fe6060f1SDimitry Andric std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec, 84e8d8bef9SDimitry Andric CommandReturnObject &result) override; 85e8d8bef9SDimitry Andric 86fe6060f1SDimitry Andric void 87fe6060f1SDimitry Andric CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options, 88fe6060f1SDimitry Andric CommandReturnObject &result) override; 89fe6060f1SDimitry Andric 90fe6060f1SDimitry Andric Status SetBreakpointCommandCallback(BreakpointOptions &bp_options, 91*06c3fb27SDimitry Andric const char *command_body_text, 92*06c3fb27SDimitry Andric bool is_callback) override; 93fe6060f1SDimitry Andric 94fe6060f1SDimitry Andric void SetWatchpointCommandCallback(WatchpointOptions *wp_options, 95*06c3fb27SDimitry Andric const char *command_body_text, 96*06c3fb27SDimitry Andric bool is_callback) override; 97e8d8bef9SDimitry Andric 98e8d8bef9SDimitry Andric Status SetBreakpointCommandCallbackFunction( 99fe6060f1SDimitry Andric BreakpointOptions &bp_options, const char *function_name, 100e8d8bef9SDimitry Andric StructuredData::ObjectSP extra_args_sp) override; 101e8d8bef9SDimitry Andric 102480093f4SDimitry Andric private: 103480093f4SDimitry Andric std::unique_ptr<Lua> m_lua; 104480093f4SDimitry Andric bool m_session_is_active = false; 105e8d8bef9SDimitry Andric 106fe6060f1SDimitry Andric Status RegisterBreakpointCallback(BreakpointOptions &bp_options, 107fe6060f1SDimitry Andric const char *command_body_text, 108fe6060f1SDimitry Andric StructuredData::ObjectSP extra_args_sp); 109fe6060f1SDimitry Andric 110fe6060f1SDimitry Andric Status RegisterWatchpointCallback(WatchpointOptions *wp_options, 111e8d8bef9SDimitry Andric const char *command_body_text, 112e8d8bef9SDimitry Andric StructuredData::ObjectSP extra_args_sp); 113480093f4SDimitry Andric }; 114480093f4SDimitry Andric 115480093f4SDimitry Andric } // namespace lldb_private 116480093f4SDimitry Andric 117480093f4SDimitry Andric #endif // liblldb_ScriptInterpreterLua_h_ 118