bombela/backward-cpp

Problem calling load_here() in a parent constructor

craigsoules opened this issue · 0 comments

We are trying to capture a backtrace in a parent class constructor, but it is failing to do so. The code looks like this:

class Error() {
private:                                                                                                                                                                                                       
    backward::StackTrace _trace;
public:
    Error() { _trace.load_here() }

    void print_trace() {
        backward::Printer printer;                                                                                                                                                                             
        printer.print(_trace);   
    }
}

class MyError() {
public:
    MyError() { }
}

void error() {
    throw MyError();
}

int main(int argc, char *argv[]) {
    try {
        error();
   } catch(Error &e) {
       e.print_trace();
   }
}

In the version of backward from vcpkg there is actually a bug where the call to details::unwind returns -1 causing a vector sizing exception to be thrown, which it looks like has been fixed, however, I'm unclear why it can't do the unwinding properly in this case.

Is there something special about parent constructors that causes unwind to fail to work properly? Thanks!