BOUT-dev
BOUT-dev copied to clipboard
Use `cpptrace` for prettier backtraces from exceptions
We have historically been reluctant to add too many external dependencies, but with CMake and spack making it easier to pull them in and build them, I thought I'd try this library for generating stack traces.
Two useful things:
- it's very portable out of the box, so we don't need to rely on external utilities like
addr2lineand instead can always enable backtraces - we can print snippets:
#3 in checkData(double)
at /home/peter/Codes/BOUT++/BOUT-dev/include/bout/utils.hxx:493:65
491: inline void checkData(BoutReal f) {
492: if (!std::isfinite(f)) {
> 493: throw BoutException("BoutReal: Operation on non-finite data");
^
494: }
495: }
#4 in operator*(Field3D const&, double)
at /home/peter/Codes/BOUT++/BOUT-dev/src/field/generated_fieldops.cxx:480:12
478: Field3D result{emptyFrom(lhs)};
479: checkData(lhs);
> 480: checkData(rhs);
^
481:
482: result.setRegion(lhs.getRegionID());
#5 in Blob2D::rhs(double)
at /home/peter/Codes/BOUT++/BOUT-dev/examples/blob2d/blob2d.cxx:177:41
176: ddt(n) = -bracket(phi, n, BRACKET_ARAKAWA) // ExB term
> 177: + 2 * DDZ(n) * (rho_s / R_c) // Curvature term
^
178: + D_n * Delp2(n); // Diffusion term
179: if (compressible) {
and can even enable colour:
It also has its own signal handler we could perhaps use instead of ours (though I've not tested this out).
Lastly, this is maybe a complete enough solution that we could also remove MsgStack/TRACE/AUTO_TRACE?