The latest edge snapd build contains a new way to debug snaps. Unlike the current “snap run --gdb” this new option runs the application as the regular user and also allows attaching gdb frontends that can talk to gdbserver. It still requires sudo
once for the attaching of gdbserver.
To debug a program you can use:
$ snap run --experimental-gdbserver test-snapd-tools-core18.echo "hello gdb"
Welcome to "snap run --gdbserver".
You are right before your application is run.
Please open a different terminal and run:
gdb -ex="target remote :38881" -ex=continue -ex="signal SIGCONT"
(gdb) continue
or use your favorite gdb frontend and connect to :38881
and on a different terminal:
$ gdb -ex="target remote :38881" -ex=continue -ex="signal SIGCONT"
GNU gdb (Ubuntu 9.1-0ubuntu1) 9.1
...
Reading target:/usr/lib/debug/lib/x86_64-linux-gnu//libc-2.27.so from remote target...
(No debugging symbols found in target:/lib/x86_64-linux-gnu/libc.so.6)
Reading symbols from target:/lib64/ld-linux-x86-64.so.2...
Reading /lib64/ld-2.27.so from remote target...
Reading /lib64/.debug/ld-2.27.so from remote target...
Reading /usr/lib/debug//lib64/ld-2.27.so from remote target...
Reading /usr/lib/debug/lib64//ld-2.27.so from remote target...
Reading target:/usr/lib/debug/lib64//ld-2.27.so from remote target...
(No debugging symbols found in target:/lib64/ld-linux-x86-64.so.2)
Reading /lib64/ld-linux-x86-64.so.2 from remote target...
0x00007f58caef5e75 in raise () from target:/lib/x86_64-linux-gnu/libc.so.6
Continuing.
--Type <RET> for more, q to quit, c to continue without paging--
Program received signal SIGSTOP, Stopped (signal).
0x00007f58caef5e75 in raise () from target:/lib/x86_64-linux-gnu/libc.so.6
Continuing with signal SIGCONT.
Program received signal SIGCONT, Continued.
0x00007f58caef5e97 in raise () from target:/lib/x86_64-linux-gnu/libc.so.6
(gdb)
At this points it’s right before the exec() of the program. Using “cont” will run the program normally.