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*5f7ddb14SDimitry Andric #include <vector>
13*5f7ddb14SDimitry Andric 
14*5f7ddb14SDimitry Andric #include "lldb/Breakpoint/WatchpointOptions.h"
15af732203SDimitry Andric #include "lldb/Core/StructuredDataImpl.h"
16480093f4SDimitry Andric #include "lldb/Interpreter/ScriptInterpreter.h"
17af732203SDimitry Andric #include "lldb/Utility/Status.h"
18af732203SDimitry 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:
24af732203SDimitry Andric   class CommandDataLua : public BreakpointOptions::CommandData {
25af732203SDimitry Andric   public:
CommandDataLua()26af732203SDimitry Andric     CommandDataLua() : BreakpointOptions::CommandData() {
27af732203SDimitry Andric       interpreter = lldb::eScriptLanguageLua;
28af732203SDimitry Andric     }
CommandDataLua(StructuredData::ObjectSP extra_args_sp)29af732203SDimitry Andric     CommandDataLua(StructuredData::ObjectSP extra_args_sp)
30af732203SDimitry Andric         : BreakpointOptions::CommandData(), m_extra_args_sp(extra_args_sp) {
31af732203SDimitry Andric       interpreter = lldb::eScriptLanguageLua;
32af732203SDimitry Andric     }
33af732203SDimitry Andric     StructuredData::ObjectSP m_extra_args_sp;
34af732203SDimitry Andric   };
35af732203SDimitry 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*5f7ddb14SDimitry Andric   bool LoadScriptingModule(const char *filename,
47*5f7ddb14SDimitry Andric                            const LoadScriptOptions &options,
48480093f4SDimitry Andric                            lldb_private::Status &error,
49af732203SDimitry Andric                            StructuredData::ObjectSP *module_sp = nullptr,
50af732203SDimitry 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 
63af732203SDimitry Andric   static bool BreakpointCallbackFunction(void *baton,
64af732203SDimitry Andric                                          StoppointCallbackContext *context,
65af732203SDimitry Andric                                          lldb::user_id_t break_id,
66af732203SDimitry Andric                                          lldb::user_id_t break_loc_id);
67af732203SDimitry Andric 
68*5f7ddb14SDimitry Andric   static bool WatchpointCallbackFunction(void *baton,
69*5f7ddb14SDimitry Andric                                          StoppointCallbackContext *context,
70*5f7ddb14SDimitry Andric                                          lldb::user_id_t watch_id);
71*5f7ddb14SDimitry 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 
82af732203SDimitry Andric   void CollectDataForBreakpointCommandCallback(
83*5f7ddb14SDimitry Andric       std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec,
84af732203SDimitry Andric       CommandReturnObject &result) override;
85af732203SDimitry Andric 
86*5f7ddb14SDimitry Andric   void
87*5f7ddb14SDimitry Andric   CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options,
88*5f7ddb14SDimitry Andric                                           CommandReturnObject &result) override;
89*5f7ddb14SDimitry Andric 
90*5f7ddb14SDimitry Andric   Status SetBreakpointCommandCallback(BreakpointOptions &bp_options,
91*5f7ddb14SDimitry Andric                                       const char *command_body_text) override;
92*5f7ddb14SDimitry Andric 
93*5f7ddb14SDimitry Andric   void SetWatchpointCommandCallback(WatchpointOptions *wp_options,
94af732203SDimitry Andric                                     const char *command_body_text) override;
95af732203SDimitry Andric 
96af732203SDimitry Andric   Status SetBreakpointCommandCallbackFunction(
97*5f7ddb14SDimitry Andric       BreakpointOptions &bp_options, const char *function_name,
98af732203SDimitry Andric       StructuredData::ObjectSP extra_args_sp) override;
99af732203SDimitry Andric 
100480093f4SDimitry Andric private:
101480093f4SDimitry Andric   std::unique_ptr<Lua> m_lua;
102480093f4SDimitry Andric   bool m_session_is_active = false;
103af732203SDimitry Andric 
104*5f7ddb14SDimitry Andric   Status RegisterBreakpointCallback(BreakpointOptions &bp_options,
105*5f7ddb14SDimitry Andric                                     const char *command_body_text,
106*5f7ddb14SDimitry Andric                                     StructuredData::ObjectSP extra_args_sp);
107*5f7ddb14SDimitry Andric 
108*5f7ddb14SDimitry Andric   Status RegisterWatchpointCallback(WatchpointOptions *wp_options,
109af732203SDimitry Andric                                     const char *command_body_text,
110af732203SDimitry Andric                                     StructuredData::ObjectSP extra_args_sp);
111480093f4SDimitry Andric };
112480093f4SDimitry Andric 
113480093f4SDimitry Andric } // namespace lldb_private
114480093f4SDimitry Andric 
115480093f4SDimitry Andric #endif // liblldb_ScriptInterpreterLua_h_
116