16-Oct-2007

Debugging tricks, part 2

In Part 1, we saw that the OpenVMS debugger could be invoked dynamically via a call to lib$signal. This is rather cool, but even better is that you can pass commands directly to the debugger.

If you have ever had an end user call you up to report an error, and after you've asked them to read you the message and traceback they say Oh, I don't have it on the screen any more, then this trick is for you.

The trick is especially useful in condition handlers to combat that particular scenario. The condition handler can output the unexpected error's characteristics to a file, which can then be reviewed by the software developers.

The following code demonstrates this functionality.


#include <stdio.h>
#include <stdlib.h>
#include <ssdef.h>
#include <stsdef.h>
#include <string.h>
#include <lib$routines.h>


static int handler (void) {

char command_string[] = "Xset log err.txt;set output log,noterm;" \
                        "show calls;go;exit";

    (void)printf ("In the condition handler\n");
    /*
    ** command_string needs to be a "counted ascii string".
    ** This is a single byte specifying the string length
    ** followed by the string.  In the initializer above, we
    ** have just stuck a dummy value in the first
    ** byte.  Replace it with the length of the string.
    */
    command_string[0] = (char)strlen (command_string) - 1;

    (void)lib$signal (SS$_DEBUG,
                      1,
                      command_string);

    (void)printf ("Now back in the condition handler\n");

    /*
    ** Handle the ACCVIO.
    */
    return SS$_CONTINUE;
}


int main (void) {

    /*
    ** Establish a condition handler.
    */
    (void)lib$establish (&handler);

    /*
    ** Simulate an access violation...
    */
    (void)lib$signal (SS$_ACCVIO);

    (void)printf ("After the error\n");
}

Posted at October 16, 2007 2:27 PM
Tag Set:

Comments are closed