flatpak-vscode icon indicating copy to clipboard operation
flatpak-vscode copied to clipboard

Guide: Debug with gdb

Open Hofer-Julian opened this issue 2 years ago • 1 comments

  1. Install Native Debug

  2. Allow breakpoints everywhere (maybe native debug doesn't include .rs files? Let's open an issue there)

{
    "debug.allowBreakpointsEverywhere": true
}

  1. Create the file gdb.sh with content similar to this (we could create that automatically) (Note: "Everything before gdb "$@" should be the same command as when you run the flatpak minus the executable name (which is in this case "shortwave))
#!/bin/sh

flatpak-spawn --host flatpak build --with-appdir --allow=devel --bind-mount=/run/user/1000/doc=/run/user/1000/doc/by-app/de.haeckerfelix.Shortwave.Devel --share=network --share=ipc --socket=fallback-x11 --socket=wayland --device=dri --socket=pulseaudio --filesystem=xdg-music --env=RUST_LOG=shortwave=debug --env=RUST_BACKTRACE=1 --talk-name='org.freedesktop.portal.*' --talk-name=org.a11y.Bus --env=DESKTOP_SESSION=gnome --env=XDG_SESSION_DESKTOP=gnome --env=XDG_SESSION_TYPE=wayland --env=LANG=de_AT.UTF-8 --env=XDG_CURRENT_DESKTOP=GNOME --env=WAYLAND_DISPLAY=wayland-0 --env=AT_SPI_BUS_ADDRESS=unix:path=/run/user/1000/at-spi-bus /var/home/julian/Projekte/gnome/applications/Shortwave/.flatpak/repo gdb "$@"
  1. Make gdb.sh executable
chmod +x gdb.sh
  1. Create a file .vscode/launch.json with similar content (Replace the executable name with yours. We should also auto generate that)
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug",
            "type": "gdb",
            "request": "launch",
            "gdbpath": "./gdb.sh",
            "target": ".flatpak/repo/files/bin/shortwave",
            "arguments": "launch.json",
            "cwd": "${workspaceRoot}",
            "valuesFormatting": "parseText"
        },        
    ]
}

Hofer-Julian avatar Jul 25 '21 12:07 Hofer-Julian

Bonus: Automatically build the application first.

adapt launch.json to include preLaunchTask

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug",
            "type": "gdb",
            "request": "launch",
            "preLaunchTask": "flatpak: build",
            "gdbpath": "./gdb.sh",
            "target": ".flatpak/repo/files/bin/shortwave",
            "arguments": "",
            "cwd": "${workspaceRoot}",
            "valuesFormatting": "parseText"
        },        
    ]
}

add to your tasks.json file

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "command": "flatpak-spawn --host flatpak build --share=network --nofilesystem=host --filesystem=/home/haecker-felix/Dokumente/Projekte/Shortwave --filesystem=/home/haecker-felix/Dokumente/Projekte/Shortwave/.flatpak/repo --env=PATH=$PATH:/usr/lib/sdk/rust-stable/bin --filesystem=/home/haecker-felix/Dokumente/Projekte/Shortwave/_build /home/haecker-felix/Dokumente/Projekte/Shortwave/.flatpak/repo meson install -C _build",
            "label": "flatpak: build",
            "group": "build"
        }
    ]
}

haecker-felix avatar Jul 25 '21 13:07 haecker-felix