From 0040ae031e35739725ec5419349c63b456d0ecb8 Mon Sep 17 00:00:00 2001 From: SD Asif Hossein Date: Wed, 19 Jun 2024 19:13:34 +0600 Subject: [PATCH 1/3] Migrate to heap-allocated stack, added a debug script and other improvements --- src/bin/pallene-debug | 50 ++++++++++ src/pallene/coder.lua | 33 ++++--- src/pallene/pallenelib.lua | 188 ++++++++++++++++++++++++------------- 3 files changed, 196 insertions(+), 75 deletions(-) create mode 100755 src/bin/pallene-debug diff --git a/src/bin/pallene-debug b/src/bin/pallene-debug new file mode 100755 index 00000000..f9c3074c --- /dev/null +++ b/src/bin/pallene-debug @@ -0,0 +1,50 @@ +#!/usr/bin/env lua + +if #arg == 0 then + io.stderr:write("pallene-debug: need a file to debug. Abort!\n") + os.exit(1) +end + +-- File to run. +local filename = arg[1] +-- Remove the filename from the argument so that +-- it is identical to the arguments list if we had run +-- the file explicitly. +table.remove(arg, 1) + +-- Try opening the file. +local file, err = io.open(filename, "r") +if not file then + io.stderr:write("pallene-debug: could not open file: "..err.."\n") + os.exit(1) +end + +-- Try reading from the file. +local content = file:read("*all") +if not content then + io.stderr:write("pallene-debug: could not read file '"..filename.."'. Abort!\n") + os.exit(1) +end +-- We no longer need the file. +file:close() + +-- Silently run the code, loading the Pallene/Pallene Tracer compatible +-- modules so that we can figure out whether we have Pallene Tracer or not. +local _, _ = pcall(load(content)) + +-- Check whether we have Pallene Tracer enabled. +if not pallene_tracer_debug_traceback then + io.stderr:write("pallene-debug: could not find debug traceback fn: Make sure you include Pallene modules and compile them with `--use-traceback` flag.\n") + os.exit(1) +end + +-- Inject the wrapper code. +content = [[ +function __pallene_debug_wrapper() +]]..content..[[ +end + +xpcall(__pallene_debug_wrapper, pallene_tracer_debug_traceback) +]] + +load(content, filename)() diff --git a/src/pallene/coder.lua b/src/pallene/coder.lua index 62666727..40ffbba2 100644 --- a/src/pallene/coder.lua +++ b/src/pallene/coder.lua @@ -462,8 +462,7 @@ function Coder:pallene_entry_point_definition(f_id) if self.flags.use_traceback then table.insert(prologue, util.render([[ /**/ - pt_cont_t *cont = pvalue(&K->uv[0].uv); - PALLENE_C_FRAMEENTER(cont, "$name"); + PALLENE_C_FRAMEENTER(L, "$name"); /**/ ]], { name = func.name @@ -472,7 +471,7 @@ function Coder:pallene_entry_point_definition(f_id) setline = string.format("PALLENE_SETLINE(%d);", func.loc and func.loc.line or 0) if #func.typ.ret_types == 0 then - void_frameexit = "PALLENE_FRAMEEXIT(cont);" + void_frameexit = "PALLENE_FRAMEEXIT();" end end @@ -597,25 +596,31 @@ function Coder:lua_entry_point_definition(f_id) local frameenter = "" local frameexit = "" + local nargs = #arg_types + local cargs = nargs if self.flags.use_traceback then frameenter = util.render([[ /**/ - pt_cont_t *cont = pvalue(&K->uv[0].uv); - PALLENE_LUA_FRAMEENTER(cont, $fun_name); + PALLENE_LUA_FRAMEENTER(L, $fun_name); /**/ ]], { fun_name = self:lua_entry_point_name(f_id), }) - frameexit = "PALLENE_FRAMEEXIT(cont);" + -- It's as simple as popping the finalizer. + frameexit = "lua_pop(L, 1);" + + -- We will be having our finalizer on top of our stack. + cargs = cargs + 1 end local arity_check = util.render([[ int nargs = lua_gettop(L); - if (l_unlikely(nargs != $nargs)) { + if (l_unlikely(nargs != $cargs)) { pallene_runtime_arity_error(L, $fname, $nargs, nargs); } ]], { - nargs = C.integer(#arg_types), + cargs = C.integer(cargs), + nargs = C.integer(nargs), fname = C.string(fname), }) @@ -670,8 +675,8 @@ function Coder:lua_entry_point_definition(f_id) /**/ ${ret_decls} ${call_pallene} - ${push_results} ${lua_fexit} + ${push_results} return $nresults; } ]], { @@ -698,7 +703,8 @@ end define_union("Constant", { Metatable = {"typ"}, String = {"str"}, - DebugUserdata = {} + DebugUserdata = {}, + DebugMetatable = {}, }) function Coder:init_upvalues() @@ -706,6 +712,7 @@ function Coder:init_upvalues() -- If we are using tracebacks if self.flags.use_traceback then table.insert(self.constants, coder.Constant.DebugUserdata()) + table.insert(self.constants, coder.Constant.DebugMetatable()) end -- Metatables @@ -1656,7 +1663,7 @@ end gen_cmd["Return"] = function(self, cmd) local frameexit = "" if self.flags.use_traceback then - frameexit = "PALLENE_FRAMEEXIT(cont);" + frameexit = "PALLENE_FRAMEEXIT();" end if #cmd.srcs == 0 then @@ -1879,6 +1886,10 @@ function Coder:generate_luaopen_function() /* Initialize Pallene Tracer. */ lua_pushlightuserdata(L, (void *) pallene_tracer_init(L)); ]]); + elseif tag == "coder.Constant.DebugMetatable" then + table.insert(init_constants, [[ + /* `pallene_tracer_init` fn pushes the finalizer metatable into the stack. */ + ]]) else tagged_union.error(tag) end diff --git a/src/pallene/pallenelib.lua b/src/pallene/pallenelib.lua index 6a0b82d1..edd71747 100644 --- a/src/pallene/pallenelib.lua +++ b/src/pallene/pallenelib.lua @@ -44,11 +44,19 @@ return [==[ #include #include #include +#include #define PALLENE_UNREACHABLE __builtin_unreachable() -/* Part of Pallene Tracer. */ -#define PALLENE_C_FRAMEENTER(cont, name) \ +/* PALLENE TRACER MACROS */ + +/* Prepares finalizer function for Lua interface calls. */ +#define PALLENE_PREPARE_FINALIZER() \ + setobj(L, s2v(L->top.p++), &K->uv[1].uv); \ + lua_toclose(L, -1) + +#define PALLENE_C_FRAMEENTER(L, name) \ + pt_cont_t *cont = pvalue(&K->uv[0].uv); \ static pt_fn_details_t _details = { \ .fn_name = name, \ .mod_name = PALLENE_SOURCE_FILE \ @@ -59,22 +67,30 @@ return [==[ .details = &_details \ } \ }; \ - pallene_tracer_frameenter(cont, &_frame) + pallene_tracer_frameenter(L, cont, &_frame) -#define PALLENE_LUA_FRAMEENTER(cont, sig) \ +#define PALLENE_LUA_FRAMEENTER(L, sig) \ + pt_cont_t *cont = pvalue(&K->uv[0].uv); \ pt_frame_t _frame = { \ .type = PALLENE_TRACER_FRAME_TYPE_LUA, \ .shared = { \ .frame_sig = sig \ } \ }; \ - pallene_tracer_frameenter(cont, &_frame) + pallene_tracer_frameenter(L, cont, &_frame); \ + PALLENE_PREPARE_FINALIZER() -#define PALLENE_SETLINE(line) pallene_tracer_setline(&_frame, line) -#define PALLENE_FRAMEEXIT(cont) pallene_tracer_frameexit(cont) +#define PALLENE_SETLINE(line) pallene_tracer_setline(cont, line) +#define PALLENE_FRAMEEXIT() pallene_tracer_frameexit(cont) /* Pallene stack reference entry for the registry. */ -#define PALLENE_TRACER_STACK_ENTRY "__PALLENE_TRACER_STACK" +#define PALLENE_TRACER_CONTAINER_ENTRY "__PALLENE_TRACER_CONTAINER" + +/* Finalizer metatable key. */ +#define PALLENE_TRACER_METATABLE_ENTRY "__PALLENE_TRACER_METATABLE" + +/* The size of the Pallene call stack. */ +#define PALLENE_MAX_CALLSTACK 2000000 /* Traceback elipsis threshold. */ #define PALLENE_TRACEBACK_TOP_THRESHOLD 10 @@ -104,11 +120,9 @@ typedef struct pt_frame { int line; union { - const pt_fn_details_t *details; - const lua_CFunction frame_sig; + pt_fn_details_t *details; + lua_CFunction frame_sig; } shared; - - struct pt_frame *prev; } pt_frame_t; /* For Full Userdata allocation. That userdata is the module singular @@ -116,14 +130,16 @@ typedef struct pt_frame { /* 'cont' stands for 'container'. */ typedef struct pt_cont { pt_frame_t *stack; + int count; } pt_cont_t; /* Pallene Tracer. */ -static void pallene_tracer_frameenter(pt_cont_t *cont, pt_frame_t *restrict frame); -static void pallene_tracer_setline(pt_frame_t *restrict frame, int line); +static void pallene_tracer_frameenter(lua_State *L, pt_cont_t *cont, pt_frame_t *restrict frame); +static void pallene_tracer_setline(pt_cont_t *cont, int line); static void pallene_tracer_frameexit(pt_cont_t *cont); static int pallene_tracer_debug_traceback(lua_State *L); static pt_cont_t *pallene_tracer_init(lua_State *L); +static int pallene_tracer_finalizer(lua_State *L); /* Type tags */ static const char *pallene_type_name(lua_State *L, const TValue *v); @@ -144,6 +160,7 @@ static l_noret pallene_runtime_mod_by_zero_error(lua_State *L, const char* file, static l_noret pallene_runtime_number_to_integer_error(lua_State *L, const char* file, int line); static l_noret pallene_runtime_array_metatable_error(lua_State *L, const char* file, int line); static l_noret pallene_runtime_cant_grow_stack_error(lua_State *L); +static l_noret pallene_runtime_callstack_overflow_error(lua_State *L); /* Arithmetic operators */ static lua_Integer pallene_int_divi(lua_State *L, lua_Integer m, lua_Integer n, const char* file, int line); @@ -175,7 +192,7 @@ static TString *pallene_type_builtin(lua_State *L, TValue v); static TString *pallene_tostring(lua_State *L, const char* file, int line, TValue v); static void pallene_io_write(lua_State *L, TString *str); -/* Pallene tracer implementation. */ +/* PALLENE TRACER IMPLEMENTATION */ /* Private routines. */ @@ -204,7 +221,7 @@ static bool _findfield(lua_State *L, int fn_idx, int level) { return true; } /* If not go one level deeper and get the value recursively. */ - if(_findfield(L, fn_idx, level - 1)) { + else if(_findfield(L, fn_idx, level - 1)) { /* Remove the table but keep name. */ lua_remove(L, -2); @@ -266,13 +283,12 @@ static int _countlevels (lua_State *L) { } /* Counts the number of white and black frames in the Pallene call stack. */ -static void _countframes(pt_frame_t *frame, int *mwhite, int *mblack) { +static void _countframes(pt_cont_t *cont, int *mwhite, int *mblack) { *mwhite = *mblack = 0; - while(frame != NULL) { - *mwhite += (frame->type == PALLENE_TRACER_FRAME_TYPE_C); - *mblack += (frame->type == PALLENE_TRACER_FRAME_TYPE_LUA); - frame = frame->prev; + for(int i = 0; i < cont->count; i++) { + *mwhite += (cont->stack[i].type == PALLENE_TRACER_FRAME_TYPE_C); + *mblack += (cont->stack[i].type == PALLENE_TRACER_FRAME_TYPE_LUA); } } @@ -296,45 +312,48 @@ static void _dbg_print(const char *buf, bool *elipsis, int *pframes, int nframes } } -/* Private routines end. */ +/* Frees the heap-allocated resources. */ +static int _free_resources(lua_State *L) { + pt_cont_t *cont = (pt_cont_t *) lua_touserdata(L, 1); + + free(cont->stack); -static void pallene_tracer_frameenter(pt_cont_t *cont, pt_frame_t *restrict frame) { - /* If there is no frame in the Pallene stack. */ - if(l_unlikely(cont->stack == NULL)) { - frame->prev = NULL; - cont->stack = frame; + return 0; +} + +/* Private routines end. */ - return; +static void pallene_tracer_frameenter(lua_State *L, pt_cont_t *cont, pt_frame_t *restrict frame) { + /* If we ran out of Pallene frames. */ + if(l_unlikely(cont->count + 1 >= PALLENE_MAX_CALLSTACK)) { + pallene_runtime_callstack_overflow_error(L); } - frame->prev = cont->stack; - cont->stack = frame; + cont->stack[cont->count++] = *frame; } -static void pallene_tracer_setline(pt_frame_t *restrict frame, int line) { - frame->line = line; +static void pallene_tracer_setline(pt_cont_t *cont, int line) { + if(cont->count != 0) + cont->stack[cont->count - 1].line = line; } static void pallene_tracer_frameexit(pt_cont_t *cont) { - /* We are popping the very last frame. */ - if(cont->stack->prev == NULL) { - cont->stack = NULL; - return; - } - - cont->stack = cont->stack->prev; + cont->count -= (cont->count > 0); } /* Helper macro specific to this function only :). */ #define DBG_PRINT() _dbg_print(buf, &elipsis, &pframes, nframes) static int pallene_tracer_debug_traceback(lua_State *L) { - lua_getfield(L, LUA_REGISTRYINDEX, PALLENE_TRACER_STACK_ENTRY); - pt_frame_t *stack = ((pt_cont_t *) lua_touserdata(L, -1))->stack; + lua_getfield(L, LUA_REGISTRYINDEX, PALLENE_TRACER_CONTAINER_ENTRY); + pt_cont_t *cont = (pt_cont_t *) lua_touserdata(L, -1); + pt_frame_t *stack = cont->stack; + /* The point where we are in the Pallene stack. */ + int index = cont->count - 1; lua_pop(L, 1); /* Max number of white and black frames. */ int mwhite, mblack; - _countframes(stack, &mwhite, &mblack); + _countframes(cont, &mwhite, &mblack); /* Max levels of Lua stack. */ int mlevel = _countlevels(L); @@ -364,28 +383,26 @@ static int pallene_tracer_debug_traceback(lua_State *L) { /* If the frame is a C frame. */ if(lua_iscfunction(L, -1)) { - if(stack != NULL) { + if(index >= 0) { /* Check whether this frame is tracked (Pallene C frames). */ - pt_frame_t *check = stack; - while(check->type != PALLENE_TRACER_FRAME_TYPE_LUA) - check = check->prev; + int check = index; + while(stack[check].type != PALLENE_TRACER_FRAME_TYPE_LUA) + check--; /* If the frame signature matches, we switch to printing Pallene frames. */ - if(lua_tocfunction(L, -1) == check->shared.frame_sig) { + if(lua_tocfunction(L, -1) == stack[check].shared.frame_sig) { /* Now print all the frames in Pallene stack. */ - while(stack != check) { + for(; index > check; index--) { sprintf(buf, " %s:%d: in function '%s'\n", - stack->shared.details->mod_name, - stack->line, stack->shared.details->fn_name); + stack[index].shared.details->mod_name, + stack[index].line, stack[index].shared.details->fn_name); DBG_PRINT(); - - stack = stack->prev; } - /* 'check' is guaranteed to be a Lua interface frame. - Which is basically our 'stack' at this point. So, + /* 'check' idx is guaranteed to be a Lua interface frame. + Which is basically our 'stack' index at this point. So, we simply ignore the Lua interface frame. */ - stack = stack->prev; + index--; /* We are done. */ lua_settop(L, top); @@ -426,28 +443,66 @@ static int pallene_tracer_debug_traceback(lua_State *L) { } #undef DBG_PRINT +/* This function is expected to push the finalizer metatable in the stack. */ static pt_cont_t *pallene_tracer_init(lua_State *L) { pt_cont_t *cont = NULL; /* Try getting the userdata. */ - lua_getfield(L, LUA_REGISTRYINDEX, PALLENE_TRACER_STACK_ENTRY); + lua_getfield(L, LUA_REGISTRYINDEX, PALLENE_TRACER_CONTAINER_ENTRY); /* If we don't find any userdata, create one. */ if(l_unlikely(lua_isnil(L, -1) == 1)) { cont = (pt_cont_t *) lua_newuserdata(L, sizeof(pt_cont_t)); - cont->stack = NULL; + cont->stack = malloc(PALLENE_MAX_CALLSTACK * sizeof(pt_frame_t)); + cont->count = 0; - lua_setfield(L, LUA_REGISTRYINDEX, PALLENE_TRACER_STACK_ENTRY); + lua_newtable(L); + lua_pushcfunction(L, _free_resources); + lua_setfield(L, -2, "__gc"); + lua_setmetatable(L, -2); + + /* This is our finalizer which will reside in the value stack. */ + lua_newtable(L); + lua_newtable(L); + lua_pushvalue(L, -3); + + /* Our finalizer fn. */ + lua_pushcclosure(L, pallene_tracer_finalizer, 1); + lua_setfield(L, -2, "__close"); + lua_setmetatable(L, -2); + + /* Metatable registry. */ + lua_setfield(L, LUA_REGISTRYINDEX, PALLENE_TRACER_METATABLE_ENTRY); + + /* Stack container registry .*/ + lua_setfield(L, LUA_REGISTRYINDEX, PALLENE_TRACER_CONTAINER_ENTRY); /* The debug traceback fn. */ lua_register(L, "pallene_tracer_debug_traceback", pallene_tracer_debug_traceback); + + /* Push the metatable in the stack. */ + lua_getfield(L, LUA_REGISTRYINDEX, PALLENE_TRACER_METATABLE_ENTRY); } else { cont = lua_touserdata(L, -1); + lua_getfield(L, LUA_REGISTRYINDEX, PALLENE_TRACER_METATABLE_ENTRY); } return cont; } +static int pallene_tracer_finalizer(lua_State *L) { + /* Get the userdata. */ + pt_cont_t *cont = (pt_cont_t *) lua_touserdata(L, lua_upvalueindex(1)); + + int idx = cont->count - 1; + while(cont->stack[idx].type != PALLENE_TRACER_FRAME_TYPE_LUA) + idx--; + + cont->count = idx; + + return 0; +} + static const char *pallene_type_name(lua_State *L, const TValue *v) { if (rawtt(v) == LUA_VNUMINT) { @@ -495,7 +550,7 @@ static void pallene_barrierback_unboxed(lua_State *L, GCObject *p, GCObject *v) } } -static void pallene_runtime_tag_check_error( +static l_noret pallene_runtime_tag_check_error( lua_State *L, const char* file, int line, @@ -527,7 +582,7 @@ static void pallene_runtime_tag_check_error( PALLENE_UNREACHABLE; } -static void pallene_runtime_arity_error(lua_State *L, const char *name, int expected, int received) +static l_noret pallene_runtime_arity_error(lua_State *L, const char *name, int expected, int received) { luaL_error(L, "wrong number of arguments to function '%s', expected %d but received %d", @@ -536,25 +591,25 @@ static void pallene_runtime_arity_error(lua_State *L, const char *name, int expe PALLENE_UNREACHABLE; } -static void pallene_runtime_divide_by_zero_error(lua_State *L, const char* file, int line) +static l_noret pallene_runtime_divide_by_zero_error(lua_State *L, const char* file, int line) { luaL_error(L, "file %s: line %d: attempt to divide by zero", file, line); PALLENE_UNREACHABLE; } -static void pallene_runtime_mod_by_zero_error(lua_State *L, const char* file, int line) +static l_noret pallene_runtime_mod_by_zero_error(lua_State *L, const char* file, int line) { luaL_error(L, "file %s: line %d: attempt to perform 'n%%0'", file, line); PALLENE_UNREACHABLE; } -static void pallene_runtime_number_to_integer_error(lua_State *L, const char* file, int line) +static l_noret pallene_runtime_number_to_integer_error(lua_State *L, const char* file, int line) { luaL_error(L, "file %s: line %d: conversion from float does not fit into integer", file, line); PALLENE_UNREACHABLE; } -static void pallene_runtime_array_metatable_error(lua_State *L, const char* file, int line) +static l_noret pallene_runtime_array_metatable_error(lua_State *L, const char* file, int line) { luaL_error(L, "file %s: line %d: arrays in Pallene must not have a metatable", file, line); PALLENE_UNREACHABLE; @@ -566,6 +621,11 @@ static l_noret pallene_runtime_cant_grow_stack_error(lua_State *L) PALLENE_UNREACHABLE; } +static l_noret pallene_runtime_callstack_overflow_error(lua_State *L) { + luaL_error(L, "pallene callstack overflow"); + PALLENE_UNREACHABLE; +} + /* Lua and Pallene round integer division towards negative infinity, while C rounds towards zero. * Here we inline luaV_div, to allow the C compiler to constant-propagate. For an explanation of the * algorithm, see the comments for luaV_div. */ From 378f9d60c9fa840557058fc792bc53d97ef03e55 Mon Sep 17 00:00:00 2001 From: SD Asif Hossein Date: Thu, 20 Jun 2024 23:28:31 +0600 Subject: [PATCH 2/3] Improvements in pallene-debug script --- src/bin/pallene-debug | 70 ++++++++++++++++++++-------------------- src/pallene/pallenec.lua | 2 +- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/bin/pallene-debug b/src/bin/pallene-debug index f9c3074c..977379bc 100755 --- a/src/bin/pallene-debug +++ b/src/bin/pallene-debug @@ -1,50 +1,50 @@ #!/usr/bin/env lua -if #arg == 0 then - io.stderr:write("pallene-debug: need a file to debug. Abort!\n") - os.exit(1) -end +local argparse = require "argparse" --- File to run. -local filename = arg[1] --- Remove the filename from the argument so that --- it is identical to the arguments list if we had run --- the file explicitly. -table.remove(arg, 1) - --- Try opening the file. -local file, err = io.open(filename, "r") -if not file then - io.stderr:write("pallene-debug: could not open file: "..err.."\n") - os.exit(1) +local opts +do + local p = argparse("pallene-debug", "Pallene debugger script for call-stack backtrace") + + p:argument("lua_script", "Lua file to debug with Pallene module") + p:argument("args", "Arguments passed to Lua script") :args("*") + + opts = p:parse() end --- Try reading from the file. -local content = file:read("*all") -if not content then - io.stderr:write("pallene-debug: could not read file '"..filename.."'. Abort!\n") +local fn, err = loadfile(opts.lua_script) + +-- Was loading and parsing the file successful? +if not fn then + io.stderr:write("pallene-debug: "..err.."\n") os.exit(1) end --- We no longer need the file. -file:close() --- Silently run the code, loading the Pallene/Pallene Tracer compatible --- modules so that we can figure out whether we have Pallene Tracer or not. -local _, _ = pcall(load(content)) +-- Supress I/O. +local original_print = print +local original_io_write = io.write + +print = function() end +io.write = function() end + +-- Run the script initially so that we can figure out whether +-- we have Pallene modules that is compiled with `--use-traceback` flag. +local _, _ = pcall(fn) --- Check whether we have Pallene Tracer enabled. +-- Restore I/O. +print = original_print +io.write = original_io_write + +-- We need the traceback fn. if not pallene_tracer_debug_traceback then - io.stderr:write("pallene-debug: could not find debug traceback fn: Make sure you include Pallene modules and compile them with `--use-traceback` flag.\n") + io.stderr:write("pallene-debug: could not find debug traceback fn: Make sure you include Pallene modules which are compiled with `--use-traceback` flag.\n") os.exit(1) end --- Inject the wrapper code. -content = [[ -function __pallene_debug_wrapper() -]]..content..[[ +-- Add a wrapper function. +local function wrapper() + fn(table.unpack(opts.args)) end -xpcall(__pallene_debug_wrapper, pallene_tracer_debug_traceback) -]] - -load(content, filename)() +-- Moment of truth. +xpcall(wrapper, pallene_tracer_debug_traceback) diff --git a/src/pallene/pallenec.lua b/src/pallene/pallenec.lua index 281a4cf2..4c33cc96 100644 --- a/src/pallene/pallenec.lua +++ b/src/pallene/pallenec.lua @@ -34,7 +34,7 @@ do ) -- No Pallene tracebacks - p:flag("--use-traceback", "Use Pallene Tracer function traceback for debugging") + p:flag("--use-traceback", "Use function traceback for debugging") p:option("-O", "Optimization level") :args(1):convert(tonumber) From 6d0111afe93fe17db37487ca93b19946f45f7844 Mon Sep 17 00:00:00 2001 From: SD Asif Hossein Date: Sat, 22 Jun 2024 20:01:57 +0600 Subject: [PATCH 3/3] Removed pallene-debug script for later implementation --- src/bin/pallene-debug | 50 ------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100755 src/bin/pallene-debug diff --git a/src/bin/pallene-debug b/src/bin/pallene-debug deleted file mode 100755 index 977379bc..00000000 --- a/src/bin/pallene-debug +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env lua - -local argparse = require "argparse" - -local opts -do - local p = argparse("pallene-debug", "Pallene debugger script for call-stack backtrace") - - p:argument("lua_script", "Lua file to debug with Pallene module") - p:argument("args", "Arguments passed to Lua script") :args("*") - - opts = p:parse() -end - -local fn, err = loadfile(opts.lua_script) - --- Was loading and parsing the file successful? -if not fn then - io.stderr:write("pallene-debug: "..err.."\n") - os.exit(1) -end - --- Supress I/O. -local original_print = print -local original_io_write = io.write - -print = function() end -io.write = function() end - --- Run the script initially so that we can figure out whether --- we have Pallene modules that is compiled with `--use-traceback` flag. -local _, _ = pcall(fn) - --- Restore I/O. -print = original_print -io.write = original_io_write - --- We need the traceback fn. -if not pallene_tracer_debug_traceback then - io.stderr:write("pallene-debug: could not find debug traceback fn: Make sure you include Pallene modules which are compiled with `--use-traceback` flag.\n") - os.exit(1) -end - --- Add a wrapper function. -local function wrapper() - fn(table.unpack(opts.args)) -end - --- Moment of truth. -xpcall(wrapper, pallene_tracer_debug_traceback)