Debugging Tips
There are a few environment variables, options or other more-or-less known tricks to debug GIMP. Let’s try to add them here for reminder and newcomers.
Basics
The following tips will help everyone on how to debug GIMP at a basic level.
Debugging on Flatpak
Note: In all flatpak commands, replace --system
with --user
if
GIMP was installed as “user” installation. Also replace stable
with
beta
or master
depending from the repository you installed GIMP
(the repos are flathub
, flathub-beta
and gnome-nightly
respectively).
If you want to use the sandbox environment (e.g. to set GIMP_DEBUG) you can do so by specifying a custom shell instead of the GIMP binary with:
flatpak run --system --command=bash org.gimp.GIMP//stable
This will run the exact same environment as the flatpak, which should
also be identical on all machines. But we recommend using the GNOME SDK as
runtime (instead of the .Platform) by prepending the --devel
option,
since it gives you access to a few additional debug tools, such as gdb
.
So, if you want better stacktraces, first type (outside the sandbox):
GNOME_SDK_VERSION=`flatpak remote-info --system flathub org.gimp.GIMP//stable | grep Sdk: | 's#.*/##'`
flatpak install --system org.gnome.Sdk//$GNOME_SDK_VERSION
Additionally to install debug symbols useful for the sandbox, run:
flatpak install --system org.gimp.GIMP.Debug//stable
flatpak install --system org.gnome.Sdk.Debug//$GNOME_SDK_VERSION
Then, enter the sandbox with “flatpak run” above and run GIMP as you wish:
gimp
Debugging on AppImage
On AppImage, to get more detailed info on stacktraces
first ensure you have debuginfod
package installed.
Then, set DEBUGINFOD_URLS
variable before calling GIMP:
export DEBUGINFOD_URLS="https://debuginfod.debian.net"
Run GIMP as customary. If your debugger supports debuginfod, it will auto download the needed .debug symbols on demand.
Debugging on Windows
Even when run from a cmd
, the standard and error outputs are not
displayed in the terminal due to Windows GUI “subsystem” design.
For this reason, unstable builds (i.e. with odd minor version)
pop up a separate debug console attached to GIMP process at start.
If you are building stable versions of GIMP for debugging and want this
debug console as well, configure with -Denable-win32-debug-console=enabled
.
But if already built without that option, you still can see a console. For a local user installation run the following on cmd:
"%LocalAppData%\Programs\GIMP 3\bin\gimp" --verbose --console-messages
For a system-wide installation:
"%ProgramFiles%\GIMP 3\bin\gimp" --verbose --console-messages
For the Store/MSIX package, enter:
gimp-3 --verbose --console-messages
Debugging on macOS
Go to Applications/Utilities, then Terminal.
Enter:
/Applications/GIMP.app/Contents/MacOS/gimp --verbose --console-messages
Debug logs
There are various GIMP_LOG()
calls in the code. These will only be
outputted when you set GIMP_DEBUG
environment variable to a
comma-separated list of domain.
For instance, for GIMP_LOG (XCF, "some string")
to be outputted,
run GIMP like this:
GIMP_DEBUG=xcf gimp
Special flags are:
- “all” to output all domain logs;
- “list-all” to get a list of available domains.
Debugging a warning
If you encounter a CRITICAL or WARNING message on console, you can make so that GIMP crashes on it, which will make it very easy to be tracked down in a debugger (for instance GDB), by running GIMP with:
gimp --g-fatal-warnings
Note that if all you want is a stacktrace, it is not necessary anymore to use a debugger and –g-fatal-warnings. In Preferences > Debugging, make sure that all type of errors are debugged, and that you have either lldb or gdb installed. Then a graphical dialog will automatically appear upon encountering any WARNING or CRITICAL with backtraces and variable contents.
Alternatively running GIMP with the CLI option --stack-trace-mode
to
values “query” or “always” will output a stacktrace too on terminal.
But this happens only for crashes, so it still requires to use
--g-fatal-warnings
for WARNING
s and CRITICAL
s.
Note: on Windows, even the debugging GUI happens only for crashes and requires that you built with Dr. Mingw dependency.
Note 2: the CLI option --stack-trace-mode
also applies to plug-ins, in order
to output a back trace on terminal.
Debugging specific cases
The following tips are more advanced and can be useful on special cases.
Debugging GTK
You can use GtkInspector to check the CSS theme among other things by running GIMP with:
GTK_DEBUG=interactive gimp
Alternatively you may also start it at anytime with ctrl-shift-d
shortcut (or ctrl-shift-i
to inspect the focused widget), if you first enable
with:
gsettings set org.gtk.Settings.Debug enable-inspector-keybinding true
Note also that running GIMP with GDK_SCALE=2
(or other values) allow
to test the interface in another scaling than your native one. This
settings is also available in the GtkInspector.
Debugging babl
Profile conversion is done with babl by default when possible, which is
much faster.
Setting GIMP_COLOR_TRANSFORM_DISABLE_BABL
environment variable switch
back to the old lcms implementation, which can be useful for comparison.
Debugging GEGL code
You may encounter this kind of warning upon exiting GIMP:
EEEEeEeek! 2 GeglBuffers leaked
To debug GeglBuffer leaks, make sure you built GEGL with -Dbuildtype=debug
or -Dbuildtype=debugoptimized
, and set the environment variable
GEGL_DEBUG
to “buffer-alloc”.
Your system also needs to have the header execinfo.h
.
Debugging icons
See file devel-docs/icons.txt
to learn more about our icons, and in
particular the environment variable GIMP_ICONS_LIKE_A_BOSS
.
Debugging the menu-bar
For GIMP 3.0, we have 2 implementations of the menubar:
- Setting a
GimpMenuModel
withgtk_application_set_menubar()
. This is used on macOS as it will create a native application menu, directly in the desktop GUI. - Creating our own
GimpMenuBar
class with custom code. This is used by default on all other OSes.
If you want to test the macOS code path on other platforms, you can run GIMP
with the environment variable GIMP_GTK_MENUBAR
set:
GIMP_GTK_MENUBAR=1 gimp
Debugging fonts
The environment variable GIMP_DEBUG_FONTS
will have GIMP list all
ignored fonts on startup, with some basic information on why they were
ignored.
Testing older GIMP versions
A useful trick when you want to quickly test a specific GIMP older version (e.g. to confirm a behavior change) is to install it with our official flatpak. The flathub repository stores past builds (up to 20 at the time of writing). You can list them with the following command:
flatpak remote-info --system --log flathub org.gimp.GIMP//stable
Each build will have a “Subject” line (a comment to indicate the build reason, it may be just dependency updates or build fixes, or sometimes a bump in GIMP version) and a commit hash. When you have identified the build you want to test, update it like this:
flatpak update --system --commit=<hash-of-build> org.gimp.GIMP//stable
Then just run your older GIMP!
Getting accurate traces from reported inaccurate traces
Even with reporter trace without debug symbols (yet debug symbols installed on your side), if you make sure you use exactly the same flatpak commit as the reporter (see Testing older GIMP versions section) or the exact same .appimage, .exe installer or .dmg from gimp.org website, you are ensured to use the same binaries. Hence you can trace back the code line from an offset.
For instance, say that your trace has this output:
gimp(file_open_image+0x4e8)[0x5637e0574738]
Here is how you can find the proper code line:
gdb gimp
(gdb) info line *(file_open_image+0x4e8)
Line 216 of "file-open.c" starts at address 0x4d5738 <file_open_image+1256> and ends at 0x4d5747 <file_open_image+1271>.
Debugging though gdbserver
In some cases, when GIMP grabs the pointer and/or keyboard, i.e. when you debug something happening on canvas in particular, it might be very hard to get back to your debugger, since your system won’t be responding to your keyboard or click events.
To work around this, you can debug remotely, or simply from a TTY (while the desktop doesn’t answer properly):
In your desktop, run GIMP through a debugger server:
gdbserver gimp
Go to a TTY and run
gdb gimp
(gdb) target remote localhost:9999
(gdb) continue
Of course, before the continue
, you may add whatever break points or
other commands necessary for your specific issue. GIMP will start in the
desktop when you hit continue
(it will likely be a slower start).
Then do your issue reproduction steps on GIMP. When you need to debug, you can go to the TTY whenever you want, not bothering about any keyboard/pointer grabs.
Note that since copy-pasting is harder in a TTY, you might want to redirect your output to a file, especially if you need to upload it or read it slowly next to GIMP code. For instance here are commands to output a full backtrace into a file from the gdb prompt and exit (to force the device ungrab by killing GIMP and go work on desktop again):
(gdb) set logging file gimp-issue-1234.txt
(gdb) set logging on
(gdb) thread apply all backtrace full
(gdb) quit
Debugging plug-ins
The process of debugging plug-ins is the most complex. So, you should look at Debugging Plug-ins dedicated page.