Compile GLib with Debug Symbols

I’m trying to develop a program in C, that relies on some functions in the libsecret Libary.
This Library in turn relies on GLib.

I have some Memory Leaks in my Program that Valgrind detects. However Valgrind doesnt tell me much about where those arise. The Output Looks like

==10387== Memcheck, a memory error detector
==10387== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==10387== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==10387== Command: ./main
==10387== 
Error creating new Collection: No such secret collection at path: /==10387== 
==10387== HEAP SUMMARY:
==10387==     in use at exit: 140,633 bytes in 1,675 blocks
==10387==   total heap usage: 9,946 allocs, 8,271 frees, 461,654 bytes allocated
==10387== 
==10387== 8 bytes in 1 blocks are definitely lost in loss record 68 of 1,370
==10387==    at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==10387==    by 0x49ABC50: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7200.4)
==10387==    by 0x4DCD351: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387==    by 0x4DCD84B: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387==    by 0x4D2CFD9: g_initable_new_valist (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387==    by 0x4D2D08C: g_initable_new (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387==    by 0x48B6EA4: _secret_prompt_instance (secret-prompt.c:96)
==10387==    by 0x48C3DB6: on_create_collection_called (secret-paths.c:1683)
==10387==    by 0x4D63E38: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387==    by 0x4D6405A: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387==    by 0x4DC573E: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387==    by 0x4D63E38: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387== 
==10387== 8 bytes in 1 blocks are definitely lost in loss record 69 of 1,370
==10387==    at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==10387==    by 0x49ABC50: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7200.4)
==10387==    by 0x4DCD449: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387==    by 0x4DCD84B: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387==    by 0x4D2CFD9: g_initable_new_valist (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387==    by 0x4D2D08C: g_initable_new (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387==    by 0x48B6EA4: _secret_prompt_instance (secret-prompt.c:96)
==10387==    by 0x48C3DB6: on_create_collection_called (secret-paths.c:1683)
==10387==    by 0x4D63E38: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387==    by 0x4D6405A: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387==    by 0x4DC573E: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387==    by 0x4D63E38: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.4)
==10387== 
==10387== LEAK SUMMARY:
==10387==    definitely lost: 16 bytes in 2 blocks
==10387==    indirectly lost: 0 bytes in 0 blocks
==10387==      possibly lost: 576 bytes in 2 blocks
==10387==    still reachable: 123,593 bytes in 1,520 blocks
==10387==         suppressed: 0 bytes in 0 blocks
==10387== Reachable blocks (those to which a pointer was found) are not shown.
==10387== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==10387== 
==10387== For lists of detected and suppressed errors, rerun with: -s
==10387== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)

As you can see there are many instances where there is just “???” shown instead of a function.
A libsecret Developer told me to please first include “debug symbols” so that they can help me efficiently.

For Libsecret I installed the Debug Symbols which I can know find

$ dpkg -l | grep -i debug
ii  cinnamon-control-center-dbg                                 6.0.1+virginia                              amd64        utilities to configure the Cinnamon desktop - debug symbols
ii  gdb                                                         12.1-0ubuntu1~22.04.2                       amd64        GNU Debugger
ii  gdbserver                                                   12.1-0ubuntu1~22.04.2                       amd64        GNU Debugger (remote server)
ii  libc6-dbg:amd64                                             2.35-0ubuntu3.8                             amd64        GNU C Library: detached debugging symbols
ii  libcinnamon-desktop-dbg:amd64                               6.0.0+virginia                              amd64        Cinnamon shared utility library - debugging symbols
ii  libcvc-dbg:amd64                                            6.0.0+virginia                              amd64        Cinnamon pulseaudio abstraction library - debug symbols
ii  libdebuginfod-common                                        0.186-1build1                               all          configuration to enable the Debian debug info server
ii  libdebuginfod1:amd64                                        0.186-1build1                               amd64        library to interact with debuginfod (development files)
ii  libdw1:amd64                                                0.186-1build1                               amd64        library that provides access to the DWARF debug information
ii  libdw1:i386                                                 0.186-1build1                               i386         library that provides access to the DWARF debug information
ii  libsecret-1-0-dbgsym:amd64                                  0.20.5-2                                    amd64        debug symbols for libsecret-1-0
ii  muffin-dbg                                                  6.0.1+virginia                              amd64        window and compositing manager (debugging symbols)
ii  nemo-dbg                                                    6.0.2+virginia                              amd64        file manager and graphical shell for Cinnamon - debugging version
ii  node-debug                                                  4.3.2+~cs4.1.7-1                            all          small debugging utility for Node.js
ii  pix-dbg                                                     3.2.2+virginia                              amd64        image viewer and browser - debugging symbols
ii  ubuntu-dbgsym-keyring                                       2021.03.26                                  all          GnuPG keys of the Ubuntu Debug Symbols Archive
ii  xed-dbg                                                     3.4.5+virginia                              amd64        Text editor (debugging symbols)
ii  xreader-dbg                                                 4.0.2+virginia                              amd64        Document viewer (debugging symbols)
ii  xviewer-dbg                                                 3.4.4+virginia                              amd64        Image viewer - debugging symbols

So those are definitely there.

I searched on how to get those for GLib and came to the conclusion, that I have to compile GLib by myself with Debug options.
So I installed GLib using

meson setup --buildtype=debug ..
ninja
sudo ninja install

and Also later tried
meson setup build --buildtype=debug -Ddebug=true -Db_sanitize=address,undefined

But those seem to didn’t work? As you can see in the Valgrind output there are still things missing & I cant find any symbol files for GLib.

My program is compiled with the -g -O0 flags so, as far as I know there should be all possible Debug Information.

For additional Information, like the Code here is the Issue at the Libsecret Repository.

If I forgto some for you crucial Information feel free to ask, it has been hours over multiple days, I tried many different things which would be far too much to all list here.

I’m new to Valgrind & may misinterpret the Output.

For Ubuntu and Debian (since you are using dpkg), the debug packages (-dbg or -dbgsym suffix) are usually in a separate repository that you have to add. On Debian, there is a wiki page section on what repository you need to add, and for Ubuntu there is a corresponding forum site. It seems the debug package is called libglib2.0-0-dbgsym for both distributions.

Thank you so much, this did the trick.
I searched everywhere and I was in the Ubuntu Wiki and there it said to try -dbgsym or -dbg
Because in /usr/share GLib is called glib-2-0-0 I tried glib-2-0-0-dbgysm (to which no package was found), but this seems to have been the wrong name.
How would I have obtained the correct Name of the Library?

AFAICT valgrind can use debuginfod servers to automagically download the debug information for a shared library (based on its buildid). It will invoke the debuginfod-find program if it’s installed (and configured) on your machine. On Debian, this program is in the debuginfod package and the configuration is in package libdebuginfod-common.