I have the issue of a PyQt-based GUI application occasionally crashing at exit with either a segmentation fault or an error message that indicates an unhandled C++ exception was encountered.
While running, there are no such issues, this problem is most likely caused by some step in the application shutdown.
How can I best debug such a "mixed" scenario of Python and C++, except for actually wrapping the application launch command with gdb, or explicitly enabling core dumps and trying a "post-mortem" analysis on the resulting core file?
Thank you very much!
Fabian Aichele
A real-world approach is to keep a registry of active objects. Add each object in its ctor, remove in the dtor. In members that you've seen crash, check if this appears in the registry. If that doesn't help, add these checks also to related methods
It's formally Undefined Behavior already to call that method, but you already have UB. However, this method won't work too well on virtual calls. In that case, it's a good moment to introduce the public non-virtual/protected virtual pattern: Replace a virtual public method X with a pair public: auto X() { checkAlive(this); return doX(); } protected: virtual Foo doX();
This pattern is also good for various other assertions,logging and similar non-functionals.
How to debug non-deterministic segmentation faults in a mixed Python-C++ library?