gdbguix

How can I debug a C program installed using guix?


I installed flatpak using guix, but it segfaulted on startup. I wanted to debug it, but guix installs a wrapper script for flatpak, so I get this error when trying to run it under gdb:

"/home/user/.guix-profile/bin/flatpak": not in executable format: file format not recognized

and I tried to edit the wrapper script to call gdb, but this wrapper script is not even editable by root, because it is owned by root and has read-only permissions.


Solution

  • Simply copy the script to your current working directory:

    cp /home/user/.guix-profile/bin/flatpak .
    

    Mark it as writable:

    chmod +w flatpak
    

    Edit the script with your favourite text editor, to replace the string exec -a with exec gdb --args.

    And finally, run it with any arguments you provided before, when it misbehaved:

    ./flatpak remote-add flathub https://flathub.org/repo/flathub.flatpakrepo
    

    In this particular case, this wasn't immediately super-useful, because a debug symbol output hasn't been built for this package. But at least I could get a backtrace out of gdb.