a simple hack to make caller apparent
Teliva isn't yet smart enough to know the caller of an indirect function where the function being called goes through a local variable. I'd expected fixing this to be a long death march. However, there's a shockingly easy fix: just make every indirect call go through an additional direct function call. My policy for zet.tlv was that function 'main' could open any file. This stopped working since I introduced spawn_main. But with this commit it's working again. I can also drop all my special-casing of 'main' since it's now a regular Lua call. We still can't rely on the caller of an indirect call. That affects start_reading and start_writing, which really need to be part of the framework.
This commit is contained in:
parent
52ae23784b
commit
f2d29c22f8
|
@ -382,7 +382,7 @@ _M.NOP = NOP
|
||||||
|
|
||||||
-- Specific to Teliva
|
-- Specific to Teliva
|
||||||
function spawn_main()
|
function spawn_main()
|
||||||
task.spawn(main)
|
task.spawn(call_main)
|
||||||
task.scheduler()
|
task.scheduler()
|
||||||
assert(false, "Teliva's scheduler ran out of work; this shouldn't happen.\n"..
|
assert(false, "Teliva's scheduler ran out of work; this shouldn't happen.\n"..
|
||||||
"Either a channel is blocked forever or you're reading past\n"..
|
"Either a channel is blocked forever or you're reading past\n"..
|
||||||
|
@ -391,6 +391,12 @@ function spawn_main()
|
||||||
curses.getch()
|
curses.getch()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- This function exists only to make the call to 'main' visible to Teliva.
|
||||||
|
-- Teliva can't yet recognize the caller of indirect calls.
|
||||||
|
function call_main()
|
||||||
|
main()
|
||||||
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
-- Tests
|
-- Tests
|
||||||
|
|
|
@ -322,7 +322,6 @@ void save_caller(lua_State* L, const char* name, int call_graph_depth) {
|
||||||
lua_getstack(L, 1, &ar);
|
lua_getstack(L, 1, &ar);
|
||||||
lua_getinfo(L, "n", &ar);
|
lua_getinfo(L, "n", &ar);
|
||||||
if (ar.name) save_caller_as(L, name, ar.name);
|
if (ar.name) save_caller_as(L, name, ar.name);
|
||||||
else if (call_graph_depth == 2) save_caller_as(L, name, "main"); // the way Teliva calls `main` messes with debug info
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char* caller(lua_State* L) {
|
char* caller(lua_State* L) {
|
||||||
|
@ -396,9 +395,6 @@ restart:
|
||||||
clear();
|
clear();
|
||||||
luaL_newmetatable(L, "__teliva_call_graph_depth");
|
luaL_newmetatable(L, "__teliva_call_graph_depth");
|
||||||
int cgt = lua_gettop(L);
|
int cgt = lua_gettop(L);
|
||||||
// special-case: we don't instrument the call to main, but it's always at depth 1
|
|
||||||
lua_pushinteger(L, 1);
|
|
||||||
lua_setfield(L, cgt, "main");
|
|
||||||
// segment definitions by depth
|
// segment definitions by depth
|
||||||
lua_getglobal(L, "teliva_program");
|
lua_getglobal(L, "teliva_program");
|
||||||
int history_array = lua_gettop(L);
|
int history_array = lua_gettop(L);
|
||||||
|
@ -514,7 +510,7 @@ restart:
|
||||||
y += 2;
|
y += 2;
|
||||||
mvprintw(y, 0, "functions: ");
|
mvprintw(y, 0, "functions: ");
|
||||||
y++;
|
y++;
|
||||||
for (int depth = 1; ; ++depth) {
|
for (int depth = /*ignore call_main*/2; ; ++depth) {
|
||||||
mvaddstr(y, 0, " ");
|
mvaddstr(y, 0, " ");
|
||||||
bool drew_anything = false;
|
bool drew_anything = false;
|
||||||
index_within_level = 0;
|
index_within_level = 0;
|
||||||
|
|
Loading…
Reference in New Issue