Giovanni's logo
CGI debugging tips
this means Version 2
blue line


What to do when the time comes to debug a CGI program

That time will come soon, just after starting.

Error 500

CGI Program failed

Error 501

Bad script request
Script '/QSYS.LIB/.../....pgm'
     not found or not executable
are waiting for you.
So, better be prepared.

Before start debugging, make sure that user profiles
   QTMHHTTP and QTMHHTP1
are enabled.

1- Setup

HTTP server jobs do not bump out, they record CGI programs failures in their joblogs.
So, first of all, they must have a readable joblog
  1. before OS/400 release V4r3m0
      chgjobd qtcp/qtmhhttp log(4 00 *seclvl) + inqmsgrpy(*dft)
    from OS/400 release V4r3m0 on
      chgjobd qhttpsvr/qzhbhttp log(4 00 *seclvl) + inqmsgrpy(*dft)
  2.   endtcpsvr *http
  3.   strtcpsvr *http
Second, you must change the "script time-out" value in your http directives, by specifying a time value high enough to let you complete your debugs without having the server job terminating because of an excessive wait time on the server response.
  1.   wrkhttpcfg config
    add or change the following directive
      ScriptTimeOut nn mins
    by specifying af least 30 for nn .
  2.   endtcpsvr *http
  3.   strtcpsvr *http
The third problem, is to find which HTTP server job detected the failure.
If you have too many HTTP server jobs, you will spend too much time in looking at their joblogs. To reduce the number of HTTP server jobs (for instance, to a maximum of 3)
  1. endtcpsvr *http
  2. chghttpa nbrsvr(3 3)
  3. strtcpsvr *http
Next, to find out the HTTP server job detecting the failure
  1. if before OS/400 release V4R3M0,
      wrkactjob sbs(qsyswrk),
    otherwise
      wrkactjob sbs(qhttpsvr)
  2. roll up to the http server jobs with a jobname same as the istance name of the http server you are using (usually DEFAULT) and press F10
  3. run again your failing CGI
  4. press F5 to refresh the wrkactjob display
  5. display the joblogs of the http server jobs with a CPU % other than .0

2- Trivial cases

  1. If your browser displays error 404, that may just mean that your HTTP directives are not working
  2. If you have installed library cgidev2, disable any proxy from your web browser and try to run the following:
    http://.../cgidev2o/hello.htm
    (replace ... with the TCP address of your AS/400)
    • If you get no response, but an Error 400 message, it may mean that your HTTP server is not serving your request. Some of the causes:
      • Your HTTP server is not active; you can check it by entering command
        wrkactjob sbs(qhttpsvr)
      • Your HTTP server is active, but some other active HTTP server is locking port 80 for its own exclusive use. This happens for instance when you also run DOMINO. You may then try to change the port of your HTTP configuration in the following way:
        1. Assume your HTTP server is DEFAULT (controlled by HTTP configuration member CONFIG)
        2. Enter command
              wrkhttpcfg cfg(config) to work with your HTTP server configuration
        3. Look for a Port directive.
        4. If you find it, change the port number. For instance, instead of port 80, assign port 7777.
        5. If you do not find it, just add a directive like
              Port 7777
        6. Re-start your HTTP server
        7. Re-try the URL by entering
              http://...:7777/cgidev2o/hello.htm
  3. If you get Error 500 in running
    http://.../cgidev2o/hello.htm
    do the following:
    • make sure that library CGIDEV2 and program CGIDEV2/HELLO1 are authorized to the *public for *use
    • make sure that the configuration directives of your HTTP server (command wrkhttpcfg) contain the directives needed to run CGIDEV2 CGIs, and that this HTTP server was re-started after installing such directives (CGIDEV2 directives may be installed through command CGIDEV2/HTTPCFG)
    • make sure that the configuration directives of your HTTP server contain the following directives
         enable get
         enable post
    • make sure you installed the last available PTF Cumulative for product 5769DG1 (IBM HTTP Server for AS/400)
  4. If none of the above solved your problem, you may want to restart your HTTP server telling to maintain a "very verbose" trace:
    STRTCPSVR SERVER(*HTTP) HTTPSVR(DEFAULT '-vv')
    Then look at the trace spool files (QPZHBTRC) generated by the -vv trace. You can find them by entering command
        WRKSPLF SELECT(QTMHHTTP)
Note 1. Troubleshooting information for CGI is in manual HTTP Server for AS/400 Web Programming Guide, Chapter 10.
Note 2.Information about PTFs can be fount at http://as400service.rochester.ibm.com/

3- Non trivial cases

This is the most common situation.
You got to the point where you have really to debug your CGI program.

To perform debug, you must have compiled your ILE modules with the option
DBGVIEW(*SOURCE)
If you have done so,
  1. strsrvjob ..... the http server job which detected the failure
  2. strdbg your_CGI_program updprod(*yes)
  3. Some basics, when the source of the initial module is displayed
    • on the command line,
      F string
      to find a string
    • F16 to find next
    • move a cursor to a source line and press F6 to add a breakpoint
  4. Rerun your CGI program.
    Hopefully it will stop at some breakpoint of yours, you may tell from your debug session
  5. More hints on debug
    • position the cursor on a variable and press F11 to display its value
    • you can do the same on the command line by entering
      eval variable_name
    • to change the value of a variable, on the command line enter
      • eval variable_name = 'value'
        if it is a character variable
      • eval variable_name = value
        if it is a numeric variable
    • to execute one step of coding, press F10
    • to resume execution till the next breakpoint, press F12
    • if your module calls another module, and you want to debug this latter one
      • add a breakpoint on the call statement
      • when execution stops on this statement, press F22 to display and add breakpoints to this latter module
By sure you will become the most proficient debugger in your neighbourhood!