Skip to content

feat: add cpptrace for better stack traces #4042

Open
kdrienCG wants to merge 12 commits intodevelopfrom
feature/kdrienCG/betterStackTrace
Open

feat: add cpptrace for better stack traces #4042
kdrienCG wants to merge 12 commits intodevelopfrom
feature/kdrienCG/betterStackTrace

Conversation

@kdrienCG
Copy link
Copy Markdown

@kdrienCG kdrienCG commented Apr 28, 2026

(Requires TPL PR #347)

This PR aims to improve the stack trace output when an error is thrown.

When GEOS crashes from a C++ exception, the stack trace we log is not really useful: it points at main.cpp instead of the code that actually threw, missing on valuable informations for devs. This is not a bug in the error handler, it is how the C++ runtime works.
cpptrace solves this by providing a mechanism to get stack traces from thrown exceptions, that will make us able to know exactly where the code went.

Here is an example defining a myThrowingFunction() incorrectly using a map directly (written in the main.cpp for convenience)

Without cpptrace:

***** Exception
***** Rank 0
***** Message :
map::at

***** StackTrace of 7 frames
  - Frame  0:  geos::ErrorLogger::initCurrentExceptionMessage(geos::MsgType, std::basic_string_view<char, std::char_traits<char> >, int) 
  - Frame  1:  main /somewhere/in/my/disk/geos/GEOS/src/main/main.cpp:272 (discriminator 3)
  - Frame  2:  __libc_start_main 
  - Frame  3:  _start 
  - Frame  4:  main /somewhere/in/my/disk/geos/GEOS/src/main/main.cpp:275 (discriminator 2)
  - Frame  5:  __libc_start_main 
  - Frame  6:  _start 
*****

With cpptrace:
(truncated to fit the PR description)

***** Exception
***** Rank 0
***** Message :
map::at

***** StackTrace of 15 frames
  - Frame  0: at libstdc++.so.6
  - Frame  1: in __gxx_personality_v0 at libstdc++.so.6
  - Frame  2: at libstdc++.so.6
  - Frame  3: in std::map<std::string, int, std::less<std::string>>::at(std::string const&) at stl_map.h:551:24
  - Frame  4: in myThrowingFunction() at main.cpp:40:24
  - Frame  5: in operator() at main.cpp:49:16
  - Frame  6: in do_try_catch<const geos::NotAnError&, main(int, char**)::<lambda()>&, main(int, char**)::<lambda...
  - Frame  7: in operator() at from_current.hpp:143:32
  - Frame  8: in operator() at from_current.hpp:143:32
  - Frame  9: in operator() at from_current.hpp:143:32
  - Frame 10: in try_catch_impl<main(int, char**)::<lambda()>&, main(int, char**)::<lambda(const geos::NotAnError...
  - Frame 11: in try_catch<main(int, char**)::<lambda()>&, main(int, char**)::<lambda(const geos::NotAnError&)>&...
  - Frame 12: in main at main.cpp:129:22
  - Frame 13: in __libc_start_main at libc.so.6
  - Frame 14: in _start at geosx
*****

We have a detailled stack trace with the name of the function that throws and the correct line and character position.

@kdrienCG kdrienCG self-assigned this Apr 28, 2026
@kdrienCG kdrienCG added type: feature New feature or request flag: requires updated TPL(s) Needs a specific TPL PR labels Apr 28, 2026
@kdrienCG kdrienCG marked this pull request as ready for review May 5, 2026 16:50
@rrsettgast
Copy link
Copy Markdown
Member

@kdrienCG Is there a discussion somewhere about whether we want to add this dependency?

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

Labels

flag: requires updated TPL(s) Needs a specific TPL PR type: feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants