Koozali SME Server Debugging
One issue that is often found to be problematic by new developers is debugging perl code on your SME server.
There are several ways to do this, both locally and remotely.
Enable template debugging
I happened to stumble over this in the templates.pm file
config set processtemplate Debug yes
This will add some debugging lines to /var/log/messages showing you the progress of the template expansion.
To disable either set the key to no or delete it.
Builtin Db routines
You can also use a couple of routines from db.pm
=item B<db_print> db_print(\%config); db_print(\%config, $key); Prints out keys and raw values in the %config database. If $key is given it prints the $key and its raw value. If no $key is given it prints out all the keys and their raw values.
=item B<db_show> db_show(\%config); db_show(\%config, $key); Prints out keys and their values in a human readable format. If $key is given it prints out the $key, type and properties of that $key. Otherwise it prints out the key, type and properties for all keys.
=item B<db_print_type> db_print_type(\%config); db_print_type(\%config, $key); Prints out keys and their types in the %config database. If $key is given, it prints out just that $key and its type. Otherwise it prints out all the keys and their types.
=item B<db_print_prop> db_print_prop(\%config, $key); db_print_prop(\%config, $key, $property); Prints out the properties (or a single $property) of the given $key in the %config.
Locally using perl -d
There are a number of tutorials online.
To start you use:
perl -d myFile.pl
There are then a number of options you can use to control the debugger:
l 10 - list line 10 l get_pattern - find lines matching 'pattern' b 22 - set breakpoint at line 22 s - step forward a line including all subroutines n - step forward a line but jump through subroutines c - continue to next break point c 47 - continue to line 47 p $variable - print variable q - quit
Remote debugging using an IDE
I have been using Komodo IDE courtesy of an Open Source Developers licence from Activestate
They produce an Open Source 'light' version of the full IDE called Komodo Edit but it does not have the debug facilities.
The simplest mode to use with Komodo IDE is to just use the IDE as a debugger to step through code. Code on the remote server can be edited if you have sufficient permissions.
This will enable us to work with one desktop and one server. See the section on debug proxy for multiple connections
From your installed Komodo directory we need to copy a set of files to the server.
I actually copied the entire dbgp directory as there are other files in there that are useful including the debug proxy.
scp -r ~/komdoeditDirectory/lib/support/dbgp email@example.com://opt/
We should now have /opt/dbgp on the server
We now need to set some paths on the server:
export PERL5LIB=/opt/dbgp/perllib:$PERL5LIB export PERLDB_OPTS=RemotePort=your.desktop.i.p:9020 async=1
If required you can also add a user identifier:
Note: As with local debugging, the Break Now function is disabled by default. Setting async=1 breaks at the first line - see the docs for more information
Single machine setup
On your desktop we need to set up the Listener for Komodo.
Edit/Preferences/Debugger/Connection Set a specific port to 9020 (match the port above) Set a user name as above
Now we need to start a program on the server. The debug code will then call Komodo.
The following forms should work
perl -d myFile.pl
Add -d to the header of your file e.g.
#!/usr/bin/perl -w -d
Add -d to /sbin/e-smith/signal-event
You should get a popup from Komodo stating that a remote application has requested a debugger session. When you click yes you will get a second box stating that a mapping could not be opened. If we are just going to use Komodo as a debugger then we can answer no and you are then in debug mode allowing you to step through the code and view variables.
Mapping for editing
Should you wish to actually edit code as well you will need to set up some form of file mapping between the URI that the debugger sends and your 'Server' setup in Komodo
Note that without some of the esmith libraries installed locally you will get some warnings about being unable to locate certain files but these can safely be ignored.
In Komodo preferences you need to setup a Server/Remote Account for the remote server. e.g.
Remote Account : Test_v9 Type: SCP Port: 2222 Username: root Pass: somepass (or alternatively use SSH keys)
You can then set up a mapping similar to this:
URI : file://v9-test/ Maps To : scp://Test_v9/
URI : file://v9-test/etc/e-smith Maps To : scp://Test_v9/etc/e-smith
You could be more specific about the directories should you require. Remember that you inherit the server permissions - you cannot save a file that is Read Only on the server !
Local file mapping
Although I have not tried this I believe that you can potentially map from the server to your local files. You can then edit locally, upload and re test.
Tidying up afterwards
Either reboot the server or use the following:
export PERL5LIB=/usr/local/lib64/perl5:/usr/local/share/perl5:/usr/lib64/perl5/vendor_perl:/usr/share/perl5/vendor_perl export PERLDB_OPTS= export DBGP_IDEKEY=jdoe
Perl CGI Debugging
Please see here for further details:
You would need a custom httpd.conf fragment. I used 46PerlDebug with these options (configure to suit)
SetEnv PERL5LIB "/opt/dbgp/perllib:$PERL5LIB" SetEnv PERLDB_OPTS "RemotePort=192.168.x.x async=1" SetEnv DBGP_IDEKEY "user"
You should now be able access your cgi-script and debug accordingly.
However, having tried it you cannot use this on server-manager panels because perl is setuid.
It could be used in other scenarios, but not server-manager.
Multiple machine debug proxy