diff options
| author | ruki <[email protected]> | 2022-02-08 22:41:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-02-08 22:41:02 +0800 |
| commit | 26af8f1eb23348c435bf535522e220a7c8b02af6 (patch) | |
| tree | ec2a8c3486967f80b6d009cf6f482b79ade44652 | |
| parent | 2de89897498bd3f6eeb8dc130206dc53d3c7efa7 (diff) | |
debug stuck backtrace
| -rw-r--r-- | core/src/xmake/engine.c | 65 | ||||
| -rw-r--r-- | xmake/core/base/coroutine.lua | 6 | ||||
| -rw-r--r-- | xmake/plugins/show/lists/envs.lua | 2 |
3 files changed, 36 insertions, 37 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index aba443be4..86f902580 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -691,6 +691,41 @@ static tb_bool_t xm_engine_get_project_directory(xm_engine_t* engine, tb_char_t* return ok; } +#if defined(TB_CONFIG_OS_WINDOWS) || defined(SIGINT) +static tb_void_t xm_engine_dump_traceback(lua_State* lua) +{ + // @note it's not safe, but it doesn't matter, we're just trying to get the stack backtrace for debugging + lua_getglobal(lua, "debug"); + lua_getfield(lua, -1, "traceback"); + lua_replace(lua, -2); + lua_pushvalue(lua, 1); + lua_pushinteger(lua, 2); + lua_call(lua, 2, 1); + tb_trace_i("%s", lua_tostring(lua, -1)); +} +#endif + +#if defined(TB_CONFIG_OS_WINDOWS) +static BOOL WINAPI xm_engine_signal_handler(DWORD signo) +{ + if (signo == CTRL_C_EVENT && g_lua) + { + xm_engine_dump_traceback(g_lua); + tb_abort(); + } + return TRUE; +} +#elif defined(SIGINT) +static tb_void_t xm_engine_signal_handler(tb_int_t signo) +{ + if (signo == SIGINT && g_lua) + { + xm_engine_dump_traceback(g_lua); + tb_abort(); + } +} +#endif + static tb_void_t xm_engine_init_host(xm_engine_t* engine) { // check @@ -837,36 +872,6 @@ static tb_void_t xm_engine_init_features(xm_engine_t* engine) lua_setglobal(engine->lua, "_FEATURES"); } -#if defined(TB_CONFIG_OS_WINDOWS) -static BOOL WINAPI xm_engine_signal_handler(tb_int_t signo) -{ - if (signo == CTRL_C_EVENT) - { - tb_trace_i("signal: %d", signo); - tb_abort(); - } - return TRUE; -} -#elif defined(SIGINT) -static tb_void_t xm_engine_signal_handler(tb_int_t signo) -{ - if (signo == SIGINT) - { - tb_trace_i("signal: %d", signo); -#if 0 - lua_getfield(lua, 1, "debug"); - lua_pushvalue(lua, -2); - lua_pushvalue(lua, 1); - if (lua_pcall(lua, 2, 0, 0) != 0) - { - tb_printl(lua_pushfstring(lua, "error calling " LUA_QL("$interactive_setfenv") " (%s)", lua_tostring(lua, -1))); - } -#endif - tb_abort(); - } -} -#endif - static tb_void_t xm_engine_init_signal(xm_engine_t* engine) { // we enable it to catch the current lua stack in ctrl-c signal handler if XMAKE_PROFILE=stuck diff --git a/xmake/core/base/coroutine.lua b/xmake/core/base/coroutine.lua index 2f1c347a8..43a5d6d8a 100644 --- a/xmake/core/base/coroutine.lua +++ b/xmake/core/base/coroutine.lua @@ -31,8 +31,6 @@ coroutine._resume = coroutine._resume or coroutine.resume -- resume coroutine function coroutine.resume(co, ...) - - -- resume it local ok, results = coroutine._resume(co, ...) if not ok then @@ -47,12 +45,8 @@ function coroutine.resume(co, ...) errors = results:sub(pos + 1) end end - - -- failed return false, errors end - - -- ok return true, results end diff --git a/xmake/plugins/show/lists/envs.lua b/xmake/plugins/show/lists/envs.lua index 4092901fa..8e66db1e8 100644 --- a/xmake/plugins/show/lists/envs.lua +++ b/xmake/plugins/show/lists/envs.lua @@ -36,7 +36,7 @@ function main() XMAKE_RAMDIR = {"Set the ramdisk directory.", os.getenv("XMAKE_RAMDIR")}, XMAKE_RCFILES = {"Set the runtime configuration files.", path.joinenv(project.rcfiles())}, XMAKE_TMPDIR = {"Set the temporary directory.", os.tmpdir()}, - XMAKE_PROFILE = {"Start profiler, e.g. perf, trace.", os.getenv("XMAKE_PROFILE")}, + XMAKE_PROFILE = {"Start profiler, e.g. perf, trace, stuck.", os.getenv("XMAKE_PROFILE")}, XMAKE_PKG_CACHEDIR = {"Set the cache directory of packages.", os.getenv("XMAKE_PKG_CACHEDIR")}, XMAKE_PKG_INSTALLDIR = {"Set the install directory of packages.", os.getenv("XMAKE_PACKAGEDIR")}} local width = 24 |
