Improve debugging support

This is what we discussed in #14533, let me know feedback.