bombela / backward-cpp

A beautiful stack trace pretty printer for C++
MIT License
3.68k stars 467 forks source link

Simple way to pretty print a truncated stack trace? #256

Closed SdtElectronics closed 2 years ago

SdtElectronics commented 2 years ago

The sources of stack trace for the innermost frames are always the same (from libraries reading the debug info, libraries unwinding the stack and backward-cpp itself) which I don't care much. It would be nice if they can be dropped. I found TraceResolver allows specifying a specific frame, which can be leveraged to accomplish this, but I have to format the message as Printer refuses to accept ResolvedTrace as argument:

backward.hpp:4037:25: error: ‘struct backward::ResolvedTrace’ has no member named ‘thread_id’
 4037 |     print_header(os, st.thread_id());
      |                      ~~~^~~~~~~~~
backward.hpp:4039:32: error: ‘struct backward::ResolvedTrace’ has no member named ‘size’
 4039 |     for (size_t trace_idx = st.size(); trace_idx > 0; --trace_idx) {
      |                             ~~~^~~~
backward.hpp:4040:43: error: no match for ‘operator[]’ (operand types are ‘backward::ResolvedTrace’ and ‘size_t’ {aka ‘long unsigned int’})
 4040 |       print_trace(os, _resolver.resolve(st[trace_idx - 1]), colorize);

I wonder if there is a way to pretty print a truncated stack trace as simple as using Stacktrace with Printer?

bombela commented 2 years ago

Does void skip_n_firsts(size_t) on the StackTrace object help?

https://github.com/bombela/backward-cpp/blob/master/backward.hpp#L731

SdtElectronics commented 2 years ago

Does void skip_n_firsts(size_t) on the StackTrace object help?

This does exactly what I want. Thanks!