When a stack overflows, the system performs an exit_block/1 with an appropriate exit tag, ie.
These exits can be caught by wrapping a goal that is likely to overflow the stacks into an appropriate block/3, e.g.
..., block(big_goal(X), global_trail_overflow, react_to_overflow), ...
In the debugger, you can locate the overflow by jumping to a LEAVE port (z command). See chapter 19 for more details on memory usage.