How to get full Valgrind report in Builder?

Hi there,

I’m developing a small GTK4 application in a Flatpak version of Gnome Builder, and trying to detect leaks using Valgrind from the Run button. When I get the report, it suggests adding the extra --leak-check=full option to the command, but I couldn’t find where could I modify the run command or add flags.
Note, that I’m developing this GTK4 app on an Ubuntu LTS with GTK3, so if I just try to run the built executable, it won’t be able to find the GTK4 libraries.

Question:

  1. How can I add the --leak-check=full option to the Valgrind run command in Gnome Builder?
  2. Or how can I run Valgrind from any command line so that it respects the GTK4 runtime of the flatpak binary?

Thank you in advance!

You can run a new build terminal with SHIFT + CTRL + ALT +T then you would be inside the locale flatpak repository that was created for your application. This should allow you to run valgrind yourself

Thank you for your response. When I open the terminal with that hotkey, it opens a terminal in my home folder (~/). I can run valgrind, but there’s no executable binary. Even locate doesn’t tell me where is the executable. Unfortunately I cannot use valgrind without the executable.

If you have build the app with Builder it should be in /app/bin

OK, I’ve found the executable in ~/.var/app/org.gnome.Builder/cache/gnome-builder/projects/fluidapp/builds/de.teamaux.Fluidapp.json-flatpak-org.gnome.Platform-42-x86_64-master/src, but this terminal just doesn’t seem to respect the flatpak dependencies, and complaining on the lack of the gtk4 libraries as any other terminal:

./fluidapp: error while loading shared libraries: libgtk-4.so.1: cannot open shared object file: No such file or directory

Note that the terminal will set $BUILDDIR to the build directory for you. So you can just cd $BUILDDIR after opening the terminal.

Most likely you’re running the binary from the build directory which probably doesn’t have finalized link paths setup yet (I think Meson does that as part of installation).

Builder has a “hidden” feature that lets you install your project (so it will be in /app/bin) which you should run instead of the binary from the build directory. Ctrl+Enter then type install and press Enter again to install the project. You can also go to the build panel (middle panel on the left sidebar) and then expand the Build Details expander, and click on the “install” row.

At that point, you can just do valgrind --leak-check=full --track-origins=yes /app/bin/foobar

Also, I’ve added --leak-check=full to the GTK 4 port, and I’ll see about making it toggle’able from the run menu.

1 Like

Thank you for the hints. In theory that would suffice, and I’d be happy. In reality however install doesn’t install my app in /app/bin, and $BUILDDIR is empty, so cd $BUILDDIR just leads to ~/.
Here’s the output (it looks OK):

flatpak build --env=LANG=hu_HU.UTF-8 --env=USER=vezir --env=HOME=/home/vezir --env=PATH=/usr/bin:/bin --env=TERM=xterm-256color --env=V=0 --env=CCACHE_DIR=/home/vezir/.var/app/org.gnome.Builder/cache/gnome-builder/flatpak-builder/ccache --env=FLATPAK_CONFIG_DIR=/home/vezir/.var/app/org.gnome.Builder/data/gnome-builder/flatpak/etc --env=PATH=/app/bin:/usr/bin --env=G_MESSAGES_DEBUG= --env=XDG_RUNTIME_DIR=/run/user/1000 --build-dir=/home/vezir/.var/app/org.gnome.Builder/cache/gnome-builder/projects/fluidapp/builds/de.teamaux.Fluidapp.json-flatpak-org.gnome.Platform-41-x86_64-master --share=network --nofilesystem=host --filesystem=/home/vezir/.var/app/org.gnome.Builder/cache/gnome-builder --filesystem=/home/vezir/Projects/fluidapp --filesystem=/home/vezir/.var/app/org.gnome.Builder/cache/gnome-builder/projects/fluidapp/builds/de.teamaux.Fluidapp.json-flatpak-org.gnome.Platform-41-x86_64-master --env=NOCONFIGURE=1 /home/vezir/.var/app/org.gnome.Builder/cache/gnome-builder/projects/fluidapp/flatpak/staging/x86_64-master ninja
ninja: no work to do.
flatpak build --env=TERM=xterm-256color --env=V=0 --env=CCACHE_DIR=/home/vezir/.var/app/org.gnome.Builder/cache/gnome-builder/flatpak-builder/ccache --env=FLATPAK_CONFIG_DIR=/home/vezir/.var/app/org.gnome.Builder/data/gnome-builder/flatpak/etc --env=PATH=/app/bin:/usr/bin --env=G_MESSAGES_DEBUG= --env=XDG_RUNTIME_DIR=/run/user/1000 --build-dir=/home/vezir/.var/app/org.gnome.Builder/cache/gnome-builder/projects/fluidapp/builds/de.teamaux.Fluidapp.json-flatpak-org.gnome.Platform-41-x86_64-master --share=network --nofilesystem=host --filesystem=/home/vezir/.var/app/org.gnome.Builder/cache/gnome-builder --filesystem=/home/vezir/Projects/fluidapp --filesystem=/home/vezir/.var/app/org.gnome.Builder/cache/gnome-builder/projects/fluidapp/builds/de.teamaux.Fluidapp.json-flatpak-org.gnome.Platform-41-x86_64-master --env=NOCONFIGURE=1 /home/vezir/.var/app/org.gnome.Builder/cache/gnome-builder/projects/fluidapp/flatpak/staging/x86_64-master ninja install
[0/1] Installing files.
Installing data/de.teamaux.Fluidapp.desktop to /app/share/applications
Installing data/de.teamaux.Fluidapp.appdata.xml to /app/share/appdata
Installing src/fluidapp to /app/bin
Installing /home/vezir/Projects/fluidapp/data/de.teamaux.Fluidapp.gschema.xml to /app/share/glib-2.0/schemas
Installing /home/vezir/Projects/fluidapp/data/icons/hicolor/scalable/apps/de.teamaux.Fluidapp.svg to /app/share/icons/hicolor/scalable/apps
Installing /home/vezir/Projects/fluidapp/data/icons/hicolor/symbolic/apps/de.teamaux.Fluidapp-symbolic.svg to /app/share/icons/hicolor/symbolic/apps
Running custom install script '/usr/bin/meson --internal gettext install --subdir=po --localedir=share/locale --pkgname=fluidapp'
Running custom install script '/home/vezir/Projects/fluidapp/build-aux/meson/postinstall.py'

FYI, I’ve finally found a way to run Valgrind with arbitrary options on the executable within the runtime. Here’s the trick:

  1. Run Gnome builder with Flatpak from the command line: flatpak run --runtime=org.gnome.Sdk org.gnome.Builder
  2. In another terminal window use the command flatpak ps to get the instance id for the builder
  3. Finally run Valgrind using flatpak: flatpak enter <INSTANCE_ID> valgrind [VALGRIND_OPTIONS] <EXECUTABLE>

Example: flatpak enter 4198261558 valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all --log-file="/home/vezir/Projects/fluidapp/valgrind.log" /home/vezir/.var/app/org.gnome.Builder/cache/gnome-builder/projects/fluidapp/builds/de.teamaux.Fluidapp.json-flatpak-org.gnome.Platform-42-x86_64-master/src/fluidapp

I made it a bit easier for you when the GTK 4 version of Builder lands.

1 Like

Awesome! Thank you. :grin:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.