Debugging a Program With dbx

Pointer to Fortran 90 Derived Type

You can show structures--f90 derived types, and pointers with dbx.


DebStruc.f90



Declare  a                    derived type.



Declare prod1  and prod2 targets.
Declare curr and prior pointers.

Make curr point to prod1.
Make prior point to prod1.
Initialize prior.

Set curr to prior.
Print name from curr and prior.
 demo% f90 -o debstr -g DebStruc.f90
 demo% dbx debstr
 (dbx) stop in main
 (2) stop in main
 (dbx) list 1,99
     1   PROGRAM DebStruPtr! Debug structures & pointers
     2      TYPE product
     3         INTEGER        id
     4         CHARACTER*16   name
     5         CHARACTER*8    model
     6         REAL           cost
     7         REAL           price
     8      END TYPE product
     9   
    10      TYPE(product), TARGET :: prod1, prod2
    11      TYPE(product), POINTER :: curr, prior
    12   
    13      curr => prod2
    14      prior => prod1
    15      prior%id = 82
    16      prior%name = "Coffee Cup"
    17      prior%model = "XL"
    18      prior%cost = 24.0
    19      prior%price = 104.0
    20      curr = prior
    21      WRITE ( *, * ) curr%name, " ", prior%name
    22   END PROGRAM DebStruPtr
 (dbx) stop at 21 
 (1) stop at "DebStruc.f90":21
 (dbx) run 
 Running: debstr 


(process id 10972)
stopped in main at line 21 in file "DebStruc.f90" 
   21      WRITE ( *, * ) curr%name, " ", prior%name 
(dbx) print prod1
 prod1 = (
	id = 82 
	name = "Coffee Cup" 
	model = "XL" 
	cost = 24.0 
	price = 104.0
) 

Above, dbx displays all fields of the derived type, including field names.

You can use structures--inquire about an item of an f90 derived type.


Ask about the variable

Ask about the type (-t)
 (dbx) whatis prod1
 product prod1 
 (dbx) whatis -t product
 type product
    integer*4 id 
    character*16 name 
    character*8 model 
    real cost 
    real price 
 end type product 

To print a pointer:


dbx displays the contents of a pointer, which is an address. This address can be different with every run.
 (dbx) print prior
 prior = (
     id    = 82
     name = 'Coffee Cup'
     model = 'XL'
     cost = 24.0
     price = 104.0
 )