.TI F77/DBX "Sep. 4, 1985"
Dbx - The Source Level Debugger

The UNIX source language debugger is called "dbx".
This write-up illustrates how to use dbx to examine
the memory image of a program after a fatal error.
Dbx can also be used to step through the execution of a program,
see "man dbx" for full details.
To get the full benefit of dbx, you must specify the -g flag
when compiling and loading.
We will use the following program to illustrate the use of dbx:

.nf
		dimension vec(10)
	
		do 10 i = 1, 10
	10	vec(i) = 10.0/(i - 5)
		end
.fi

Compile it, execute it, and invoke dbx to examine the dump:

.nf
	% f77 -g prog.f
	prog.f:
	   MAIN:
	%
	% a.out
	*** Arithmetic Exception: Floating divide by zero
    	Illegal instruction (core dumped)
	% 
	% dbx
	dbx version 3.3 of 8/28/85 19:51 (ucbopal).
	Type 'help' for help.
	enter object file name (default is `a.out'): 
	reading symbolic information ...
	[using memory image in core]
	(dbx) 
.fi

When dbx is running, it changes the prompt to "(dbx)".
To exit dbx, use the "quit" command.
Within dbx, the "help" command summarizes some (not all) of the dbx
commands.
The dbx command "where" displays a subroutine traceback telling
which line in each subroutine is active:
.nf

	(dbx)
	(dbx) where
	abort() at 0x15de
	f77_abort(0x8, 0x1) at 0xa74
	sigdie(0x8, 0x9, 0x7fffec68, 0x12e) at 0x229
	MAIN(), line 4 in "prog.f"
	main(0x1, 0x7fffeccc, 0x7fffecd4) at 0x123

.fi
If you did not compile with -g, but did load with -g (e.g. f77 -g *.o);
\&"where" still gives a traceback of the names of active subroutines,
but without line numbers.

The "list" command lists the source for the currently active source
file:

.nf
	(dbx) list
	    1		dimension vec(10)
	    2	
	    3		do 10 i = 1, 10
	    4   10	vec(i) = 10.0/(i - 5)
	    5   	end
.fi

The default is to list 10 lines at a time; you can specify a range of
lines as in "list 32,45".  Switch the active source file with the "file"
command.  Use the "print" command to display the values of variables.
If an array name is specified, the entire array is printed:
.nf

	(dbx) 
	(dbx) print vec
	[1]	-2.5
	[2]	-3.33333
	[3]	-5.0
	[4]	-10.0
	[5]	0.0
	[6]	0.0
	[7]	0.0
	[8]	0.0
	[9]	0.0
	[10]	0.0

.fi
You can also request individual elements, e.g.: "print vec[2], vec[8]".
Note you must use square brackets around subscripts instead of parentheses.

The "/" command, listed in "man dbx" under "Machine Level Commands",
allows you to list any part of memory.
It may be used to print part of a vector or array, something that can not
be specified with the "print" command.
The general format of "/" is:

	address/count mode

Commonly used modes with Fortran are:

.nf
	D	print an integer in decimal
	f	print a single precision real
	g	print a double precision real
	X	print an integer or single precision real in hexadecimal
	c	print a byte as a character
	s	print a string of characters terminated by a null (0 byte)
.fi

To print vec() with the "/" command, type:

	&vec/10 f

This says to start displaying memory at the address "&vec", which is the
address of vector vec(), display 10 items using floating point format:
 
.nf
	(dbx) &vec/10 f
	00002c34:  -2.500000 -3.333333 -5.000000 -10.000000
	00002c44:  0.000000 0.000000 0.000000 0.000000
	00002c54:  0.000000 0.000000
.fi

The "/" command may be used to print part of a vector or array.
The following prints vec(3)...vec(6):

.nf
	(dbx) 
	(dbx) &vec+8/4 f
	00002c3c:  -5.000000 -10.000001 0.000000 0.000000
.fi

The initial address uses byte arithmetic, so that &vec+8 is the address
of vec(3).
