DB 2 Debug

It can be difficult to debug ILE stored procedures from scripts and PASE code using QSQSRVR jobs. Here is a technique used by the pros.

  • server job QSQSRVR — ILE Stored procedure debug (XMLSERVICE SRVPGM example)
Using "*LOCAL-*DEBUG" to stop the QSQSRVR job.
1. Run the test script that contains control “*LOCAL-*DEBUG” and script will wait "hang"
   > connect("*LOCAL-*DEBUG",myprofile,mypassword)
2. A MSGW inquiry message in DSPMSG QSYSOPR will be generated. 
   > DSPMSG QSYSOPR
     GIVE ME A "G" TO CONTINUE PROCESSING    DB2
     F1=Help
     F9=Display message details  
                            Display Message Details                             
     From job . . . . . . . . . . . :   QP0ZSPWP 
     User . . . . . . . . . . . . :     QSECOFR
     Number . . . . . . . . . . . :     713706 
     From program . . . . . . . . . :   QSQCLI
3. Check the job log for the QSQSRVR job information.
   > DSPJOBLOG JOB(713706/QSECOFR/QP0ZSPWP)                                     
                            Display Job Log
     Job 712321/QUSER/QSQSRVR used for SQL server mode processing.
     Job 712324/QUSER/QSQSRVR used for SQL server mode processing. <-- last one
     GIVE ME A "G" TO CONTINUE PROCESSING    DB2
4. STRSRVJOB using that job information as parameters. 
   > STRSRVJOB JOB(712324/QUSER/QSQSRVR)
5. STRDBG with the program and library you wish to debug.
   > STRDBG PGM(*NONE) SRVPGM(XMLSERVICE/XMLSTOREDP)
     P iRunMe          B                   
     D iRunMe          PI             1N 
       :  
       if pXmlOut <> *NULL;  <-- F6=Add/Clear breakpoint
     F12=Resume
6. Answer the MSGW ”G” is fine. 
7. The RPG program source will appear in debug mode in your terminal
8. When done inspecting and stepping, let the RPG program complete. 
    > ENDDBG 
    > ENDSRVJOB
  • client job (any) — PASE program/script debug c code

You can use same technique to debug PASE job/code.
1. Run “*LOCAL-*DEBUG”
   GIVE ME A "G" TO CONTINUE PROCESSING    DB2
   From job . . . . . . . . . . . :   QP0ZSPWP    
   User . . . . . . . . . . . . :     QSECOFR   
   Number . . . . . . . . . . . :     713707
2. Use PASE ps -ef to find job in wait.
   $ ps -ef
     adc 241574 241157   0 12:13:45  pts/0  0:00 ./db2_cli_in_nut_shell
3. Use PASE getjobid to verify correct job
   $ getjobid 241574                                      
     Process identifier 241574 is 713707/QSECOFR/QP0ZSPWP
4. Use PASE dbx -a to attach debugger
   $ dbx -a 241574 <-- hangs until answer QSYSOPR message
5. Answer the MSGW ”G” is fine. 
   $ dbx ... resumes  
     Waiting to attach to process 241574 ...
     Successfully attached to ./db2_cli_in_nut_shell.
   (dbx) step
     stopped in open_connect at line 269 in file "./db2_cli_in_nut_shell.c" ($t1)
     269     if (rc != SQL_SUCCESS) die(hdbc, SQL_HANDLE_DBC, 1);
   (dbx) print rc
     0 
   (dbx) list
     270     return rc;
     271   }
   (dbx) print &rc
     0x2ff13b88 
   (dbx) 0x2ff13b88 / 4X
     0x2ff13b88:  00000000 00000004 0000000b 00010003 
   (dbx) where
     open_connect(database = "*LOCAL-*DEBUG", user = "DB2", password =
   (dbx) registers
     $r0:0xd01e9fd8  $stkp:0x2ff13b50   $toc:0x20000a60    $r3:0x00000000  
   (dbx) map
      Entry 1:
         Object name: /home/ADC/db2sample/./db2_cli_in_nut_shell
         Text origin:     0x10000000
         Text length:     0x786a
         Data origin:     0x20000568
         Data length:     0x698
         File descriptor: 0x3
      Entry 2:
         Object name: /usr/lib/nls/loc/uconv/UTF8TBL
   (dbx) stepi
      stopped in open_connect at 0x10001034 ($t1)
      0x10001034 (open_connect+0x1f0) 2f800000        cmpi   cr7,0x0,r0,0x0
   (dbx) nexti
      stopped in open_connect at 0x10001038 ($t1)
      0x10001038 (open_connect+0x1f4) 419e0020         beq   cr7,0x10001058
   (dbx) next
      stopped in open_connect at line 270 in file "./db2_cli_in_nut_shell.c" ($t1)
      270     return rc;
   (dbx) detach   <-- release process to run
   (dbx) quit     <-- kill process immediately