cpptrace
cpptrace copied to clipboard
Request: specify formatting per-frame
I saw that there are some upcoming formatting improvements (yay) especially for symbol shortening, and I wanted to give some attention to per-frame formatting.
Most of the time, I don't want to filter out a whole frame in a third-party library, but I don't want to print its source code either, and often even the line number in some libc++ header isn't useful.
As a request, I'd love to being able to visit each stack frame and determine whether to use color, show snippets, and include fine-grained source location, rather than for the entire formatted stacktrace output.
Example of what I'm thinking, where only some frames are highlighted:
I made the above using a transform that does frame.line.reset() and inserts ESC[0m into filename and symbol. Just applying this hack using a regex for common trampolines and thunks (e.g. libstdc++ __invoke_r) already makes for a massive quality of life improvement.
Thanks for opening this issue, I think this is a reasonable thing to want to do. There are a lot of possible settings for frames (color, source code, line numbers, etc as you mentioned) and I'm not sure the best way to design an interface that allows control of all these while also being extensible for the future, especially without making it complex to use. The library formatting facility tries to provide a one size fits most utility and for any more complicated formatting I usually recommend people write their own formatter. I think this is a generally useful idea though that would help with making traces easier to read.
Instead of making another builder sort of class or dealing with ABI breakage of a struct with settings, I'm exploring adding a setting called .interesting that lets the user indicate if a frame is interesting or not. If not, the formatter will prune symbol names (new setting in the next release), skip snippets, and skip colors. I'm not sure I'm 100% in love with it though, as it might not offer enough control.