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
20namespace lldb_private {
21class Lua;
22class ScriptInterpreterLua : public ScriptInterpreter {
23public:
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 = {},
51 lldb::TargetSP loaded_into_target_sp = {}) override;
52
53 StructuredData::DictionarySP GetInterpreterInfo() override;
54
55 // Static Functions
56 static void Initialize();
57
58 static void Terminate();
59
60 static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger);
61
62 static llvm::StringRef GetPluginNameStatic() { return "script-lua"; }
63
64 static llvm::StringRef GetPluginDescriptionStatic();
65
66 static bool BreakpointCallbackFunction(void *baton,
67 StoppointCallbackContext *context,
68 lldb::user_id_t break_id,
69 lldb::user_id_t break_loc_id);
70
71 static bool WatchpointCallbackFunction(void *baton,
72 StoppointCallbackContext *context,
73 lldb::user_id_t watch_id);
74
75 // PluginInterface protocol
76 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
77
78 Lua &GetLua();
79
80 llvm::Error EnterSession(lldb::user_id_t debugger_id);
81 llvm::Error LeaveSession();
82
83 void CollectDataForBreakpointCommandCallback(
84 std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec,
85 CommandReturnObject &result) override;
86
87 void
88 CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options,
89 CommandReturnObject &result) override;
90
91 Status SetBreakpointCommandCallback(BreakpointOptions &bp_options,
92 const char *command_body_text,
93 bool is_callback) override;
94
95 void SetWatchpointCommandCallback(WatchpointOptions *wp_options,
96 const char *command_body_text,
97 bool is_callback) override;
98
99 Status SetBreakpointCommandCallbackFunction(
100 BreakpointOptions &bp_options, const char *function_name,
101 StructuredData::ObjectSP extra_args_sp) override;
102
103private:
104 std::unique_ptr<Lua> m_lua;
105 bool m_session_is_active = false;
106
107 Status RegisterBreakpointCallback(BreakpointOptions &bp_options,
108 const char *command_body_text,
109 StructuredData::ObjectSP extra_args_sp);
110
111 Status RegisterWatchpointCallback(WatchpointOptions *wp_options,
112 const char *command_body_text,
113 StructuredData::ObjectSP extra_args_sp);
114};
115
116} // namespace lldb_private
117
118#endif // liblldb_ScriptInterpreterLua_h_
119

source code of lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h