]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-lua: Add dlua_dump_stack
authorAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 26 Jun 2020 09:16:31 +0000 (12:16 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 3 Jul 2020 06:56:42 +0000 (09:56 +0300)
Useful for debugging why stack leaks

src/lib-lua/dlua-script.c
src/lib-lua/dlua-script.h

index 4b1c63e5c2bec379e43657cca14b1147fb66d265..d3e7746f4cbbeed2fee273467f78884777e3903b 100644 (file)
@@ -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;
+}
index f5a15a83385ea624b4da86d2c55b6433f5dd0f19..9388498992b222f691b0c804f23f27660d1e55ca 100644 (file)
@@ -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