13#include "llvm/Support/Error.h"
14#include "llvm/Support/FormatVariadic.h"
20 int n = lua_gettop(L);
21 lua_getglobal(L,
"io");
22 lua_getfield(L, -1,
"stdout");
23 lua_getfield(L, -1,
"write");
24 for (
int i = 1; i <= n; i++) {
27 luaL_tolstring(L, i,
nullptr);
28 lua_pushstring(L, i != n ?
"\t" :
"\n");
49 luaL_loadbuffer(
m_lua_state, buffer.data(), buffer.size(),
"buffer") ||
52 return llvm::Error::success();
54 llvm::Error e = llvm::make_error<llvm::StringError>(
55 llvm::formatv(
"{0}\n", lua_tostring(
m_lua_state, -1)),
56 llvm::inconvertibleErrorCode());
65 const char *fmt_str =
"return function(frame, bp_loc, ...) {0} end";
66 std::string func_str = llvm::formatv(fmt_str, body).str();
67 if (luaL_dostring(
m_lua_state, func_str.c_str()) != LUA_OK) {
68 llvm::Error e = llvm::make_error<llvm::StringError>(
69 llvm::formatv(
"{0}", lua_tostring(
m_lua_state, -1)),
70 llvm::inconvertibleErrorCode());
76 return llvm::Error::success();
88 m_lua_state, stop_frame_sp, bp_loc_sp, extra_args_impl);
94 const char *fmt_str =
"return function(frame, wp, ...) {0} end";
95 std::string func_str = llvm::formatv(fmt_str, body).str();
96 if (luaL_dostring(
m_lua_state, func_str.c_str()) != LUA_OK) {
97 llvm::Error e = llvm::make_error<llvm::StringError>(
98 llvm::formatv(
"{0}", lua_tostring(
m_lua_state, -1)),
99 llvm::inconvertibleErrorCode());
105 return llvm::Error::success();
120 luaL_loadbuffer(
m_lua_state, buffer.data(), buffer.size(),
"buffer");
121 if (
error == LUA_OK) {
124 return llvm::Error::success();
127 llvm::Error e = llvm::make_error<llvm::StringError>(
128 llvm::formatv(
"{0}\n", lua_tostring(
m_lua_state, -1)),
129 llvm::inconvertibleErrorCode());
138 return llvm::make_error<llvm::StringError>(
"invalid path",
139 llvm::inconvertibleErrorCode());
143 return llvm::make_error<llvm::StringError>(
"invalid extension",
144 llvm::inconvertibleErrorCode());
149 if (
error != LUA_OK) {
150 llvm::Error e = llvm::make_error<llvm::StringError>(
151 llvm::formatv(
"{0}\n", lua_tostring(
m_lua_state, -1)),
152 llvm::inconvertibleErrorCode());
160 return llvm::Error::success();
164 assert(out !=
nullptr);
165 assert(err !=
nullptr);
170 if (luaL_Stream *s =
static_cast<luaL_Stream *
>(
171 luaL_testudata(
m_lua_state, -1, LUA_FILEHANDLE))) {
176 return llvm::make_error<llvm::StringError>(
"could not get stdout",
177 llvm::inconvertibleErrorCode());
181 if (luaL_Stream *s =
static_cast<luaL_Stream *
>(
182 luaL_testudata(
m_lua_state, -1, LUA_FILEHANDLE))) {
187 return llvm::make_error<llvm::StringError>(
"could not get stderr",
188 llvm::inconvertibleErrorCode());
192 return llvm::Error::success();
static llvm::raw_ostream & error(Stream &strm)
static int lldb_print(lua_State *L)
A uniqued constant string class.
const char * GetCString() const
Get the string value as a C string.
ConstString GetFileNameStrippingExtension() const
Return the filename without the extension part.
llvm::StringRef GetFileNameExtension() const
Extract the extension of the file.
static FileSystem & Instance()
llvm::Error LoadModule(llvm::StringRef filename)
llvm::Expected< bool > CallBreakpointCallback(void *baton, lldb::StackFrameSP stop_frame_sp, lldb::BreakpointLocationSP bp_loc_sp, StructuredData::ObjectSP extra_args_sp)
llvm::Expected< bool > CallWatchpointCallback(void *baton, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp)
llvm::Error RegisterWatchpointCallback(void *baton, const char *body)
llvm::Error CheckSyntax(llvm::StringRef buffer)
llvm::Error Run(llvm::StringRef buffer)
llvm::Error ChangeIO(FILE *out, FILE *err)
llvm::Error RegisterBreakpointCallback(void *baton, const char *body)
std::shared_ptr< Object > ObjectSP
static llvm::Expected< bool > LLDBSwigLuaWatchpointCallbackFunction(lua_State *L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp)
static llvm::Expected< bool > LLDBSwigLuaBreakpointCallbackFunction(lua_State *L, lldb::StackFrameSP stop_frame_sp, lldb::BreakpointLocationSP bp_loc_sp, const StructuredDataImpl &extra_args_impl)
A class that represents a running process on the host machine.
int luaopen_lldb(lua_State *L)
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
std::shared_ptr< lldb_private::Watchpoint > WatchpointSP