If you are using Qt Creator on Ubuntu 23.04
or Debian 12 Bookworm
, you might have noticed this detail: during debugging addresses are shown instead of local variable values.
I spent some anger to find the cause of this problem and in this post I will share with you the solution.
Qt Creator injects, at the start of the debug session, some Python scripts into the GDB, they know how to pretty print
Qt complex variables, QString
, QByteArray
, QYourGrandma
and so on. For GDB these types are just pointers and without the scripts it returns by default their addresses.
⚠️ Here is one of the reasons that when debugging Qt applications in VS Code it does not resolve Qt variables. VS Code does not inject these scripts andpretty print
does not happen.
On Ubuntu 23.04
and Debian 12 Bookworm
Python 3 is version 3.11.x
. In this version the getargspec
function of the inspect
module has been removed it was already marked as deprecated and so it was finally removed. And the Qt Creator v9.0.2
scripts use this function.
And now? 🤔
Well, easy, let's port the script that's using the getargspec
. Yes, but the problem was coming to the conclusion that the problem was the use of getargspec
. Do you know why? Because GDB doesn't complain, no stack trace, nothing, it just doesn't work like it should. So, the way was to debug, by print, and "track" the script execution flow.
But since I'm very nice, I'll save you that work and I'll share the solution.
Run the following command in the terminal:
sudo sed -i 's/inspect\.getargspec/inspect.getfullargspec/g' /usr/share/qtcreator/debugger/dumper.py
Done, now just start Qt Creator and be happy with debug and pretty print
working.
What are we doing in this command? As described in What's New In Python 3.11 we are replacing the call to getargspec
with getfullargspec
.
⚠️ Make sure you haveUse Debugging Helpers
enabled in Qt Creator settings.Edit > Preferences > Debugger > Locals & Expressions
:
Without this option enabled, Qt Creator does not inject scripts into GDB.
If you are using the VS Code extension to debug Torizon applications, and is facing the same problem, there is already a tasks that applies the fix in the Qt Creator script. Just run the fix-debugger-helper-qt-creator
task, input your admin user password and that's it.
Until this is fixed in the Qt Creator package for Debian and Ubuntu this is one solution. If you use another distro, or another version of Qt Creator, check if the problem is the same and if so, port the script.
Was this post helpful to you? Let me know, contact me, follow me on social media: