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