bombela / backward-cpp

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

"Reverse" stacktrace #215

Open aytey opened 3 years ago

aytey commented 3 years ago

Apologies if I missed this (I did search for "reverse", but searching for "backwards" clearly isn't going to work!), but is there a way to get backwards-cpp to spit out the stacktrace in reverse?

I am currently using this code (from the README):

using namespace backward;
StackTrace st; st.load_here(32);
st.skip_n_firsts(3);
Printer p; p.print(st);

but I'd like to see the innermost frames at the top (like how you'd see it with gdb).

I poked into Printer::print and this calls Printer::print_stacktrace, which then iterates (forward) on the content of the stacktrace, but it seems there's no way to ask it go to in reverse.

So, two questions:

  1. Is there an easy way to get backwards-cpp to give a reversed stacktrace?
  2. If not, would adding a reversed=True default argument to Printer::print/Printer::print_stacktrace be acceptable as a PR?
bombela commented 3 years ago

You could print yourself in the order you want. The included printer is not fancy. You could copy paste it and modify it in your application.

The Printer is an object for the purpose of holding configuration options. A PR that adds a reverse option to the printer would be welcome.