From: Aki Tuomi Date: Fri, 26 Jun 2020 09:16:31 +0000 (+0300) Subject: lib-lua: Add dlua_dump_stack X-Git-Tag: 2.3.11.2~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5bf39d84179fe7a4540f975af87cf5e7d7383adf;p=thirdparty%2Fdovecot%2Fcore.git lib-lua: Add dlua_dump_stack Useful for debugging why stack leaks --- diff --git a/src/lib-lua/dlua-script.c b/src/lib-lua/dlua-script.c index 4b1c63e5c2..d3e7746f4c 100644 --- a/src/lib-lua/dlua-script.c +++ b/src/lib-lua/dlua-script.c @@ -4,6 +4,7 @@ #include "llist.h" #include "istream.h" #include "sha1.h" +#include "str.h" #include "hex-binary.h" #include "eacces-error.h" #include "dlua-script-private.h" @@ -354,3 +355,29 @@ void dlua_setmembers(struct dlua_script *script, values++; } } + +void dlua_dump_stack(struct dlua_script *script) +{ + /* get everything in stack */ + int top = lua_gettop(script->L); + for (int i = 1; i <= top; i++) T_BEGIN { /* repeat for each level */ + int t = lua_type(script->L, i); + string_t *line = t_str_new(32); + str_printfa(line, "#%d: ", i); + switch (t) { + case LUA_TSTRING: /* strings */ + str_printfa(line, "`%s'", lua_tostring(script->L, i)); + break; + case LUA_TBOOLEAN: /* booleans */ + str_printfa(line, "`%s'", lua_toboolean(script->L, i) ? "true" : "false"); + break; + case LUA_TNUMBER: /* numbers */ + str_printfa(line, "%g", lua_tonumber(script->L, i)); + break; + default: /* other values */ + str_printfa(line, "%s", lua_typename(script->L, t)); + break; + } + i_debug("%s", str_c(line)); + } T_END; +} diff --git a/src/lib-lua/dlua-script.h b/src/lib-lua/dlua-script.h index f5a15a8338..9388498992 100644 --- a/src/lib-lua/dlua-script.h +++ b/src/lib-lua/dlua-script.h @@ -32,4 +32,7 @@ void dlua_push_event(struct dlua_script *script, struct event *event); /* get event from given stack position */ struct event *dlua_check_event(struct dlua_script *script, int arg); +/* dumps current stack as i_debug lines */ +void dlua_dump_stack(struct dlua_script *script); + #endif