Debugging a Program With dbx

Using RTC in Batch Mode

bcheck(1) is a convenient batch interface to the RTC feature of dbx. It runs a program under dbx and by default places the RTC error output in the default file program.errs.

bcheck can perform memory leak checking, memory access checking, memory use checking, or all three. Its default action is to perform only leak checking. Refer to the bcheck (1) man page for more details on its use.

The syntax for bcheck is:


bcheck [-access | -all | -leaks | -memuse] [-o logfile
] [-q] 
[-s script] program
 [args]

Use the -o logfile option to specify a different name for the logfile. Use the -s script option before executing the program to read in the dbx commands contained in the file script. The script file typically contains commands like suppress and dbxenv to tailor the error output of bcheck.

The -q option makes bcheck completely quiet, returning with the same status as the program. This is useful when you want to use bcheck in scripts or makefiles.

Perform only leak checking on hello:


bcheck hello

Perform only access checking on mach with the argument 5:


bcheck -access mach 5

Perform memory use checking on cc quietly and exit with normal exit status:


bcheck -memuse -q cc -c prog.c

The program does not stop when runtime errors are detected in batch mode. All error output is redirected to your error log file logfile. But the program stops when breakpoints are encountered or if the program is interrupted.

In batch mode, the complete stack backtrace is generated and redirected to the error log file. The number of stack frames can be controlled using the dbxenv variable stack_max_size.

If the file logfile already exists, bcheck erases the contents of that file before it redirects the batch output to it.

You can also enable a batch-like mode directly from dbx by setting the following dbxenv variables:


(dbx) dbxenv rtc_auto_continue on
(dbx) dbxenv rtc_error_log_file_name logfile

With these settings, the program does not stop when runtime errors are detected, and all error output is redirected to your error log file.