How can I attach a debugger to an NSAPI application?

NSAPI applications are run in separate processes on your Zeus WebServer, one process per virtual server.

  • Compile your NSAPI module (the .so or .sl library) with -g to include debugging information.
  • Start the virtual server that uses the module.
  • Determine the pid of the zeus.nsapi process that manages that virtual server:

       bash$ ps -ef | grep zeus.nsapi      root 24711 24709 0 14:05:13 ? 0:01 zeus.nsapi test-1      root 24712 24709 0 14:05:13 ? 0:01 zeus.nsapi test-2

    In this instance, process 24711 runs NSAPI applications on behalf of virtual server 'test-1' whilst process 24712 acts in the same way for virtual server 'test-2'.

  • Start your debugger and attach it to the process. Set a breakpoint for the function you want to trace (e.g. my_func).

       bash$ gdb $ZEUSHOME/web/bin/zeus.nsapi   (gdb) attach 24711   (gdb) break my_func   (gdb) cont

When you next request a web page that uses this function, the debuggerwill break in this function. You can step through the function,examining local variables and so on.

If you want to break in a function that is called at Init,you need to be a bit more clever because the function is called justafter the new zeus.nsapi process is fork'ed andexec'ed. Most debuggers cannot follow forks.

You can use a dummy Init function that blocks for long enoughfor you to attach a debugger to the new process. pause() andsleep() are good candidates.

/* sleep.c * Use as follows: *   Init fn="load-modules" funcs="mysleep" shlib="sleep.so" *   Init fn="mysleep" secs="20" */#include <unistd.h>  /* for sleep() */#include <stdlib.h>  /* for atoi()  */char *pblock_findval( const char*, const void* );int mysleep( void *args, void *sn, void *rq ){   const char *secs = pblock_findval( "secs", args );   if( secs ) sleep( atoi( secs ) );   return 0;}

Compile this up to a .so file, for example:

Using gcc:

gcc -g -c -fPIC sleep.c
gcc -shared -o sleep.so sleep.o
Using HP cc:
cc -Ae -g -c +z sleep.c
ld -b -o sleep.so sleep.o

Put the following in your obj.conf, before any otherInit directives:

   Init fn="load-modules" funcs="mysleep" shlib="sleep.so"   Init fn="mysleep" secs="20"

(shlib should include the full path to the sleep.so library)

Then when you start your virtual server, you have 20 seconds to figure out the process id and attach a debugger to it!

Content Manager [Administrator] 19 September 2005  Permalink  
Download Free Trial

Recent Articles

Other Resources



www.zeus.com