Print values ​​from a Fortran polymorphic derivative to GDB

I am trying to debug the following code using gdb (GNU gdb (Ubuntu / Linaro 7.4-2012.04-0ubuntu2.1) and gfortran (gcc version 4.6.3). If I start gdb and go through the fun routine, I want to print variables of a derived type "mytype" is inside the class_test module. It is easy to print the variable "int", which is also in the module "class_test" with the command: print class_test :: int. My question is how to print the variable int1, int2 ... int4, if gdb steps through the fun routine?

!! class definition

  module class_test


 integer :: int = 1


 type, public :: mytype

    private

    integer :: int1  = 2

    integer :: int2  = 3

    integer :: int3  = 4

    integer :: int4  = 5

  contains


  procedure, pass(this) :: fun

  end type mytype

  contains

  subroutine fun ( this )

  class(mytype) :: this

  write (*,*) "subroutine" 

  end subroutine fun

  end module class_test


  !! Program
  program test 

 use class_test

 type(mytype) :: struct

 write (*,*) "whateveryouwant"

 call struct%fun()


  end program
+4
source share
2 answers

, , . :

(gdb) break class_test::fun
(gdb) run
(gdb) info args

struct, this:

this = ( 0x601080 <struct>, 0x400ae0 <__class_test_MOD___vtab_class_test_Mytype> )

struct gdb segfault . (Fortran 2008) storage_size, , this 128 . 4- , 0x601080, :

(gdb) x/4u 0x601080

0x601080 <struct.1905>: 2       3       4       5

, struct 2, 3, 4 5, .

, , .

+1

GDB, Fortran gdb?, , _data . -

print this%_data%int1

( , , Google, . , , GDB, - Fortran. - , .)

Fortran , , .

( "this" "temp", - , , GDB), GDB ( 7.11.1 Ubuntu):

(gdb) print temp
$1 = ( 0x601070 <struct>, 0x4009c0 <__class_test_MOD___vtab_class_test_Mytype> )
(gdb) print temp%_data
$2 = (PTR TO -> ( Type mytype
integer(kind=4) :: int1
integer(kind=4) :: int2
integer(kind=4) :: int3
integer(kind=4) :: int4
End Type mytype )) 0x601070 <struct>
(gdb) print temp%_data%int1
$3 = 2
(gdb) print temp%_data%int2
$4 = 3
+1

Source: https://habr.com/ru/post/1541820/


All Articles