Koozali SME Server Debugging

From SME Server
Jump to navigationJump to search

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.

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

Remotely using an IDE

I have been using Komodoedit IDE courtesy of an Open Source Developers licence from Activestate

The simplest mode to use with Komodo is to just use the IDE as a debugger to step through code without actually editing in the IDE.

http://docs.komodoide.com/Manual/debugperl


Server setup

Single machine setup

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 root@some.server://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

Note: As with local debugging, the Break Now function is disabled by default and enabled with async - see the docs for more information

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)

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

Then do

perl myFile.pl

Add -d to /sbin/e-smith/signal-event

Then do

signal-event some-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/

Or

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=

Multiple machine debug proxy

TBA