Sample dbx Runs



next up previous contents index
Next: SAMPLE DOT FILES Up: Unix Debugging Tools: Previous: Prerequisites for dbx

Sample dbx Runs

As an example, let's say our old program area.f from Chapters 2 and 8 has somehow been corrupted and no longer gives correct answers. It compiles fine and runs fine, but we must have inadvertently changed something in viewing the file. (The problem is that we have lost an asterisk in the line which calculates the area, so that it now reads A = pi * r*2 rather than A = pi * r**2; but let's assume only superuser knows this and won't tell us.) We compile area.f in our usual way and store the executable in area. We now use dbx to examine the program during execution. (If xde is available, you can push buttons rather than give the subcommands.)
   

% f77 -wO area.f -o area   	Compile, optimize, object in area.   
% dbx area   	Begin debugging the executable area.    
% (xde area)   	Alternative X Window interface for dbx.   
dbx version 3.1 for AIX.   	   
Type 'help' for help.   	   
reading symbolic info ...warning:   	   
no source compiled with -g   	   
(dbx)   	(dbx) = dbx promp.   
(dbx)quit   	Get out of dbx, need -g option.   
%    	The shell's prompt returns.   
% f77 -g area.f -o area   	Compile, optimize, object in area.   

  When we are told that we forgot to invoke the -g option, we quit dbx and then compile properly. Now we are really ready to start debugging. We make execution of the program stop at critical points called breakpoints with the dbx subcommand stop, move on from there with the step subcommand, and use the dbx subcommand print to examine a variable's value:

% dbx area   	Begin debugging executable area.   
dbx version 3.1 for AIX.   	   
Type 'help' for help.   	   
reading symbolic information ...   	   
(dbx)list 1,20   	We tell dbx  to list lines 1:20.   
1          PROGRAM area   	   
2   c   	   
3   c area of circle, r input from terminal   	   
4   c   	   
5           DOUBLE PRECISION pi, r, A   	   
6   c calculate pi   	   
7          pi = 3.141593   	   
8   c read r from standard input (terminal)   	   
9          Write(*,*) 'specify radius'   	   
10          Read (*, *)  r   	   
11   c calculate area   	   
12           A = pi * r*2   	   
13   c               write area onto terminal screen   	   
14           Write(*,10) 'radius r =', r, ' A =', A   	   
15    10          Format(a20, f10.2, a15, f12.3)   	   
16           STOP 'area'   	   
17           END   	   
(dbx)stop at 14    	We set breakpoint.   
[1] stop at 14   	dbx's confirmation.   
(dbx)run   	Run program now.   
specify radius   	The program's query.   
   	We enter 2   
[1] stopped in area at line 14   	dbx stops area.   
(dbx)print radius   	We ask for value of radius.  
"radius" is not defined   	Our mistake, it's called r.   
(dbx)print r   	We ask for value of r   
2.0   	dbx tells us value of r at breakpoint.   
[1] stopped in area at line 14   	dbx stops area,   
14  Write(*,10) 'radius r=',r,'A=',A   	  and lists line.   
(dbx)continue   	We tell dbx to continue.   
radius r = 2.00 A = 12.566   	area's output.   
STOP area   	area's output.    
execution completed   	Message from dbx.   
(dbx)print pi   	We ask for value of .   
3.1415929794311523   	dbx gives  at breakpoint.   
(dbx)status   	List active dbx command.   
[1] stopped in area at line 14   	Command # 1 active.   
(dbx)delete 1   	Remove command #1, breakpoint.   
(dbx)list 12   	List line 12.   
12  A = pi * r*2   	Line from code with error.   
(dbx)edit   	You edit area.f to insert missing *.   
(dbx)quit   	Get out of debugger.     
% f77 -wO area.f -o area   	Recompile area.f.   
% area   	We rerun program.   
specify radius   	   
.0   	   
radius r =   2.00 A =  12.566   	The right answer.   

Again notice that you must recompile the program after editing and then use dbx on the new program.



next up previous contents index
Next: SAMPLE DOT FILES Up: Unix Debugging Tools: Previous: Prerequisites for dbx