xref: /llvm-project/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h (revision cfb96d845a684a5c567823dbe2aa4392937ee979)
1 //===-- ScriptInterpreterLua.h ----------------------------------*- C++ -*-===//
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 #ifndef liblldb_ScriptInterpreterLua_h_
10 #define liblldb_ScriptInterpreterLua_h_
11 
12 #include <vector>
13 
14 #include "lldb/Core/StructuredDataImpl.h"
15 #include "lldb/Interpreter/ScriptInterpreter.h"
16 #include "lldb/Utility/Status.h"
17 #include "lldb/lldb-enumerations.h"
18 
19 namespace lldb_private {
20 class Lua;
21 class ScriptInterpreterLua : public ScriptInterpreter {
22 public:
23   class CommandDataLua : public BreakpointOptions::CommandData {
24   public:
25     CommandDataLua() : BreakpointOptions::CommandData() {
26       interpreter = lldb::eScriptLanguageLua;
27     }
28     CommandDataLua(StructuredData::ObjectSP extra_args_sp)
29         : BreakpointOptions::CommandData(), m_extra_args_sp(extra_args_sp) {
30       interpreter = lldb::eScriptLanguageLua;
31     }
32     StructuredData::ObjectSP m_extra_args_sp;
33   };
34 
35   ScriptInterpreterLua(Debugger &debugger);
36 
37   ~ScriptInterpreterLua() override;
38 
39   bool ExecuteOneLine(
40       llvm::StringRef command, CommandReturnObject *result,
41       const ExecuteScriptOptions &options = ExecuteScriptOptions()) override;
42 
43   void ExecuteInterpreterLoop() override;
44 
45   bool LoadScriptingModule(const char *filename, bool init_session,
46                            lldb_private::Status &error,
47                            StructuredData::ObjectSP *module_sp = nullptr,
48                            FileSpec extra_search_dir = {}) override;
49 
50   // Static Functions
51   static void Initialize();
52 
53   static void Terminate();
54 
55   static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger);
56 
57   static lldb_private::ConstString GetPluginNameStatic();
58 
59   static const char *GetPluginDescriptionStatic();
60 
61   static bool BreakpointCallbackFunction(void *baton,
62                                          StoppointCallbackContext *context,
63                                          lldb::user_id_t break_id,
64                                          lldb::user_id_t break_loc_id);
65 
66   // PluginInterface protocol
67   lldb_private::ConstString GetPluginName() override;
68 
69   uint32_t GetPluginVersion() override;
70 
71   Lua &GetLua();
72 
73   llvm::Error EnterSession(lldb::user_id_t debugger_id);
74   llvm::Error LeaveSession();
75 
76   void CollectDataForBreakpointCommandCallback(
77       std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec,
78       CommandReturnObject &result) override;
79 
80   Status SetBreakpointCommandCallback(BreakpointOptions &bp_options,
81                                       const char *command_body_text) override;
82 
83   Status SetBreakpointCommandCallbackFunction(
84       BreakpointOptions &bp_options, const char *function_name,
85       StructuredData::ObjectSP extra_args_sp) override;
86 
87 private:
88   std::unique_ptr<Lua> m_lua;
89   bool m_session_is_active = false;
90 
91   Status RegisterBreakpointCallback(BreakpointOptions &bp_options,
92                                     const char *command_body_text,
93                                     StructuredData::ObjectSP extra_args_sp);
94 };
95 
96 } // namespace lldb_private
97 
98 #endif // liblldb_ScriptInterpreterLua_h_
99