xref: /llvm-project/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h (revision e81ba283131cf76ae62fa9b601a24d080578efaa)
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, bool init_session,
47                            lldb_private::Status &error,
48                            StructuredData::ObjectSP *module_sp = nullptr,
49                            FileSpec extra_search_dir = {}) override;
50 
51   // Static Functions
52   static void Initialize();
53 
54   static void Terminate();
55 
56   static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger);
57 
58   static lldb_private::ConstString GetPluginNameStatic();
59 
60   static const char *GetPluginDescriptionStatic();
61 
62   static bool BreakpointCallbackFunction(void *baton,
63                                          StoppointCallbackContext *context,
64                                          lldb::user_id_t break_id,
65                                          lldb::user_id_t break_loc_id);
66 
67   static bool WatchpointCallbackFunction(void *baton,
68                                          StoppointCallbackContext *context,
69                                          lldb::user_id_t watch_id);
70 
71   // PluginInterface protocol
72   lldb_private::ConstString GetPluginName() override;
73 
74   uint32_t GetPluginVersion() override;
75 
76   Lua &GetLua();
77 
78   llvm::Error EnterSession(lldb::user_id_t debugger_id);
79   llvm::Error LeaveSession();
80 
81   void CollectDataForBreakpointCommandCallback(
82       std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec,
83       CommandReturnObject &result) override;
84 
85   void
86   CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options,
87                                           CommandReturnObject &result) override;
88 
89   Status SetBreakpointCommandCallback(BreakpointOptions &bp_options,
90                                       const char *command_body_text) override;
91 
92   void SetWatchpointCommandCallback(WatchpointOptions *wp_options,
93                                     const char *command_body_text) override;
94 
95   Status SetBreakpointCommandCallbackFunction(
96       BreakpointOptions &bp_options, const char *function_name,
97       StructuredData::ObjectSP extra_args_sp) override;
98 
99 private:
100   std::unique_ptr<Lua> m_lua;
101   bool m_session_is_active = false;
102 
103   Status RegisterBreakpointCallback(BreakpointOptions &bp_options,
104                                     const char *command_body_text,
105                                     StructuredData::ObjectSP extra_args_sp);
106 
107   Status RegisterWatchpointCallback(WatchpointOptions *wp_options,
108                                     const char *command_body_text,
109                                     StructuredData::ObjectSP extra_args_sp);
110 };
111 
112 } // namespace lldb_private
113 
114 #endif // liblldb_ScriptInterpreterLua_h_
115