Back in the days of VMS on VAX, a standard trick for software developers was to use the PATCH
command to turn off the debug bit in an image file that had been compiled and linked with the /DEBUG
qualifier. In this way, the image could be deployed into production with full debugging symbol tables available, allowing the developers to flip one bit to obtain full debug support if required for troubleshooting.
A more elegant way to achieve the same functionality today is to directly invoke the debugger from your image.
By using the little known /DSF
qualifier on the LINK
command, you can generate an external "Debug Symbol File" which can be then used with a call to the debugger to achieve similar functionality to the VAX hack.
The following code demonstrates the procedure:
$ create demo.c
$ deck
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ssdef.h>
#include <lib$routines.h>
int main (void) {
static time_t t;
t = time (NULL);
(void)printf ("Invoking the debugger at %u...\n", t);
(void)lib$signal (SS$_DEBUG);
(void)printf ("t = %u\n", t);
}
$ eod
$ cc/debug demo ! Optionally, /noopt can be used
$ link/dsf demo
$ run demo
When the machine encounters the call to lib$signal()
, the debugger is dynamically invoked, and you will find yourself at the usual DBG>
prompt. From here, you can perform all the usual debugging commands; for example, EXAMINE T
.
Note that the .DSF
file must reside in the same directory as the image. Additionally, you should leave the debugger with the GO
command rather than EXIT
. This allows the rest of the program to complete normally.
In a production image, the call to invoke the debugger could be conditional on an executive mode group logical name, allowing the systems administrator to enable debugging for an appropriate group of testers or developers.
Posted at October 15, 2007 11:35 AMComments are closed