Xfce Wiki

Sub domains
 

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
howto:panel_plugin_debug [2007/12/09 20:28] – reformat a bit (useless I know, I'm borred) 88.172.125.130howto:panel_plugin_debug [2009/01/26 13:54] 88.172.125.130
Line 1: Line 1:
 ====== Panel Plugin Debugging ====== ====== Panel Plugin Debugging ======
 +Debugging **external** panel plugins is possible by wrapping the executable against a shell script that runs a debug tool.
  
-An easy way to debug an external panel-plugin with Valgrind :+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''.
  
-  * In /usr/local/libexec/xfce4/panel-plugins/ (or where your plugins are installed) rename the panel binary named foo-plugin to foo-plugin.real +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. 
-  * Create an executable shellscript named foo-plugin in the same place, containing :+ 
 +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''"
 + 
 +===== Debug with Valgrind (full example) ===== 
 + 
 +  * Make a copy of the desktop entry file 
 + 
 +  cp /usr/local/share/xfce4/panel-plugins/clipman.desktop \ 
 +  /usr/local/share/xfce4/panel-plugins/clipman-valgrind.desktop 
 + 
 +  * Edit the new file and change the Name= key to differentiate it from the original plugin, for instance append the name of the debug tool like "Clipman (valgrind)" 
 +  * Change the Exec= key to point it to the shell script (remember the original pathyou need it for the shell script) 
 +  * Create an **executable** shell script containing:
  
   #!/bin/sh   #!/bin/sh
-  valgrind --log-file=/path/to/valgrind.output /path/to/panel-plugins/foo-plugin.real $@+  valgrind --log-file=$HOME/clipman-valgrind.log \ 
 +  /usr/local/libexec/xfce4/panel-plugins/clipman $@ 
 + 
 +  * Now you can add the plugin "Clipman (valgrind)" to the panel as usual 
 +  * You are able to use <code>tail -f $HOME/clipman-valgrind.log</code> 
 + 
 +{{wiki:information.png}} It'll be really slow as wrapped in valgrind, but you'll be able to hunt memory leaks. 
 + 
 +=== More useful call to Valgrind === 
 + 
 +  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 $@ 
 + 
 +===== Debug with GDB (short example) ===== 
 +If you didn't read the example about Valgrind, do so, it contains mandatory information if you don't understand the following example. 
 + 
 +  * Make a copy of the desktop entry file 
 + 
 +  cp /usr/local/share/xfce4/panel-plugins/clipman.desktop \ 
 +  /usr/local/share/xfce4/panel-plugins/clipman-gdb.desktop 
 + 
 +  * Change the Exec= key to point it to the shell script (remember the original path, you need it for the shell script) 
 +  * Create an **executable** shell script containing: 
 + 
 +  #!/bin/sh 
 +  gdb -ex r -ex bt -ex continue -ex q --args /usr/local/libexec/xfce4/panel-plugins/clipman $@ 
 +  > $HOME/clipman-gdb.log 2>&
 + 
 +=== Using GDB on running instances ===
  
-  * Add the plugin to the panel as usual +If you want an interactive debug session with GDB, you can simply find the process id of the plugin by running
-Note. It'll be really slow as wrapped in valgrindbut you'll be able to hunt memory leaks using tail -f /path/to/valgrind.output +
  
 +  $ gdb /usr/local/libexec/xfce4/panel-plugins/clipman $(pidof clipman)
 +  ...
 +  (gdb) continue
  
-===== Alternative way ===== +which will find the PID of clipman, and debug it using the debug symbols in /usr/local/libexec/xfce4/panel-plugins/clipmanFor this to workclipman must already be runningYou can also attach GDB to a process from the GDB prompt by using the attach command:
-Edit your .desktop file of the plugin (for most easy resultsdirectly in the source directory) and append .valgrind to the xfce-exec lineThen create a file like described abovebut named xfce4-my-plugin.valgrind in the same location. It will never ever be overwritten by any of your subsequent installations, and your .desktop file won't destroy anything as well. Ah, make the .valgrind script executable as well.+
  
-Pay attention to edit the xfce-exec line before checking into subversion or making a release.+  (gdb) attach $PID
  
-===== More senseful call to Valgrind =====+Again, the plugin must already be loaded for this to work.
  
-''%%valgrind --tool=memcheck --leak-check=full --show-reachable=yes -v --log-file=/home/user/valgrind.txt /usr/local/libexec/xfce4/panel-plugins/xfce4-sensors-plugin $@%%''+====== Some tips ====== 
 +  * By creating your own desktop entry file, it will never get overwritten by any installation, and the file doesn't cause any problem. 
 +  * You can point the Execkey to your development directory, for instance /home/john/clipman/panel-plugin/xfce4-clipman-plugin-gdb, and write the shell script xfce4-clipman-plugin-gdb that points to the binary inside your development directory aswell.  This avoids you to install the binary every time, all you will need is to restart the panel (''xfce4-panel -r'') after you compile your plugin :-P