McIDAS Programmer's Manual
Version 2015

[Search Manual] [Table of Contents] [Go to Previous] [Go to Next]

Debugging servers

Because ADDE servers read from stdin and write to stdout, you can't call the sdest or Mcprintf function to trace the progress of a server for two reasons:

The solution is to dump messages needed for tracing errors to a file. If errors are reported and tracing is activated, the function M0sxtrce or m0sxtrce will write trace messages to a file named trce. If tracing is not activated, M0sxtrce or m0sxtrce does nothing.

The keyword TRACE is appended to each client request. If TRACE=0, which is the default, tracing is not performed. If TRACE=nonzero value, tracing is activated. The function M0IsTraceSet or m0istraceset automatically activates tracing on the server if the value for TRACE in the client request string is a nonzero number. If you write secondary servers, a call to M0IsTraceSet is made within the function M0InitLocalServer. To activate tracing within a server on your own, call M0sxSetTraceOn or m0sxsettraceon. To turn it off, call M0sxSetTraceOff or m0sxsettraceoff.

Since each account has only one trace file, prefix each line of your tracing strings with the name of the server generating that string. When you look through the contents of the trace file, you can easily find the trace information generated by the problem server.

You can also use the Mctrace or mctrace function to automatically append the server name to the trace message and set a flag for each message. The flag restricts tracing to only selected values of the keyword TRACE.

The sample code fragment below is from the server TOMGSERV.

const char    Server[] = {"TOMGSERV"};
char         *request;
servacct      request_block;
char          trace_string[500];
short         init_stat;

initblok_ (&init_stat);

/* get the client request and set tracing */

ok = M0sxGetClientRequest (&request_block, &request);
ok = M0IsTraceSet (request); 

/* print a trace message containing the entire user request */

sprintf (trace_string, "%s: %s", Server, request);
M0sxtrce (trace_string)

/* continue processing */

If the user enters the following client request:


Upon completion, the file trace will contain this line:


[Search Manual] [Table of Contents] [Go to Previous] [Go to Next]