xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
1480093f4SDimitry Andric //===-- ScriptInterpreterLua.h ----------------------------------*- C++ -*-===//
2480093f4SDimitry Andric //
3480093f4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4480093f4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5480093f4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6480093f4SDimitry Andric //
7480093f4SDimitry Andric //===----------------------------------------------------------------------===//
8480093f4SDimitry Andric 
9480093f4SDimitry Andric #ifndef liblldb_ScriptInterpreterLua_h_
10480093f4SDimitry Andric #define liblldb_ScriptInterpreterLua_h_
11480093f4SDimitry Andric 
12*e8d8bef9SDimitry Andric #include "lldb/Core/StructuredDataImpl.h"
13480093f4SDimitry Andric #include "lldb/Interpreter/ScriptInterpreter.h"
14*e8d8bef9SDimitry Andric #include "lldb/Utility/Status.h"
15*e8d8bef9SDimitry Andric #include "lldb/lldb-enumerations.h"
16480093f4SDimitry Andric 
17480093f4SDimitry Andric namespace lldb_private {
18480093f4SDimitry Andric class Lua;
19480093f4SDimitry Andric class ScriptInterpreterLua : public ScriptInterpreter {
20480093f4SDimitry Andric public:
21*e8d8bef9SDimitry Andric   class CommandDataLua : public BreakpointOptions::CommandData {
22*e8d8bef9SDimitry Andric   public:
23*e8d8bef9SDimitry Andric     CommandDataLua() : BreakpointOptions::CommandData() {
24*e8d8bef9SDimitry Andric       interpreter = lldb::eScriptLanguageLua;
25*e8d8bef9SDimitry Andric     }
26*e8d8bef9SDimitry Andric     CommandDataLua(StructuredData::ObjectSP extra_args_sp)
27*e8d8bef9SDimitry Andric         : BreakpointOptions::CommandData(), m_extra_args_sp(extra_args_sp) {
28*e8d8bef9SDimitry Andric       interpreter = lldb::eScriptLanguageLua;
29*e8d8bef9SDimitry Andric     }
30*e8d8bef9SDimitry Andric     StructuredData::ObjectSP m_extra_args_sp;
31*e8d8bef9SDimitry Andric   };
32*e8d8bef9SDimitry Andric 
33480093f4SDimitry Andric   ScriptInterpreterLua(Debugger &debugger);
34480093f4SDimitry Andric 
35480093f4SDimitry Andric   ~ScriptInterpreterLua() override;
36480093f4SDimitry Andric 
37480093f4SDimitry Andric   bool ExecuteOneLine(
38480093f4SDimitry Andric       llvm::StringRef command, CommandReturnObject *result,
39480093f4SDimitry Andric       const ExecuteScriptOptions &options = ExecuteScriptOptions()) override;
40480093f4SDimitry Andric 
41480093f4SDimitry Andric   void ExecuteInterpreterLoop() override;
42480093f4SDimitry Andric 
43*e8d8bef9SDimitry Andric   bool LoadScriptingModule(const char *filename, bool init_session,
44480093f4SDimitry Andric                            lldb_private::Status &error,
45*e8d8bef9SDimitry Andric                            StructuredData::ObjectSP *module_sp = nullptr,
46*e8d8bef9SDimitry Andric                            FileSpec extra_search_dir = {}) override;
47480093f4SDimitry Andric 
48480093f4SDimitry Andric   // Static Functions
49480093f4SDimitry Andric   static void Initialize();
50480093f4SDimitry Andric 
51480093f4SDimitry Andric   static void Terminate();
52480093f4SDimitry Andric 
53480093f4SDimitry Andric   static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger);
54480093f4SDimitry Andric 
55480093f4SDimitry Andric   static lldb_private::ConstString GetPluginNameStatic();
56480093f4SDimitry Andric 
57480093f4SDimitry Andric   static const char *GetPluginDescriptionStatic();
58480093f4SDimitry Andric 
59*e8d8bef9SDimitry Andric   static bool BreakpointCallbackFunction(void *baton,
60*e8d8bef9SDimitry Andric                                          StoppointCallbackContext *context,
61*e8d8bef9SDimitry Andric                                          lldb::user_id_t break_id,
62*e8d8bef9SDimitry Andric                                          lldb::user_id_t break_loc_id);
63*e8d8bef9SDimitry Andric 
64480093f4SDimitry Andric   // PluginInterface protocol
65480093f4SDimitry Andric   lldb_private::ConstString GetPluginName() override;
66480093f4SDimitry Andric 
67480093f4SDimitry Andric   uint32_t GetPluginVersion() override;
68480093f4SDimitry Andric 
69480093f4SDimitry Andric   Lua &GetLua();
70480093f4SDimitry Andric 
71480093f4SDimitry Andric   llvm::Error EnterSession(lldb::user_id_t debugger_id);
72480093f4SDimitry Andric   llvm::Error LeaveSession();
73480093f4SDimitry Andric 
74*e8d8bef9SDimitry Andric   void CollectDataForBreakpointCommandCallback(
75*e8d8bef9SDimitry Andric       std::vector<BreakpointOptions *> &bp_options_vec,
76*e8d8bef9SDimitry Andric       CommandReturnObject &result) override;
77*e8d8bef9SDimitry Andric 
78*e8d8bef9SDimitry Andric   Status SetBreakpointCommandCallback(BreakpointOptions *bp_options,
79*e8d8bef9SDimitry Andric                                       const char *command_body_text) override;
80*e8d8bef9SDimitry Andric 
81*e8d8bef9SDimitry Andric   Status SetBreakpointCommandCallbackFunction(
82*e8d8bef9SDimitry Andric       BreakpointOptions *bp_options, const char *function_name,
83*e8d8bef9SDimitry Andric       StructuredData::ObjectSP extra_args_sp) override;
84*e8d8bef9SDimitry Andric 
85480093f4SDimitry Andric private:
86480093f4SDimitry Andric   std::unique_ptr<Lua> m_lua;
87480093f4SDimitry Andric   bool m_session_is_active = false;
88*e8d8bef9SDimitry Andric 
89*e8d8bef9SDimitry Andric   Status RegisterBreakpointCallback(BreakpointOptions *bp_options,
90*e8d8bef9SDimitry Andric                                     const char *command_body_text,
91*e8d8bef9SDimitry Andric                                     StructuredData::ObjectSP extra_args_sp);
92480093f4SDimitry Andric };
93480093f4SDimitry Andric 
94480093f4SDimitry Andric } // namespace lldb_private
95480093f4SDimitry Andric 
96480093f4SDimitry Andric #endif // liblldb_ScriptInterpreterLua_h_
97