Examples of using the dbx utility

To examine the state of the process in memory for a sample program /mylog/appl/execut/samp:
int main(void) {
   int *p1 = 0;
   *p1 = 42;
   return 0; 
}
that is the object from a compile using the c89 -g option, enter:
c89 -g -o samp samp.c
dbx -r samp
dbx runs the program until it reaches an abnormal termination condition and then prompts you for a debugging subcommand:
FDBX6421: Loaded debug data from "./samp.dbg"

FDBX0163: Entering debugger…
FDBX0089: dbx for z/OS.
FDBX0399: Compiled: Dec  8 2003 at 13:58:54
FDBX0400: OS level: 15.00 03; LE level: 4.1.5; (Local)
FDBX6499: CDA levels: ELF=P040106.z1r6, DWARF=P040106.zosv1r6,
                      DDPI=P040106.zosv1r6
FDBX0100: Type 'help' for help.
FDBX0048: Set an event like 'st in main' then use 'c' to start debugging.
FDBX0150: Debug target is 31-bit


segmentation violation (invalid key access) in main at line 6 in file  
"/mylog/appl/execut/samp/samp.c" ($t1)
    6       return 0;
(dbx31) quit
As another example, consider that the following program, looper.c, can never end because the value of i is never incremented:
#include <stdio.h>

int main(void)
{
    int i, x[64];

    for (i = 0; i < 10;) {
        printf("%d\n", x[i]);
        sleep(1);
    }
    return 0;
}
Compile the program with the c89 -g option to produce an executable program with symbolic debugging capability:
c89 -g -o looper looper.c
Then run the program from the command line:
looper &
Seeing that your program does not end as expected, you want to debug it while it continues to run. To attach dbx to a process that was just started in the background, type the following:
dbx -a $!

or perform the following steps:

  1. Determine the ID number associated with the process that is running to attach to looper. You must open another shell session if you did not run looper as a background process. From the second shell session you just established, enter the following shell command:
    ps -u userid -o pid,tty,time,comm
    where userid is your TSO/E user ID that is running looper. All active processes that belong to that user ID are displayed:
          PID TT              TIME COMMAND
       655362 ?           00:00:10
       458755 ttyp0000    00:00:00 /bin/sh
       524292 ttyp0000    00:00:02 looper
            6 ttyp0000    00:00:00 /bin/ps

    The process ID associated with looper is 524292.

  2. To attach dbx to looper, enter:
    dbx -a 524292
    dbx attaches to the process running the program, displays the last instruction processed, and prompts you for a debugging subcommand:
    FDBX0089: dbx for z/OS.
    FDBX0399: Compiled: Dec  8 2003 at 13:58:54
    FDBX0400: OS level: 15.00 03; LE level: 4.1.5; (Local)
    FDBX6499: CDA levels: ELF=P040106.zosv1r6, DWARF=P040106.zosv1r6,
                          DDPI=P040106.zosv1r6
    FDBX0100: Type 'help' for help.
    FDBX0048: Set an event like 'st in main' then use 'c' to start debugging.
    FDBX0278: Waiting to attach to process 33619980 …
    FDBX6421: Loaded debug data from "./looper.dbg"
    
    attached in . at 0x0d9d8d1c ($t1)
    sleep() at 0xd9d8ca8, PPA1 at 0xd9dded0, stack at 0x2001f3c0
    main.$b2, line 9 in "/tmp/looper.c"
    main(), line 9 in "/tmp/looper.c"
    EDCZMINV() at 0xdaa6416, PPA1 at 0xdaa6416, stack at 0x2001f0f8
    CEEBBEXT() at 0xce89130, PPA1 at 0xce89418, stack at 0x2001f030
    0x0d9d8d1c ()     58f0d0a0     l      $r15,X'A0'(,$r13)
    FDBX0150: Debug target is 31-bit
    (dbx31) quit

You can now query and debug the process as if it had been originally started with dbx. When you are finished debugging the process and have ended dbx, enter the shell exit command to end the second shell session and return to your initial session.