[HN Gopher] Logging all C++ destructors, poor mans run-time tracing
       ___________________________________________________________________
        
       Logging all C++ destructors, poor mans run-time tracing
        
       Author : jandeboevrie
       Score  : 16 points
       Date   : 2024-09-21 19:06 UTC (3 hours ago)
        
 (HTM) web link (raymii.org)
 (TXT) w3m dump (raymii.org)
        
       | meindnoch wrote:
       | And what was the bug in the end?
        
       | neverartful wrote:
       | I did something similar once but my implementation didn't rely on
       | any compiler features. I made tracing macros for constructors,
       | destructors, and regular c++ methods. If the tracing was turned
       | on in the macros, the information given to the macro (class name,
       | method name, etc.) would be passed to the tracing manager. The
       | tracing manager would serialize to a string and send it through a
       | TCP socket. I also wrote a GUI tracing monitor that would listen
       | on a socket for tracing messages and then display the trace
       | messages received (including counts by class and method). The
       | tracing monitor had filters to tweak. It was a nice tool to have
       | and was very instrumental in finding memory leaks and obscure
       | crashes. This was back in the late 1990s or early 2000s.
        
       | jprete wrote:
       | Address/MemorySanitizer are also meant for this kind of problem.
       | https://github.com/google/sanitizers/wiki/AddressSanitizer
       | https://github.com/google/sanitizers/wiki/MemorySanitizer
       | 
       | Also valgrind, but I'm more familiar with the first two.
        
       | loeg wrote:
       | But what was the shutdown bug you were trying to identify? Was
       | this destructor logging actually useful? The article teases the
       | problem and provides detailed instructions for reproducing the
       | logging, but doesn't actually describe solving the problem.
        
       | grahamj wrote:
       | That's not very inclusive. This would be fine for poor women too.
        
       | rqtwteye wrote:
       | I did this a long time ago with macros. It helped me to find a
       | ton of leaks in a huge video codec codebase.
       | 
       | I still don't understand the hate for the C preprocessor. It
       | enables doing this like this without any overhead. Set a flag and
       | you get constructor/destructor logging and whatever else you
       | want. Don't set it and you get the regular behavior. Zero
       | overhead.
        
       ___________________________________________________________________
       (page generated 2024-09-21 23:00 UTC)