Logging all C++ destructors, poor mans run-time tracing - Raymii.org

submited by
Style Pass
2024-09-21 19:30:10

I recently faced a challenging issue with an application that wasn't shutting down correctly, either segfaulting or terminating without an active exception. Running the program via valgrind to check for memory leaks wasn't possible because the program couldn’t perform its cleanup if it didn't shut down correctly. This article covers adding runtime instrumentation provided by gcc to log destructors. This helped me figure out what was still left over from the closed-source framework in use preventing correct shutdowns or causing segfaults. It includes example code, setup instructions and insights into handling shutdown issues in large, multi-threaded codebases.

Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below: I'm developing an open source monitoring app called Leaf Node Monitoring, for windows, linux & android. Go check it out! Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs. You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $200 credit for 60 days. Spend $25 after your credit expires and I'll get $25!

This is an embedded application that normally never exits, so shutdown behavior hadn't been a focus. Given the large codebase with many threads, pinpointing the shutdown issues was difficult.

Leave a Comment