From 5a44605143362c8d240c20c849593a3739bf9bed Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 13 Nov 2021 08:16:41 -0800 Subject: instrumenting function calls with their depth --- src/lua.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/lua.c') diff --git a/src/lua.c b/src/lua.c index 08c5f92..59c50ca 100644 --- a/src/lua.c +++ b/src/lua.c @@ -370,6 +370,16 @@ void switch_to_editor (lua_State *L, const char *message) { if (Script_name) edit(L, Script_name, message); else { + luaL_newmetatable(L, "__teliva_call_graph_depth"); + int cgt = lua_gettop(L); + printf("cgt: %d\n", cgt); + for (lua_pushnil(L); lua_next(L, cgt) != 0;) { + const char* function_name = lua_tostring(L, -2); + int depth = lua_tointeger(L, -1); + printf("%s: %d\n", function_name, depth); + lua_pop(L, 1); // pop value, leave key on stack for next iteration + } + exit(4); Current_definition = "main"; write_definition_to_file(L, Current_definition, "teliva_editbuffer"); edit(L, "teliva_editbuffer", /*status message*/ ""); -- cgit 1.4.1-2-gfad0