diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2019-08-11 19:44:04 +0000 |
|---|---|---|
| committer | Quentin Young <qlyoung@nvidia.com> | 2020-12-01 18:37:14 -0500 |
| commit | e93f19fb66c491f36e9579ccb83517c1e77a9a29 (patch) | |
| tree | cddb36293c842637f38880af7908e5aa65c44a58 /lib/frrlua.c | |
| parent | 0fe6a43d9040524f6715adaaf8f9d7d7aa28a53e (diff) | |
lib: add Lua stack dumper
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/frrlua.c')
| -rw-r--r-- | lib/frrlua.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/frrlua.c b/lib/frrlua.c index 252b667961..15fda79201 100644 --- a/lib/frrlua.c +++ b/lib/frrlua.c @@ -25,6 +25,7 @@ #include "prefix.h" #include "frrlua.h" #include "log.h" +#include "buffer.h" /* * FRR convenience functions. @@ -170,4 +171,49 @@ void frrlua_export_logging(lua_State *L) lua_setfield(L, -2, "log"); } +/* + * Debugging. + */ + +char *frrlua_stackdump(lua_State *L) +{ + int top = lua_gettop(L); + + char tmpbuf[64]; + struct buffer *buf = buffer_new(4098); + + for (int i = 1; i <= top; i++) { + int t = lua_type(L, i); + + switch (t) { + case LUA_TSTRING: /* strings */ + snprintf(tmpbuf, sizeof(tmpbuf), "\"%s\"\n", + lua_tostring(L, i)); + buffer_putstr(buf, tmpbuf); + break; + case LUA_TBOOLEAN: /* booleans */ + snprintf(tmpbuf, sizeof(tmpbuf), "%s\n", + lua_toboolean(L, i) ? "true" : "false"); + buffer_putstr(buf, tmpbuf); + break; + case LUA_TNUMBER: /* numbers */ + snprintf(tmpbuf, sizeof(tmpbuf), "%g\n", + lua_tonumber(L, i)); + buffer_putstr(buf, tmpbuf); + break; + default: /* other values */ + snprintf(tmpbuf, sizeof(tmpbuf), "%s\n", + lua_typename(L, t)); + buffer_putstr(buf, tmpbuf); + break; + } + } + + char *result = XSTRDUP(MTYPE_TMP, buffer_getstr(buf)); + + buffer_free(buf); + + return result; +} + #endif |
