Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug logging for C++ object destruction #58773

Open
velle opened this issue Sep 17, 2024 · 3 comments
Open

Debug logging for C++ object destruction #58773

velle opened this issue Sep 17, 2024 · 3 comments

Comments

@velle
Copy link
Contributor

velle commented Sep 17, 2024

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
Copy link
Collaborator

nyalldawson commented Sep 17, 2024

@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
Copy link
Contributor Author

velle commented Sep 17, 2024

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
Copy link
Collaborator

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

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

No branches or pull requests

2 participants