Skip to content

Conversation

@ZedThree
Copy link
Member

@ZedThree ZedThree commented Dec 5, 2025

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:

  1. it's very portable out of the box, so we don't need to rely on external utilities like addr2line and instead can always enable backtraces
  2. 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:

image

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?

Always generating the backtraces can slow the unit tests down by a factor x2-3

An alternative might be to store the `cpptrace:stacktrace` and only convert to
string in `BoutException::what()`
@ZedThree ZedThree requested a review from bendudson December 5, 2025 15:11
@ZedThree
Copy link
Member Author

Lots of CMake pain here

@bendudson
Copy link
Contributor

Thanks @ZedThree ! This does look nice, if the CMake pain can be overcome. I think if it works portably then it could replace all the MsgStack / AUTOTRACE code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants