Implement clean_up_backtrace_handler()

Split off legacy/trac#31594 (moved):

clean_up_backtrace_handler() doesn't do anything, but it should: