From a970522ce2c32440405f12fbc928df1ca8f5d294 Mon Sep 17 00:00:00 2001 From: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Date: Thu, 5 Feb 2026 14:36:56 -0800 Subject: [PATCH] Adds a helper proc that dumps the names of all the procs in the stack (#95065) ## About The Pull Request It will basically ALWAYS error in some way, but I've found it quite helpful for debugging and I figure that's worth the cost. Really shouldn't be used on live... ever. --- code/__HELPERS/stack_trace.dm | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/code/__HELPERS/stack_trace.dm b/code/__HELPERS/stack_trace.dm index bb2d78de110..7a99ff6c2f7 100644 --- a/code/__HELPERS/stack_trace.dm +++ b/code/__HELPERS/stack_trace.dm @@ -2,3 +2,39 @@ /// Do not call directly, use the [stack_trace] macro instead. /proc/_stack_trace(message, file, line) CRASH("[message][WORKAROUND_IDENTIFIER][json_encode(list(file, line))][WORKAROUND_IDENTIFIER]") + + +#if (DM_BUILD > 1667) +#warn if this is ci please remove my Note: comment below, thanks, love you! +#endif +#define STACK_DEPTH_SEARCH_LIMIT 2000 +/// Returns an ordered list of all our parent procs, highest to deepest +/// Note: This will frequently cause erorrs and have seemingly infinitely repeating procs on the current good byond version +/// It'll be fixed when we can update to latest for dev but you likely can't do that right now (since debugging hasn't been fixed yet) +/// BIGGER, MORE IMPORTANT NOTE: Should not be used on master maybe ever, introspection like this is mostly useful for debugging +/// if you have another use I suspect you are just creating god's strongest footgun and should rethink things +/proc/dump_stack(max_depth = STACK_DEPTH_SEARCH_LIMIT) + var/list/proc_paths = list() + var/crashed = FALSE + var/depth = 0 + var/callee/stack_entry = caller + try + while(!isnull(stack_entry) && depth <= max_depth) + proc_paths += stack_entry.proc + stack_entry = stack_entry.caller + depth += 1 + catch + //union job. avoids crashing the stack again + //I just do not trust this construct to work reliably + crashed = TRUE + + if(crashed) + stack_trace("dump_stack's stack walking crashed after walking [length(proc_paths)] procs, Last Read: [proc_paths[length(proc_paths)]] Last Accessed: [stack_entry]") + return proc_paths + + if(depth > max_depth) + stack_trace("dump_stack's stack walking exceeded our soft limit after walking [length(proc_paths)] procs, Last Read: [proc_paths[length(proc_paths)]] Next Accessed: [stack_entry]") + return proc_paths + return proc_paths + +#undef STACK_DEPTH_SEARCH_LIMIT