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