xref: /openbsd-src/gnu/llvm/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1061da546Spatrick //===-- ScriptInterpreterLua.h ----------------------------------*- C++ -*-===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick 
9061da546Spatrick #ifndef liblldb_ScriptInterpreterLua_h_
10061da546Spatrick #define liblldb_ScriptInterpreterLua_h_
11061da546Spatrick 
12be691f3bSpatrick #include <vector>
13be691f3bSpatrick 
14be691f3bSpatrick #include "lldb/Breakpoint/WatchpointOptions.h"
15be691f3bSpatrick #include "lldb/Core/StructuredDataImpl.h"
16061da546Spatrick #include "lldb/Interpreter/ScriptInterpreter.h"
17be691f3bSpatrick #include "lldb/Utility/Status.h"
18be691f3bSpatrick #include "lldb/lldb-enumerations.h"
19061da546Spatrick 
20061da546Spatrick namespace lldb_private {
21061da546Spatrick class Lua;
22061da546Spatrick class ScriptInterpreterLua : public ScriptInterpreter {
23061da546Spatrick public:
24be691f3bSpatrick   class CommandDataLua : public BreakpointOptions::CommandData {
25be691f3bSpatrick   public:
CommandDataLua()26be691f3bSpatrick     CommandDataLua() : BreakpointOptions::CommandData() {
27be691f3bSpatrick       interpreter = lldb::eScriptLanguageLua;
28be691f3bSpatrick     }
CommandDataLua(StructuredData::ObjectSP extra_args_sp)29be691f3bSpatrick     CommandDataLua(StructuredData::ObjectSP extra_args_sp)
30be691f3bSpatrick         : BreakpointOptions::CommandData(), m_extra_args_sp(extra_args_sp) {
31be691f3bSpatrick       interpreter = lldb::eScriptLanguageLua;
32be691f3bSpatrick     }
33be691f3bSpatrick     StructuredData::ObjectSP m_extra_args_sp;
34be691f3bSpatrick   };
35be691f3bSpatrick 
36061da546Spatrick   ScriptInterpreterLua(Debugger &debugger);
37061da546Spatrick 
38061da546Spatrick   ~ScriptInterpreterLua() override;
39061da546Spatrick 
40061da546Spatrick   bool ExecuteOneLine(
41061da546Spatrick       llvm::StringRef command, CommandReturnObject *result,
42061da546Spatrick       const ExecuteScriptOptions &options = ExecuteScriptOptions()) override;
43061da546Spatrick 
44061da546Spatrick   void ExecuteInterpreterLoop() override;
45061da546Spatrick 
46be691f3bSpatrick   bool LoadScriptingModule(const char *filename,
47be691f3bSpatrick                            const LoadScriptOptions &options,
48061da546Spatrick                            lldb_private::Status &error,
49be691f3bSpatrick                            StructuredData::ObjectSP *module_sp = nullptr,
50be691f3bSpatrick                            FileSpec extra_search_dir = {}) override;
51061da546Spatrick 
52*f6aab3d8Srobert   StructuredData::DictionarySP GetInterpreterInfo() override;
53*f6aab3d8Srobert 
54061da546Spatrick   // Static Functions
55061da546Spatrick   static void Initialize();
56061da546Spatrick 
57061da546Spatrick   static void Terminate();
58061da546Spatrick 
59061da546Spatrick   static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger);
60061da546Spatrick 
GetPluginNameStatic()61*f6aab3d8Srobert   static llvm::StringRef GetPluginNameStatic() { return "script-lua"; }
62061da546Spatrick 
63*f6aab3d8Srobert   static llvm::StringRef GetPluginDescriptionStatic();
64061da546Spatrick 
65be691f3bSpatrick   static bool BreakpointCallbackFunction(void *baton,
66be691f3bSpatrick                                          StoppointCallbackContext *context,
67be691f3bSpatrick                                          lldb::user_id_t break_id,
68be691f3bSpatrick                                          lldb::user_id_t break_loc_id);
69be691f3bSpatrick 
70be691f3bSpatrick   static bool WatchpointCallbackFunction(void *baton,
71be691f3bSpatrick                                          StoppointCallbackContext *context,
72be691f3bSpatrick                                          lldb::user_id_t watch_id);
73be691f3bSpatrick 
74061da546Spatrick   // PluginInterface protocol
GetPluginName()75*f6aab3d8Srobert   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
76061da546Spatrick 
77061da546Spatrick   Lua &GetLua();
78061da546Spatrick 
79061da546Spatrick   llvm::Error EnterSession(lldb::user_id_t debugger_id);
80061da546Spatrick   llvm::Error LeaveSession();
81061da546Spatrick 
82be691f3bSpatrick   void CollectDataForBreakpointCommandCallback(
83be691f3bSpatrick       std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec,
84be691f3bSpatrick       CommandReturnObject &result) override;
85be691f3bSpatrick 
86be691f3bSpatrick   void
87be691f3bSpatrick   CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options,
88be691f3bSpatrick                                           CommandReturnObject &result) override;
89be691f3bSpatrick 
90be691f3bSpatrick   Status SetBreakpointCommandCallback(BreakpointOptions &bp_options,
91be691f3bSpatrick                                       const char *command_body_text) override;
92be691f3bSpatrick 
93be691f3bSpatrick   void SetWatchpointCommandCallback(WatchpointOptions *wp_options,
94be691f3bSpatrick                                     const char *command_body_text) override;
95be691f3bSpatrick 
96be691f3bSpatrick   Status SetBreakpointCommandCallbackFunction(
97be691f3bSpatrick       BreakpointOptions &bp_options, const char *function_name,
98be691f3bSpatrick       StructuredData::ObjectSP extra_args_sp) override;
99be691f3bSpatrick 
100061da546Spatrick private:
101061da546Spatrick   std::unique_ptr<Lua> m_lua;
102061da546Spatrick   bool m_session_is_active = false;
103be691f3bSpatrick 
104be691f3bSpatrick   Status RegisterBreakpointCallback(BreakpointOptions &bp_options,
105be691f3bSpatrick                                     const char *command_body_text,
106be691f3bSpatrick                                     StructuredData::ObjectSP extra_args_sp);
107be691f3bSpatrick 
108be691f3bSpatrick   Status RegisterWatchpointCallback(WatchpointOptions *wp_options,
109be691f3bSpatrick                                     const char *command_body_text,
110be691f3bSpatrick                                     StructuredData::ObjectSP extra_args_sp);
111061da546Spatrick };
112061da546Spatrick 
113061da546Spatrick } // namespace lldb_private
114061da546Spatrick 
115061da546Spatrick #endif // liblldb_ScriptInterpreterLua_h_
116