13#include "llvm/Support/Error.h"
14#include "llvm/Support/ErrorExtras.h"
15#include "llvm/Support/FormatVariadic.h"
21 int n = lua_gettop(L);
22 lua_getglobal(L,
"io");
23 lua_getfield(L, -1,
"stdout");
24 lua_getfield(L, -1,
"write");
25 for (
int i = 1; i <= n; i++) {
28 luaL_tolstring(L, i,
nullptr);
29 lua_pushstring(L, i != n ?
"\t" :
"\n");
50 luaL_loadbuffer(
m_lua_state, buffer.data(), buffer.size(),
"buffer") ||
53 return llvm::Error::success();
56 llvm::createStringErrorV(
"{0}\n", lua_tostring(
m_lua_state, -1));
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) {
69 llvm::createStringErrorV(
"{0}", lua_tostring(
m_lua_state, -1));
75 return llvm::Error::success();
87 m_lua_state, stop_frame_sp, bp_loc_sp, extra_args_impl);
93 const char *fmt_str =
"return function(frame, wp, ...) {0} end";
94 std::string func_str = llvm::formatv(fmt_str, body).str();
95 if (luaL_dostring(
m_lua_state, func_str.c_str()) != LUA_OK) {
97 llvm::createStringErrorV(
"{0}", lua_tostring(
m_lua_state, -1));
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();
126 llvm::createStringErrorV(
"{0}\n", lua_tostring(
m_lua_state, -1));
135 return llvm::createStringError(
"invalid path");
139 return llvm::createStringError(
"invalid extension");
144 if (
error != LUA_OK) {
146 llvm::createStringErrorV(
"{0}\n", lua_tostring(
m_lua_state, -1));
154 return llvm::Error::success();
158 assert(out !=
nullptr);
159 assert(err !=
nullptr);
164 if (luaL_Stream *s =
static_cast<luaL_Stream *
>(
165 luaL_testudata(
m_lua_state, -1, LUA_FILEHANDLE))) {
170 return llvm::createStringError(
"could not get stdout");
174 if (luaL_Stream *s =
static_cast<luaL_Stream *
>(
175 luaL_testudata(
m_lua_state, -1, LUA_FILEHANDLE))) {
180 return llvm::createStringError(
"could not get stderr");
184 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