PL/I Debugging in JCL and IMS

PL/I programs containing EXEC SQL, EXEC CICS, or EXEC DLI statements can use the preprocessor -optexec option with the plitest parameter. This causes the preprocessor to inject a PL/I macro into the code. The macro invokes the debugger through an infused PLITEST() call. This is done automatically and does not require editing a side file such as PLIDEBUG.DAT. It also does not require knowledge of explicit CodeWatch commands.

However, this debugging method cannot be used for batch programs that do not have EXEC language capability, or for IMS-based programs that use PLITDLI instead of EXEC DLI.

For these types of programs, you can use a technique similar to that used by the EXEC preprocessor, but in the PL/I Macro preprocessor, to automatically generate a PLITEST() call.

  1. Put the following code anywhere within the execution path of the program to be debugged:
    %if ATTACHDEBUGGER %then
    %do;
        DCL JAVAUI FIXED BIN(31) NATIVE VALUE(1); 
        CALL PLITEST("shlib " || procedurename() || ".dll;" || 
                     "env "   || procedurename() || ";br STARTDEBUG;" ||
                     "br %exit [det;q];c", 
                     " ", JAVAUI);
        STARTDEBUG:;
    %end;
    

    This code causes a debugger to automatically attach itself during program execution, and stop on the STARTDEBUG label.

    Note: The above code assumes a Windows environment with the assumption that a .DLL is being used. If working in a UNIX environment, just replace .dll with .so. It uses the PL/I built-in function PROCEDURENAME() to dynamically determine the environment and the shlib argument.
  2. If compiling the program from the command line, add the following options to the mfplx command (or just the -define option if invoking mfpp explicitly):
    –deb -macro -define attachdebugger
  3. Start the Enterprise Server and execute the program.
    Note: If working in a Windows environment, the Enterprise Server must be started from an Enterprise Developer command prompt using casstart, or the debugger won't be attached.

In the code sample, the %if..%do condition is functionally similar to $IF in COBOL or #ifdef in C. The sample as a whole is a functional equivalent to CBL_DEBUGBREAK, with the added capability of being ably to specify any additional CodeWatch commands, such as setting breakpoints, to be executed upon startup.