qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.65k stars 3.01k forks source link

Debug logging for C++ object destruction #58773

Open velle opened 2 months ago

velle commented 2 months ago

Feature description

I have realized that when programming in Python, using the binary C++ back-end of QGIS, I have to care a lot about whether objects are cleaned up before they are supposed to, because of Python garbage collection. Otherwise I run into segfaults.

Because this is new, and honestly quite complex, for me, I have helped myself in debugging such issues by adding some qDebug statements to the C++ code. E.g. in:

QgsApplication::~QgsApplication()
{
  qDebug("running QgsApplication destructor");
  (...)
}

I've done this to six classes this far; classes where I either had or suspected such issues.

Would it be welcome if I submitted such debugging code to master? Or will I need to keep this only on my local instance? It takes a long time to recompile the C++ code locally, just to add a couple of debug messages :)

Additional context

No response

nyalldawson commented 2 months ago

@velle there's already extensive logging code like this, which uses QgsDebugMsgLevel(....). You'll only get the output on debug builds (not release builds, for performance reasons), and you need to set the environment variable QGIS_DEBUG to 2 or greater, where larger numbers result in more verbose logs.

velle commented 2 months ago

Im asking specifically about adding these debug messages in destructors, and only in a handful of classes. I did not notice any logging in these destructors, when looking in the source code. Is there?

I need something that helps me see what things are destructed and when. That helps me understand what causes segfaults.

nyalldawson commented 2 months ago

There's some in destructors already, more would be welcome if they use QgsDebugMsgLevel appropriately! 👍