Files
LemonInTheDark a970522ce2 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.
2026-02-05 17:36:56 -05:00

41 lines
1.8 KiB
Plaintext

/// gives us the stack trace from CRASH() without ending the current proc.
/// 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