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());
64 const char *fmt_str =
"return function(frame, bp_loc, ...) {0} end";
65 std::string func_str = llvm::formatv(fmt_str, body).str();
66 if (luaL_dostring(
m_lua_state, func_str.c_str()) != LUA_OK) {
67 llvm::Error e = llvm::make_error<llvm::StringError>(
68 llvm::formatv(
"{0}", lua_tostring(
m_lua_state, -1)),
69 llvm::inconvertibleErrorCode());
75 return llvm::Error::success();
87 m_lua_state, stop_frame_sp, bp_loc_sp, extra_args_impl);
92 const char *fmt_str =
"return function(frame, wp, ...) {0} end";
93 std::string func_str = llvm::formatv(fmt_str, body).str();
94 if (luaL_dostring(
m_lua_state, func_str.c_str()) != LUA_OK) {
95 llvm::Error e = llvm::make_error<llvm::StringError>(
96 llvm::formatv(
"{0}", lua_tostring(
m_lua_state, -1)),
97 llvm::inconvertibleErrorCode());
103 return llvm::Error::success();
118 luaL_loadbuffer(
m_lua_state, buffer.data(), buffer.size(),
"buffer");
119 if (
error == LUA_OK) {
122 return llvm::Error::success();
125 llvm::Error e = llvm::make_error<llvm::StringError>(
126 llvm::formatv(
"{0}\n", lua_tostring(
m_lua_state, -1)),
127 llvm::inconvertibleErrorCode());
136 return llvm::make_error<llvm::StringError>(
"invalid path",
137 llvm::inconvertibleErrorCode());
141 return llvm::make_error<llvm::StringError>(
"invalid extension",
142 llvm::inconvertibleErrorCode());
147 if (
error != LUA_OK) {
148 llvm::Error e = llvm::make_error<llvm::StringError>(
149 llvm::formatv(
"{0}\n", lua_tostring(
m_lua_state, -1)),
150 llvm::inconvertibleErrorCode());
158 return llvm::Error::success();
162 assert(out !=
nullptr);
163 assert(err !=
nullptr);
168 if (luaL_Stream *s =
static_cast<luaL_Stream *
>(
169 luaL_testudata(
m_lua_state, -1, LUA_FILEHANDLE))) {
174 return llvm::make_error<llvm::StringError>(
"could not get stdout",
175 llvm::inconvertibleErrorCode());
179 if (luaL_Stream *s =
static_cast<luaL_Stream *
>(
180 luaL_testudata(
m_lua_state, -1, LUA_FILEHANDLE))) {
185 return llvm::make_error<llvm::StringError>(
"could not get stderr",
186 llvm::inconvertibleErrorCode());
190 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::Expected< bool > CallWatchpointCallback(void *baton, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp)
llvm::Error RegisterBreakpointCallback(void *baton, const char *body)
llvm::Error CheckSyntax(llvm::StringRef buffer)
llvm::Error ChangeIO(FILE *out, FILE *err)
llvm::Error LoadModule(llvm::StringRef filename)
llvm::Error Run(llvm::StringRef buffer)
llvm::Expected< bool > CallBreakpointCallback(void *baton, lldb::StackFrameSP stop_frame_sp, lldb::BreakpointLocationSP bp_loc_sp, StructuredData::ObjectSP extra_args_sp)
llvm::Error RegisterWatchpointCallback(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