Debugging external panel plugins is possible by wrapping the executable against a shell script that runs a debug tool.
The exec command is available inside the desktop entry file that is shipped with every panel plugin. They are installed inside the directory ”$prefix/share/xfce4/panel-plugins”. If the desktop entry file contains a key X-XFCE-Module instead of X-XFCE-Exec than it means it is an internal panel plugin. Internal panel plugins can be debugged by running the tools directly on xfce4-panel.
So, this lets you quite some possibilities to wrap an external panel plugin. You can create a new desktop entry file just for the purpose of running it with a debug tool, you can change the desktop entry file directly to point it to the shell script, or you can rename the panel plugin binary and write a shell script as the original file.
In the examples below we will use the first method that consists into creating a new desktop entry file. We will use as example a plugin called ”clipman” that is installed inside the prefix ”/usr/local”.
cp /usr/local/share/xfce4/panel-plugins/clipman.desktop \ /usr/local/share/xfce4/panel-plugins/clipman-valgrind.desktop
#!/bin/sh valgrind --log-file=$HOME/clipman-valgrind.log \ /usr/local/libexec/xfce4/panel-plugins/clipman $@
tail -f $HOME/clipman-valgrind.log
It'll be really slow as wrapped in valgrind, but you'll be able to hunt memory leaks.
G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind --tool=memcheck --leak-check=full \ --show-reachable=yes -v --log-file=$HOME/valgrind.log \ /usr/local/libexec/xfce4/panel-plugins/xfce4-sensors-plugin $@
If you didn't read the example about Valgrind, do so, it contains mandatory information if you don't understand the following example.
cp /usr/local/share/xfce4/panel-plugins/clipman.desktop \ /usr/local/share/xfce4/panel-plugins/clipman-gdb.desktop
#!/bin/sh gdb -ex r -ex bt -ex continue -ex q --args /usr/local/libexec/xfce4/panel-plugins/clipman $@ \ > $HOME/clipman-gdb.log 2>&1
If you want an interactive debug session with GDB, you can simply find the process id of the plugin by running
$ gdb /usr/local/libexec/xfce4/panel-plugins/clipman $(pidof clipman) ... (gdb) continue
which will find the PID of clipman, and debug it using the debug symbols in /usr/local/libexec/xfce4/panel-plugins/clipman. For this to work, clipman must already be running. You can also attach GDB to a process from the GDB prompt by using the attach command:
(gdb) attach $PID
Again, the plugin must already be loaded for this to work.
$ xfce4-panel -x
$ xfce4-panel > file 2>&1 & disown
$ xfce4-panel -x $ xfce4-panel & disown
xfce4-panel -r) after you compile your plugin