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 12*fe6060f1SDimitry Andric #include <vector> 13*fe6060f1SDimitry Andric 14*fe6060f1SDimitry 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: 26e8d8bef9SDimitry Andric CommandDataLua() : BreakpointOptions::CommandData() { 27e8d8bef9SDimitry Andric interpreter = lldb::eScriptLanguageLua; 28e8d8bef9SDimitry Andric } 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 46*fe6060f1SDimitry Andric bool LoadScriptingModule(const char *filename, 47*fe6060f1SDimitry 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 52480093f4SDimitry Andric // Static Functions 53480093f4SDimitry Andric static void Initialize(); 54480093f4SDimitry Andric 55480093f4SDimitry Andric static void Terminate(); 56480093f4SDimitry Andric 57480093f4SDimitry Andric static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger); 58480093f4SDimitry Andric 59480093f4SDimitry Andric static lldb_private::ConstString GetPluginNameStatic(); 60480093f4SDimitry Andric 61480093f4SDimitry Andric static const char *GetPluginDescriptionStatic(); 62480093f4SDimitry Andric 63e8d8bef9SDimitry Andric static bool BreakpointCallbackFunction(void *baton, 64e8d8bef9SDimitry Andric StoppointCallbackContext *context, 65e8d8bef9SDimitry Andric lldb::user_id_t break_id, 66e8d8bef9SDimitry Andric lldb::user_id_t break_loc_id); 67e8d8bef9SDimitry Andric 68*fe6060f1SDimitry Andric static bool WatchpointCallbackFunction(void *baton, 69*fe6060f1SDimitry Andric StoppointCallbackContext *context, 70*fe6060f1SDimitry Andric lldb::user_id_t watch_id); 71*fe6060f1SDimitry Andric 72480093f4SDimitry Andric // PluginInterface protocol 73480093f4SDimitry Andric lldb_private::ConstString GetPluginName() override; 74480093f4SDimitry Andric 75480093f4SDimitry Andric uint32_t GetPluginVersion() override; 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( 83*fe6060f1SDimitry Andric std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec, 84e8d8bef9SDimitry Andric CommandReturnObject &result) override; 85e8d8bef9SDimitry Andric 86*fe6060f1SDimitry Andric void 87*fe6060f1SDimitry Andric CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options, 88*fe6060f1SDimitry Andric CommandReturnObject &result) override; 89*fe6060f1SDimitry Andric 90*fe6060f1SDimitry Andric Status SetBreakpointCommandCallback(BreakpointOptions &bp_options, 91*fe6060f1SDimitry Andric const char *command_body_text) override; 92*fe6060f1SDimitry Andric 93*fe6060f1SDimitry Andric void SetWatchpointCommandCallback(WatchpointOptions *wp_options, 94e8d8bef9SDimitry Andric const char *command_body_text) override; 95e8d8bef9SDimitry Andric 96e8d8bef9SDimitry Andric Status SetBreakpointCommandCallbackFunction( 97*fe6060f1SDimitry Andric BreakpointOptions &bp_options, const char *function_name, 98e8d8bef9SDimitry Andric StructuredData::ObjectSP extra_args_sp) override; 99e8d8bef9SDimitry Andric 100480093f4SDimitry Andric private: 101480093f4SDimitry Andric std::unique_ptr<Lua> m_lua; 102480093f4SDimitry Andric bool m_session_is_active = false; 103e8d8bef9SDimitry Andric 104*fe6060f1SDimitry Andric Status RegisterBreakpointCallback(BreakpointOptions &bp_options, 105*fe6060f1SDimitry Andric const char *command_body_text, 106*fe6060f1SDimitry Andric StructuredData::ObjectSP extra_args_sp); 107*fe6060f1SDimitry Andric 108*fe6060f1SDimitry Andric Status RegisterWatchpointCallback(WatchpointOptions *wp_options, 109e8d8bef9SDimitry Andric const char *command_body_text, 110e8d8bef9SDimitry Andric StructuredData::ObjectSP extra_args_sp); 111480093f4SDimitry Andric }; 112480093f4SDimitry Andric 113480093f4SDimitry Andric } // namespace lldb_private 114480093f4SDimitry Andric 115480093f4SDimitry Andric #endif // liblldb_ScriptInterpreterLua_h_ 116